UNPKG

@eth-optimism/balance-monitor

Version:

[Optimism] Forta Agent that reports whether certain accounts have fallen below some balance

45 lines 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.heartBeat = exports.createAlert = exports.describeFinding = void 0; const ethers_1 = require("ethers"); const node_fetch_1 = __importDefault(require("node-fetch")); const describeFinding = (account, actual, threshold) => { return `Balance of account ${account} is (${ethers_1.ethers.utils.formatEther(actual)} eth) below threshold (${ethers_1.ethers.utils.formatEther(threshold)} eth)`; }; exports.describeFinding = describeFinding; const createAlert = async (alertOpts) => { const response = await (0, node_fetch_1.default)('https://api.opsgenie.com/v2/alerts', { method: 'post', body: JSON.stringify({ message: alertOpts.message, alias: alertOpts.alias, responders: [{ id: process.env.OPS_GENIE_TEAM, type: 'team' }], tags: ['Bedrock-Beta', 'Balance-Low'], priority: 'P2', }), headers: { 'Content-type': 'application/json', Authorization: `GenieKey ${process.env.OPS_GENIE_KEY}`, }, }); if (!response.ok) { console.log(`Error creating alert: ${JSON.stringify(response.body)}`); } }; exports.createAlert = createAlert; const heartBeat = async () => { const response = await (0, node_fetch_1.default)(`https://api.opsgenie.com/v2/heartbeats/${process.env.OPS_GENIE_HEARTBEAT_NAME}/ping`, { method: 'get', headers: { Authorization: `GenieKey ${process.env.OPS_GENIE_KEY}`, }, }); if (!response.ok) { console.log(`Error creating alert: ${JSON.stringify(response.body)}`); } }; exports.heartBeat = heartBeat; //# sourceMappingURL=utils.js.map