Skip to content

Commit

Permalink
- test new monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyferion committed Jul 22, 2024
1 parent ffabf79 commit 18c207f
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 59 deletions.
2 changes: 1 addition & 1 deletion tasks/Arbitrum Child Chain Gauges Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "0b7807ed-ce8d-476b-8598-040c296adfba",
"codeDigest": "Lbe/wPLqSnTBKSWY0zl1T0bqAHdC8wcmI+PulxIOE04=",
"codeDigest": "yMMBTzEskFbvV3rsibUbS9xaNrrRfHEXLjbXwLp14ig=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Arbitrum Gauge Reward Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "0b7807ed-ce8d-476b-8598-040c296adfba",
"codeDigest": "VAXszrjt32eHr0P5Bcb8spLGO4hPth6k1LOvjI/mmj8=",
"codeDigest": "Gyi9eVhiNH6yGbpYP2ckBreRJumWvAy9AfJtB1uUFrw=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Arbitrum Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "0b7807ed-ce8d-476b-8598-040c296adfba",
"codeDigest": "UXuV6iqfQby+0KGjehYI3iXsJDak9IxQt+GTEb7207A=",
"codeDigest": "YtmYL4uGi+o6vU7lC45hbn/ypIxwuFFil8A7KK3eqfk=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "73e57662-7a23-462e-96ce-40810292a07f",
"codeDigest": "sS3eYAqrL7B01Bt1rj7xecvnauAWpaOKQuAjc3yuMVY=",
"codeDigest": "J8ekRVRDVzwcvYBrCPyDbKttQiPNuxxrjosjwnrK1VQ=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Avalanche Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "73e57662-7a23-462e-96ce-40810292a07f",
"codeDigest": "w00wukVN4PgdtbQrVJcIZnmoBeyHPfY1zfMViG183qE=",
"codeDigest": "kbZrX/knso8RuVO4ZQAQ8zobOqnAjgUeZMs/Dm60Kks=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Base Child Chain Gauges Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "384e11fa-9222-4556-9f93-add1fef65f83",
"codeDigest": "eG/8vwi4ciSs6xagWudZzPJqjcJ0yIlbUh2V0u3rNfM=",
"codeDigest": "fUlbBQV4fosQ1xSW6KX9aYWniVspDVFpXm4v5sjbTQw=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Base Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "384e11fa-9222-4556-9f93-add1fef65f83",
"codeDigest": "MiuOSFB+J0RYapzNx7w1xGxvPWHnGZUIj3YKOHa13qI=",
"codeDigest": "/cc4zyMdDjiP66EZUF4D41mUiXIR6HcoFjLdo/XJ1s8=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Gnosis Child Chain Gauges Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "df853bf7-3ccc-4461-9b20-cd4a1caf475a",
"codeDigest": "Rsdn4m3ZmNzBCFlWTwMbkBjEoZN9KhewdlByMY6Wb+Y=",
"codeDigest": "KhECsX+VQhdipxdQdzhyls/vXCXhtMWNhnHs9mYpI0w=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Gnosis Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "df853bf7-3ccc-4461-9b20-cd4a1caf475a",
"codeDigest": "xU4guW4V7Df7s6MQdzGzahGsA0D0UlQy8Lo6ary8KFg=",
"codeDigest": "5+rhCqGBD/4rZbqnZXSp53KbPvV+CzFmd2NO8vfBiVY=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
4 changes: 2 additions & 2 deletions tasks/LZ Rate Updater/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"name": "LZ Rate Updater",
"paused": false,
"trigger": {
"cron": "4 12 27 6 *",
"cron": "4 12 23 7 *",
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "/je7afaaTlVJe+LYTKeRJ+s76n2e8J6XB0xEdFDbLmQ=",
"codeDigest": "tdY6zc+mKflniHNkZtBw+YxKCtUdAazSa4zYczqeVFg=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Mainnet Checkpoint Root Gauges/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "c7/zDODx6XXz/5NccgCVERCLPjFnNNe6wH5Uj6WATtY=",
"codeDigest": "mrqzHmRvYfgffR6Hsimtnf6X1f71ZQkom/eQpvOYlik=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Mainnet Checkpoint Specific Root Gauges/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "ha9wDv8cx9gVrUITXVky19Ie5TEsFydNoqKe2eQFh2g=",
"codeDigest": "dikeKKQbclfgLZdZR5dJES/NxPm4up0PGrOOACoQEaM=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Mainnet Gauge Adder/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "PJF8WdDUI4vUbjcMLlYUnr+bAOBImd4r7R6p0WjxCws=",
"codeDigest": "4vghH9KZR/GhnuOUkpN1ww5CtDGhtQTE2hDOv060yps=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
89 changes: 52 additions & 37 deletions tasks/Mainnet Gauge Adder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ const {
DefenderRelaySigner,
DefenderRelayProvider,
} = require('defender-relay-client/lib/ethers')
const {Relayer} = require('defender-relay-client');
const ethers = require('ethers')

const GAUGE_CHECKPOINTER_ADDRESS = '0x0C8f71D19f87c0bD1b9baD2484EcC3388D5DbB98'
const GAUGE_CHECKPOINTER_ABI = `[{"inputs":[{"internalType":"contract IGaugeAdder","name":"gaugeAdder","type":"address"},{"internalType":"contract IAuthorizerAdaptorEntrypoint","name":"authorizerAdaptorEntrypoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IStakelessGauge","name":"gauge","type":"address"},{"indexed":true,"internalType":"string","name":"indexedGaugeType","type":"string"},{"indexed":false,"internalType":"string","name":"gaugeType","type":"string"}],"name":"GaugeAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IStakelessGauge","name":"gauge","type":"address"},{"indexed":true,"internalType":"string","name":"indexedGaugeType","type":"string"},{"indexed":false,"internalType":"string","name":"gaugeType","type":"string"}],"name":"GaugeRemoved","type":"event"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"contract IStakelessGauge[]","name":"gauges","type":"address[]"}],"name":"addGauges","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"contract IStakelessGauge[]","name":"gauges","type":"address[]"}],"name":"addGaugesWithVerifiedType","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minRelativeWeight","type":"uint256"}],"name":"checkpointGaugesAboveRelativeWeight","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"uint256","name":"minRelativeWeight","type":"uint256"}],"name":"checkpointGaugesOfTypeAboveRelativeWeight","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"address","name":"gauge","type":"address"}],"name":"checkpointSingleGauge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"getActionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAuthorizer","outputs":[{"internalType":"contract IAuthorizer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGaugeAdder","outputs":[{"internalType":"contract IGaugeAdder","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getGaugeAtIndex","outputs":[{"internalType":"contract IStakelessGauge","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"address","name":"gauge","type":"address"}],"name":"getSingleBridgeCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"minRelativeWeight","type":"uint256"}],"name":"getTotalBridgeCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"}],"name":"getTotalGauges","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"contract IStakelessGauge","name":"gauge","type":"address"}],"name":"hasGauge","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"}],"name":"isValidGaugeType","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"gaugeType","type":"string"},{"internalType":"contract IStakelessGauge[]","name":"gauges","type":"address[]"}],"name":"removeGauges","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
const SUBGRAPH_URL = 'https://api.studio.thegraph.com/query/75376/balancer-gauges/version/latest'
const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-gauges'
const SUBGRAPH_QUERY = `{
rootGauges (first:1000 where:{
isKilled:false
Expand All @@ -24,7 +23,6 @@ const SUBGRAPH_QUERY = `{
}
}`

// aux function to get all gauges from subgraph
async function getGauges() {
const response = await fetch(SUBGRAPH_URL, {
method: 'POST',
Expand All @@ -36,52 +34,69 @@ async function getGauges() {
let singleRecipientGauges = json.data.singleRecipientGauges;
singleRecipientGauges.forEach(obj => obj.chain = "EthereumSingleRecipientGauge");


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

exports.handler = async function (event, context) {
try {
console.log('Getting gauges from the subgraph...');
const gauges = await getGauges();

const provider = new DefenderRelayProvider(event);
const signer = new DefenderRelaySigner(event, provider, {speed: 'fast'});
const checkpointerContract = new ethers.Contract(GAUGE_CHECKPOINTER_ADDRESS, GAUGE_CHECKPOINTER_ABI, signer);

const chains = [...new Set(gauges.map(gauge => gauge.chain))];

for (let i = 0; i < chains.length; i++) {
const chain = chains[i];
console.log('Adding gauges for chain ', chain);
const gaugesForChain = gauges.filter(gauge => gauge.chain === chain);

let gaugesToAdd = [];
for (let j = 0; j < gaugesForChain.length; j++) {
const gaugeAddress = gaugesForChain[j].id;
const gaugeType = gaugesForChain[j].chain;

// Entrypoint for the Autotask
exports.handler = async function (event) {
const relayer = new Relayer(event);
// Use relayer for sending txs
console.log('Getting gauges from the subgraph...');
const gauges = await getGauges();
const gaugeExists = await checkpointerContract.connect(signer).hasGauge(gaugeType, gaugeAddress);
if (!gaugeExists) {
gaugesToAdd.push(gaugeAddress);
}
}

const provider = new DefenderRelayProvider(event);
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))];
// for each chain, add the gauges to the checkpointer contract
for (let i = 0; i < chains.length; i++) {
const chain = chains[i];
console.log('Adding gauges for chain ', chain);
const gaugesForChain = gauges.filter(gauge => gauge.chain === chain);
// create an empty array to store the gauges that need to be added to the checkpointer
let gaugesToAdd = [];
for (let j = 0; j < gaugesForChain.length; j++) {
const gaugeAddress = gaugesForChain[j].id;
const gaugeType = gaugesForChain[j].chain;
// check if the gauge exists in the gauge checkpointer contract
const gaugeExists = await checkpointerContract.connect(signer).hasGauge(gaugeType, gaugeAddress);
// if the gauge doesn't exist, add it to the list of gauges to add
if (!gaugeExists) {
gaugesToAdd.push(gaugeAddress);
if (gaugesToAdd.length > 0) {
console.log('Adding gauges ', gaugesToAdd, ' of type ', chain, ' to the checkpointer contract');
const tx = await checkpointerContract.connect(signer).addGauges(chain, gaugesToAdd);
console.log(tx);
} else {
console.log('No gauges to add for chain ', chain);
}
}
// add the gauges to the checkpointer contract
if (gaugesToAdd.length > 0) {
console.log('Adding gauges ', gaugesToAdd, ' of type ', chain, ' to the checkpointer contract');
const tx = await checkpointerContract.connect(signer).addGauges(chain, gaugesToAdd);
console.log(tx);

console.log('Gauge checkpointer script completed successfully.');
} catch (error) {
console.error('An error occurred in the gauge checkpointer script:', error);

if (context) {
const { notificationClient } = context;
try {
notificationClient.send({
channelAlias: 'Hal Maxi Bot (tg)',
subject: 'MAINNET GAUGE ADDER FAILED',
message: 'There was a problem running the Mainnet Gauge Adder on Open Zeppelin.'
});
} catch (error) {
console.error('Failed to send notification', error);
}
} else {
console.log('No gauges to add for chain ', chain);
console.log('No context, not sending notification');
}

// Re-throw the error to ensure the task is marked as failed
throw error;
}
}

// 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;
Expand Down
2 changes: 1 addition & 1 deletion tasks/Mainnet low gas warning/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"cron": "0 * * * *",
"type": "schedule"
},
"codeDigest": "pnnTCSfr9L50yOT0+e8RgnFGjoh1lCv8i+pNwOkNOYs=",
"codeDigest": "IQ6xyCSMBZClU2lmQnwhdtj8rM4hwufSABBmLwEo9Sg=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Optimism Child Chain Gauges Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"cron": "*/5 * * * 4",
"type": "schedule"
},
"codeDigest": "5KCDjFsDIAZbsKE9JLv49voQezIMTgbB2tkZvwv8u+g=",
"codeDigest": "LX84UahWbG5f6SX3ai+y0thOEKKar0hF1Q+soOyANS4=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Polygon Child Chain Gauges Checkpointer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "8735c61b-7c5b-48ac-a088-cc727adcb016",
"codeDigest": "FyCzw/61YbnF6uLEELzg0kFwLdpRtW/xF/aKJP7f0+Y=",
"codeDigest": "gsUpBkeWCKuPSgTYkaNw4NRtEyTywZkPBHYnwy/5V78=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Polygon Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "8735c61b-7c5b-48ac-a088-cc727adcb016",
"codeDigest": "0P1iXr5Kjm+uppfPgBTlXFZIHQzMrwvcvq8ZkF4siBQ=",
"codeDigest": "2txiBAU53iftbq5ILdw7vYnv5tA+zlRvYviTdrIouM8=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "2a1aaf2f-30d1-463b-8063-a2f4a67d6bab",
"codeDigest": "Z/kMMBOso+9NQMMo4+ijh9tmTrecQU8tndtdu4zftsM=",
"codeDigest": "qu97iVNRizLF2ZKexiEmtsbTxDYEWBv3OU4sdbkmc8w=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/Polygon ZkEVM Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "2a1aaf2f-30d1-463b-8063-a2f4a67d6bab",
"codeDigest": "uES6Qy0noS8oOedYnLPfuZ2Bofkk1GQnGgYkw+euO+s=",
"codeDigest": "lq2/z/6UEcDb5HZ6JBvzf/bes0Y74xHPMCi6/eIR+S4=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/VeBalFeeInjector Upkeeper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "jtILbuG8s2jsDAUrI0BvnuOlCy8CaSNluzNhLMTXkaw=",
"codeDigest": "ZBd0AAH3M4NzqC11/GEBbodmaIJvsMJnYCVwKUBq2z0=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}
2 changes: 1 addition & 1 deletion tasks/bb-a-WETH Rebalancer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "schedule"
},
"relayerId": "003ec47a-7c81-4572-af06-2943fead4af2",
"codeDigest": "Bh3a11lAc5LKzDFiFtXRjltXUDCkoutCp72VoUNLMP0=",
"codeDigest": "Bklsh2Fe5qxEsxrFgWt5/l1xtn4+WUFD1oFGnWd9Iuc=",
"runtime": "nodejs20.x",
"dependenciesVersion": "v2024-06-13"
}

0 comments on commit 18c207f

Please sign in to comment.