Skip to content

Commit

Permalink
fix: handle decode ibc memo on vault trading transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed May 4, 2024
1 parent 0892dee commit 989d0e2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
13 changes: 9 additions & 4 deletions packages/ibc-routing/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import dotenv from "dotenv";
dotenv.config();
// import dotenv from "dotenv";
// dotenv.config();

// export const config = {
// ORAIBRIDGE_RPC_URL: process.env.ORAIBRIDGE_RPC_URL ?? "https://bridge-v2.rpc.orai.io",
// ORAICHAIN_RPC_URL: process.env.ORAICHAIN_RPC_URL ?? "https://rpc.orai.io"
// };

export const config = {
ORAIBRIDGE_RPC_URL: process.env.ORAIBRIDGE_RPC_URL ?? "https://bridge-v2.rpc.orai.io",
ORAICHAIN_RPC_URL: process.env.ORAICHAIN_RPC_URL ?? "https://rpc.orai.io"
ORAIBRIDGE_RPC_URL: "https://bridge-v2.rpc.orai.io",
ORAICHAIN_RPC_URL: "https://rpc.orai.io"
};
12 changes: 10 additions & 2 deletions packages/ibc-routing/src/intepreters/handlers/common.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export const handleStoreOnRecvPacketOraichain = async (
const packetAckAttr = writeAckEvent.attributes.find((attr) => attr.key === "packet_ack");
if (!packetAckAttr) throw generateError("Could not find packet ack attr in storeOnRecvPacketOraichain");
const packetDataAttr = JSON.parse(writeAckEvent.attributes.find((attr) => attr.key === "packet_data").value);
console.log("Memo:", decodeIbcMemo(packetDataAttr.memo, false));
// console.log("Memo:", decodeIbcMemo(packetDataAttr.memo, false));

// packet ack format: {"result":"MQ=="} or {"result":"<something-else-in-base-64"}
const packetAck = JSON.parse(packetAckAttr.value).result;
Expand Down Expand Up @@ -640,7 +640,15 @@ export const handleStoreOnRecvPacketOraichain = async (
if (!memo) {
return false;
}
const decodeMemo = decodeIbcMemo(memo);

// The error case from Vault Trading Contract, so we have to handle it also
let decodeMemo = {
destinationReceiver: memo
};
try {
decodeMemo = decodeIbcMemo(memo);
} catch (err) {}

// which mean it does not have send packet
if (decodeMemo.destinationReceiver.includes("orai1")) {
return false;
Expand Down
18 changes: 9 additions & 9 deletions packages/ibc-routing/test/sample.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ describe("Test sync ether", () => {
ethers.utils.getAddress("0xb40C364e70bbD98E8aaab707A41a52A2eAF5733f"),
provider
);
// const eventFilter = gravity.filters["SendToCosmosEvent(address,address,string,uint256,uint256)"](
// "0x55d398326f99059fF775485246999027B3197955",
// "0x9a0A02B296240D2620E339cCDE386Ff612f07Be5"
// );
const eventFilter = gravity.filters["TransactionBatchExecutedEvent(uint256,address,uint256)"](
32408,
"0x55d398326f99059fF775485246999027B3197955"
const eventFilter = gravity.filters["SendToCosmosEvent(address,address,string,uint256,uint256)"](
"0x55d398326f99059fF775485246999027B3197955",
"0x9a0A02B296240D2620E339cCDE386Ff612f07Be5"
);
const data = await gravity.queryFilter(eventFilter, 38318558, 38318558);
console.log(data[1]);
// const eventFilter = gravity.filters["TransactionBatchExecutedEvent(uint256,address,uint256)"](
// 32408,
// "0x55d398326f99059fF775485246999027B3197955"
// );
const data = await gravity.queryFilter(eventFilter, 38421000, 38421649);
console.log(data);
});
});

Expand Down
15 changes: 11 additions & 4 deletions packages/ibc-routing/test/search-tx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import { buildQuery } from "@cosmjs/tendermint-rpc/build/tendermint37/requests";
describe("Testing searchTx using rpc", () => {
it("Try testing stargate-client query", async () => {
const queryTags: QueryTag[] = [
{ key: "batched_tx_ids.batched_tx_id", value: "34116" },
{
key: "gravity.v1.EventOutgoingBatch.bridge_contract",
value: "0xb40C364e70bbD98E8aaab707A41a52A2eAF5733f"
key: `send_packet.packet_sequence`,
value: `${"22866"}`
},
{
key: `send_packet.packet_src_channel`,
value: "channel-29"
},
{
key: `send_packet.packet_dst_channel`,
value: "channel-1"
}
];
const query = buildQuery({
tags: queryTags
});
const stargateClient = await StargateClient.connect("https://bridge-v2.rpc.orai.io");
const stargateClient = await StargateClient.connect("https://rpc.orai.io");
const txs = await stargateClient.searchTx(query);

console.log(txs);
Expand Down

0 comments on commit 989d0e2

Please sign in to comment.