From f6c534fa02e8b48f57d2b618e9690e6261d83fe0 Mon Sep 17 00:00:00 2001 From: fewensa Date: Wed, 17 Sep 2025 04:36:09 +0000 Subject: [PATCH 1/2] Enhance relay method with static call and error handling for Tron transactions --- .../src/client/contract_relayer.ts | 106 +++++++++++------- 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/packages/relay-relayer/src/client/contract_relayer.ts b/packages/relay-relayer/src/client/contract_relayer.ts index c6eeb76..ece8a02 100644 --- a/packages/relay-relayer/src/client/contract_relayer.ts +++ b/packages/relay-relayer/src/client/contract_relayer.ts @@ -122,15 +122,32 @@ export class RelayerContractClient { options.message.gasLimit, options.message.encoded, ]) - .send( - feeLimit ? { "feeLimit": feeLimit } : { "feeLimit": 300_000000 } - ); + .send(feeLimit ? { feeLimit: feeLimit } : { feeLimit: 300_000000 }); console.log("Relay on Tron", tronResult); return tronResult; } catch (e) { console.error("Relay on Tron error: ", e); } } else { + try { + const result = await this.contract["relay"].staticCall( + options.message, + contractOptions + ); + if (result) { + logger.info("relayer.relay static call success, result: %o", result, { + target: "ormpipe-relay", + breads: ["contract", this.config.chainName], + }); + } + } catch (e) { + logger.error("relayer.relay static call failed, error: %o", e, { + target: "ormpipe-relay", + breads: ["contract", this.config.chainName], + }); + throw new Error("relayer.relay static call failed: error: " + e); + } + const tx = await this.contract["relay"](options.message, contractOptions); return await tx.wait(); } @@ -141,54 +158,61 @@ export class RelayerContractClient { this._tronweb.address.fromPrivateKey(this.config.signer) ); - const rawParameter = this._tronweb.utils.abi.encodeParamsV2ByABI({ - "inputs": [ - { - "components": [ - { "internalType": "address", "name": "channel", "type": "address" }, - { "internalType": "uint256", "name": "index", "type": "uint256" }, - { - "internalType": "uint256", - "name": "fromChainId", - "type": "uint256" - }, - { "internalType": "address", "name": "from", "type": "address" }, - { "internalType": "uint256", "name": "toChainId", "type": "uint256" }, - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "gasLimit", "type": "uint256" }, - { "internalType": "bytes", "name": "encoded", "type": "bytes" } - ], - "internalType": "struct Message", - "name": "message", - "type": "tuple" - } - ], - "name": "relay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, [[ - options.message.channel, - options.message.index, - options.message.fromChainId, - options.message.from, - options.message.toChainId, - options.message.to, - options.message.gasLimit, - options.message.encoded, - ]]) + const rawParameter = this._tronweb.utils.abi.encodeParamsV2ByABI( + { + inputs: [ + { + components: [ + { internalType: "address", name: "channel", type: "address" }, + { internalType: "uint256", name: "index", type: "uint256" }, + { + internalType: "uint256", + name: "fromChainId", + type: "uint256", + }, + { internalType: "address", name: "from", type: "address" }, + { internalType: "uint256", name: "toChainId", type: "uint256" }, + { internalType: "address", name: "to", type: "address" }, + { internalType: "uint256", name: "gasLimit", type: "uint256" }, + { internalType: "bytes", name: "encoded", type: "bytes" }, + ], + internalType: "struct Message", + name: "message", + type: "tuple", + }, + ], + name: "relay", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + [ + [ + options.message.channel, + options.message.index, + options.message.fromChainId, + options.message.from, + options.message.toChainId, + options.message.to, + options.message.gasLimit, + options.message.encoded, + ], + ] + ); try { const _result = await this._tronweb.transactionBuilder.estimateEnergy( this.config.address.replace("0x", "41"), "relay((address,uint256,uint256,address,uint256,address,uint256,bytes))", { shieldedParameter: rawParameter }, - [], tronPubKey) + [], + tronPubKey + ); const energyRequired = _result.energy_required; const energyPricesResult = await this._tronweb.trx.getEnergyPrices(); console.log(energyPricesResult); const energyPrices = energyPricesResult.split(","); - const latestPrice = (energyPrices[energyPrices.length - 1].split(":"))[1]; + const latestPrice = energyPrices[energyPrices.length - 1].split(":")[1]; const feeLimit = Math.ceil(1.1 * energyRequired * latestPrice); console.log("estimate energy: ", energyRequired, latestPrice, feeLimit); return feeLimit; From 6784b054a076f0409e189f25e15973448d5e4a2c Mon Sep 17 00:00:00 2001 From: fewensa Date: Wed, 17 Sep 2025 05:28:11 +0000 Subject: [PATCH 2/2] Add static call test for relay method with environment variable support --- .gitignore | 2 ++ packages/relay-relayer/test/simple.test.ts | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.gitignore b/.gitignore index 5ca3081..fc2e2d3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ build /relay *.out .nx + +.env diff --git a/packages/relay-relayer/test/simple.test.ts b/packages/relay-relayer/test/simple.test.ts index a881ff4..2ba5414 100644 --- a/packages/relay-relayer/test/simple.test.ts +++ b/packages/relay-relayer/test/simple.test.ts @@ -1,4 +1,32 @@ +import { ethers } from "ethers"; + + +const abi = require("../../../assets/abis/v2/Relayer.json"); test('simple-test', () => { expect(3).toBe(3) }) + +test.skip('test-static-call', async () => { + const signerKey = process.env['SIGNING_KEY']; + const evm = new ethers.JsonRpcProvider('https://eth-mainnet.public.blastapi.io'); + const wallet = new ethers.Wallet(signerKey!, evm); + const contract: ethers.Contract = new ethers.Contract('0x114890eB7386F94eae410186F20968bFAf66142a', abi, wallet); + + const result = await contract["relay"].staticCall( + { + channel: '0x13b2211a7cA45Db2808F6dB05557ce5347e3634e', + index: 9592, + fromChainId: 46, + from: '0x2cd1867Fb8016f93710B6386f7f9F1D540A60812', + toChainId: 1, + to: '0x2cd1867Fb8016f93710B6386f7f9F1D540A60812', + gasLimit: 225920, + encoded: '0x394d1bca000000000000000000000000682294d1c00a9ca13290b53b7544b8f734d6501f00000000000000000000000002e5c0a36fb0c83ccebcd4d6177a7e223d6f0b7c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000002641841a477000000000000000000000000000000000000000000000000000000000000002e0000000000000000000000002b496f19a420c02490db859fefeccd71edc2c046000000000000000000000000dc0c760c0fb4672d06088515f6446a71df0c64c1000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001a4e80f03d0000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000e7578598aac020abfb918f33a20fad5b71d670b4000000000000000000000000092e19c46c9daab7824393f1cd9c22f5bea135600000000000000000000000004ca75992d2750bec270731a72dfdede6b9e71cc7000000000000000000000000b0d1b94ab8abba458377975aba226beef00df19200000000000000000000000000000000000000000000aedaf79ab5a96c2c000000000000000000000000000000000000000000000000000000000199248e08fd00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000c29dcb1f12a1618262ef9fba673b77140adc02d600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000014b0d1b94ab8abba458377975aba226beef00df1920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + }, + { + gasLimit: 449506, + } + ); + console.log(result); +});