clients/js: refactor worm info

This commit is contained in:
heyitaki 2023-05-06 09:02:05 +00:00 committed by aki
parent 7bc96a1ebc
commit 4f13263089
31 changed files with 104 additions and 132 deletions

View File

@ -36,9 +36,9 @@ else
usage usage
fi fi
WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core) WORMHOLE_ADDR=$(worm info contract "$NETWORK" aptos Core)
TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge) TOKEN_BRIDGE_ADDR=$(worm info contract "$NETWORK" aptos TokenBridge)
NFT_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos NFTBridge) NFT_BRIDGE_ADDR=$(worm info contract "$NETWORK" aptos NFTBridge)
NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR" NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR"

View File

@ -24,7 +24,7 @@ done
VAAS=$(set | grep "REGISTER_.*_NFT_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1) VAAS=$(set | grep "REGISTER_.*_NFT_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1)
# TODO: this will not be needed when the sdk is published # TODO: this will not be needed when the sdk is published
NFT_BRIDGE_ADDR=$(worm contract devnet aptos NFTBridge) NFT_BRIDGE_ADDR=$(worm info contract devnet aptos NFTBridge)
# 5. use 'worm' to submit each registration VAA # 5. use 'worm' to submit each registration VAA
for VAA in $VAAS for VAA in $VAAS

View File

@ -28,9 +28,9 @@ else
usage usage
fi fi
WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core) WORMHOLE_ADDR=$(worm info contract "$NETWORK" aptos Core)
TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge) TOKEN_BRIDGE_ADDR=$(worm info contract "$NETWORK" aptos TokenBridge)
NFT_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos NFTBridge) NFT_BRIDGE_ADDR=$(worm info contract "$NETWORK" aptos NFTBridge)
NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR" NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR"
@ -55,7 +55,7 @@ VAA=$(worm generate upgrade -c aptos -a "$HASH" -m "$MODULE" -g $GUARDIAN_SECRET
echo "Submitting VAA: $VAA" echo "Submitting VAA: $VAA"
# TODO: --contract-address should not be neded after the sdk has these addresses # TODO: --contract-address should not be neded after the sdk has these addresses
CONTRACT_ADDR=$(worm contract "$NETWORK" aptos "$MODULE") CONTRACT_ADDR=$(worm info contract "$NETWORK" aptos "$MODULE")
worm submit --network "$NETWORK" "$VAA" --contract-address "$CONTRACT_ADDR" worm submit --network "$NETWORK" "$VAA" --contract-address "$CONTRACT_ADDR"
worm aptos upgrade $DIR --network "$NETWORK" --contract-address "$CONTRACT_ADDR" --named-addresses "$NAMED_ADDRS" worm aptos upgrade $DIR --network "$NETWORK" --contract-address "$CONTRACT_ADDR" --named-addresses "$NAMED_ADDRS"
worm aptos migrate --network "$NETWORK" --contract-address "$CONTRACT_ADDR" worm aptos migrate --network "$NETWORK" --contract-address "$CONTRACT_ADDR"

View File

@ -38,7 +38,13 @@ export async function execute_algorand(
let target_contract: string; let target_contract: string;
switch (payload.module) { switch (payload.module) {
case "Core": case "Core": {
if (!contracts.core) {
throw new Error(
`Core bridge address not defined for Algorand ${network}`
);
}
target_contract = contracts.core; target_contract = contracts.core;
switch (payload.type) { switch (payload.type) {
case "GuardianSetUpgrade": case "GuardianSetUpgrade":
@ -52,14 +58,17 @@ export async function execute_algorand(
default: default:
impossible(payload); impossible(payload);
} }
break; break;
case "NFTBridge": }
if (contracts.nft_bridge === undefined) { case "NFTBridge": {
if (!contracts.nft_bridge) {
// NOTE: this code can safely be removed once the algorand NFT bridge is // NOTE: this code can safely be removed once the algorand NFT bridge is
// released, but it's fine for it to stay, as the condition will just be // released, but it's fine for it to stay, as the condition will just be
// skipped once 'contracts.nft_bridge' is defined // skipped once 'contracts.nft_bridge' is defined
throw new Error("NFT bridge not supported yet for algorand"); throw new Error("NFT bridge not supported yet for Algorand");
} }
target_contract = contracts.nft_bridge; target_contract = contracts.nft_bridge;
switch (payload.type) { switch (payload.type) {
case "ContractUpgrade": case "ContractUpgrade":
@ -76,11 +85,16 @@ export async function execute_algorand(
default: default:
impossible(payload); impossible(payload);
} }
break; break;
case "TokenBridge": }
if (contracts.token_bridge === undefined) { case "TokenBridge": {
throw new Error("contracts.token_bridge is undefined"); if (!contracts.token_bridge) {
throw new Error(
`Token bridge address not defined for Algorand ${network}`
);
} }
target_contract = contracts.token_bridge; target_contract = contracts.token_bridge;
switch (payload.type) { switch (payload.type) {
case "ContractUpgrade": case "ContractUpgrade":
@ -102,7 +116,9 @@ export async function execute_algorand(
default: default:
impossible(payload); impossible(payload);
} }
break; break;
}
default: default:
target_contract = impossible(payload); target_contract = impossible(payload);
} }

View File

@ -24,7 +24,7 @@ import {
RPC_OPTIONS, RPC_OPTIONS,
} from "../consts"; } from "../consts";
import { NETWORKS } from "../networks"; import { NETWORKS } from "../networks";
import { runCommand, VALIDATOR_OPTIONS } from "../start-validator"; import { runCommand, VALIDATOR_OPTIONS } from "../startValidator";
import { assertNetwork, checkBinary, evm_address, hex } from "../utils"; import { assertNetwork, checkBinary, evm_address, hex } from "../utils";
const APTOS_NODE_URL = "http://0.0.0.0:8080/v1"; const APTOS_NODE_URL = "http://0.0.0.0:8080/v1";

View File

@ -22,6 +22,7 @@ import { Other } from "@certusone/wormhole-sdk/lib/esm/vaa";
import axios from "axios"; import axios from "axios";
import { ethers } from "ethers"; import { ethers } from "ethers";
import yargs from "yargs"; import yargs from "yargs";
import { NETWORK_OPTIONS } from "../consts";
import { NETWORKS } from "../networks"; import { NETWORKS } from "../networks";
import { assertNetwork, Network } from "../utils"; import { assertNetwork, Network } from "../utils";
import { parse, Payload, serialiseVAA, sign, Signature, VAA } from "../vaa"; import { parse, Payload, serialiseVAA, sign, Signature, VAA } from "../vaa";
@ -36,12 +37,7 @@ export const builder = (y: typeof yargs) =>
type: "string", type: "string",
demandOption: true, demandOption: true,
}) })
.option("network", { .option("network", NETWORK_OPTIONS)
alias: "n",
describe: "network",
choices: ["mainnet", "testnet", "devnet"],
demandOption: true,
} as const)
.option("guardian-set-index", { .option("guardian-set-index", {
alias: "gsi", alias: "gsi",
describe: "guardian set index", describe: "guardian set index",

View File

@ -9,6 +9,7 @@ import {
import { ethers } from "ethers"; import { ethers } from "ethers";
import { homedir } from "os"; import { homedir } from "os";
import yargs from "yargs"; import yargs from "yargs";
import { NETWORK_OPTIONS } from "../consts";
import { import {
getImplementation, getImplementation,
hijack_evm, hijack_evm,
@ -16,7 +17,7 @@ import {
setStorageAt, setStorageAt,
} from "../evm"; } from "../evm";
import { NETWORKS } from "../networks"; import { NETWORKS } from "../networks";
import { runCommand, VALIDATOR_OPTIONS } from "../start-validator"; import { runCommand, VALIDATOR_OPTIONS } from "../startValidator";
import { assertNetwork, evm_address } from "../utils"; import { assertNetwork, evm_address } from "../utils";
export const command = "evm"; export const command = "evm";
@ -95,24 +96,16 @@ export const builder = function (y: typeof yargs) {
.option("chain", { .option("chain", {
alias: "c", alias: "c",
describe: "Chain to query", describe: "Chain to query",
type: "string", choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
choices: Object.keys(CHAINS),
demandOption: true, demandOption: true,
}) } as const)
.option("module", { .option("module", {
alias: "m", alias: "m",
describe: "Module to query", describe: "Module to query",
type: "string",
choices: ["Core", "NFTBridge", "TokenBridge"], choices: ["Core", "NFTBridge", "TokenBridge"],
demandOption: true, demandOption: true,
}) } as const)
.option("network", { .option("network", NETWORK_OPTIONS)
alias: "n",
describe: "network",
type: "string",
choices: ["mainnet", "testnet", "devnet"],
demandOption: true,
})
.option("contract-address", { .option("contract-address", {
alias: "a", alias: "a",
describe: "Contract to query (override config)", describe: "Contract to query (override config)",
@ -127,17 +120,18 @@ export const builder = function (y: typeof yargs) {
demandOption: false, demandOption: false,
}), }),
async (argv) => { async (argv) => {
assertChain(argv["chain"]); const chain = argv.chain;
assertEVMChain(argv["chain"]); assertChain(chain);
assertEVMChain(chain);
const network = argv.network.toUpperCase(); const network = argv.network.toUpperCase();
assertNetwork(network); assertNetwork(network);
const module = argv["module"] as "Core" | "NFTBridge" | "TokenBridge"; const module = argv.module;
const rpc = argv["rpc"] ?? NETWORKS[network][argv["chain"]].rpc; const rpc = argv.rpc ?? NETWORKS[network][chain].rpc;
if (argv["implementation-only"]) { if (argv["implementation-only"]) {
console.log( console.log(
await getImplementation( await getImplementation(
network, network,
argv["chain"], chain,
module, module,
argv["contract-address"], argv["contract-address"],
rpc rpc
@ -148,7 +142,7 @@ export const builder = function (y: typeof yargs) {
JSON.stringify( JSON.stringify(
await query_contract_evm( await query_contract_evm(
network, network,
argv["chain"], chain,
module, module,
argv["contract-address"], argv["contract-address"],
rpc rpc
@ -186,7 +180,7 @@ export const builder = function (y: typeof yargs) {
}), }),
async (argv) => { async (argv) => {
const guardian_addresses = argv["guardian-address"].split(","); const guardian_addresses = argv["guardian-address"].split(",");
let rpc = argv["rpc"] ?? NETWORKS.DEVNET.ethereum.rpc; let rpc = argv.rpc ?? NETWORKS.DEVNET.ethereum.rpc;
await hijack_evm( await hijack_evm(
rpc, rpc,
argv["core-contract-address"], argv["core-contract-address"],

View File

@ -67,7 +67,7 @@ export const builder = function (y: typeof yargs) {
.option("chain", { .option("chain", {
alias: "c", alias: "c",
describe: "Chain to register", describe: "Chain to register",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const) } as const)
.option("contract-address", { .option("contract-address", {
@ -113,7 +113,7 @@ export const builder = function (y: typeof yargs) {
.option("chain", { .option("chain", {
alias: "c", alias: "c",
describe: "Chain to upgrade", describe: "Chain to upgrade",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const) } as const)
.option("contract-address", { .option("contract-address", {
@ -154,7 +154,7 @@ export const builder = function (y: typeof yargs) {
.option("emitter-chain", { .option("emitter-chain", {
alias: "e", alias: "e",
describe: "Emitter chain of the VAA", describe: "Emitter chain of the VAA",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const) } as const)
.option("emitter-address", { .option("emitter-address", {
@ -166,10 +166,9 @@ export const builder = function (y: typeof yargs) {
.option("chain", { .option("chain", {
alias: "c", alias: "c",
describe: "Token's chain", describe: "Token's chain",
type: "string", choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
choices: Object.keys(CHAINS),
demandOption: true, demandOption: true,
}) } as const)
.option("token-address", { .option("token-address", {
alias: "a", alias: "a",
describe: "Token's address", describe: "Token's address",

View File

@ -12,7 +12,7 @@ export const builder = (y: typeof yargs) => {
return y.positional("chain", { return y.positional("chain", {
describe: "Chain to query", describe: "Chain to query",
type: "string", type: "string",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const); } as const);
}; };

View File

@ -3,10 +3,9 @@ import {
assertChain, assertChain,
} from "@certusone/wormhole-sdk/lib/esm/utils/consts"; } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import yargs from "yargs"; import yargs from "yargs";
import { CONTRACTS } from "../consts"; import { CONTRACTS } from "../../consts";
import { getEmitterAddress } from "../emitter"; import { assertNetwork } from "../../utils";
import { assertNetwork } from "../utils"; import { impossible } from "../../vaa";
import { impossible } from "../vaa";
export const command = "contract <network> <chain> <module>"; export const command = "contract <network> <chain> <module>";
export const desc = "Print contract address"; export const desc = "Print contract address";
@ -19,29 +18,23 @@ export const builder = (y: typeof yargs) =>
} as const) } as const)
.positional("chain", { .positional("chain", {
describe: "Chain to query", describe: "Chain to query",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const) } as const)
.positional("module", { .positional("module", {
describe: "Module to query", describe: "Module to query",
choices: ["Core", "NFTBridge", "TokenBridge"], choices: ["Core", "NFTBridge", "TokenBridge"],
demandOption: true, demandOption: true,
} as const) } as const);
.option("emitter", {
alias: "e",
describe: "Print in emitter address format",
type: "boolean",
default: false,
demandOption: false,
});
export const handler = async ( export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]> argv: Awaited<ReturnType<typeof builder>["argv"]>
) => { ) => {
assertChain(argv["chain"]);
const network = argv.network.toUpperCase(); const network = argv.network.toUpperCase();
assertNetwork(network); assertNetwork(network);
const chain = argv["chain"]; const chain = argv["chain"];
assertChain(chain);
const module = argv["module"]; const module = argv["module"];
let addr: string | undefined; let addr: string | undefined;
switch (module) { switch (module) {
case "Core": case "Core":
@ -66,9 +59,5 @@ export const handler = async (
throw new Error(`${module} not deployed on ${chain}`); throw new Error(`${module} not deployed on ${chain}`);
} }
if (argv["emitter"]) {
addr = await getEmitterAddress(chain, addr);
}
console.log(addr); console.log(addr);
}; };

View File

@ -3,19 +3,19 @@ import {
assertChain, assertChain,
} from "@certusone/wormhole-sdk/lib/esm/utils/consts"; } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import yargs from "yargs"; import yargs from "yargs";
import { getEmitterAddress } from "../emitter"; import { getEmitterAddress } from "../../emitter";
export const command = "convert-to-emitter <chain> <address-to-convert>"; export const command = "emitter <chain> <address>";
export const desc = "Print address in emitter address format"; export const desc = "Print address in emitter address format";
export const builder = (y: typeof yargs) => export const builder = (y: typeof yargs) =>
y y
.positional("chain", { .positional("chain", {
describe: "Chain to query", describe: "Chain to query",
type: "string", type: "string",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const) } as const)
.positional("address-to-convert", { .positional("address", {
describe: "Address to be converted to emitter address format", describe: "Address to be converted to emitter address format",
type: "string", type: "string",
demandOption: true, demandOption: true,
@ -23,8 +23,6 @@ export const builder = (y: typeof yargs) =>
export const handler = async ( export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]> argv: Awaited<ReturnType<typeof builder>["argv"]>
) => { ) => {
assertChain(argv["chain"]); assertChain(argv.chain);
console.log( console.log(await getEmitterAddress(argv.chain, argv.address));
await getEmitterAddress(argv["chain"], argv["address-to-convert"])
);
}; };

View File

@ -1,16 +1,12 @@
import yargs from "yargs"; import yargs from "yargs";
import * as chainId from "./chainId"; import * as chainId from "./chainId";
import * as contractAddress from "./contractAddress"; import * as contract from "./contract";
import * as convertToEmitter from "./convert-to-emitter"; import * as emitter from "./emitter";
import * as rpc from "./rpc"; import * as rpc from "./rpc";
export const command = "info"; export const command = "info";
export const desc = "Contract, chain, rpc and address information utilities"; export const desc = "Contract, chain, rpc and address information utilities";
// Imports modules logic from root commands, more info here -> https://github.com/yargs/yargs/blob/main/docs/advanced.md#providing-a-command-module // Imports modules logic from root commands, more info here -> https://github.com/yargs/yargs/blob/main/docs/advanced.md#providing-a-command-module
export const builder = (y: typeof yargs) => export const builder = (y: typeof yargs) =>
y y.command(chainId).command(contract).command(emitter).command(rpc);
.command(chainId)
.command(contractAddress)
.command(convertToEmitter)
.command(rpc);
export const handler = () => {}; export const handler = () => {};

View File

@ -3,8 +3,8 @@ import {
assertChain, assertChain,
} from "@certusone/wormhole-sdk/lib/esm/utils/consts"; } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import yargs from "yargs"; import yargs from "yargs";
import { NETWORKS } from "../networks"; import { NETWORKS } from "../../networks";
import { assertNetwork } from "../utils"; import { assertNetwork } from "../../utils";
export const command = "rpc <network> <chain>"; export const command = "rpc <network> <chain>";
export const desc = "Print RPC address"; export const desc = "Print RPC address";
@ -17,7 +17,7 @@ export const builder = (y: typeof yargs) =>
} as const) } as const)
.positional("chain", { .positional("chain", {
describe: "Chain to query", describe: "Chain to query",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: true, demandOption: true,
} as const); } as const);
export const handler = async ( export const handler = async (

View File

@ -97,7 +97,7 @@ export const builder = function (y: typeof yargs) {
const masterKey = KeyPair.fromString(key); const masterKey = KeyPair.fromString(key);
const keyStore = new InMemoryKeyStore(); const keyStore = new InMemoryKeyStore();
keyStore.setKey(networkId, argv["account"], masterKey); keyStore.setKey(networkId, argv.account, masterKey);
const near = await connect({ const near = await connect({
deps: { deps: {
keyStore, keyStore,
@ -107,7 +107,7 @@ export const builder = function (y: typeof yargs) {
headers: {}, headers: {},
}); });
const masterAccount = new Account(near.connection, argv["account"]); const masterAccount = new Account(near.connection, argv.account);
const result = await masterAccount.functionCall({ const result = await masterAccount.functionCall({
contractId: target, contractId: target,
methodName: "update_contract", methodName: "update_contract",
@ -169,7 +169,7 @@ export const builder = function (y: typeof yargs) {
const masterKey = KeyPair.fromString(key); const masterKey = KeyPair.fromString(key);
const keyStore = new InMemoryKeyStore(); const keyStore = new InMemoryKeyStore();
keyStore.setKey(networkId, argv["account"], masterKey); keyStore.setKey(networkId, argv.account, masterKey);
keyStore.setKey(networkId, target, masterKey); keyStore.setKey(networkId, target, masterKey);
const near = await connect({ const near = await connect({
@ -180,13 +180,13 @@ export const builder = function (y: typeof yargs) {
nodeUrl: rpc, nodeUrl: rpc,
headers: {}, headers: {},
}); });
const masterAccount = new Account(near.connection, argv["account"]); const masterAccount = new Account(near.connection, argv.account);
const targetAccount = new Account(near.connection, target); const targetAccount = new Account(near.connection, target);
console.log({ ...argv, key, rpc, target }); console.log({ ...argv, key, rpc, target });
if (argv.attach) { if (argv.attach) {
console.log( console.log(
`Sending money: ${target} from ${argv["account"]} being sent ${argv["attach"]}` `Sending money: ${target} from ${argv.account} being sent ${argv.attach}`
); );
console.log( console.log(
await masterAccount.sendMoney(target, new BN(argv.attach)) await masterAccount.sendMoney(target, new BN(argv.attach))
@ -195,7 +195,7 @@ export const builder = function (y: typeof yargs) {
console.log("deploying contract"); console.log("deploying contract");
console.log( console.log(
await targetAccount.deployContract(readFileSync(argv["file"])) await targetAccount.deployContract(readFileSync(argv.file))
); );
} }
); );

View File

@ -21,6 +21,6 @@ export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]> argv: Awaited<ReturnType<typeof builder>["argv"]>
) => { ) => {
console.log( console.log(
ethers.utils.recoverAddress(hex(argv["digest"]), hex(argv["signature"])) ethers.utils.recoverAddress(hex(argv.digest), hex(argv.signature))
); );
}; };

View File

@ -10,6 +10,7 @@ import {
import yargs from "yargs"; import yargs from "yargs";
import { execute_algorand } from "../algorand"; import { execute_algorand } from "../algorand";
import { execute_aptos } from "../aptos"; import { execute_aptos } from "../aptos";
import { NETWORK_OPTIONS } from "../consts";
import { execute_evm } from "../evm"; import { execute_evm } from "../evm";
import { execute_injective } from "../injective"; import { execute_injective } from "../injective";
import { execute_near } from "../near"; import { execute_near } from "../near";
@ -33,15 +34,10 @@ export const builder = (y: typeof yargs) =>
.option("chain", { .option("chain", {
alias: "c", alias: "c",
describe: "chain name", describe: "chain name",
choices: Object.keys(CHAINS), choices: Object.keys(CHAINS) as (keyof typeof CHAINS)[],
demandOption: false, demandOption: false,
} as const) } as const)
.option("network", { .option("network", NETWORK_OPTIONS)
alias: "n",
describe: "network",
choices: ["mainnet", "testnet", "devnet"],
demandOption: true,
} as const)
.option("contract-address", { .option("contract-address", {
alias: "a", alias: "a",
describe: "Contract to submit VAA to (override config)", describe: "Contract to submit VAA to (override config)",
@ -61,7 +57,6 @@ export const handler = async (
const parsed_vaa = parse(buf); const parsed_vaa = parse(buf);
assertKnownPayload(parsed_vaa); assertKnownPayload(parsed_vaa);
console.log(parsed_vaa.payload); console.log(parsed_vaa.payload);
const network = argv.network.toUpperCase(); const network = argv.network.toUpperCase();
@ -87,7 +82,7 @@ export const handler = async (
const vaa_chain = toChainName(vaa_chain_id); const vaa_chain = toChainName(vaa_chain_id);
// get chain from command line arg // get chain from command line arg
const cli_chain = argv["chain"]; const cli_chain = argv.chain;
let chain: ChainName; let chain: ChainName;
if (cli_chain !== undefined) { if (cli_chain !== undefined) {
@ -113,7 +108,7 @@ export const handler = async (
network, network,
chain, chain,
argv["contract-address"], argv["contract-address"],
argv["rpc"] argv.rpc
); );
} else if (isTerraChain(chain)) { } else if (isTerraChain(chain)) {
await execute_terra(parsed_vaa.payload, buf, network, chain); await execute_terra(parsed_vaa.payload, buf, network, chain);
@ -136,14 +131,14 @@ export const handler = async (
} else if (chain === "osmosis") { } else if (chain === "osmosis") {
throw Error("OSMOSIS is not supported yet"); throw Error("OSMOSIS is not supported yet");
} else if (chain === "sui") { } else if (chain === "sui") {
await submitSui(parsed_vaa.payload, buf, network, argv["rpc"]); await submitSui(parsed_vaa.payload, buf, network, argv.rpc);
} else if (chain === "aptos") { } else if (chain === "aptos") {
await execute_aptos( await execute_aptos(
parsed_vaa.payload, parsed_vaa.payload,
buf, buf,
network, network,
argv["contract-address"], argv["contract-address"],
argv["rpc"] argv.rpc
); );
} else if (chain === "wormchain") { } else if (chain === "wormchain") {
throw Error("Wormchain is not supported yet"); throw Error("Wormchain is not supported yet");

View File

@ -3,7 +3,7 @@ import { Yargs } from "../Yargs";
import { addBuildCommands } from "./build"; import { addBuildCommands } from "./build";
import { addDeployCommands } from "./deploy"; import { addDeployCommands } from "./deploy";
import { addInitCommands } from "./init"; import { addInitCommands } from "./init";
import { addPublishMessageCommands } from "./publish_message"; import { addPublishMessageCommands } from "./publishMessage";
import { addSetupCommands } from "./setup"; import { addSetupCommands } from "./setup";
import { addUtilsCommands } from "./utils"; import { addUtilsCommands } from "./utils";

View File

@ -61,9 +61,9 @@ export const addPublishMessageCommands: YargsAddCommandsFn = (
const network = argv.network.toUpperCase(); const network = argv.network.toUpperCase();
assertNetwork(network); assertNetwork(network);
const packageId = argv["package-id"]; const packageId = argv["package-id"];
const stateObjectId = argv["state"]; const stateObjectId = argv.state;
const wormholeStateObjectId = argv["wormhole-state"]; const wormholeStateObjectId = argv["wormhole-state"];
const message = argv["message"]; const message = argv.message;
const privateKey = argv["private-key"]; const privateKey = argv["private-key"];
const rpc = argv.rpc ?? NETWORKS[network].sui.rpc; const rpc = argv.rpc ?? NETWORKS[network].sui.rpc;

View File

@ -84,11 +84,10 @@ export const addUtilsCommands: YargsAddCommandsFn = (y: typeof yargs) =>
.option("network", { .option("network", {
alias: "n", alias: "n",
describe: "Network", describe: "Network",
type: "string",
choices: ["mainnet", "testnet", "devnet"], choices: ["mainnet", "testnet", "devnet"],
default: "devnet", default: "devnet",
demandOption: false, demandOption: false,
}) } as const)
.option("rpc", RPC_OPTIONS), .option("rpc", RPC_OPTIONS),
async (argv) => { async (argv) => {
const network = argv.network.toUpperCase(); const network = argv.network.toUpperCase();

View File

@ -4,6 +4,7 @@ import { Implementation__factory } from "@certusone/wormhole-sdk/lib/esm/ethers-
import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts"; import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
import { ethers } from "ethers"; import { ethers } from "ethers";
import yargs from "yargs"; import yargs from "yargs";
import { NETWORK_OPTIONS } from "../consts";
import { NETWORKS } from "../networks"; import { NETWORKS } from "../networks";
import { assertNetwork } from "../utils"; import { assertNetwork } from "../utils";
@ -17,12 +18,7 @@ export const builder = (y: typeof yargs) =>
type: "string", type: "string",
demandOption: true, demandOption: true,
}) })
.option("network", { .option("network", NETWORK_OPTIONS);
alias: "n",
describe: "network",
choices: ["mainnet", "testnet", "devnet"],
demandOption: true,
} as const);
export const handler = async ( export const handler = async (
argv: Awaited<ReturnType<typeof builder>["argv"]> argv: Awaited<ReturnType<typeof builder>["argv"]>
) => { ) => {

View File

@ -6,26 +6,21 @@ import { hideBin } from "yargs/helpers";
import "./side-effects"; import "./side-effects";
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs // https://github.com/yargs/yargs/blob/main/docs/advanced.md#example-command-hierarchy-using-indexmjs
import * as aptos from "./cmds/aptos"; import * as aptos from "./cmds/aptos";
import * as chainId from "./cmds/chainId"; import * as editVaa from "./cmds/editVaa";
import * as contractAddress from "./cmds/contractAddress";
import * as editVaa from "./cmds/edit-vaa";
import * as evm from "./cmds/evm"; import * as evm from "./cmds/evm";
import * as generate from "./cmds/generate"; import * as generate from "./cmds/generate";
import * as info from "./cmds/info"; import * as info from "./cmds/info";
import * as near from "./cmds/near"; import * as near from "./cmds/near";
import * as parse from "./cmds/parse"; import * as parse from "./cmds/parse";
import * as recover from "./cmds/recover"; import * as recover from "./cmds/recover";
import * as rpc from "./cmds/rpc";
import * as submit from "./cmds/submit"; import * as submit from "./cmds/submit";
import * as sui from "./cmds/sui"; import * as sui from "./cmds/sui";
import * as verifyVaa from "./cmds/verify-vaa"; import * as verifyVaa from "./cmds/verifyVaa";
yargs(hideBin(process.argv)) yargs(hideBin(process.argv))
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#commanddirdirectory-opts // https://github.com/yargs/yargs/blob/main/docs/advanced.md#commanddirdirectory-opts
// can't use `.commandDir` because bundling + tree-shaking // can't use `.commandDir` because bundling + tree-shaking
.command(aptos) .command(aptos)
.command(chainId)
.command(contractAddress)
.command(editVaa) .command(editVaa)
.command(evm) .command(evm)
.command(generate) .command(generate)
@ -33,7 +28,6 @@ yargs(hideBin(process.argv))
.command(near) .command(near)
.command(parse) .command(parse)
.command(recover) .command(recover)
.command(rpc)
.command(submit) .command(submit)
.command(sui) .command(sui)
.command(verifyVaa) .command(verifyVaa)

View File

@ -9,5 +9,5 @@
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true "strict": true
}, },
"include": ["src"] "include": ["src", "types"]
} }

View File

@ -12,4 +12,4 @@ fi
CHAIN_NAME="$1" CHAIN_NAME="$1"
DOCKER_ARGS="-p 8545:8545" ./foundry anvil --host 0.0.0.0 --base-fee 0 --fork-url $(worm rpc mainnet $CHAIN_NAME) --mnemonic "myth like bonus scare over problem client lizard pioneer submit female collect" DOCKER_ARGS="-p 8545:8545" ./foundry anvil --host 0.0.0.0 --base-fee 0 --fork-url $(worm info rpc mainnet $CHAIN_NAME) --mnemonic "myth like bonus scare over problem client lizard pioneer submit female collect"

View File

@ -10,7 +10,7 @@ import "../contracts/bridge/BridgeStructs.sol";
contract BridgeTest is Bridge, Script { contract BridgeTest is Bridge, Script {
// forge script scripts/TokenABI.s.sol -s "token_constructor_args(bytes, address)" 0x01000000020d00b7ba3819d44da891c74c583e29eb2222dd37dabbe7929bdbf4f2186bbcc721085d85d9906bbd8ca5ae62cdf30c7555dc4c57fd15f84a0161c27e91846203439c0102736caa697f6c17c2e6b0526291b0e6b4dec760a8494df7f69c93be3df1956224637ef962be9a28ef2dbeebe6bdb30311d9f2394966a1bb170634bd69913abfb200038c598c6e7c288c5dbb0f0008c38168d3f00ac8da7b3ad5420f30c8808c94a8a972c090d25da27558f1b8f8d30f894850d3139f4df92c8e8736be7803d397f33e0006649e6aca07694046fd94b5851ff3711783d4f4c8e0319f9de9431232cb153bce2ff2ac0f7bfad6f3db461571cd6ecffc99d7740a7b653d2f6a25908d821d9ca70107b31051fda4062585f80b291978a480cae6c9191d37a67bc2e1e61db8e97907fa71b5064d2ada48b4cd2f8c4def7fd50484004d1ceb3438a8f67ea071a31a6a88000af4842bbcd0fad425bd3b82bc3b1acefd72555fd1fbb49b71700ec2b41ac6309f20222e24c557f4ad6af35d96f1d4c38fb25177e027a22d2d071956d5d45985ba000bc0ebb4202aae662de331bce75d5e49ea97ac9a74df65006250c96ca9d82a16be6e78c577004a6059169aa7640436e1e5deef5d80bfa52784cf82f67bb368e066010d14586fa1f6f37d2c4d0eae78c42ecc3c9fc6bf17b3a57406382165d615cfb4a1651b979419c42e40a3f62fbe05eb3ff4bafac0af30c15a060e39d935776e54cc000e98d02eb76745301cb5fb12e6b0c7e3e9be347460ed51be360828c46be3bc40ef622f9234fb443b431db9e98980a7165b36eda10bd37abf6998156ebbdf96c4b6010fda503c3deb9c937709ab5742c4a44ed29f04664585c4c73568cd3b4863e1e2326b9cab4d1b139d9698585bb8abcbdc4072b3f98fdfe1b50fa35656c1451f862400106644b7697f41052d4d7c1685d342df4828c7ba7231f86c04476805271c58b4e30614ee43988072decec39f0400a48583f7b6d0fb109516385f73a64ce2a2b16501111cc03c23da18a3ed794cb944aa6d131306c243d13f207796c9ea9430a6c7da063b0ffbc75416c924b588ecc24c3d1c6136ea8e181a4f3d8c1d3d1831c7d4ae7301120b48f7b0c43cb43b4541d179f4bdfe6b9c83289b5b7cd494f6ea33eec062b36408606f4ad406365539d6b3a6b59b2eeae70baf0266c341fb476c8092d64ebd620062cb923534d80000000e000000000000000000000000796dff6d74f3e27060b71255fe517bfb23c93eed00000000000000560102000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a000e12635553440000000000000000000000000000000000000000000000000000000043656c6f20446f6c6c6172000000000000000000000000000000000000000000 $(worm contract mainnet ethereum TokenBridge) // forge script scripts/TokenABI.s.sol -s "token_constructor_args(bytes, address)" 0x01000000020d00b7ba3819d44da891c74c583e29eb2222dd37dabbe7929bdbf4f2186bbcc721085d85d9906bbd8ca5ae62cdf30c7555dc4c57fd15f84a0161c27e91846203439c0102736caa697f6c17c2e6b0526291b0e6b4dec760a8494df7f69c93be3df1956224637ef962be9a28ef2dbeebe6bdb30311d9f2394966a1bb170634bd69913abfb200038c598c6e7c288c5dbb0f0008c38168d3f00ac8da7b3ad5420f30c8808c94a8a972c090d25da27558f1b8f8d30f894850d3139f4df92c8e8736be7803d397f33e0006649e6aca07694046fd94b5851ff3711783d4f4c8e0319f9de9431232cb153bce2ff2ac0f7bfad6f3db461571cd6ecffc99d7740a7b653d2f6a25908d821d9ca70107b31051fda4062585f80b291978a480cae6c9191d37a67bc2e1e61db8e97907fa71b5064d2ada48b4cd2f8c4def7fd50484004d1ceb3438a8f67ea071a31a6a88000af4842bbcd0fad425bd3b82bc3b1acefd72555fd1fbb49b71700ec2b41ac6309f20222e24c557f4ad6af35d96f1d4c38fb25177e027a22d2d071956d5d45985ba000bc0ebb4202aae662de331bce75d5e49ea97ac9a74df65006250c96ca9d82a16be6e78c577004a6059169aa7640436e1e5deef5d80bfa52784cf82f67bb368e066010d14586fa1f6f37d2c4d0eae78c42ecc3c9fc6bf17b3a57406382165d615cfb4a1651b979419c42e40a3f62fbe05eb3ff4bafac0af30c15a060e39d935776e54cc000e98d02eb76745301cb5fb12e6b0c7e3e9be347460ed51be360828c46be3bc40ef622f9234fb443b431db9e98980a7165b36eda10bd37abf6998156ebbdf96c4b6010fda503c3deb9c937709ab5742c4a44ed29f04664585c4c73568cd3b4863e1e2326b9cab4d1b139d9698585bb8abcbdc4072b3f98fdfe1b50fa35656c1451f862400106644b7697f41052d4d7c1685d342df4828c7ba7231f86c04476805271c58b4e30614ee43988072decec39f0400a48583f7b6d0fb109516385f73a64ce2a2b16501111cc03c23da18a3ed794cb944aa6d131306c243d13f207796c9ea9430a6c7da063b0ffbc75416c924b588ecc24c3d1c6136ea8e181a4f3d8c1d3d1831c7d4ae7301120b48f7b0c43cb43b4541d179f4bdfe6b9c83289b5b7cd494f6ea33eec062b36408606f4ad406365539d6b3a6b59b2eeae70baf0266c341fb476c8092d64ebd620062cb923534d80000000e000000000000000000000000796dff6d74f3e27060b71255fe517bfb23c93eed00000000000000560102000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a000e12635553440000000000000000000000000000000000000000000000000000000043656c6f20446f6c6c6172000000000000000000000000000000000000000000 $(worm info contract mainnet ethereum TokenBridge)
function token_constructor_args(bytes calldata encodedVM, address tokenBridge) public { function token_constructor_args(bytes calldata encodedVM, address tokenBridge) public {
Messages m = new Messages(); Messages m = new Messages();
Structs.VM memory vm = m.parseVM(encodedVM); Structs.VM memory vm = m.parseVM(encodedVM);

View File

@ -79,7 +79,7 @@ shift $((OPTIND - 1))
[ -z "$module" ] && usage [ -z "$module" ] && usage
# Get core contract address # Get core contract address
CORE=$(worm contract mainnet "$chain_name" Core) CORE=$(worm info contract mainnet "$chain_name" Core)
echo "core: $CORE" echo "core: $CORE"
# Use the local devnet guardian key (this is not a production key) # Use the local devnet guardian key (this is not a production key)
@ -142,7 +142,7 @@ case "$module" in
;; ;;
esac esac
CONTRACT=$(worm contract mainnet "$chain_name" "$MODULE") CONTRACT=$(worm info contract mainnet "$chain_name" "$MODULE")
# Step 1) Figure out the contract address depending on the flags -- either use # Step 1) Figure out the contract address depending on the flags -- either use
# an address passed in as an argument, or use the most recent contract in the repo. # an address passed in as an argument, or use the most recent contract in the repo.

View File

@ -59,7 +59,7 @@ if [[ -n $network ]]; then
echo "worm binary could not be found. See installation instructions in clients/js/README.md" echo "worm binary could not be found. See installation instructions in clients/js/README.md"
exit 1 exit 1
fi fi
rpc=$(worm rpc "$network" "$chain") rpc=$(worm info rpc "$network" "$chain")
fi fi
if [[ -z $rpc ]]; then if [[ -z $rpc ]]; then

View File

@ -407,7 +407,7 @@ if [ "$evm" = true ]; then
Next, use the \`verify\` script to verify that the deployed bytecodes we are upgrading to match the build artifacts: Next, use the \`verify\` script to verify that the deployed bytecodes we are upgrading to match the build artifacts:
\`\`\`shell \`\`\`shell
wormhole/ethereum $ ./verify -r $(worm rpc mainnet $chain_name) -c $chain_name $(evm_artifact) $address wormhole/ethereum $ ./verify -r $(worm info rpc mainnet $chain_name) -c $chain_name $(evm_artifact) $address
\`\`\` \`\`\`
EOF EOF

View File

@ -90,10 +90,10 @@ shift $((OPTIND - 1))
[ -z "$module" ] && usage [ -z "$module" ] && usage
# Use the worm client to get the emitter address and wormhole chain ID. # Use the worm client to get the emitter address and wormhole chain ID.
[ -z "$address" ] && address=`worm contract --emitter mainnet $chain_name $module` [ -z "$address" ] && address=`worm info contract --emitter mainnet $chain_name $module`
[ -z "$address" ] && usage [ -z "$address" ] && usage
chain=`worm chain-id $chain_name` chain=`worm info chain-id $chain_name`
[ -z "$chain" ] && usage [ -z "$chain" ] && usage
### The script constructs the governance proposal in two different steps. First, ### The script constructs the governance proposal in two different steps. First,