@across-protocol/sdk 4.3.111-alpha.4 → 4.3.111
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 +64 -50
- package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/bybit.js +29 -16
- package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/env.js +15 -11
- package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
- package/dist/cjs/addressAggregator/adapters/file.js +45 -32
- 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 +36 -22
- package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/cjs/addressAggregator/index.js +87 -57
- package/dist/cjs/addressAggregator/index.js.map +1 -1
- package/dist/cjs/apiClient/abstractClient.js +8 -9
- package/dist/cjs/apiClient/abstractClient.js.map +1 -1
- package/dist/cjs/apiClient/index.js +1 -1
- package/dist/cjs/apiClient/mockedClient.js +29 -23
- package/dist/cjs/apiClient/mockedClient.js.map +1 -1
- package/dist/cjs/apiClient/productionClient.js +103 -65
- package/dist/cjs/apiClient/productionClient.js.map +1 -1
- package/dist/cjs/arch/evm/BlockUtils.js +208 -122
- 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 +288 -134
- 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 +49 -38
- 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 +158 -102
- 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 +1147 -708
- 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 +236 -174
- 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 +355 -166
- package/dist/cjs/arch/svm/utils.js.map +1 -1
- package/dist/cjs/caching/Arweave/ArweaveClient.js +246 -168
- 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 +49 -40
- 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 +18 -13
- 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 +381 -302
- 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 +83 -58
- package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +900 -709
- 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 +128 -95
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +53 -48
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +8 -10
- package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +90 -67
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +24 -46
- 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 +708 -526
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +179 -133
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -124
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +389 -357
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +8 -9
- 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 +67 -58
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockEvents.js +52 -47
- package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +185 -142
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +192 -208
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +143 -140
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +73 -57
- 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 +437 -285
- package/dist/cjs/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/coingecko/index.js +1 -1
- package/dist/cjs/constants.js +30 -23
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/contracts/acrossConfigStore.js +48 -27
- package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
- package/dist/cjs/contracts/hubPool.js +20 -36
- package/dist/cjs/contracts/hubPool.js.map +1 -1
- package/dist/cjs/contracts/index.js +1 -1
- package/dist/cjs/contracts/utils.js +8 -6
- package/dist/cjs/contracts/utils.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +16 -7
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js +45 -26
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +28 -16
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.js +112 -73
- package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/solana.js +33 -20
- package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/cjs/gasPriceOracle/oracle.js +104 -77
- 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 +35 -33
- package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
- package/dist/cjs/lpFeeCalculator/rateModel.js +9 -7
- package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
- package/dist/cjs/merkleDistributor/MerkleDistributor.js +18 -20
- 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 +100 -45
- package/dist/cjs/pool/TransactionManager.js.map +1 -1
- package/dist/cjs/pool/index.js +1 -1
- package/dist/cjs/pool/poolClient.js +731 -464
- 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 +100 -45
- package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
- package/dist/cjs/pool/uma/clients/erc20/client.js +16 -18
- 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 +5 -4
- package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
- package/dist/cjs/pool/uma/utils.js +30 -11
- package/dist/cjs/pool/uma/utils.js.map +1 -1
- package/dist/cjs/priceClient/adapters/acrossApi.js +39 -22
- package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
- package/dist/cjs/priceClient/adapters/baseAdapter.js +73 -49
- package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/cjs/priceClient/adapters/coingecko.js +61 -34
- package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
- package/dist/cjs/priceClient/adapters/default.js +31 -16
- package/dist/cjs/priceClient/adapters/default.js.map +1 -1
- package/dist/cjs/priceClient/adapters/defiLlama.js +74 -40
- 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 +159 -110
- package/dist/cjs/priceClient/priceClient.js.map +1 -1
- package/dist/cjs/providers/alchemy.js +19 -17
- package/dist/cjs/providers/alchemy.js.map +1 -1
- package/dist/cjs/providers/cachedProvider.js +129 -88
- package/dist/cjs/providers/cachedProvider.js.map +1 -1
- package/dist/cjs/providers/drpc.js +11 -9
- package/dist/cjs/providers/drpc.js.map +1 -1
- package/dist/cjs/providers/index.js +1 -1
- package/dist/cjs/providers/infura.js +12 -10
- package/dist/cjs/providers/infura.js.map +1 -1
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +15 -7
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -6
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +15 -7
- package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +66 -42
- 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 +31 -29
- package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
- package/dist/cjs/providers/quicknode.js +21 -19
- package/dist/cjs/providers/quicknode.js.map +1 -1
- package/dist/cjs/providers/rateLimitedProvider.js +79 -64
- package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
- package/dist/cjs/providers/retryProvider.js +246 -163
- package/dist/cjs/providers/retryProvider.js.map +1 -1
- package/dist/cjs/providers/solana/baseRpcFactories.js +18 -14
- package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
- package/dist/cjs/providers/solana/cachedRpcFactory.js +112 -70
- package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/defaultRpcFactory.js +15 -8
- 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 +191 -135
- package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +90 -67
- package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
- package/dist/cjs/providers/solana/retryRpcFactory.js +79 -52
- 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 +53 -31
- 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 +28 -26
- package/dist/cjs/providers/utils.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +162 -108
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +26 -14
- package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +29 -20
- 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 +137 -88
- 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 +297 -199
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/typeguards/error.js +7 -5
- package/dist/cjs/typeguards/error.js.map +1 -1
- package/dist/cjs/typeguards/index.js +1 -1
- package/dist/cjs/utils/AddressUtils.js +144 -117
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/ArrayUtils.js +78 -21
- package/dist/cjs/utils/ArrayUtils.js.map +1 -1
- package/dist/cjs/utils/BigNumberUtils.js +10 -9
- package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
- package/dist/cjs/utils/BlockExplorerUtils.js +30 -26
- package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
- package/dist/cjs/utils/BlockFinder.js +5 -2
- package/dist/cjs/utils/BlockFinder.js.map +1 -1
- package/dist/cjs/utils/BlockUtils.js +41 -24
- package/dist/cjs/utils/BlockUtils.js.map +1 -1
- package/dist/cjs/utils/BundleUtils.js +24 -21
- package/dist/cjs/utils/BundleUtils.js.map +1 -1
- package/dist/cjs/utils/CCTPUtils.js +126 -62
- package/dist/cjs/utils/CCTPUtils.js.map +1 -1
- package/dist/cjs/utils/CachingUtils.js +42 -20
- 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 +99 -122
- package/dist/cjs/utils/DepositUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.js +70 -49
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/FormattingUtils.js +32 -26
- package/dist/cjs/utils/FormattingUtils.js.map +1 -1
- package/dist/cjs/utils/HyperLiquidUtils.js +23 -10
- package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
- package/dist/cjs/utils/IPFSUtils.js +34 -16
- 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 +12 -10
- package/dist/cjs/utils/LogUtils.js.map +1 -1
- package/dist/cjs/utils/Multicall.js +115 -56
- package/dist/cjs/utils/Multicall.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.js +28 -12
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/NumberUtils.js +3 -1
- package/dist/cjs/utils/NumberUtils.js.map +1 -1
- package/dist/cjs/utils/ObjectUtils.js +41 -27
- package/dist/cjs/utils/ObjectUtils.js.map +1 -1
- package/dist/cjs/utils/Profiler.js +83 -80
- package/dist/cjs/utils/Profiler.js.map +1 -1
- package/dist/cjs/utils/ReviverUtils.js +9 -5
- 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 +64 -41
- 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 +22 -12
- package/dist/cjs/utils/abi/index.js.map +1 -1
- package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +12 -9
- 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 +53 -40
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/esm/addressAggregator/adapters/abstract.js +64 -48
- package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/bybit.js +29 -15
- package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/env.js +14 -9
- package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/file.js +43 -29
- package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
- package/dist/esm/addressAggregator/adapters/risklabs.js +35 -20
- package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
- package/dist/esm/addressAggregator/index.js +83 -52
- 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 +9 -15
- package/dist/esm/apiClient/abstractClient.js.map +1 -1
- package/dist/esm/apiClient/mockedClient.js +26 -21
- package/dist/esm/apiClient/mockedClient.js.map +1 -1
- package/dist/esm/apiClient/productionClient.js +101 -61
- package/dist/esm/apiClient/productionClient.js.map +1 -1
- package/dist/esm/arch/evm/BlockUtils.js +217 -139
- package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
- package/dist/esm/arch/evm/SpokeUtils.js +289 -146
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/evm/utils/wait.js +46 -34
- package/dist/esm/arch/evm/utils/wait.js.map +1 -1
- package/dist/esm/arch/svm/BlockUtils.js +166 -118
- package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.js +1150 -738
- 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 +232 -172
- 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 +345 -155
- package/dist/esm/arch/svm/utils.js.map +1 -1
- package/dist/esm/caching/Arweave/ArweaveClient.js +256 -182
- package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/caching/IPFS/PinataIPFSClient.js +48 -47
- package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
- package/dist/esm/caching/Memory/MemoryCacheClient.js +19 -13
- package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +408 -333
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BaseAbstractClient.js +92 -66
- package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +1054 -927
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +131 -102
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +59 -57
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -7
- package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +94 -75
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +23 -45
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.js +740 -581
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +178 -133
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -126
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +399 -372
- 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 +64 -53
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockEvents.js +49 -42
- package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.js +182 -138
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +188 -202
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +132 -127
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +69 -53
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
- package/dist/esm/coingecko/Coingecko.js +443 -298
- package/dist/esm/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/constants.js +47 -40
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/contracts/acrossConfigStore.js +46 -24
- package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
- package/dist/esm/contracts/hubPool.js +18 -34
- package/dist/esm/contracts/hubPool.js.map +1 -1
- package/dist/esm/contracts/utils.js +5 -3
- package/dist/esm/contracts/utils.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js +14 -6
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/ethereum.js +42 -22
- package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js +25 -13
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.js +108 -72
- package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/solana.js +31 -22
- package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
- package/dist/esm/gasPriceOracle/oracle.js +96 -70
- 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 +33 -30
- package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
- package/dist/esm/lpFeeCalculator/rateModel.js +9 -7
- package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
- package/dist/esm/merkleDistributor/MerkleDistributor.js +17 -18
- package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
- package/dist/esm/pool/TransactionManager.js +100 -45
- package/dist/esm/pool/TransactionManager.js.map +1 -1
- package/dist/esm/pool/poolClient.js +740 -479
- 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 +100 -45
- package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
- package/dist/esm/pool/uma/clients/erc20/client.js +13 -15
- package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
- package/dist/esm/pool/uma/oracle/utils.js +3 -2
- package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
- package/dist/esm/pool/uma/utils.js +28 -9
- package/dist/esm/pool/uma/utils.js.map +1 -1
- package/dist/esm/priceClient/adapters/acrossApi.js +40 -21
- package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
- package/dist/esm/priceClient/adapters/baseAdapter.js +72 -46
- package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/esm/priceClient/adapters/coingecko.js +61 -33
- package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
- package/dist/esm/priceClient/adapters/default.js +31 -15
- package/dist/esm/priceClient/adapters/default.js.map +1 -1
- package/dist/esm/priceClient/adapters/defiLlama.js +73 -38
- package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
- package/dist/esm/priceClient/priceClient.js +158 -109
- package/dist/esm/priceClient/priceClient.js.map +1 -1
- package/dist/esm/providers/alchemy.js +18 -16
- package/dist/esm/providers/alchemy.js.map +1 -1
- package/dist/esm/providers/cachedProvider.js +134 -99
- 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 +10 -8
- package/dist/esm/providers/drpc.js.map +1 -1
- package/dist/esm/providers/infura.js +11 -9
- package/dist/esm/providers/infura.js.map +1 -1
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +15 -6
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -5
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +15 -6
- package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +66 -41
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
- package/dist/esm/providers/mocks/mockEthersProvider.js +30 -27
- package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
- package/dist/esm/providers/quicknode.js +20 -18
- package/dist/esm/providers/quicknode.js.map +1 -1
- package/dist/esm/providers/rateLimitedProvider.js +80 -68
- package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
- package/dist/esm/providers/retryProvider.js +259 -186
- package/dist/esm/providers/retryProvider.js.map +1 -1
- package/dist/esm/providers/solana/baseRpcFactories.js +19 -13
- package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
- package/dist/esm/providers/solana/cachedRpcFactory.js +112 -75
- package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/defaultRpcFactory.js +14 -6
- package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +202 -149
- package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/rateLimitedRpcFactory.js +90 -70
- package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
- package/dist/esm/providers/solana/retryRpcFactory.js +74 -50
- 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 +51 -28
- 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 +20 -17
- package/dist/esm/providers/utils.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +152 -98
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +26 -13
- package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js +19 -9
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +128 -83
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +299 -211
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/typeguards/error.js +5 -3
- package/dist/esm/typeguards/error.js.map +1 -1
- package/dist/esm/utils/AddressUtils.js +147 -115
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/ArrayUtils.js +78 -21
- package/dist/esm/utils/ArrayUtils.js.map +1 -1
- package/dist/esm/utils/BigNumberUtils.js +12 -11
- package/dist/esm/utils/BigNumberUtils.js.map +1 -1
- package/dist/esm/utils/BlockExplorerUtils.js +23 -19
- package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
- package/dist/esm/utils/BlockFinder.js +6 -2
- package/dist/esm/utils/BlockFinder.js.map +1 -1
- package/dist/esm/utils/BlockUtils.js +40 -31
- package/dist/esm/utils/BlockUtils.js.map +1 -1
- package/dist/esm/utils/BundleUtils.js +24 -21
- package/dist/esm/utils/BundleUtils.js.map +1 -1
- package/dist/esm/utils/CCTPUtils.js +123 -62
- package/dist/esm/utils/CCTPUtils.js.map +1 -1
- package/dist/esm/utils/CachingUtils.js +38 -17
- 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 +98 -121
- package/dist/esm/utils/DepositUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.js +69 -52
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/FormattingUtils.js +26 -20
- package/dist/esm/utils/FormattingUtils.js.map +1 -1
- package/dist/esm/utils/HyperLiquidUtils.js +22 -8
- package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
- package/dist/esm/utils/IPFSUtils.js +35 -16
- 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 +12 -8
- package/dist/esm/utils/LogUtils.js.map +1 -1
- package/dist/esm/utils/Multicall.js +110 -50
- package/dist/esm/utils/Multicall.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.js +28 -12
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/NumberUtils.js +3 -1
- package/dist/esm/utils/NumberUtils.js.map +1 -1
- package/dist/esm/utils/ObjectUtils.js +41 -27
- package/dist/esm/utils/ObjectUtils.js.map +1 -1
- package/dist/esm/utils/Profiler.js +82 -77
- package/dist/esm/utils/Profiler.js.map +1 -1
- package/dist/esm/utils/ReviverUtils.js +7 -3
- package/dist/esm/utils/ReviverUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.js +78 -83
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.js +57 -33
- 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 +20 -10
- package/dist/esm/utils/abi/index.js.map +1 -1
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +12 -8
- package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
- package/dist/esm/utils/common.js +52 -38
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
- package/dist/types/utils/Multicall.d.ts.map +1 -1
- package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +1 -0
- package/src/gasPriceOracle/oracle.ts +1 -0
- package/src/utils/Multicall.ts +1 -0
- package/src/utils/NetworkUtils.ts +8 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
|
|
1
2
|
import assert from "assert";
|
|
2
3
|
import * as uma from "./uma";
|
|
3
4
|
import { bnZero, toBNWei, fixedPointAdjustment, calcPeriodicCompoundInterest, calcApr, BigNumber, fromWei, } from "../utils";
|
|
@@ -8,203 +9,247 @@ import has from "lodash/has";
|
|
|
8
9
|
import { calculateInstantaneousRate } from "../lpFeeCalculator";
|
|
9
10
|
import { hubPool, acrossConfigStore } from "../contracts";
|
|
10
11
|
import { AcceleratingDistributor__factory, MerkleDistributor__factory, } from "../typechain";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
contract
|
|
18
|
-
address;
|
|
19
|
-
constructor(contract, address) {
|
|
12
|
+
var erc20 = uma.clients.erc20;
|
|
13
|
+
var loop = uma.utils.loop;
|
|
14
|
+
var TransactionManager = uma.across.TransactionManager;
|
|
15
|
+
var _a = uma.across.constants, SECONDS_PER_YEAR = _a.SECONDS_PER_YEAR, DEFAULT_BLOCK_DELTA = _a.DEFAULT_BLOCK_DELTA;
|
|
16
|
+
var AddressZero = ethers.constants.AddressZero;
|
|
17
|
+
var PoolState = /** @class */ (function () {
|
|
18
|
+
function PoolState(contract, address) {
|
|
20
19
|
this.contract = contract;
|
|
21
20
|
this.address = address;
|
|
22
21
|
}
|
|
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
|
-
|
|
22
|
+
PoolState.prototype.read = function (l1Token, latestBlock, previousBlock) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
24
|
+
var exchangeRatePrevious, exchangeRateCurrent, pooledToken, liquidityUtilizationCurrent;
|
|
25
|
+
return __generator(this, function (_a) {
|
|
26
|
+
switch (_a.label) {
|
|
27
|
+
case 0: return [4 /*yield*/, this.exchangeRateAtBlock(l1Token, previousBlock || latestBlock - 1)];
|
|
28
|
+
case 1:
|
|
29
|
+
exchangeRatePrevious = _a.sent();
|
|
30
|
+
return [4 /*yield*/, this.contract.callStatic.exchangeRateCurrent(l1Token)];
|
|
31
|
+
case 2:
|
|
32
|
+
exchangeRateCurrent = _a.sent();
|
|
33
|
+
return [4 /*yield*/, this.contract.pooledTokens(l1Token)];
|
|
34
|
+
case 3:
|
|
35
|
+
pooledToken = _a.sent();
|
|
36
|
+
return [4 /*yield*/, this.contract.callStatic.liquidityUtilizationCurrent(l1Token)];
|
|
37
|
+
case 4:
|
|
38
|
+
liquidityUtilizationCurrent = _a.sent();
|
|
39
|
+
return [2 /*return*/, __assign({ address: this.address, l1Token: l1Token, latestBlock: latestBlock, previousBlock: previousBlock, exchangeRatePrevious: exchangeRatePrevious, exchangeRateCurrent: exchangeRateCurrent, liquidityUtilizationCurrent: liquidityUtilizationCurrent }, pooledToken)];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
PoolState.prototype.exchangeRateAtBlock = function (l1Token, blockTag) {
|
|
45
|
+
return this.contract.callStatic.exchangeRateCurrent(l1Token, { blockTag: blockTag });
|
|
46
|
+
};
|
|
47
|
+
return PoolState;
|
|
48
|
+
}());
|
|
49
|
+
var PoolEventState = /** @class */ (function () {
|
|
50
|
+
function PoolEventState(contract, startBlock) {
|
|
51
|
+
if (startBlock === void 0) { startBlock = 0; }
|
|
52
|
+
var _this = this;
|
|
52
53
|
this.contract = contract;
|
|
53
54
|
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
|
+
};
|
|
54
79
|
this.iface = new ethers.utils.Interface(hubPool.Factory.abi);
|
|
55
80
|
}
|
|
56
|
-
|
|
57
|
-
return uma.oracle.utils.eventKey(params);
|
|
58
|
-
};
|
|
59
|
-
hasEvent(params) {
|
|
81
|
+
PoolEventState.prototype.hasEvent = function (params) {
|
|
60
82
|
return this.seen.has(this.makeId(params));
|
|
61
|
-
}
|
|
62
|
-
addEvent(params) {
|
|
83
|
+
};
|
|
84
|
+
PoolEventState.prototype.addEvent = function (params) {
|
|
63
85
|
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
|
-
};
|
|
95
86
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
PoolEventState.prototype.read = function (endBlock, l1TokenAddress, userAddress) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var events, _a, _b, _c, _d;
|
|
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); })
|
|
99
112
|
.map(this.makeEventFromLog);
|
|
100
113
|
// save these events
|
|
101
114
|
this.processEvents(events);
|
|
102
115
|
// only process token receipt events, because we just want the l1 token involved with this transfer
|
|
103
|
-
|
|
116
|
+
var eventState = hubPool.getEventState(events);
|
|
104
117
|
// event state is keyed by l1token address
|
|
105
|
-
|
|
118
|
+
var l1Tokens = Object.keys(eventState);
|
|
106
119
|
assert(l1Tokens.length, "Token not found from events");
|
|
107
120
|
assert(l1Tokens.length === 1, "Multiple tokens found from events");
|
|
108
121
|
return l1Tokens[0];
|
|
109
|
-
}
|
|
110
|
-
readTxReceipt(receipt) {
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
};
|
|
123
|
+
PoolEventState.prototype.readTxReceipt = function (receipt) {
|
|
124
|
+
var _this = this;
|
|
125
|
+
var events = receipt.logs
|
|
126
|
+
.filter(function (log) { return ethers.utils.getAddress(log.address) === ethers.utils.getAddress(_this.contract.address); })
|
|
113
127
|
.map(this.makeEventFromLog);
|
|
114
128
|
this.processEvents(events);
|
|
115
129
|
return hubPool.getEventState(this.events);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
startBlock
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
constructor(contract, userAddress, startBlock = 0, acceleratingDistributorContractAddress = "") {
|
|
130
|
+
};
|
|
131
|
+
return PoolEventState;
|
|
132
|
+
}());
|
|
133
|
+
export { PoolEventState };
|
|
134
|
+
var UserState = /** @class */ (function () {
|
|
135
|
+
function UserState(contract, userAddress, startBlock, acceleratingDistributorContractAddress) {
|
|
136
|
+
if (startBlock === void 0) { startBlock = 0; }
|
|
137
|
+
if (acceleratingDistributorContractAddress === void 0) { acceleratingDistributorContractAddress = ""; }
|
|
138
|
+
var _this = this;
|
|
126
139
|
this.contract = contract;
|
|
127
140
|
this.userAddress = userAddress;
|
|
128
141
|
this.startBlock = startBlock;
|
|
129
142
|
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
|
+
};
|
|
130
151
|
}
|
|
131
|
-
makeId(params) {
|
|
152
|
+
UserState.prototype.makeId = function (params) {
|
|
132
153
|
return uma.oracle.utils.eventKey(params);
|
|
133
|
-
}
|
|
134
|
-
hasEvent(params) {
|
|
154
|
+
};
|
|
155
|
+
UserState.prototype.hasEvent = function (params) {
|
|
135
156
|
return this.seen.has(this.makeId(params));
|
|
136
|
-
}
|
|
137
|
-
addEvent(params) {
|
|
157
|
+
};
|
|
158
|
+
UserState.prototype.addEvent = function (params) {
|
|
138
159
|
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;
|
|
145
160
|
};
|
|
146
161
|
/**
|
|
147
162
|
* readEvents. Fetch and cache events for the user.
|
|
148
163
|
*
|
|
149
164
|
* @param {number} endBlock
|
|
150
165
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
166
|
+
UserState.prototype.readEvents = function (endBlock) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
var userAddress, events, _a, _b, _c, _d;
|
|
169
|
+
var _this = this;
|
|
170
|
+
return __generator(this, function (_e) {
|
|
171
|
+
switch (_e.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
if (endBlock <= this.startBlock)
|
|
174
|
+
return [2 /*return*/, []];
|
|
175
|
+
userAddress = this.userAddress;
|
|
176
|
+
_b = (_a = Promise).all;
|
|
177
|
+
_c = [[]];
|
|
178
|
+
return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.Transfer(userAddress, undefined), this.startBlock, endBlock)];
|
|
179
|
+
case 1:
|
|
180
|
+
_d = [__spreadArray.apply(void 0, _c.concat([(_e.sent()), true]))];
|
|
181
|
+
return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.Transfer(undefined, userAddress), this.startBlock, endBlock)];
|
|
182
|
+
case 2: return [4 /*yield*/, _b.apply(_a, [__spreadArray.apply(void 0, _d.concat([(_e.sent()), true]))])];
|
|
183
|
+
case 3:
|
|
184
|
+
events = (_e.sent())
|
|
185
|
+
// filter out events we have seen
|
|
186
|
+
.filter(this.filterSeen)
|
|
187
|
+
// filter out mint/burn transfers
|
|
188
|
+
.filter(function (event) {
|
|
189
|
+
// ignore mint events
|
|
190
|
+
return event.args.from !== AddressZero &&
|
|
191
|
+
// ignore burn events
|
|
192
|
+
event.args.to !== AddressZero &&
|
|
193
|
+
// ignore AD transfer events in
|
|
194
|
+
event.args.to !== _this.acceleratingDistributorContractAddress &&
|
|
195
|
+
// ignore AD transfer events out
|
|
196
|
+
event.args.from !== _this.acceleratingDistributorContractAddress &&
|
|
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
|
+
});
|
|
182
215
|
});
|
|
183
|
-
|
|
184
|
-
this.startBlock = endBlock + 1;
|
|
185
|
-
return this.events;
|
|
186
|
-
}
|
|
216
|
+
};
|
|
187
217
|
/**
|
|
188
218
|
* read. Reads the state for the user, building state from events as well as contract calls.
|
|
189
219
|
*
|
|
190
220
|
* @param {number} endBlock
|
|
191
221
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
222
|
+
UserState.prototype.read = function (endBlock) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var userAddress, transferEvents, state, balanceTransferred;
|
|
225
|
+
var _a;
|
|
226
|
+
var _b;
|
|
227
|
+
return __generator(this, function (_c) {
|
|
228
|
+
switch (_c.label) {
|
|
229
|
+
case 0:
|
|
230
|
+
userAddress = this.userAddress;
|
|
231
|
+
return [4 /*yield*/, this.readEvents(endBlock)];
|
|
232
|
+
case 1:
|
|
233
|
+
transferEvents = _c.sent();
|
|
234
|
+
state = uma.clients.erc20.getEventState(transferEvents);
|
|
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
|
+
}());
|
|
205
250
|
export function calculateRemoval(amountWei, percentWei) {
|
|
206
|
-
|
|
207
|
-
|
|
251
|
+
var receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
|
|
252
|
+
var remain = amountWei.sub(receive);
|
|
208
253
|
return {
|
|
209
254
|
receive: receive.toString(),
|
|
210
255
|
remain: remain.toString(),
|
|
@@ -212,25 +257,22 @@ export function calculateRemoval(amountWei, percentWei) {
|
|
|
212
257
|
}
|
|
213
258
|
// params here mimic the user object type
|
|
214
259
|
export function previewRemoval(values, percentFloat) {
|
|
215
|
-
|
|
260
|
+
var percentWei = toBNWei(percentFloat);
|
|
216
261
|
return {
|
|
217
|
-
position: {
|
|
218
|
-
|
|
219
|
-
},
|
|
220
|
-
fees: {
|
|
221
|
-
...calculateRemoval(BigNumber.from(values.feesEarned), percentWei),
|
|
222
|
-
},
|
|
223
|
-
total: {
|
|
224
|
-
...calculateRemoval(BigNumber.from(values.positionValue), percentWei),
|
|
225
|
-
},
|
|
262
|
+
position: __assign({}, calculateRemoval(BigNumber.from(values.totalDeposited), percentWei)),
|
|
263
|
+
fees: __assign({}, calculateRemoval(BigNumber.from(values.feesEarned), percentWei)),
|
|
264
|
+
total: __assign({}, calculateRemoval(BigNumber.from(values.positionValue), percentWei)),
|
|
226
265
|
};
|
|
227
266
|
}
|
|
228
|
-
function joinUserState(poolState, tokenEventState, userState, transferValue
|
|
229
|
-
|
|
267
|
+
function joinUserState(poolState, tokenEventState, userState, transferValue, cumulativeStakeBalance, cumulativeStakeClaimBalance) {
|
|
268
|
+
if (transferValue === void 0) { transferValue = bnZero; }
|
|
269
|
+
if (cumulativeStakeBalance === void 0) { cumulativeStakeBalance = bnZero; }
|
|
270
|
+
if (cumulativeStakeClaimBalance === void 0) { cumulativeStakeClaimBalance = bnZero; }
|
|
271
|
+
var positionValue = BigNumber.from(poolState.exchangeRateCurrent)
|
|
230
272
|
.mul(userState.balanceOf.add(cumulativeStakeBalance))
|
|
231
273
|
.div(fixedPointAdjustment);
|
|
232
|
-
|
|
233
|
-
|
|
274
|
+
var totalDeposited = BigNumber.from((tokenEventState === null || tokenEventState === void 0 ? void 0 : tokenEventState.tokenBalances[userState.address]) || "0").add(cumulativeStakeClaimBalance);
|
|
275
|
+
var feesEarned = positionValue.sub(totalDeposited.add(transferValue));
|
|
234
276
|
return {
|
|
235
277
|
address: userState.address,
|
|
236
278
|
poolAddress: poolState.address,
|
|
@@ -241,15 +283,15 @@ function joinUserState(poolState, tokenEventState, userState, transferValue = bn
|
|
|
241
283
|
};
|
|
242
284
|
}
|
|
243
285
|
function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
286
|
+
var totalPoolSize = poolState.liquidReserves.add(poolState.utilizedReserves);
|
|
287
|
+
var secondsElapsed = latestBlock.timestamp - previousBlock.timestamp;
|
|
288
|
+
var blocksElapsed = latestBlock.number - previousBlock.number;
|
|
289
|
+
var exchangeRatePrevious = poolState.exchangeRatePrevious.toString();
|
|
290
|
+
var exchangeRateCurrent = poolState.exchangeRateCurrent.toString();
|
|
291
|
+
var liquidityUtilizationCurrent = poolState.liquidityUtilizationCurrent.toString();
|
|
292
|
+
var estimatedApy = calcPeriodicCompoundInterest(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
|
|
293
|
+
var estimatedApr = calcApr(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
|
|
294
|
+
var projectedApr = "";
|
|
253
295
|
if (rateModel) {
|
|
254
296
|
projectedApr = fromWei(calculateInstantaneousRate(rateModel, liquidityUtilizationCurrent)
|
|
255
297
|
.mul(liquidityUtilizationCurrent)
|
|
@@ -263,55 +305,45 @@ function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
|
|
|
263
305
|
liquidReserves: poolState.liquidReserves.toString(),
|
|
264
306
|
exchangeRateCurrent: poolState.exchangeRateCurrent.toString(),
|
|
265
307
|
exchangeRatePrevious: poolState.exchangeRatePrevious.toString(),
|
|
266
|
-
estimatedApy,
|
|
267
|
-
estimatedApr,
|
|
268
|
-
blocksElapsed,
|
|
269
|
-
secondsElapsed,
|
|
270
|
-
projectedApr,
|
|
308
|
+
estimatedApy: estimatedApy,
|
|
309
|
+
estimatedApr: estimatedApr,
|
|
310
|
+
blocksElapsed: blocksElapsed,
|
|
311
|
+
secondsElapsed: secondsElapsed,
|
|
312
|
+
projectedApr: projectedApr,
|
|
271
313
|
utilizedReserves: poolState.utilizedReserves.toString(),
|
|
272
|
-
liquidityUtilizationCurrent,
|
|
314
|
+
liquidityUtilizationCurrent: liquidityUtilizationCurrent,
|
|
273
315
|
};
|
|
274
316
|
}
|
|
275
|
-
|
|
276
|
-
address
|
|
277
|
-
provider;
|
|
278
|
-
poolState;
|
|
279
|
-
contract;
|
|
280
|
-
constructor(address, provider) {
|
|
317
|
+
var ReadPoolClient = /** @class */ (function () {
|
|
318
|
+
function ReadPoolClient(address, provider) {
|
|
281
319
|
this.address = address;
|
|
282
320
|
this.provider = provider;
|
|
283
321
|
this.contract = hubPool.connect(address, this.provider);
|
|
284
322
|
this.poolState = new PoolState(this.contract, this.address);
|
|
285
323
|
}
|
|
286
|
-
read(tokenAddress, latestBlock) {
|
|
324
|
+
ReadPoolClient.prototype.read = function (tokenAddress, latestBlock) {
|
|
287
325
|
return this.poolState.read(tokenAddress, latestBlock);
|
|
288
|
-
}
|
|
289
|
-
|
|
326
|
+
};
|
|
327
|
+
return ReadPoolClient;
|
|
328
|
+
}());
|
|
329
|
+
export { ReadPoolClient };
|
|
290
330
|
export function validateWithdraw(pool, user, lpTokenAmount) {
|
|
291
|
-
|
|
331
|
+
var l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
|
|
292
332
|
assert(BigNumber.from(l1TokensToReturn).gt("0"), "Must withdraw amount greater than 0");
|
|
293
333
|
assert(BigNumber.from(lpTokenAmount).lte(user.lpTokens), "You cannot withdraw more than you have");
|
|
294
|
-
return { lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
|
|
334
|
+
return { lpTokenAmount: lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
|
|
295
335
|
}
|
|
296
|
-
|
|
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) {
|
|
336
|
+
var Client = /** @class */ (function () {
|
|
337
|
+
function Client(config, deps, emit) {
|
|
312
338
|
this.config = config;
|
|
313
339
|
this.deps = deps;
|
|
314
340
|
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 = {};
|
|
315
347
|
config.chainId = config.chainId || 1;
|
|
316
348
|
this.hubPool = this.createHubPoolContract(deps.provider);
|
|
317
349
|
this.acceleratingDistributor = this.createAcceleratingDistributorContract(deps.provider);
|
|
@@ -319,320 +351,549 @@ export class Client {
|
|
|
319
351
|
this.poolEvents = new PoolEventState(this.hubPool, this.config.hubPoolStartBlock);
|
|
320
352
|
this.configStoreClient = new acrossConfigStore.Client(config.configStoreAddress, deps.provider);
|
|
321
353
|
}
|
|
322
|
-
getOrCreateErc20Contract(address) {
|
|
354
|
+
Client.prototype.getOrCreateErc20Contract = function (address) {
|
|
323
355
|
if (this.erc20s[address])
|
|
324
356
|
return this.erc20s[address];
|
|
325
357
|
this.erc20s[address] = erc20.connect(address, this.deps.provider);
|
|
326
358
|
return this.erc20s[address];
|
|
327
|
-
}
|
|
328
|
-
getOrCreatePoolContract() {
|
|
359
|
+
};
|
|
360
|
+
Client.prototype.getOrCreatePoolContract = function () {
|
|
329
361
|
return this.hubPool;
|
|
330
|
-
}
|
|
331
|
-
createHubPoolContract(signerOrProvider) {
|
|
362
|
+
};
|
|
363
|
+
Client.prototype.createHubPoolContract = function (signerOrProvider) {
|
|
332
364
|
return hubPool.connect(this.config.hubPoolAddress, signerOrProvider);
|
|
333
|
-
}
|
|
334
|
-
getOrCreatePoolEvents() {
|
|
365
|
+
};
|
|
366
|
+
Client.prototype.getOrCreatePoolEvents = function () {
|
|
335
367
|
return this.poolEvents;
|
|
336
|
-
}
|
|
337
|
-
createAcceleratingDistributorContract(signerOrProvider) {
|
|
368
|
+
};
|
|
369
|
+
Client.prototype.createAcceleratingDistributorContract = function (signerOrProvider) {
|
|
338
370
|
return AcceleratingDistributor__factory.connect(this.config.acceleratingDistributorAddress, signerOrProvider);
|
|
339
|
-
}
|
|
340
|
-
createMerkleDistributorContract(signerOrProvider) {
|
|
371
|
+
};
|
|
372
|
+
Client.prototype.createMerkleDistributorContract = function (signerOrProvider) {
|
|
341
373
|
return MerkleDistributor__factory.connect(this.config.merkleDistributorAddress, signerOrProvider);
|
|
342
|
-
}
|
|
343
|
-
getOrCreateAcceleratingDistributorContract() {
|
|
374
|
+
};
|
|
375
|
+
Client.prototype.getOrCreateAcceleratingDistributorContract = function () {
|
|
344
376
|
return this.acceleratingDistributor;
|
|
345
|
-
}
|
|
346
|
-
getOrCreateMerkleDistributorContract() {
|
|
377
|
+
};
|
|
378
|
+
Client.prototype.getOrCreateMerkleDistributorContract = function () {
|
|
347
379
|
return this.merkleDistributor;
|
|
348
|
-
}
|
|
349
|
-
getOrCreateUserService(userAddress, tokenAddress) {
|
|
380
|
+
};
|
|
381
|
+
Client.prototype.getOrCreateUserService = function (userAddress, tokenAddress) {
|
|
350
382
|
if (has(this.userServices, [tokenAddress, userAddress]))
|
|
351
383
|
return get(this.userServices, [tokenAddress, userAddress]);
|
|
352
|
-
|
|
353
|
-
|
|
384
|
+
var erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
|
|
385
|
+
var userService = new UserState(erc20Contract, userAddress);
|
|
354
386
|
// this service is stateful now, so needs to be cached
|
|
355
387
|
set(this.userServices, [tokenAddress, userAddress], userService);
|
|
356
388
|
return userService;
|
|
357
|
-
}
|
|
358
|
-
updateExchangeRateTable(l1TokenAddress, exchangeRateTable) {
|
|
389
|
+
};
|
|
390
|
+
Client.prototype.updateExchangeRateTable = function (l1TokenAddress, exchangeRateTable) {
|
|
359
391
|
if (!this.exchangeRateTable[l1TokenAddress])
|
|
360
392
|
this.exchangeRateTable[l1TokenAddress] = {};
|
|
361
|
-
this.exchangeRateTable[l1TokenAddress] = {
|
|
393
|
+
this.exchangeRateTable[l1TokenAddress] = __assign(__assign({}, this.exchangeRateTable[l1TokenAddress]), exchangeRateTable);
|
|
362
394
|
return this.exchangeRateTable[l1TokenAddress];
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
395
|
+
};
|
|
396
|
+
Client.prototype.resolveStakingData = function (lpToken, l1TokenAddress, userState) {
|
|
397
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
+
var acceleratingDistributorContract, merkleDistributorContract, poolContract, claimList, amountOfLPClaimed, cumulativeBalance;
|
|
399
|
+
var _this = this;
|
|
400
|
+
return __generator(this, function (_a) {
|
|
401
|
+
switch (_a.label) {
|
|
402
|
+
case 0:
|
|
403
|
+
assert(this.config.acceleratingDistributorAddress, "Must have the accelerating distributor address");
|
|
404
|
+
assert(this.config.merkleDistributorAddress, "Must have the merkle distributor address");
|
|
405
|
+
acceleratingDistributorContract = this.getOrCreateAcceleratingDistributorContract();
|
|
406
|
+
merkleDistributorContract = this.getOrCreateMerkleDistributorContract();
|
|
407
|
+
poolContract = this.getOrCreatePoolContract();
|
|
408
|
+
return [4 /*yield*/, merkleDistributorContract.queryFilter(merkleDistributorContract.filters.Claimed(undefined, undefined, userState.address, undefined, undefined, lpToken))];
|
|
409
|
+
case 1:
|
|
410
|
+
claimList = _a.sent();
|
|
411
|
+
return [4 /*yield*/, Promise.all(claimList.map(function (claim) { return __awaiter(_this, void 0, void 0, function () {
|
|
412
|
+
var _a, _b;
|
|
413
|
+
return __generator(this, function (_c) {
|
|
414
|
+
switch (_c.label) {
|
|
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
|
+
};
|
|
383
435
|
// calculates the value of each LP token transfer at the block it was sent. this only works if we have archive node
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
436
|
+
Client.prototype.calculateLpTransferValue = function (l1TokenAddress, userState) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
+
var contract, pool, blockNumbers, exchangeRateTable, _a, _b, _c, _d;
|
|
439
|
+
var _this = this;
|
|
440
|
+
return __generator(this, function (_e) {
|
|
441
|
+
switch (_e.label) {
|
|
442
|
+
case 0:
|
|
443
|
+
assert(this.config.hasArchive, "Can only calculate historical lp values with archive node");
|
|
444
|
+
contract = this.getOrCreatePoolContract();
|
|
445
|
+
pool = new PoolState(contract, this.config.hubPoolAddress);
|
|
446
|
+
blockNumbers = userState.transferEvents
|
|
447
|
+
.map(function (x) { return x.blockNumber; })
|
|
448
|
+
// we are going to lookup exchange rates for block numbers only if we dont already have it
|
|
449
|
+
// its possible these values do not exist, so to prevent crashing do optional chaining
|
|
450
|
+
.filter(function (blockNumber) { var _a, _b; return !((_b = (_a = _this.exchangeRateTable) === null || _a === void 0 ? void 0 : _a[l1TokenAddress]) === null || _b === void 0 ? void 0 : _b[blockNumber]); });
|
|
451
|
+
_a = this.updateExchangeRateTable;
|
|
452
|
+
_b = [l1TokenAddress];
|
|
453
|
+
_d = (_c = Object).fromEntries;
|
|
454
|
+
return [4 /*yield*/, Promise.all(blockNumbers.map(function (blockNumber) { return __awaiter(_this, void 0, void 0, function () {
|
|
455
|
+
var _a;
|
|
456
|
+
return __generator(this, function (_b) {
|
|
457
|
+
switch (_b.label) {
|
|
458
|
+
case 0:
|
|
459
|
+
_a = [blockNumber];
|
|
460
|
+
return [4 /*yield*/, pool.exchangeRateAtBlock(l1TokenAddress, blockNumber)];
|
|
461
|
+
case 1: return [2 /*return*/, _a.concat([_b.sent()])];
|
|
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;
|
|
410
484
|
if (this.transactionManagers[address])
|
|
411
485
|
return this.transactionManagers[address];
|
|
412
|
-
|
|
486
|
+
var txman = TransactionManager({ confirmations: this.config.confirmations }, signer, function (event, id, data) {
|
|
413
487
|
if (event === "submitted") {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
488
|
+
_this.state.transactions[id].state = event;
|
|
489
|
+
_this.state.transactions[id].hash = data;
|
|
490
|
+
_this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
|
|
417
491
|
}
|
|
418
492
|
if (event === "mined") {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
493
|
+
var txReceipt = data;
|
|
494
|
+
_this.state.transactions[id].state = event;
|
|
495
|
+
_this.state.transactions[id].receipt = txReceipt;
|
|
496
|
+
_this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
|
|
423
497
|
// trigger pool and user update for a known mined transaction
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
498
|
+
var tx = _this.state.transactions[id];
|
|
499
|
+
_this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch(function (err) {
|
|
500
|
+
_this.emit(["error"], err);
|
|
427
501
|
});
|
|
428
502
|
}
|
|
429
503
|
if (event === "error") {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
504
|
+
_this.state.transactions[id].state = event;
|
|
505
|
+
_this.state.transactions[id].error = data;
|
|
506
|
+
_this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
|
|
433
507
|
}
|
|
434
508
|
});
|
|
435
509
|
this.transactionManagers[address] = txman;
|
|
436
510
|
return txman;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
511
|
+
};
|
|
512
|
+
Client.prototype.addEthLiquidity = function (signer_1, l1TokenAmount_1) {
|
|
513
|
+
return __awaiter(this, arguments, void 0, function (signer, l1TokenAmount, overrides) {
|
|
514
|
+
var _a, hubPoolAddress, l1Token, userAddress, contract, txman, request, id;
|
|
515
|
+
if (overrides === void 0) { overrides = {}; }
|
|
516
|
+
return __generator(this, function (_b) {
|
|
517
|
+
switch (_b.label) {
|
|
518
|
+
case 0:
|
|
519
|
+
_a = this.config, hubPoolAddress = _a.hubPoolAddress, l1Token = _a.wethAddress;
|
|
520
|
+
return [4 /*yield*/, signer.getAddress()];
|
|
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
|
+
});
|
|
447
545
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
this
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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
|
+
});
|
|
683
|
+
});
|
|
684
|
+
};
|
|
685
|
+
Client.prototype.getPoolState = function (l1TokenAddress) {
|
|
534
686
|
return this.state.pools[l1TokenAddress];
|
|
535
|
-
}
|
|
536
|
-
hasPoolState(l1TokenAddress) {
|
|
687
|
+
};
|
|
688
|
+
Client.prototype.hasPoolState = function (l1TokenAddress) {
|
|
537
689
|
return Boolean(this.state.pools[l1TokenAddress]);
|
|
538
|
-
}
|
|
539
|
-
setUserState(l1TokenAddress, userAddress, state) {
|
|
690
|
+
};
|
|
691
|
+
Client.prototype.setUserState = function (l1TokenAddress, userAddress, state) {
|
|
540
692
|
set(this.state, ["users", userAddress, l1TokenAddress], state);
|
|
541
693
|
return state;
|
|
542
|
-
}
|
|
543
|
-
getUserState(l1TokenAddress, userAddress) {
|
|
694
|
+
};
|
|
695
|
+
Client.prototype.getUserState = function (l1TokenAddress, userAddress) {
|
|
544
696
|
return get(this.state, ["users", userAddress, l1TokenAddress]);
|
|
545
|
-
}
|
|
546
|
-
hasUserState(l1TokenAddress, userAddress) {
|
|
697
|
+
};
|
|
698
|
+
Client.prototype.hasUserState = function (l1TokenAddress, userAddress) {
|
|
547
699
|
return has(this.state, ["users", userAddress, l1TokenAddress]);
|
|
548
|
-
}
|
|
549
|
-
hasTxState(id) {
|
|
700
|
+
};
|
|
701
|
+
Client.prototype.hasTxState = function (id) {
|
|
550
702
|
return has(this.state, ["transactions", id]);
|
|
551
|
-
}
|
|
552
|
-
getTxState(id) {
|
|
703
|
+
};
|
|
704
|
+
Client.prototype.getTxState = function (id) {
|
|
553
705
|
return get(this.state, ["transactions", id]);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
706
|
+
};
|
|
707
|
+
Client.prototype.updateAndEmitUser = function (userState, poolState, poolEventState) {
|
|
708
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
709
|
+
var l1TokenAddress, lpToken, userAddress, transferValue, _a, stakeData, tokenEventState, newUserState;
|
|
710
|
+
return __generator(this, function (_b) {
|
|
711
|
+
switch (_b.label) {
|
|
712
|
+
case 0:
|
|
713
|
+
l1TokenAddress = poolState.l1Token, lpToken = poolState.lpToken;
|
|
714
|
+
userAddress = userState.address;
|
|
715
|
+
if (!this.config.hasArchive) return [3 /*break*/, 2];
|
|
716
|
+
return [4 /*yield*/, this.calculateLpTransferValue(l1TokenAddress, userState)];
|
|
717
|
+
case 1:
|
|
718
|
+
_a = _b.sent();
|
|
719
|
+
return [3 /*break*/, 3];
|
|
720
|
+
case 2:
|
|
721
|
+
_a = bnZero;
|
|
722
|
+
_b.label = 3;
|
|
723
|
+
case 3:
|
|
724
|
+
transferValue = _a;
|
|
725
|
+
return [4 /*yield*/, this.resolveStakingData(lpToken, l1TokenAddress, userState)];
|
|
726
|
+
case 4:
|
|
727
|
+
stakeData = _b.sent();
|
|
728
|
+
tokenEventState = poolEventState[l1TokenAddress];
|
|
729
|
+
newUserState = this.setUserState(l1TokenAddress, userAddress, joinUserState(poolState, tokenEventState, userState, transferValue, stakeData.cumulativeBalance, stakeData.amountAirdropped));
|
|
730
|
+
this.emit(["users", userAddress, l1TokenAddress], newUserState);
|
|
731
|
+
return [2 /*return*/];
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
Client.prototype.updateUserWithTransaction = function (userAddress, txReceipt) {
|
|
737
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
738
|
+
var latestBlock, getPoolEventState, l1TokenAddress, poolState, poolEventState, lpToken, getUserState, userState;
|
|
739
|
+
return __generator(this, function (_a) {
|
|
740
|
+
switch (_a.label) {
|
|
741
|
+
case 0: return [4 /*yield*/, this.deps.provider.getBlock("latest")];
|
|
742
|
+
case 1:
|
|
743
|
+
latestBlock = _a.sent();
|
|
744
|
+
getPoolEventState = this.getOrCreatePoolEvents();
|
|
745
|
+
l1TokenAddress = getPoolEventState.getL1TokenFromReceipt(txReceipt);
|
|
746
|
+
return [4 /*yield*/, this.updatePool(l1TokenAddress, latestBlock)];
|
|
747
|
+
case 2:
|
|
748
|
+
_a.sent();
|
|
749
|
+
poolState = this.getPoolState(l1TokenAddress);
|
|
750
|
+
poolEventState = getPoolEventState.readTxReceipt(txReceipt);
|
|
751
|
+
lpToken = poolState.lpToken;
|
|
752
|
+
getUserState = this.getOrCreateUserService(userAddress, lpToken);
|
|
753
|
+
return [4 /*yield*/, getUserState.read(latestBlock.number)];
|
|
754
|
+
case 3:
|
|
755
|
+
userState = _a.sent();
|
|
756
|
+
return [4 /*yield*/, this.updateAndEmitUser(userState, poolState, poolEventState)];
|
|
757
|
+
case 4:
|
|
758
|
+
_a.sent();
|
|
759
|
+
return [2 /*return*/];
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
};
|
|
764
|
+
Client.prototype.updateUser = function (userAddress, l1TokenAddress) {
|
|
765
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
766
|
+
var latestBlock, poolState, lpToken, getPoolEventState, poolEventState, getUserState, userState;
|
|
767
|
+
return __generator(this, function (_a) {
|
|
768
|
+
switch (_a.label) {
|
|
769
|
+
case 0: return [4 /*yield*/, this.deps.provider.getBlock("latest")];
|
|
770
|
+
case 1:
|
|
771
|
+
latestBlock = _a.sent();
|
|
772
|
+
return [4 /*yield*/, this.updatePool(l1TokenAddress, latestBlock)];
|
|
773
|
+
case 2:
|
|
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
|
+
};
|
|
622
871
|
// starts transaction checking intervals, defaults to 30 seconds
|
|
623
|
-
startInterval
|
|
872
|
+
Client.prototype.startInterval = function (delayMs) {
|
|
873
|
+
var _this = this;
|
|
874
|
+
if (delayMs === void 0) { delayMs = 30000; }
|
|
624
875
|
assert(!this.intervalStarted, "Interval already started, try stopping first");
|
|
625
876
|
this.intervalStarted = true;
|
|
626
|
-
loop(
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
877
|
+
loop(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
878
|
+
return __generator(this, function (_a) {
|
|
879
|
+
switch (_a.label) {
|
|
880
|
+
case 0:
|
|
881
|
+
assert(this.intervalStarted, "HubPool Interval Stopped");
|
|
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);
|
|
631
890
|
});
|
|
632
|
-
}
|
|
891
|
+
};
|
|
633
892
|
// starts transaction checking intervals
|
|
634
|
-
stopInterval() {
|
|
893
|
+
Client.prototype.stopInterval = function () {
|
|
635
894
|
this.intervalStarted = false;
|
|
636
|
-
}
|
|
637
|
-
|
|
895
|
+
};
|
|
896
|
+
return Client;
|
|
897
|
+
}());
|
|
898
|
+
export { Client };
|
|
638
899
|
//# sourceMappingURL=poolClient.js.map
|