client/js: adds key and rpc support for submit VAA on Sei mainnet. (#3399)
* Client/js: adds key and rpc support for submit VAA on Sei. * Client/js: adds default RPC for Sei mainnet. * misc: prettier format
This commit is contained in:
parent
da246424a8
commit
c311f07ec3
|
@ -1,5 +1,8 @@
|
||||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||||
import { calculateFee } from "@cosmjs/stargate";
|
import { calculateFee } from "@cosmjs/stargate";
|
||||||
|
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
|
||||||
|
import { toUtf8 } from "@cosmjs/encoding";
|
||||||
|
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
|
||||||
import { getSigningCosmWasmClient } from "@sei-js/core";
|
import { getSigningCosmWasmClient } from "@sei-js/core";
|
||||||
|
|
||||||
import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
|
import { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
|
||||||
|
@ -10,10 +13,13 @@ import { impossible, Payload } from "../../vaa";
|
||||||
export const submit = async (
|
export const submit = async (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
vaa: Buffer,
|
vaa: Buffer,
|
||||||
network: Network
|
network: Network,
|
||||||
|
rpc?: string
|
||||||
) => {
|
) => {
|
||||||
const contracts = CONTRACTS[network].sei;
|
const contracts = CONTRACTS[network].sei;
|
||||||
const { rpc, key } = NETWORKS[network].sei;
|
const networkInfo = NETWORKS[network].sei;
|
||||||
|
rpc = rpc || networkInfo.rpc;
|
||||||
|
const key = networkInfo.key;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
throw Error(`No ${network} key defined for Sei`);
|
throw Error(`No ${network} key defined for Sei`);
|
||||||
}
|
}
|
||||||
|
@ -131,7 +137,30 @@ export const submit = async (
|
||||||
});
|
});
|
||||||
const [account] = await wallet.getAccounts();
|
const [account] = await wallet.getAccounts();
|
||||||
const client = await getSigningCosmWasmClient(rpc, wallet);
|
const client = await getSigningCosmWasmClient(rpc, wallet);
|
||||||
const fee = calculateFee(300000, "0.1usei");
|
|
||||||
|
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
||||||
|
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
||||||
|
value: MsgExecuteContract.fromPartial({
|
||||||
|
sender: account.address,
|
||||||
|
contract: target_contract,
|
||||||
|
msg: toUtf8(JSON.stringify(execute_msg)),
|
||||||
|
funds: [],
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
// For some reason, the simulation only provides the gas used but no events
|
||||||
|
// so we can't determine whether it worked unless we do away with cosmjs and query the node ourselves.
|
||||||
|
// See https://github.com/cosmos/cosmjs/issues/1148#issuecomment-1129259646
|
||||||
|
const gasUsed = await client.simulate(
|
||||||
|
account.address,
|
||||||
|
[executeContractMsg],
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
// It looks like the simulation is a bit lacking when it comes to estimating gas.
|
||||||
|
// See https://github.com/cosmos/cosmos-sdk/issues/4938
|
||||||
|
// That's why we multiply it by a factor of 1.3
|
||||||
|
const estimatedGas = Math.floor((gasUsed * 130) / 100);
|
||||||
|
|
||||||
|
const fee = calculateFee(estimatedGas, "0.1usei");
|
||||||
const result = await client.execute(
|
const result = await client.execute(
|
||||||
account.address,
|
account.address,
|
||||||
target_contract,
|
target_contract,
|
||||||
|
|
|
@ -173,7 +173,7 @@ async function executeSubmit(
|
||||||
} else if (chain === "xpla") {
|
} else if (chain === "xpla") {
|
||||||
await execute_xpla(parsedVaa.payload, buf, network);
|
await execute_xpla(parsedVaa.payload, buf, network);
|
||||||
} else if (chain === "sei") {
|
} else if (chain === "sei") {
|
||||||
await submitSei(parsedVaa.payload, buf, network);
|
await submitSei(parsedVaa.payload, buf, network, rpc);
|
||||||
} 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") {
|
||||||
|
|
|
@ -165,8 +165,8 @@ const MAINNET = {
|
||||||
chain_id: 8453,
|
chain_id: 8453,
|
||||||
},
|
},
|
||||||
sei: {
|
sei: {
|
||||||
rpc: undefined,
|
rpc: "https://sei-rpc.polkachu.com/",
|
||||||
key: undefined,
|
key: getEnvVar("SEI_KEY"),
|
||||||
},
|
},
|
||||||
rootstock: {
|
rootstock: {
|
||||||
rpc: "https://public-node.rsk.co",
|
rpc: "https://public-node.rsk.co",
|
||||||
|
|
Loading…
Reference in New Issue