Skip to content

Commit c0478a2

Browse files
authored
refactor(contract_manager): support batch set fee proposal (#2405)
* refactor(contract_manager): support batch set fee proposal * refactor scripts
1 parent c70c7f8 commit c0478a2

17 files changed

+145
-115
lines changed

contract_manager/scripts/common.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const COMMON_DEPLOY_OPTIONS = {
7878
},
7979
chain: {
8080
type: "array",
81+
string: true,
8182
demandOption: true,
8283
desc: "Chains to upload the contract on. Must be one of the chains available in the store",
8384
},
@@ -207,22 +208,6 @@ export function findEntropyContract(chain: EvmChain): EvmEntropyContract {
207208
throw new Error(`Entropy contract not found for chain ${chain.getId()}`);
208209
}
209210

210-
/**
211-
* Finds an EVM chain by its name.
212-
* @param {string} chainName The name of the chain to find.
213-
* @returns The EVM chain instance.
214-
* @throws {Error} an error if the chain is not found or is not an EVM chain.
215-
*/
216-
export function findEvmChain(chainName: string): EvmChain {
217-
const chain = DefaultStore.chains[chainName];
218-
if (!chain) {
219-
throw new Error(`Chain ${chainName} not found`);
220-
} else if (!(chain instanceof EvmChain)) {
221-
throw new Error(`Chain ${chainName} is not an EVM chain`);
222-
}
223-
return chain;
224-
}
225-
226211
/**
227212
* Finds the wormhole contract for a given EVM chain.
228213
* @param {EvmChain} chain The EVM chain to find the wormhole contract for.

contract_manager/scripts/deploy_evm_contract.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,16 @@ const parser = yargs(hideBin(process.argv))
3333
async function main() {
3434
const argv = await parser.argv;
3535

36-
const chain = DefaultStore.chains[argv.chain];
37-
38-
if (!chain) {
39-
throw new Error(`Chain ${argv.contract} not found`);
40-
}
41-
42-
if (chain instanceof EvmChain) {
43-
const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
44-
const address = await chain.deploy(
45-
toPrivateKey(argv["private-key"]),
46-
artifact["abi"],
47-
artifact["bytecode"],
48-
argv["deploy-args"] || []
49-
);
50-
51-
console.log(`Deployed contract at ${address}`);
52-
} else {
53-
throw new Error("Chain is not an EVM chain");
54-
}
36+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
37+
const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
38+
const address = await chain.deploy(
39+
toPrivateKey(argv["private-key"]),
40+
artifact["abi"],
41+
artifact["bytecode"],
42+
argv["deploy-args"] || []
43+
);
44+
45+
console.log(`Deployed contract at ${address}`);
5546
}
5647

5748
main();

contract_manager/scripts/deploy_evm_entropy_contracts.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ async function topupAccountsIfNecessary(
172172
async function main() {
173173
const argv = await parser.argv;
174174

175-
const chainName = argv.chain;
176-
const chain = DefaultStore.chains[chainName];
177-
if (!chain) {
178-
throw new Error(`Chain ${chainName} not found`);
179-
} else if (!(chain instanceof EvmChain)) {
180-
throw new Error(`Chain ${chainName} is not an EVM chain`);
181-
}
175+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
182176

183177
const deploymentConfig: DeploymentConfig = {
184178
type: toDeploymentType(argv.deploymentType),

contract_manager/scripts/deploy_evm_pricefeed_contracts.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ async function main() {
111111
const chainNames = argv.chain;
112112

113113
for (const chainName of chainNames) {
114-
const chain = DefaultStore.chains[chainName];
115-
if (!chain) {
116-
throw new Error(`Chain ${chainName} not found`);
117-
} else if (!(chain instanceof EvmChain)) {
118-
throw new Error(`Chain ${chainName} is not an EVM chain`);
119-
}
114+
const chain = DefaultStore.getChainOrThrow(chainName, EvmChain);
120115

121116
console.log(`Deploying price feed contracts on ${chain.getId()}...`);
122117

contract_manager/scripts/entropy_debug_reveal.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
3-
import { toPrivateKey } from "../src";
4-
import {
5-
COMMON_DEPLOY_OPTIONS,
6-
findEntropyContract,
7-
findEvmChain,
8-
} from "./common";
3+
import { DefaultStore, EvmChain, toPrivateKey } from "../src";
4+
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";
95

106
const parser = yargs(hideBin(process.argv))
117
.usage(
@@ -29,7 +25,7 @@ const parser = yargs(hideBin(process.argv))
2925

3026
async function main() {
3127
const argv = await parser.argv;
32-
const chain = findEvmChain(argv.chain);
28+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
3329
const contract = findEntropyContract(chain);
3430
const sequenceNumber = argv.sequenceNumber;
3531

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- chainName: aurora
2+
fee: 3
3+
exponent: 12
4+
- chainName: avalanche
5+
fee: 25
6+
exponent: 13
7+
- chainName: conflux_espace
8+
fee: 1
9+
exponent: 17
10+
- chainName: cronos
11+
fee: 6
12+
exponent: 16
13+
- chainName: meter
14+
fee: 2
15+
exponent: 16
16+
- chainName: ronin
17+
fee: 1
18+
exponent: 15
19+
- chainName: sei_evm_mainnet
20+
fee: 1
21+
exponent: 16
22+
- chainName: shimmer
23+
fee: 1
24+
exponent: 18
Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,62 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
3-
import { DefaultStore } from "../src";
4-
import { Chain } from "../src/chains";
3+
import { DefaultStore, loadHotWallet } from "../src";
4+
import { readFileSync } from "fs";
5+
import { parse } from "yaml";
56

67
const parser = yargs(hideBin(process.argv))
7-
.usage("Usage: $0 --chain <chain_id> --fee <fee> --exponent <exponent>")
8+
.usage("Usage: $0 --config <path/to/config.yaml>")
89
.options({
9-
chain: {
10+
"config-path": {
1011
type: "string",
1112
demandOption: true,
12-
desc: "Chain for which to generate the Set Fee payload",
13+
desc: "Path to the config file",
1314
},
14-
fee: {
15-
type: "number",
15+
"ops-key-path": {
16+
type: "string",
1617
demandOption: true,
17-
desc: "The new fee to set",
18+
desc: "Path to the ops key file",
1819
},
19-
exponent: {
20-
type: "number",
21-
demandOption: true,
22-
desc: "The new fee exponent to set",
20+
vault: {
21+
type: "string",
22+
default: "mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj",
23+
desc: "Vault ID",
2324
},
2425
});
2526

2627
async function main() {
27-
const { chain, fee, exponent } = await parser.argv;
28+
const {
29+
"config-path": configPath,
30+
"ops-key-path": opsKeyPath,
31+
vault: vaultId,
32+
} = await parser.argv;
33+
34+
const config = parse(readFileSync(configPath, "utf8"));
35+
36+
const updatePayloads: Buffer[] = [];
37+
for (const setFeeEntry of config) {
38+
const chain = DefaultStore.getChainOrThrow(setFeeEntry.chainName);
39+
const payload = chain.generateGovernanceSetFeePayload(
40+
setFeeEntry.fee,
41+
setFeeEntry.exponent
42+
);
43+
updatePayloads.push(payload);
44+
console.log(
45+
`Generated payload for chain ${setFeeEntry.chainName}:`,
46+
payload.toString("hex")
47+
);
48+
}
49+
50+
const vault = DefaultStore.vaults[vaultId];
2851

29-
const chain_obj = DefaultStore.chains[chain];
30-
if (!chain_obj) {
31-
throw new Error(`Chain with ID '${chain}' does not exist.`);
52+
if (!vault) {
53+
throw new Error(`Vault with ID '${vaultId}' does not exist.`);
3254
}
3355

34-
const payload = chain_obj.generateGovernanceSetFeePayload(fee, exponent);
35-
console.log(
36-
`Generated payload for chain ${chain_obj}:`,
37-
payload.toString("hex")
38-
);
56+
const keypair = await loadHotWallet(opsKeyPath);
57+
vault.connect(keypair);
58+
const proposal = await vault.proposeWormholeMessage(updatePayloads);
59+
console.log("Proposal address:", proposal.address.toBase58());
3960
}
4061

4162
main();

contract_manager/scripts/generate_upgrade_near_contract_proposal.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ async function main() {
3131
const argv = await parser.argv;
3232

3333
// Near wormhole contracts have the same id on testnet and mainnet.
34-
const chain = DefaultStore.chains.near;
35-
if (!(chain instanceof NearChain)) {
36-
throw new Error("Near chain is missing");
37-
}
34+
const chain = DefaultStore.getChainOrThrow("near", NearChain);
3835

3936
const vault =
4037
DefaultStore.vaults[

contract_manager/scripts/generate_upgrade_ton_contract_proposal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ async function main() {
4242
const wormholeChainName = toChainName(chainId);
4343

4444
// Get the TON chain instance from DefaultStore based on network
45-
const chain = DefaultStore.chains[isMainnet ? "ton_mainnet" : "ton_testnet"];
46-
if (!chain || !(chain instanceof TonChain)) {
47-
throw new Error(`Chain configuration not found for TON ${argv.network}`);
48-
}
45+
const chain = DefaultStore.getChainOrThrow(
46+
isMainnet ? "ton_mainnet" : "ton_testnet",
47+
TonChain
48+
);
4949

5050
const vault =
5151
DefaultStore.vaults[

contract_manager/scripts/latency_entropy.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
3-
import { toPrivateKey } from "../src";
4-
import {
5-
COMMON_DEPLOY_OPTIONS,
6-
findEntropyContract,
7-
findEvmChain,
8-
} from "./common";
3+
import { DefaultStore, EvmChain, toPrivateKey } from "../src";
4+
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";
95

106
const parser = yargs(hideBin(process.argv))
117
.usage(
@@ -24,7 +20,7 @@ const parser = yargs(hideBin(process.argv))
2420

2521
async function main() {
2622
const argv = await parser.argv;
27-
const chain = findEvmChain(argv.chain);
23+
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
2824
const contract = findEntropyContract(chain);
2925

3026
const provider = await contract.getDefaultProvider();

0 commit comments

Comments
 (0)