Skip to content

Commit

Permalink
fix(contract_manager): top up keeper balance when deploying (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m authored Jun 7, 2024
1 parent caf68f1 commit ed4778c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
64 changes: 35 additions & 29 deletions contract_manager/scripts/deploy_evm_entropy_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { EvmChain } from "../src/chains";
import { DefaultStore } from "../src/store";
import {
DeploymentType,
ENTROPY_DEFAULT_KEEPER,
ENTROPY_DEFAULT_PROVIDER,
EvmEntropyContract,
getDefaultDeploymentConfig,
toDeploymentType,
Expand All @@ -24,10 +26,6 @@ interface DeploymentConfig extends BaseDeployConfig {
}

const CACHE_FILE = ".cache-deploy-evm-entropy-contracts";
const ENTROPY_DEFAULT_PROVIDER = {
mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506",
testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344",
};

const parser = yargs(hideBin(process.argv))
.scriptName("deploy_evm_entropy_contracts.ts")
Expand Down Expand Up @@ -125,34 +123,42 @@ async function deployEntropyContracts(
);
}

async function topupProviderIfNecessary(
async function topupAccountsIfNecessary(
chain: EvmChain,
deploymentConfig: DeploymentConfig
) {
const provider = chain.isMainnet()
? ENTROPY_DEFAULT_PROVIDER.mainnet
: ENTROPY_DEFAULT_PROVIDER.testnet;
const web3 = new Web3(chain.getRpcUrl());
const balance = Number(
web3.utils.fromWei(await web3.eth.getBalance(provider), "ether")
);
const MIN_BALANCE = 0.01;
console.log(`Provider balance: ${balance} ETH`);
if (balance < MIN_BALANCE) {
console.log(
`Balance is less than ${MIN_BALANCE}. Topping up the provider address...`
);
const signer = web3.eth.accounts.privateKeyToAccount(
deploymentConfig.privateKey
for (const [accountName, defaultAddresses] of [
["keeper", ENTROPY_DEFAULT_KEEPER],
["provider", ENTROPY_DEFAULT_PROVIDER],
] as const) {
const accountAddress = chain.isMainnet()
? defaultAddresses.mainnet
: defaultAddresses.testnet;
const web3 = new Web3(chain.getRpcUrl());
const balance = Number(
web3.utils.fromWei(await web3.eth.getBalance(accountAddress), "ether")
);
web3.eth.accounts.wallet.add(signer);
const tx = await web3.eth.sendTransaction({
from: signer.address,
to: provider,
gas: 30000,
value: web3.utils.toWei(`${MIN_BALANCE}`, "ether"),
});
console.log("Topped up the provider address. Tx: ", tx.transactionHash);
const MIN_BALANCE = 0.01;
console.log(`${accountName} balance: ${balance} ETH`);
if (balance < MIN_BALANCE) {
console.log(
`Balance is less than ${MIN_BALANCE}. Topping up the ${accountName} address...`
);
const signer = web3.eth.accounts.privateKeyToAccount(
deploymentConfig.privateKey
);
web3.eth.accounts.wallet.add(signer);
const tx = await web3.eth.sendTransaction({
from: signer.address,
to: accountAddress,
gas: 30000,
value: web3.utils.toWei(`${MIN_BALANCE}`, "ether"),
});
console.log(
`Topped up the ${accountName} address. Tx: `,
tx.transactionHash
);
}
}
}

Expand Down Expand Up @@ -182,7 +188,7 @@ async function main() {
CACHE_FILE
);

await topupProviderIfNecessary(chain, deploymentConfig);
await topupAccountsIfNecessary(chain, deploymentConfig);

console.log(
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n`
Expand Down
11 changes: 4 additions & 7 deletions contract_manager/scripts/list_entropy_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { DefaultStore } from "../src";
import { DefaultStore, ENTROPY_DEFAULT_KEEPER } from "../src";
import Web3 from "web3";

const parser = yargs(hideBin(process.argv))
Expand All @@ -13,15 +13,11 @@ const parser = yargs(hideBin(process.argv))
},
});

const KEEPER_ADDRESS = {
mainnet: "0xBcAb779fCa45290288C35F5E231c37F9fA87b130",
testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df",
};

async function main() {
const argv = await parser.argv;
const entries = [];
const keeperAddress = KEEPER_ADDRESS[argv.testnet ? "testnet" : "mainnet"];
const keeperAddress =
ENTROPY_DEFAULT_KEEPER[argv.testnet ? "testnet" : "mainnet"];
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
if (contract.getChain().isMainnet() === argv.testnet) continue;
try {
Expand All @@ -40,6 +36,7 @@ async function main() {
chain: contract.getChain().getId(),
contract: contract.address,
provider: providerInfo.uri,
feeManager: providerInfo.feeManager,
balance: Web3.utils.fromWei(balance),
keeperBalance: Web3.utils.fromWei(keeperBalance),
seq: providerInfo.sequenceNumber,
Expand Down
10 changes: 10 additions & 0 deletions contract_manager/src/contracts/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ interface EntropyProviderInfo {
sequenceNumber: string;
currentCommitment: string;
currentCommitmentSequenceNumber: string;
feeManager: string;
}

interface EntropyRequest {
Expand All @@ -500,6 +501,15 @@ interface EntropyRequest {
isRequestWithCallback: boolean;
}

export const ENTROPY_DEFAULT_PROVIDER = {
mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506",
testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344",
};
export const ENTROPY_DEFAULT_KEEPER = {
mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130",
testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df",
};

export class EvmEntropyContract extends Storable {
static type = "EvmEntropyContract";

Expand Down

0 comments on commit ed4778c

Please sign in to comment.