Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: monitoring flow limit updates [AXE-2551] #109

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const axios = require('axios').default;
const { ethers } = require('ethers');

const PAGER_DUTY_ALERT_URL = 'https://events.pagerduty.com/v2/enqueue';
const Severity = {
INFO: 'info',
CRITICAL: 'critical',
WARNING: 'warning',
1: 'info',
2: 'warning',
};
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

const flowLimitUpdateFn = async (context, event) => {
if (!event || !event.logs || !context || !context.metadata) {
throw new Error('INVALID_INPUT_FOR_ACTION');
}

const { flowLimitSet } = await context.storage.getJson('EventsABI');
const flowLimitSetHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(flowLimitSet));

const itsAddresses = await context.storage.getJson('ITSAddresses');
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

let severity = 0;
const tokenIDs = [];
const tokenManagers = [];
const operators = [];

for (const log of event.logs) {
if (log.topics[0] === flowLimitSetHash) {
console.log(`event emitted: ${flowLimitSet}`);

if (log.topics.length < 2) {
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('INVALID_LOG_TOPICS_LENGTH');
}

if (log.data.length < 66) {
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('INVALID_LOG_DATA_LENGTH');
}

// log data contains address in first 32 bytes i.e. first 64 chars, here data string is also prefixed with 0x.
const operatorAddress = '0x' + log.data.substring(26, 66);
const tempSeverity = itsAddresses.includes(operatorAddress.toLowerCase()) ? 1 : 2;

if (tempSeverity > severity) {
severity = tempSeverity;
}

tokenIDs.push(log.topics[1]);
tokenManagers.push(log.address);
operators.push(operatorAddress);
}
}

if (severity) {
try {
await axios.post(
PAGER_DUTY_ALERT_URL,
{
routing_key: await context.secrets.get('PD_ROUTING_KEY'),
event_action: 'trigger',
payload: {
summary: 'Flow limit updated',
source: 'ITS',
severity: Severity[severity],
custom_details: {
timestamp: Date.now(),
chain_name: context.metadata.getNetwork(),
trigger_event: event,
token_ids: tokenIDs,
token_managers: tokenManagers,
operators,
},
},
},
{
'Content-Type': 'application/json',
},
);
} catch (error) {
console.log('PD error status: ', error.response.status);
console.log('PD error data: ', error.response.data);
throw Error('SENDING_ALERTS_FAILED');
}
} else {
throw new Error('NO_FLOW_LIMIT_UPDATES_DETECTED');
}
};

module.exports = { flowLimitUpdateFn };
13 changes: 13 additions & 0 deletions tenderly-suite/flow-limit-update/tenderly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
account_id: "axelarEng"
actions:
axelareng/its:
runtime: v2
sources: flow-limit-update
specs:
flow-limit-update:
description: This action sends alerts to pagerduty based on operator's address updating them.
function: flowLimitUpdate:flowLimitUpdateFn
trigger:
type: transaction
execution_type: sequential
project_slug: "ITS"
Loading