@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, __generator, __spreadArray } from "tslib";
|
|
2
1
|
import assert from "assert";
|
|
3
2
|
import * as uma from "./uma";
|
|
4
3
|
import { bnZero, toBNWei, fixedPointAdjustment, calcPeriodicCompoundInterest, calcApr, BigNumber, fromWei, } from "../utils";
|
|
@@ -9,247 +8,203 @@ import has from "lodash/has";
|
|
|
9
8
|
import { calculateInstantaneousRate } from "../lpFeeCalculator";
|
|
10
9
|
import { hubPool, acrossConfigStore } from "../contracts";
|
|
11
10
|
import { AcceleratingDistributor__factory, MerkleDistributor__factory, } from "../typechain";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const { erc20 } = uma.clients;
|
|
12
|
+
const { loop } = uma.utils;
|
|
13
|
+
const { TransactionManager } = uma.across;
|
|
14
|
+
const { SECONDS_PER_YEAR, DEFAULT_BLOCK_DELTA } = uma.across.constants;
|
|
15
|
+
const { AddressZero } = ethers.constants;
|
|
16
|
+
class PoolState {
|
|
17
|
+
contract;
|
|
18
|
+
address;
|
|
19
|
+
constructor(contract, address) {
|
|
19
20
|
this.contract = contract;
|
|
20
21
|
this.address = address;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (startBlock === void 0) { startBlock = 0; }
|
|
52
|
-
var _this = this;
|
|
23
|
+
async read(l1Token, latestBlock, previousBlock) {
|
|
24
|
+
// typechain does not have complete types for call options, so we have to cast blockTag to any
|
|
25
|
+
const exchangeRatePrevious = await this.exchangeRateAtBlock(l1Token, previousBlock || latestBlock - 1);
|
|
26
|
+
const exchangeRateCurrent = await this.contract.callStatic.exchangeRateCurrent(l1Token);
|
|
27
|
+
const pooledToken = await this.contract.pooledTokens(l1Token);
|
|
28
|
+
const liquidityUtilizationCurrent = await this.contract.callStatic.liquidityUtilizationCurrent(l1Token);
|
|
29
|
+
return {
|
|
30
|
+
address: this.address,
|
|
31
|
+
l1Token,
|
|
32
|
+
latestBlock,
|
|
33
|
+
previousBlock,
|
|
34
|
+
exchangeRatePrevious,
|
|
35
|
+
exchangeRateCurrent,
|
|
36
|
+
liquidityUtilizationCurrent,
|
|
37
|
+
...pooledToken,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exchangeRateAtBlock(l1Token, blockTag) {
|
|
41
|
+
return this.contract.callStatic.exchangeRateCurrent(l1Token, { blockTag });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class PoolEventState {
|
|
45
|
+
contract;
|
|
46
|
+
startBlock;
|
|
47
|
+
seen = new Set();
|
|
48
|
+
iface;
|
|
49
|
+
// maintain ordered unique list of events so we can calculate state
|
|
50
|
+
events = [];
|
|
51
|
+
constructor(contract, startBlock = 0) {
|
|
53
52
|
this.contract = contract;
|
|
54
53
|
this.startBlock = startBlock;
|
|
55
|
-
this.seen = new Set();
|
|
56
|
-
// maintain ordered unique list of events so we can calculate state
|
|
57
|
-
this.events = [];
|
|
58
|
-
this.makeId = function (params) {
|
|
59
|
-
return uma.oracle.utils.eventKey(params);
|
|
60
|
-
};
|
|
61
|
-
this.filterSeen = function (params) {
|
|
62
|
-
var seen = _this.hasEvent(params);
|
|
63
|
-
if (!seen)
|
|
64
|
-
_this.addEvent(params);
|
|
65
|
-
return !seen;
|
|
66
|
-
};
|
|
67
|
-
this.processEvent = function (event) {
|
|
68
|
-
if (!_this.filterSeen(event))
|
|
69
|
-
return;
|
|
70
|
-
_this.events = uma.oracle.utils.insertOrderedAscending(_this.events, event, _this.makeId);
|
|
71
|
-
};
|
|
72
|
-
this.processEvents = function (events) {
|
|
73
|
-
events.forEach(_this.processEvent);
|
|
74
|
-
};
|
|
75
|
-
this.makeEventFromLog = function (log) {
|
|
76
|
-
var description = _this.iface.parseLog(log);
|
|
77
|
-
return __assign(__assign(__assign({}, log), description), { event: description.name, eventSignature: description.signature });
|
|
78
|
-
};
|
|
79
54
|
this.iface = new ethers.utils.Interface(hubPool.Factory.abi);
|
|
80
55
|
}
|
|
81
|
-
|
|
82
|
-
return
|
|
56
|
+
makeId = (params) => {
|
|
57
|
+
return uma.oracle.utils.eventKey(params);
|
|
83
58
|
};
|
|
84
|
-
|
|
59
|
+
hasEvent(params) {
|
|
60
|
+
return this.seen.has(this.makeId(params));
|
|
61
|
+
}
|
|
62
|
+
addEvent(params) {
|
|
85
63
|
this.seen.add(this.makeId(params));
|
|
64
|
+
}
|
|
65
|
+
filterSeen = (params) => {
|
|
66
|
+
const seen = this.hasEvent(params);
|
|
67
|
+
if (!seen)
|
|
68
|
+
this.addEvent(params);
|
|
69
|
+
return !seen;
|
|
70
|
+
};
|
|
71
|
+
processEvent = (event) => {
|
|
72
|
+
if (!this.filterSeen(event))
|
|
73
|
+
return;
|
|
74
|
+
this.events = uma.oracle.utils.insertOrderedAscending(this.events, event, this.makeId);
|
|
75
|
+
};
|
|
76
|
+
processEvents = (events) => {
|
|
77
|
+
events.forEach(this.processEvent);
|
|
78
|
+
};
|
|
79
|
+
async read(endBlock, l1TokenAddress, userAddress) {
|
|
80
|
+
const events = await Promise.all([
|
|
81
|
+
...(await this.contract.queryFilter(this.contract.filters.LiquidityAdded(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)),
|
|
82
|
+
...(await this.contract.queryFilter(this.contract.filters.LiquidityRemoved(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)),
|
|
83
|
+
]);
|
|
84
|
+
this.processEvents(events);
|
|
85
|
+
return hubPool.getEventState(this.events);
|
|
86
|
+
}
|
|
87
|
+
makeEventFromLog = (log) => {
|
|
88
|
+
const description = this.iface.parseLog(log);
|
|
89
|
+
return {
|
|
90
|
+
...log,
|
|
91
|
+
...description,
|
|
92
|
+
event: description.name,
|
|
93
|
+
eventSignature: description.signature,
|
|
94
|
+
};
|
|
86
95
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return __generator(this, function (_e) {
|
|
91
|
-
switch (_e.label) {
|
|
92
|
-
case 0:
|
|
93
|
-
_b = (_a = Promise).all;
|
|
94
|
-
_c = [[]];
|
|
95
|
-
return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.LiquidityAdded(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)];
|
|
96
|
-
case 1:
|
|
97
|
-
_d = [__spreadArray.apply(void 0, _c.concat([(_e.sent()), true]))];
|
|
98
|
-
return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.LiquidityRemoved(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)];
|
|
99
|
-
case 2: return [4 /*yield*/, _b.apply(_a, [__spreadArray.apply(void 0, _d.concat([(_e.sent()), true]))])];
|
|
100
|
-
case 3:
|
|
101
|
-
events = _e.sent();
|
|
102
|
-
this.processEvents(events);
|
|
103
|
-
return [2 /*return*/, hubPool.getEventState(this.events)];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
PoolEventState.prototype.getL1TokenFromReceipt = function (receipt) {
|
|
109
|
-
var _this = this;
|
|
110
|
-
var events = receipt.logs
|
|
111
|
-
.filter(function (log) { return ethers.utils.getAddress(log.address) === ethers.utils.getAddress(_this.contract.address); })
|
|
96
|
+
getL1TokenFromReceipt(receipt) {
|
|
97
|
+
const events = receipt.logs
|
|
98
|
+
.filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
|
|
112
99
|
.map(this.makeEventFromLog);
|
|
113
100
|
// save these events
|
|
114
101
|
this.processEvents(events);
|
|
115
102
|
// only process token receipt events, because we just want the l1 token involved with this transfer
|
|
116
|
-
|
|
103
|
+
const eventState = hubPool.getEventState(events);
|
|
117
104
|
// event state is keyed by l1token address
|
|
118
|
-
|
|
105
|
+
const l1Tokens = Object.keys(eventState);
|
|
119
106
|
assert(l1Tokens.length, "Token not found from events");
|
|
120
107
|
assert(l1Tokens.length === 1, "Multiple tokens found from events");
|
|
121
108
|
return l1Tokens[0];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
.filter(function (log) { return ethers.utils.getAddress(log.address) === ethers.utils.getAddress(_this.contract.address); })
|
|
109
|
+
}
|
|
110
|
+
readTxReceipt(receipt) {
|
|
111
|
+
const events = receipt.logs
|
|
112
|
+
.filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
|
|
127
113
|
.map(this.makeEventFromLog);
|
|
128
114
|
this.processEvents(events);
|
|
129
115
|
return hubPool.getEventState(this.events);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
class UserState {
|
|
119
|
+
contract;
|
|
120
|
+
userAddress;
|
|
121
|
+
startBlock;
|
|
122
|
+
acceleratingDistributorContractAddress;
|
|
123
|
+
seen = new Set();
|
|
124
|
+
events = [];
|
|
125
|
+
constructor(contract, userAddress, startBlock = 0, acceleratingDistributorContractAddress = "") {
|
|
139
126
|
this.contract = contract;
|
|
140
127
|
this.userAddress = userAddress;
|
|
141
128
|
this.startBlock = startBlock;
|
|
142
129
|
this.acceleratingDistributorContractAddress = acceleratingDistributorContractAddress;
|
|
143
|
-
this.seen = new Set();
|
|
144
|
-
this.events = [];
|
|
145
|
-
this.filterSeen = function (params) {
|
|
146
|
-
var seen = _this.hasEvent(params);
|
|
147
|
-
if (!seen)
|
|
148
|
-
_this.addEvent(params);
|
|
149
|
-
return !seen;
|
|
150
|
-
};
|
|
151
130
|
}
|
|
152
|
-
|
|
131
|
+
makeId(params) {
|
|
153
132
|
return uma.oracle.utils.eventKey(params);
|
|
154
|
-
}
|
|
155
|
-
|
|
133
|
+
}
|
|
134
|
+
hasEvent(params) {
|
|
156
135
|
return this.seen.has(this.makeId(params));
|
|
157
|
-
}
|
|
158
|
-
|
|
136
|
+
}
|
|
137
|
+
addEvent(params) {
|
|
159
138
|
this.seen.add(this.makeId(params));
|
|
139
|
+
}
|
|
140
|
+
filterSeen = (params) => {
|
|
141
|
+
const seen = this.hasEvent(params);
|
|
142
|
+
if (!seen)
|
|
143
|
+
this.addEvent(params);
|
|
144
|
+
return !seen;
|
|
160
145
|
};
|
|
161
146
|
/**
|
|
162
147
|
* readEvents. Fetch and cache events for the user.
|
|
163
148
|
*
|
|
164
149
|
* @param {number} endBlock
|
|
165
150
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// ignore self transfer events
|
|
198
|
-
event.args.from !== event.args.to;
|
|
199
|
-
})
|
|
200
|
-
.flat();
|
|
201
|
-
this.events = this.events.concat(events).sort(function (a, b) {
|
|
202
|
-
if (a.blockNumber !== b.blockNumber)
|
|
203
|
-
return a.blockNumber - b.blockNumber;
|
|
204
|
-
if (a.transactionIndex !== b.transactionIndex)
|
|
205
|
-
return a.transactionIndex - b.transactionIndex;
|
|
206
|
-
if (a.logIndex !== b.logIndex)
|
|
207
|
-
return a.logIndex - b.logIndex;
|
|
208
|
-
throw new Error("Duplicate events at tx hash: " + a.transactionHash);
|
|
209
|
-
});
|
|
210
|
-
// ethers queries are inclusive [start,end] unless start === end, then exclusive (start,end). we increment to make sure we dont see same event twice
|
|
211
|
-
this.startBlock = endBlock + 1;
|
|
212
|
-
return [2 /*return*/, this.events];
|
|
213
|
-
}
|
|
214
|
-
});
|
|
151
|
+
async readEvents(endBlock) {
|
|
152
|
+
if (endBlock <= this.startBlock)
|
|
153
|
+
return [];
|
|
154
|
+
const { userAddress } = this;
|
|
155
|
+
const events = (await Promise.all([
|
|
156
|
+
...(await this.contract.queryFilter(this.contract.filters.Transfer(userAddress, undefined), this.startBlock, endBlock)),
|
|
157
|
+
...(await this.contract.queryFilter(this.contract.filters.Transfer(undefined, userAddress), this.startBlock, endBlock)),
|
|
158
|
+
]))
|
|
159
|
+
// filter out events we have seen
|
|
160
|
+
.filter(this.filterSeen)
|
|
161
|
+
// filter out mint/burn transfers
|
|
162
|
+
.filter((event) =>
|
|
163
|
+
// ignore mint events
|
|
164
|
+
event.args.from !== AddressZero &&
|
|
165
|
+
// ignore burn events
|
|
166
|
+
event.args.to !== AddressZero &&
|
|
167
|
+
// ignore AD transfer events in
|
|
168
|
+
event.args.to !== this.acceleratingDistributorContractAddress &&
|
|
169
|
+
// ignore AD transfer events out
|
|
170
|
+
event.args.from !== this.acceleratingDistributorContractAddress &&
|
|
171
|
+
// ignore self transfer events
|
|
172
|
+
event.args.from !== event.args.to)
|
|
173
|
+
.flat();
|
|
174
|
+
this.events = this.events.concat(events).sort((a, b) => {
|
|
175
|
+
if (a.blockNumber !== b.blockNumber)
|
|
176
|
+
return a.blockNumber - b.blockNumber;
|
|
177
|
+
if (a.transactionIndex !== b.transactionIndex)
|
|
178
|
+
return a.transactionIndex - b.transactionIndex;
|
|
179
|
+
if (a.logIndex !== b.logIndex)
|
|
180
|
+
return a.logIndex - b.logIndex;
|
|
181
|
+
throw new Error("Duplicate events at tx hash: " + a.transactionHash);
|
|
215
182
|
});
|
|
216
|
-
|
|
183
|
+
// ethers queries are inclusive [start,end] unless start === end, then exclusive (start,end). we increment to make sure we dont see same event twice
|
|
184
|
+
this.startBlock = endBlock + 1;
|
|
185
|
+
return this.events;
|
|
186
|
+
}
|
|
217
187
|
/**
|
|
218
188
|
* read. Reads the state for the user, building state from events as well as contract calls.
|
|
219
189
|
*
|
|
220
190
|
* @param {number} endBlock
|
|
221
191
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
balanceTransferred = ((_b = state === null || state === void 0 ? void 0 : state.balances) === null || _b === void 0 ? void 0 : _b[userAddress]) || "0";
|
|
236
|
-
_a = {
|
|
237
|
-
transferEvents: transferEvents,
|
|
238
|
-
balanceTransferred: balanceTransferred,
|
|
239
|
-
address: userAddress
|
|
240
|
-
};
|
|
241
|
-
return [4 /*yield*/, this.contract.balanceOf(userAddress)];
|
|
242
|
-
case 2: return [2 /*return*/, (_a.balanceOf = _c.sent(),
|
|
243
|
-
_a)];
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
return UserState;
|
|
249
|
-
}());
|
|
192
|
+
async read(endBlock) {
|
|
193
|
+
const { userAddress } = this;
|
|
194
|
+
const transferEvents = await this.readEvents(endBlock);
|
|
195
|
+
const state = uma.clients.erc20.getEventState(transferEvents);
|
|
196
|
+
const balanceTransferred = state?.balances?.[userAddress] || "0";
|
|
197
|
+
return {
|
|
198
|
+
transferEvents,
|
|
199
|
+
balanceTransferred,
|
|
200
|
+
address: userAddress,
|
|
201
|
+
balanceOf: await this.contract.balanceOf(userAddress),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
250
205
|
export function calculateRemoval(amountWei, percentWei) {
|
|
251
|
-
|
|
252
|
-
|
|
206
|
+
const receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
|
|
207
|
+
const remain = amountWei.sub(receive);
|
|
253
208
|
return {
|
|
254
209
|
receive: receive.toString(),
|
|
255
210
|
remain: remain.toString(),
|
|
@@ -257,22 +212,25 @@ export function calculateRemoval(amountWei, percentWei) {
|
|
|
257
212
|
}
|
|
258
213
|
// params here mimic the user object type
|
|
259
214
|
export function previewRemoval(values, percentFloat) {
|
|
260
|
-
|
|
215
|
+
const percentWei = toBNWei(percentFloat);
|
|
261
216
|
return {
|
|
262
|
-
position:
|
|
263
|
-
|
|
264
|
-
|
|
217
|
+
position: {
|
|
218
|
+
...calculateRemoval(BigNumber.from(values.totalDeposited), percentWei),
|
|
219
|
+
},
|
|
220
|
+
fees: {
|
|
221
|
+
...calculateRemoval(BigNumber.from(values.feesEarned), percentWei),
|
|
222
|
+
},
|
|
223
|
+
total: {
|
|
224
|
+
...calculateRemoval(BigNumber.from(values.positionValue), percentWei),
|
|
225
|
+
},
|
|
265
226
|
};
|
|
266
227
|
}
|
|
267
|
-
function joinUserState(poolState, tokenEventState, userState, transferValue, cumulativeStakeBalance, cumulativeStakeClaimBalance) {
|
|
268
|
-
|
|
269
|
-
if (cumulativeStakeBalance === void 0) { cumulativeStakeBalance = bnZero; }
|
|
270
|
-
if (cumulativeStakeClaimBalance === void 0) { cumulativeStakeClaimBalance = bnZero; }
|
|
271
|
-
var positionValue = BigNumber.from(poolState.exchangeRateCurrent)
|
|
228
|
+
function joinUserState(poolState, tokenEventState, userState, transferValue = bnZero, cumulativeStakeBalance = bnZero, cumulativeStakeClaimBalance = bnZero) {
|
|
229
|
+
const positionValue = BigNumber.from(poolState.exchangeRateCurrent)
|
|
272
230
|
.mul(userState.balanceOf.add(cumulativeStakeBalance))
|
|
273
231
|
.div(fixedPointAdjustment);
|
|
274
|
-
|
|
275
|
-
|
|
232
|
+
const totalDeposited = BigNumber.from(tokenEventState?.tokenBalances[userState.address] || "0").add(cumulativeStakeClaimBalance);
|
|
233
|
+
const feesEarned = positionValue.sub(totalDeposited.add(transferValue));
|
|
276
234
|
return {
|
|
277
235
|
address: userState.address,
|
|
278
236
|
poolAddress: poolState.address,
|
|
@@ -283,15 +241,15 @@ function joinUserState(poolState, tokenEventState, userState, transferValue, cum
|
|
|
283
241
|
};
|
|
284
242
|
}
|
|
285
243
|
function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
244
|
+
const totalPoolSize = poolState.liquidReserves.add(poolState.utilizedReserves);
|
|
245
|
+
const secondsElapsed = latestBlock.timestamp - previousBlock.timestamp;
|
|
246
|
+
const blocksElapsed = latestBlock.number - previousBlock.number;
|
|
247
|
+
const exchangeRatePrevious = poolState.exchangeRatePrevious.toString();
|
|
248
|
+
const exchangeRateCurrent = poolState.exchangeRateCurrent.toString();
|
|
249
|
+
const liquidityUtilizationCurrent = poolState.liquidityUtilizationCurrent.toString();
|
|
250
|
+
const estimatedApy = calcPeriodicCompoundInterest(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
|
|
251
|
+
const estimatedApr = calcApr(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
|
|
252
|
+
let projectedApr = "";
|
|
295
253
|
if (rateModel) {
|
|
296
254
|
projectedApr = fromWei(calculateInstantaneousRate(rateModel, liquidityUtilizationCurrent)
|
|
297
255
|
.mul(liquidityUtilizationCurrent)
|
|
@@ -305,45 +263,55 @@ function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
|
|
|
305
263
|
liquidReserves: poolState.liquidReserves.toString(),
|
|
306
264
|
exchangeRateCurrent: poolState.exchangeRateCurrent.toString(),
|
|
307
265
|
exchangeRatePrevious: poolState.exchangeRatePrevious.toString(),
|
|
308
|
-
estimatedApy
|
|
309
|
-
estimatedApr
|
|
310
|
-
blocksElapsed
|
|
311
|
-
secondsElapsed
|
|
312
|
-
projectedApr
|
|
266
|
+
estimatedApy,
|
|
267
|
+
estimatedApr,
|
|
268
|
+
blocksElapsed,
|
|
269
|
+
secondsElapsed,
|
|
270
|
+
projectedApr,
|
|
313
271
|
utilizedReserves: poolState.utilizedReserves.toString(),
|
|
314
|
-
liquidityUtilizationCurrent
|
|
272
|
+
liquidityUtilizationCurrent,
|
|
315
273
|
};
|
|
316
274
|
}
|
|
317
|
-
|
|
318
|
-
|
|
275
|
+
export class ReadPoolClient {
|
|
276
|
+
address;
|
|
277
|
+
provider;
|
|
278
|
+
poolState;
|
|
279
|
+
contract;
|
|
280
|
+
constructor(address, provider) {
|
|
319
281
|
this.address = address;
|
|
320
282
|
this.provider = provider;
|
|
321
283
|
this.contract = hubPool.connect(address, this.provider);
|
|
322
284
|
this.poolState = new PoolState(this.contract, this.address);
|
|
323
285
|
}
|
|
324
|
-
|
|
286
|
+
read(tokenAddress, latestBlock) {
|
|
325
287
|
return this.poolState.read(tokenAddress, latestBlock);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
}());
|
|
329
|
-
export { ReadPoolClient };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
330
290
|
export function validateWithdraw(pool, user, lpTokenAmount) {
|
|
331
|
-
|
|
291
|
+
const l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
|
|
332
292
|
assert(BigNumber.from(l1TokensToReturn).gt("0"), "Must withdraw amount greater than 0");
|
|
333
293
|
assert(BigNumber.from(lpTokenAmount).lte(user.lpTokens), "You cannot withdraw more than you have");
|
|
334
|
-
return { lpTokenAmount
|
|
294
|
+
return { lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
|
|
335
295
|
}
|
|
336
|
-
|
|
337
|
-
|
|
296
|
+
export class Client {
|
|
297
|
+
config;
|
|
298
|
+
deps;
|
|
299
|
+
emit;
|
|
300
|
+
transactionManagers = {};
|
|
301
|
+
hubPool;
|
|
302
|
+
acceleratingDistributor;
|
|
303
|
+
merkleDistributor;
|
|
304
|
+
state = { pools: {}, users: {}, transactions: {} };
|
|
305
|
+
poolEvents;
|
|
306
|
+
erc20s = {};
|
|
307
|
+
intervalStarted = false;
|
|
308
|
+
configStoreClient;
|
|
309
|
+
exchangeRateTable = {};
|
|
310
|
+
userServices = {};
|
|
311
|
+
constructor(config, deps, emit) {
|
|
338
312
|
this.config = config;
|
|
339
313
|
this.deps = deps;
|
|
340
314
|
this.emit = emit;
|
|
341
|
-
this.transactionManagers = {};
|
|
342
|
-
this.state = { pools: {}, users: {}, transactions: {} };
|
|
343
|
-
this.erc20s = {};
|
|
344
|
-
this.intervalStarted = false;
|
|
345
|
-
this.exchangeRateTable = {};
|
|
346
|
-
this.userServices = {};
|
|
347
315
|
config.chainId = config.chainId || 1;
|
|
348
316
|
this.hubPool = this.createHubPoolContract(deps.provider);
|
|
349
317
|
this.acceleratingDistributor = this.createAcceleratingDistributorContract(deps.provider);
|
|
@@ -351,549 +319,320 @@ var Client = /** @class */ (function () {
|
|
|
351
319
|
this.poolEvents = new PoolEventState(this.hubPool, this.config.hubPoolStartBlock);
|
|
352
320
|
this.configStoreClient = new acrossConfigStore.Client(config.configStoreAddress, deps.provider);
|
|
353
321
|
}
|
|
354
|
-
|
|
322
|
+
getOrCreateErc20Contract(address) {
|
|
355
323
|
if (this.erc20s[address])
|
|
356
324
|
return this.erc20s[address];
|
|
357
325
|
this.erc20s[address] = erc20.connect(address, this.deps.provider);
|
|
358
326
|
return this.erc20s[address];
|
|
359
|
-
}
|
|
360
|
-
|
|
327
|
+
}
|
|
328
|
+
getOrCreatePoolContract() {
|
|
361
329
|
return this.hubPool;
|
|
362
|
-
}
|
|
363
|
-
|
|
330
|
+
}
|
|
331
|
+
createHubPoolContract(signerOrProvider) {
|
|
364
332
|
return hubPool.connect(this.config.hubPoolAddress, signerOrProvider);
|
|
365
|
-
}
|
|
366
|
-
|
|
333
|
+
}
|
|
334
|
+
getOrCreatePoolEvents() {
|
|
367
335
|
return this.poolEvents;
|
|
368
|
-
}
|
|
369
|
-
|
|
336
|
+
}
|
|
337
|
+
createAcceleratingDistributorContract(signerOrProvider) {
|
|
370
338
|
return AcceleratingDistributor__factory.connect(this.config.acceleratingDistributorAddress, signerOrProvider);
|
|
371
|
-
}
|
|
372
|
-
|
|
339
|
+
}
|
|
340
|
+
createMerkleDistributorContract(signerOrProvider) {
|
|
373
341
|
return MerkleDistributor__factory.connect(this.config.merkleDistributorAddress, signerOrProvider);
|
|
374
|
-
}
|
|
375
|
-
|
|
342
|
+
}
|
|
343
|
+
getOrCreateAcceleratingDistributorContract() {
|
|
376
344
|
return this.acceleratingDistributor;
|
|
377
|
-
}
|
|
378
|
-
|
|
345
|
+
}
|
|
346
|
+
getOrCreateMerkleDistributorContract() {
|
|
379
347
|
return this.merkleDistributor;
|
|
380
|
-
}
|
|
381
|
-
|
|
348
|
+
}
|
|
349
|
+
getOrCreateUserService(userAddress, tokenAddress) {
|
|
382
350
|
if (has(this.userServices, [tokenAddress, userAddress]))
|
|
383
351
|
return get(this.userServices, [tokenAddress, userAddress]);
|
|
384
|
-
|
|
385
|
-
|
|
352
|
+
const erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
|
|
353
|
+
const userService = new UserState(erc20Contract, userAddress);
|
|
386
354
|
// this service is stateful now, so needs to be cached
|
|
387
355
|
set(this.userServices, [tokenAddress, userAddress], userService);
|
|
388
356
|
return userService;
|
|
389
|
-
}
|
|
390
|
-
|
|
357
|
+
}
|
|
358
|
+
updateExchangeRateTable(l1TokenAddress, exchangeRateTable) {
|
|
391
359
|
if (!this.exchangeRateTable[l1TokenAddress])
|
|
392
360
|
this.exchangeRateTable[l1TokenAddress] = {};
|
|
393
|
-
this.exchangeRateTable[l1TokenAddress] =
|
|
361
|
+
this.exchangeRateTable[l1TokenAddress] = { ...this.exchangeRateTable[l1TokenAddress], ...exchangeRateTable };
|
|
394
362
|
return this.exchangeRateTable[l1TokenAddress];
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
case 0:
|
|
416
|
-
_b = (_a = claim.args.amount).mul;
|
|
417
|
-
return [4 /*yield*/, poolContract.callStatic.exchangeRateCurrent(l1TokenAddress, { blockTag: claim.blockNumber })];
|
|
418
|
-
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}); }))];
|
|
422
|
-
case 2:
|
|
423
|
-
amountOfLPClaimed = (_a.sent()).reduce(function (prev, acc) { return acc.add(prev); }, bnZero);
|
|
424
|
-
return [4 /*yield*/, acceleratingDistributorContract.getUserStake(lpToken, userState.address)];
|
|
425
|
-
case 3:
|
|
426
|
-
cumulativeBalance = (_a.sent()).cumulativeBalance;
|
|
427
|
-
return [2 /*return*/, {
|
|
428
|
-
cumulativeBalance: cumulativeBalance,
|
|
429
|
-
amountAirdropped: amountOfLPClaimed,
|
|
430
|
-
}];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
363
|
+
}
|
|
364
|
+
async resolveStakingData(lpToken, l1TokenAddress, userState) {
|
|
365
|
+
assert(this.config.acceleratingDistributorAddress, "Must have the accelerating distributor address");
|
|
366
|
+
assert(this.config.merkleDistributorAddress, "Must have the merkle distributor address");
|
|
367
|
+
// Define the contracts we need to interact with.
|
|
368
|
+
const acceleratingDistributorContract = this.getOrCreateAcceleratingDistributorContract();
|
|
369
|
+
const merkleDistributorContract = this.getOrCreateMerkleDistributorContract();
|
|
370
|
+
const poolContract = this.getOrCreatePoolContract();
|
|
371
|
+
// Get the list of all claims made by the user.
|
|
372
|
+
const claimList = await merkleDistributorContract.queryFilter(merkleDistributorContract.filters.Claimed(undefined, undefined, userState.address, undefined, undefined, lpToken));
|
|
373
|
+
// Calculate the total amount of LP tokens claimed by the user from the merkle
|
|
374
|
+
// distributor contract with the exchange rate at the time of the claim.
|
|
375
|
+
const amountOfLPClaimed = (await Promise.all(claimList.map(async (claim) => claim.args.amount.mul(await poolContract.callStatic.exchangeRateCurrent(l1TokenAddress, { blockTag: claim.blockNumber }))))).reduce((prev, acc) => acc.add(prev), bnZero);
|
|
376
|
+
// Get the cumulative balance of the user from the accelerating distributor contract.
|
|
377
|
+
const { cumulativeBalance } = await acceleratingDistributorContract.getUserStake(lpToken, userState.address);
|
|
378
|
+
return {
|
|
379
|
+
cumulativeBalance,
|
|
380
|
+
amountAirdropped: amountOfLPClaimed,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
435
383
|
// calculates the value of each LP token transfer at the block it was sent. this only works if we have archive node
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
}); }))];
|
|
465
|
-
case 1:
|
|
466
|
-
exchangeRateTable = _a.apply(this, _b.concat([_d.apply(_c, [_e.sent()])]));
|
|
467
|
-
return [2 /*return*/, userState.transferEvents.reduce(function (result, transfer) {
|
|
468
|
-
var exchangeRate = exchangeRateTable[transfer.blockNumber];
|
|
469
|
-
if (transfer.args.to === userState.address) {
|
|
470
|
-
return result.add(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
|
|
471
|
-
}
|
|
472
|
-
if (transfer.args.from === userState.address) {
|
|
473
|
-
return result.sub(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
|
|
474
|
-
}
|
|
475
|
-
// we make sure to filter out any transfers where to/from is the same user
|
|
476
|
-
return result;
|
|
477
|
-
}, bnZero)];
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
};
|
|
482
|
-
Client.prototype.getOrCreateTransactionManager = function (signer, address) {
|
|
483
|
-
var _this = this;
|
|
384
|
+
async calculateLpTransferValue(l1TokenAddress, userState) {
|
|
385
|
+
assert(this.config.hasArchive, "Can only calculate historical lp values with archive node");
|
|
386
|
+
const contract = this.getOrCreatePoolContract();
|
|
387
|
+
const pool = new PoolState(contract, this.config.hubPoolAddress);
|
|
388
|
+
const blockNumbers = userState.transferEvents
|
|
389
|
+
.map((x) => x.blockNumber)
|
|
390
|
+
// we are going to lookup exchange rates for block numbers only if we dont already have it
|
|
391
|
+
// its possible these values do not exist, so to prevent crashing do optional chaining
|
|
392
|
+
.filter((blockNumber) => !this.exchangeRateTable?.[l1TokenAddress]?.[blockNumber]);
|
|
393
|
+
// new exchange rate lookups
|
|
394
|
+
const exchangeRateTable = this.updateExchangeRateTable(l1TokenAddress, Object.fromEntries(await Promise.all(blockNumbers.map(async (blockNumber) => {
|
|
395
|
+
return [blockNumber, await pool.exchangeRateAtBlock(l1TokenAddress, blockNumber)];
|
|
396
|
+
}))));
|
|
397
|
+
return userState.transferEvents.reduce((result, transfer) => {
|
|
398
|
+
const exchangeRate = exchangeRateTable[transfer.blockNumber];
|
|
399
|
+
if (transfer.args.to === userState.address) {
|
|
400
|
+
return result.add(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
|
|
401
|
+
}
|
|
402
|
+
if (transfer.args.from === userState.address) {
|
|
403
|
+
return result.sub(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
|
|
404
|
+
}
|
|
405
|
+
// we make sure to filter out any transfers where to/from is the same user
|
|
406
|
+
return result;
|
|
407
|
+
}, bnZero);
|
|
408
|
+
}
|
|
409
|
+
getOrCreateTransactionManager(signer, address) {
|
|
484
410
|
if (this.transactionManagers[address])
|
|
485
411
|
return this.transactionManagers[address];
|
|
486
|
-
|
|
412
|
+
const txman = TransactionManager({ confirmations: this.config.confirmations }, signer, (event, id, data) => {
|
|
487
413
|
if (event === "submitted") {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
414
|
+
this.state.transactions[id].state = event;
|
|
415
|
+
this.state.transactions[id].hash = data;
|
|
416
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
491
417
|
}
|
|
492
418
|
if (event === "mined") {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
419
|
+
const txReceipt = data;
|
|
420
|
+
this.state.transactions[id].state = event;
|
|
421
|
+
this.state.transactions[id].receipt = txReceipt;
|
|
422
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
497
423
|
// trigger pool and user update for a known mined transaction
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
424
|
+
const tx = this.state.transactions[id];
|
|
425
|
+
this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch((err) => {
|
|
426
|
+
this.emit(["error"], err);
|
|
501
427
|
});
|
|
502
428
|
}
|
|
503
429
|
if (event === "error") {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
430
|
+
this.state.transactions[id].state = event;
|
|
431
|
+
this.state.transactions[id].error = data;
|
|
432
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
507
433
|
}
|
|
508
434
|
});
|
|
509
435
|
this.transactionManagers[address] = txman;
|
|
510
436
|
return txman;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
case 1:
|
|
522
|
-
userAddress = _b.sent();
|
|
523
|
-
contract = this.getOrCreatePoolContract();
|
|
524
|
-
txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
525
|
-
return [4 /*yield*/, contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, __assign(__assign({}, overrides), { value: l1TokenAmount }))];
|
|
526
|
-
case 2:
|
|
527
|
-
request = _b.sent();
|
|
528
|
-
id = txman.request(request);
|
|
529
|
-
this.state.transactions[id] = {
|
|
530
|
-
id: id,
|
|
531
|
-
state: "requested",
|
|
532
|
-
toAddress: hubPoolAddress,
|
|
533
|
-
fromAddress: userAddress,
|
|
534
|
-
type: "Add Liquidity",
|
|
535
|
-
description: "Adding ETH to pool",
|
|
536
|
-
request: request,
|
|
537
|
-
};
|
|
538
|
-
this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
|
|
539
|
-
return [4 /*yield*/, txman.update()];
|
|
540
|
-
case 3:
|
|
541
|
-
_b.sent();
|
|
542
|
-
return [2 /*return*/, id];
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
};
|
|
547
|
-
Client.prototype.addTokenLiquidity = function (signer_1, l1Token_1, l1TokenAmount_1) {
|
|
548
|
-
return __awaiter(this, arguments, void 0, function (signer, l1Token, l1TokenAmount, overrides) {
|
|
549
|
-
var hubPoolAddress, userAddress, contract, txman, request, id;
|
|
550
|
-
if (overrides === void 0) { overrides = {}; }
|
|
551
|
-
return __generator(this, function (_a) {
|
|
552
|
-
switch (_a.label) {
|
|
553
|
-
case 0:
|
|
554
|
-
hubPoolAddress = this.config.hubPoolAddress;
|
|
555
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
556
|
-
case 1:
|
|
557
|
-
userAddress = _a.sent();
|
|
558
|
-
contract = this.getOrCreatePoolContract();
|
|
559
|
-
txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
560
|
-
return [4 /*yield*/, contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, overrides)];
|
|
561
|
-
case 2:
|
|
562
|
-
request = _a.sent();
|
|
563
|
-
return [4 /*yield*/, txman.request(request)];
|
|
564
|
-
case 3:
|
|
565
|
-
id = _a.sent();
|
|
566
|
-
this.state.transactions[id] = {
|
|
567
|
-
id: id,
|
|
568
|
-
state: "requested",
|
|
569
|
-
toAddress: hubPoolAddress,
|
|
570
|
-
fromAddress: userAddress,
|
|
571
|
-
type: "Add Liquidity",
|
|
572
|
-
description: "Adding Tokens to pool",
|
|
573
|
-
request: request,
|
|
574
|
-
};
|
|
575
|
-
this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
|
|
576
|
-
return [4 /*yield*/, txman.update()];
|
|
577
|
-
case 4:
|
|
578
|
-
_a.sent();
|
|
579
|
-
return [2 /*return*/, id];
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
Client.prototype.validateWithdraw = function (l1Token, userAddress, lpAmount) {
|
|
585
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
586
|
-
var poolState, userState;
|
|
587
|
-
return __generator(this, function (_a) {
|
|
588
|
-
switch (_a.label) {
|
|
589
|
-
case 0: return [4 /*yield*/, this.updatePool(l1Token)];
|
|
590
|
-
case 1:
|
|
591
|
-
_a.sent();
|
|
592
|
-
poolState = this.getPoolState(l1Token);
|
|
593
|
-
if (!!this.hasUserState(l1Token, userAddress)) return [3 /*break*/, 3];
|
|
594
|
-
return [4 /*yield*/, this.updateUser(l1Token, userAddress)];
|
|
595
|
-
case 2:
|
|
596
|
-
_a.sent();
|
|
597
|
-
_a.label = 3;
|
|
598
|
-
case 3:
|
|
599
|
-
userState = this.getUserState(poolState.l1Token, userAddress);
|
|
600
|
-
return [2 /*return*/, validateWithdraw(poolState, userState, lpAmount)];
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
};
|
|
605
|
-
Client.prototype.removeTokenLiquidity = function (signer_1, l1Token_1, lpTokenAmount_1) {
|
|
606
|
-
return __awaiter(this, arguments, void 0, function (signer, l1Token, lpTokenAmount, overrides) {
|
|
607
|
-
var hubPoolAddress, userAddress, contract, txman, request, id;
|
|
608
|
-
if (overrides === void 0) { overrides = {}; }
|
|
609
|
-
return __generator(this, function (_a) {
|
|
610
|
-
switch (_a.label) {
|
|
611
|
-
case 0:
|
|
612
|
-
hubPoolAddress = this.config.hubPoolAddress;
|
|
613
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
614
|
-
case 1:
|
|
615
|
-
userAddress = _a.sent();
|
|
616
|
-
return [4 /*yield*/, this.validateWithdraw(l1Token, userAddress, lpTokenAmount)];
|
|
617
|
-
case 2:
|
|
618
|
-
_a.sent();
|
|
619
|
-
contract = this.getOrCreatePoolContract();
|
|
620
|
-
txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
621
|
-
return [4 /*yield*/, contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, false, overrides)];
|
|
622
|
-
case 3:
|
|
623
|
-
request = _a.sent();
|
|
624
|
-
return [4 /*yield*/, txman.request(request)];
|
|
625
|
-
case 4:
|
|
626
|
-
id = _a.sent();
|
|
627
|
-
this.state.transactions[id] = {
|
|
628
|
-
id: id,
|
|
629
|
-
state: "requested",
|
|
630
|
-
toAddress: hubPoolAddress,
|
|
631
|
-
fromAddress: userAddress,
|
|
632
|
-
type: "Remove Liquidity",
|
|
633
|
-
description: "Withdrawing Tokens from pool",
|
|
634
|
-
request: request,
|
|
635
|
-
};
|
|
636
|
-
this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
|
|
637
|
-
return [4 /*yield*/, txman.update()];
|
|
638
|
-
case 5:
|
|
639
|
-
_a.sent();
|
|
640
|
-
return [2 /*return*/, id];
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
};
|
|
645
|
-
Client.prototype.removeEthliquidity = function (signer_1, lpTokenAmount_1) {
|
|
646
|
-
return __awaiter(this, arguments, void 0, function (signer, lpTokenAmount, overrides) {
|
|
647
|
-
var _a, hubPoolAddress, l1Token, userAddress, contract, txman, request, id;
|
|
648
|
-
if (overrides === void 0) { overrides = {}; }
|
|
649
|
-
return __generator(this, function (_b) {
|
|
650
|
-
switch (_b.label) {
|
|
651
|
-
case 0:
|
|
652
|
-
_a = this.config, hubPoolAddress = _a.hubPoolAddress, l1Token = _a.wethAddress;
|
|
653
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
654
|
-
case 1:
|
|
655
|
-
userAddress = _b.sent();
|
|
656
|
-
return [4 /*yield*/, this.validateWithdraw(l1Token, userAddress, lpTokenAmount)];
|
|
657
|
-
case 2:
|
|
658
|
-
_b.sent();
|
|
659
|
-
contract = this.getOrCreatePoolContract();
|
|
660
|
-
txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
661
|
-
return [4 /*yield*/, contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, true, overrides)];
|
|
662
|
-
case 3:
|
|
663
|
-
request = _b.sent();
|
|
664
|
-
return [4 /*yield*/, txman.request(request)];
|
|
665
|
-
case 4:
|
|
666
|
-
id = _b.sent();
|
|
667
|
-
this.state.transactions[id] = {
|
|
668
|
-
id: id,
|
|
669
|
-
state: "requested",
|
|
670
|
-
toAddress: hubPoolAddress,
|
|
671
|
-
fromAddress: userAddress,
|
|
672
|
-
type: "Remove Liquidity",
|
|
673
|
-
description: "Withdrawing Eth from pool",
|
|
674
|
-
request: request,
|
|
675
|
-
};
|
|
676
|
-
this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
|
|
677
|
-
return [4 /*yield*/, txman.update()];
|
|
678
|
-
case 5:
|
|
679
|
-
_b.sent();
|
|
680
|
-
return [2 /*return*/, id];
|
|
681
|
-
}
|
|
682
|
-
});
|
|
437
|
+
}
|
|
438
|
+
async addEthLiquidity(signer, l1TokenAmount, overrides = {}) {
|
|
439
|
+
const { hubPoolAddress, wethAddress: l1Token } = this.config;
|
|
440
|
+
const userAddress = await signer.getAddress();
|
|
441
|
+
const contract = this.getOrCreatePoolContract();
|
|
442
|
+
const txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
443
|
+
// dont allow override value here
|
|
444
|
+
const request = await contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, {
|
|
445
|
+
...overrides,
|
|
446
|
+
value: l1TokenAmount,
|
|
683
447
|
});
|
|
684
|
-
|
|
685
|
-
|
|
448
|
+
const id = txman.request(request);
|
|
449
|
+
this.state.transactions[id] = {
|
|
450
|
+
id,
|
|
451
|
+
state: "requested",
|
|
452
|
+
toAddress: hubPoolAddress,
|
|
453
|
+
fromAddress: userAddress,
|
|
454
|
+
type: "Add Liquidity",
|
|
455
|
+
description: "Adding ETH to pool",
|
|
456
|
+
request,
|
|
457
|
+
};
|
|
458
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
459
|
+
await txman.update();
|
|
460
|
+
return id;
|
|
461
|
+
}
|
|
462
|
+
async addTokenLiquidity(signer, l1Token, l1TokenAmount, overrides = {}) {
|
|
463
|
+
const { hubPoolAddress } = this.config;
|
|
464
|
+
const userAddress = await signer.getAddress();
|
|
465
|
+
const contract = this.getOrCreatePoolContract();
|
|
466
|
+
const txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
467
|
+
const request = await contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, overrides);
|
|
468
|
+
const id = await txman.request(request);
|
|
469
|
+
this.state.transactions[id] = {
|
|
470
|
+
id,
|
|
471
|
+
state: "requested",
|
|
472
|
+
toAddress: hubPoolAddress,
|
|
473
|
+
fromAddress: userAddress,
|
|
474
|
+
type: "Add Liquidity",
|
|
475
|
+
description: "Adding Tokens to pool",
|
|
476
|
+
request,
|
|
477
|
+
};
|
|
478
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
479
|
+
await txman.update();
|
|
480
|
+
return id;
|
|
481
|
+
}
|
|
482
|
+
async validateWithdraw(l1Token, userAddress, lpAmount) {
|
|
483
|
+
await this.updatePool(l1Token);
|
|
484
|
+
const poolState = this.getPoolState(l1Token);
|
|
485
|
+
if (!this.hasUserState(l1Token, userAddress)) {
|
|
486
|
+
await this.updateUser(l1Token, userAddress);
|
|
487
|
+
}
|
|
488
|
+
const userState = this.getUserState(poolState.l1Token, userAddress);
|
|
489
|
+
return validateWithdraw(poolState, userState, lpAmount);
|
|
490
|
+
}
|
|
491
|
+
async removeTokenLiquidity(signer, l1Token, lpTokenAmount, overrides = {}) {
|
|
492
|
+
const { hubPoolAddress } = this.config;
|
|
493
|
+
const userAddress = await signer.getAddress();
|
|
494
|
+
await this.validateWithdraw(l1Token, userAddress, lpTokenAmount);
|
|
495
|
+
const contract = this.getOrCreatePoolContract();
|
|
496
|
+
const txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
497
|
+
const request = await contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, false, overrides);
|
|
498
|
+
const id = await txman.request(request);
|
|
499
|
+
this.state.transactions[id] = {
|
|
500
|
+
id,
|
|
501
|
+
state: "requested",
|
|
502
|
+
toAddress: hubPoolAddress,
|
|
503
|
+
fromAddress: userAddress,
|
|
504
|
+
type: "Remove Liquidity",
|
|
505
|
+
description: "Withdrawing Tokens from pool",
|
|
506
|
+
request,
|
|
507
|
+
};
|
|
508
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
509
|
+
await txman.update();
|
|
510
|
+
return id;
|
|
511
|
+
}
|
|
512
|
+
async removeEthliquidity(signer, lpTokenAmount, overrides = {}) {
|
|
513
|
+
const { hubPoolAddress, wethAddress: l1Token } = this.config;
|
|
514
|
+
const userAddress = await signer.getAddress();
|
|
515
|
+
await this.validateWithdraw(l1Token, userAddress, lpTokenAmount);
|
|
516
|
+
const contract = this.getOrCreatePoolContract();
|
|
517
|
+
const txman = this.getOrCreateTransactionManager(signer, userAddress);
|
|
518
|
+
const request = await contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, true, overrides);
|
|
519
|
+
const id = await txman.request(request);
|
|
520
|
+
this.state.transactions[id] = {
|
|
521
|
+
id,
|
|
522
|
+
state: "requested",
|
|
523
|
+
toAddress: hubPoolAddress,
|
|
524
|
+
fromAddress: userAddress,
|
|
525
|
+
type: "Remove Liquidity",
|
|
526
|
+
description: "Withdrawing Eth from pool",
|
|
527
|
+
request,
|
|
528
|
+
};
|
|
529
|
+
this.emit(["transactions", id], { ...this.state.transactions[id] });
|
|
530
|
+
await txman.update();
|
|
531
|
+
return id;
|
|
532
|
+
}
|
|
533
|
+
getPoolState(l1TokenAddress) {
|
|
686
534
|
return this.state.pools[l1TokenAddress];
|
|
687
|
-
}
|
|
688
|
-
|
|
535
|
+
}
|
|
536
|
+
hasPoolState(l1TokenAddress) {
|
|
689
537
|
return Boolean(this.state.pools[l1TokenAddress]);
|
|
690
|
-
}
|
|
691
|
-
|
|
538
|
+
}
|
|
539
|
+
setUserState(l1TokenAddress, userAddress, state) {
|
|
692
540
|
set(this.state, ["users", userAddress, l1TokenAddress], state);
|
|
693
541
|
return state;
|
|
694
|
-
}
|
|
695
|
-
|
|
542
|
+
}
|
|
543
|
+
getUserState(l1TokenAddress, userAddress) {
|
|
696
544
|
return get(this.state, ["users", userAddress, l1TokenAddress]);
|
|
697
|
-
}
|
|
698
|
-
|
|
545
|
+
}
|
|
546
|
+
hasUserState(l1TokenAddress, userAddress) {
|
|
699
547
|
return has(this.state, ["users", userAddress, l1TokenAddress]);
|
|
700
|
-
}
|
|
701
|
-
|
|
548
|
+
}
|
|
549
|
+
hasTxState(id) {
|
|
702
550
|
return has(this.state, ["transactions", id]);
|
|
703
|
-
}
|
|
704
|
-
|
|
551
|
+
}
|
|
552
|
+
getTxState(id) {
|
|
705
553
|
return get(this.state, ["transactions", id]);
|
|
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
|
-
|
|
743
|
-
|
|
744
|
-
|
|
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
|
-
_a.sent();
|
|
775
|
-
poolState = this.getPoolState(l1TokenAddress);
|
|
776
|
-
lpToken = poolState.lpToken;
|
|
777
|
-
getPoolEventState = this.getOrCreatePoolEvents();
|
|
778
|
-
return [4 /*yield*/, getPoolEventState.read(latestBlock.number, l1TokenAddress, userAddress)];
|
|
779
|
-
case 3:
|
|
780
|
-
poolEventState = _a.sent();
|
|
781
|
-
getUserState = this.getOrCreateUserService(userAddress, lpToken);
|
|
782
|
-
return [4 /*yield*/, getUserState.read(latestBlock.number)];
|
|
783
|
-
case 4:
|
|
784
|
-
userState = _a.sent();
|
|
785
|
-
return [4 /*yield*/, this.updateAndEmitUser(userState, poolState, poolEventState)];
|
|
786
|
-
case 5:
|
|
787
|
-
_a.sent();
|
|
788
|
-
return [2 /*return*/];
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
};
|
|
793
|
-
Client.prototype.updatePool = function (l1TokenAddress, overrideLatestBlock) {
|
|
794
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
795
|
-
var _a, blockDelta, contract, pool, latestBlock, _b, previousBlock, state, rateModel, err_1;
|
|
796
|
-
return __generator(this, function (_c) {
|
|
797
|
-
switch (_c.label) {
|
|
798
|
-
case 0:
|
|
799
|
-
_a = this.config.blockDelta, blockDelta = _a === void 0 ? DEFAULT_BLOCK_DELTA : _a;
|
|
800
|
-
contract = this.getOrCreatePoolContract();
|
|
801
|
-
pool = new PoolState(contract, this.config.hubPoolAddress);
|
|
802
|
-
_b = overrideLatestBlock;
|
|
803
|
-
if (_b) return [3 /*break*/, 2];
|
|
804
|
-
return [4 /*yield*/, this.deps.provider.getBlock("latest")];
|
|
805
|
-
case 1:
|
|
806
|
-
_b = (_c.sent());
|
|
807
|
-
_c.label = 2;
|
|
808
|
-
case 2:
|
|
809
|
-
latestBlock = _b;
|
|
810
|
-
return [4 /*yield*/, this.deps.provider.getBlock(latestBlock.number - blockDelta)];
|
|
811
|
-
case 3:
|
|
812
|
-
previousBlock = _c.sent();
|
|
813
|
-
return [4 /*yield*/, pool.read(l1TokenAddress, latestBlock.number, previousBlock.number)];
|
|
814
|
-
case 4:
|
|
815
|
-
state = _c.sent();
|
|
816
|
-
rateModel = undefined;
|
|
817
|
-
_c.label = 5;
|
|
818
|
-
case 5:
|
|
819
|
-
_c.trys.push([5, 7, , 8]);
|
|
820
|
-
return [4 /*yield*/, this.configStoreClient.getRateModel(l1TokenAddress)];
|
|
821
|
-
case 6:
|
|
822
|
-
// Use the default rate model (i.e. not any of the routeRateModels to project the Pool's APR). This assumes
|
|
823
|
-
// that the default rate model is the most often used, but this may change in future if many different
|
|
824
|
-
// route rate models are set.
|
|
825
|
-
rateModel = _c.sent();
|
|
826
|
-
return [3 /*break*/, 8];
|
|
827
|
-
case 7:
|
|
828
|
-
err_1 = _c.sent();
|
|
829
|
-
// we could swallow this error or just log it since getting the rate model is optional,
|
|
830
|
-
// but we will just emit it to the caller and let them decide what to do with it.
|
|
831
|
-
this.emit(["error"], err_1);
|
|
832
|
-
return [3 /*break*/, 8];
|
|
833
|
-
case 8:
|
|
834
|
-
this.state.pools[l1TokenAddress] = joinPoolState(state, latestBlock, previousBlock, rateModel);
|
|
835
|
-
this.emit(["pools", l1TokenAddress], this.state.pools[l1TokenAddress]);
|
|
836
|
-
return [2 /*return*/];
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
});
|
|
840
|
-
};
|
|
841
|
-
Client.prototype.updateTransactions = function () {
|
|
842
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
843
|
-
var _i, _a, txMan, err_2;
|
|
844
|
-
return __generator(this, function (_b) {
|
|
845
|
-
switch (_b.label) {
|
|
846
|
-
case 0:
|
|
847
|
-
_i = 0, _a = Object.values(this.transactionManagers);
|
|
848
|
-
_b.label = 1;
|
|
849
|
-
case 1:
|
|
850
|
-
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
851
|
-
txMan = _a[_i];
|
|
852
|
-
_b.label = 2;
|
|
853
|
-
case 2:
|
|
854
|
-
_b.trys.push([2, 4, , 5]);
|
|
855
|
-
return [4 /*yield*/, txMan.update()];
|
|
856
|
-
case 3:
|
|
857
|
-
_b.sent();
|
|
858
|
-
return [3 /*break*/, 5];
|
|
859
|
-
case 4:
|
|
860
|
-
err_2 = _b.sent();
|
|
861
|
-
this.emit(["error"], err_2);
|
|
862
|
-
return [3 /*break*/, 5];
|
|
863
|
-
case 5:
|
|
864
|
-
_i++;
|
|
865
|
-
return [3 /*break*/, 1];
|
|
866
|
-
case 6: return [2 /*return*/];
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
});
|
|
870
|
-
};
|
|
554
|
+
}
|
|
555
|
+
async updateAndEmitUser(userState, poolState, poolEventState) {
|
|
556
|
+
const { l1Token: l1TokenAddress, lpToken } = poolState;
|
|
557
|
+
const { address: userAddress } = userState;
|
|
558
|
+
const transferValue = this.config.hasArchive
|
|
559
|
+
? await this.calculateLpTransferValue(l1TokenAddress, userState)
|
|
560
|
+
: bnZero;
|
|
561
|
+
const stakeData = await this.resolveStakingData(lpToken, l1TokenAddress, userState);
|
|
562
|
+
const tokenEventState = poolEventState[l1TokenAddress];
|
|
563
|
+
const newUserState = this.setUserState(l1TokenAddress, userAddress, joinUserState(poolState, tokenEventState, userState, transferValue, stakeData.cumulativeBalance, stakeData.amountAirdropped));
|
|
564
|
+
this.emit(["users", userAddress, l1TokenAddress], newUserState);
|
|
565
|
+
}
|
|
566
|
+
async updateUserWithTransaction(userAddress, txReceipt) {
|
|
567
|
+
const latestBlock = await this.deps.provider.getBlock("latest");
|
|
568
|
+
const getPoolEventState = this.getOrCreatePoolEvents();
|
|
569
|
+
const l1TokenAddress = getPoolEventState.getL1TokenFromReceipt(txReceipt);
|
|
570
|
+
await this.updatePool(l1TokenAddress, latestBlock);
|
|
571
|
+
const poolState = this.getPoolState(l1TokenAddress);
|
|
572
|
+
const poolEventState = getPoolEventState.readTxReceipt(txReceipt);
|
|
573
|
+
const lpToken = poolState.lpToken;
|
|
574
|
+
const getUserState = this.getOrCreateUserService(userAddress, lpToken);
|
|
575
|
+
const userState = await getUserState.read(latestBlock.number);
|
|
576
|
+
await this.updateAndEmitUser(userState, poolState, poolEventState);
|
|
577
|
+
}
|
|
578
|
+
async updateUser(userAddress, l1TokenAddress) {
|
|
579
|
+
const latestBlock = await this.deps.provider.getBlock("latest");
|
|
580
|
+
await this.updatePool(l1TokenAddress, latestBlock);
|
|
581
|
+
const poolState = this.getPoolState(l1TokenAddress);
|
|
582
|
+
const lpToken = poolState.lpToken;
|
|
583
|
+
const getPoolEventState = this.getOrCreatePoolEvents();
|
|
584
|
+
const poolEventState = await getPoolEventState.read(latestBlock.number, l1TokenAddress, userAddress);
|
|
585
|
+
const getUserState = this.getOrCreateUserService(userAddress, lpToken);
|
|
586
|
+
const userState = await getUserState.read(latestBlock.number);
|
|
587
|
+
await this.updateAndEmitUser(userState, poolState, poolEventState);
|
|
588
|
+
}
|
|
589
|
+
async updatePool(l1TokenAddress, overrideLatestBlock) {
|
|
590
|
+
// default to 100 block delta unless specified otherwise in config
|
|
591
|
+
const { blockDelta = DEFAULT_BLOCK_DELTA } = this.config;
|
|
592
|
+
const contract = this.getOrCreatePoolContract();
|
|
593
|
+
const pool = new PoolState(contract, this.config.hubPoolAddress);
|
|
594
|
+
const latestBlock = overrideLatestBlock || (await this.deps.provider.getBlock("latest"));
|
|
595
|
+
const previousBlock = await this.deps.provider.getBlock(latestBlock.number - blockDelta);
|
|
596
|
+
const state = await pool.read(l1TokenAddress, latestBlock.number, previousBlock.number);
|
|
597
|
+
let rateModel = undefined;
|
|
598
|
+
try {
|
|
599
|
+
// Use the default rate model (i.e. not any of the routeRateModels to project the Pool's APR). This assumes
|
|
600
|
+
// that the default rate model is the most often used, but this may change in future if many different
|
|
601
|
+
// route rate models are set.
|
|
602
|
+
rateModel = await this.configStoreClient.getRateModel(l1TokenAddress);
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
// we could swallow this error or just log it since getting the rate model is optional,
|
|
606
|
+
// but we will just emit it to the caller and let them decide what to do with it.
|
|
607
|
+
this.emit(["error"], err);
|
|
608
|
+
}
|
|
609
|
+
this.state.pools[l1TokenAddress] = joinPoolState(state, latestBlock, previousBlock, rateModel);
|
|
610
|
+
this.emit(["pools", l1TokenAddress], this.state.pools[l1TokenAddress]);
|
|
611
|
+
}
|
|
612
|
+
async updateTransactions() {
|
|
613
|
+
for (const txMan of Object.values(this.transactionManagers)) {
|
|
614
|
+
try {
|
|
615
|
+
await txMan.update();
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
this.emit(["error"], err);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
871
622
|
// starts transaction checking intervals, defaults to 30 seconds
|
|
872
|
-
|
|
873
|
-
var _this = this;
|
|
874
|
-
if (delayMs === void 0) { delayMs = 30000; }
|
|
623
|
+
startInterval(delayMs = 30000) {
|
|
875
624
|
assert(!this.intervalStarted, "Interval already started, try stopping first");
|
|
876
625
|
this.intervalStarted = true;
|
|
877
|
-
loop(
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
return [4 /*yield*/, this.updateTransactions()];
|
|
883
|
-
case 1:
|
|
884
|
-
_a.sent();
|
|
885
|
-
return [2 /*return*/];
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
}); }, delayMs).catch(function (err) {
|
|
889
|
-
_this.emit(["error"], err);
|
|
626
|
+
loop(async () => {
|
|
627
|
+
assert(this.intervalStarted, "HubPool Interval Stopped");
|
|
628
|
+
await this.updateTransactions();
|
|
629
|
+
}, delayMs).catch((err) => {
|
|
630
|
+
this.emit(["error"], err);
|
|
890
631
|
});
|
|
891
|
-
}
|
|
632
|
+
}
|
|
892
633
|
// starts transaction checking intervals
|
|
893
|
-
|
|
634
|
+
stopInterval() {
|
|
894
635
|
this.intervalStarted = false;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
}());
|
|
898
|
-
export { Client };
|
|
636
|
+
}
|
|
637
|
+
}
|
|
899
638
|
//# sourceMappingURL=poolClient.js.map
|