Skip to content

refactor(contract_manager): support batch set fee proposal #2405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions contract_manager/scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const COMMON_DEPLOY_OPTIONS = {
},
chain: {
type: "array",
string: true,
demandOption: true,
desc: "Chains to upload the contract on. Must be one of the chains available in the store",
},
Expand Down Expand Up @@ -207,22 +208,6 @@ export function findEntropyContract(chain: EvmChain): EvmEntropyContract {
throw new Error(`Entropy contract not found for chain ${chain.getId()}`);
}

/**
* Finds an EVM chain by its name.
* @param {string} chainName The name of the chain to find.
* @returns The EVM chain instance.
* @throws {Error} an error if the chain is not found or is not an EVM chain.
*/
export function findEvmChain(chainName: string): EvmChain {
const chain = DefaultStore.chains[chainName];
if (!chain) {
throw new Error(`Chain ${chainName} not found`);
} else if (!(chain instanceof EvmChain)) {
throw new Error(`Chain ${chainName} is not an EVM chain`);
}
return chain;
}

/**
* Finds the wormhole contract for a given EVM chain.
* @param {EvmChain} chain The EVM chain to find the wormhole contract for.
Expand Down
29 changes: 10 additions & 19 deletions contract_manager/scripts/deploy_evm_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,16 @@ const parser = yargs(hideBin(process.argv))
async function main() {
const argv = await parser.argv;

const chain = DefaultStore.chains[argv.chain];

if (!chain) {
throw new Error(`Chain ${argv.contract} not found`);
}

if (chain instanceof EvmChain) {
const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
const address = await chain.deploy(
toPrivateKey(argv["private-key"]),
artifact["abi"],
artifact["bytecode"],
argv["deploy-args"] || []
);

console.log(`Deployed contract at ${address}`);
} else {
throw new Error("Chain is not an EVM chain");
}
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
const address = await chain.deploy(
toPrivateKey(argv["private-key"]),
artifact["abi"],
artifact["bytecode"],
argv["deploy-args"] || []
);

console.log(`Deployed contract at ${address}`);
}

main();
8 changes: 1 addition & 7 deletions contract_manager/scripts/deploy_evm_entropy_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ async function topupAccountsIfNecessary(
async function main() {
const argv = await parser.argv;

const chainName = argv.chain;
const chain = DefaultStore.chains[chainName];
if (!chain) {
throw new Error(`Chain ${chainName} not found`);
} else if (!(chain instanceof EvmChain)) {
throw new Error(`Chain ${chainName} is not an EVM chain`);
}
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);

const deploymentConfig: DeploymentConfig = {
type: toDeploymentType(argv.deploymentType),
Expand Down
7 changes: 1 addition & 6 deletions contract_manager/scripts/deploy_evm_pricefeed_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ async function main() {
const chainNames = argv.chain;

for (const chainName of chainNames) {
const chain = DefaultStore.chains[chainName];
if (!chain) {
throw new Error(`Chain ${chainName} not found`);
} else if (!(chain instanceof EvmChain)) {
throw new Error(`Chain ${chainName} is not an EVM chain`);
}
const chain = DefaultStore.getChainOrThrow(chainName, EvmChain);

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

Expand Down
10 changes: 3 additions & 7 deletions contract_manager/scripts/entropy_debug_reveal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { toPrivateKey } from "../src";
import {
COMMON_DEPLOY_OPTIONS,
findEntropyContract,
findEvmChain,
} from "./common";
import { DefaultStore, EvmChain, toPrivateKey } from "../src";
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";

const parser = yargs(hideBin(process.argv))
.usage(
Expand All @@ -29,7 +25,7 @@ const parser = yargs(hideBin(process.argv))

async function main() {
const argv = await parser.argv;
const chain = findEvmChain(argv.chain);
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
const contract = findEntropyContract(chain);
const sequenceNumber = argv.sequenceNumber;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- chainName: aurora
fee: 3
exponent: 12
- chainName: avalanche
fee: 25
exponent: 13
- chainName: conflux_espace
fee: 1
exponent: 17
- chainName: cronos
fee: 6
exponent: 16
- chainName: meter
fee: 2
exponent: 16
- chainName: ronin
fee: 1
exponent: 15
- chainName: sei_evm_mainnet
fee: 1
exponent: 16
- chainName: shimmer
fee: 1
exponent: 18
63 changes: 42 additions & 21 deletions contract_manager/scripts/generate_governance_set_fee_payload.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { DefaultStore } from "../src";
import { Chain } from "../src/chains";
import { DefaultStore, loadHotWallet } from "../src";
import { readFileSync } from "fs";
import { parse } from "yaml";

const parser = yargs(hideBin(process.argv))
.usage("Usage: $0 --chain <chain_id> --fee <fee> --exponent <exponent>")
.usage("Usage: $0 --config <path/to/config.yaml>")
.options({
chain: {
"config-path": {
type: "string",
demandOption: true,
desc: "Chain for which to generate the Set Fee payload",
desc: "Path to the config file",
},
fee: {
type: "number",
"ops-key-path": {
type: "string",
demandOption: true,
desc: "The new fee to set",
desc: "Path to the ops key file",
},
exponent: {
type: "number",
demandOption: true,
desc: "The new fee exponent to set",
vault: {
type: "string",
default: "mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj",
desc: "Vault ID",
},
});

async function main() {
const { chain, fee, exponent } = await parser.argv;
const {
"config-path": configPath,
"ops-key-path": opsKeyPath,
vault: vaultId,
} = await parser.argv;

const config = parse(readFileSync(configPath, "utf8"));

const updatePayloads: Buffer[] = [];
for (const setFeeEntry of config) {
const chain = DefaultStore.getChainOrThrow(setFeeEntry.chainName);
const payload = chain.generateGovernanceSetFeePayload(
setFeeEntry.fee,
setFeeEntry.exponent
);
updatePayloads.push(payload);
console.log(
`Generated payload for chain ${setFeeEntry.chainName}:`,
payload.toString("hex")
);
}

const vault = DefaultStore.vaults[vaultId];

const chain_obj = DefaultStore.chains[chain];
if (!chain_obj) {
throw new Error(`Chain with ID '${chain}' does not exist.`);
if (!vault) {
throw new Error(`Vault with ID '${vaultId}' does not exist.`);
}

const payload = chain_obj.generateGovernanceSetFeePayload(fee, exponent);
console.log(
`Generated payload for chain ${chain_obj}:`,
payload.toString("hex")
);
const keypair = await loadHotWallet(opsKeyPath);
vault.connect(keypair);
const proposal = await vault.proposeWormholeMessage(updatePayloads);
console.log("Proposal address:", proposal.address.toBase58());
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ async function main() {
const argv = await parser.argv;

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

const vault =
DefaultStore.vaults[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ async function main() {
const wormholeChainName = toChainName(chainId);

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

const vault =
DefaultStore.vaults[
Expand Down
10 changes: 3 additions & 7 deletions contract_manager/scripts/latency_entropy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { toPrivateKey } from "../src";
import {
COMMON_DEPLOY_OPTIONS,
findEntropyContract,
findEvmChain,
} from "./common";
import { DefaultStore, EvmChain, toPrivateKey } from "../src";
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";

const parser = yargs(hideBin(process.argv))
.usage(
Expand All @@ -24,7 +20,7 @@ const parser = yargs(hideBin(process.argv))

async function main() {
const argv = await parser.argv;
const chain = findEvmChain(argv.chain);
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
const contract = findEntropyContract(chain);

const provider = await contract.getDefaultProvider();
Expand Down
10 changes: 3 additions & 7 deletions contract_manager/scripts/latency_entropy_with_callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import {
DefaultStore,
EvmChain,
EvmEntropyContract,
PrivateKey,
toPrivateKey,
} from "../src";
import {
COMMON_DEPLOY_OPTIONS,
findEntropyContract,
findEvmChain,
} from "./common";
import Web3 from "web3";
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";

const parser = yargs(hideBin(process.argv))
.usage(
Expand Down Expand Up @@ -111,7 +107,7 @@ async function main() {
}
}
} else if (argv.chain) {
const chain = findEvmChain(argv.chain);
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
const contract = findEntropyContract(chain);
await testLatency(contract, privateKey);
}
Expand Down
12 changes: 11 additions & 1 deletion contract_manager/scripts/list_entropy_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ const parser = yargs(hideBin(process.argv))

async function main() {
const argv = await parser.argv;
const entries = [];
const entries: {
chain: string;
contract: string;
provider: string;
feeManager: string;
balance: string;
keeperBalance: string;
seq: string;
version: string;
}[] = [];

const keeperAddress =
ENTROPY_DEFAULT_KEEPER[argv.testnet ? "testnet" : "mainnet"];
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
Expand Down
6 changes: 5 additions & 1 deletion contract_manager/scripts/list_evm_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const parser = yargs(hideBin(process.argv))

async function main() {
const argv = await parser.argv;
const entries = [];
const entries: {
chain: string;
contract: string;
version: string;
}[] = [];
for (const contract of Object.values(DefaultStore.contracts)) {
if (contract.getChain().isMainnet() === argv.testnet) continue;
if (contract instanceof EvmPriceFeedContract) {
Expand Down
7 changes: 6 additions & 1 deletion contract_manager/scripts/list_wormhole_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const parser = yargs(hideBin(process.argv))

async function main() {
const argv = await parser.argv;
const entries = [];
const entries: {
chain: string;
contract: string;
guardianSetIndex: number;
chainId: number;
}[] = [];
for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
if (
contract instanceof EvmWormholeContract &&
Expand Down
19 changes: 5 additions & 14 deletions contract_manager/scripts/load_test_entropy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import {
DefaultStore,
EvmEntropyContract,
PrivateKey,
toPrivateKey,
} from "../src";
import {
COMMON_DEPLOY_OPTIONS,
findEntropyContract,
findEvmChain,
} from "./common";
import { DefaultStore, EvmChain, toPrivateKey } from "../src";
import { COMMON_DEPLOY_OPTIONS, findEntropyContract } from "./common";
import Web3 from "web3";

const parser = yargs(hideBin(process.argv))
Expand All @@ -23,12 +14,12 @@ const parser = yargs(hideBin(process.argv))
chain: {
type: "string",
demandOption: true,
desc: "test latency for the contract on this chain",
desc: "Chain to load test the entropy contract on",
},
"tester-address": {
type: "string",
demandOption: true,
desc: "Tester contract address",
desc: "Address of the EntropyTester contract",
},
"success-count": {
type: "number",
Expand Down Expand Up @@ -72,7 +63,7 @@ const ABI = [
async function main() {
const argv = await parser.argv;
const privateKey = toPrivateKey(argv.privateKey);
const chain = findEvmChain(argv.chain);
const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
const contract = findEntropyContract(chain);
const provider = await contract.getDefaultProvider();
const fee = await contract.getFee(provider);
Expand Down
Loading
Loading