|
|
|
@ -1,16 +1,13 @@ |
|
|
|
|
import { Console } from 'console'; |
|
|
|
|
import { ethers } from 'ethers'; |
|
|
|
|
import { Gauge, Pushgateway, Registry } from 'prom-client'; |
|
|
|
|
import { Gauge, Registry } from 'prom-client'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
ChainConnection, |
|
|
|
|
ChainName, |
|
|
|
|
CompleteChainMap, |
|
|
|
|
} from '@abacus-network/sdk'; |
|
|
|
|
import { ChainConnection, CompleteChainMap } from '@abacus-network/sdk'; |
|
|
|
|
|
|
|
|
|
import { AgentKey, ReadOnlyAgentKey } from '../../src/agents/agent'; |
|
|
|
|
import { getRelayerKeys } from '../../src/agents/key-utils'; |
|
|
|
|
import { KEY_ROLE_ENUM } from '../../src/agents/roles'; |
|
|
|
|
import { submitMetrics } from '../../src/utils/metrics'; |
|
|
|
|
import { readJSONAtPath } from '../../src/utils/utils'; |
|
|
|
|
import { |
|
|
|
|
assertEnvironment, |
|
|
|
@ -43,12 +40,6 @@ const walletBalanceGauge = new Gauge({ |
|
|
|
|
}); |
|
|
|
|
metricsRegister.registerMetric(walletBalanceGauge); |
|
|
|
|
|
|
|
|
|
interface FunderBalance { |
|
|
|
|
chain: ChainName; |
|
|
|
|
address?: string; |
|
|
|
|
balance: number; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Min delta is 1/10 of the desired balance
|
|
|
|
|
const MIN_DELTA_NUMERATOR = ethers.BigNumber.from(1); |
|
|
|
|
const MIN_DELTA_DENOMINATOR = ethers.BigNumber.from(10); |
|
|
|
@ -148,8 +139,6 @@ async function main() { |
|
|
|
|
: getRelayerKeys(agentConfig); |
|
|
|
|
|
|
|
|
|
const chains = relayerKeys.map((key) => key.chainName!); |
|
|
|
|
const balances: FunderBalance[] = []; |
|
|
|
|
|
|
|
|
|
let failureOccurred = false; |
|
|
|
|
|
|
|
|
|
for (const chain of chains) { |
|
|
|
@ -183,16 +172,23 @@ async function main() { |
|
|
|
|
failureOccurred = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
balances.push({ |
|
|
|
|
chain, |
|
|
|
|
address: funderAddress, |
|
|
|
|
balance: parseFloat( |
|
|
|
|
ethers.utils.formatEther(await chainConnection.signer!.getBalance()), |
|
|
|
|
), |
|
|
|
|
}); |
|
|
|
|
walletBalanceGauge |
|
|
|
|
.labels({ |
|
|
|
|
chain, |
|
|
|
|
wallet_address: funderAddress ?? 'unknown', |
|
|
|
|
wallet_name: 'relayer-funder', |
|
|
|
|
token_symbol: 'Native', |
|
|
|
|
token_name: 'Native', |
|
|
|
|
...constMetricLabels, |
|
|
|
|
}) |
|
|
|
|
.set( |
|
|
|
|
parseFloat( |
|
|
|
|
ethers.utils.formatEther(await chainConnection.signer!.getBalance()), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await submitFunderBalanceMetrics(balances); |
|
|
|
|
await submitMetrics(metricsRegister); |
|
|
|
|
|
|
|
|
|
if (failureOccurred) { |
|
|
|
|
error('At least one failure occurred when funding relayers'); |
|
|
|
@ -217,53 +213,13 @@ function getRelayerKeysFromSerializedAddressFile(path: string): AgentKey[] { |
|
|
|
|
.filter((key: AgentKey) => key.role === KEY_ROLE_ENUM.Relayer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getPushGateway(): Pushgateway | null { |
|
|
|
|
const gatewayAddr = process.env['PROMETHEUS_PUSH_GATEWAY']; |
|
|
|
|
if (gatewayAddr) { |
|
|
|
|
return new Pushgateway(gatewayAddr, [], metricsRegister); |
|
|
|
|
} else { |
|
|
|
|
warn( |
|
|
|
|
'Prometheus push gateway address was not defined; not publishing metrics.', |
|
|
|
|
); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function submitFunderBalanceMetrics(balances: FunderBalance[]) { |
|
|
|
|
const gateway = getPushGateway(); |
|
|
|
|
if (!gateway) return; |
|
|
|
|
|
|
|
|
|
for (const { chain, address, balance } of balances) { |
|
|
|
|
walletBalanceGauge |
|
|
|
|
.labels({ |
|
|
|
|
chain, |
|
|
|
|
wallet_address: address ?? 'unknown', |
|
|
|
|
wallet_name: 'relayer-funder', |
|
|
|
|
token_symbol: 'Native', |
|
|
|
|
token_name: 'Native', |
|
|
|
|
...constMetricLabels, |
|
|
|
|
}) |
|
|
|
|
.set(balance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const { resp, body } = await gateway.push({ jobName: 'relayer_funder' }); |
|
|
|
|
const statusCode = |
|
|
|
|
typeof resp == 'object' && resp != null && 'statusCode' in resp |
|
|
|
|
? (resp as any).statusCode |
|
|
|
|
: 'unknown'; |
|
|
|
|
log(`Prometheus metrics pushed to PushGateway`, { |
|
|
|
|
statusCode, |
|
|
|
|
body, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function log(message: string, data?: any) { |
|
|
|
|
logWithFunction(console.log, message, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function warn(message: string, data?: any) { |
|
|
|
|
logWithFunction(console.warn, message, data); |
|
|
|
|
} |
|
|
|
|
// function warn(message: string, data?: any) {
|
|
|
|
|
// logWithFunction(console.warn, message, data);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
function error(message: string, data?: any) { |
|
|
|
|
logWithFunction(console.error, message, data); |
|
|
|
|