Skip to content

Instantly share code, notes, and snippets.

@assafmo
Created March 19, 2024 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assafmo/65034e62e0bf5411611c8cf700add916 to your computer and use it in GitHub Desktop.
Save assafmo/65034e62e0bf5411611c8cf700add916 to your computer and use it in GitHub Desktop.
Manually send an IBC timeout
// Run this code with `ts-node main.ts`
import { IbcClient, Link } from "@confio/relayer";
import { stringToPath } from "@cosmjs/crypto";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import Long from "long";
import { fromHex } from "secretjs";
export async function createIbcConnection(): Promise<Link> {
const signerSecret = await DirectSecp256k1HdWallet.fromMnemonic("TODO", {
hdPaths: [stringToPath("m/44'/529'/0'/0/0")],
prefix: "secret",
});
const [accountSecret] = await signerSecret.getAccounts();
const signerOrai = await DirectSecp256k1HdWallet.fromMnemonic("TODO", {
hdPaths: [stringToPath("m/44'/118'/0'/0/0")],
prefix: "orai",
});
const [accountOrai] = await signerOrai.getAccounts();
// Create IBC Client for chain A
const clientA = await IbcClient.connectWithSigner(
"https://secret-4.api.trivium.network:26657",
signerSecret,
accountSecret.address,
{
// prefix: "secret",
gasPrice: GasPrice.fromString("0.1uscrt"),
estimatedBlockTime: 5800,
estimatedIndexerTime: 500,
}
);
// Create IBC Client for chain A
const clientB = await IbcClient.connectWithSigner(
"https://mainnet-orai-rpc.konsortech.xyz",
signerOrai,
accountOrai.address,
{
// prefix: "orai",
gasPrice: GasPrice.fromString("0.05orai"),
estimatedBlockTime: 1750,
estimatedIndexerTime: 500,
}
);
return await Link.createWithExistingConnections(
clientA,
clientB,
"connection-190",
"connection-142"
);
}
// async main function
async function main() {
console.log("creating IBC connection...");
const ibcConnection = await createIbcConnection();
console.log("sending timeout...");
const result = await ibcConnection.timeoutPackets("A", [
{
height: 0, // unused in timeoutPackets()
packet: {
/**
* number corresponds to the order of sends and receives, where a Packet
* with an earlier sequence number must be sent and received before a Packet
* with a later sequence number.
*/
sequence: Long.fromString("4"),
/** identifies the port on the sending chain. */
sourcePort: "wasm.secret1tqmms5awftpuhalcv5h5mg76fa0tkdz4jv9ex4",
/** identifies the channel end on the sending chain. */
sourceChannel: "channel-140",
/** identifies the port on the receiving chain. */
destinationPort: "transfer",
/** identifies the channel end on the receiving chain. */
destinationChannel: "channel-222",
/** actual opaque bytes transferred directly to the application module */
data: fromHex(
"7b22616d6f756e74223a2232303837313338303030303030222c2264656e6f6d223a22637732303a7365637265743135337775363035767670393334786864346b396474643634307a736570356a6b65737374646d222c227265636569766572223a226f72616931646d79613034716e7574756e6163746c63326d6d6c6e6a716e736d357270376c673337757637222c2273656e646572223a2273656372657431646d79613034716e7574756e6163746c63326d6d6c6e6a716e736d357270376c6538756b7333227d"
),
/** block height after which the packet times out */
timeoutHeight: {
revisionNumber: Long.fromString("0"),
revisionHeight: Long.fromString("0"),
},
/** block timestamp (in nanoseconds) after which the packet times out */
timeoutTimestamp: Long.fromString("1710397129632269738"),
},
},
]);
console.log(result);
}
main();
{
"dependencies": {
"@confio/relayer": "0.7.0",
"@cosmjs/crypto": "0.29.4",
"@cosmjs/proto-signing": "^0.29.5",
"@cosmjs/stargate": "0.29.4",
"secretjs": "^1.11.1",
"sinon": "17.0.1"
},
"devDependencies": {
"@types/node": "^18.11.18",
"ts-node": "10.9.1",
"typescript": "4.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment