@across-protocol/sdk 4.3.111-alpha.0 → 4.3.111-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/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 -30
- 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 -104
- 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 -115
- package/dist/cjs/utils/Multicall.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.js +12 -28
- 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 -47
- 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 -96
- 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 -110
- package/dist/esm/utils/Multicall.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.js +12 -28
- 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/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 +2 -2
- package/src/constants.ts +0 -1
- package/src/gasPriceOracle/oracle.ts +0 -1
- package/src/utils/Multicall.ts +0 -1
- package/src/utils/NetworkUtils.ts +1 -8
|
@@ -2,411 +2,284 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Coingecko = void 0;
|
|
4
4
|
exports.msToS = msToS;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
7
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
8
|
+
const lodash_get_1 = tslib_1.__importDefault(require("lodash.get"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
10
|
function msToS(ms) {
|
|
11
11
|
return Math.floor(ms / 1000);
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
class Coingecko {
|
|
14
|
+
host;
|
|
15
|
+
proHost;
|
|
16
|
+
logger;
|
|
17
|
+
apiKey;
|
|
18
|
+
customPlatformIdMap;
|
|
19
|
+
static instance;
|
|
20
|
+
prices;
|
|
21
|
+
pricesBySymbol;
|
|
22
|
+
_maxPriceAge = 300;
|
|
23
|
+
retryDelay = 1;
|
|
24
|
+
numRetries = 0;
|
|
25
|
+
basicApiTimeout = 500;
|
|
26
|
+
platformIdMap = new Map();
|
|
27
|
+
tokenIdMap = {};
|
|
28
|
+
static get(logger, apiKey, customPlatformIdMap) {
|
|
29
|
+
if (!this.instance)
|
|
30
|
+
this.instance = new Coingecko("https://api.coingecko.com/api/v3", "https://pro-api.coingecko.com/api/v3", logger, apiKey, customPlatformIdMap);
|
|
31
|
+
return this.instance;
|
|
32
|
+
}
|
|
33
|
+
get maxPriceAge() {
|
|
34
|
+
return this._maxPriceAge;
|
|
35
|
+
}
|
|
36
|
+
set maxPriceAge(age) {
|
|
37
|
+
(0, assert_1.default)(age >= 0);
|
|
38
|
+
this.logger.debug({
|
|
39
|
+
at: "Coingecko#maxPriceAge",
|
|
40
|
+
message: `Setting maxPriceAge (S) ${this._maxPriceAge} => ${age}.`,
|
|
41
|
+
});
|
|
42
|
+
this._maxPriceAge = age;
|
|
43
|
+
}
|
|
44
|
+
constructor(host, proHost, logger, apiKey, customPlatformIdMap) {
|
|
15
45
|
this.host = host;
|
|
16
46
|
this.proHost = proHost;
|
|
17
47
|
this.logger = logger;
|
|
18
48
|
this.apiKey = apiKey;
|
|
19
49
|
this.customPlatformIdMap = customPlatformIdMap;
|
|
20
|
-
this._maxPriceAge = 300;
|
|
21
|
-
this.retryDelay = 1;
|
|
22
|
-
this.numRetries = 0;
|
|
23
|
-
this.basicApiTimeout = 500;
|
|
24
|
-
this.platformIdMap = new Map();
|
|
25
|
-
this.tokenIdMap = {};
|
|
26
50
|
this.prices = {};
|
|
27
51
|
this.pricesBySymbol = {};
|
|
28
52
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(0, assert_1.default)(age >= 0);
|
|
40
|
-
this.logger.debug({
|
|
41
|
-
at: "Coingecko#maxPriceAge",
|
|
42
|
-
message: "Setting maxPriceAge (S) ".concat(this._maxPriceAge, " => ").concat(age, "."),
|
|
43
|
-
});
|
|
44
|
-
this._maxPriceAge = age;
|
|
45
|
-
},
|
|
46
|
-
enumerable: false,
|
|
47
|
-
configurable: true
|
|
48
|
-
});
|
|
49
|
-
Coingecko.prototype.getPlatformId = function (chainId) {
|
|
50
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var id, platforms;
|
|
52
|
-
var _this = this;
|
|
53
|
-
return tslib_1.__generator(this, function (_a) {
|
|
54
|
-
switch (_a.label) {
|
|
55
|
-
case 0:
|
|
56
|
-
id = this.platformIdMap.get(chainId);
|
|
57
|
-
if (id) {
|
|
58
|
-
return [2, id];
|
|
59
|
-
}
|
|
60
|
-
return [4, this.getPlatforms()];
|
|
61
|
-
case 1:
|
|
62
|
-
platforms = _a.sent();
|
|
63
|
-
this.platformIdMap = new Map(platforms.filter(function (chain) { return Boolean(chain.chain_identifier); }).map(function (chain) { return [chain.chain_identifier, chain.id]; }));
|
|
64
|
-
if (this.customPlatformIdMap) {
|
|
65
|
-
Object.entries(this.customPlatformIdMap).forEach(function (_a) {
|
|
66
|
-
var chainId = _a[0], platformId = _a[1];
|
|
67
|
-
_this.platformIdMap.set(Number(chainId), platformId);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
id = this.platformIdMap.get(chainId);
|
|
71
|
-
if (!id) {
|
|
72
|
-
this.logger.error({
|
|
73
|
-
message: "Coingecko does not support chain with id ".concat(chainId),
|
|
74
|
-
at: "Coingecko#getPlatformId",
|
|
75
|
-
});
|
|
76
|
-
throw new Error("Coingecko does not support chain with id ".concat(chainId));
|
|
77
|
-
}
|
|
78
|
-
return [2, id];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
Coingecko.prototype.getCoingeckoTokenId = function (address, chainId) {
|
|
84
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var id, platformId, message;
|
|
86
|
-
return tslib_1.__generator(this, function (_a) {
|
|
87
|
-
switch (_a.label) {
|
|
88
|
-
case 0:
|
|
89
|
-
try {
|
|
90
|
-
id = (0, utils_1.getCoingeckoTokenIdByAddress)(address, chainId);
|
|
91
|
-
return [2, id];
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
this.logger.warn({
|
|
95
|
-
at: "Coingecko#getCoingeckoTokenIdByAddress",
|
|
96
|
-
message: "Token with address ".concat(address, " not found in constants. Attempting to fetch ID from coingecko API..."),
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return [4, this.getPlatformId(chainId)];
|
|
100
|
-
case 1:
|
|
101
|
-
platformId = _a.sent();
|
|
102
|
-
id = this.getTokenIdFromAddress(address, platformId);
|
|
103
|
-
if (id) {
|
|
104
|
-
return [2, id];
|
|
105
|
-
}
|
|
106
|
-
return [4, this.updateTokenMap()];
|
|
107
|
-
case 2:
|
|
108
|
-
_a.sent();
|
|
109
|
-
id = this.getTokenIdFromAddress(address, platformId);
|
|
110
|
-
if (!id) {
|
|
111
|
-
message = "Coin with address ".concat(address, " does not exist on chain with id ").concat(chainId);
|
|
112
|
-
this.logger.error({
|
|
113
|
-
at: "Coingecko#getCoingeckoTokenIdByAddress",
|
|
114
|
-
message: message,
|
|
115
|
-
});
|
|
116
|
-
throw new Error(message);
|
|
117
|
-
}
|
|
118
|
-
return [2, id];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
Coingecko.prototype.getTokenIdFromAddress = function (address, platformId) {
|
|
124
|
-
var _a;
|
|
125
|
-
return (_a = Object.entries(this.tokenIdMap).find(function (_a) {
|
|
126
|
-
var _b;
|
|
127
|
-
var _ = _a[0], value = _a[1];
|
|
128
|
-
return Boolean(((_b = value === null || value === void 0 ? void 0 : value[platformId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === address.toLowerCase());
|
|
129
|
-
})) === null || _a === void 0 ? void 0 : _a[0];
|
|
130
|
-
};
|
|
131
|
-
Coingecko.prototype.updateTokenMap = function () {
|
|
132
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var rawTokenList;
|
|
134
|
-
return tslib_1.__generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0: return [4, this.call("coins/list?include_platform=true")];
|
|
137
|
-
case 1:
|
|
138
|
-
rawTokenList = _a.sent();
|
|
139
|
-
this.tokenIdMap = Object.fromEntries(rawTokenList
|
|
140
|
-
.filter(function (token) { var _a; return Boolean(((_a = Object.values(token === null || token === void 0 ? void 0 : token.platforms)) === null || _a === void 0 ? void 0 : _a.length) > 0); })
|
|
141
|
-
.map(function (token) { return [token.id, token.platforms]; }));
|
|
142
|
-
return [2, this.tokenIdMap];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
Coingecko.prototype.getHistoricContractPrices = function (contract_1, from_1, to_1) {
|
|
148
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (contract, from, to, currency) {
|
|
149
|
-
var _from, _to, result;
|
|
150
|
-
if (currency === void 0) { currency = "usd"; }
|
|
151
|
-
return tslib_1.__generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0:
|
|
154
|
-
(0, assert_1.default)(contract, "requires contract address");
|
|
155
|
-
(0, assert_1.default)(currency, "requires currency symbol");
|
|
156
|
-
(0, assert_1.default)(from, "requires from timestamp");
|
|
157
|
-
(0, assert_1.default)(to, "requires to timestamp");
|
|
158
|
-
_from = msToS(from);
|
|
159
|
-
_to = msToS(to);
|
|
160
|
-
return [4, this.call("coins/ethereum/contract/".concat(contract.toLowerCase(), "/market_chart/range/?vs_currency=").concat(currency, "&from=").concat(_from, "&to=").concat(_to))];
|
|
161
|
-
case 1:
|
|
162
|
-
result = _a.sent();
|
|
163
|
-
if (result.prices)
|
|
164
|
-
return [2, result.prices];
|
|
165
|
-
throw new Error("Something went wrong fetching coingecko prices!");
|
|
166
|
-
}
|
|
53
|
+
async getPlatformId(chainId) {
|
|
54
|
+
let id = this.platformIdMap.get(chainId);
|
|
55
|
+
if (id) {
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
const platforms = await this.getPlatforms();
|
|
59
|
+
this.platformIdMap = new Map(platforms.filter((chain) => Boolean(chain.chain_identifier)).map((chain) => [chain.chain_identifier, chain.id]));
|
|
60
|
+
if (this.customPlatformIdMap) {
|
|
61
|
+
Object.entries(this.customPlatformIdMap).forEach(([chainId, platformId]) => {
|
|
62
|
+
this.platformIdMap.set(Number(chainId), platformId);
|
|
167
63
|
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (currency === void 0) { currency = "usd"; }
|
|
175
|
-
if (chainId === void 0) { chainId = 1; }
|
|
176
|
-
return tslib_1.__generator(this, function (_c) {
|
|
177
|
-
switch (_c.label) {
|
|
178
|
-
case 0: return [4, this.getCoingeckoTokenId(contractAddress, chainId)];
|
|
179
|
-
case 1:
|
|
180
|
-
coingeckoTokenIdentifier = _c.sent();
|
|
181
|
-
(0, assert_1.default)(date, "Requires date string");
|
|
182
|
-
url = "coins/".concat(coingeckoTokenIdentifier, "/history");
|
|
183
|
-
queryParams = {
|
|
184
|
-
date: date,
|
|
185
|
-
localization: "false",
|
|
186
|
-
};
|
|
187
|
-
return [4, this.call("".concat(url, "?").concat(new URLSearchParams(queryParams).toString()))];
|
|
188
|
-
case 2:
|
|
189
|
-
result = _c.sent();
|
|
190
|
-
price = (_b = (_a = result === null || result === void 0 ? void 0 : result.market_data) === null || _a === void 0 ? void 0 : _a.current_price) === null || _b === void 0 ? void 0 : _b[currency];
|
|
191
|
-
(0, assert_1.default)(price, "No price found for ".concat(contractAddress, " on ").concat(date));
|
|
192
|
-
return [2, price];
|
|
193
|
-
}
|
|
64
|
+
}
|
|
65
|
+
id = this.platformIdMap.get(chainId);
|
|
66
|
+
if (!id) {
|
|
67
|
+
this.logger.error({
|
|
68
|
+
message: `Coingecko does not support chain with id ${chainId}`,
|
|
69
|
+
at: "Coingecko#getPlatformId",
|
|
194
70
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
case 1:
|
|
210
|
-
platform_id = _a.sent();
|
|
211
|
-
priceCache = this.getPriceCache(currency, platform_id);
|
|
212
|
-
tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
213
|
-
if (!(tokenPrice === undefined)) return [3, 3];
|
|
214
|
-
return [4, this.getContractPrices([contractAddress], currency, platform_id)];
|
|
215
|
-
case 2:
|
|
216
|
-
_a.sent();
|
|
217
|
-
tokenPrice = priceCache[contractAddress];
|
|
218
|
-
_a.label = 3;
|
|
219
|
-
case 3:
|
|
220
|
-
(0, assert_1.default)(tokenPrice !== undefined);
|
|
221
|
-
return [2, [tokenPrice.timestamp.toString(), tokenPrice.price]];
|
|
222
|
-
}
|
|
71
|
+
throw new Error(`Coingecko does not support chain with id ${chainId}`);
|
|
72
|
+
}
|
|
73
|
+
return id;
|
|
74
|
+
}
|
|
75
|
+
async getCoingeckoTokenId(address, chainId) {
|
|
76
|
+
let id;
|
|
77
|
+
try {
|
|
78
|
+
id = (0, utils_1.getCoingeckoTokenIdByAddress)(address, chainId);
|
|
79
|
+
return id;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.logger.warn({
|
|
83
|
+
at: "Coingecko#getCoingeckoTokenIdByAddress",
|
|
84
|
+
message: `Token with address ${address} not found in constants. Attempting to fetch ID from coingecko API...`,
|
|
223
85
|
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
238
|
-
if (!(tokenPrice === undefined)) return [3, 4];
|
|
239
|
-
return [4, this.getCoingeckoTokenId(contractAddress, chainId)];
|
|
240
|
-
case 2:
|
|
241
|
-
coingeckoId = _a.sent();
|
|
242
|
-
return [4, this.call("simple/price?ids=".concat(coingeckoId, "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
|
|
243
|
-
case 3:
|
|
244
|
-
result = _a.sent();
|
|
245
|
-
cgPrice = result === null || result === void 0 ? void 0 : result[coingeckoId];
|
|
246
|
-
if (cgPrice === undefined || !(cgPrice === null || cgPrice === void 0 ? void 0 : cgPrice[currency])) {
|
|
247
|
-
errMsg = "No price found for ".concat(coingeckoId);
|
|
248
|
-
this.logger.debug({
|
|
249
|
-
at: "Coingecko#getCurrentPriceById",
|
|
250
|
-
message: errMsg,
|
|
251
|
-
});
|
|
252
|
-
throw new Error(errMsg);
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
this.updatePriceCache(cgPrice, contractAddress, currency, platform_id);
|
|
256
|
-
}
|
|
257
|
-
_a.label = 4;
|
|
258
|
-
case 4:
|
|
259
|
-
tokenPrice = priceCache[contractAddress];
|
|
260
|
-
(0, assert_1.default)(tokenPrice !== undefined);
|
|
261
|
-
return [2, [tokenPrice.timestamp.toString(), tokenPrice.price]];
|
|
262
|
-
}
|
|
86
|
+
}
|
|
87
|
+
const platformId = await this.getPlatformId(chainId);
|
|
88
|
+
id = this.getTokenIdFromAddress(address, platformId);
|
|
89
|
+
if (id) {
|
|
90
|
+
return id;
|
|
91
|
+
}
|
|
92
|
+
await this.updateTokenMap();
|
|
93
|
+
id = this.getTokenIdFromAddress(address, platformId);
|
|
94
|
+
if (!id) {
|
|
95
|
+
const message = `Coin with address ${address} does not exist on chain with id ${chainId}`;
|
|
96
|
+
this.logger.error({
|
|
97
|
+
at: "Coingecko#getCoingeckoTokenIdByAddress",
|
|
98
|
+
message,
|
|
263
99
|
});
|
|
100
|
+
throw new Error(message);
|
|
101
|
+
}
|
|
102
|
+
return id;
|
|
103
|
+
}
|
|
104
|
+
getTokenIdFromAddress(address, platformId) {
|
|
105
|
+
return Object.entries(this.tokenIdMap).find(([_, value]) => Boolean(value?.[platformId]?.toLowerCase() === address.toLowerCase()))?.[0];
|
|
106
|
+
}
|
|
107
|
+
async updateTokenMap() {
|
|
108
|
+
const rawTokenList = await this.call("coins/list?include_platform=true");
|
|
109
|
+
this.tokenIdMap = Object.fromEntries(rawTokenList
|
|
110
|
+
.filter((token) => Boolean(Object.values(token?.platforms)?.length > 0))
|
|
111
|
+
.map((token) => [token.id, token.platforms]));
|
|
112
|
+
return this.tokenIdMap;
|
|
113
|
+
}
|
|
114
|
+
async getHistoricContractPrices(contract, from, to, currency = "usd") {
|
|
115
|
+
(0, assert_1.default)(contract, "requires contract address");
|
|
116
|
+
(0, assert_1.default)(currency, "requires currency symbol");
|
|
117
|
+
(0, assert_1.default)(from, "requires from timestamp");
|
|
118
|
+
(0, assert_1.default)(to, "requires to timestamp");
|
|
119
|
+
const _from = msToS(from);
|
|
120
|
+
const _to = msToS(to);
|
|
121
|
+
const result = await this.call(`coins/ethereum/contract/${contract.toLowerCase()}/market_chart/range/?vs_currency=${currency}&from=${_from}&to=${_to}`);
|
|
122
|
+
if (result.prices)
|
|
123
|
+
return result.prices;
|
|
124
|
+
throw new Error("Something went wrong fetching coingecko prices!");
|
|
125
|
+
}
|
|
126
|
+
async getContractHistoricDayPrice(contractAddress, date, currency = "usd", chainId = 1) {
|
|
127
|
+
const coingeckoTokenIdentifier = await this.getCoingeckoTokenId(contractAddress, chainId);
|
|
128
|
+
(0, assert_1.default)(date, "Requires date string");
|
|
129
|
+
const url = `coins/${coingeckoTokenIdentifier}/history`;
|
|
130
|
+
const queryParams = {
|
|
131
|
+
date,
|
|
132
|
+
localization: "false",
|
|
133
|
+
};
|
|
134
|
+
const result = await this.call(`${url}?${new URLSearchParams(queryParams).toString()}`);
|
|
135
|
+
const price = result?.market_data?.current_price?.[currency];
|
|
136
|
+
(0, assert_1.default)(price, `No price found for ${contractAddress} on ${date}`);
|
|
137
|
+
return price;
|
|
138
|
+
}
|
|
139
|
+
getContractDetails(contract_address, platform_id = "ethereum") {
|
|
140
|
+
return this.call(`coins/${platform_id}/contract/${contract_address.toLowerCase()}`);
|
|
141
|
+
}
|
|
142
|
+
async getCurrentPriceByContract(contractAddress, currency = "usd", chainId = 1) {
|
|
143
|
+
const platform_id = await this.getPlatformId(chainId);
|
|
144
|
+
const priceCache = this.getPriceCache(currency, platform_id);
|
|
145
|
+
let tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
146
|
+
if (tokenPrice === undefined) {
|
|
147
|
+
await this.getContractPrices([contractAddress], currency, platform_id);
|
|
148
|
+
tokenPrice = priceCache[contractAddress];
|
|
149
|
+
}
|
|
150
|
+
(0, assert_1.default)(tokenPrice !== undefined);
|
|
151
|
+
return [tokenPrice.timestamp.toString(), tokenPrice.price];
|
|
152
|
+
}
|
|
153
|
+
async getCurrentPriceById(contractAddress, currency = "usd", chainId = 1) {
|
|
154
|
+
const platform_id = await this.getPlatformId(chainId);
|
|
155
|
+
const priceCache = this.getPriceCache(currency, platform_id);
|
|
156
|
+
let tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
157
|
+
if (tokenPrice === undefined) {
|
|
158
|
+
const coingeckoId = await this.getCoingeckoTokenId(contractAddress, chainId);
|
|
159
|
+
const result = await this.call(`simple/price?ids=${coingeckoId}&vs_currencies=${currency}&include_last_updated_at=true`);
|
|
160
|
+
const cgPrice = result?.[coingeckoId];
|
|
161
|
+
if (cgPrice === undefined || !cgPrice?.[currency]) {
|
|
162
|
+
const errMsg = `No price found for ${coingeckoId}`;
|
|
163
|
+
this.logger.debug({
|
|
164
|
+
at: "Coingecko#getCurrentPriceById",
|
|
165
|
+
message: errMsg,
|
|
166
|
+
});
|
|
167
|
+
throw new Error(errMsg);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.updatePriceCache(cgPrice, contractAddress, currency, platform_id);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
tokenPrice = priceCache[contractAddress];
|
|
174
|
+
(0, assert_1.default)(tokenPrice !== undefined);
|
|
175
|
+
return [tokenPrice.timestamp.toString(), tokenPrice.price];
|
|
176
|
+
}
|
|
177
|
+
async getCurrentPriceBySymbol(symbol, currency = "usd") {
|
|
178
|
+
let tokenPrice = this.getCachedSymbolPrice(symbol, currency);
|
|
179
|
+
if (tokenPrice === undefined) {
|
|
180
|
+
const result = await this.call(`simple/price?symbols=${symbol}&vs_currencies=${currency}&include_last_updated_at=true`);
|
|
181
|
+
const cgPrice = result?.[symbol.toLowerCase()] || result?.[symbol.toUpperCase()];
|
|
182
|
+
if (cgPrice === undefined || !cgPrice?.[currency]) {
|
|
183
|
+
const errMsg = `Failed to retrieve ${symbol}/${currency} price via Coingecko API`;
|
|
184
|
+
this.logger.debug({
|
|
185
|
+
at: "Coingecko#getCurrentPriceBySymbol",
|
|
186
|
+
message: errMsg,
|
|
187
|
+
});
|
|
188
|
+
throw new Error(errMsg);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
this.updatePriceCacheBySymbol(cgPrice, symbol, currency);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
tokenPrice = this.getCachedSymbolPrice(symbol, currency);
|
|
195
|
+
(0, assert_1.default)(tokenPrice !== undefined);
|
|
196
|
+
return [tokenPrice.timestamp.toString(), tokenPrice.price];
|
|
197
|
+
}
|
|
198
|
+
async getContractPrices(addresses, currency = "usd", platform_id = "ethereum") {
|
|
199
|
+
const priceCache = this.getPriceCache(currency, platform_id);
|
|
200
|
+
addresses.forEach((addr) => {
|
|
201
|
+
if (priceCache[addr] === undefined) {
|
|
202
|
+
priceCache[addr] = { address: addr, price: 0, timestamp: 0 };
|
|
203
|
+
}
|
|
264
204
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
switch (_a.label) {
|
|
272
|
-
case 0:
|
|
273
|
-
tokenPrice = this.getCachedSymbolPrice(symbol, currency);
|
|
274
|
-
if (!(tokenPrice === undefined)) return [3, 2];
|
|
275
|
-
return [4, this.call("simple/price?symbols=".concat(symbol, "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
|
|
276
|
-
case 1:
|
|
277
|
-
result = _a.sent();
|
|
278
|
-
cgPrice = (result === null || result === void 0 ? void 0 : result[symbol.toLowerCase()]) || (result === null || result === void 0 ? void 0 : result[symbol.toUpperCase()]);
|
|
279
|
-
if (cgPrice === undefined || !(cgPrice === null || cgPrice === void 0 ? void 0 : cgPrice[currency])) {
|
|
280
|
-
errMsg = "Failed to retrieve ".concat(symbol, "/").concat(currency, " price via Coingecko API");
|
|
281
|
-
this.logger.debug({
|
|
282
|
-
at: "Coingecko#getCurrentPriceBySymbol",
|
|
283
|
-
message: errMsg,
|
|
284
|
-
});
|
|
285
|
-
throw new Error(errMsg);
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
this.updatePriceCacheBySymbol(cgPrice, symbol, currency);
|
|
289
|
-
}
|
|
290
|
-
_a.label = 2;
|
|
291
|
-
case 2:
|
|
292
|
-
tokenPrice = this.getCachedSymbolPrice(symbol, currency);
|
|
293
|
-
(0, assert_1.default)(tokenPrice !== undefined);
|
|
294
|
-
return [2, [tokenPrice.timestamp.toString(), tokenPrice.price]];
|
|
295
|
-
}
|
|
296
|
-
});
|
|
205
|
+
const contract_addresses = Object.keys(priceCache);
|
|
206
|
+
(0, assert_1.default)(contract_addresses.length > 0, "Must supply at least 1 contract address");
|
|
207
|
+
this.logger.debug({
|
|
208
|
+
at: "Coingecko#getContractPrices",
|
|
209
|
+
message: `Updating ${platform_id}/${currency} token prices.`,
|
|
210
|
+
tokens: contract_addresses,
|
|
297
211
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
priceCache = this.getPriceCache(currency, platform_id);
|
|
309
|
-
addresses.forEach(function (addr) {
|
|
310
|
-
if (priceCache[addr] === undefined) {
|
|
311
|
-
priceCache[addr] = { address: addr, price: 0, timestamp: 0 };
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
contract_addresses = Object.keys(priceCache);
|
|
315
|
-
(0, assert_1.default)(contract_addresses.length > 0, "Must supply at least 1 contract address");
|
|
316
|
-
this.logger.debug({
|
|
317
|
-
at: "Coingecko#getContractPrices",
|
|
318
|
-
message: "Updating ".concat(platform_id, "/").concat(currency, " token prices."),
|
|
319
|
-
tokens: contract_addresses,
|
|
320
|
-
});
|
|
321
|
-
result = {};
|
|
322
|
-
_a.label = 1;
|
|
323
|
-
case 1:
|
|
324
|
-
_a.trys.push([1, 3, , 4]);
|
|
325
|
-
return [4, this.call("simple/token_price/".concat(platform_id, "?contract_addresses=").concat(contract_addresses.join("%2C"), "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
|
|
326
|
-
case 2:
|
|
327
|
-
result = _a.sent();
|
|
328
|
-
return [3, 4];
|
|
329
|
-
case 3:
|
|
330
|
-
err_1 = _a.sent();
|
|
331
|
-
errMsg = "Failed to retrieve ".concat(platform_id, "/").concat(currency, " prices (").concat(err_1, ")");
|
|
332
|
-
this.logger.debug({
|
|
333
|
-
at: "Coingecko#getContractPrices",
|
|
334
|
-
message: errMsg,
|
|
335
|
-
tokens: contract_addresses,
|
|
336
|
-
});
|
|
337
|
-
throw new Error(errMsg);
|
|
338
|
-
case 4:
|
|
339
|
-
contract_addresses.forEach(function (addr) {
|
|
340
|
-
var cgPrice = result[addr.toLowerCase()];
|
|
341
|
-
if (cgPrice === undefined) {
|
|
342
|
-
_this.logger.debug({
|
|
343
|
-
at: "Coingecko#getContractPrices",
|
|
344
|
-
message: "Token ".concat(addr, " not included in CoinGecko response."),
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
_this.updatePriceCache(cgPrice, addr, currency, platform_id);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
return [2, addresses.map(function (addr) { return priceCache[addr]; })];
|
|
352
|
-
}
|
|
212
|
+
let result = {};
|
|
213
|
+
try {
|
|
214
|
+
result = await this.call(`simple/token_price/${platform_id}?contract_addresses=${contract_addresses.join("%2C")}&vs_currencies=${currency}&include_last_updated_at=true`);
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
const errMsg = `Failed to retrieve ${platform_id}/${currency} prices (${err})`;
|
|
218
|
+
this.logger.debug({
|
|
219
|
+
at: "Coingecko#getContractPrices",
|
|
220
|
+
message: errMsg,
|
|
221
|
+
tokens: contract_addresses,
|
|
353
222
|
});
|
|
223
|
+
throw new Error(errMsg);
|
|
224
|
+
}
|
|
225
|
+
contract_addresses.forEach((addr) => {
|
|
226
|
+
const cgPrice = result[addr.toLowerCase()];
|
|
227
|
+
if (cgPrice === undefined) {
|
|
228
|
+
this.logger.debug({
|
|
229
|
+
at: "Coingecko#getContractPrices",
|
|
230
|
+
message: `Token ${addr} not included in CoinGecko response.`,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.updatePriceCache(cgPrice, addr, currency, platform_id);
|
|
235
|
+
}
|
|
354
236
|
});
|
|
355
|
-
|
|
356
|
-
|
|
237
|
+
return addresses.map((addr) => priceCache[addr]);
|
|
238
|
+
}
|
|
239
|
+
getPlatforms() {
|
|
357
240
|
return this.call("asset_platforms");
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
at: "sdk/coingecko",
|
|
378
|
-
message: "Basic CG url request failed, falling back to CG PRO host ".concat(proHost),
|
|
379
|
-
errMessage: err_2.message,
|
|
380
|
-
});
|
|
381
|
-
return [4, this._callPro(path)];
|
|
382
|
-
case 5: return [2, _a.sent()];
|
|
383
|
-
case 6: return [2];
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
}); };
|
|
241
|
+
}
|
|
242
|
+
call(path) {
|
|
243
|
+
const sendRequest = async () => {
|
|
244
|
+
const { proHost } = this;
|
|
245
|
+
if (this.apiKey === undefined) {
|
|
246
|
+
return (await this._callBasic(path));
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
return (await this._callBasic(path, this.basicApiTimeout));
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
this.logger.debug({
|
|
253
|
+
at: "sdk/coingecko",
|
|
254
|
+
message: `Basic CG url request failed, falling back to CG PRO host ${proHost}`,
|
|
255
|
+
errMessage: err.message,
|
|
256
|
+
});
|
|
257
|
+
return await this._callPro(path);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
387
260
|
return (0, utils_1.retry)(sendRequest, this.apiKey === undefined ? this.numRetries : 0, this.retryDelay);
|
|
388
|
-
}
|
|
389
|
-
|
|
261
|
+
}
|
|
262
|
+
getPriceCache(currency, platform_id) {
|
|
390
263
|
if (this.prices[platform_id] === undefined)
|
|
391
264
|
this.prices[platform_id] = {};
|
|
392
265
|
if (this.prices[platform_id][currency] === undefined)
|
|
393
266
|
this.prices[platform_id][currency] = {};
|
|
394
267
|
return this.prices[platform_id][currency];
|
|
395
|
-
}
|
|
396
|
-
|
|
268
|
+
}
|
|
269
|
+
getPriceCacheBySymbol(symbol) {
|
|
397
270
|
if (this.pricesBySymbol[symbol] === undefined)
|
|
398
271
|
this.pricesBySymbol[symbol] = {};
|
|
399
272
|
return this.pricesBySymbol[symbol];
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
273
|
+
}
|
|
274
|
+
getCachedAddressPrice(contractAddress, currency, platform_id) {
|
|
275
|
+
const priceCache = this.getPriceCache(currency, platform_id);
|
|
276
|
+
const now = msToS(Date.now());
|
|
277
|
+
const tokenPrice = priceCache[contractAddress];
|
|
405
278
|
if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
|
|
406
279
|
if (this.maxPriceAge > 0) {
|
|
407
280
|
this.logger.debug({
|
|
408
281
|
at: "Coingecko#getCachedAddressPrice",
|
|
409
|
-
message:
|
|
282
|
+
message: `Cache miss on ${platform_id}/${currency} for ${contractAddress}`,
|
|
410
283
|
maxPriceAge: this.maxPriceAge,
|
|
411
284
|
tokenPrice: tokenPrice,
|
|
412
285
|
});
|
|
@@ -416,23 +289,23 @@ var Coingecko = (function () {
|
|
|
416
289
|
else {
|
|
417
290
|
this.logger.debug({
|
|
418
291
|
at: "Coingecko#getCachedAddressPrice",
|
|
419
|
-
message:
|
|
292
|
+
message: `Cache hit on token ${contractAddress} (age ${now - tokenPrice.timestamp} S).`,
|
|
420
293
|
price: tokenPrice,
|
|
421
294
|
});
|
|
422
295
|
return tokenPrice;
|
|
423
296
|
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
297
|
+
}
|
|
298
|
+
getCachedSymbolPrice(symbol, currency) {
|
|
299
|
+
const priceCache = this.getPriceCacheBySymbol(symbol);
|
|
300
|
+
const now = msToS(Date.now());
|
|
301
|
+
const tokenPrice = priceCache[currency];
|
|
429
302
|
if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
|
|
430
303
|
return undefined;
|
|
431
304
|
}
|
|
432
305
|
return tokenPrice;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
306
|
+
}
|
|
307
|
+
updatePriceCache(cgPrice, contractAddress, currency, platform_id) {
|
|
308
|
+
const priceCache = this.getPriceCache(currency, platform_id);
|
|
436
309
|
if (priceCache[contractAddress] === undefined) {
|
|
437
310
|
priceCache[contractAddress] = { address: contractAddress, price: 0, timestamp: 0 };
|
|
438
311
|
}
|
|
@@ -444,19 +317,19 @@ var Coingecko = (function () {
|
|
|
444
317
|
};
|
|
445
318
|
this.logger.debug({
|
|
446
319
|
at: "Coingecko#updatePriceCache",
|
|
447
|
-
message:
|
|
320
|
+
message: `Updated ${platform_id}/${currency}/${contractAddress} token price cache.`,
|
|
448
321
|
});
|
|
449
322
|
}
|
|
450
323
|
else {
|
|
451
324
|
this.logger.debug({
|
|
452
325
|
at: "Coingecko#updatePriceCache",
|
|
453
|
-
message:
|
|
326
|
+
message: `No new price available for token ${contractAddress}.`,
|
|
454
327
|
token: cgPrice,
|
|
455
328
|
});
|
|
456
329
|
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
330
|
+
}
|
|
331
|
+
updatePriceCacheBySymbol(cgPrice, symbol, currency) {
|
|
332
|
+
const priceCache = this.getPriceCacheBySymbol(symbol);
|
|
460
333
|
if (priceCache[currency] === undefined) {
|
|
461
334
|
priceCache[currency] = { price: 0, timestamp: 0 };
|
|
462
335
|
}
|
|
@@ -467,64 +340,39 @@ var Coingecko = (function () {
|
|
|
467
340
|
};
|
|
468
341
|
this.logger.debug({
|
|
469
342
|
at: "Coingecko#updatePriceCacheBySymbol",
|
|
470
|
-
message:
|
|
343
|
+
message: `Updated ${symbol}/${currency} token price cache.`,
|
|
471
344
|
});
|
|
472
345
|
}
|
|
473
346
|
else {
|
|
474
347
|
this.logger.debug({
|
|
475
348
|
at: "Coingecko#updatePriceCacheBySymbol",
|
|
476
|
-
message:
|
|
349
|
+
message: `No new price available for symbol ${symbol}.`,
|
|
477
350
|
token: cgPrice,
|
|
478
351
|
});
|
|
479
352
|
}
|
|
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
|
-
Coingecko.prototype._callPro = function (path) {
|
|
505
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
506
|
-
var url, result, err_4, msg;
|
|
507
|
-
return tslib_1.__generator(this, function (_a) {
|
|
508
|
-
switch (_a.label) {
|
|
509
|
-
case 0:
|
|
510
|
-
url = "".concat(this.proHost, "/").concat(path);
|
|
511
|
-
_a.label = 1;
|
|
512
|
-
case 1:
|
|
513
|
-
_a.trys.push([1, 3, , 4]);
|
|
514
|
-
return [4, (0, axios_1.default)(url, { params: { x_cg_pro_api_key: this.apiKey } })];
|
|
515
|
-
case 2:
|
|
516
|
-
result = _a.sent();
|
|
517
|
-
return [2, result.data];
|
|
518
|
-
case 3:
|
|
519
|
-
err_4 = _a.sent();
|
|
520
|
-
msg = (0, lodash_get_1.default)(err_4, "response.data.error", (0, lodash_get_1.default)(err_4, "response.statusText", err_4.message));
|
|
521
|
-
throw new Error(msg);
|
|
522
|
-
case 4: return [2];
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
});
|
|
526
|
-
};
|
|
527
|
-
return Coingecko;
|
|
528
|
-
}());
|
|
353
|
+
}
|
|
354
|
+
async _callBasic(path, timeout) {
|
|
355
|
+
const url = `${this.host}/${path}`;
|
|
356
|
+
try {
|
|
357
|
+
const result = await (0, axios_1.default)(url, { timeout });
|
|
358
|
+
return result.data;
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
const msg = (0, lodash_get_1.default)(err, "response.data.error", (0, lodash_get_1.default)(err, "response.statusText", err.message));
|
|
362
|
+
throw new Error(msg);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async _callPro(path) {
|
|
366
|
+
const url = `${this.proHost}/${path}`;
|
|
367
|
+
try {
|
|
368
|
+
const result = await (0, axios_1.default)(url, { params: { x_cg_pro_api_key: this.apiKey } });
|
|
369
|
+
return result.data;
|
|
370
|
+
}
|
|
371
|
+
catch (err) {
|
|
372
|
+
const msg = (0, lodash_get_1.default)(err, "response.data.error", (0, lodash_get_1.default)(err, "response.statusText", err.message));
|
|
373
|
+
throw new Error(msg);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
529
377
|
exports.Coingecko = Coingecko;
|
|
530
378
|
//# sourceMappingURL=Coingecko.js.map
|