Skip to content

Commit

Permalink
hot_fix: make the relayer work after v0.50.0
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed Nov 15, 2024
1 parent 16d8bf7 commit 6ce388a
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 181 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@babel/traverse": "7.24.1",
"@oraichain/cw-simulate": "^2.8.103",
"@oraichain/cw-simulate": "^2.8.104",
"@swc/core": "^1.4.11",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-to-ton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"dependencies": {
"@oraichain/cosmos-rpc-sync": "next",
"@oraichain/cosmos-rpc-sync": "^2.1.2",
"@oraichain/oraidex-common": "^1.1.29",
"@oraichain/ton-bridge-contracts": "^0.15.9",
"@oraichain/tonbridge-contracts-sdk": "^1.3.6",
Expand Down
35 changes: 35 additions & 0 deletions packages/cw-to-ton/src/scripts/queryBridgeAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { QueryClient } from "@cosmjs/stargate";
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
import { parseWasmEvents } from "@oraichain/oraidex-common";
import {
BridgeAdapter,
getExistenceProofSnakeCell,
getPacketProofs,
} from "@oraichain/ton-bridge-contracts";
import { Network } from "@orbs-network/ton-access";
import { TransferPacket } from "../dtos/packets/TransferPacket";
import { BRIDGE_WASM_ACTION } from "../services";
import { createTonWallet, waitSeqno } from "../utils";
import { Address, toNano, TupleItemCell } from "@ton/core";
import { ExistenceProof } from "cosmjs-types/cosmos/ics23/v1/proofs";
import * as dotenv from "dotenv";
dotenv.config();
const argv = process.argv.slice(2);
const provenHeight = parseInt(argv[0]);
const packetTx = argv[1];

(async () => {
const needProvenHeight = provenHeight + 1;
const { client, walletContract, key } = await createTonWallet(
process.env.TON_MNEMONIC!,
process.env.NODE_ENV as Network
);
const bridgeAdapter = BridgeAdapter.createFromAddress(
Address.parse(process.env.TON_BRIDGE!)
);
const bridgeAdapterContract = client.open(bridgeAdapter);
const data = await bridgeAdapterContract.getBridgeData();
const lightClientMaster = (data.pop() as TupleItemCell).cell;
console.log(lightClientMaster.beginParse().loadAddress());
})();
34 changes: 34 additions & 0 deletions packages/cw-to-ton/src/scripts/queryLightClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { QueryClient } from "@cosmjs/stargate";
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
import { parseWasmEvents } from "@oraichain/oraidex-common";
import {
BridgeAdapter,
getExistenceProofSnakeCell,
getPacketProofs,
LightClientMaster,
} from "@oraichain/ton-bridge-contracts";
import { Network } from "@orbs-network/ton-access";
import { TransferPacket } from "../dtos/packets/TransferPacket";
import { BRIDGE_WASM_ACTION } from "../services";
import { createTonWallet, waitSeqno } from "../utils";
import { Address, toNano } from "@ton/core";
import { ExistenceProof } from "cosmjs-types/cosmos/ics23/v1/proofs";
import * as dotenv from "dotenv";
dotenv.config();

(async () => {
const { client, walletContract, key } = await createTonWallet(
process.env.TON_MNEMONIC!,
process.env.NODE_ENV as Network
);
const lightClientMaster = LightClientMaster.createFromAddress(
Address.parse(process.env.COSMOS_LIGHT_CLIENT_MASTER!)
);
const lightClientMasterContract = client.open(lightClientMaster);
const cosmwasmClient = await CosmWasmClient.connect(
process.env.COSMOS_RPC_URL!
);

console.log("Height", await lightClientMasterContract.getTrustedHeight());
})();
25 changes: 15 additions & 10 deletions packages/cw-to-ton/src/scripts/relayUnsentPacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
getPacketProofs,
} from "@oraichain/ton-bridge-contracts";
import { Network } from "@orbs-network/ton-access";
import { TransferPacket } from "@src/dtos/packets/TransferPacket";
import { BRIDGE_WASM_ACTION } from "@src/services";
import { createTonWallet, waitSeqno } from "@src/utils";
import { TransferPacket } from "../dtos/packets/TransferPacket";
import { BRIDGE_WASM_ACTION } from "../services";
import { createTonWallet, waitSeqno } from "../utils";
import { Address, toNano } from "@ton/core";
import { ExistenceProof } from "cosmjs-types/cosmos/ics23/v1/proofs";
import * as dotenv from "dotenv";
Expand All @@ -22,18 +22,22 @@ const packetTx = argv[1];
(async () => {
const needProvenHeight = provenHeight + 1;
const { client, walletContract, key } = await createTonWallet(
process.env.TON_MNEMONIC,
process.env.TON_MNEMONIC!,
process.env.NODE_ENV as Network
);
const bridgeAdapter = BridgeAdapter.createFromAddress(
Address.parse(process.env.TON_BRIDGE)
Address.parse(process.env.TON_BRIDGE!)
);
const bridgeAdapterContract = client.open(bridgeAdapter);
console.log(await bridgeAdapterContract.getBridgeData());
// process.env.COSMOS_RPC_URL!
const cosmwasmClient = await CosmWasmClient.connect(
process.env.COSMOS_RPC_URL
"http://3.14.142.99:26657"
);
console.log(packetTx);
const tx = await cosmwasmClient.getTx(packetTx);
const wasmAttr = parseWasmEvents(tx.events);
console.log(tx);
const wasmAttr = parseWasmEvents(tx!.events);
const filterByContractAddress = (attr: Record<string, string>) =>
attr["_contract_address"] === process.env.WASM_BRIDGE;
// This action come from user need to normalize and submit by relayer.
Expand All @@ -44,26 +48,27 @@ const packetTx = argv[1];

const transferPacket = TransferPacket.fromRawAttributes(packetEvent);
const tendermint37 = await Tendermint37Client.connect(
process.env.COSMOS_RPC_URL
process.env.COSMOS_RPC_URL as string
);
const queryClient = new QueryClient(tendermint37 as any);
console.log(provenHeight, BigInt(packetEvent["seq"]));
const packetProofs = await getPacketProofs(
queryClient,
process.env.WASM_BRIDGE,
process.env.WASM_BRIDGE as string,
provenHeight,
BigInt(packetEvent["seq"])
);

const proofs = packetProofs.map((proof) => {
return ExistenceProof.fromJSON(proof);
});

await bridgeAdapterContract.sendBridgeRecvPacket(
walletContract.sender(key.secretKey),
{
provenHeight: needProvenHeight,
packet: transferPacket.intoCell(),
proofs: getExistenceProofSnakeCell(proofs as any),
proofs: getExistenceProofSnakeCell(proofs as any)!,
},
{ value: toNano("0.7") }
);
Expand Down
16 changes: 7 additions & 9 deletions packages/cw-to-ton/src/services/cosmos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ export class CosmwasmBridgeParser implements ICosmwasmParser<Packets> {
const allBridgeData = txs
.filter(filterOutSuccessTx)
.flatMap((tx) => {
const logs: Log[] = JSON.parse(tx.rawLog);
return logs.map((log) =>
this.extractEventToPacketDtos(
log.events,
tx.hash,
tx.height,
tx.timestamp
)
return this.extractEventToPacketDtos(
tx.events,
tx.hash,
tx.height,
tx.timestamp
);
})
.filter(
Expand Down Expand Up @@ -129,7 +126,7 @@ export class CosmwasmWatcher<T> extends EventEmitter {
this.syncData.destroy();
}
this.running = true;
await this.syncData.start();
this.syncData.startSpecificService("polling");
this.syncData.on(CHANNEL.QUERY, async (chunk: Txs) => {
try {
const parsedData = this.cosmwasmParser.processChunk(chunk) as Packets;
Expand Down Expand Up @@ -325,6 +322,7 @@ export const createCosmosBridgeWatcher = async (config: Config) => {
syncDataOpt.offset = config.syncBlockOffSet;
}
const syncData = new SyncData(syncDataOpt);
await syncData.initClient();
const bridgeParser = new CosmwasmBridgeParser(config.wasmBridge);
const cosmwasmWatcher = new CosmwasmWatcher(syncData, bridgeParser);
return cosmwasmWatcher;
Expand Down
2 changes: 1 addition & 1 deletion packages/orchestrator/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Config = {
export function loadConfig(): Config {
const cwToTon: CwToTonConfig = {
tonMnemonic: process.env.TON_MNEMONIC || "",
cosmosRpcUrl: process.env.COSMOS_RPC_URL || "https://rpc.orai.io/",
cosmosRpcUrl: process.env.COSMOS_RPC_URL || "https://indexer.orai.io/",
syncBlockOffSet: Number(process.env.SYNC_BLOCK_OFFSET || 20000000),
syncLimit: Number(process.env.SYNC_LIMIT || 50),
syncThreads: Number(process.env.SYNC_THREADS || 4),
Expand Down
Loading

0 comments on commit 6ce388a

Please sign in to comment.