Skip to content

Commit ed4778c

Browse files
authored
fix(contract_manager): top up keeper balance when deploying (#1666)
1 parent caf68f1 commit ed4778c

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

contract_manager/scripts/deploy_evm_entropy_contracts.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { EvmChain } from "../src/chains";
44
import { DefaultStore } from "../src/store";
55
import {
66
DeploymentType,
7+
ENTROPY_DEFAULT_KEEPER,
8+
ENTROPY_DEFAULT_PROVIDER,
79
EvmEntropyContract,
810
getDefaultDeploymentConfig,
911
toDeploymentType,
@@ -24,10 +26,6 @@ interface DeploymentConfig extends BaseDeployConfig {
2426
}
2527

2628
const CACHE_FILE = ".cache-deploy-evm-entropy-contracts";
27-
const ENTROPY_DEFAULT_PROVIDER = {
28-
mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506",
29-
testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344",
30-
};
3129

3230
const parser = yargs(hideBin(process.argv))
3331
.scriptName("deploy_evm_entropy_contracts.ts")
@@ -125,34 +123,42 @@ async function deployEntropyContracts(
125123
);
126124
}
127125

128-
async function topupProviderIfNecessary(
126+
async function topupAccountsIfNecessary(
129127
chain: EvmChain,
130128
deploymentConfig: DeploymentConfig
131129
) {
132-
const provider = chain.isMainnet()
133-
? ENTROPY_DEFAULT_PROVIDER.mainnet
134-
: ENTROPY_DEFAULT_PROVIDER.testnet;
135-
const web3 = new Web3(chain.getRpcUrl());
136-
const balance = Number(
137-
web3.utils.fromWei(await web3.eth.getBalance(provider), "ether")
138-
);
139-
const MIN_BALANCE = 0.01;
140-
console.log(`Provider balance: ${balance} ETH`);
141-
if (balance < MIN_BALANCE) {
142-
console.log(
143-
`Balance is less than ${MIN_BALANCE}. Topping up the provider address...`
144-
);
145-
const signer = web3.eth.accounts.privateKeyToAccount(
146-
deploymentConfig.privateKey
130+
for (const [accountName, defaultAddresses] of [
131+
["keeper", ENTROPY_DEFAULT_KEEPER],
132+
["provider", ENTROPY_DEFAULT_PROVIDER],
133+
] as const) {
134+
const accountAddress = chain.isMainnet()
135+
? defaultAddresses.mainnet
136+
: defaultAddresses.testnet;
137+
const web3 = new Web3(chain.getRpcUrl());
138+
const balance = Number(
139+
web3.utils.fromWei(await web3.eth.getBalance(accountAddress), "ether")
147140
);
148-
web3.eth.accounts.wallet.add(signer);
149-
const tx = await web3.eth.sendTransaction({
150-
from: signer.address,
151-
to: provider,
152-
gas: 30000,
153-
value: web3.utils.toWei(`${MIN_BALANCE}`, "ether"),
154-
});
155-
console.log("Topped up the provider address. Tx: ", tx.transactionHash);
141+
const MIN_BALANCE = 0.01;
142+
console.log(`${accountName} balance: ${balance} ETH`);
143+
if (balance < MIN_BALANCE) {
144+
console.log(
145+
`Balance is less than ${MIN_BALANCE}. Topping up the ${accountName} address...`
146+
);
147+
const signer = web3.eth.accounts.privateKeyToAccount(
148+
deploymentConfig.privateKey
149+
);
150+
web3.eth.accounts.wallet.add(signer);
151+
const tx = await web3.eth.sendTransaction({
152+
from: signer.address,
153+
to: accountAddress,
154+
gas: 30000,
155+
value: web3.utils.toWei(`${MIN_BALANCE}`, "ether"),
156+
});
157+
console.log(
158+
`Topped up the ${accountName} address. Tx: `,
159+
tx.transactionHash
160+
);
161+
}
156162
}
157163
}
158164

@@ -182,7 +188,7 @@ async function main() {
182188
CACHE_FILE
183189
);
184190

185-
await topupProviderIfNecessary(chain, deploymentConfig);
191+
await topupAccountsIfNecessary(chain, deploymentConfig);
186192

187193
console.log(
188194
`Deployment config: ${JSON.stringify(deploymentConfig, null, 2)}\n`

contract_manager/scripts/list_entropy_contracts.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
3-
import { DefaultStore } from "../src";
3+
import { DefaultStore, ENTROPY_DEFAULT_KEEPER } from "../src";
44
import Web3 from "web3";
55

66
const parser = yargs(hideBin(process.argv))
@@ -13,15 +13,11 @@ const parser = yargs(hideBin(process.argv))
1313
},
1414
});
1515

16-
const KEEPER_ADDRESS = {
17-
mainnet: "0xBcAb779fCa45290288C35F5E231c37F9fA87b130",
18-
testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df",
19-
};
20-
2116
async function main() {
2217
const argv = await parser.argv;
2318
const entries = [];
24-
const keeperAddress = KEEPER_ADDRESS[argv.testnet ? "testnet" : "mainnet"];
19+
const keeperAddress =
20+
ENTROPY_DEFAULT_KEEPER[argv.testnet ? "testnet" : "mainnet"];
2521
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
2622
if (contract.getChain().isMainnet() === argv.testnet) continue;
2723
try {
@@ -40,6 +36,7 @@ async function main() {
4036
chain: contract.getChain().getId(),
4137
contract: contract.address,
4238
provider: providerInfo.uri,
39+
feeManager: providerInfo.feeManager,
4340
balance: Web3.utils.fromWei(balance),
4441
keeperBalance: Web3.utils.fromWei(keeperBalance),
4542
seq: providerInfo.sequenceNumber,

contract_manager/src/contracts/evm.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ interface EntropyProviderInfo {
487487
sequenceNumber: string;
488488
currentCommitment: string;
489489
currentCommitmentSequenceNumber: string;
490+
feeManager: string;
490491
}
491492

492493
interface EntropyRequest {
@@ -500,6 +501,15 @@ interface EntropyRequest {
500501
isRequestWithCallback: boolean;
501502
}
502503

504+
export const ENTROPY_DEFAULT_PROVIDER = {
505+
mainnet: "0x52DeaA1c84233F7bb8C8A45baeDE41091c616506",
506+
testnet: "0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344",
507+
};
508+
export const ENTROPY_DEFAULT_KEEPER = {
509+
mainnet: "0xbcab779fca45290288c35f5e231c37f9fa87b130",
510+
testnet: "0xa5A68ed167431Afe739846A22597786ba2da85df",
511+
};
512+
503513
export class EvmEntropyContract extends Storable {
504514
static type = "EvmEntropyContract";
505515

0 commit comments

Comments
 (0)