Skip to content

Commit

Permalink
- fix Mainnet Checkopoint Root Gauge bug
Browse files Browse the repository at this point in the history
- add stakeless gauges to mainnet gauge adder
  • Loading branch information
Hyferion committed Apr 18, 2024
1 parent 177cacc commit 99bbba6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion tasks/Mainnet Checkpoint Root Gauges/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async function sendNotification(context, _subject, _message) {

// Entrypoint for the Autotask
exports.handler = async function (credentials, context) {
const autotaskClient = new AutotaskClient({ apiKey: credentials.secrets.apiKey, apiSecret: credentials.secrets.apiSecret });
const autotaskClient = new AutotaskClient({
apiKey: credentials.secrets.DEFENDER_API_KEY,
apiSecret: credentials.secrets.DEFENDER_API_SECRET
});
let autotaskMetadata = await autotaskClient.get(credentials.autotaskId);
const provider = new DefenderRelayProvider(credentials);
const signer = new DefenderRelaySigner(credentials, provider, { speed: 'average' });
Expand Down
36 changes: 29 additions & 7 deletions tasks/Mainnet Gauge Adder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
DefenderRelaySigner,
DefenderRelayProvider,
} = require('defender-relay-client/lib/ethers')
const { Relayer } = require('defender-relay-client');
const {Relayer} = require('defender-relay-client');
const ethers = require('ethers')

const GAUGE_CHECKPOINTER_ADDRESS = '0x0C8f71D19f87c0bD1b9baD2484EcC3388D5DbB98'
Expand All @@ -16,18 +16,28 @@ const SUBGRAPH_QUERY = `{
id
chain
}
singleRecipientGauges(first: 100, where:{
isKilled:false
gauge_not:null
}) {
id
}
}`

// aux function to get all gauges from subgraph
async function getGauges() {
const response = await fetch(SUBGRAPH_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: SUBGRAPH_QUERY }),
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({query: SUBGRAPH_QUERY}),
})
const json = await response.json()
let result = json.data.rootGauges
return result
let rootGauges = json.data.rootGauges;
let singleRecipientGauges = json.data.singleRecipientGauges;
singleRecipientGauges.forEach(obj => obj.chain = "Ethereum");


return [...rootGauges, ...singleRecipientGauges]
}


Expand All @@ -37,9 +47,9 @@ exports.handler = async function (event) {
// Use relayer for sending txs
console.log('Getting gauges from the subgraph...');
const gauges = await getGauges();
console.log(gauges);

const provider = new DefenderRelayProvider(event);
const signer = new DefenderRelaySigner(event, provider, { speed: 'fast' });
const signer = new DefenderRelaySigner(event, provider, {speed: 'fast'});
const checkpointerContract = new ethers.Contract(GAUGE_CHECKPOINTER_ADDRESS, GAUGE_CHECKPOINTER_ABI, signer);
// get the unique chains
const chains = [...new Set(gauges.map(gauge => gauge.chain))];
Expand Down Expand Up @@ -69,4 +79,16 @@ exports.handler = async function (event) {
console.log('No gauges to add for chain ', chain);
}
}
}

// To run locally (this code will not be executed in Autotasks)
if (require.main === module) {
require('dotenv').config();
const {DEFENDER_API_KEY: apiKey, DEFENDER_API_SECRET: apiSecret} = process.env;
exports.handler({apiKey, apiSecret})
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
}

0 comments on commit 99bbba6

Please sign in to comment.