Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ build
/relay
*.out
.nx

.env
106 changes: 65 additions & 41 deletions packages/relay-relayer/src/client/contract_relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions packages/relay-relayer/test/simple.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});