@across-protocol/sdk 4.3.110 → 4.3.111-alpha.1
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/addressAggregator/adapters/abstract.js +50 -64
- package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/bybit.js +16 -29
- package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/env.js +11 -15
- package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/file.js +32 -45
- package/dist/cjs/addressAggregator/adapters/file.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/index.js +1 -1
- package/dist/cjs/addressAggregator/adapters/risklabs.js +22 -36
- package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/cjs/addressAggregator/index.js +57 -87
- package/dist/cjs/addressAggregator/index.js.map +1 -1
- package/dist/cjs/apiClient/abstractClient.js +9 -8
- package/dist/cjs/apiClient/abstractClient.js.map +1 -1
- package/dist/cjs/apiClient/index.js +1 -1
- package/dist/cjs/apiClient/mockedClient.js +23 -29
- package/dist/cjs/apiClient/mockedClient.js.map +1 -1
- package/dist/cjs/apiClient/productionClient.js +65 -103
- package/dist/cjs/apiClient/productionClient.js.map +1 -1
- package/dist/cjs/arch/evm/BlockUtils.js +122 -208
- package/dist/cjs/arch/evm/BlockUtils.js.map +1 -1
- package/dist/cjs/arch/evm/MessageUtils.js +1 -1
- package/dist/cjs/arch/evm/MessageUtils.js.map +1 -1
- package/dist/cjs/arch/evm/SpokeUtils.js +134 -288
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/evm/index.js +1 -1
- package/dist/cjs/arch/evm/utils/index.js +1 -1
- package/dist/cjs/arch/evm/utils/wait.js +38 -49
- package/dist/cjs/arch/evm/utils/wait.js.map +1 -1
- package/dist/cjs/arch/index.js +1 -1
- package/dist/cjs/arch/svm/BlockUtils.js +102 -158
- package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
- package/dist/cjs/arch/svm/MessageUtils.js +2 -2
- package/dist/cjs/arch/svm/MessageUtils.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.js +708 -1147
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/svm/encoders.js +1 -1
- package/dist/cjs/arch/svm/encoders.js.map +1 -1
- package/dist/cjs/arch/svm/eventsClient.js +174 -236
- package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
- package/dist/cjs/arch/svm/index.js +1 -1
- package/dist/cjs/arch/svm/provider.js +3 -3
- package/dist/cjs/arch/svm/provider.js.map +1 -1
- package/dist/cjs/arch/svm/utils.js +166 -355
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/caching/Arweave/ArweaveClient.js +168 -246
- package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/cjs/caching/Arweave/index.js +1 -1
- package/dist/cjs/caching/IPFS/PinataIPFSClient.js +40 -49
- package/dist/cjs/caching/IPFS/PinataIPFSClient.js.map +1 -1
- package/dist/cjs/caching/IPFS/index.js +1 -1
- package/dist/cjs/caching/Memory/MemoryCacheClient.js +13 -18
- package/dist/cjs/caching/Memory/MemoryCacheClient.js.map +1 -1
- package/dist/cjs/caching/Memory/index.js +1 -1
- package/dist/cjs/caching/index.js +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +302 -381
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/index.js +1 -1
- package/dist/cjs/clients/BaseAbstractClient.js +58 -83
- package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +709 -900
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/index.js +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +95 -128
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +48 -53
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +10 -8
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +67 -90
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +46 -24
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/index.js +1 -1
- package/dist/cjs/clients/HubPoolClient.js +526 -708
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -179
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +124 -183
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +357 -389
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +9 -8
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/index.js +3 -3
- package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/cjs/clients/index.js +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js +58 -67
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockEvents.js +47 -52
- package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +142 -185
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +208 -192
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +140 -143
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +57 -73
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/index.js +1 -1
- package/dist/cjs/coingecko/Coingecko.js +285 -437
- package/dist/cjs/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/coingecko/index.js +1 -1
- package/dist/cjs/constants.js +23 -29
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/contracts/acrossConfigStore.js +27 -48
- package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
- package/dist/cjs/contracts/hubPool.js +36 -20
- package/dist/cjs/contracts/hubPool.js.map +1 -1
- package/dist/cjs/contracts/index.js +1 -1
- package/dist/cjs/contracts/utils.js +6 -8
- package/dist/cjs/contracts/utils.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +7 -16
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js +26 -45
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +16 -28
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.js +73 -112
- package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/solana.js +20 -33
- package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/cjs/gasPriceOracle/oracle.js +77 -103
- package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/gasPriceOracle/types.js +3 -3
- package/dist/cjs/gasPriceOracle/types.js.map +1 -1
- package/dist/cjs/gasPriceOracle/util.js +8 -8
- package/dist/cjs/gasPriceOracle/util.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/interfaces/index.js +1 -1
- package/dist/cjs/lpFeeCalculator/index.js +1 -1
- package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js +33 -35
- package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
- package/dist/cjs/lpFeeCalculator/rateModel.js +7 -9
- package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
- package/dist/cjs/merkleDistributor/MerkleDistributor.js +20 -18
- package/dist/cjs/merkleDistributor/MerkleDistributor.js.map +1 -1
- package/dist/cjs/merkleDistributor/index.js +1 -1
- package/dist/cjs/merkleDistributor/model/index.js +1 -1
- package/dist/cjs/pool/TransactionManager.js +45 -100
- package/dist/cjs/pool/TransactionManager.js.map +1 -1
- package/dist/cjs/pool/index.js +1 -1
- package/dist/cjs/pool/poolClient.js +464 -731
- package/dist/cjs/pool/poolClient.js.map +1 -1
- package/dist/cjs/pool/uma/across/index.js +1 -1
- package/dist/cjs/pool/uma/across/transactionManager.js +45 -100
- package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
- package/dist/cjs/pool/uma/clients/erc20/client.js +18 -16
- package/dist/cjs/pool/uma/clients/erc20/client.js.map +1 -1
- package/dist/cjs/pool/uma/clients/erc20/index.js +1 -1
- package/dist/cjs/pool/uma/clients/index.js +1 -1
- package/dist/cjs/pool/uma/index.js +1 -1
- package/dist/cjs/pool/uma/oracle/index.js +1 -1
- package/dist/cjs/pool/uma/oracle/utils.js +4 -5
- package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
- package/dist/cjs/pool/uma/utils.js +11 -30
- package/dist/cjs/pool/uma/utils.js.map +1 -1
- package/dist/cjs/priceClient/adapters/acrossApi.js +22 -39
- package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
- package/dist/cjs/priceClient/adapters/baseAdapter.js +49 -73
- package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/cjs/priceClient/adapters/coingecko.js +34 -61
- package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
- package/dist/cjs/priceClient/adapters/default.js +16 -31
- package/dist/cjs/priceClient/adapters/default.js.map +1 -1
- package/dist/cjs/priceClient/adapters/defiLlama.js +40 -74
- package/dist/cjs/priceClient/adapters/defiLlama.js.map +1 -1
- package/dist/cjs/priceClient/adapters/index.js +1 -1
- package/dist/cjs/priceClient/index.js +1 -1
- package/dist/cjs/priceClient/priceClient.js +110 -159
- package/dist/cjs/priceClient/priceClient.js.map +1 -1
- package/dist/cjs/providers/alchemy.js +17 -19
- package/dist/cjs/providers/alchemy.js.map +1 -1
- package/dist/cjs/providers/cachedProvider.js +88 -129
- package/dist/cjs/providers/cachedProvider.js.map +1 -1
- package/dist/cjs/providers/drpc.js +9 -11
- package/dist/cjs/providers/drpc.js.map +1 -1
- package/dist/cjs/providers/index.js +1 -1
- package/dist/cjs/providers/infura.js +10 -12
- package/dist/cjs/providers/infura.js.map +1 -1
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +7 -15
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +6 -14
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +7 -15
- package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +42 -66
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/index.js +1 -1
- package/dist/cjs/providers/mocks/mockEthersProvider.js +29 -31
- package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
- package/dist/cjs/providers/quicknode.js +19 -21
- package/dist/cjs/providers/quicknode.js.map +1 -1
- package/dist/cjs/providers/rateLimitedProvider.js +64 -79
- package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
- package/dist/cjs/providers/retryProvider.js +163 -246
- package/dist/cjs/providers/retryProvider.js.map +1 -1
- package/dist/cjs/providers/solana/baseRpcFactories.js +14 -18
- package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
- package/dist/cjs/providers/solana/cachedRpcFactory.js +70 -112
- package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/defaultRpcFactory.js +8 -15
- package/dist/cjs/providers/solana/defaultRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/index.js +1 -1
- package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js +135 -191
- package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +67 -90
- package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/retryRpcFactory.js +52 -79
- package/dist/cjs/providers/solana/retryRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/utils.js +2 -2
- package/dist/cjs/providers/solana/utils.js.map +1 -1
- package/dist/cjs/providers/speedProvider.js +31 -53
- package/dist/cjs/providers/speedProvider.js.map +1 -1
- package/dist/cjs/providers/types.js +1 -1
- package/dist/cjs/providers/types.js.map +1 -1
- package/dist/cjs/providers/utils.js +26 -28
- package/dist/cjs/providers/utils.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +108 -162
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +14 -26
- package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +20 -29
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +88 -137
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/index.js +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +199 -297
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/typeguards/error.js +5 -7
- package/dist/cjs/typeguards/error.js.map +1 -1
- package/dist/cjs/typeguards/index.js +1 -1
- package/dist/cjs/utils/AddressUtils.js +117 -144
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/ArrayUtils.js +21 -78
- package/dist/cjs/utils/ArrayUtils.js.map +1 -1
- package/dist/cjs/utils/BigNumberUtils.js +9 -10
- package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
- package/dist/cjs/utils/BlockExplorerUtils.js +26 -30
- package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
- package/dist/cjs/utils/BlockFinder.js +2 -5
- package/dist/cjs/utils/BlockFinder.js.map +1 -1
- package/dist/cjs/utils/BlockUtils.js +24 -41
- package/dist/cjs/utils/BlockUtils.js.map +1 -1
- package/dist/cjs/utils/BundleUtils.js +21 -24
- package/dist/cjs/utils/BundleUtils.js.map +1 -1
- package/dist/cjs/utils/CCTPUtils.js +62 -126
- package/dist/cjs/utils/CCTPUtils.js.map +1 -1
- package/dist/cjs/utils/CachingUtils.js +20 -42
- package/dist/cjs/utils/CachingUtils.js.map +1 -1
- package/dist/cjs/utils/ContractUtils.js +5 -5
- package/dist/cjs/utils/ContractUtils.js.map +1 -1
- package/dist/cjs/utils/DepositUtils.js +122 -99
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +49 -70
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/FormattingUtils.js +26 -32
- package/dist/cjs/utils/FormattingUtils.js.map +1 -1
- package/dist/cjs/utils/HyperLiquidUtils.js +10 -23
- package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
- package/dist/cjs/utils/IPFSUtils.js +16 -34
- package/dist/cjs/utils/IPFSUtils.js.map +1 -1
- package/dist/cjs/utils/JSONUtils.js +6 -6
- package/dist/cjs/utils/JSONUtils.js.map +1 -1
- package/dist/cjs/utils/LogUtils.js +10 -12
- package/dist/cjs/utils/LogUtils.js.map +1 -1
- package/dist/cjs/utils/Multicall.js +56 -114
- package/dist/cjs/utils/Multicall.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.js +12 -21
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/NumberUtils.js +1 -3
- package/dist/cjs/utils/NumberUtils.js.map +1 -1
- package/dist/cjs/utils/ObjectUtils.js +27 -41
- package/dist/cjs/utils/ObjectUtils.js.map +1 -1
- package/dist/cjs/utils/Profiler.js +80 -83
- package/dist/cjs/utils/Profiler.js.map +1 -1
- package/dist/cjs/utils/ReviverUtils.js +5 -9
- package/dist/cjs/utils/ReviverUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.js +84 -84
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.js +41 -64
- package/dist/cjs/utils/TokenUtils.js.map +1 -1
- package/dist/cjs/utils/TypeGuards.js +1 -1
- package/dist/cjs/utils/TypeGuards.js.map +1 -1
- package/dist/cjs/utils/ValidatorUtils.js +7 -7
- package/dist/cjs/utils/ValidatorUtils.js.map +1 -1
- package/dist/cjs/utils/abi/contracts/index.js +1 -1
- package/dist/cjs/utils/abi/index.js +12 -22
- package/dist/cjs/utils/abi/index.js.map +1 -1
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +9 -12
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
- package/dist/cjs/utils/abi/typechain/index.js +1 -1
- package/dist/cjs/utils/common.js +40 -53
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/esm/addressAggregator/adapters/abstract.js +48 -64
- package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/bybit.js +15 -29
- package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/env.js +9 -14
- package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/file.js +29 -43
- package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/risklabs.js +20 -35
- package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/esm/addressAggregator/index.js +52 -83
- package/dist/esm/addressAggregator/index.js.map +1 -1
- package/dist/esm/addressAggregator/types.js +1 -1
- package/dist/esm/addressAggregator/types.js.map +1 -1
- package/dist/esm/apiClient/abstractClient.js +15 -9
- package/dist/esm/apiClient/abstractClient.js.map +1 -1
- package/dist/esm/apiClient/mockedClient.js +21 -26
- package/dist/esm/apiClient/mockedClient.js.map +1 -1
- package/dist/esm/apiClient/productionClient.js +61 -101
- package/dist/esm/apiClient/productionClient.js.map +1 -1
- package/dist/esm/arch/evm/BlockUtils.js +139 -217
- package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.js +146 -289
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/evm/utils/wait.js +34 -46
- package/dist/esm/arch/evm/utils/wait.js.map +1 -1
- package/dist/esm/arch/svm/BlockUtils.js +118 -166
- package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.js +738 -1150
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/svm/constants.js +1 -1
- package/dist/esm/arch/svm/constants.js.map +1 -1
- package/dist/esm/arch/svm/eventsClient.js +172 -232
- package/dist/esm/arch/svm/eventsClient.js.map +1 -1
- package/dist/esm/arch/svm/provider.js +1 -1
- package/dist/esm/arch/svm/provider.js.map +1 -1
- package/dist/esm/arch/svm/utils.js +155 -345
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/caching/Arweave/ArweaveClient.js +182 -256
- package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/caching/IPFS/PinataIPFSClient.js +47 -48
- package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
- package/dist/esm/caching/Memory/MemoryCacheClient.js +13 -19
- package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +333 -408
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BaseAbstractClient.js +66 -92
- package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +927 -1054
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +102 -131
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +57 -59
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +7 -5
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +75 -94
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +45 -23
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.js +581 -740
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -178
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +126 -183
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +372 -399
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js +9 -9
- package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/index.js +2 -2
- package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/types.js +2 -2
- package/dist/esm/clients/SpokePoolClient/types.js.map +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.js +53 -64
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockEvents.js +42 -49
- package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.js +138 -182
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +202 -188
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +127 -132
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +53 -69
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/esm/coingecko/Coingecko.js +298 -443
- package/dist/esm/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/constants.js +40 -46
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/contracts/acrossConfigStore.js +24 -46
- package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
- package/dist/esm/contracts/hubPool.js +34 -18
- package/dist/esm/contracts/hubPool.js.map +1 -1
- package/dist/esm/contracts/utils.js +3 -5
- package/dist/esm/contracts/utils.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js +6 -14
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/ethereum.js +22 -42
- package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js +13 -25
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.js +72 -108
- package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/solana.js +22 -31
- package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/esm/gasPriceOracle/oracle.js +70 -95
- package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/gasPriceOracle/types.js +2 -2
- package/dist/esm/gasPriceOracle/types.js.map +1 -1
- package/dist/esm/gasPriceOracle/util.js +4 -4
- package/dist/esm/gasPriceOracle/util.js.map +1 -1
- package/dist/esm/lpFeeCalculator/lpFeeCalculator.js +30 -33
- package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
- package/dist/esm/lpFeeCalculator/rateModel.js +7 -9
- package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
- package/dist/esm/merkleDistributor/MerkleDistributor.js +18 -17
- package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
- package/dist/esm/pool/TransactionManager.js +45 -100
- package/dist/esm/pool/TransactionManager.js.map +1 -1
- package/dist/esm/pool/poolClient.js +479 -740
- package/dist/esm/pool/poolClient.js.map +1 -1
- package/dist/esm/pool/uma/across/constants.js +2 -2
- package/dist/esm/pool/uma/across/constants.js.map +1 -1
- package/dist/esm/pool/uma/across/transactionManager.js +45 -100
- package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
- package/dist/esm/pool/uma/clients/erc20/client.js +15 -13
- package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
- package/dist/esm/pool/uma/oracle/utils.js +2 -3
- package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
- package/dist/esm/pool/uma/utils.js +9 -28
- package/dist/esm/pool/uma/utils.js.map +1 -1
- package/dist/esm/priceClient/adapters/acrossApi.js +21 -40
- package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
- package/dist/esm/priceClient/adapters/baseAdapter.js +46 -72
- package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/esm/priceClient/adapters/coingecko.js +33 -61
- package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
- package/dist/esm/priceClient/adapters/default.js +15 -31
- package/dist/esm/priceClient/adapters/default.js.map +1 -1
- package/dist/esm/priceClient/adapters/defiLlama.js +38 -73
- package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
- package/dist/esm/priceClient/priceClient.js +109 -158
- package/dist/esm/priceClient/priceClient.js.map +1 -1
- package/dist/esm/providers/alchemy.js +16 -18
- package/dist/esm/providers/alchemy.js.map +1 -1
- package/dist/esm/providers/cachedProvider.js +99 -134
- package/dist/esm/providers/cachedProvider.js.map +1 -1
- package/dist/esm/providers/constants.js +3 -3
- package/dist/esm/providers/constants.js.map +1 -1
- package/dist/esm/providers/drpc.js +8 -10
- package/dist/esm/providers/drpc.js.map +1 -1
- package/dist/esm/providers/infura.js +9 -11
- package/dist/esm/providers/infura.js.map +1 -1
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +6 -15
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +5 -14
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +6 -15
- package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +41 -66
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/mockEthersProvider.js +27 -30
- package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
- package/dist/esm/providers/quicknode.js +18 -20
- package/dist/esm/providers/quicknode.js.map +1 -1
- package/dist/esm/providers/rateLimitedProvider.js +68 -80
- package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
- package/dist/esm/providers/retryProvider.js +186 -259
- package/dist/esm/providers/retryProvider.js.map +1 -1
- package/dist/esm/providers/solana/baseRpcFactories.js +13 -19
- package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
- package/dist/esm/providers/solana/cachedRpcFactory.js +75 -112
- package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/defaultRpcFactory.js +6 -14
- package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +149 -202
- package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/rateLimitedRpcFactory.js +70 -90
- package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/retryRpcFactory.js +50 -74
- package/dist/esm/providers/solana/retryRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/utils.js +1 -1
- package/dist/esm/providers/solana/utils.js.map +1 -1
- package/dist/esm/providers/speedProvider.js +28 -51
- package/dist/esm/providers/speedProvider.js.map +1 -1
- package/dist/esm/providers/types.js +2 -2
- package/dist/esm/providers/types.js.map +1 -1
- package/dist/esm/providers/utils.js +17 -20
- package/dist/esm/providers/utils.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +98 -152
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +13 -26
- package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js +9 -19
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +83 -128
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +211 -299
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/typeguards/error.js +3 -5
- package/dist/esm/typeguards/error.js.map +1 -1
- package/dist/esm/utils/AddressUtils.js +115 -147
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/ArrayUtils.js +21 -78
- package/dist/esm/utils/ArrayUtils.js.map +1 -1
- package/dist/esm/utils/BigNumberUtils.js +11 -12
- package/dist/esm/utils/BigNumberUtils.js.map +1 -1
- package/dist/esm/utils/BlockExplorerUtils.js +19 -23
- package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
- package/dist/esm/utils/BlockFinder.js +2 -6
- package/dist/esm/utils/BlockFinder.js.map +1 -1
- package/dist/esm/utils/BlockUtils.js +31 -40
- package/dist/esm/utils/BlockUtils.js.map +1 -1
- package/dist/esm/utils/BundleUtils.js +21 -24
- package/dist/esm/utils/BundleUtils.js.map +1 -1
- package/dist/esm/utils/CCTPUtils.js +62 -123
- package/dist/esm/utils/CCTPUtils.js.map +1 -1
- package/dist/esm/utils/CachingUtils.js +17 -38
- package/dist/esm/utils/CachingUtils.js.map +1 -1
- package/dist/esm/utils/ContractUtils.js +3 -3
- package/dist/esm/utils/ContractUtils.js.map +1 -1
- package/dist/esm/utils/DepositUtils.js +121 -98
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +52 -69
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/FormattingUtils.js +20 -26
- package/dist/esm/utils/FormattingUtils.js.map +1 -1
- package/dist/esm/utils/HyperLiquidUtils.js +8 -22
- package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
- package/dist/esm/utils/IPFSUtils.js +16 -35
- package/dist/esm/utils/IPFSUtils.js.map +1 -1
- package/dist/esm/utils/JSONUtils.js +4 -4
- package/dist/esm/utils/JSONUtils.js.map +1 -1
- package/dist/esm/utils/LogUtils.js +8 -12
- package/dist/esm/utils/LogUtils.js.map +1 -1
- package/dist/esm/utils/Multicall.js +50 -109
- package/dist/esm/utils/Multicall.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.js +12 -21
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/NumberUtils.js +1 -3
- package/dist/esm/utils/NumberUtils.js.map +1 -1
- package/dist/esm/utils/ObjectUtils.js +27 -41
- package/dist/esm/utils/ObjectUtils.js.map +1 -1
- package/dist/esm/utils/Profiler.js +77 -82
- package/dist/esm/utils/Profiler.js.map +1 -1
- package/dist/esm/utils/ReviverUtils.js +3 -7
- package/dist/esm/utils/ReviverUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.js +83 -78
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.js +33 -57
- package/dist/esm/utils/TokenUtils.js.map +1 -1
- package/dist/esm/utils/ValidatorUtils.js +4 -4
- package/dist/esm/utils/ValidatorUtils.js.map +1 -1
- package/dist/esm/utils/abi/index.js +10 -20
- package/dist/esm/utils/abi/index.js.map +1 -1
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +8 -12
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
- package/dist/esm/utils/common.js +38 -52
- package/dist/esm/utils/common.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign, __awaiter, __extends, __generator, __spreadArray } from "tslib";
|
|
2
1
|
import assert from "assert";
|
|
3
2
|
import _ from "lodash";
|
|
4
3
|
import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL, TOKEN_SYMBOLS_MAP } from "../constants";
|
|
@@ -6,39 +5,42 @@ import * as lpFeeCalculator from "../lpFeeCalculator";
|
|
|
6
5
|
import { EVMBlockFinder } from "../arch/evm";
|
|
7
6
|
import { BigNumber, bnZero, dedupArray, assign, fetchTokenInfo, getCachedBlockForTimestamp, getCurrentTime, isDefined, mapAsync, paginatedEventQuery, shouldCache, sortEventsDescending, spreadEventWithBlockNumber, toBN, getTokenInfo, getUsdcSymbol, chainIsSvm, getDeployedAddress, SvmAddress, EvmAddress, } from "../utils";
|
|
8
7
|
import { BaseAbstractClient, isUpdateFailureReason, UpdateFailureReason } from "./BaseAbstractClient";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
8
|
+
export class HubPoolClient extends BaseAbstractClient {
|
|
9
|
+
logger;
|
|
10
|
+
hubPool;
|
|
11
|
+
configStoreClient;
|
|
12
|
+
deploymentBlock;
|
|
13
|
+
chainId;
|
|
14
|
+
configOverride;
|
|
15
|
+
l1Tokens = []; // L1Tokens and their associated info.
|
|
16
|
+
// @dev `token` here is a 20-byte hex sting
|
|
17
|
+
lpTokens = {};
|
|
18
|
+
proposedRootBundles = [];
|
|
19
|
+
canceledRootBundles = [];
|
|
20
|
+
disputedRootBundles = [];
|
|
21
|
+
executedRootBundles = [];
|
|
22
|
+
crossChainContracts = {};
|
|
23
|
+
l1TokensToDestinationTokensWithBlock = {};
|
|
24
|
+
pendingRootBundle;
|
|
25
|
+
currentTime;
|
|
26
|
+
blockFinder;
|
|
27
|
+
constructor(logger, hubPool, configStoreClient, deploymentBlock = 0, chainId = 1, eventSearchConfig = { from: 0, maxLookBack: 0 }, configOverride = {
|
|
28
|
+
ignoredHubExecutedBundles: [],
|
|
29
|
+
ignoredHubProposedBundles: [],
|
|
30
|
+
}, cachingMechanism) {
|
|
31
|
+
super(eventSearchConfig, cachingMechanism);
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
this.hubPool = hubPool;
|
|
34
|
+
this.configStoreClient = configStoreClient;
|
|
35
|
+
this.deploymentBlock = deploymentBlock;
|
|
36
|
+
this.chainId = chainId;
|
|
37
|
+
this.configOverride = configOverride;
|
|
38
|
+
this.latestHeightSearched = Math.min(deploymentBlock - 1, 0);
|
|
39
|
+
this.firstHeightToSearch = eventSearchConfig.from;
|
|
40
|
+
const provider = this.hubPool.provider;
|
|
41
|
+
this.blockFinder = new EVMBlockFinder(provider);
|
|
42
|
+
}
|
|
43
|
+
hubPoolEventFilters() {
|
|
42
44
|
return {
|
|
43
45
|
SetPoolRebalanceRoute: this.hubPool.filters.SetPoolRebalanceRoute(),
|
|
44
46
|
L1TokenEnabledForLiquidityProvision: this.hubPool.filters.L1TokenEnabledForLiquidityProvision(),
|
|
@@ -48,118 +50,107 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
48
50
|
RootBundleExecuted: this.hubPool.filters.RootBundleExecuted(),
|
|
49
51
|
CrossChainContractsSet: this.hubPool.filters.CrossChainContractsSet(),
|
|
50
52
|
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
+
}
|
|
54
|
+
hasPendingProposal() {
|
|
53
55
|
return this.pendingRootBundle !== undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
+
}
|
|
57
|
+
getPendingRootBundle() {
|
|
56
58
|
return this.pendingRootBundle;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
+
}
|
|
60
|
+
getProposedRootBundles() {
|
|
59
61
|
return this.proposedRootBundles;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
+
}
|
|
63
|
+
getCancelledRootBundles() {
|
|
62
64
|
return this.canceledRootBundles;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
+
}
|
|
66
|
+
getDisputedRootBundles() {
|
|
65
67
|
return this.disputedRootBundles;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
+
}
|
|
69
|
+
getExecutedRootBundles() {
|
|
68
70
|
return this.executedRootBundles;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (block === void 0) { block = Number.MAX_SAFE_INTEGER; }
|
|
71
|
+
}
|
|
72
|
+
getSpokePoolForBlock(chain, block = Number.MAX_SAFE_INTEGER) {
|
|
72
73
|
if (!this.crossChainContracts[chain]) {
|
|
73
|
-
throw new Error(
|
|
74
|
+
throw new Error(`No cross chain contracts set for ${chain}`);
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
const mostRecentSpokePoolUpdateBeforeBlock = sortEventsDescending(this.crossChainContracts[chain]).find((crossChainContract) => crossChainContract.blockNumber <= block);
|
|
76
77
|
if (!mostRecentSpokePoolUpdateBeforeBlock) {
|
|
77
|
-
throw new Error(
|
|
78
|
+
throw new Error(`No cross chain contract found before block ${block} for chain ${chain}`);
|
|
78
79
|
}
|
|
79
80
|
else {
|
|
80
81
|
return mostRecentSpokePoolUpdateBeforeBlock.spokePool;
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
83
|
+
}
|
|
84
|
+
getSpokePoolActivationBlock(chain, spokePool) {
|
|
84
85
|
// Return first time that this spoke pool was registered in the HubPool as a cross chain contract. We can use
|
|
85
86
|
// this block as the oldest block that we should query for SpokePoolClient purposes.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return mostRecentSpokePoolUpdateBeforeBlock === null || mostRecentSpokePoolUpdateBeforeBlock === void 0 ? void 0 : mostRecentSpokePoolUpdateBeforeBlock.blockNumber;
|
|
90
|
-
};
|
|
87
|
+
const mostRecentSpokePoolUpdateBeforeBlock = this.crossChainContracts[chain].find((crossChainContract) => crossChainContract.spokePool.eq(spokePool));
|
|
88
|
+
return mostRecentSpokePoolUpdateBeforeBlock?.blockNumber;
|
|
89
|
+
}
|
|
91
90
|
// Returns the latest L2 token to use for an L1 token as of the input hub block.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (latestHubBlock === void 0) { latestHubBlock = Number.MAX_SAFE_INTEGER; }
|
|
95
|
-
if (!((_b = (_a = this.l1TokensToDestinationTokensWithBlock) === null || _a === void 0 ? void 0 : _a[l1Token.toNative()]) === null || _b === void 0 ? void 0 : _b[destinationChainId])) {
|
|
91
|
+
getL2TokenForL1TokenAtBlock(l1Token, destinationChainId, latestHubBlock = Number.MAX_SAFE_INTEGER) {
|
|
92
|
+
if (!this.l1TokensToDestinationTokensWithBlock?.[l1Token.toNative()]?.[destinationChainId]) {
|
|
96
93
|
return undefined;
|
|
97
94
|
}
|
|
98
95
|
// Find the last mapping published before the target block.
|
|
99
|
-
|
|
96
|
+
const l2Token = this.l1TokensToDestinationTokensWithBlock[l1Token.toNative()][destinationChainId].find((mapping) => mapping.blockNumber <= latestHubBlock);
|
|
100
97
|
return !isDefined(l2Token) || l2Token.l2Token.isZeroAddress() ? undefined : l2Token.l2Token;
|
|
101
|
-
}
|
|
98
|
+
}
|
|
102
99
|
// Returns the latest L1 token to use for an L2 token as of the input hub block.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (latestHubBlock === void 0) { latestHubBlock = Number.MAX_SAFE_INTEGER; }
|
|
106
|
-
var l2Tokens = Object.keys(this.l1TokensToDestinationTokensWithBlock).flatMap(function (l1Token) {
|
|
107
|
-
var _a;
|
|
100
|
+
getL1TokenForL2TokenAtBlock(l2Token, destinationChainId, latestHubBlock = Number.MAX_SAFE_INTEGER) {
|
|
101
|
+
const l2Tokens = Object.keys(this.l1TokensToDestinationTokensWithBlock).flatMap((l1Token) => {
|
|
108
102
|
// Get the latest L2 token mapping for the given L1 token.
|
|
109
103
|
// @dev Since tokens on L2s (like Solana) can have 32 byte addresses, filter on the lower 20 bytes of the token only.
|
|
110
|
-
|
|
104
|
+
const sortedL2Tokens = sortEventsDescending((this.l1TokensToDestinationTokensWithBlock[l1Token][destinationChainId] ?? []).filter((dstTokenWithBlock) => dstTokenWithBlock.blockNumber <= latestHubBlock));
|
|
111
105
|
// If the latest L2 token mapping is equal to the target L2 token, return it.
|
|
112
106
|
return sortedL2Tokens.length > 0 && sortedL2Tokens[0].l2Token.truncateToBytes20() === l2Token.truncateToBytes20()
|
|
113
107
|
? sortedL2Tokens[0]
|
|
114
108
|
: [];
|
|
115
109
|
});
|
|
116
110
|
return l2Tokens.length === 0 ? undefined : sortEventsDescending(l2Tokens)[0].l1Token;
|
|
117
|
-
}
|
|
118
|
-
|
|
111
|
+
}
|
|
112
|
+
getL1TokenForDeposit(deposit) {
|
|
119
113
|
// L1-->L2 token mappings are set via PoolRebalanceRoutes which occur on mainnet,
|
|
120
114
|
// so we use the latest token mapping. This way if a very old deposit is filled, the relayer can use the
|
|
121
115
|
// latest L2 token mapping to find the L1 token counterpart.
|
|
122
116
|
return this.getL1TokenForL2TokenAtBlock(deposit.inputToken, deposit.originChainId, deposit.quoteBlockNumber);
|
|
123
|
-
}
|
|
124
|
-
|
|
117
|
+
}
|
|
118
|
+
l2TokenEnabledForL1Token(l1Token, destinationChainId) {
|
|
125
119
|
return this.l2TokenEnabledForL1TokenAtBlock(l1Token, destinationChainId, Number.MAX_SAFE_INTEGER);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
var _a, _b, _c;
|
|
120
|
+
}
|
|
121
|
+
l2TokenEnabledForL1TokenAtBlock(l1Token, destinationChainId, hubBlockNumber) {
|
|
129
122
|
// Find the last mapping published before the target block.
|
|
130
|
-
|
|
123
|
+
const l2Token = sortEventsDescending(this.l1TokensToDestinationTokensWithBlock?.[l1Token.toNative()]?.[destinationChainId] ?? []).find((mapping) => mapping.blockNumber <= hubBlockNumber);
|
|
131
124
|
return isDefined(l2Token) && !l2Token.l2Token.isZeroAddress();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var l1Token = this.getL1TokenForL2TokenAtBlock(l2Token, l2ChainId, hubPoolBlock);
|
|
125
|
+
}
|
|
126
|
+
l2TokenHasPoolRebalanceRoute(l2Token, l2ChainId, hubPoolBlock = this.latestHeightSearched) {
|
|
127
|
+
const l1Token = this.getL1TokenForL2TokenAtBlock(l2Token, l2ChainId, hubPoolBlock);
|
|
136
128
|
return isDefined(l1Token);
|
|
137
|
-
}
|
|
129
|
+
}
|
|
138
130
|
/**
|
|
139
131
|
* @dev If tokenAddress + chain do not exist in TOKEN_SYMBOLS_MAP then this will throw.
|
|
140
132
|
* @param tokenAddress Token address on `chain`
|
|
141
133
|
* @param chainId Chain where the `tokenAddress` exists in TOKEN_SYMBOLS_MAP.
|
|
142
134
|
* @returns Token info for the given token address on the L2 chain including symbol and decimal.
|
|
143
135
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var tokenInfo = getTokenInfo(address, chainId);
|
|
136
|
+
getTokenInfoForAddress(address, chainId) {
|
|
137
|
+
const tokenInfo = getTokenInfo(address, chainId);
|
|
147
138
|
// @dev Temporarily handle case where an L2 token for chain ID can map to more than one TOKEN_SYMBOLS_MAP
|
|
148
139
|
// entry. For example, L2 Bridged USDC maps to both the USDC and USDC.e/USDbC entries in TOKEN_SYMBOLS_MAP.
|
|
149
140
|
if (tokenInfo.symbol.toLowerCase() === "usdc" && chainId !== this.chainId) {
|
|
150
|
-
tokenInfo.symbol =
|
|
141
|
+
tokenInfo.symbol = getUsdcSymbol(address, chainId) ?? "UNKNOWN USDC";
|
|
151
142
|
}
|
|
152
143
|
return tokenInfo;
|
|
153
|
-
}
|
|
144
|
+
}
|
|
154
145
|
/**
|
|
155
146
|
* Resolve a given timestamp to a block number on the HubPool chain.
|
|
156
147
|
* @param timestamp A single timestamp to be resolved to a block number on the HubPool chain.
|
|
157
148
|
* @returns The block number corresponding to the supplied timestamp.
|
|
158
149
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
getBlockNumber(timestamp) {
|
|
151
|
+
const hints = { lowBlock: this.deploymentBlock };
|
|
161
152
|
return getCachedBlockForTimestamp(this.chainId, timestamp, this.blockFinder, this.cachingMechanism, hints);
|
|
162
|
-
}
|
|
153
|
+
}
|
|
163
154
|
/**
|
|
164
155
|
* For an array of timestamps, resolve each unique timestamp to a block number on the HubPool chain.
|
|
165
156
|
* @dev Inputs are filtered for uniqueness and sorted to improve BlockFinder efficiency.
|
|
@@ -167,55 +158,18 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
167
158
|
* @param timestamps Array of timestamps to be resolved to a block number on the HubPool chain.
|
|
168
159
|
* @returns A mapping of quoteTimestamp -> HubPool block number.
|
|
169
160
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
timestamp = sortedTimestamps_1[_i];
|
|
183
|
-
_a = blockNumbers;
|
|
184
|
-
_b = timestamp;
|
|
185
|
-
return [4 /*yield*/, this.getBlockNumber(timestamp)];
|
|
186
|
-
case 2:
|
|
187
|
-
_a[_b] = _c.sent();
|
|
188
|
-
_c.label = 3;
|
|
189
|
-
case 3:
|
|
190
|
-
_i++;
|
|
191
|
-
return [3 /*break*/, 1];
|
|
192
|
-
case 4: return [2 /*return*/, blockNumbers];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
HubPoolClient.prototype.getCurrentPoolUtilization = function (l1Token) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
199
|
-
var blockNumber, _a;
|
|
200
|
-
var _b;
|
|
201
|
-
return __generator(this, function (_c) {
|
|
202
|
-
switch (_c.label) {
|
|
203
|
-
case 0:
|
|
204
|
-
if (!((_b = this.latestHeightSearched) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
205
|
-
_a = _b;
|
|
206
|
-
return [3 /*break*/, 3];
|
|
207
|
-
case 1: return [4 /*yield*/, this.hubPool.provider.getBlockNumber()];
|
|
208
|
-
case 2:
|
|
209
|
-
_a = (_c.sent());
|
|
210
|
-
_c.label = 3;
|
|
211
|
-
case 3:
|
|
212
|
-
blockNumber = _a;
|
|
213
|
-
return [4 /*yield*/, this.getUtilization(l1Token, blockNumber, bnZero, getCurrentTime(), 0)];
|
|
214
|
-
case 4: return [2 /*return*/, _c.sent()];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
};
|
|
161
|
+
async getBlockNumbers(timestamps) {
|
|
162
|
+
const sortedTimestamps = dedupArray(timestamps).sort((x, y) => x - y);
|
|
163
|
+
const blockNumbers = {};
|
|
164
|
+
for (const timestamp of sortedTimestamps) {
|
|
165
|
+
blockNumbers[timestamp] = await this.getBlockNumber(timestamp);
|
|
166
|
+
}
|
|
167
|
+
return blockNumbers;
|
|
168
|
+
}
|
|
169
|
+
async getCurrentPoolUtilization(l1Token) {
|
|
170
|
+
const blockNumber = this.latestHeightSearched ?? (await this.hubPool.provider.getBlockNumber());
|
|
171
|
+
return await this.getUtilization(l1Token, blockNumber, bnZero, getCurrentTime(), 0);
|
|
172
|
+
}
|
|
219
173
|
/**
|
|
220
174
|
* For a HubPool token at a specific block number, compute the relevant utilization.
|
|
221
175
|
* @param hubPoolToken HubPool token to query utilization for.
|
|
@@ -225,261 +179,190 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
225
179
|
* @param timeToCache Age at which the response is able to be cached.
|
|
226
180
|
* @returns HubPool utilization at `blockNumber` after optional `amount` increase in utilization.
|
|
227
181
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
originChainId = deposit.originChainId, paymentChainId = deposit.paymentChainId, inputAmount = deposit.inputAmount, quoteTimestamp = deposit.quoteTimestamp;
|
|
362
|
-
quoteBlock = quoteBlocks[quoteTimestamp];
|
|
363
|
-
if (paymentChainId === undefined || paymentChainId === originChainId) {
|
|
364
|
-
return [2 /*return*/, { quoteBlock: quoteBlock, realizedLpFeePct: bnZero }];
|
|
365
|
-
}
|
|
366
|
-
hubPoolToken = getHubPoolToken(deposit, quoteBlock);
|
|
367
|
-
if (hubPoolToken === undefined) {
|
|
368
|
-
throw new Error("Cannot computeRealizedLpFeePct for deposit with no pool rebalance route for input token ".concat(deposit.inputToken, " on ").concat(originChainId));
|
|
369
|
-
}
|
|
370
|
-
rateModel = this.configStoreClient.getRateModelForBlockNumber(hubPoolToken, originChainId, paymentChainId, quoteBlock);
|
|
371
|
-
preUtilization = utilization[hubPoolToken.toNative()][quoteBlock];
|
|
372
|
-
return [4 /*yield*/, this.getUtilization(hubPoolToken, quoteBlock, inputAmount, quoteTimestamp, timeToCache)];
|
|
373
|
-
case 1:
|
|
374
|
-
postUtilization = _a.sent();
|
|
375
|
-
realizedLpFeePct = lpFeeCalculator.calculateRealizedLpFeePct(rateModel, preUtilization, postUtilization);
|
|
376
|
-
return [2 /*return*/, { quoteBlock: quoteBlock, realizedLpFeePct: realizedLpFeePct }];
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
}); };
|
|
380
|
-
timeToCache = (_c = this.configOverride.timeToCache) !== null && _c !== void 0 ? _c : DEFAULT_CACHING_SAFE_LAG;
|
|
381
|
-
quoteTimestamps = dedupArray(deposits.map(function (_a) {
|
|
382
|
-
var quoteTimestamp = _a.quoteTimestamp;
|
|
383
|
-
return quoteTimestamp;
|
|
384
|
-
}));
|
|
385
|
-
return [4 /*yield*/, this.getBlockNumbers(quoteTimestamps)];
|
|
386
|
-
case 1:
|
|
387
|
-
quoteBlocks = _d.sent();
|
|
388
|
-
// Identify the unique hubPoolToken & quoteTimestamp mappings. This is used to optimise subsequent HubPool queries.
|
|
389
|
-
deposits.forEach(function (deposit) { return resolveUniqueQuoteTimestamps(deposit); });
|
|
390
|
-
_b = (_a = Object).fromEntries;
|
|
391
|
-
return [4 /*yield*/, mapAsync(getHubPoolTokens(), function (hubPoolToken) { return __awaiter(_this, void 0, void 0, function () {
|
|
392
|
-
var _a;
|
|
393
|
-
return __generator(this, function (_b) {
|
|
394
|
-
switch (_b.label) {
|
|
395
|
-
case 0:
|
|
396
|
-
_a = [hubPoolToken.toNative()];
|
|
397
|
-
return [4 /*yield*/, resolveUtilization(hubPoolToken)];
|
|
398
|
-
case 1: return [2 /*return*/, _a.concat([
|
|
399
|
-
_b.sent()
|
|
400
|
-
])];
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
}); })];
|
|
404
|
-
case 2:
|
|
405
|
-
// For each token / quoteBlock pair, resolve the utilisation for each quoted block.
|
|
406
|
-
// This can be reused for each deposit with the same HubPool token and quoteTimestamp pair.
|
|
407
|
-
utilization = _b.apply(_a, [_d.sent()]);
|
|
408
|
-
return [4 /*yield*/, mapAsync(deposits, function (deposit) { return __awaiter(_this, void 0, void 0, function () {
|
|
409
|
-
var quoteBlock;
|
|
410
|
-
return __generator(this, function (_a) {
|
|
411
|
-
switch (_a.label) {
|
|
412
|
-
case 0:
|
|
413
|
-
quoteBlock = quoteBlocks[deposit.quoteTimestamp];
|
|
414
|
-
if (!this.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, quoteBlock)) return [3 /*break*/, 2];
|
|
415
|
-
return [4 /*yield*/, computeRealizedLpFeePct(deposit)];
|
|
416
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
417
|
-
case 2: return [2 /*return*/, {
|
|
418
|
-
quoteBlock: quoteBlock,
|
|
419
|
-
realizedLpFeePct: bnZero,
|
|
420
|
-
}];
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
}); })];
|
|
424
|
-
case 3:
|
|
425
|
-
// For each deposit, compute the post-relay HubPool utilisation independently.
|
|
426
|
-
// @dev The caller expects to receive an array in the same length and ordering as the input `deposits`.
|
|
427
|
-
return [2 /*return*/, _d.sent()];
|
|
428
|
-
}
|
|
429
|
-
});
|
|
182
|
+
async getUtilization(hubPoolToken, blockNumber, depositAmount, timestamp, timeToCache) {
|
|
183
|
+
// Resolve this function call as an async anonymous function
|
|
184
|
+
const resolver = () => {
|
|
185
|
+
const overrides = { blockTag: blockNumber };
|
|
186
|
+
const token = hubPoolToken.toNative();
|
|
187
|
+
// For zero amount, just get the utilisation at `blockNumber`.
|
|
188
|
+
return depositAmount.eq(bnZero)
|
|
189
|
+
? this.hubPool.callStatic.liquidityUtilizationCurrent(token, overrides)
|
|
190
|
+
: this.hubPool.callStatic.liquidityUtilizationPostRelay(token, depositAmount, overrides);
|
|
191
|
+
};
|
|
192
|
+
// Resolve the cache locally so that we can appease typescript
|
|
193
|
+
const cache = this.cachingMechanism;
|
|
194
|
+
// If there is no cache or the timestamp is not old enough to be cached, just resolve the function.
|
|
195
|
+
if (!cache || !shouldCache(getCurrentTime(), timestamp, timeToCache)) {
|
|
196
|
+
return resolver();
|
|
197
|
+
}
|
|
198
|
+
// Otherwise, let's resolve the key
|
|
199
|
+
const key = depositAmount.eq(bnZero)
|
|
200
|
+
? `utilization_${hubPoolToken.toNative()}_${blockNumber}`
|
|
201
|
+
: `utilization_${hubPoolToken.toNative()}_${blockNumber}_${depositAmount.toString()}`;
|
|
202
|
+
const result = await cache.get(key);
|
|
203
|
+
if (isDefined(result)) {
|
|
204
|
+
return BigNumber.from(result);
|
|
205
|
+
}
|
|
206
|
+
// We were not able to find a valid result, so let's resolve the function.
|
|
207
|
+
const utilization = await resolver();
|
|
208
|
+
if (cache && shouldCache(getCurrentTime(), timestamp, timeToCache)) {
|
|
209
|
+
// If we should cache the result, store it for up to DEFAULT_CACHING_TTL.
|
|
210
|
+
await cache.set(key, `${utilization.toString()}`, DEFAULT_CACHING_TTL);
|
|
211
|
+
}
|
|
212
|
+
return utilization;
|
|
213
|
+
}
|
|
214
|
+
async computeRealizedLpFeePct(deposit) {
|
|
215
|
+
const [lpFee] = await this.batchComputeRealizedLpFeePct([deposit]);
|
|
216
|
+
return lpFee;
|
|
217
|
+
}
|
|
218
|
+
async batchComputeRealizedLpFeePct(deposits) {
|
|
219
|
+
assert(deposits.length > 0, "No deposits supplied to batchComputeRealizedLpFeePct");
|
|
220
|
+
if (!isDefined(this.currentTime)) {
|
|
221
|
+
throw new Error("HubPoolClient has not set a currentTime");
|
|
222
|
+
}
|
|
223
|
+
// Map each HubPool token to an array of unique quoteTimestamps.
|
|
224
|
+
const utilizationTimestamps = {};
|
|
225
|
+
// Map each HubPool token to utilization at a particular block number.
|
|
226
|
+
let utilization = {};
|
|
227
|
+
let quoteBlocks = {};
|
|
228
|
+
// Map SpokePool token addresses to HubPool token addresses.
|
|
229
|
+
// Note: Should only be accessed via `getHubPoolToken()` or `getHubPoolTokens()`.
|
|
230
|
+
const hubPoolTokens = {};
|
|
231
|
+
const getHubPoolToken = (deposit, quoteBlockNumber) => {
|
|
232
|
+
const tokenKey = `${deposit.originChainId}-${deposit.inputToken}`;
|
|
233
|
+
const l1Token = this.getL1TokenForDeposit({ ...deposit, quoteBlockNumber });
|
|
234
|
+
if (!isDefined(l1Token)) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
return (hubPoolTokens[tokenKey] ??= l1Token);
|
|
238
|
+
};
|
|
239
|
+
// Filter hubPoolTokens for duplicates by reverting to their native string
|
|
240
|
+
// representation. This is required for deduplication to work reliably.
|
|
241
|
+
const getHubPoolTokens = () => dedupArray(Object.values(hubPoolTokens)
|
|
242
|
+
.filter(isDefined)
|
|
243
|
+
.map((token) => token.toNative())).map((token) => EvmAddress.from(token));
|
|
244
|
+
// Helper to resolve the unique hubPoolToken & quoteTimestamp mappings.
|
|
245
|
+
const resolveUniqueQuoteTimestamps = (deposit) => {
|
|
246
|
+
const { quoteTimestamp } = deposit;
|
|
247
|
+
// Resolve the HubPool token address for this origin chainId/token pair, if it isn't already known.
|
|
248
|
+
const quoteBlockNumber = quoteBlocks[quoteTimestamp];
|
|
249
|
+
const hubPoolToken = getHubPoolToken(deposit, quoteBlockNumber);
|
|
250
|
+
if (!hubPoolToken) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
// Append the quoteTimestamp for this HubPool token, if it isn't already enqueued.
|
|
254
|
+
const token = hubPoolToken.toNative();
|
|
255
|
+
utilizationTimestamps[token] ??= [];
|
|
256
|
+
if (!utilizationTimestamps[token].includes(quoteTimestamp)) {
|
|
257
|
+
utilizationTimestamps[token].push(quoteTimestamp);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
// Helper to resolve existing HubPool token utilisation for an array of unique block numbers.
|
|
261
|
+
// Produces a mapping of blockNumber -> utilization for a specific token.
|
|
262
|
+
const resolveUtilization = async (hubPoolToken) => {
|
|
263
|
+
return Object.fromEntries(await mapAsync(utilizationTimestamps[hubPoolToken.toNative()], async (quoteTimestamp) => {
|
|
264
|
+
const blockNumber = quoteBlocks[quoteTimestamp];
|
|
265
|
+
const utilization = await this.getUtilization(hubPoolToken, blockNumber, bnZero, // amount
|
|
266
|
+
quoteTimestamp, timeToCache);
|
|
267
|
+
return [blockNumber, utilization];
|
|
268
|
+
}));
|
|
269
|
+
};
|
|
270
|
+
// Helper compute the realizedLpFeePct of an individual deposit based on pre-retrieved batch data.
|
|
271
|
+
const computeRealizedLpFeePct = async (deposit) => {
|
|
272
|
+
const { originChainId, paymentChainId, inputAmount, quoteTimestamp } = deposit;
|
|
273
|
+
const quoteBlock = quoteBlocks[quoteTimestamp];
|
|
274
|
+
if (paymentChainId === undefined || paymentChainId === originChainId) {
|
|
275
|
+
return { quoteBlock, realizedLpFeePct: bnZero };
|
|
276
|
+
}
|
|
277
|
+
const hubPoolToken = getHubPoolToken(deposit, quoteBlock);
|
|
278
|
+
if (hubPoolToken === undefined) {
|
|
279
|
+
throw new Error(`Cannot computeRealizedLpFeePct for deposit with no pool rebalance route for input token ${deposit.inputToken} on ${originChainId}`);
|
|
280
|
+
}
|
|
281
|
+
const rateModel = this.configStoreClient.getRateModelForBlockNumber(hubPoolToken, originChainId, paymentChainId, quoteBlock);
|
|
282
|
+
const preUtilization = utilization[hubPoolToken.toNative()][quoteBlock];
|
|
283
|
+
const postUtilization = await this.getUtilization(hubPoolToken, quoteBlock, inputAmount, quoteTimestamp, timeToCache);
|
|
284
|
+
const realizedLpFeePct = lpFeeCalculator.calculateRealizedLpFeePct(rateModel, preUtilization, postUtilization);
|
|
285
|
+
return { quoteBlock, realizedLpFeePct };
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Execution flow starts here.
|
|
289
|
+
*/
|
|
290
|
+
const timeToCache = this.configOverride.timeToCache ?? DEFAULT_CACHING_SAFE_LAG;
|
|
291
|
+
// Filter all deposits for unique quoteTimestamps, to be resolved to a blockNumber in parallel.
|
|
292
|
+
const quoteTimestamps = dedupArray(deposits.map(({ quoteTimestamp }) => quoteTimestamp));
|
|
293
|
+
quoteBlocks = await this.getBlockNumbers(quoteTimestamps);
|
|
294
|
+
// Identify the unique hubPoolToken & quoteTimestamp mappings. This is used to optimise subsequent HubPool queries.
|
|
295
|
+
deposits.forEach((deposit) => resolveUniqueQuoteTimestamps(deposit));
|
|
296
|
+
// For each token / quoteBlock pair, resolve the utilisation for each quoted block.
|
|
297
|
+
// This can be reused for each deposit with the same HubPool token and quoteTimestamp pair.
|
|
298
|
+
utilization = Object.fromEntries(await mapAsync(getHubPoolTokens(), async (hubPoolToken) => [
|
|
299
|
+
hubPoolToken.toNative(),
|
|
300
|
+
await resolveUtilization(hubPoolToken),
|
|
301
|
+
]));
|
|
302
|
+
// For each deposit, compute the post-relay HubPool utilisation independently.
|
|
303
|
+
// @dev The caller expects to receive an array in the same length and ordering as the input `deposits`.
|
|
304
|
+
return await mapAsync(deposits, async (deposit) => {
|
|
305
|
+
const quoteBlock = quoteBlocks[deposit.quoteTimestamp];
|
|
306
|
+
if (this.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, quoteBlock)) {
|
|
307
|
+
return await computeRealizedLpFeePct(deposit);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return {
|
|
311
|
+
quoteBlock,
|
|
312
|
+
realizedLpFeePct: bnZero,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
430
315
|
});
|
|
431
|
-
}
|
|
432
|
-
|
|
316
|
+
}
|
|
317
|
+
getL1Tokens() {
|
|
433
318
|
return this.l1Tokens;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return this.l1Tokens.find(
|
|
437
|
-
}
|
|
438
|
-
|
|
319
|
+
}
|
|
320
|
+
getTokenInfoForL1Token(l1Token) {
|
|
321
|
+
return this.l1Tokens.find((token) => token.address.eq(l1Token));
|
|
322
|
+
}
|
|
323
|
+
getLpTokenInfoForL1Token(l1Token) {
|
|
439
324
|
return this.lpTokens[l1Token.toNative()];
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (hubPoolBlock === void 0) { hubPoolBlock = this.latestHeightSearched; }
|
|
325
|
+
}
|
|
326
|
+
areTokensEquivalent(tokenA, chainIdA, tokenB, chainIdB, hubPoolBlock = this.latestHeightSearched) {
|
|
443
327
|
if (!this.l2TokenHasPoolRebalanceRoute(tokenA, chainIdA, hubPoolBlock) ||
|
|
444
328
|
!this.l2TokenHasPoolRebalanceRoute(tokenB, chainIdB, hubPoolBlock)) {
|
|
445
329
|
return false;
|
|
446
330
|
}
|
|
447
331
|
// Resolve both SpokePool tokens back to their respective HubPool tokens and verify that they match.
|
|
448
|
-
|
|
449
|
-
|
|
332
|
+
const l1TokenA = this.getL1TokenForL2TokenAtBlock(tokenA, chainIdA, hubPoolBlock);
|
|
333
|
+
const l1TokenB = this.getL1TokenForL2TokenAtBlock(tokenB, chainIdB, hubPoolBlock);
|
|
450
334
|
if (!isDefined(l1TokenA) || !isDefined(l1TokenB) || !l1TokenA.eq(l1TokenB)) {
|
|
451
335
|
return false;
|
|
452
336
|
}
|
|
453
337
|
// Resolve both HubPool tokens back to a current SpokePool token and verify that they match.
|
|
454
|
-
|
|
455
|
-
|
|
338
|
+
const _tokenA = this.getL2TokenForL1TokenAtBlock(l1TokenA, chainIdA, hubPoolBlock);
|
|
339
|
+
const _tokenB = this.getL2TokenForL1TokenAtBlock(l1TokenB, chainIdB, hubPoolBlock);
|
|
456
340
|
return isDefined(_tokenA) && isDefined(_tokenB) && tokenA.eq(_tokenA) && tokenB.eq(_tokenB);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
};
|
|
341
|
+
}
|
|
342
|
+
getSpokeActivationBlockForChain(chainId) {
|
|
343
|
+
return this.getSpokePoolActivationBlock(chainId, this.getSpokePoolForBlock(chainId)) ?? 0;
|
|
344
|
+
}
|
|
462
345
|
// Root bundles are valid if all of their pool rebalance leaves have been executed before the next bundle, or the
|
|
463
346
|
// latest mainnet block to search. Whichever comes first.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
347
|
+
isRootBundleValid(rootBundle, latestMainnetBlock) {
|
|
348
|
+
const nextRootBundle = this.getFollowingRootBundle(rootBundle);
|
|
349
|
+
const executedLeafCount = this.getExecutedLeavesForRootBundle(rootBundle, nextRootBundle ? Math.min(nextRootBundle.blockNumber, latestMainnetBlock) : latestMainnetBlock);
|
|
467
350
|
return executedLeafCount.length === rootBundle.poolRebalanceLeafCount;
|
|
468
|
-
}
|
|
351
|
+
}
|
|
469
352
|
// This should find the ProposeRootBundle event whose bundle block number for `chain` is closest to the `block`
|
|
470
353
|
// without being smaller. It returns the bundle block number for the chain or undefined if not matched.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
354
|
+
getRootBundleEvalBlockNumberContainingBlock(latestMainnetBlock, block, chain, chainIdListOverride) {
|
|
355
|
+
const chainIdList = chainIdListOverride ?? this.configStoreClient.getChainIdIndicesForBlock(latestMainnetBlock);
|
|
356
|
+
let endingBlockNumber;
|
|
474
357
|
// Search proposed root bundles in reverse chronological order.
|
|
475
|
-
for (
|
|
476
|
-
|
|
477
|
-
|
|
358
|
+
for (let i = this.proposedRootBundles.length - 1; i >= 0; i--) {
|
|
359
|
+
const rootBundle = this.proposedRootBundles[i];
|
|
360
|
+
const nextRootBundle = this.getFollowingRootBundle(rootBundle);
|
|
478
361
|
if (!this.isRootBundleValid(rootBundle, nextRootBundle ? nextRootBundle.blockNumber : latestMainnetBlock)) {
|
|
479
362
|
continue;
|
|
480
363
|
}
|
|
481
364
|
// 0 is the default value bundleEvalBlockNumber.
|
|
482
|
-
|
|
365
|
+
const bundleEvalBlockNumber = this.getBundleEndBlockForChain(rootBundle, chain, chainIdList);
|
|
483
366
|
// Since we're iterating from newest to oldest, bundleEvalBlockNumber is only decreasing, and if the
|
|
484
367
|
// bundleEvalBlockNumber is smaller than the target block, then we should return the last set `endingBlockNumber`.
|
|
485
368
|
if (bundleEvalBlockNumber <= block) {
|
|
@@ -491,18 +374,18 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
491
374
|
endingBlockNumber = bundleEvalBlockNumber;
|
|
492
375
|
}
|
|
493
376
|
return endingBlockNumber;
|
|
494
|
-
}
|
|
377
|
+
}
|
|
495
378
|
// TODO: This might not be necessary since the cumulative root bundle count doesn't grow fast enough, but consider
|
|
496
379
|
// using _.findLast/_.find instead of resorting the arrays if these functions begin to take a lot time.
|
|
497
|
-
|
|
498
|
-
return this.proposedRootBundles.filter(
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
return sortEventsDescending(this.canceledRootBundles).filter(
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
return sortEventsDescending(this.disputedRootBundles).filter(
|
|
505
|
-
}
|
|
380
|
+
getProposedRootBundlesInBlockRange(startingBlock, endingBlock) {
|
|
381
|
+
return this.proposedRootBundles.filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
|
|
382
|
+
}
|
|
383
|
+
getCancelledRootBundlesInBlockRange(startingBlock, endingBlock) {
|
|
384
|
+
return sortEventsDescending(this.canceledRootBundles).filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
|
|
385
|
+
}
|
|
386
|
+
getDisputedRootBundlesInBlockRange(startingBlock, endingBlock) {
|
|
387
|
+
return sortEventsDescending(this.disputedRootBundles).filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
|
|
388
|
+
}
|
|
506
389
|
/**
|
|
507
390
|
* Retrieves token mappings that were modified within a specified block range.
|
|
508
391
|
* @param startingBlock - The starting block of the range (inclusive).
|
|
@@ -510,115 +393,108 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
510
393
|
* @returns An array of destination tokens, each containing the `l2ChainId`, that
|
|
511
394
|
* were modified within the given block range.
|
|
512
395
|
*/
|
|
513
|
-
|
|
396
|
+
getTokenMappingsModifiedInBlockRange(startingBlock, endingBlock) {
|
|
514
397
|
// This function iterates over `l1TokensToDestinationTokensWithBlock`, a nested
|
|
515
398
|
// structure of L1 tokens mapped to destination chain IDs, each containing lists
|
|
516
399
|
// of destination tokens with associated block numbers.
|
|
517
400
|
return (Object.values(this.l1TokensToDestinationTokensWithBlock)
|
|
518
|
-
.flatMap(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
})
|
|
401
|
+
.flatMap((destinationTokens) =>
|
|
402
|
+
// Map through destination chain IDs and their associated tokens
|
|
403
|
+
Object.entries(destinationTokens).flatMap(([destinationChainId, tokensWithBlock]) =>
|
|
404
|
+
// Map the tokens to add the l2ChainId field for each token
|
|
405
|
+
tokensWithBlock.map((token) => ({
|
|
406
|
+
...token,
|
|
407
|
+
l2ChainId: Number(destinationChainId),
|
|
408
|
+
}))))
|
|
526
409
|
// Filter out tokens whose blockNumber is outside the block range
|
|
527
|
-
.filter(
|
|
528
|
-
}
|
|
529
|
-
|
|
410
|
+
.filter((token) => token.blockNumber >= startingBlock && token.blockNumber <= endingBlock));
|
|
411
|
+
}
|
|
412
|
+
getLatestProposedRootBundle() {
|
|
530
413
|
return this.proposedRootBundles[this.proposedRootBundles.length - 1];
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
414
|
+
}
|
|
415
|
+
getFollowingRootBundle(currentRootBundle) {
|
|
416
|
+
const index = _.findLastIndex(this.proposedRootBundles, (bundle) => bundle.blockNumber === currentRootBundle.blockNumber);
|
|
534
417
|
// If index of current root bundle is not found or is the last bundle, return undefined.
|
|
535
418
|
if (index === -1 || index === this.proposedRootBundles.length - 1) {
|
|
536
419
|
return undefined;
|
|
537
420
|
}
|
|
538
421
|
return this.proposedRootBundles[index + 1];
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return this.executedRootBundles.filter(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
HubPoolClient.prototype.getValidatedRootBundles = function (latestMainnetBlock) {
|
|
551
|
-
var _this = this;
|
|
552
|
-
if (latestMainnetBlock === void 0) { latestMainnetBlock = Number.MAX_SAFE_INTEGER; }
|
|
553
|
-
return this.proposedRootBundles.filter(function (rootBundle) {
|
|
422
|
+
}
|
|
423
|
+
getExecutedLeavesForRootBundle(rootBundle, latestMainnetBlockToSearch) {
|
|
424
|
+
return this.executedRootBundles.filter((executedLeaf) => executedLeaf.blockNumber <= latestMainnetBlockToSearch &&
|
|
425
|
+
// Note: We can use > instead of >= here because a leaf can never be executed in same block as its root
|
|
426
|
+
// proposal due to bundle liveness enforced by HubPool. This importantly avoids the edge case
|
|
427
|
+
// where the execution all leaves occurs in the same block as the next proposal, leading us to think
|
|
428
|
+
// that the next proposal is fully executed when its not.
|
|
429
|
+
executedLeaf.blockNumber > rootBundle.blockNumber);
|
|
430
|
+
}
|
|
431
|
+
getValidatedRootBundles(latestMainnetBlock = Number.MAX_SAFE_INTEGER) {
|
|
432
|
+
return this.proposedRootBundles.filter((rootBundle) => {
|
|
554
433
|
if (rootBundle.blockNumber > latestMainnetBlock) {
|
|
555
434
|
return false;
|
|
556
435
|
}
|
|
557
|
-
return
|
|
436
|
+
return this.isRootBundleValid(rootBundle, latestMainnetBlock);
|
|
558
437
|
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
var _this = this;
|
|
438
|
+
}
|
|
439
|
+
getLatestFullyExecutedRootBundle(latestMainnetBlock) {
|
|
562
440
|
// Search for latest ProposeRootBundleExecuted event followed by all of its RootBundleExecuted event suggesting
|
|
563
441
|
// that all pool rebalance leaves were executed. This ignores any proposed bundles that were partially executed.
|
|
564
|
-
return _.findLast(this.proposedRootBundles,
|
|
442
|
+
return _.findLast(this.proposedRootBundles, (rootBundle) => {
|
|
565
443
|
if (rootBundle.blockNumber > latestMainnetBlock) {
|
|
566
444
|
return false;
|
|
567
445
|
}
|
|
568
|
-
return
|
|
446
|
+
return this.isRootBundleValid(rootBundle, latestMainnetBlock);
|
|
569
447
|
});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (startBlock === void 0) { startBlock = 0; }
|
|
574
|
-
return this.proposedRootBundles.find(function (rootBundle) {
|
|
448
|
+
}
|
|
449
|
+
getEarliestFullyExecutedRootBundle(latestMainnetBlock, startBlock = 0) {
|
|
450
|
+
return this.proposedRootBundles.find((rootBundle) => {
|
|
575
451
|
if (rootBundle.blockNumber > latestMainnetBlock) {
|
|
576
452
|
return false;
|
|
577
453
|
}
|
|
578
454
|
if (rootBundle.blockNumber < startBlock) {
|
|
579
455
|
return false;
|
|
580
456
|
}
|
|
581
|
-
return
|
|
457
|
+
return this.isRootBundleValid(rootBundle, latestMainnetBlock);
|
|
582
458
|
});
|
|
583
|
-
}
|
|
459
|
+
}
|
|
584
460
|
// If n is negative, then return the Nth latest executed bundle, otherwise return the Nth earliest
|
|
585
461
|
// executed bundle. Latest means most recent, earliest means oldest. N cannot be 0.
|
|
586
462
|
// `startBlock` can be used to set the starting point from which we look forwards or backwards, depending
|
|
587
463
|
// on whether n is positive or negative.
|
|
588
|
-
|
|
464
|
+
getNthFullyExecutedRootBundle(n, startBlock) {
|
|
589
465
|
if (n === 0) {
|
|
590
466
|
throw new Error("n cannot be 0");
|
|
591
467
|
}
|
|
592
468
|
if (!this.latestHeightSearched) {
|
|
593
469
|
throw new Error("HubPoolClient::getNthFullyExecutedRootBundle client not updated");
|
|
594
470
|
}
|
|
595
|
-
|
|
471
|
+
let bundleToReturn;
|
|
596
472
|
// If n is negative, then return the Nth latest executed bundle, otherwise return the Nth earliest
|
|
597
473
|
// executed bundle.
|
|
598
474
|
if (n < 0) {
|
|
599
|
-
|
|
600
|
-
for (
|
|
475
|
+
let nextLatestMainnetBlock = startBlock ?? this.latestHeightSearched;
|
|
476
|
+
for (let i = 0; i < Math.abs(n); i++) {
|
|
601
477
|
bundleToReturn = this.getLatestFullyExecutedRootBundle(nextLatestMainnetBlock);
|
|
602
|
-
|
|
478
|
+
const bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
|
|
603
479
|
// Subtract 1 so that next `getLatestFullyExecutedRootBundle` call filters out the root bundle we just found
|
|
604
480
|
// because its block number is > nextLatestMainnetBlock.
|
|
605
481
|
nextLatestMainnetBlock = Math.max(0, bundleBlockNumber - 1);
|
|
606
482
|
}
|
|
607
483
|
}
|
|
608
484
|
else {
|
|
609
|
-
|
|
610
|
-
for (
|
|
485
|
+
let nextStartBlock = startBlock ?? 0;
|
|
486
|
+
for (let i = 0; i < n; i++) {
|
|
611
487
|
bundleToReturn = this.getEarliestFullyExecutedRootBundle(this.latestHeightSearched, nextStartBlock);
|
|
612
|
-
|
|
488
|
+
const bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
|
|
613
489
|
// Add 1 so that next `getEarliestFullyExecutedRootBundle` call filters out the root bundle we just found
|
|
614
490
|
// because its block number is < nextStartBlock.
|
|
615
491
|
nextStartBlock = Math.min(bundleBlockNumber + 1, this.latestHeightSearched);
|
|
616
492
|
}
|
|
617
493
|
}
|
|
618
494
|
return bundleToReturn;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
495
|
+
}
|
|
496
|
+
getLatestBundleEndBlockForChain(chainIdList, latestMainnetBlock, chainId) {
|
|
497
|
+
const latestFullyExecutedPoolRebalanceRoot = this.getLatestFullyExecutedRootBundle(latestMainnetBlock);
|
|
622
498
|
// If no event, then we can return a conservative default starting block like 0,
|
|
623
499
|
// or we could throw an Error.
|
|
624
500
|
if (!latestFullyExecutedPoolRebalanceRoot) {
|
|
@@ -628,341 +504,308 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
628
504
|
// bundleEvaluationBlockNumbers array using CHAIN_ID_LIST. For each chainId, their starting block number is that
|
|
629
505
|
// chain's bundleEvaluationBlockNumber + 1 in this past proposal event.
|
|
630
506
|
return this.getBundleEndBlockForChain(latestFullyExecutedPoolRebalanceRoot, chainId, chainIdList);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
|
|
507
|
+
}
|
|
508
|
+
getNextBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId) {
|
|
509
|
+
const endBlock = this.getLatestBundleEndBlockForChain(chainIdList, latestMainnetBlock, chainId);
|
|
634
510
|
// This assumes that chain ID's are only added to the chain ID list over time, and that chains are never
|
|
635
511
|
// deleted.
|
|
636
512
|
return endBlock > 0 ? endBlock + 1 : 0;
|
|
637
|
-
}
|
|
513
|
+
}
|
|
638
514
|
// @dev Returns the start block of the next bundle assuming that if there is a currently outstanding root bundle proposal, it will pass liveness.
|
|
639
|
-
|
|
515
|
+
getOptimisticBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId) {
|
|
640
516
|
// If there is no pending root bundle, then return block ranges based on the latest fully executed root bundle.
|
|
641
517
|
if (!this.hasPendingProposal()) {
|
|
642
518
|
return this.getNextBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId);
|
|
643
519
|
}
|
|
644
520
|
// We cannot normally index `this.proposedRootBundles` since a bundle there may have been previously disputed, so only index `this.proposedRootBundles`
|
|
645
521
|
// if we have a pending proposal, since this must mean that the pending root bundle is the most recent proposed root bundle.
|
|
646
|
-
|
|
522
|
+
const latestProposedBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
|
|
647
523
|
// If there is no previous root bundle, then return 0.
|
|
648
524
|
if (!isDefined(latestProposedBundle)) {
|
|
649
525
|
return 0;
|
|
650
526
|
}
|
|
651
527
|
// Otherwise, get the bundle end block for the optimistic bundle.
|
|
652
|
-
|
|
528
|
+
const optimisticEndBlock = this.getBundleEndBlockForChain(latestProposedBundle, chainId, chainIdList);
|
|
653
529
|
// As above, this assumes that chain ID's are only added to the chain ID list over time, and that chains are never
|
|
654
530
|
// deleted.
|
|
655
531
|
return optimisticEndBlock > 0 ? optimisticEndBlock + 1 : 0;
|
|
656
|
-
}
|
|
657
|
-
|
|
532
|
+
}
|
|
533
|
+
getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token) {
|
|
658
534
|
// Search ExecutedRootBundles in descending block order to find the most recent event before the target block.
|
|
659
|
-
return sortEventsDescending(this.executedRootBundles).find(
|
|
535
|
+
return sortEventsDescending(this.executedRootBundles).find((executedLeaf) => {
|
|
660
536
|
return (executedLeaf.blockNumber <= block &&
|
|
661
537
|
executedLeaf.chainId === chain &&
|
|
662
|
-
executedLeaf.l1Tokens.some(
|
|
538
|
+
executedLeaf.l1Tokens.some((token) => token.eq(l1Token)));
|
|
663
539
|
});
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
540
|
+
}
|
|
541
|
+
getRunningBalanceBeforeBlockForChain(block, chain, l1Token) {
|
|
542
|
+
const executedRootBundle = this.getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token);
|
|
667
543
|
return this.getRunningBalanceForToken(l1Token, executedRootBundle);
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
|
|
544
|
+
}
|
|
545
|
+
getRunningBalanceForToken(l1Token, executedRootBundle) {
|
|
546
|
+
let runningBalance = toBN(0);
|
|
671
547
|
if (executedRootBundle) {
|
|
672
|
-
|
|
548
|
+
const indexOfL1Token = executedRootBundle.l1Tokens.findIndex((tokenInBundle) => tokenInBundle.eq(l1Token));
|
|
673
549
|
if (indexOfL1Token !== -1) {
|
|
674
550
|
runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
|
|
675
551
|
}
|
|
676
552
|
}
|
|
677
|
-
return { runningBalance
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
return
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
553
|
+
return { runningBalance };
|
|
554
|
+
}
|
|
555
|
+
async _update(eventNames) {
|
|
556
|
+
const hubPoolEvents = this.hubPoolEventFilters();
|
|
557
|
+
const searchConfig = await this.updateSearchConfig(this.hubPool.provider);
|
|
558
|
+
if (isUpdateFailureReason(searchConfig)) {
|
|
559
|
+
return { success: false, reason: searchConfig };
|
|
560
|
+
}
|
|
561
|
+
const supportedEvents = Object.keys(hubPoolEvents);
|
|
562
|
+
if (eventNames.some((eventName) => !supportedEvents.includes(eventName))) {
|
|
563
|
+
return { success: false, reason: UpdateFailureReason.BadRequest };
|
|
564
|
+
}
|
|
565
|
+
const eventSearchConfigs = eventNames.map((eventName) => {
|
|
566
|
+
const _searchConfig = { ...searchConfig }; // shallow copy
|
|
567
|
+
// By default, an event's query range is controlled by the `searchConfig` passed in during
|
|
568
|
+
// instantiation. However, certain events generally must be queried back to HubPool genesis.
|
|
569
|
+
const overrideEvents = ["CrossChainContractsSet", "L1TokenEnabledForLiquidityProvision", "SetPoolRebalanceRoute"];
|
|
570
|
+
if (overrideEvents.includes(eventName) && !this.isUpdated) {
|
|
571
|
+
_searchConfig.from = this.deploymentBlock;
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
eventName,
|
|
575
|
+
filter: hubPoolEvents[eventName],
|
|
576
|
+
searchConfig: _searchConfig,
|
|
577
|
+
};
|
|
578
|
+
});
|
|
579
|
+
this.logger.debug({
|
|
580
|
+
at: "HubPoolClient",
|
|
581
|
+
message: "Updating HubPool client",
|
|
582
|
+
searchConfig: eventSearchConfigs.map(({ eventName, searchConfig }) => ({ eventName, searchConfig })),
|
|
583
|
+
});
|
|
584
|
+
const timerStart = Date.now();
|
|
585
|
+
const { hubPool } = this;
|
|
586
|
+
const multicallFunctions = ["getCurrentTime", "rootBundleProposal"];
|
|
587
|
+
const [multicallOutput, ...events] = await Promise.all([
|
|
588
|
+
hubPool.callStatic.multicall(multicallFunctions.map((f) => hubPool.interface.encodeFunctionData(f)), { blockTag: searchConfig.to }),
|
|
589
|
+
...eventSearchConfigs.map((config) => paginatedEventQuery(hubPool, config.filter, config.searchConfig)),
|
|
590
|
+
]);
|
|
591
|
+
const [currentTime, pendingRootBundleProposal] = multicallFunctions.map((fn, idx) => {
|
|
592
|
+
const output = hubPool.interface.decodeFunctionResult(fn, multicallOutput[idx]);
|
|
593
|
+
return output.length > 1 ? output : output[0];
|
|
594
|
+
});
|
|
595
|
+
this.logger.debug({
|
|
596
|
+
at: "HubPoolClient#_update",
|
|
597
|
+
message: `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`,
|
|
598
|
+
});
|
|
599
|
+
const _events = Object.fromEntries(eventNames.map((eventName, idx) => [eventName, events[idx]]));
|
|
600
|
+
return {
|
|
601
|
+
success: true,
|
|
602
|
+
currentTime,
|
|
603
|
+
pendingRootBundleProposal: {
|
|
604
|
+
...pendingRootBundleProposal,
|
|
605
|
+
proposer: EvmAddress.from(pendingRootBundleProposal.proposer),
|
|
606
|
+
},
|
|
607
|
+
searchEndBlock: searchConfig.to,
|
|
608
|
+
events: _events,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
async update(eventsToQuery = Object.keys(this.hubPoolEventFilters())) {
|
|
612
|
+
if (!this.configStoreClient.isUpdated) {
|
|
613
|
+
throw new Error("ConfigStoreClient not updated");
|
|
614
|
+
}
|
|
615
|
+
const update = await this._update(eventsToQuery);
|
|
616
|
+
if (!update.success) {
|
|
617
|
+
if (update.reason !== UpdateFailureReason.AlreadyUpdated) {
|
|
618
|
+
throw new Error(`Unable to update HubPoolClient: ${update.reason}`);
|
|
619
|
+
}
|
|
620
|
+
// No need to touch `this.isUpdated` because it should already be set from a previous update.
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const { events, currentTime, pendingRootBundleProposal, searchEndBlock } = update;
|
|
624
|
+
if (eventsToQuery.includes("CrossChainContractsSet")) {
|
|
625
|
+
for (const event of events["CrossChainContractsSet"]) {
|
|
626
|
+
const args = spreadEventWithBlockNumber(event);
|
|
627
|
+
const dataToAdd = {
|
|
628
|
+
spokePool: EvmAddress.from(args.spokePool),
|
|
629
|
+
blockNumber: args.blockNumber,
|
|
630
|
+
txnRef: args.txnRef,
|
|
631
|
+
logIndex: args.logIndex,
|
|
632
|
+
txnIndex: args.txnIndex,
|
|
633
|
+
l2ChainId: args.l2ChainId,
|
|
634
|
+
};
|
|
635
|
+
// If the chain is SVM then the resulting SpokePool address will be inferred based on the lower 20
|
|
636
|
+
// bytes of the address. Matching addresses will be promoted to a full 32-byte SvmAddress type.
|
|
637
|
+
if (chainIsSvm(args.l2ChainId)) {
|
|
638
|
+
const solanaSpokePool = getDeployedAddress("SvmSpoke", args.l2ChainId);
|
|
639
|
+
if (!solanaSpokePool) {
|
|
640
|
+
throw new Error(`SVM spoke pool not found for chain ${args.l2ChainId}`);
|
|
641
|
+
}
|
|
642
|
+
const svmSpoke = SvmAddress.from(solanaSpokePool);
|
|
643
|
+
const truncatedAddress = svmSpoke.truncateToBytes20();
|
|
644
|
+
// Verify the event address matches our expected truncated address
|
|
645
|
+
if (args.spokePool.toLowerCase() !== truncatedAddress.toLowerCase()) {
|
|
646
|
+
throw new Error(`SVM spoke pool address mismatch for chain ${args.l2ChainId}. ` +
|
|
647
|
+
`Expected ${truncatedAddress}, got ${args.spokePool}`);
|
|
648
|
+
}
|
|
649
|
+
dataToAdd.spokePool = svmSpoke;
|
|
650
|
+
}
|
|
651
|
+
assign(this.crossChainContracts, [args.l2ChainId], [dataToAdd]);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (eventsToQuery.includes("SetPoolRebalanceRoute")) {
|
|
655
|
+
for (const event of events["SetPoolRebalanceRoute"]) {
|
|
656
|
+
const args = spreadEventWithBlockNumber(event);
|
|
657
|
+
// If the destination chain is SVM, then we need to convert the destination token to the Solana address.
|
|
658
|
+
// This is because the HubPool contract only holds a truncated address for the USDC token and currently
|
|
659
|
+
// only supports USDC as a destination token for Solana.
|
|
660
|
+
let destinationToken = EvmAddress.from(args.destinationToken);
|
|
661
|
+
if (chainIsSvm(args.destinationChainId)) {
|
|
662
|
+
const usdcTokenSol = TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
|
|
663
|
+
const svmUsdc = SvmAddress.from(usdcTokenSol);
|
|
664
|
+
if (destinationToken.truncateToBytes20() !== svmUsdc.truncateToBytes20()) {
|
|
665
|
+
throw new Error(`SVM USDC address mismatch for chain ${args.destinationChainId}. ` +
|
|
666
|
+
`Expected ${svmUsdc.truncateToBytes20()}, got ${destinationToken}`);
|
|
667
|
+
}
|
|
668
|
+
destinationToken = svmUsdc;
|
|
669
|
+
}
|
|
670
|
+
const newRoute = {
|
|
671
|
+
l1Token: EvmAddress.from(args.l1Token),
|
|
672
|
+
l2Token: destinationToken,
|
|
673
|
+
blockNumber: args.blockNumber,
|
|
674
|
+
txnIndex: args.txnIndex,
|
|
675
|
+
logIndex: args.logIndex,
|
|
676
|
+
txnRef: args.txnRef,
|
|
677
|
+
};
|
|
678
|
+
if (this.l1TokensToDestinationTokensWithBlock[args.l1Token]?.[args.destinationChainId]) {
|
|
679
|
+
// Events are most likely coming in descending orders already but just in case we sort them again.
|
|
680
|
+
this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId] = sortEventsDescending([
|
|
681
|
+
...this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId],
|
|
682
|
+
newRoute,
|
|
683
|
+
]);
|
|
743
684
|
}
|
|
685
|
+
else {
|
|
686
|
+
assign(this.l1TokensToDestinationTokensWithBlock, [args.l1Token, args.destinationChainId], [newRoute]);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
// For each enabled Lp token fetch the token symbol and decimals from the token contract. Note this logic will
|
|
691
|
+
// only run iff a new token has been enabled. Will only append iff the info is not there already.
|
|
692
|
+
// Filter out any duplicate addresses. This might happen due to enabling, disabling and re-enabling a token.
|
|
693
|
+
if (eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) {
|
|
694
|
+
const uniqueL1Tokens = dedupArray(events["L1TokenEnabledForLiquidityProvision"].map((event) => String(event.args["l1Token"])));
|
|
695
|
+
const [tokenInfo, lpTokenInfo] = await Promise.all([
|
|
696
|
+
Promise.all(uniqueL1Tokens.map(async (l1Token) => {
|
|
697
|
+
const tokenInfo = await fetchTokenInfo(l1Token, this.hubPool.provider);
|
|
698
|
+
return {
|
|
699
|
+
...tokenInfo,
|
|
700
|
+
address: EvmAddress.from(l1Token),
|
|
701
|
+
};
|
|
702
|
+
})),
|
|
703
|
+
Promise.all(uniqueL1Tokens.map(async (l1Token) => await this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock }))),
|
|
704
|
+
]);
|
|
705
|
+
for (const info of tokenInfo) {
|
|
706
|
+
if (!this.l1Tokens.find((token) => token.address.eq(info.address))) {
|
|
707
|
+
if (info.decimals > 0 && info.decimals <= 18) {
|
|
708
|
+
this.l1Tokens.push(info);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
throw new Error(`Unsupported HubPool token: ${JSON.stringify(info)}`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
uniqueL1Tokens.forEach((token, i) => {
|
|
716
|
+
this.lpTokens[token] = {
|
|
717
|
+
lastLpFeeUpdate: lpTokenInfo[i].lastLpFeeUpdate,
|
|
718
|
+
liquidReserves: lpTokenInfo[i].liquidReserves,
|
|
719
|
+
};
|
|
744
720
|
});
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
if (chainIsSvm(args.destinationChainId)) {
|
|
808
|
-
usdcTokenSol = TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
|
|
809
|
-
svmUsdc = SvmAddress.from(usdcTokenSol);
|
|
810
|
-
if (destinationToken.truncateToBytes20() !== svmUsdc.truncateToBytes20()) {
|
|
811
|
-
throw new Error("SVM USDC address mismatch for chain ".concat(args.destinationChainId, ". ") +
|
|
812
|
-
"Expected ".concat(svmUsdc.truncateToBytes20(), ", got ").concat(destinationToken));
|
|
813
|
-
}
|
|
814
|
-
destinationToken = svmUsdc;
|
|
815
|
-
}
|
|
816
|
-
newRoute = {
|
|
817
|
-
l1Token: EvmAddress.from(args.l1Token),
|
|
818
|
-
l2Token: destinationToken,
|
|
819
|
-
blockNumber: args.blockNumber,
|
|
820
|
-
txnIndex: args.txnIndex,
|
|
821
|
-
logIndex: args.logIndex,
|
|
822
|
-
txnRef: args.txnRef,
|
|
823
|
-
};
|
|
824
|
-
if ((_l = this.l1TokensToDestinationTokensWithBlock[args.l1Token]) === null || _l === void 0 ? void 0 : _l[args.destinationChainId]) {
|
|
825
|
-
// Events are most likely coming in descending orders already but just in case we sort them again.
|
|
826
|
-
this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId] = sortEventsDescending(__spreadArray(__spreadArray([], this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId], true), [
|
|
827
|
-
newRoute,
|
|
828
|
-
], false));
|
|
829
|
-
}
|
|
830
|
-
else {
|
|
831
|
-
assign(this.l1TokensToDestinationTokensWithBlock, [args.l1Token, args.destinationChainId], [newRoute]);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
if (!eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) return [3 /*break*/, 3];
|
|
836
|
-
uniqueL1Tokens = dedupArray(events["L1TokenEnabledForLiquidityProvision"].map(function (event) { return String(event.args["l1Token"]); }));
|
|
837
|
-
return [4 /*yield*/, Promise.all([
|
|
838
|
-
Promise.all(uniqueL1Tokens.map(function (l1Token) { return __awaiter(_this, void 0, void 0, function () {
|
|
839
|
-
var tokenInfo;
|
|
840
|
-
return __generator(this, function (_a) {
|
|
841
|
-
switch (_a.label) {
|
|
842
|
-
case 0: return [4 /*yield*/, fetchTokenInfo(l1Token, this.hubPool.provider)];
|
|
843
|
-
case 1:
|
|
844
|
-
tokenInfo = _a.sent();
|
|
845
|
-
return [2 /*return*/, __assign(__assign({}, tokenInfo), { address: EvmAddress.from(l1Token) })];
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
}); })),
|
|
849
|
-
Promise.all(uniqueL1Tokens.map(function (l1Token) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
850
|
-
switch (_a.label) {
|
|
851
|
-
case 0: return [4 /*yield*/, this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock })];
|
|
852
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
853
|
-
}
|
|
854
|
-
}); }); })),
|
|
855
|
-
])];
|
|
856
|
-
case 2:
|
|
857
|
-
_d = _m.sent(), tokenInfo = _d[0], lpTokenInfo_1 = _d[1];
|
|
858
|
-
_loop_1 = function (info) {
|
|
859
|
-
if (!this_1.l1Tokens.find(function (token) { return token.address.eq(info.address); })) {
|
|
860
|
-
if (info.decimals > 0 && info.decimals <= 18) {
|
|
861
|
-
this_1.l1Tokens.push(info);
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
throw new Error("Unsupported HubPool token: ".concat(JSON.stringify(info)));
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
this_1 = this;
|
|
869
|
-
for (_e = 0, tokenInfo_1 = tokenInfo; _e < tokenInfo_1.length; _e++) {
|
|
870
|
-
info = tokenInfo_1[_e];
|
|
871
|
-
_loop_1(info);
|
|
872
|
-
}
|
|
873
|
-
uniqueL1Tokens.forEach(function (token, i) {
|
|
874
|
-
_this.lpTokens[token] = {
|
|
875
|
-
lastLpFeeUpdate: lpTokenInfo_1[i].lastLpFeeUpdate,
|
|
876
|
-
liquidReserves: lpTokenInfo_1[i].liquidReserves,
|
|
877
|
-
};
|
|
878
|
-
});
|
|
879
|
-
_m.label = 3;
|
|
880
|
-
case 3:
|
|
881
|
-
if (eventsToQuery.includes("ProposeRootBundle")) {
|
|
882
|
-
(_h = this.proposedRootBundles).push.apply(_h, events["ProposeRootBundle"]
|
|
883
|
-
.filter(function (event) { return !_this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber); })
|
|
884
|
-
.map(function (_event) {
|
|
885
|
-
var args = spreadEventWithBlockNumber(_event);
|
|
886
|
-
return __assign(__assign({}, args), { proposer: EvmAddress.from(args.proposer) });
|
|
887
|
-
}));
|
|
888
|
-
}
|
|
889
|
-
if (eventsToQuery.includes("RootBundleCanceled")) {
|
|
890
|
-
(_j = this.canceledRootBundles).push.apply(_j, events["RootBundleCanceled"].map(function (event) { return spreadEventWithBlockNumber(event); }));
|
|
891
|
-
}
|
|
892
|
-
if (eventsToQuery.includes("RootBundleDisputed")) {
|
|
893
|
-
(_k = this.disputedRootBundles).push.apply(_k, events["RootBundleDisputed"].map(function (event) { return spreadEventWithBlockNumber(event); }));
|
|
894
|
-
}
|
|
895
|
-
if (eventsToQuery.includes("RootBundleExecuted")) {
|
|
896
|
-
for (_f = 0, _g = events["RootBundleExecuted"]; _f < _g.length; _f++) {
|
|
897
|
-
event_3 = _g[_f];
|
|
898
|
-
if (this.configOverride.ignoredHubExecutedBundles.includes(event_3.blockNumber)) {
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
executedRootBundle = spreadEventWithBlockNumber(event_3);
|
|
902
|
-
l1Tokens = executedRootBundle.l1Tokens, runningBalances = executedRootBundle.runningBalances;
|
|
903
|
-
nTokens = l1Tokens.length;
|
|
904
|
-
// Safeguard
|
|
905
|
-
if (![nTokens, nTokens * 2].includes(runningBalances.length)) {
|
|
906
|
-
throw new Error("Invalid runningBalances length: ".concat(runningBalances.length, ".") +
|
|
907
|
-
" Expected ".concat(nTokens, " or ").concat(nTokens * 2, " for chain ").concat(this.chainId, " transaction ").concat(event_3.transactionHash));
|
|
908
|
-
}
|
|
909
|
-
executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
|
|
910
|
-
this.executedRootBundles.push(__assign(__assign({}, executedRootBundle), { l1Tokens: l1Tokens.map(function (l1Token) { return EvmAddress.from(l1Token); }) }));
|
|
911
|
-
}
|
|
721
|
+
}
|
|
722
|
+
if (eventsToQuery.includes("ProposeRootBundle")) {
|
|
723
|
+
this.proposedRootBundles.push(...events["ProposeRootBundle"]
|
|
724
|
+
.filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
|
|
725
|
+
.map((_event) => {
|
|
726
|
+
const args = spreadEventWithBlockNumber(_event);
|
|
727
|
+
return {
|
|
728
|
+
...args,
|
|
729
|
+
proposer: EvmAddress.from(args.proposer),
|
|
730
|
+
};
|
|
731
|
+
}));
|
|
732
|
+
}
|
|
733
|
+
if (eventsToQuery.includes("RootBundleCanceled")) {
|
|
734
|
+
this.canceledRootBundles.push(...events["RootBundleCanceled"].map((event) => spreadEventWithBlockNumber(event)));
|
|
735
|
+
}
|
|
736
|
+
if (eventsToQuery.includes("RootBundleDisputed")) {
|
|
737
|
+
this.disputedRootBundles.push(...events["RootBundleDisputed"].map((event) => spreadEventWithBlockNumber(event)));
|
|
738
|
+
}
|
|
739
|
+
if (eventsToQuery.includes("RootBundleExecuted")) {
|
|
740
|
+
for (const event of events["RootBundleExecuted"]) {
|
|
741
|
+
if (this.configOverride.ignoredHubExecutedBundles.includes(event.blockNumber)) {
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
// Set running balances and incentive balances for this bundle.
|
|
745
|
+
const executedRootBundle = spreadEventWithBlockNumber(event);
|
|
746
|
+
const { l1Tokens, runningBalances } = executedRootBundle;
|
|
747
|
+
const nTokens = l1Tokens.length;
|
|
748
|
+
// Safeguard
|
|
749
|
+
if (![nTokens, nTokens * 2].includes(runningBalances.length)) {
|
|
750
|
+
throw new Error(`Invalid runningBalances length: ${runningBalances.length}.` +
|
|
751
|
+
` Expected ${nTokens} or ${nTokens * 2} for chain ${this.chainId} transaction ${event.transactionHash}`);
|
|
752
|
+
}
|
|
753
|
+
executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
|
|
754
|
+
this.executedRootBundles.push({
|
|
755
|
+
...executedRootBundle,
|
|
756
|
+
l1Tokens: l1Tokens.map((l1Token) => EvmAddress.from(l1Token)),
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
// If the contract's current rootBundleProposal() value has an unclaimedPoolRebalanceLeafCount > 0, then
|
|
761
|
+
// it means that either the root bundle proposal is in the challenge period and can be disputed, or it has
|
|
762
|
+
// passed the challenge period and pool rebalance leaves can be executed. Once all leaves are executed, the
|
|
763
|
+
// unclaimed count will drop to 0 and at that point there is nothing more that we can do with this root bundle
|
|
764
|
+
// besides proposing another one.
|
|
765
|
+
if (eventsToQuery.includes("ProposeRootBundle")) {
|
|
766
|
+
if (pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount > 0) {
|
|
767
|
+
const mostRecentProposedRootBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
|
|
768
|
+
this.pendingRootBundle = {
|
|
769
|
+
poolRebalanceRoot: pendingRootBundleProposal.poolRebalanceRoot,
|
|
770
|
+
relayerRefundRoot: pendingRootBundleProposal.relayerRefundRoot,
|
|
771
|
+
slowRelayRoot: pendingRootBundleProposal.slowRelayRoot,
|
|
772
|
+
proposer: pendingRootBundleProposal.proposer,
|
|
773
|
+
unclaimedPoolRebalanceLeafCount: pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount,
|
|
774
|
+
challengePeriodEndTimestamp: pendingRootBundleProposal.challengePeriodEndTimestamp,
|
|
775
|
+
bundleEvaluationBlockNumbers: mostRecentProposedRootBundle.bundleEvaluationBlockNumbers.map((block) => {
|
|
776
|
+
// Ideally, the HubPool.sol contract should limit the size of the elements within the
|
|
777
|
+
// bundleEvaluationBlockNumbers array. But because it doesn't, we wrap the cast of BN --> Number
|
|
778
|
+
// in a try/catch statement and return some value that would always be disputable.
|
|
779
|
+
// This catches the denial of service attack vector where a malicious proposer proposes with bundle block
|
|
780
|
+
// evaluation block numbers larger than what BigNumber::toNumber() can handle.
|
|
781
|
+
try {
|
|
782
|
+
return block.toNumber();
|
|
912
783
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
// passed the challenge period and pool rebalance leaves can be executed. Once all leaves are executed, the
|
|
916
|
-
// unclaimed count will drop to 0 and at that point there is nothing more that we can do with this root bundle
|
|
917
|
-
// besides proposing another one.
|
|
918
|
-
if (eventsToQuery.includes("ProposeRootBundle")) {
|
|
919
|
-
if (pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount > 0) {
|
|
920
|
-
mostRecentProposedRootBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
|
|
921
|
-
this.pendingRootBundle = {
|
|
922
|
-
poolRebalanceRoot: pendingRootBundleProposal.poolRebalanceRoot,
|
|
923
|
-
relayerRefundRoot: pendingRootBundleProposal.relayerRefundRoot,
|
|
924
|
-
slowRelayRoot: pendingRootBundleProposal.slowRelayRoot,
|
|
925
|
-
proposer: pendingRootBundleProposal.proposer,
|
|
926
|
-
unclaimedPoolRebalanceLeafCount: pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount,
|
|
927
|
-
challengePeriodEndTimestamp: pendingRootBundleProposal.challengePeriodEndTimestamp,
|
|
928
|
-
bundleEvaluationBlockNumbers: mostRecentProposedRootBundle.bundleEvaluationBlockNumbers.map(function (block) {
|
|
929
|
-
// Ideally, the HubPool.sol contract should limit the size of the elements within the
|
|
930
|
-
// bundleEvaluationBlockNumbers array. But because it doesn't, we wrap the cast of BN --> Number
|
|
931
|
-
// in a try/catch statement and return some value that would always be disputable.
|
|
932
|
-
// This catches the denial of service attack vector where a malicious proposer proposes with bundle block
|
|
933
|
-
// evaluation block numbers larger than what BigNumber::toNumber() can handle.
|
|
934
|
-
try {
|
|
935
|
-
return block.toNumber();
|
|
936
|
-
}
|
|
937
|
-
catch (_a) {
|
|
938
|
-
return 0;
|
|
939
|
-
}
|
|
940
|
-
}),
|
|
941
|
-
proposalBlockNumber: mostRecentProposedRootBundle.blockNumber,
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
this.pendingRootBundle = undefined;
|
|
946
|
-
}
|
|
784
|
+
catch {
|
|
785
|
+
return 0;
|
|
947
786
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
787
|
+
}),
|
|
788
|
+
proposalBlockNumber: mostRecentProposedRootBundle.blockNumber,
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
this.pendingRootBundle = undefined;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
this.currentTime = currentTime;
|
|
796
|
+
this.latestHeightSearched = searchEndBlock;
|
|
797
|
+
this.firstHeightToSearch = update.searchEndBlock + 1; // Next iteration should start off from where this one ended.
|
|
798
|
+
this.eventSearchConfig.to = undefined; // Caller can re-set on subsequent updates if necessary.
|
|
799
|
+
this.isUpdated = true;
|
|
800
|
+
this.logger.debug({ at: "HubPoolClient::update", message: "HubPool client updated!", searchEndBlock, currentTime });
|
|
801
|
+
}
|
|
959
802
|
// Returns end block for `chainId` in ProposedRootBundle.bundleBlockEvalNumbers. Looks up chainId
|
|
960
803
|
// in chainId list, gets the index where its located, and returns the value of the index in
|
|
961
804
|
// bundleBlockEvalNumbers. Returns 0 if `chainId` can't be found in `chainIdList` and if index doesn't
|
|
962
805
|
// exist in bundleBlockEvalNumbers.
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
806
|
+
getBundleEndBlockForChain(proposeRootBundleEvent, chainId, chainIdList) {
|
|
807
|
+
const bundleEvaluationBlockNumbers = proposeRootBundleEvent.bundleEvaluationBlockNumbers;
|
|
808
|
+
const chainIdIndex = chainIdList.indexOf(chainId);
|
|
966
809
|
if (chainIdIndex === -1) {
|
|
967
810
|
return 0;
|
|
968
811
|
}
|
|
@@ -973,8 +816,6 @@ var HubPoolClient = /** @class */ (function (_super) {
|
|
|
973
816
|
return 0;
|
|
974
817
|
}
|
|
975
818
|
return bundleEvaluationBlockNumbers[chainIdIndex].toNumber();
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
}(BaseAbstractClient));
|
|
979
|
-
export { HubPoolClient };
|
|
819
|
+
}
|
|
820
|
+
}
|
|
980
821
|
//# sourceMappingURL=HubPoolClient.js.map
|