From f0551b629e8e7f660e20f9f9ad704a11150c0e86 Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Mon, 18 Mar 2024 17:32:01 +0000 Subject: [PATCH] Hacky solana balance monitoring (#3432) ### Description - See https://github.com/hyperlane-xyz/issues/issues/1047 - Intentionally going with a "hacky" short term approach because we consistently hit this, we're unlikely to prioritize a better solution for v3, and this change is only for v2 which we are in maintenance-only mode, so it's ok to hardcode these accounts ### Drive-by changes - New monorepo base image to fix building, which requires node 18 apparently ### Related issues ### Backward compatibility ### Testing --- Dockerfile | 2 +- .../config/environments/mainnet2/funding.ts | 2 +- .../funding/fund-keys-from-deployer.ts | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3b9b30b71a..ec3c51ce6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16-alpine +FROM node:18-alpine WORKDIR /hyperlane-monorepo diff --git a/typescript/infra/config/environments/mainnet2/funding.ts b/typescript/infra/config/environments/mainnet2/funding.ts index 22b7e95abc..d25145a6e2 100644 --- a/typescript/infra/config/environments/mainnet2/funding.ts +++ b/typescript/infra/config/environments/mainnet2/funding.ts @@ -9,7 +9,7 @@ import { environment } from './chains'; export const keyFunderConfig: KeyFunderConfig = { docker: { repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo', - tag: '98658d0-20231207-121541', + tag: '4798278-20240318-115942', }, // We're currently using the same deployer key as mainnet. // To minimize nonce clobbering we offset the key funder cron diff --git a/typescript/infra/scripts/funding/fund-keys-from-deployer.ts b/typescript/infra/scripts/funding/fund-keys-from-deployer.ts index a319f05f63..37ec1ff8cd 100644 --- a/typescript/infra/scripts/funding/fund-keys-from-deployer.ts +++ b/typescript/infra/scripts/funding/fund-keys-from-deployer.ts @@ -1,4 +1,5 @@ import { EthBridger, getL2Network } from '@arbitrum/sdk'; +import { Connection, PublicKey } from '@solana/web3.js'; import { BigNumber, ethers } from 'ethers'; import { Gauge, Registry } from 'prom-client'; import { format } from 'util'; @@ -21,6 +22,7 @@ import { } from '@hyperlane-xyz/utils'; import { Contexts } from '../../config/contexts'; +import { getSecretRpcEndpoint } from '../../src/agents'; import { KeyAsAddress, getRoleKeysPerChain } from '../../src/agents/key-utils'; import { BaseCloudAgentKey, @@ -431,6 +433,14 @@ class ContextFunder { const failure = await this.attemptToFundKey(key, chain); failureOccurred ||= failure; } + + if ( + this.environment === 'mainnet2' && + this.context === Contexts.Hyperlane + ) { + this.updateSolanaWalletBalanceGauge(); + } + return failureOccurred; }); @@ -709,6 +719,54 @@ class ContextFunder { ), ); } + + private async updateSolanaWalletBalanceGauge() { + const chain = 'solana'; + + const solanaRpcUrls = await getSecretRpcEndpoint( + this.environment, + chain, + false, + ); + const solanaProvider = new Connection(solanaRpcUrls[0], 'confirmed'); + const accounts = [ + { + // The Solana relayer + pubkey: new PublicKey('CLT7m1JBCqJx6FM3obi9ohTnML1zmdzFcX2SgWj1D8qV'), + walletName: 'relayer', + }, + { + // The account used to pay for state rent used by new ZBC balances + pubkey: new PublicKey('DRoxXLkV2sAsZb7bPbCJQnucTxvQCcfzfmThC3ZVNorv'), + walletName: 'nautilus-zbc-rent', + }, + ]; + + for (const { pubkey, walletName } of accounts) { + log('Fetching Solana wallet balance', { + chain, + pubkey: pubkey.toString(), + walletName, + }); + const balance = await solanaProvider.getBalance(pubkey); + log('Got Solana wallet balance', { + balance, + chain, + pubkey: pubkey.toString(), + walletName, + }); + walletBalanceGauge + .labels({ + chain, + wallet_address: pubkey.toString(), + wallet_name: walletName, + token_symbol: 'Native', + token_name: 'Native', + ...constMetricLabels, + }) + .set(balance / 1e9); + } + } } async function getAddressInfo(