This package makes it easier to interact with Tenderly API for simulating transactions. It exposes functions to gather transaction information, simulate transactions and apply overrides such as faking approvals and token balances.
In order to use this package you will need to add this line in your package.json
using the npm github syntax as follows:
"@lifi/tenderlysim": "git@github.com:lifinance/tenderly-sim"
const quote = await http()
.get<LiFiStep>(
'https://li.quest/v1/quote?fromChain=POL&fromAmount=1000000&fromToken=USDC&fromAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&toChain=POL&toToken=DAI&integrator=postman&slippage=0.03'
)
.then((q) => q.data)
const config: TenderlyConfig = {
accessKey: '---',
user: 'LiFi',
project: 'simulate',
}
logger().info(quote)
const sim = await simulate(config)(
{
fromToken: quote.action.fromToken.address,
toToken: quote.action.toToken.address,
fromChain: quote.action.fromChainId,
fromAmount: BigInt(quote.action.fromAmount),
transactionRequest: quote.transactionRequest!,
},
{
senderTokenBalanceAndApproval: true,
senderNativeBalance: false,
}
)
which results in the following response:
{
"result": "WORKED",
"simulation": {
"id": "191d2b0b-e92f-46fc-809a-3edb089a3dc8",
"project_id": "f7c3f141-bf2e-4e27-bb24-d4f5c355455a",
"owner_id": "367f1f0a-a61e-4397-b4d1-1222ffa42777",
"network_id": "137",
"block_number": 60500475,
"transaction_index": 0,
"from": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
"to": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"input": "0x4666fc809022dcd5929a421d9df95e5be8c5a00fa845c320b876f6f58ff76398626e8b9700000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000552008c0f6870c2f77e5cc1d2eb9bdff03e30ea00000000000000000000000000000000000000000000000000d76664c066ba77a00000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000007706f73746d616e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a3078303030303030303030303030303030303030303030303030303030303030303030303030303030300000000000000000000000000000000000000000000000000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e0000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000008f3cf7ad23cd3cadbd9735aff958023239c6a06300000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001442646478b0000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c335900000000000000000000000000000000000000000000000000000000000f42400000000000000000000000008f3cf7ad23cd3cadbd9735aff958023239c6a0630000000000000000000000000000000000000000000000000d76664c066ba77a0000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000042023c499c542cef5e3811e1192ce70d8cc03d5c335901ffff01bc8f3da0bd42e1f2509cd8671ce7c7e5f7fd39c8011231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gas": 640103,
"gas_price": "33000000036",
"gas_used": 368375,
"value": "0",
"method": "swapTokensSingleV3ERC20ToERC20",
"status": true,
"access_list": null,
"queue_origin": "",
"block_header": {
"number": "0x39b29fb",
"hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x5a70a6bf770a0c8cdfb96bd5f0555e9f98a33e73afaeb3d36415b7c995392c62",
"sha3Uncles": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptsRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x66ba08fc",
"difficulty": "0x17",
"gasLimit": "0x1c78737",
"gasUsed": "0x79aa04",
"miner": "0x0000000000000000000000000000000000000000",
"extraData": "0xd78301030683626f7288676f312e32322e36856c696e75780000000000000000f87580f872c0c0c0c0c0c0c103c0c0c108c180c0c0c0c0c10cc101c110c0c111c0c0c115c116c113c117c119c11ac11bc11cc11dc118c11fc120c121c0c123c10fc0c122c127c0c129c0c101c0c12dc12ec0c128c131c0c133c20a34c0c0c137c138c0c0c0c0c125c135c13fc0c0c20c35c0c0c0c132c0fefbb33b097ed70b4eb69b2c51eac3273421ffb0892e7a746ea24b1a350da78348db1d29b0371bec11071dcda93d033d27a7aed08e2d5900d6a0d0b0729fc3bf00",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"baseFeePerGas": "0x1",
"size": "0x0",
"totalDifficulty": "0x0",
"uncles": null,
"transactions": null
},
"state_overrides": {
"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359": {
"storage": {
"0x1b97ad081d0128f22397aee12eada728ac24d30fb68803f99829a39e3486bf47": "0x00000000000000000000000000000000000000000000000000000000000f4240",
"0xb26e7f10e47fab21d4150c3b04278a58e182f70019f420f00f371a8fb881fe15": "0x00000000000000000000000000000000000000000000000000000000000f4240"
}
}
},
"deposit_tx": false,
"system_tx": false,
"nonce": 4852,
"addresses": [
"0x552008c0f6870c2f77e5cc1d2eb9bdff03e30ea0",
"0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
"0x31a9b1835864706af10103b31ea2b79bdb995f5f",
"0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"0x235ae97b28466db30469b89a9fe4cff0659f82cb",
"0x46b3fdf7b5cde91ac049936bf0bdb12c5d22202e",
"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
"0x490e379c9cff64944be82b849f8fd5972c7999a7",
"0xbc8f3da0bd42e1f2509cd8671ce7c7e5f7fd39c8",
"0x6394c365fd17fb316c34ba60610067abdf88a7b1",
"0x411b0facc3489691f28ad58c47006af5e3ab3a28"
],
"contract_ids": [
"eth:137:0x552008c0f6870c2f77e5cc1d2eb9bdff03e30ea0",
"eth:137:0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae",
"eth:137:0x31a9b1835864706af10103b31ea2b79bdb995f5f",
"eth:137:0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"eth:137:0x235ae97b28466db30469b89a9fe4cff0659f82cb",
"eth:137:0x46b3fdf7b5cde91ac049936bf0bdb12c5d22202e",
"eth:137:0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
"eth:137:0x490e379c9cff64944be82b849f8fd5972c7999a7",
"eth:137:0xbc8f3da0bd42e1f2509cd8671ce7c7e5f7fd39c8",
"eth:137:0x6394c365fd17fb316c34ba60610067abdf88a7b1",
"eth:137:0x411b0facc3489691f28ad58c47006af5e3ab3a28"
],
"shared": false,
"created_at": "2024-08-12T13:07:09.414383789Z"
},
"link": "https://dashboard.tenderly.co/LiFi/simulate/simulator/191d2b0b-e92f-46fc-809a-3edb089a3dc8"
}
The supported chains have to be matched between the chains Tenderly supports and the chain LI.FI has types for.
-
Run
pnpm update
to load the newest types version of LI.FI. -
Visit the Tenderly docs to see what chains were added
-
Add new chains in ./src/tenderly/tenderly.config.ts
-
Push changes as a PR for review