Top up relayer funds from deployer (#642)

* Add fund-relayers-from-deployer.ts

* Add testnet block explorer URLs

* Ensure chain connection props are passed through

* Address pr comments

Co-authored-by: Trevor Porter <trkporter@ucdavis.edu>
pull/651/head
Yorke Rhodes 2 years ago committed by GitHub
parent 460d4cade3
commit e4afb5d872
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 100
      typescript/infra/scripts/fund-relayers-from-deployer.ts
  2. 3
      typescript/infra/scripts/utils.ts
  3. 31
      typescript/infra/src/agents/key-utils.ts
  4. 7
      typescript/sdk/src/chains.ts

@ -0,0 +1,100 @@
import { ethers } from 'ethers';
import { ChainConnection, CompleteChainMap } from '@abacus-network/sdk';
import { AgentKey } from '../src/agents/agent';
import { getRelayerKeys } from '../src/agents/key-utils';
import { getCoreEnvironmentConfig, getEnvironment } from './utils';
const MIN_DELTA = ethers.utils.parseUnits('0.001', 'ether');
const desiredBalancePerChain: CompleteChainMap<string> = {
celo: '0.05',
alfajores: '0.1',
avalanche: '0.1',
fuji: '0.1',
ethereum: '0.1',
kovan: '0.1',
polygon: '1',
mumbai: '0.1',
optimism: '0.05',
optimismkovan: '0.1',
arbitrum: '0.01',
arbitrumrinkeby: '0.1',
bsc: '0.01',
bsctestnet: '0.1',
// unused
goerli: '0',
auroratestnet: '0',
test1: '0',
test2: '0',
test3: '0',
};
async function fundRelayer(
chainConnection: ChainConnection,
relayer: AgentKey,
desiredBalance: string,
) {
const currentBalance = await chainConnection.provider.getBalance(
relayer.address,
);
const desiredBalanceEther = ethers.utils.parseUnits(desiredBalance, 'ether');
const delta = desiredBalanceEther.sub(currentBalance);
if (delta.gt(MIN_DELTA)) {
console.log(
`sending ${relayer.chainName} relayer ${ethers.utils.formatEther(
delta,
)}...`,
);
const tx = await chainConnection.signer!.sendTransaction({
to: relayer.address,
value: delta,
...chainConnection.overrides,
});
console.log(chainConnection.getTxUrl(tx));
await tx.wait(chainConnection.confirmations);
}
console.log(
`${relayer.chainName} relayer : ${ethers.utils.formatEther(
await chainConnection.provider.getBalance(relayer.address),
)}`,
);
}
async function main() {
const environment = await getEnvironment();
const config = getCoreEnvironmentConfig(environment);
const multiProvider = await config.getMultiProvider();
const relayerKeys = getRelayerKeys(config.agent);
const chains = relayerKeys.map((key) => key.chainName!);
for (const chain of chains) {
const chainConnection = multiProvider.getChainConnection(chain);
const desiredBalance = desiredBalancePerChain[chain];
console.group(
chain,
`funder : ${ethers.utils.formatEther(
await chainConnection.signer!.getBalance(),
)} relayer desired : ${desiredBalance}`,
);
for (const relayerKey of relayerKeys.filter(
(key) => key.chainName !== chain,
)) {
await relayerKey.fetch();
await fundRelayer(chainConnection, relayerKey, desiredBalance);
}
console.groupEnd();
}
}
main().catch(console.error);

@ -49,10 +49,9 @@ export async function getMultiProviderFromGCP<Chain extends ChainName>(
const provider = await fetchProvider(environment, chain);
const signer = await fetchSigner(environment, chain, provider);
return {
...config,
provider,
signer,
overrides: config.overrides,
confirmations: config.confirmations,
};
}),
);

@ -27,21 +27,30 @@ export function getKey<Chain extends ChainName>(
}
}
export function getValidatorKeys(
agentConfig: AgentConfig<any>,
): Array<AgentKey> {
// For each chainName, create validatorCount keys
return agentConfig.chainNames.flatMap((chainName) =>
Array(agentConfig.validatorSets[chainName].validators.length).map(
(_, index) =>
getKey(agentConfig, KEY_ROLE_ENUM.Validator, chainName, index),
),
);
}
export function getRelayerKeys(agentConfig: AgentConfig<any>): Array<AgentKey> {
return agentConfig.chainNames.map((chainName) =>
getKey(agentConfig, KEY_ROLE_ENUM.Relayer, chainName),
);
}
export function getAllKeys(agentConfig: AgentConfig<any>): Array<AgentKey> {
return KEY_ROLES.flatMap((role) => {
if (role === KEY_ROLE_ENUM.Validator) {
// For each chainName, create validatorCount keys
return agentConfig.chainNames.flatMap((chainName) =>
[
...Array(
agentConfig.validatorSets[chainName].validators.length,
).keys(),
].map((index) => getKey(agentConfig, role, chainName, index)),
);
return getValidatorKeys(agentConfig);
} else if (role === KEY_ROLE_ENUM.Relayer) {
return agentConfig.chainNames.map((chainName) =>
getKey(agentConfig, role, chainName),
);
return getRelayerKeys(agentConfig);
} else {
return [getKey(agentConfig, role)];
}

@ -71,6 +71,7 @@ export const alfajores: IChainConnection = {
44787,
),
confirmations: 1,
blockExplorerUrl: 'https://alfajores-blockscout.celo-testnet.org/',
};
export const auroratestnet: IChainConnection = {
@ -87,6 +88,7 @@ export const fuji: IChainConnection = {
43113,
),
confirmations: 1,
blockExplorerUrl: 'https://testnet.snowtrace.io/',
};
export const goerli: IChainConnection = {
@ -103,6 +105,7 @@ export const kovan: IChainConnection = {
42,
),
confirmations: 1,
blockExplorerUrl: 'https://kovan.etherscan.io/',
};
export const mumbai: IChainConnection = {
@ -111,6 +114,7 @@ export const mumbai: IChainConnection = {
80001,
),
confirmations: 30,
blockExplorerUrl: 'https://mumbai.polygonscan.com/',
};
export const bsctestnet: IChainConnection = {
@ -119,6 +123,7 @@ export const bsctestnet: IChainConnection = {
97,
),
confirmations: 1,
blockExplorerUrl: 'https://testnet.bscscan.com/',
};
export const arbitrumrinkeby: IChainConnection = {
@ -127,6 +132,7 @@ export const arbitrumrinkeby: IChainConnection = {
421611,
),
confirmations: 1,
blockExplorerUrl: 'https://testnet.arbiscan.io/',
};
export const optimismkovan: IChainConnection = {
@ -135,6 +141,7 @@ export const optimismkovan: IChainConnection = {
69,
),
confirmations: 1,
blockExplorerUrl: 'https://kovan-optimistic.etherscan.io/',
};
export const test1: IChainConnection = {

Loading…
Cancel
Save