Skip to content

Commit 935c6d1

Browse files
committed
refactor scripts
1 parent b6c661a commit 935c6d1

18 files changed

+105
-124
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_cosmwasm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function main() {
3434
const argv = await parser.argv;
3535
const { code, wormholeContract } = argv;
3636
console.log(
37-
await CosmWasmPriceFeedContract.deploy(
37+
await CosmWasmChain.deploy(
3838
DefaultStore.chains[argv.chain] as CosmWasmChain,
3939
wormholeContract,
4040
argv["private-key"],

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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
- name: aurora
1+
- chainName: aurora
22
fee: 3
33
exponent: 12
4-
- name: avalanche
4+
- chainName: avalanche
55
fee: 25
66
exponent: 13
7-
- name: conflux_espace
7+
- chainName: conflux_espace
88
fee: 1
99
exponent: 17
10-
- name: cronos
10+
- chainName: cronos
1111
fee: 6
1212
exponent: 16
13-
- name: meter
13+
- chainName: meter
1414
fee: 2
1515
exponent: 16
16-
- name: ronin
16+
- chainName: ronin
1717
fee: 1
1818
exponent: 15
19-
- name: sei_evm_mainnet
19+
- chainName: sei_evm_mainnet
2020
fee: 1
2121
exponent: 16
22-
- name: shimmer
22+
- chainName: shimmer
2323
fee: 1
2424
exponent: 18

contract_manager/scripts/generate_governance_set_fee_payload.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parse } from "yaml";
77
const parser = yargs(hideBin(process.argv))
88
.usage("Usage: $0 --config <path/to/config.yaml>")
99
.options({
10-
config: {
10+
"config-path": {
1111
type: "string",
1212
demandOption: true,
1313
desc: "Path to the config file",
@@ -26,40 +26,36 @@ const parser = yargs(hideBin(process.argv))
2626

2727
async function main() {
2828
const {
29-
config,
30-
"ops-key-path": ops_key_path,
31-
vault: vault_id,
29+
"config-path": configPath,
30+
"ops-key-path": opsKeyPath,
31+
vault: vaultId,
3232
} = await parser.argv;
3333

34-
const config_obj = parse(readFileSync(config, "utf8"));
34+
const config = parse(readFileSync(configPath, "utf8"));
3535

36-
let update_payloads: Buffer[] = [];
37-
for (const chain of config_obj) {
38-
const chain_obj = DefaultStore.chains[chain.name];
39-
if (!chain_obj) {
40-
throw new Error(`Chain with ID '${chain.name}' does not exist.`);
41-
}
42-
43-
const payload = chain_obj.generateGovernanceSetFeePayload(
44-
chain.fee,
45-
chain.exponent
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
4642
);
47-
update_payloads.push(payload);
43+
updatePayloads.push(payload);
4844
console.log(
49-
`Generated payload for chain ${chain.name}:`,
45+
`Generated payload for chain ${setFeeEntry.chainName}:`,
5046
payload.toString("hex")
5147
);
5248
}
5349

54-
const vault = DefaultStore.vaults[vault_id];
50+
const vault = DefaultStore.vaults[vaultId];
5551

5652
if (!vault) {
57-
throw new Error(`Vault with ID '${vault_id}' does not exist.`);
53+
throw new Error(`Vault with ID '${vaultId}' does not exist.`);
5854
}
5955

60-
const keypair = await loadHotWallet(ops_key_path);
56+
const keypair = await loadHotWallet(opsKeyPath);
6157
vault.connect(keypair);
62-
const proposal = await vault.proposeWormholeMessage(update_payloads);
58+
const proposal = await vault.proposeWormholeMessage(updatePayloads);
6359
console.log("Proposal address:", proposal.address.toBase58());
6460
}
6561

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[

0 commit comments

Comments
 (0)