Client/js: Sepolia and Sei support (#2738)

* Client/js: Sepolia and Sei support

* Change references to terra to sei
This commit is contained in:
bruce-riley 2023-04-20 10:19:21 -05:00 committed by GitHub
parent c5df4dbfe6
commit 3dd4fe26b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 2157 additions and 3807 deletions

View File

@ -130,6 +130,9 @@ exports.handler = async (argv) => {
} else if (chain === "xpla") {
const xpla = require("../xpla");
await xpla.execute_xpla(parsed_vaa.payload, buf, network);
} else if (chain === "sei") {
const sei = require("../sei");
await sei.execute_sei(parsed_vaa.payload, buf, network);
} else if (chain === "osmosis") {
throw Error("OSMOSIS is not supported yet");
} else if (chain === "sui") {

View File

@ -5,7 +5,7 @@ import {
TxGrpcApi,
ChainRestAuthApi,
createTransaction,
MsgExecuteContract,
MsgExecuteContractCompat,
} from "@injectivelabs/sdk-ts";
import { fromUint8Array } from "js-base64";
import { impossible, Payload } from "./vaa";
@ -131,7 +131,7 @@ export async function execute_injective(
}
console.log("execute_msg", execute_msg);
const transaction = MsgExecuteContract.fromJSON({
const transaction = MsgExecuteContractCompat.fromJSON({
sender: walletInjAddr,
contractAddress: target_contract,
exec: {
@ -147,7 +147,7 @@ export async function execute_injective(
walletInjAddr
);
const { signBytes, txRaw } = createTransaction({
message: transaction.toDirectSign(),
message: transaction,
memo: "",
fee: getStdFee((parseInt(DEFAULT_STD_FEE.gas, 10) * 2.5).toString()),
pubKey: walletPublicKey,
@ -165,7 +165,7 @@ export async function execute_injective(
const sig = await walletPK.sign(Buffer.from(signBytes));
/** Append Signatures */
txRaw.setSignaturesList([sig]);
txRaw.signatures = [sig];
const txService = new TxGrpcApi(network.grpc);

View File

@ -111,6 +111,14 @@ const MAINNET = {
chain_id: "dimension_37-1",
key: get_env_var("XPLA_KEY"),
},
sei: {
rpc: undefined,
key: undefined,
},
sepolia: {
rpc: undefined,
key: undefined,
},
btc: {
rpc: undefined,
key: undefined,
@ -245,6 +253,14 @@ const TESTNET = {
chain_id: "cube_47-5",
key: get_env_var("XPLA_KEY_TESTNET"),
},
sei: {
rpc: "https://rpc.atlantic-2.seinetwork.io",
key: get_env_var("SEI_KEY_TESTNET"),
},
sepolia: {
rpc: "https://rpc.ankr.com/eth_sepolia",
key: get_env_var("ETH_KEY_TESTNET"),
},
btc: {
rpc: undefined,
key: undefined,
@ -373,6 +389,14 @@ const DEVNET = {
chain_id: undefined,
key: undefined,
},
sei: {
rpc: undefined,
key: undefined,
},
sepolia: {
rpc: undefined,
key: undefined,
},
wormchain: {
rpc: "http://localhost:1319",
chain_id: "wormchain",

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,12 @@
"version": "0.0.3",
"dependencies": {
"@celo-tools/celo-ethers-wrapper": "^0.1.0",
"@certusone/wormhole-sdk": "^0.9.11",
"@certusone/wormhole-sdk": "^0.9.14",
"@cosmjs/encoding": "^0.26.2",
"@injectivelabs/networks": "^1.0.73",
"@injectivelabs/sdk-ts": "^1.0.368",
"@injectivelabs/utils": "^1.0.63",
"@injectivelabs/networks": "^1.10.7",
"@injectivelabs/sdk-ts": "^1.10.47",
"@injectivelabs/utils": "^1.10.5",
"@sei-js/core": "^1.3.2",
"@solana/web3.js": "^1.22.0",
"@terra-money/terra.js": "^3.1.3",
"@types/config": "^3.3.0",

118
clients/js/sei.ts Normal file
View File

@ -0,0 +1,118 @@
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { calculateFee } from "@cosmjs/stargate";
import { getSigningCosmWasmClient } from "@sei-js/core";
import { impossible, Payload } from "./vaa";
import { NETWORKS } from "./networks";
import { CONTRACTS } from "@certusone/wormhole-sdk/lib/cjs/utils/consts";
export async function execute_sei(
payload: Payload,
vaa: Buffer,
network: "MAINNET" | "TESTNET" | "DEVNET",
) {
let chain = "sei";
let n = NETWORKS[network][chain];
let contracts = CONTRACTS[network][chain];
let target_contract: string;
let execute_msg: object;
switch (payload.module) {
case "Core":
target_contract = contracts.core;
// sigh...
execute_msg = {
submit_v_a_a: {
vaa: vaa.toString("base64"),
},
};
switch (payload.type) {
case "GuardianSetUpgrade":
console.log("Submitting new guardian set");
break;
case "ContractUpgrade":
console.log("Upgrading core contract");
break;
case "RecoverChainId":
throw new Error("RecoverChainId not supported on sei")
default:
impossible(payload);
}
break;
case "NFTBridge":
if (contracts.nft_bridge === undefined) {
// NOTE: this code can safely be removed once the sei NFT bridge is
// released, but it's fine for it to stay, as the condition will just be
// skipped once 'contracts.nft_bridge' is defined
throw new Error("NFT bridge not supported yet for sei");
}
target_contract = contracts.nft_bridge;
execute_msg = {
submit_vaa: {
data: vaa.toString("base64"),
},
};
switch (payload.type) {
case "ContractUpgrade":
console.log("Upgrading contract");
break;
case "RecoverChainId":
throw new Error("RecoverChainId not supported on sei")
case "RegisterChain":
console.log("Registering chain");
break;
case "Transfer":
console.log("Completing transfer");
break;
default:
impossible(payload);
}
break;
case "TokenBridge":
target_contract = contracts.token_bridge;
execute_msg = {
submit_vaa: {
data: vaa.toString("base64"),
},
};
switch (payload.type) {
case "ContractUpgrade":
console.log("Upgrading contract");
break;
case "RecoverChainId":
throw new Error("RecoverChainId not supported on sei")
case "RegisterChain":
console.log("Registering chain");
break;
case "Transfer":
console.log("Completing transfer");
break;
case "AttestMeta":
console.log("Creating wrapped token");
break;
case "TransferWithPayload":
throw Error("Can't complete payload 3 transfer from CLI");
default:
impossible(payload);
break;
}
break;
default:
target_contract = impossible(payload);
execute_msg = impossible(payload);
}
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(n.key, { prefix: "sei" });
const [ account ] = await wallet.getAccounts();
const client = await getSigningCosmWasmClient(n.rpc, wallet);
const fee = calculateFee(300000, "0.1usei");
const result = await client.execute(
account.address,
target_contract,
execute_msg,
fee
);
console.log(`TX hash: ${result.transactionHash}`);
}