@across-protocol/sdk 4.3.138 → 4.3.139-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/arch/evm/UpgradeUtils.d.ts +2 -0
- package/dist/cjs/src/arch/evm/UpgradeUtils.js +33 -0
- package/dist/cjs/src/arch/evm/UpgradeUtils.js.map +1 -0
- package/dist/cjs/src/arch/evm/index.d.ts +1 -0
- package/dist/cjs/src/arch/evm/index.js +1 -0
- package/dist/cjs/src/arch/evm/index.js.map +1 -1
- package/dist/cjs/src/arch/index.d.ts +1 -0
- package/dist/cjs/src/arch/index.js +2 -1
- package/dist/cjs/src/arch/index.js.map +1 -1
- package/dist/cjs/src/arch/tvm/BlockUtils.d.ts +1 -0
- package/dist/cjs/src/arch/tvm/BlockUtils.js +7 -0
- package/dist/cjs/src/arch/tvm/BlockUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/MessageUtils.d.ts +1 -0
- package/dist/cjs/src/arch/tvm/MessageUtils.js +5 -0
- package/dist/cjs/src/arch/tvm/MessageUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/ResourceUtils.d.ts +14 -0
- package/dist/cjs/src/arch/tvm/ResourceUtils.js +69 -0
- package/dist/cjs/src/arch/tvm/ResourceUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/SpokeUtils.d.ts +12 -0
- package/dist/cjs/src/arch/tvm/SpokeUtils.js +207 -0
- package/dist/cjs/src/arch/tvm/SpokeUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/TransactionUtils.d.ts +7 -0
- package/dist/cjs/src/arch/tvm/TransactionUtils.js +45 -0
- package/dist/cjs/src/arch/tvm/TransactionUtils.js.map +1 -0
- package/dist/cjs/src/arch/tvm/index.d.ts +6 -0
- package/dist/cjs/src/arch/tvm/index.js +10 -0
- package/dist/cjs/src/arch/tvm/index.js.map +1 -0
- package/dist/cjs/src/arch/tvm/types.d.ts +2 -0
- package/dist/cjs/src/arch/tvm/types.js +3 -0
- package/dist/cjs/src/arch/tvm/types.js.map +1 -0
- package/dist/cjs/src/arch/tvm/utils/address.d.ts +3 -0
- package/dist/cjs/src/arch/tvm/utils/address.js +17 -0
- package/dist/cjs/src/arch/tvm/utils/address.js.map +1 -0
- package/dist/cjs/src/arch/tvm/utils/index.d.ts +2 -0
- package/dist/cjs/src/arch/tvm/utils/index.js +6 -0
- package/dist/cjs/src/arch/tvm/utils/index.js.map +1 -0
- package/dist/cjs/src/arch/tvm/utils/wait.d.ts +1 -0
- package/dist/cjs/src/{caching/IPFS/index.js → arch/tvm/utils/wait.js} +2 -2
- package/dist/cjs/src/arch/tvm/utils/wait.js.map +1 -0
- package/dist/cjs/src/caching/index.d.ts +0 -1
- package/dist/cjs/src/caching/index.js +0 -1
- package/dist/cjs/src/caching/index.js.map +1 -1
- package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +9 -2
- package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.js +33 -12
- package/dist/cjs/src/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/src/clients/SpokePoolClient/TVMSpokePoolClient.d.ts +11 -0
- package/dist/cjs/src/clients/SpokePoolClient/TVMSpokePoolClient.js +47 -0
- package/dist/cjs/src/clients/SpokePoolClient/TVMSpokePoolClient.js.map +1 -0
- package/dist/cjs/src/clients/SpokePoolClient/index.d.ts +3 -0
- package/dist/cjs/src/clients/SpokePoolClient/index.js +7 -1
- package/dist/cjs/src/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/cjs/src/clients/SpokePoolClient/types.d.ts +1 -0
- package/dist/cjs/src/clients/SpokePoolClient/types.js +2 -1
- package/dist/cjs/src/clients/SpokePoolClient/types.js.map +1 -1
- package/dist/cjs/src/clients/index.d.ts +1 -1
- package/dist/cjs/src/clients/index.js +3 -1
- package/dist/cjs/src/clients/index.js.map +1 -1
- package/dist/cjs/src/gasPriceOracle/oracle.js +1 -0
- package/dist/cjs/src/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.d.ts +79 -151
- package/dist/cjs/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/src/relayFeeCalculator/relayFeeCalculator.d.ts +77 -150
- package/dist/cjs/src/utils/AddressUtils.d.ts +11 -0
- package/dist/cjs/src/utils/AddressUtils.js +52 -1
- package/dist/cjs/src/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/src/utils/Multicall.js +1 -0
- package/dist/cjs/src/utils/Multicall.js.map +1 -1
- package/dist/cjs/src/utils/NetworkUtils.d.ts +1 -0
- package/dist/cjs/src/utils/NetworkUtils.js +9 -3
- package/dist/cjs/src/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/src/utils/TokenUtils.d.ts +154 -300
- package/dist/cjs/src/utils/TypeGuards.d.ts +3 -1
- package/dist/cjs/src/utils/TypeGuards.js +5 -0
- package/dist/cjs/src/utils/TypeGuards.js.map +1 -1
- package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.d.ts +42 -0
- package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.js +3 -0
- package/dist/cjs/src/utils/abi/typechain/SP1AutoVerifier.js.map +1 -0
- package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +26 -0
- package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js +43 -0
- package/dist/cjs/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js.map +1 -0
- package/dist/cjs/src/utils/abi/typechain/factories/index.d.ts +1 -0
- package/dist/cjs/src/utils/abi/typechain/factories/index.js +4 -2
- package/dist/cjs/src/utils/abi/typechain/factories/index.js.map +1 -1
- package/dist/cjs/src/utils/abi/typechain/index.d.ts +2 -0
- package/dist/cjs/src/utils/abi/typechain/index.js +4 -2
- package/dist/cjs/src/utils/abi/typechain/index.js.map +1 -1
- package/dist/cjs/src/utils/index.d.ts +0 -1
- package/dist/cjs/src/utils/index.js +0 -1
- package/dist/cjs/src/utils/index.js.map +1 -1
- package/dist/esm/src/arch/evm/UpgradeUtils.d.ts +9 -0
- package/dist/esm/src/arch/evm/UpgradeUtils.js +37 -0
- package/dist/esm/src/arch/evm/UpgradeUtils.js.map +1 -0
- package/dist/esm/src/arch/evm/index.d.ts +1 -0
- package/dist/esm/src/arch/evm/index.js +1 -0
- package/dist/esm/src/arch/evm/index.js.map +1 -1
- package/dist/esm/src/arch/index.d.ts +1 -0
- package/dist/esm/src/arch/index.js +2 -0
- package/dist/esm/src/arch/index.js.map +1 -1
- package/dist/esm/src/arch/tvm/BlockUtils.d.ts +1 -0
- package/dist/esm/src/arch/tvm/BlockUtils.js +2 -0
- package/dist/esm/src/arch/tvm/BlockUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/MessageUtils.d.ts +1 -0
- package/dist/esm/src/arch/tvm/MessageUtils.js +2 -0
- package/dist/esm/src/arch/tvm/MessageUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/ResourceUtils.d.ts +32 -0
- package/dist/esm/src/arch/tvm/ResourceUtils.js +88 -0
- package/dist/esm/src/arch/tvm/ResourceUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/SpokeUtils.d.ts +48 -0
- package/dist/esm/src/arch/tvm/SpokeUtils.js +237 -0
- package/dist/esm/src/arch/tvm/SpokeUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/TransactionUtils.d.ts +20 -0
- package/dist/esm/src/arch/tvm/TransactionUtils.js +57 -0
- package/dist/esm/src/arch/tvm/TransactionUtils.js.map +1 -0
- package/dist/esm/src/arch/tvm/index.d.ts +6 -0
- package/dist/esm/src/arch/tvm/index.js +7 -0
- package/dist/esm/src/arch/tvm/index.js.map +1 -0
- package/dist/esm/src/arch/tvm/types.d.ts +2 -0
- package/dist/esm/src/arch/tvm/types.js +2 -0
- package/dist/esm/src/arch/tvm/types.js.map +1 -0
- package/dist/esm/src/arch/tvm/utils/address.d.ts +18 -0
- package/dist/esm/src/arch/tvm/utils/address.js +31 -0
- package/dist/esm/src/arch/tvm/utils/address.js.map +1 -0
- package/dist/esm/src/arch/tvm/utils/index.d.ts +2 -0
- package/dist/esm/src/arch/tvm/utils/index.js +3 -0
- package/dist/esm/src/arch/tvm/utils/index.js.map +1 -0
- package/dist/esm/src/arch/tvm/utils/wait.d.ts +1 -0
- package/dist/esm/src/arch/tvm/utils/wait.js +2 -0
- package/dist/esm/src/arch/tvm/utils/wait.js.map +1 -0
- package/dist/esm/src/caching/index.d.ts +0 -1
- package/dist/esm/src/caching/index.js +0 -1
- package/dist/esm/src/caching/index.js.map +1 -1
- package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +20 -2
- package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.js +44 -12
- package/dist/esm/src/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/src/clients/SpokePoolClient/TVMSpokePoolClient.d.ts +32 -0
- package/dist/esm/src/clients/SpokePoolClient/TVMSpokePoolClient.js +66 -0
- package/dist/esm/src/clients/SpokePoolClient/TVMSpokePoolClient.js.map +1 -0
- package/dist/esm/src/clients/SpokePoolClient/index.d.ts +8 -0
- package/dist/esm/src/clients/SpokePoolClient/index.js +10 -1
- package/dist/esm/src/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/esm/src/clients/SpokePoolClient/types.d.ts +1 -0
- package/dist/esm/src/clients/SpokePoolClient/types.js +1 -0
- package/dist/esm/src/clients/SpokePoolClient/types.js.map +1 -1
- package/dist/esm/src/clients/index.d.ts +1 -1
- package/dist/esm/src/clients/index.js +1 -1
- package/dist/esm/src/clients/index.js.map +1 -1
- package/dist/esm/src/gasPriceOracle/oracle.js +1 -0
- package/dist/esm/src/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/src/relayFeeCalculator/chain-queries/factory.d.ts +79 -151
- package/dist/esm/src/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/src/relayFeeCalculator/relayFeeCalculator.d.ts +77 -150
- package/dist/esm/src/utils/AddressUtils.d.ts +11 -0
- package/dist/esm/src/utils/AddressUtils.js +59 -1
- package/dist/esm/src/utils/AddressUtils.js.map +1 -1
- package/dist/esm/src/utils/Multicall.js +1 -0
- package/dist/esm/src/utils/Multicall.js.map +1 -1
- package/dist/esm/src/utils/NetworkUtils.d.ts +6 -0
- package/dist/esm/src/utils/NetworkUtils.js +13 -3
- package/dist/esm/src/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/src/utils/TokenUtils.d.ts +154 -300
- package/dist/esm/src/utils/TypeGuards.d.ts +3 -1
- package/dist/esm/src/utils/TypeGuards.js +4 -0
- package/dist/esm/src/utils/TypeGuards.js.map +1 -1
- package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.d.ts +42 -0
- package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.js +2 -0
- package/dist/esm/src/utils/abi/typechain/SP1AutoVerifier.js.map +1 -0
- package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +26 -0
- package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js +43 -0
- package/dist/esm/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.js.map +1 -0
- package/dist/esm/src/utils/abi/typechain/factories/index.d.ts +1 -0
- package/dist/esm/src/utils/abi/typechain/factories/index.js +1 -0
- package/dist/esm/src/utils/abi/typechain/factories/index.js.map +1 -1
- package/dist/esm/src/utils/abi/typechain/index.d.ts +2 -0
- package/dist/esm/src/utils/abi/typechain/index.js +1 -0
- package/dist/esm/src/utils/abi/typechain/index.js.map +1 -1
- package/dist/esm/src/utils/index.d.ts +0 -1
- package/dist/esm/src/utils/index.js +0 -1
- package/dist/esm/src/utils/index.js.map +1 -1
- package/dist/types/src/arch/evm/UpgradeUtils.d.ts +10 -0
- package/dist/types/src/arch/evm/UpgradeUtils.d.ts.map +1 -0
- package/dist/types/src/arch/evm/index.d.ts +1 -0
- package/dist/types/src/arch/evm/index.d.ts.map +1 -1
- package/dist/types/src/arch/index.d.ts +1 -0
- package/dist/types/src/arch/index.d.ts.map +1 -1
- package/dist/types/src/arch/tvm/BlockUtils.d.ts +2 -0
- package/dist/types/src/arch/tvm/BlockUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/MessageUtils.d.ts +2 -0
- package/dist/types/src/arch/tvm/MessageUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/ResourceUtils.d.ts +33 -0
- package/dist/types/src/arch/tvm/ResourceUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/SpokeUtils.d.ts +49 -0
- package/dist/types/src/arch/tvm/SpokeUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/TransactionUtils.d.ts +21 -0
- package/dist/types/src/arch/tvm/TransactionUtils.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/index.d.ts +7 -0
- package/dist/types/src/arch/tvm/index.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/types.d.ts +3 -0
- package/dist/types/src/arch/tvm/types.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/utils/address.d.ts +19 -0
- package/dist/types/src/arch/tvm/utils/address.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/utils/index.d.ts +3 -0
- package/dist/types/src/arch/tvm/utils/index.d.ts.map +1 -0
- package/dist/types/src/arch/tvm/utils/wait.d.ts +2 -0
- package/dist/types/src/arch/tvm/utils/wait.d.ts.map +1 -0
- package/dist/types/src/caching/index.d.ts +0 -1
- package/dist/types/src/caching/index.d.ts.map +1 -1
- package/dist/types/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +20 -2
- package/dist/types/src/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/src/clients/SpokePoolClient/TVMSpokePoolClient.d.ts +33 -0
- package/dist/types/src/clients/SpokePoolClient/TVMSpokePoolClient.d.ts.map +1 -0
- package/dist/types/src/clients/SpokePoolClient/index.d.ts +8 -0
- package/dist/types/src/clients/SpokePoolClient/index.d.ts.map +1 -1
- package/dist/types/src/clients/SpokePoolClient/types.d.ts +1 -0
- package/dist/types/src/clients/SpokePoolClient/types.d.ts.map +1 -1
- package/dist/types/src/clients/index.d.ts +1 -1
- package/dist/types/src/clients/index.d.ts.map +1 -1
- package/dist/types/src/relayFeeCalculator/chain-queries/factory.d.ts +79 -151
- package/dist/types/src/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/src/relayFeeCalculator/relayFeeCalculator.d.ts +77 -150
- package/dist/types/src/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/src/utils/AddressUtils.d.ts +11 -0
- package/dist/types/src/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/src/utils/Multicall.d.ts.map +1 -1
- package/dist/types/src/utils/NetworkUtils.d.ts +6 -0
- package/dist/types/src/utils/NetworkUtils.d.ts.map +1 -1
- package/dist/types/src/utils/TokenUtils.d.ts +154 -300
- package/dist/types/src/utils/TokenUtils.d.ts.map +1 -1
- package/dist/types/src/utils/TypeGuards.d.ts +3 -1
- package/dist/types/src/utils/TypeGuards.d.ts.map +1 -1
- package/dist/types/src/utils/abi/typechain/SP1AutoVerifier.d.ts +43 -0
- package/dist/types/src/utils/abi/typechain/SP1AutoVerifier.d.ts.map +1 -0
- package/dist/types/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts +27 -0
- package/dist/types/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.d.ts.map +1 -0
- package/dist/types/src/utils/abi/typechain/factories/index.d.ts +1 -0
- package/dist/types/src/utils/abi/typechain/factories/index.d.ts.map +1 -1
- package/dist/types/src/utils/abi/typechain/index.d.ts +2 -0
- package/dist/types/src/utils/abi/typechain/index.d.ts.map +1 -1
- package/dist/types/src/utils/index.d.ts +0 -1
- package/dist/types/src/utils/index.d.ts.map +1 -1
- package/package.json +10 -35
- package/src/arch/evm/UpgradeUtils.ts +18 -0
- package/src/arch/evm/index.ts +1 -0
- package/src/arch/index.ts +1 -0
- package/src/arch/tvm/BlockUtils.ts +1 -0
- package/src/arch/tvm/MessageUtils.ts +1 -0
- package/src/arch/tvm/ResourceUtils.ts +92 -0
- package/src/arch/tvm/SpokeUtils.ts +225 -0
- package/src/arch/tvm/TransactionUtils.ts +64 -0
- package/src/arch/tvm/index.ts +6 -0
- package/src/arch/tvm/types.ts +2 -0
- package/src/arch/tvm/utils/address.ts +33 -0
- package/src/arch/tvm/utils/index.ts +2 -0
- package/src/arch/tvm/utils/wait.ts +1 -0
- package/src/caching/index.ts +0 -1
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +44 -18
- package/src/clients/SpokePoolClient/TVMSpokePoolClient.ts +65 -0
- package/src/clients/SpokePoolClient/index.ts +12 -1
- package/src/clients/SpokePoolClient/types.ts +1 -0
- package/src/clients/index.ts +2 -0
- package/src/gasPriceOracle/oracle.ts +1 -0
- package/src/relayFeeCalculator/chain-queries/factory.ts +2 -1
- package/src/utils/AddressUtils.ts +61 -1
- package/src/utils/Multicall.ts +1 -0
- package/src/utils/NetworkUtils.ts +13 -3
- package/src/utils/TypeGuards.ts +6 -1
- package/src/utils/abi/contracts/SP1AutoVerifier.json +25 -0
- package/src/utils/abi/typechain/SP1AutoVerifier.ts +112 -0
- package/src/utils/abi/typechain/factories/SP1AutoVerifier__factory.ts +49 -0
- package/src/utils/abi/typechain/factories/index.ts +1 -0
- package/src/utils/abi/typechain/index.ts +2 -0
- package/src/utils/index.ts +0 -1
- package/dist/cjs/src/caching/IPFS/PinataIPFSClient.d.ts +0 -11
- package/dist/cjs/src/caching/IPFS/PinataIPFSClient.js +0 -67
- package/dist/cjs/src/caching/IPFS/PinataIPFSClient.js.map +0 -1
- package/dist/cjs/src/caching/IPFS/index.d.ts +0 -1
- package/dist/cjs/src/caching/IPFS/index.js.map +0 -1
- package/dist/cjs/src/utils/IPFSUtils.d.ts +0 -4
- package/dist/cjs/src/utils/IPFSUtils.js +0 -32
- package/dist/cjs/src/utils/IPFSUtils.js.map +0 -1
- package/dist/esm/src/caching/IPFS/PinataIPFSClient.d.ts +0 -37
- package/dist/esm/src/caching/IPFS/PinataIPFSClient.js +0 -81
- package/dist/esm/src/caching/IPFS/PinataIPFSClient.js.map +0 -1
- package/dist/esm/src/caching/IPFS/index.d.ts +0 -1
- package/dist/esm/src/caching/IPFS/index.js +0 -2
- package/dist/esm/src/caching/IPFS/index.js.map +0 -1
- package/dist/esm/src/utils/IPFSUtils.d.ts +0 -24
- package/dist/esm/src/utils/IPFSUtils.js +0 -47
- package/dist/esm/src/utils/IPFSUtils.js.map +0 -1
- package/dist/types/src/caching/IPFS/PinataIPFSClient.d.ts +0 -38
- package/dist/types/src/caching/IPFS/PinataIPFSClient.d.ts.map +0 -1
- package/dist/types/src/caching/IPFS/index.d.ts +0 -2
- package/dist/types/src/caching/IPFS/index.d.ts.map +0 -1
- package/dist/types/src/utils/IPFSUtils.d.ts +0 -25
- package/dist/types/src/utils/IPFSUtils.d.ts.map +0 -1
- package/scripts/build-bigint-buffer.js +0 -49
- package/src/caching/IPFS/PinataIPFSClient.ts +0 -92
- package/src/caching/IPFS/index.ts +0 -1
- package/src/utils/IPFSUtils.ts +0 -45
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { Contract, providers } from "ethers";
|
|
3
|
+
import { CHAIN_IDs } from "../../constants";
|
|
4
|
+
import { FillStatus, FillWithBlock, RelayData } from "../../interfaces";
|
|
5
|
+
import { get1967Upgrades } from "../evm/UpgradeUtils";
|
|
6
|
+
import { relayFillStatus as evmRelayFillStatus } from "../evm/SpokeUtils";
|
|
7
|
+
import {
|
|
8
|
+
BigNumber,
|
|
9
|
+
getRelayDataHash,
|
|
10
|
+
isDefined,
|
|
11
|
+
isUnsafeDepositId,
|
|
12
|
+
paginatedEventQuery,
|
|
13
|
+
spreadEventWithBlockNumber,
|
|
14
|
+
unpackFillEvent,
|
|
15
|
+
} from "../../utils";
|
|
16
|
+
|
|
17
|
+
type BlockTag = providers.BlockTag;
|
|
18
|
+
|
|
19
|
+
// Re-export functions that work unchanged on TRON's JSON-RPC.
|
|
20
|
+
export { populateV3Relay, getTimestampForBlock, fillStatusArray } from "../evm/SpokeUtils";
|
|
21
|
+
|
|
22
|
+
// Local implementations for functions requiring historical eth_call,
|
|
23
|
+
// which TRON does not support (only "latest" blockTag is accepted).
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @notice Retrieve the on-chain time at a specific block number.
|
|
27
|
+
* TRON does not support historical eth_call so block timestamps are used
|
|
28
|
+
* instead of SpokePool.getCurrentTime(). In production these are equivalent.
|
|
29
|
+
*/
|
|
30
|
+
export async function getTimeAt(spokePool: Contract, blockNumber: number): Promise<number> {
|
|
31
|
+
const block = await spokePool.provider.getBlock(blockNumber);
|
|
32
|
+
return block.timestamp;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fallback fill deadline buffer (6 hours) used when a contract upgrade is
|
|
36
|
+
// detected in the query range. An upgrade implies fillDeadlineBuffer may
|
|
37
|
+
// have changed and we cannot read historical state on TRON, so we use a
|
|
38
|
+
// conservative upper bound.
|
|
39
|
+
const FALLBACK_FILL_DEADLINE_BUFFER = 21600; // 6 hours in seconds
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @notice Return the maximum fill deadline buffer across a block range.
|
|
43
|
+
* TRON does not support historical eth_call, so we read the current value.
|
|
44
|
+
* If a contract upgrade (EIP-1967 Upgraded event) occurred within the range,
|
|
45
|
+
* the value may have changed at the upgrade boundary. In that case, return
|
|
46
|
+
* the greater of the current value and a conservative 6-hour fallback.
|
|
47
|
+
*/
|
|
48
|
+
export async function getMaxFillDeadlineInRange(
|
|
49
|
+
spokePool: Contract,
|
|
50
|
+
startBlock: number,
|
|
51
|
+
endBlock: number
|
|
52
|
+
): Promise<number> {
|
|
53
|
+
const [fillDeadlineBuffer, upgrades] = await Promise.all([
|
|
54
|
+
spokePool.fillDeadlineBuffer(),
|
|
55
|
+
get1967Upgrades(spokePool, startBlock, endBlock),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
const currentBuffer = Number(fillDeadlineBuffer);
|
|
59
|
+
|
|
60
|
+
if (upgrades.length > 0) {
|
|
61
|
+
return Math.max(currentBuffer, FALLBACK_FILL_DEADLINE_BUFFER);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return currentBuffer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @notice Not supported on TVM — callers should use findDepositBlock instead.
|
|
69
|
+
*/
|
|
70
|
+
export function getDepositIdAtBlock(_contract: Contract, _blockTag: number): Promise<BigNumber> {
|
|
71
|
+
throw new Error("getDepositIdAtBlock: not supported on TVM");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @notice Find the block at which a deposit was created.
|
|
76
|
+
* TRON does not support historical eth_call, so event queries replace the
|
|
77
|
+
* EVM binary-search over numberOfDeposits().
|
|
78
|
+
*/
|
|
79
|
+
export async function findDepositBlock(
|
|
80
|
+
spokePool: Contract,
|
|
81
|
+
depositId: BigNumber,
|
|
82
|
+
lowBlock: number,
|
|
83
|
+
highBlock?: number
|
|
84
|
+
): Promise<number | undefined> {
|
|
85
|
+
if (isUnsafeDepositId(depositId)) {
|
|
86
|
+
throw new Error(`Cannot search for depositId ${depositId}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
highBlock ??= await spokePool.provider.getBlockNumber();
|
|
90
|
+
assert(highBlock > lowBlock, `Block numbers out of range (${lowBlock} >= ${highBlock})`);
|
|
91
|
+
|
|
92
|
+
const events = await paginatedEventQuery(
|
|
93
|
+
spokePool,
|
|
94
|
+
spokePool.filters.FundsDeposited(null, null, null, null, null, depositId),
|
|
95
|
+
{ from: lowBlock, to: highBlock }
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (events.length === 0) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return events[0].blockNumber;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @notice Determine the fill status of a relay at a given block.
|
|
107
|
+
* For "latest" queries, delegates to the EVM implementation (TRON's
|
|
108
|
+
* eth_call works normally for "latest"). For historical queries the
|
|
109
|
+
* status is reconstructed from on-chain events because TRON does not
|
|
110
|
+
* support eth_call with historical blockTags.
|
|
111
|
+
*/
|
|
112
|
+
export async function relayFillStatus(
|
|
113
|
+
spokePool: Contract,
|
|
114
|
+
relayData: RelayData,
|
|
115
|
+
blockTag: BlockTag = "latest",
|
|
116
|
+
destinationChainId?: number
|
|
117
|
+
): Promise<FillStatus> {
|
|
118
|
+
if (blockTag === "latest") {
|
|
119
|
+
return evmRelayFillStatus(spokePool, relayData, blockTag, destinationChainId);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
destinationChainId ??= await spokePool.chainId();
|
|
123
|
+
assert(isDefined(destinationChainId));
|
|
124
|
+
|
|
125
|
+
const hash = getRelayDataHash(relayData, destinationChainId);
|
|
126
|
+
|
|
127
|
+
// Historical blockTag: check the current state first as an optimisation.
|
|
128
|
+
// Fill status can only increase (Unfilled -> RequestedSlowFill -> Filled),
|
|
129
|
+
// so if the deposit is still Unfilled now it was Unfilled at every prior block.
|
|
130
|
+
const latestStatus = Number(await spokePool.fillStatuses(hash));
|
|
131
|
+
if (latestStatus === FillStatus.Unfilled) {
|
|
132
|
+
return FillStatus.Unfilled;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Reconstruct from events up to the requested block.
|
|
136
|
+
const fromBlock = 0;
|
|
137
|
+
const toBlock = Number(blockTag);
|
|
138
|
+
|
|
139
|
+
const fillEvents = await paginatedEventQuery(
|
|
140
|
+
spokePool,
|
|
141
|
+
spokePool.filters.FilledRelay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
142
|
+
{ from: fromBlock, to: toBlock }
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (fillEvents.length > 0) {
|
|
146
|
+
return FillStatus.Filled;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// No fill before blockTag — check for slow fill requests.
|
|
150
|
+
if (latestStatus >= FillStatus.RequestedSlowFill) {
|
|
151
|
+
const slowFillEvents = await paginatedEventQuery(
|
|
152
|
+
spokePool,
|
|
153
|
+
spokePool.filters.RequestedSlowFill(null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
154
|
+
{ from: fromBlock, to: toBlock }
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
if (slowFillEvents.length > 0) {
|
|
158
|
+
return FillStatus.RequestedSlowFill;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return FillStatus.Unfilled;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @notice Find the block at which a fill was completed.
|
|
167
|
+
* TRON does not support historical eth_call, so event queries replace the
|
|
168
|
+
* EVM binary-search over fillStatuses().
|
|
169
|
+
*/
|
|
170
|
+
export async function findFillBlock(
|
|
171
|
+
spokePool: Contract,
|
|
172
|
+
relayData: RelayData,
|
|
173
|
+
lowBlockNumber: number,
|
|
174
|
+
highBlockNumber?: number
|
|
175
|
+
): Promise<number | undefined> {
|
|
176
|
+
const { provider } = spokePool;
|
|
177
|
+
highBlockNumber ??= await provider.getBlockNumber();
|
|
178
|
+
assert(highBlockNumber > lowBlockNumber, `Block numbers out of range (${lowBlockNumber} >= ${highBlockNumber})`);
|
|
179
|
+
|
|
180
|
+
const events = await paginatedEventQuery(
|
|
181
|
+
spokePool,
|
|
182
|
+
spokePool.filters.FilledRelay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
183
|
+
{ from: lowBlockNumber, to: highBlockNumber }
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (events.length === 0) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return events[0].blockNumber;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @notice Find the fill event for a deposit.
|
|
195
|
+
* Queries fill events directly rather than binary-searching then re-querying.
|
|
196
|
+
*/
|
|
197
|
+
export async function findFillEvent(
|
|
198
|
+
spokePool: Contract,
|
|
199
|
+
relayData: RelayData,
|
|
200
|
+
lowBlockNumber: number,
|
|
201
|
+
highBlockNumber?: number
|
|
202
|
+
): Promise<FillWithBlock | undefined> {
|
|
203
|
+
const { provider } = spokePool;
|
|
204
|
+
highBlockNumber ??= await provider.getBlockNumber();
|
|
205
|
+
|
|
206
|
+
const events = await paginatedEventQuery(
|
|
207
|
+
spokePool,
|
|
208
|
+
spokePool.filters.FilledRelay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
|
|
209
|
+
{ from: lowBlockNumber, to: highBlockNumber }
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (events.length === 0) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const event = events[0];
|
|
217
|
+
// In production the chainId returned from the provider matches 1:1 with the actual chainId. Querying the provider
|
|
218
|
+
// object saves an RPC query because the chainId is cached by StaticJsonRpcProvider instances. In hre, the SpokePool
|
|
219
|
+
// may be configured with a different chainId than what is returned by the provider.
|
|
220
|
+
const destinationChainId = Object.values(CHAIN_IDs).includes(relayData.originChainId)
|
|
221
|
+
? (await spokePool.provider.getNetwork()).chainId
|
|
222
|
+
: Number(await spokePool.chainId());
|
|
223
|
+
|
|
224
|
+
return unpackFillEvent(spreadEventWithBlockNumber(event), destinationChainId);
|
|
225
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TronWeb } from "tronweb";
|
|
2
|
+
import { PopulatedTransaction } from "ethers";
|
|
3
|
+
import { evmToTronAddress } from "./utils/address";
|
|
4
|
+
|
|
5
|
+
export interface TronTransactionResult {
|
|
6
|
+
txid: string;
|
|
7
|
+
result: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Submit a populated EVM transaction to TRON via TronWeb.
|
|
12
|
+
*
|
|
13
|
+
* The EVM `populateV3Relay()` already produces correct ABI-encoded calldata.
|
|
14
|
+
* This function extracts `to` and `data` from the PopulatedTransaction,
|
|
15
|
+
* converts the target address to TRON Base58 format, and uses TronWeb's
|
|
16
|
+
* `triggerSmartContract` → `sign` → `sendRawTransaction` pipeline.
|
|
17
|
+
*
|
|
18
|
+
* @param tronWeb An authenticated TronWeb instance (with private key set).
|
|
19
|
+
* @param populatedTx The populated transaction containing `to` and `data`.
|
|
20
|
+
* @param feeLimit The maximum TRX to burn for energy consumption, in SUN (1 TRX = 1,000,000 SUN).
|
|
21
|
+
* @returns The transaction ID and result status.
|
|
22
|
+
*/
|
|
23
|
+
export async function submitTransaction(
|
|
24
|
+
tronWeb: TronWeb,
|
|
25
|
+
populatedTx: PopulatedTransaction,
|
|
26
|
+
feeLimit: number,
|
|
27
|
+
callValue: number = 0
|
|
28
|
+
): Promise<TronTransactionResult> {
|
|
29
|
+
const { to, data } = populatedTx;
|
|
30
|
+
if (!to || !data) {
|
|
31
|
+
throw new Error("submitTransaction: populatedTx must have both 'to' and 'data' fields");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const tronAddress = evmToTronAddress(to);
|
|
35
|
+
const ownerAddress = tronWeb.defaultAddress?.base58;
|
|
36
|
+
if (!ownerAddress) {
|
|
37
|
+
throw new Error("submitTransaction: TronWeb instance must have a default address configured");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Use triggerSmartContract with the `input` option to pass pre-encoded calldata.
|
|
41
|
+
// The function selector is empty — the full calldata (selector + params) is in `input`.
|
|
42
|
+
const input = data.startsWith("0x") ? data.slice(2) : data;
|
|
43
|
+
const txWrapper = await tronWeb.transactionBuilder.triggerSmartContract(
|
|
44
|
+
tronAddress,
|
|
45
|
+
// Use empty function selector — the `input` option provides the full calldata.
|
|
46
|
+
"",
|
|
47
|
+
{ feeLimit, input, callValue },
|
|
48
|
+
[],
|
|
49
|
+
ownerAddress
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!txWrapper?.result?.result) {
|
|
53
|
+
const message = txWrapper?.result?.message ?? "Unknown error";
|
|
54
|
+
throw new Error(`submitTransaction: triggerSmartContract failed: ${message}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const signedTx = await tronWeb.trx.sign(txWrapper.transaction);
|
|
58
|
+
const broadcast = await tronWeb.trx.sendRawTransaction(signedTx);
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
txid: broadcast.txid ?? signedTx.txID,
|
|
62
|
+
result: broadcast.result ?? false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TronWeb } from "tronweb";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert an EVM-format hex address (0x...) to a TRON Base58Check address (T...).
|
|
5
|
+
* @param evmAddress The 0x-prefixed hex address.
|
|
6
|
+
* @returns The TRON Base58Check-encoded address.
|
|
7
|
+
*/
|
|
8
|
+
export function evmToTronAddress(evmAddress: string): string {
|
|
9
|
+
// TronWeb.address.fromHex expects a hex address (with or without 0x prefix)
|
|
10
|
+
// and returns the Base58Check-encoded TRON address.
|
|
11
|
+
return TronWeb.address.fromHex(evmAddress);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Convert a TRON Base58Check address (T...) to an EVM-format hex address (0x...).
|
|
16
|
+
* @param tronAddress The TRON Base58Check-encoded address.
|
|
17
|
+
* @returns The 0x-prefixed hex address.
|
|
18
|
+
*/
|
|
19
|
+
export function tronToEvmAddress(tronAddress: string): string {
|
|
20
|
+
// TronWeb.address.toHex returns hex with a 41 prefix (TRON's address prefix).
|
|
21
|
+
// We strip the leading "41" and add "0x" to get standard EVM format.
|
|
22
|
+
const hex = TronWeb.address.toHex(tronAddress);
|
|
23
|
+
return "0x" + hex.slice(2);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check whether a string is a valid TRON Base58Check address.
|
|
28
|
+
* @param address The string to check.
|
|
29
|
+
* @returns True if the address is a valid TRON Base58Check address.
|
|
30
|
+
*/
|
|
31
|
+
export function isTronBase58Address(address: string): boolean {
|
|
32
|
+
return TronWeb.isAddress(address);
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../evm/utils/wait";
|
package/src/caching/index.ts
CHANGED
|
@@ -72,6 +72,34 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
72
72
|
return Object.keys(this._availableEventsOnSpoke(knownEventNames));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Retrieve the on-chain time at a specific block.
|
|
77
|
+
* EVM reads SpokePool.getCurrentTime() via multicall with a historical blockTag.
|
|
78
|
+
* @param blockNumber The block number to query.
|
|
79
|
+
* @returns The on-chain time as a number.
|
|
80
|
+
*/
|
|
81
|
+
protected async _getCurrentTime(blockNumber: number): Promise<number> {
|
|
82
|
+
const { spokePool } = this;
|
|
83
|
+
const multicallFunctions = ["getCurrentTime"];
|
|
84
|
+
const multicallOutput = await spokePool.callStatic.multicall(
|
|
85
|
+
multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
|
|
86
|
+
{ blockTag: blockNumber }
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const [currentTime] = multicallFunctions.map(
|
|
90
|
+
(fn, idx) => spokePool.interface.decodeFunctionResult(fn, multicallOutput[idx])[0]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
|
|
94
|
+
const errMsg = BigNumber.isBigNumber(currentTime)
|
|
95
|
+
? `currentTime: ${currentTime} < ${toBN(this.currentTime)}`
|
|
96
|
+
: `currentTime is not a BigNumber: ${JSON.stringify(currentTime)}`;
|
|
97
|
+
throw new Error(`EVMSpokePoolClient::update: ${errMsg}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return currentTime.toNumber();
|
|
101
|
+
}
|
|
102
|
+
|
|
75
103
|
protected override async _update(eventsToQuery: string[]): Promise<SpokePoolUpdate> {
|
|
76
104
|
const searchConfig = await this.updateSearchConfig(this.spokePool.provider);
|
|
77
105
|
if (isUpdateFailureReason(searchConfig)) {
|
|
@@ -107,25 +135,14 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
107
135
|
});
|
|
108
136
|
|
|
109
137
|
const timerStart = Date.now();
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
spokePool.callStatic.multicall(
|
|
113
|
-
multicallFunctions.map((f) => spokePool.interface.encodeFunctionData(f)),
|
|
114
|
-
{ blockTag: searchConfig.to }
|
|
115
|
-
),
|
|
138
|
+
const [currentTime, ...events] = await Promise.all([
|
|
139
|
+
this._getCurrentTime(searchConfig.to),
|
|
116
140
|
...eventSearchConfigs.map((config) => paginatedEventQuery(this.spokePool, config.filter, config.searchConfig)),
|
|
117
141
|
]);
|
|
118
142
|
this.log("debug", `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`);
|
|
119
143
|
|
|
120
|
-
|
|
121
|
-
(
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (!BigNumber.isBigNumber(currentTime) || currentTime.lt(this.currentTime)) {
|
|
125
|
-
const errMsg = BigNumber.isBigNumber(currentTime)
|
|
126
|
-
? `currentTime: ${currentTime} < ${toBN(this.currentTime)}`
|
|
127
|
-
: `currentTime is not a BigNumber: ${JSON.stringify(currentTime)}`;
|
|
128
|
-
throw new Error(`EVMSpokePoolClient::update: ${errMsg}`);
|
|
144
|
+
if (currentTime < this.currentTime) {
|
|
145
|
+
throw new Error(`EVMSpokePoolClient::update: currentTime: ${currentTime} < ${this.currentTime}`);
|
|
129
146
|
}
|
|
130
147
|
|
|
131
148
|
// Sort all events to ensure they are stored in a consistent order.
|
|
@@ -138,7 +155,7 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
138
155
|
|
|
139
156
|
return {
|
|
140
157
|
success: true,
|
|
141
|
-
currentTime
|
|
158
|
+
currentTime,
|
|
142
159
|
searchEndBlock: searchConfig.to,
|
|
143
160
|
events: eventsWithBlockNumber,
|
|
144
161
|
};
|
|
@@ -190,12 +207,21 @@ export class EVMSpokePoolClient extends SpokePoolClient {
|
|
|
190
207
|
return _getTimestampForBlock(this.spokePool.provider, blockNumber);
|
|
191
208
|
}
|
|
192
209
|
|
|
193
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Find the block at which a deposit was created.
|
|
212
|
+
* EVM uses a binary-search over historical numberOfDeposits().
|
|
213
|
+
* TVM overrides this with an event-based lookup.
|
|
214
|
+
*/
|
|
215
|
+
protected _findDepositBlock(depositId: BigNumber, lowBlock: number, highBlock?: number): Promise<number | undefined> {
|
|
216
|
+
return findDepositBlock(this.spokePool, depositId, lowBlock, highBlock);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
protected async queryDepositEvents(
|
|
194
220
|
depositId: BigNumber
|
|
195
221
|
): Promise<{ event: Log; elapsedMs: number } | { reason: string }> {
|
|
196
222
|
const tStart = Date.now();
|
|
197
223
|
const upperBound = this.latestHeightSearched || undefined;
|
|
198
|
-
const from = await
|
|
224
|
+
const from = await this._findDepositBlock(depositId, this.deploymentBlock, upperBound);
|
|
199
225
|
const chain = getNetworkName(this.chainId);
|
|
200
226
|
|
|
201
227
|
if (!from) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findDepositBlock,
|
|
3
|
+
getMaxFillDeadlineInRange as getMaxFillDeadline,
|
|
4
|
+
getTimeAt as _getTimeAt,
|
|
5
|
+
relayFillStatus,
|
|
6
|
+
} from "../../arch/tvm";
|
|
7
|
+
import { FillStatus, RelayData } from "../../interfaces";
|
|
8
|
+
import { BigNumber } from "../../utils";
|
|
9
|
+
import { EVMSpokePoolClient } from "./EVMSpokePoolClient";
|
|
10
|
+
import { TVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A TVM-specific SpokePoolClient for TRON.
|
|
14
|
+
*
|
|
15
|
+
* TRON is EVM-compatible for reads and event queries, but diverges in three areas:
|
|
16
|
+
* 1. No historical `eth_call` — only "latest" blockTag is accepted.
|
|
17
|
+
* 2. No `eth_sendRawTransaction` — TRON uses Protobuf-encoded transactions via TronWeb.
|
|
18
|
+
* 3. Energy/bandwidth fee model instead of gas.
|
|
19
|
+
*
|
|
20
|
+
* This client extends EVMSpokePoolClient, overriding only the methods affected by (1).
|
|
21
|
+
* Transaction submission (2) and fee estimation (3) are handled by the arch/tvm utilities.
|
|
22
|
+
*/
|
|
23
|
+
export class TVMSpokePoolClient extends EVMSpokePoolClient {
|
|
24
|
+
// @ts-expect-error: Narrowing the base class literal type from "EVM" to "TVM".
|
|
25
|
+
override readonly type = TVM_SPOKE_POOL_CLIENT_TYPE;
|
|
26
|
+
|
|
27
|
+
public override relayFillStatus(relayData: RelayData, atHeight?: number): Promise<FillStatus> {
|
|
28
|
+
return relayFillStatus(this.spokePool, relayData, atHeight, this.chainId);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public override getMaxFillDeadlineInRange(startBlock: number, endBlock: number): Promise<number> {
|
|
32
|
+
return getMaxFillDeadline(this.spokePool, startBlock, endBlock);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public override getTimeAt(blockNumber: number): Promise<number> {
|
|
36
|
+
return _getTimeAt(this.spokePool, blockNumber);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Override to use TVM's event-based findDepositBlock
|
|
41
|
+
* instead of EVM's binary-search over historical numberOfDeposits().
|
|
42
|
+
*/
|
|
43
|
+
protected override _findDepositBlock(
|
|
44
|
+
depositId: BigNumber,
|
|
45
|
+
lowBlock: number,
|
|
46
|
+
highBlock?: number
|
|
47
|
+
): Promise<number | undefined> {
|
|
48
|
+
return findDepositBlock(this.spokePool, depositId, lowBlock, highBlock);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Override to avoid historical eth_call for getCurrentTime.
|
|
53
|
+
* TRON does not support eth_call with historical blockTags, so we
|
|
54
|
+
* use the block timestamp from provider.getBlock() instead of
|
|
55
|
+
* SpokePool.getCurrentTime({ blockTag }).
|
|
56
|
+
*/
|
|
57
|
+
protected override async _getCurrentTime(blockNumber: number): Promise<number> {
|
|
58
|
+
const block = await this.spokePool.provider.getBlock(blockNumber);
|
|
59
|
+
const currentTime = block.timestamp;
|
|
60
|
+
if (currentTime < this.currentTime) {
|
|
61
|
+
throw new Error(`TVMSpokePoolClient::update: currentTime: ${currentTime} < ${this.currentTime}`);
|
|
62
|
+
}
|
|
63
|
+
return currentTime;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { EVMSpokePoolClient } from "./EVMSpokePoolClient";
|
|
2
2
|
import { SVMSpokePoolClient } from "./SVMSpokePoolClient";
|
|
3
|
+
import { TVMSpokePoolClient } from "./TVMSpokePoolClient";
|
|
3
4
|
import { SpokePoolClient } from "./SpokePoolClient";
|
|
4
|
-
import { EVM_SPOKE_POOL_CLIENT_TYPE, SVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
|
|
5
|
+
import { EVM_SPOKE_POOL_CLIENT_TYPE, SVM_SPOKE_POOL_CLIENT_TYPE, TVM_SPOKE_POOL_CLIENT_TYPE } from "./types";
|
|
5
6
|
|
|
6
7
|
export { EVMSpokePoolClient } from "./EVMSpokePoolClient";
|
|
7
8
|
export { SpokePoolClient, SpokePoolUpdate } from "./SpokePoolClient";
|
|
8
9
|
export { SVMSpokePoolClient } from "./SVMSpokePoolClient";
|
|
10
|
+
export { TVMSpokePoolClient } from "./TVMSpokePoolClient";
|
|
9
11
|
export { SpokePoolManager } from "./SpokePoolClientManager";
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -27,3 +29,12 @@ export function isSVMSpokePoolClient(spokePoolClient: SpokePoolClient): spokePoo
|
|
|
27
29
|
// @TODO: Should we handle the case where spokePoolClient is undefined?
|
|
28
30
|
return spokePoolClient?.type === SVM_SPOKE_POOL_CLIENT_TYPE;
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a SpokePoolClient is a TVMSpokePoolClient.
|
|
35
|
+
* @param spokePoolClient The SpokePoolClient to check.
|
|
36
|
+
* @returns True if the SpokePoolClient is a TVMSpokePoolClient, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export function isTVMSpokePoolClient(spokePoolClient: SpokePoolClient): spokePoolClient is TVMSpokePoolClient {
|
|
39
|
+
return spokePoolClient?.type === TVM_SPOKE_POOL_CLIENT_TYPE;
|
|
40
|
+
}
|
package/src/clients/index.ts
CHANGED
|
@@ -11,8 +11,10 @@ export {
|
|
|
11
11
|
SpokePoolUpdate,
|
|
12
12
|
EVMSpokePoolClient,
|
|
13
13
|
SVMSpokePoolClient,
|
|
14
|
+
TVMSpokePoolClient,
|
|
14
15
|
isEVMSpokePoolClient,
|
|
15
16
|
isSVMSpokePoolClient,
|
|
17
|
+
isTVMSpokePoolClient,
|
|
16
18
|
SpokePoolManager,
|
|
17
19
|
} from "./SpokePoolClient";
|
|
18
20
|
export * as BundleDataClient from "./BundleDataClient";
|
|
@@ -113,6 +113,7 @@ function getGasPriceEthers(provider: providers.Provider, opts: GasPriceEstimateO
|
|
|
113
113
|
[CHAIN_IDs.POLYGON]: polygon.gasStation,
|
|
114
114
|
[CHAIN_IDs.SCROLL]: ethereum.legacy,
|
|
115
115
|
[CHAIN_IDs.TEMPO]: ethereum.eip1559,
|
|
116
|
+
[CHAIN_IDs.TRON]: ethereum.legacy,
|
|
116
117
|
[CHAIN_IDs.ZK_SYNC]: ethereum.legacy,
|
|
117
118
|
// Testnet
|
|
118
119
|
[CHAIN_IDs.POLYGON_AMOY]: polygon.gasStation,
|
|
@@ -3,6 +3,7 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
|
|
|
3
3
|
import { getDeployedAddress } from "@across-protocol/contracts";
|
|
4
4
|
import { asL2Provider } from "@eth-optimism/sdk";
|
|
5
5
|
import { providers } from "ethers";
|
|
6
|
+
import { TronWeb } from "tronweb";
|
|
6
7
|
import { CUSTOM_GAS_TOKENS } from "../../constants";
|
|
7
8
|
import { chainIsEvm, chainIsOPStack, isDefined, chainIsSvm, SvmAddress } from "../../utils";
|
|
8
9
|
import { QueryBase } from "./baseQuery";
|
|
@@ -22,7 +23,7 @@ const fixedGasPrice = {
|
|
|
22
23
|
export class QueryBase__factory {
|
|
23
24
|
static create(
|
|
24
25
|
chainId: number,
|
|
25
|
-
provider: providers.Provider | svmProvider,
|
|
26
|
+
provider: providers.Provider | svmProvider | TronWeb,
|
|
26
27
|
symbolMapping = TOKEN_SYMBOLS_MAP,
|
|
27
28
|
spokePoolAddress = getDeployedAddress("SpokePool", chainId),
|
|
28
29
|
relayerAddress = getDefaultRelayer(chainId),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isAddress } from "viem";
|
|
2
2
|
import { providers, utils } from "ethers";
|
|
3
3
|
import bs58 from "bs58";
|
|
4
|
-
import {
|
|
4
|
+
import { TronWeb } from "tronweb";
|
|
5
|
+
import { BigNumber, chainIsEvm, chainIsSvm, chainIsTvm } from "./";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Verify whether an address' bytecode resembles an EIP-7702 delegation.
|
|
@@ -107,6 +108,7 @@ export function toAddressType(address: string, chainId: number): Address {
|
|
|
107
108
|
|
|
108
109
|
if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
|
|
109
110
|
else if (chainIsSvm(chainId) && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
|
|
111
|
+
else if (chainIsTvm(chainId)) return TvmAddress.from(address);
|
|
110
112
|
|
|
111
113
|
return new RawAddress(rawAddress);
|
|
112
114
|
}
|
|
@@ -187,6 +189,7 @@ export abstract class Address {
|
|
|
187
189
|
isValidOn(chainId: number): boolean {
|
|
188
190
|
if (chainIsEvm(chainId)) return EvmAddress.validate(this.rawAddress);
|
|
189
191
|
if (chainIsSvm(chainId)) return SvmAddress.validate(this.rawAddress);
|
|
192
|
+
if (chainIsTvm(chainId)) return TvmAddress.validate(this.rawAddress);
|
|
190
193
|
return false;
|
|
191
194
|
}
|
|
192
195
|
|
|
@@ -227,6 +230,10 @@ export abstract class Address {
|
|
|
227
230
|
isSVM(): this is SvmAddress {
|
|
228
231
|
return false;
|
|
229
232
|
}
|
|
233
|
+
|
|
234
|
+
isTVM(): this is TvmAddress {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
// Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
|
|
@@ -304,6 +311,59 @@ export class SvmAddress extends Address {
|
|
|
304
311
|
}
|
|
305
312
|
}
|
|
306
313
|
|
|
314
|
+
// Subclass of address which handles TRON (TVM) addresses. Internally stores a 20-byte address (same as EVM),
|
|
315
|
+
// but toNative() returns the TRON Base58Check-encoded address (T...).
|
|
316
|
+
export class TvmAddress extends Address {
|
|
317
|
+
private readonly _type = "tvm";
|
|
318
|
+
private nativeAddress: string | undefined = undefined;
|
|
319
|
+
|
|
320
|
+
constructor(rawAddress: Uint8Array) {
|
|
321
|
+
if (!TvmAddress.validate(rawAddress)) {
|
|
322
|
+
throw new Error(`${utils.hexlify(rawAddress)} is not a valid TVM address`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
super(rawAddress);
|
|
326
|
+
this._type; // tsc noUnusedLocals appeasement.
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
static validate(rawAddress: Uint8Array): boolean {
|
|
330
|
+
return (
|
|
331
|
+
rawAddress.length == 20 || (rawAddress.length === 32 && rawAddress.slice(0, 12).every((field) => field === 0))
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
override isTVM(): this is TvmAddress {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Returns the TRON Base58Check-encoded address (T...).
|
|
340
|
+
override toNative(): string {
|
|
341
|
+
const computeNative = () => {
|
|
342
|
+
const hexString = utils.hexlify(this.rawAddress);
|
|
343
|
+
// Strip leading zeros to get the 20-byte portion, then convert to TRON format.
|
|
344
|
+
const evmHex = utils.hexZeroPad(utils.hexStripZeros(hexString), 20);
|
|
345
|
+
return TronWeb.address.fromHex(evmHex);
|
|
346
|
+
};
|
|
347
|
+
return (this.nativeAddress ??= computeNative());
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
override toHexString(): string {
|
|
351
|
+
return this.toEvmAddress();
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Constructs a new TvmAddress from a string. Accepts both 0x-prefixed hex and TRON Base58Check addresses.
|
|
355
|
+
static from(address: string): TvmAddress {
|
|
356
|
+
if (address.startsWith("0x")) {
|
|
357
|
+
return new this(utils.arrayify(address));
|
|
358
|
+
}
|
|
359
|
+
// For base58 Tron addresses, convert via TronWeb to get the hex representation.
|
|
360
|
+
const hex = TronWeb.address.toHex(address);
|
|
361
|
+
// TronWeb returns hex with a 0x41 prefix (TRON's address byte). Strip 0x41 to get 20 bytes.
|
|
362
|
+
const rawHex = "0x" + hex.slice(2);
|
|
363
|
+
return new this(utils.arrayify(rawHex));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
307
367
|
export class RawAddress extends Address {
|
|
308
368
|
private readonly _type = "raw";
|
|
309
369
|
|