diff --git a/clients/js/algorand.ts b/clients/js/algorand.ts index e4836625d..c56b7c6ec 100644 --- a/clients/js/algorand.ts +++ b/clients/js/algorand.ts @@ -1,4 +1,3 @@ -import { CONTRACTS } from "@certusone/wormhole-sdk"; import { NETWORKS } from "./networks"; import { impossible, Payload } from "./vaa"; import { Account, Algodv2, mnemonicToSecretKey } from "algosdk"; @@ -6,6 +5,7 @@ import { signSendAndConfirmAlgorand, _submitVAAAlgorand, } from "@certusone/wormhole-sdk/lib/cjs/algorand"; +import { CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; export async function execute_algorand( payload: Payload, diff --git a/clients/js/aptos.ts b/clients/js/aptos.ts index 3f6a10514..9ade5125f 100644 --- a/clients/js/aptos.ts +++ b/clients/js/aptos.ts @@ -1,11 +1,11 @@ import { AptosAccount, TxnBuilderTypes, AptosClient, BCS } from "aptos"; import { NETWORKS } from "./networks"; import { impossible, Payload } from "./vaa"; -import { assertChain, ChainId, CONTRACTS } from "@certusone/wormhole-sdk"; import { Bytes, Seq } from "aptos/dist/transaction_builder/bcs/types"; import { TypeTag } from "aptos/dist/transaction_builder/aptos_types"; import { sha3_256 } from "js-sha3"; import { ethers } from "ethers"; +import { assertChain, ChainId, CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; export async function execute_aptos( payload: Payload, diff --git a/clients/js/cmds/aptos.ts b/clients/js/cmds/aptos.ts index 4b4b96401..51533f7b6 100644 --- a/clients/js/cmds/aptos.ts +++ b/clients/js/cmds/aptos.ts @@ -1,4 +1,3 @@ -import { assertChain, CHAIN_ID_APTOS, CHAIN_ID_SOLANA, coalesceChainId } from "@certusone/wormhole-sdk"; import { BCS, FaucetClient } from "aptos"; import { ethers } from "ethers"; import yargs from "yargs"; @@ -8,6 +7,7 @@ import { config } from '../config'; import fs from 'fs'; import sha3 from 'js-sha3'; import { NETWORKS } from "../networks"; +import { assertChain, CHAIN_ID_APTOS, CHAIN_ID_SOLANA, coalesceChainId } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; type Network = "MAINNET" | "TESTNET" | "DEVNET" diff --git a/clients/js/evm.ts b/clients/js/evm.ts index 54a53c462..1987d5ac0 100644 --- a/clients/js/evm.ts +++ b/clients/js/evm.ts @@ -1,11 +1,11 @@ -import { BridgeImplementation__factory, CHAINS, Implementation__factory, NFTBridgeImplementation__factory } from "@certusone/wormhole-sdk" -import { BigNumber, ethers } from "ethers" +import { ethers } from "ethers" import { NETWORKS } from "./networks" import { encode, Encoding, impossible, Payload, typeWidth } from "./vaa" -import { Contracts, CONTRACTS, EVMChainName } from "@certusone/wormhole-sdk" import axios from "axios"; import * as celo from "@celo-tools/celo-ethers-wrapper"; import { solidityKeccak256 } from "ethers/lib/utils" +import { CHAINS, CONTRACTS, Contracts, EVMChainName } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; +import { BridgeImplementation__factory, Implementation__factory, NFTBridgeImplementation__factory } from "@certusone/wormhole-sdk/lib/cjs/ethers-contracts"; const _IMPLEMENTATION_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" diff --git a/clients/js/injective.ts b/clients/js/injective.ts index 694aa7eeb..40f34bc4c 100644 --- a/clients/js/injective.ts +++ b/clients/js/injective.ts @@ -10,7 +10,7 @@ import { createTransaction, MsgArg, TxGrpcClient } from "@injectivelabs/tx-ts"; import { fromUint8Array } from "js-base64"; import { impossible, Payload } from "./vaa"; import { NETWORKS } from "./networks"; -import { CONTRACTS } from "@certusone/wormhole-sdk"; +import { CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; export async function execute_injective( payload: Payload, diff --git a/clients/js/main.ts b/clients/js/main.ts index fdc304f50..a98d8411f 100644 --- a/clients/js/main.ts +++ b/clients/js/main.ts @@ -11,7 +11,7 @@ // drop that particular message... // const info = console.info; -console.info = function (x) { +console.info = function(x: string) { if (x != "secp256k1 unavailable, reverting to browser version") { info(x); } @@ -22,48 +22,14 @@ import yargs from "yargs"; import { hideBin } from "yargs/helpers"; import { fromBech32, toHex } from "@cosmjs/encoding"; -import { CONTRACTS as SDK_CONTRACTS } from "@certusone/wormhole-sdk"; -import { - isTerraChain, - assertEVMChain, - setDefaultWasm, - hexToUint8Array, - getEmitterAddressSolana, - getEmitterAddressTerra, - getEmitterAddressEth, - getEmitterAddressAlgorand, - getEmitterAddressNear, - isCosmWasmChain, -} from "@certusone/wormhole-sdk"; -import { execute_solana } from "./solana"; -import { - execute_evm, - getImplementation, - hijack_evm, - query_contract_evm, - setStorageAt, -} from "./evm"; -import { execute_terra } from "./terra"; -import { execute_aptos } from "./aptos"; -import { execute_near, upgrade_near, deploy_near } from "./near"; import * as vaa from "./vaa"; import { impossible, Payload, serialiseVAA, VAA } from "./vaa"; -import { - assertChain, - ChainName, - CHAINS, - toChainName, - isEVMChain, - toChainId, - tryNativeToHexString, -} from "@certusone/wormhole-sdk"; import { ethers } from "ethers"; import { NETWORKS } from "./networks"; import base58 from "bs58"; -import { execute_algorand } from "./algorand"; -import { execute_injective } from "./injective"; -import { execute_xpla } from "./xpla"; import { isOutdated } from "./cmds/update"; +import { setDefaultWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm"; +import { assertChain, assertEVMChain, ChainName, CHAINS, CONTRACTS as SDK_CONTRACTS, isCosmWasmChain, isEVMChain, isTerraChain, toChainId, toChainName } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; setDefaultWasm("node"); @@ -78,7 +44,7 @@ const GOVERNANCE_CHAIN = 1; const GOVERNANCE_EMITTER = "0000000000000000000000000000000000000000000000000000000000000004"; -// TODO: put this into the sdk when things have finalised +// TODO: remove this once the aptos SDK changes are merged in const OVERRIDES = { MAINNET: { aptos: { @@ -445,17 +411,18 @@ yargs(hideBin(process.argv)) impossible(module); } if (argv["emitter"]) { + const emitter = require("@certusone/wormhole-sdk/lib/cjs/bridge/getEmitterAddress") if (chain === "solana" || chain === "pythnet") { // TODO: Create an isSolanaChain() - addr = await getEmitterAddressSolana(addr); - } else if (isCosmWasmChain(chain)) { - addr = await getEmitterAddressTerra(addr); + addr = await emitter.getEmitterAddressSolana(addr); + } else if (emitter.isCosmWasmChain(chain)) { + addr = await emitter.getEmitterAddressTerra(addr); } else if (chain === "algorand") { - addr = getEmitterAddressAlgorand(BigInt(addr)); + addr = emitter.getEmitterAddressAlgorand(BigInt(addr)); } else if (chain === "near") { - addr = await getEmitterAddressNear(addr); + addr = emitter.getEmitterAddressNear(addr); } else { - addr = getEmitterAddressEth(addr); + addr = emitter.getEmitterAddressEth(addr); } } console.log(addr); @@ -511,6 +478,7 @@ yargs(hideBin(process.argv)) "near", "NEAR utilites", (yargs) => { + const near = require("./near") return ( yargs .option("module", { @@ -562,7 +530,7 @@ yargs(hideBin(process.argv)) }); }, async (argv) => { - await upgrade_near(argv); + await near.upgrade_near(argv); } ) .command( @@ -575,7 +543,7 @@ yargs(hideBin(process.argv)) }); }, async (argv) => { - await deploy_near(argv); + await near.deploy_near(argv); } ) ); @@ -591,6 +559,7 @@ yargs(hideBin(process.argv)) "evm", "EVM utilites", (yargs) => { + const evm = require("./evm") return yargs .option("rpc", { describe: "RPC endpoint", @@ -635,7 +604,7 @@ yargs(hideBin(process.argv)) }); }, async (argv) => { - const result = await setStorageAt( + const result = await evm.setStorageAt( argv["rpc"], evm_address(argv["contract-address"]), argv["storage-slot"], @@ -708,7 +677,7 @@ yargs(hideBin(process.argv)) let rpc = argv["rpc"] ?? NETWORKS[network][argv["chain"]].rpc; if (argv["implementation-only"]) { console.log( - await getImplementation( + await evm.getImplementation( network, argv["chain"], module, @@ -719,7 +688,7 @@ yargs(hideBin(process.argv)) } else { console.log( JSON.stringify( - await query_contract_evm( + await evm.query_contract_evm( network, argv["chain"], module, @@ -761,7 +730,7 @@ yargs(hideBin(process.argv)) async (argv) => { const guardian_addresses = argv["guardian-address"].split(","); let rpc = argv["rpc"] ?? NETWORKS.DEVNET.ethereum.rpc; - await hijack_evm( + await evm.hijack_evm( rpc, argv["core-contract-address"], guardian_addresses, @@ -870,7 +839,8 @@ yargs(hideBin(process.argv)) "This VAA does not specify the target chain, please provide it by hand using the '--chain' flag." ); } else if (isEVMChain(chain)) { - await execute_evm( + const evm = require("./evm") + await evm.execute_evm( parsed_vaa.payload, buf, network, @@ -879,27 +849,34 @@ yargs(hideBin(process.argv)) argv["rpc"] ); } else if (isTerraChain(chain)) { - await execute_terra(parsed_vaa.payload, buf, network, chain); + const terra = require("./terra") + await terra.execute_terra(parsed_vaa.payload, buf, network, chain); } else if (chain === "solana" || chain === "pythnet") { - await execute_solana(parsed_vaa, buf, network, chain); + const solana = require("./solana") + await solana.execute_solana(parsed_vaa, buf, network, chain); } else if (chain === "algorand") { - await execute_algorand( + const algorand = require("./algorand") + await algorand.execute_algorand( parsed_vaa.payload, - hexToUint8Array(vaa_hex), + Buffer.from(vaa_hex, "hex"), network ); } else if (chain === "near") { - await execute_near(parsed_vaa.payload, vaa_hex, network); + const near = require("./near") + await near.execute_near(parsed_vaa.payload, vaa_hex, network); } else if (chain === "injective") { - await execute_injective(parsed_vaa.payload, buf, network); + const injective = require("./injective") + await injective.execute_injective(parsed_vaa.payload, buf, network); } else if (chain === "xpla") { - await execute_xpla(parsed_vaa.payload, buf, network); + const xpla = require("./xpla") + await xpla.execute_xpla(parsed_vaa.payload, buf, network); } else if (chain === "osmosis") { throw Error("OSMOSIS is not supported yet"); } else if (chain === "sui") { throw Error("SUI is not supported yet"); } else if (chain === "aptos") { - await execute_aptos( + const aptos = require("./aptos") + await aptos.execute_aptos( parsed_vaa.payload, buf, network, @@ -948,7 +925,8 @@ function parseAddress(chain: ChainName, address: string): string { // TODO: is there a better native format for aptos? return "0x" + evm_address(address); } else if (chain === "wormholechain") { - return "0x" + tryNativeToHexString(address, chain); + const sdk = require("@certusone/wormhole-sdk/lib/cjs/utils/array") + return "0x" + sdk.tryNativeToHexString(address, chain); } else { impossible(chain); } diff --git a/clients/js/near.ts b/clients/js/near.ts index 776a95491..09366f213 100644 --- a/clients/js/near.ts +++ b/clients/js/near.ts @@ -1,6 +1,6 @@ import { impossible, Payload } from "./vaa"; import { NETWORKS } from "./networks"; -import { CONTRACTS } from "@certusone/wormhole-sdk"; +import { CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; const { parseSeedPhrase, generateSeedPhrase } = require("near-seed-phrase"); const fs = require("fs"); diff --git a/clients/js/networks.ts b/clients/js/networks.ts index ec68036f8..9c56a25e2 100644 --- a/clients/js/networks.ts +++ b/clients/js/networks.ts @@ -1,4 +1,4 @@ -import { ChainName } from "@certusone/wormhole-sdk"; +import { ChainName } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; require("dotenv").config({ path: `${process.env.HOME}/.wormhole/.env` }); diff --git a/clients/js/package-lock.json b/clients/js/package-lock.json index 280083ee3..cbd1c3cee 100644 --- a/clients/js/package-lock.json +++ b/clients/js/package-lock.json @@ -1,12 +1,12 @@ { - "name": "wormhole-client", - "version": "1.0.0", + "name": "@wormhole-foundation/wormhole-client", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "wormhole-client", - "version": "1.0.0", + "name": "@wormhole-foundation/wormhole-client", + "version": "0.0.1", "dependencies": { "@celo-tools/celo-ethers-wrapper": "^0.1.0", "@certusone/wormhole-sdk": "^0.7.2", diff --git a/clients/js/solana.ts b/clients/js/solana.ts index 831f21161..29ccf541d 100644 --- a/clients/js/solana.ts +++ b/clients/js/solana.ts @@ -2,9 +2,9 @@ import * as web3s from '@solana/web3.js' import { NETWORKS } from "./networks"; import { impossible, Payload, VAA } from "./vaa"; import base58 from "bs58"; -import { CHAINS, importCoreWasm, importNftWasm, importTokenWasm, ixFromRust, SolanaChainName } from "@certusone/wormhole-sdk"; -import { CONTRACTS } from "@certusone/wormhole-sdk" -import { postVaaSolanaWithRetry } from "@certusone/wormhole-sdk" +import { CHAINS, CONTRACTS, SolanaChainName } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; +import { importCoreWasm, importNftWasm, importTokenWasm } from '@certusone/wormhole-sdk/lib/cjs/solana/wasm'; +import { ixFromRust, postVaaSolanaWithRetry } from '@certusone/wormhole-sdk/lib/cjs/solana'; export async function execute_solana( v: VAA, @@ -24,7 +24,7 @@ export async function execute_solana( case "Core": if (bridge_id === undefined) { throw Error("core bridge contract is undefined") - } + } const bridge = await importCoreWasm() switch (v.payload.type) { case "GuardianSetUpgrade": diff --git a/clients/js/terra.ts b/clients/js/terra.ts index 6547131ee..2e6414469 100644 --- a/clients/js/terra.ts +++ b/clients/js/terra.ts @@ -8,8 +8,8 @@ import { import { fromUint8Array } from "js-base64"; import { impossible, Payload } from "./vaa"; import { NETWORKS } from "./networks"; -import { CONTRACTS, TerraChainName } from "@certusone/wormhole-sdk"; import axios from "axios"; +import { CONTRACTS, TerraChainName } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; export async function execute_terra( payload: Payload, diff --git a/clients/js/xpla.ts b/clients/js/xpla.ts index c0307378a..c5cc41fe2 100644 --- a/clients/js/xpla.ts +++ b/clients/js/xpla.ts @@ -8,8 +8,7 @@ import { import { fromUint8Array } from "js-base64"; import { impossible, Payload } from "./vaa"; import { NETWORKS } from "./networks"; -import { CONTRACTS } from "@certusone/wormhole-sdk"; -import axios from "axios"; +import { CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts"; export async function execute_xpla( payload: Payload,