|
|
@ -1,16 +1,13 @@ |
|
|
|
import { Console } from 'console'; |
|
|
|
import { Console } from 'console'; |
|
|
|
import { ethers } from 'ethers'; |
|
|
|
import { ethers } from 'ethers'; |
|
|
|
import { Gauge, Pushgateway, Registry } from 'prom-client'; |
|
|
|
import { Gauge, Registry } from 'prom-client'; |
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
import { ChainConnection, CompleteChainMap } from '@abacus-network/sdk'; |
|
|
|
ChainConnection, |
|
|
|
|
|
|
|
ChainName, |
|
|
|
|
|
|
|
CompleteChainMap, |
|
|
|
|
|
|
|
} from '@abacus-network/sdk'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { AgentKey, ReadOnlyAgentKey } from '../../src/agents/agent'; |
|
|
|
import { AgentKey, ReadOnlyAgentKey } from '../../src/agents/agent'; |
|
|
|
import { getRelayerKeys } from '../../src/agents/key-utils'; |
|
|
|
import { getRelayerKeys } from '../../src/agents/key-utils'; |
|
|
|
import { KEY_ROLE_ENUM } from '../../src/agents/roles'; |
|
|
|
import { KEY_ROLE_ENUM } from '../../src/agents/roles'; |
|
|
|
|
|
|
|
import { submitMetrics } from '../../src/utils/metrics'; |
|
|
|
import { readJSONAtPath } from '../../src/utils/utils'; |
|
|
|
import { readJSONAtPath } from '../../src/utils/utils'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
assertEnvironment, |
|
|
|
assertEnvironment, |
|
|
@ -43,12 +40,6 @@ const walletBalanceGauge = new Gauge({ |
|
|
|
}); |
|
|
|
}); |
|
|
|
metricsRegister.registerMetric(walletBalanceGauge); |
|
|
|
metricsRegister.registerMetric(walletBalanceGauge); |
|
|
|
|
|
|
|
|
|
|
|
interface FunderBalance { |
|
|
|
|
|
|
|
chain: ChainName; |
|
|
|
|
|
|
|
address?: string; |
|
|
|
|
|
|
|
balance: number; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Min delta is 1/10 of the desired balance
|
|
|
|
// Min delta is 1/10 of the desired balance
|
|
|
|
const MIN_DELTA_NUMERATOR = ethers.BigNumber.from(1); |
|
|
|
const MIN_DELTA_NUMERATOR = ethers.BigNumber.from(1); |
|
|
|
const MIN_DELTA_DENOMINATOR = ethers.BigNumber.from(10); |
|
|
|
const MIN_DELTA_DENOMINATOR = ethers.BigNumber.from(10); |
|
|
@ -148,8 +139,6 @@ async function main() { |
|
|
|
: getRelayerKeys(agentConfig); |
|
|
|
: getRelayerKeys(agentConfig); |
|
|
|
|
|
|
|
|
|
|
|
const chains = relayerKeys.map((key) => key.chainName!); |
|
|
|
const chains = relayerKeys.map((key) => key.chainName!); |
|
|
|
const balances: FunderBalance[] = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let failureOccurred = false; |
|
|
|
let failureOccurred = false; |
|
|
|
|
|
|
|
|
|
|
|
for (const chain of chains) { |
|
|
|
for (const chain of chains) { |
|
|
@ -183,16 +172,23 @@ async function main() { |
|
|
|
failureOccurred = true; |
|
|
|
failureOccurred = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
balances.push({ |
|
|
|
walletBalanceGauge |
|
|
|
chain, |
|
|
|
.labels({ |
|
|
|
address: funderAddress, |
|
|
|
chain, |
|
|
|
balance: parseFloat( |
|
|
|
wallet_address: funderAddress ?? 'unknown', |
|
|
|
ethers.utils.formatEther(await chainConnection.signer!.getBalance()), |
|
|
|
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) { |
|
|
|
if (failureOccurred) { |
|
|
|
error('At least one failure occurred when funding relayers'); |
|
|
|
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); |
|
|
|
.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) { |
|
|
|
function log(message: string, data?: any) { |
|
|
|
logWithFunction(console.log, message, data); |
|
|
|
logWithFunction(console.log, message, data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function warn(message: string, data?: any) { |
|
|
|
// function warn(message: string, data?: any) {
|
|
|
|
logWithFunction(console.warn, message, data); |
|
|
|
// logWithFunction(console.warn, message, data);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
function error(message: string, data?: any) { |
|
|
|
function error(message: string, data?: any) { |
|
|
|
logWithFunction(console.error, message, data); |
|
|
|
logWithFunction(console.error, message, data); |
|
|
|