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:
scnale 2024-01-31 13:05:38 -03:00 committed by GitHub
parent da246424a8
commit c311f07ec3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 6 deletions

View File

@ -1,5 +1,8 @@
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
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 { CONTRACTS } from "@certusone/wormhole-sdk/lib/esm/utils/consts";
@ -10,10 +13,13 @@ import { impossible, Payload } from "../../vaa";
export const submit = async (
payload: Payload,
vaa: Buffer,
network: Network
network: Network,
rpc?: string
) => {
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) {
throw Error(`No ${network} key defined for Sei`);
}
@ -131,7 +137,30 @@ export const submit = async (
});
const [account] = await wallet.getAccounts();
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(
account.address,
target_contract,

View File

@ -173,7 +173,7 @@ async function executeSubmit(
} else if (chain === "xpla") {
await execute_xpla(parsedVaa.payload, buf, network);
} else if (chain === "sei") {
await submitSei(parsedVaa.payload, buf, network);
await submitSei(parsedVaa.payload, buf, network, rpc);
} else if (chain === "osmosis") {
throw Error("OSMOSIS is not supported yet");
} else if (chain === "sui") {

View File

@ -165,8 +165,8 @@ const MAINNET = {
chain_id: 8453,
},
sei: {
rpc: undefined,
key: undefined,
rpc: "https://sei-rpc.polkachu.com/",
key: getEnvVar("SEI_KEY"),
},
rootstock: {
rpc: "https://public-node.rsk.co",