@across-protocol/sdk 4.3.110 → 4.3.111-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (558) hide show
  1. package/dist/cjs/addressAggregator/adapters/abstract.js +50 -64
  2. package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
  3. package/dist/cjs/addressAggregator/adapters/bybit.js +16 -29
  4. package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
  5. package/dist/cjs/addressAggregator/adapters/env.js +11 -15
  6. package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
  7. package/dist/cjs/addressAggregator/adapters/file.js +32 -45
  8. package/dist/cjs/addressAggregator/adapters/file.js.map +1 -1
  9. package/dist/cjs/addressAggregator/adapters/index.js +1 -1
  10. package/dist/cjs/addressAggregator/adapters/risklabs.js +22 -36
  11. package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
  12. package/dist/cjs/addressAggregator/index.js +57 -87
  13. package/dist/cjs/addressAggregator/index.js.map +1 -1
  14. package/dist/cjs/apiClient/abstractClient.js +9 -8
  15. package/dist/cjs/apiClient/abstractClient.js.map +1 -1
  16. package/dist/cjs/apiClient/index.js +1 -1
  17. package/dist/cjs/apiClient/mockedClient.js +23 -29
  18. package/dist/cjs/apiClient/mockedClient.js.map +1 -1
  19. package/dist/cjs/apiClient/productionClient.js +65 -103
  20. package/dist/cjs/apiClient/productionClient.js.map +1 -1
  21. package/dist/cjs/arch/evm/BlockUtils.js +122 -208
  22. package/dist/cjs/arch/evm/BlockUtils.js.map +1 -1
  23. package/dist/cjs/arch/evm/MessageUtils.js +1 -1
  24. package/dist/cjs/arch/evm/MessageUtils.js.map +1 -1
  25. package/dist/cjs/arch/evm/SpokeUtils.js +134 -288
  26. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  27. package/dist/cjs/arch/evm/index.js +1 -1
  28. package/dist/cjs/arch/evm/utils/index.js +1 -1
  29. package/dist/cjs/arch/evm/utils/wait.js +38 -49
  30. package/dist/cjs/arch/evm/utils/wait.js.map +1 -1
  31. package/dist/cjs/arch/index.js +1 -1
  32. package/dist/cjs/arch/svm/BlockUtils.js +102 -158
  33. package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
  34. package/dist/cjs/arch/svm/MessageUtils.js +2 -2
  35. package/dist/cjs/arch/svm/MessageUtils.js.map +1 -1
  36. package/dist/cjs/arch/svm/SpokeUtils.js +708 -1147
  37. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  38. package/dist/cjs/arch/svm/encoders.js +1 -1
  39. package/dist/cjs/arch/svm/encoders.js.map +1 -1
  40. package/dist/cjs/arch/svm/eventsClient.js +174 -236
  41. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  42. package/dist/cjs/arch/svm/index.js +1 -1
  43. package/dist/cjs/arch/svm/provider.js +3 -3
  44. package/dist/cjs/arch/svm/provider.js.map +1 -1
  45. package/dist/cjs/arch/svm/utils.js +166 -355
  46. package/dist/cjs/arch/svm/utils.js.map +1 -1
  47. package/dist/cjs/caching/Arweave/ArweaveClient.js +168 -246
  48. package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
  49. package/dist/cjs/caching/Arweave/index.js +1 -1
  50. package/dist/cjs/caching/IPFS/PinataIPFSClient.js +40 -49
  51. package/dist/cjs/caching/IPFS/PinataIPFSClient.js.map +1 -1
  52. package/dist/cjs/caching/IPFS/index.js +1 -1
  53. package/dist/cjs/caching/Memory/MemoryCacheClient.js +13 -18
  54. package/dist/cjs/caching/Memory/MemoryCacheClient.js.map +1 -1
  55. package/dist/cjs/caching/Memory/index.js +1 -1
  56. package/dist/cjs/caching/index.js +1 -1
  57. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +302 -381
  58. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  59. package/dist/cjs/clients/AcrossConfigStoreClient/index.js +1 -1
  60. package/dist/cjs/clients/BaseAbstractClient.js +58 -83
  61. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  62. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +709 -900
  63. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  64. package/dist/cjs/clients/BundleDataClient/index.js +1 -1
  65. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +95 -128
  66. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  67. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +48 -53
  68. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  69. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +10 -8
  70. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  71. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +67 -90
  72. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  73. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +46 -24
  74. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  75. package/dist/cjs/clients/BundleDataClient/utils/index.js +1 -1
  76. package/dist/cjs/clients/HubPoolClient.js +526 -708
  77. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  78. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -179
  79. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  80. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +124 -183
  81. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  82. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +357 -389
  83. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  84. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +9 -8
  85. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  86. package/dist/cjs/clients/SpokePoolClient/index.js +3 -3
  87. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  88. package/dist/cjs/clients/index.js +1 -1
  89. package/dist/cjs/clients/mocks/MockConfigStoreClient.js +58 -67
  90. package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
  91. package/dist/cjs/clients/mocks/MockEvents.js +47 -52
  92. package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
  93. package/dist/cjs/clients/mocks/MockHubPoolClient.js +142 -185
  94. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  95. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +208 -192
  96. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  97. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +140 -143
  98. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  99. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +57 -73
  100. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  101. package/dist/cjs/clients/mocks/index.js +1 -1
  102. package/dist/cjs/coingecko/Coingecko.js +285 -437
  103. package/dist/cjs/coingecko/Coingecko.js.map +1 -1
  104. package/dist/cjs/coingecko/index.js +1 -1
  105. package/dist/cjs/constants.js +23 -29
  106. package/dist/cjs/constants.js.map +1 -1
  107. package/dist/cjs/contracts/acrossConfigStore.js +27 -48
  108. package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
  109. package/dist/cjs/contracts/hubPool.js +36 -20
  110. package/dist/cjs/contracts/hubPool.js.map +1 -1
  111. package/dist/cjs/contracts/index.js +1 -1
  112. package/dist/cjs/contracts/utils.js +6 -8
  113. package/dist/cjs/contracts/utils.js.map +1 -1
  114. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +7 -16
  115. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  116. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +26 -45
  117. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  118. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +16 -28
  119. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  120. package/dist/cjs/gasPriceOracle/adapters/polygon.js +73 -112
  121. package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
  122. package/dist/cjs/gasPriceOracle/adapters/solana.js +20 -33
  123. package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
  124. package/dist/cjs/gasPriceOracle/oracle.js +77 -103
  125. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  126. package/dist/cjs/gasPriceOracle/types.js +3 -3
  127. package/dist/cjs/gasPriceOracle/types.js.map +1 -1
  128. package/dist/cjs/gasPriceOracle/util.js +8 -8
  129. package/dist/cjs/gasPriceOracle/util.js.map +1 -1
  130. package/dist/cjs/index.js +1 -1
  131. package/dist/cjs/interfaces/index.js +1 -1
  132. package/dist/cjs/lpFeeCalculator/index.js +1 -1
  133. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js +33 -35
  134. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  135. package/dist/cjs/lpFeeCalculator/rateModel.js +7 -9
  136. package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
  137. package/dist/cjs/merkleDistributor/MerkleDistributor.js +20 -18
  138. package/dist/cjs/merkleDistributor/MerkleDistributor.js.map +1 -1
  139. package/dist/cjs/merkleDistributor/index.js +1 -1
  140. package/dist/cjs/merkleDistributor/model/index.js +1 -1
  141. package/dist/cjs/pool/TransactionManager.js +45 -100
  142. package/dist/cjs/pool/TransactionManager.js.map +1 -1
  143. package/dist/cjs/pool/index.js +1 -1
  144. package/dist/cjs/pool/poolClient.js +464 -731
  145. package/dist/cjs/pool/poolClient.js.map +1 -1
  146. package/dist/cjs/pool/uma/across/index.js +1 -1
  147. package/dist/cjs/pool/uma/across/transactionManager.js +45 -100
  148. package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
  149. package/dist/cjs/pool/uma/clients/erc20/client.js +18 -16
  150. package/dist/cjs/pool/uma/clients/erc20/client.js.map +1 -1
  151. package/dist/cjs/pool/uma/clients/erc20/index.js +1 -1
  152. package/dist/cjs/pool/uma/clients/index.js +1 -1
  153. package/dist/cjs/pool/uma/index.js +1 -1
  154. package/dist/cjs/pool/uma/oracle/index.js +1 -1
  155. package/dist/cjs/pool/uma/oracle/utils.js +4 -5
  156. package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
  157. package/dist/cjs/pool/uma/utils.js +11 -30
  158. package/dist/cjs/pool/uma/utils.js.map +1 -1
  159. package/dist/cjs/priceClient/adapters/acrossApi.js +22 -39
  160. package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
  161. package/dist/cjs/priceClient/adapters/baseAdapter.js +49 -73
  162. package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
  163. package/dist/cjs/priceClient/adapters/coingecko.js +34 -61
  164. package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
  165. package/dist/cjs/priceClient/adapters/default.js +16 -31
  166. package/dist/cjs/priceClient/adapters/default.js.map +1 -1
  167. package/dist/cjs/priceClient/adapters/defiLlama.js +40 -74
  168. package/dist/cjs/priceClient/adapters/defiLlama.js.map +1 -1
  169. package/dist/cjs/priceClient/adapters/index.js +1 -1
  170. package/dist/cjs/priceClient/index.js +1 -1
  171. package/dist/cjs/priceClient/priceClient.js +110 -159
  172. package/dist/cjs/priceClient/priceClient.js.map +1 -1
  173. package/dist/cjs/providers/alchemy.js +17 -19
  174. package/dist/cjs/providers/alchemy.js.map +1 -1
  175. package/dist/cjs/providers/cachedProvider.js +88 -129
  176. package/dist/cjs/providers/cachedProvider.js.map +1 -1
  177. package/dist/cjs/providers/drpc.js +9 -11
  178. package/dist/cjs/providers/drpc.js.map +1 -1
  179. package/dist/cjs/providers/index.js +1 -1
  180. package/dist/cjs/providers/infura.js +10 -12
  181. package/dist/cjs/providers/infura.js.map +1 -1
  182. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +7 -15
  183. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  184. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +6 -14
  185. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  186. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +7 -15
  187. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  188. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +42 -66
  189. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  190. package/dist/cjs/providers/mocks/index.js +1 -1
  191. package/dist/cjs/providers/mocks/mockEthersProvider.js +29 -31
  192. package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
  193. package/dist/cjs/providers/quicknode.js +19 -21
  194. package/dist/cjs/providers/quicknode.js.map +1 -1
  195. package/dist/cjs/providers/rateLimitedProvider.js +64 -79
  196. package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
  197. package/dist/cjs/providers/retryProvider.js +163 -246
  198. package/dist/cjs/providers/retryProvider.js.map +1 -1
  199. package/dist/cjs/providers/solana/baseRpcFactories.js +14 -18
  200. package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
  201. package/dist/cjs/providers/solana/cachedRpcFactory.js +70 -112
  202. package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
  203. package/dist/cjs/providers/solana/defaultRpcFactory.js +8 -15
  204. package/dist/cjs/providers/solana/defaultRpcFactory.js.map +1 -1
  205. package/dist/cjs/providers/solana/index.js +1 -1
  206. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js +135 -191
  207. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  208. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +67 -90
  209. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  210. package/dist/cjs/providers/solana/retryRpcFactory.js +52 -79
  211. package/dist/cjs/providers/solana/retryRpcFactory.js.map +1 -1
  212. package/dist/cjs/providers/solana/utils.js +2 -2
  213. package/dist/cjs/providers/solana/utils.js.map +1 -1
  214. package/dist/cjs/providers/speedProvider.js +31 -53
  215. package/dist/cjs/providers/speedProvider.js.map +1 -1
  216. package/dist/cjs/providers/types.js +1 -1
  217. package/dist/cjs/providers/types.js.map +1 -1
  218. package/dist/cjs/providers/utils.js +26 -28
  219. package/dist/cjs/providers/utils.js.map +1 -1
  220. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +108 -162
  221. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  222. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +14 -26
  223. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  224. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +20 -29
  225. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  226. package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -1
  227. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +88 -137
  228. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  229. package/dist/cjs/relayFeeCalculator/index.js +1 -1
  230. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +199 -297
  231. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  232. package/dist/cjs/typeguards/error.js +5 -7
  233. package/dist/cjs/typeguards/error.js.map +1 -1
  234. package/dist/cjs/typeguards/index.js +1 -1
  235. package/dist/cjs/utils/AddressUtils.js +117 -144
  236. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  237. package/dist/cjs/utils/ArrayUtils.js +21 -78
  238. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  239. package/dist/cjs/utils/BigNumberUtils.js +9 -10
  240. package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
  241. package/dist/cjs/utils/BlockExplorerUtils.js +26 -30
  242. package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
  243. package/dist/cjs/utils/BlockFinder.js +2 -5
  244. package/dist/cjs/utils/BlockFinder.js.map +1 -1
  245. package/dist/cjs/utils/BlockUtils.js +24 -41
  246. package/dist/cjs/utils/BlockUtils.js.map +1 -1
  247. package/dist/cjs/utils/BundleUtils.js +21 -24
  248. package/dist/cjs/utils/BundleUtils.js.map +1 -1
  249. package/dist/cjs/utils/CCTPUtils.js +62 -126
  250. package/dist/cjs/utils/CCTPUtils.js.map +1 -1
  251. package/dist/cjs/utils/CachingUtils.js +20 -42
  252. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  253. package/dist/cjs/utils/ContractUtils.js +5 -5
  254. package/dist/cjs/utils/ContractUtils.js.map +1 -1
  255. package/dist/cjs/utils/DepositUtils.js +122 -99
  256. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  257. package/dist/cjs/utils/EventUtils.js +49 -70
  258. package/dist/cjs/utils/EventUtils.js.map +1 -1
  259. package/dist/cjs/utils/FormattingUtils.js +26 -32
  260. package/dist/cjs/utils/FormattingUtils.js.map +1 -1
  261. package/dist/cjs/utils/HyperLiquidUtils.js +10 -23
  262. package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
  263. package/dist/cjs/utils/IPFSUtils.js +16 -34
  264. package/dist/cjs/utils/IPFSUtils.js.map +1 -1
  265. package/dist/cjs/utils/JSONUtils.js +6 -6
  266. package/dist/cjs/utils/JSONUtils.js.map +1 -1
  267. package/dist/cjs/utils/LogUtils.js +10 -12
  268. package/dist/cjs/utils/LogUtils.js.map +1 -1
  269. package/dist/cjs/utils/Multicall.js +56 -114
  270. package/dist/cjs/utils/Multicall.js.map +1 -1
  271. package/dist/cjs/utils/NetworkUtils.js +12 -21
  272. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  273. package/dist/cjs/utils/NumberUtils.js +1 -3
  274. package/dist/cjs/utils/NumberUtils.js.map +1 -1
  275. package/dist/cjs/utils/ObjectUtils.js +27 -41
  276. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  277. package/dist/cjs/utils/Profiler.js +80 -83
  278. package/dist/cjs/utils/Profiler.js.map +1 -1
  279. package/dist/cjs/utils/ReviverUtils.js +5 -9
  280. package/dist/cjs/utils/ReviverUtils.js.map +1 -1
  281. package/dist/cjs/utils/SpokeUtils.js +84 -84
  282. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  283. package/dist/cjs/utils/TokenUtils.js +41 -64
  284. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  285. package/dist/cjs/utils/TypeGuards.js +1 -1
  286. package/dist/cjs/utils/TypeGuards.js.map +1 -1
  287. package/dist/cjs/utils/ValidatorUtils.js +7 -7
  288. package/dist/cjs/utils/ValidatorUtils.js.map +1 -1
  289. package/dist/cjs/utils/abi/contracts/index.js +1 -1
  290. package/dist/cjs/utils/abi/index.js +12 -22
  291. package/dist/cjs/utils/abi/index.js.map +1 -1
  292. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +9 -12
  293. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  294. package/dist/cjs/utils/abi/typechain/index.js +1 -1
  295. package/dist/cjs/utils/common.js +40 -53
  296. package/dist/cjs/utils/common.js.map +1 -1
  297. package/dist/cjs/utils/index.js +1 -1
  298. package/dist/esm/addressAggregator/adapters/abstract.js +48 -64
  299. package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
  300. package/dist/esm/addressAggregator/adapters/bybit.js +15 -29
  301. package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
  302. package/dist/esm/addressAggregator/adapters/env.js +9 -14
  303. package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
  304. package/dist/esm/addressAggregator/adapters/file.js +29 -43
  305. package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
  306. package/dist/esm/addressAggregator/adapters/risklabs.js +20 -35
  307. package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
  308. package/dist/esm/addressAggregator/index.js +52 -83
  309. package/dist/esm/addressAggregator/index.js.map +1 -1
  310. package/dist/esm/addressAggregator/types.js +1 -1
  311. package/dist/esm/addressAggregator/types.js.map +1 -1
  312. package/dist/esm/apiClient/abstractClient.js +15 -9
  313. package/dist/esm/apiClient/abstractClient.js.map +1 -1
  314. package/dist/esm/apiClient/mockedClient.js +21 -26
  315. package/dist/esm/apiClient/mockedClient.js.map +1 -1
  316. package/dist/esm/apiClient/productionClient.js +61 -101
  317. package/dist/esm/apiClient/productionClient.js.map +1 -1
  318. package/dist/esm/arch/evm/BlockUtils.js +139 -217
  319. package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
  320. package/dist/esm/arch/evm/SpokeUtils.js +146 -289
  321. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  322. package/dist/esm/arch/evm/utils/wait.js +34 -46
  323. package/dist/esm/arch/evm/utils/wait.js.map +1 -1
  324. package/dist/esm/arch/svm/BlockUtils.js +118 -166
  325. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  326. package/dist/esm/arch/svm/SpokeUtils.js +738 -1150
  327. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  328. package/dist/esm/arch/svm/constants.js +1 -1
  329. package/dist/esm/arch/svm/constants.js.map +1 -1
  330. package/dist/esm/arch/svm/eventsClient.js +172 -232
  331. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  332. package/dist/esm/arch/svm/provider.js +1 -1
  333. package/dist/esm/arch/svm/provider.js.map +1 -1
  334. package/dist/esm/arch/svm/utils.js +155 -345
  335. package/dist/esm/arch/svm/utils.js.map +1 -1
  336. package/dist/esm/caching/Arweave/ArweaveClient.js +182 -256
  337. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  338. package/dist/esm/caching/IPFS/PinataIPFSClient.js +47 -48
  339. package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
  340. package/dist/esm/caching/Memory/MemoryCacheClient.js +13 -19
  341. package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
  342. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +333 -408
  343. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  344. package/dist/esm/clients/BaseAbstractClient.js +66 -92
  345. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  346. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +927 -1054
  347. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  348. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +102 -131
  349. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  350. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +57 -59
  351. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  352. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +7 -5
  353. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  354. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +75 -94
  355. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  356. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +45 -23
  357. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  358. package/dist/esm/clients/HubPoolClient.js +581 -740
  359. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  360. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -178
  361. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  362. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +126 -183
  363. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  364. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +372 -399
  365. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  366. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js +9 -9
  367. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  368. package/dist/esm/clients/SpokePoolClient/index.js +2 -2
  369. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  370. package/dist/esm/clients/SpokePoolClient/types.js +2 -2
  371. package/dist/esm/clients/SpokePoolClient/types.js.map +1 -1
  372. package/dist/esm/clients/mocks/MockConfigStoreClient.js +53 -64
  373. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  374. package/dist/esm/clients/mocks/MockEvents.js +42 -49
  375. package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
  376. package/dist/esm/clients/mocks/MockHubPoolClient.js +138 -182
  377. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  378. package/dist/esm/clients/mocks/MockSpokePoolClient.js +202 -188
  379. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  380. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +127 -132
  381. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  382. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +53 -69
  383. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  384. package/dist/esm/coingecko/Coingecko.js +298 -443
  385. package/dist/esm/coingecko/Coingecko.js.map +1 -1
  386. package/dist/esm/constants.js +40 -46
  387. package/dist/esm/constants.js.map +1 -1
  388. package/dist/esm/contracts/acrossConfigStore.js +24 -46
  389. package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
  390. package/dist/esm/contracts/hubPool.js +34 -18
  391. package/dist/esm/contracts/hubPool.js.map +1 -1
  392. package/dist/esm/contracts/utils.js +3 -5
  393. package/dist/esm/contracts/utils.js.map +1 -1
  394. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +6 -14
  395. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  396. package/dist/esm/gasPriceOracle/adapters/ethereum.js +22 -42
  397. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  398. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +13 -25
  399. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  400. package/dist/esm/gasPriceOracle/adapters/polygon.js +72 -108
  401. package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
  402. package/dist/esm/gasPriceOracle/adapters/solana.js +22 -31
  403. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
  404. package/dist/esm/gasPriceOracle/oracle.js +70 -95
  405. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  406. package/dist/esm/gasPriceOracle/types.js +2 -2
  407. package/dist/esm/gasPriceOracle/types.js.map +1 -1
  408. package/dist/esm/gasPriceOracle/util.js +4 -4
  409. package/dist/esm/gasPriceOracle/util.js.map +1 -1
  410. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js +30 -33
  411. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  412. package/dist/esm/lpFeeCalculator/rateModel.js +7 -9
  413. package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
  414. package/dist/esm/merkleDistributor/MerkleDistributor.js +18 -17
  415. package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
  416. package/dist/esm/pool/TransactionManager.js +45 -100
  417. package/dist/esm/pool/TransactionManager.js.map +1 -1
  418. package/dist/esm/pool/poolClient.js +479 -740
  419. package/dist/esm/pool/poolClient.js.map +1 -1
  420. package/dist/esm/pool/uma/across/constants.js +2 -2
  421. package/dist/esm/pool/uma/across/constants.js.map +1 -1
  422. package/dist/esm/pool/uma/across/transactionManager.js +45 -100
  423. package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
  424. package/dist/esm/pool/uma/clients/erc20/client.js +15 -13
  425. package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
  426. package/dist/esm/pool/uma/oracle/utils.js +2 -3
  427. package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
  428. package/dist/esm/pool/uma/utils.js +9 -28
  429. package/dist/esm/pool/uma/utils.js.map +1 -1
  430. package/dist/esm/priceClient/adapters/acrossApi.js +21 -40
  431. package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
  432. package/dist/esm/priceClient/adapters/baseAdapter.js +46 -72
  433. package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
  434. package/dist/esm/priceClient/adapters/coingecko.js +33 -61
  435. package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
  436. package/dist/esm/priceClient/adapters/default.js +15 -31
  437. package/dist/esm/priceClient/adapters/default.js.map +1 -1
  438. package/dist/esm/priceClient/adapters/defiLlama.js +38 -73
  439. package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
  440. package/dist/esm/priceClient/priceClient.js +109 -158
  441. package/dist/esm/priceClient/priceClient.js.map +1 -1
  442. package/dist/esm/providers/alchemy.js +16 -18
  443. package/dist/esm/providers/alchemy.js.map +1 -1
  444. package/dist/esm/providers/cachedProvider.js +99 -134
  445. package/dist/esm/providers/cachedProvider.js.map +1 -1
  446. package/dist/esm/providers/constants.js +3 -3
  447. package/dist/esm/providers/constants.js.map +1 -1
  448. package/dist/esm/providers/drpc.js +8 -10
  449. package/dist/esm/providers/drpc.js.map +1 -1
  450. package/dist/esm/providers/infura.js +9 -11
  451. package/dist/esm/providers/infura.js.map +1 -1
  452. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +6 -15
  453. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  454. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +5 -14
  455. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  456. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +6 -15
  457. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  458. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +41 -66
  459. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  460. package/dist/esm/providers/mocks/mockEthersProvider.js +27 -30
  461. package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
  462. package/dist/esm/providers/quicknode.js +18 -20
  463. package/dist/esm/providers/quicknode.js.map +1 -1
  464. package/dist/esm/providers/rateLimitedProvider.js +68 -80
  465. package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
  466. package/dist/esm/providers/retryProvider.js +186 -259
  467. package/dist/esm/providers/retryProvider.js.map +1 -1
  468. package/dist/esm/providers/solana/baseRpcFactories.js +13 -19
  469. package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
  470. package/dist/esm/providers/solana/cachedRpcFactory.js +75 -112
  471. package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
  472. package/dist/esm/providers/solana/defaultRpcFactory.js +6 -14
  473. package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
  474. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +149 -202
  475. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  476. package/dist/esm/providers/solana/rateLimitedRpcFactory.js +70 -90
  477. package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  478. package/dist/esm/providers/solana/retryRpcFactory.js +50 -74
  479. package/dist/esm/providers/solana/retryRpcFactory.js.map +1 -1
  480. package/dist/esm/providers/solana/utils.js +1 -1
  481. package/dist/esm/providers/solana/utils.js.map +1 -1
  482. package/dist/esm/providers/speedProvider.js +28 -51
  483. package/dist/esm/providers/speedProvider.js.map +1 -1
  484. package/dist/esm/providers/types.js +2 -2
  485. package/dist/esm/providers/types.js.map +1 -1
  486. package/dist/esm/providers/utils.js +17 -20
  487. package/dist/esm/providers/utils.js.map +1 -1
  488. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +98 -152
  489. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  490. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +13 -26
  491. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  492. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +9 -19
  493. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  494. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +83 -128
  495. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  496. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +211 -299
  497. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  498. package/dist/esm/typeguards/error.js +3 -5
  499. package/dist/esm/typeguards/error.js.map +1 -1
  500. package/dist/esm/utils/AddressUtils.js +115 -147
  501. package/dist/esm/utils/AddressUtils.js.map +1 -1
  502. package/dist/esm/utils/ArrayUtils.js +21 -78
  503. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  504. package/dist/esm/utils/BigNumberUtils.js +11 -12
  505. package/dist/esm/utils/BigNumberUtils.js.map +1 -1
  506. package/dist/esm/utils/BlockExplorerUtils.js +19 -23
  507. package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
  508. package/dist/esm/utils/BlockFinder.js +2 -6
  509. package/dist/esm/utils/BlockFinder.js.map +1 -1
  510. package/dist/esm/utils/BlockUtils.js +31 -40
  511. package/dist/esm/utils/BlockUtils.js.map +1 -1
  512. package/dist/esm/utils/BundleUtils.js +21 -24
  513. package/dist/esm/utils/BundleUtils.js.map +1 -1
  514. package/dist/esm/utils/CCTPUtils.js +62 -123
  515. package/dist/esm/utils/CCTPUtils.js.map +1 -1
  516. package/dist/esm/utils/CachingUtils.js +17 -38
  517. package/dist/esm/utils/CachingUtils.js.map +1 -1
  518. package/dist/esm/utils/ContractUtils.js +3 -3
  519. package/dist/esm/utils/ContractUtils.js.map +1 -1
  520. package/dist/esm/utils/DepositUtils.js +121 -98
  521. package/dist/esm/utils/DepositUtils.js.map +1 -1
  522. package/dist/esm/utils/EventUtils.js +52 -69
  523. package/dist/esm/utils/EventUtils.js.map +1 -1
  524. package/dist/esm/utils/FormattingUtils.js +20 -26
  525. package/dist/esm/utils/FormattingUtils.js.map +1 -1
  526. package/dist/esm/utils/HyperLiquidUtils.js +8 -22
  527. package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
  528. package/dist/esm/utils/IPFSUtils.js +16 -35
  529. package/dist/esm/utils/IPFSUtils.js.map +1 -1
  530. package/dist/esm/utils/JSONUtils.js +4 -4
  531. package/dist/esm/utils/JSONUtils.js.map +1 -1
  532. package/dist/esm/utils/LogUtils.js +8 -12
  533. package/dist/esm/utils/LogUtils.js.map +1 -1
  534. package/dist/esm/utils/Multicall.js +50 -109
  535. package/dist/esm/utils/Multicall.js.map +1 -1
  536. package/dist/esm/utils/NetworkUtils.js +12 -21
  537. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  538. package/dist/esm/utils/NumberUtils.js +1 -3
  539. package/dist/esm/utils/NumberUtils.js.map +1 -1
  540. package/dist/esm/utils/ObjectUtils.js +27 -41
  541. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  542. package/dist/esm/utils/Profiler.js +77 -82
  543. package/dist/esm/utils/Profiler.js.map +1 -1
  544. package/dist/esm/utils/ReviverUtils.js +3 -7
  545. package/dist/esm/utils/ReviverUtils.js.map +1 -1
  546. package/dist/esm/utils/SpokeUtils.js +83 -78
  547. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  548. package/dist/esm/utils/TokenUtils.js +33 -57
  549. package/dist/esm/utils/TokenUtils.js.map +1 -1
  550. package/dist/esm/utils/ValidatorUtils.js +4 -4
  551. package/dist/esm/utils/ValidatorUtils.js.map +1 -1
  552. package/dist/esm/utils/abi/index.js +10 -20
  553. package/dist/esm/utils/abi/index.js.map +1 -1
  554. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +8 -12
  555. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  556. package/dist/esm/utils/common.js +38 -52
  557. package/dist/esm/utils/common.js.map +1 -1
  558. package/package.json +2 -2
@@ -1,4 +1,3 @@
1
- import { __awaiter, __generator } from "tslib";
2
1
  import axios from "axios";
3
2
  import assert from "assert";
4
3
  import get from "lodash.get";
@@ -7,169 +6,125 @@ export function msToS(ms) {
7
6
  return Math.floor(ms / 1000);
8
7
  }
9
8
  // Singleton Coingecko class.
10
- var Coingecko = /** @class */ (function () {
11
- function Coingecko(host, proHost, logger, apiKey, customPlatformIdMap) {
9
+ export class Coingecko {
10
+ host;
11
+ proHost;
12
+ logger;
13
+ apiKey;
14
+ customPlatformIdMap;
15
+ static instance;
16
+ prices;
17
+ pricesBySymbol;
18
+ _maxPriceAge = 300; // seconds
19
+ // Retry configuration.
20
+ retryDelay = 1;
21
+ numRetries = 0; // Most failures are due to 429 rate-limiting, so there is no point in retrying.
22
+ basicApiTimeout = 500; // ms
23
+ platformIdMap = new Map(); // chainId => platform_id (137 => "polygon-pos")
24
+ tokenIdMap = {}; // coinGeckoId => { platform_id : "tokenAddress":}
25
+ static get(logger, apiKey, customPlatformIdMap) {
26
+ if (!this.instance)
27
+ this.instance = new Coingecko("https://api.coingecko.com/api/v3", "https://pro-api.coingecko.com/api/v3", logger, apiKey, customPlatformIdMap);
28
+ return this.instance;
29
+ }
30
+ get maxPriceAge() {
31
+ return this._maxPriceAge;
32
+ }
33
+ set maxPriceAge(age) {
34
+ assert(age >= 0);
35
+ this.logger.debug({
36
+ at: "Coingecko#maxPriceAge",
37
+ message: `Setting maxPriceAge (S) ${this._maxPriceAge} => ${age}.`,
38
+ });
39
+ this._maxPriceAge = age;
40
+ }
41
+ constructor(host, proHost, logger, apiKey, customPlatformIdMap) {
12
42
  this.host = host;
13
43
  this.proHost = proHost;
14
44
  this.logger = logger;
15
45
  this.apiKey = apiKey;
16
46
  this.customPlatformIdMap = customPlatformIdMap;
17
- this._maxPriceAge = 300; // seconds
18
- // Retry configuration.
19
- this.retryDelay = 1;
20
- this.numRetries = 0; // Most failures are due to 429 rate-limiting, so there is no point in retrying.
21
- this.basicApiTimeout = 500; // ms
22
- this.platformIdMap = new Map(); // chainId => platform_id (137 => "polygon-pos")
23
- this.tokenIdMap = {}; // coinGeckoId => { platform_id : "tokenAddress":}
24
47
  this.prices = {};
25
48
  this.pricesBySymbol = {};
26
49
  }
27
- Coingecko.get = function (logger, apiKey, customPlatformIdMap) {
28
- if (!this.instance)
29
- this.instance = new Coingecko("https://api.coingecko.com/api/v3", "https://pro-api.coingecko.com/api/v3", logger, apiKey, customPlatformIdMap);
30
- return this.instance;
31
- };
32
- Object.defineProperty(Coingecko.prototype, "maxPriceAge", {
33
- get: function () {
34
- return this._maxPriceAge;
35
- },
36
- set: function (age) {
37
- assert(age >= 0);
38
- this.logger.debug({
39
- at: "Coingecko#maxPriceAge",
40
- message: "Setting maxPriceAge (S) ".concat(this._maxPriceAge, " => ").concat(age, "."),
50
+ async getPlatformId(chainId) {
51
+ let id = this.platformIdMap.get(chainId);
52
+ if (id) {
53
+ return id;
54
+ }
55
+ const platforms = await this.getPlatforms();
56
+ this.platformIdMap = new Map(platforms.filter((chain) => Boolean(chain.chain_identifier)).map((chain) => [chain.chain_identifier, chain.id]));
57
+ // Extend the platformIdMap with any custom platform ids
58
+ if (this.customPlatformIdMap) {
59
+ Object.entries(this.customPlatformIdMap).forEach(([chainId, platformId]) => {
60
+ this.platformIdMap.set(Number(chainId), platformId);
41
61
  });
42
- this._maxPriceAge = age;
43
- },
44
- enumerable: false,
45
- configurable: true
46
- });
47
- Coingecko.prototype.getPlatformId = function (chainId) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var id, platforms;
50
- var _this = this;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
53
- case 0:
54
- id = this.platformIdMap.get(chainId);
55
- if (id) {
56
- return [2 /*return*/, id];
57
- }
58
- return [4 /*yield*/, this.getPlatforms()];
59
- case 1:
60
- platforms = _a.sent();
61
- this.platformIdMap = new Map(platforms.filter(function (chain) { return Boolean(chain.chain_identifier); }).map(function (chain) { return [chain.chain_identifier, chain.id]; }));
62
- // Extend the platformIdMap with any custom platform ids
63
- if (this.customPlatformIdMap) {
64
- Object.entries(this.customPlatformIdMap).forEach(function (_a) {
65
- var chainId = _a[0], platformId = _a[1];
66
- _this.platformIdMap.set(Number(chainId), platformId);
67
- });
68
- }
69
- id = this.platformIdMap.get(chainId);
70
- if (!id) {
71
- this.logger.error({
72
- message: "Coingecko does not support chain with id ".concat(chainId),
73
- at: "Coingecko#getPlatformId",
74
- });
75
- throw new Error("Coingecko does not support chain with id ".concat(chainId));
76
- }
77
- return [2 /*return*/, id];
78
- }
62
+ }
63
+ id = this.platformIdMap.get(chainId);
64
+ if (!id) {
65
+ this.logger.error({
66
+ message: `Coingecko does not support chain with id ${chainId}`,
67
+ at: "Coingecko#getPlatformId",
79
68
  });
80
- });
81
- };
69
+ throw new Error(`Coingecko does not support chain with id ${chainId}`);
70
+ }
71
+ return id;
72
+ }
82
73
  // for tokens not found in our constants, we can attempt to fetch the id from coingecko itself
83
- Coingecko.prototype.getCoingeckoTokenId = function (address, chainId) {
84
- return __awaiter(this, void 0, void 0, function () {
85
- var id, platformId, message;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- try {
90
- id = getCoingeckoTokenIdByAddress(address, chainId);
91
- return [2 /*return*/, 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 /*yield*/, this.getPlatformId(chainId)];
100
- case 1:
101
- platformId = _a.sent();
102
- id = this.getTokenIdFromAddress(address, platformId);
103
- if (id) {
104
- return [2 /*return*/, id];
105
- }
106
- return [4 /*yield*/, 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 /*return*/, id];
119
- }
74
+ async getCoingeckoTokenId(address, chainId) {
75
+ let id;
76
+ try {
77
+ id = getCoingeckoTokenIdByAddress(address, chainId);
78
+ return id;
79
+ }
80
+ catch (error) {
81
+ this.logger.warn({
82
+ at: "Coingecko#getCoingeckoTokenIdByAddress",
83
+ message: `Token with address ${address} not found in constants. Attempting to fetch ID from coingecko API...`,
120
84
  });
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 __awaiter(this, void 0, void 0, function () {
133
- var rawTokenList;
134
- return __generator(this, function (_a) {
135
- switch (_a.label) {
136
- case 0: return [4 /*yield*/, 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 /*return*/, this.tokenIdMap];
143
- }
85
+ }
86
+ const platformId = await this.getPlatformId(chainId);
87
+ id = this.getTokenIdFromAddress(address, platformId);
88
+ if (id) {
89
+ return id;
90
+ }
91
+ await this.updateTokenMap();
92
+ id = this.getTokenIdFromAddress(address, platformId);
93
+ if (!id) {
94
+ const message = `Coin with address ${address} does not exist on chain with id ${chainId}`;
95
+ this.logger.error({
96
+ at: "Coingecko#getCoingeckoTokenIdByAddress",
97
+ message,
144
98
  });
145
- });
146
- };
99
+ throw new Error(message);
100
+ }
101
+ return id;
102
+ }
103
+ getTokenIdFromAddress(address, platformId) {
104
+ return Object.entries(this.tokenIdMap).find(([_, value]) => Boolean(value?.[platformId]?.toLowerCase() === address.toLowerCase()))?.[0];
105
+ }
106
+ async updateTokenMap() {
107
+ const rawTokenList = await this.call("coins/list?include_platform=true");
108
+ this.tokenIdMap = Object.fromEntries(rawTokenList
109
+ .filter((token) => Boolean(Object.values(token?.platforms)?.length > 0))
110
+ .map((token) => [token.id, token.platforms]));
111
+ return this.tokenIdMap;
112
+ }
147
113
  // Fetch historic prices for a `contract` denominated in `currency` between timestamp `from` and `to`. Note timestamps
148
114
  // are assumed to be js timestamps and are converted to unixtimestamps by dividing by 1000.
149
- Coingecko.prototype.getHistoricContractPrices = function (contract_1, from_1, to_1) {
150
- return __awaiter(this, arguments, void 0, function (contract, from, to, currency) {
151
- var _from, _to, result;
152
- if (currency === void 0) { currency = "usd"; }
153
- return __generator(this, function (_a) {
154
- switch (_a.label) {
155
- case 0:
156
- assert(contract, "requires contract address");
157
- assert(currency, "requires currency symbol");
158
- assert(from, "requires from timestamp");
159
- assert(to, "requires to timestamp");
160
- _from = msToS(from);
161
- _to = msToS(to);
162
- return [4 /*yield*/, this.call("coins/ethereum/contract/".concat(contract.toLowerCase(), "/market_chart/range/?vs_currency=").concat(currency, "&from=").concat(_from, "&to=").concat(_to))];
163
- case 1:
164
- result = _a.sent();
165
- // fyi timestamps are returned in ms in contrast to the current price endpoint
166
- if (result.prices)
167
- return [2 /*return*/, result.prices];
168
- throw new Error("Something went wrong fetching coingecko prices!");
169
- }
170
- });
171
- });
172
- };
115
+ async getHistoricContractPrices(contract, from, to, currency = "usd") {
116
+ assert(contract, "requires contract address");
117
+ assert(currency, "requires currency symbol");
118
+ assert(from, "requires from timestamp");
119
+ assert(to, "requires to timestamp");
120
+ const _from = msToS(from);
121
+ const _to = msToS(to);
122
+ const result = await this.call(`coins/ethereum/contract/${contract.toLowerCase()}/market_chart/range/?vs_currency=${currency}&from=${_from}&to=${_to}`);
123
+ // fyi timestamps are returned in ms in contrast to the current price endpoint
124
+ if (result.prices)
125
+ return result.prices;
126
+ throw new Error("Something went wrong fetching coingecko prices!");
127
+ }
173
128
  /**
174
129
  * Get the current price of a token denominated in `currency`.
175
130
  * @param contractAddress The L1 token address to fetch the price for.
@@ -178,253 +133,177 @@ var Coingecko = /** @class */ (function () {
178
133
  * @returns The price of the token at the given date.
179
134
  * @throws If today is selected and it is before 3am UTC or if the price is not found.
180
135
  */
181
- Coingecko.prototype.getContractHistoricDayPrice = function (contractAddress_1, date_1) {
182
- return __awaiter(this, arguments, void 0, function (contractAddress, date, currency, chainId) {
183
- var coingeckoTokenIdentifier, url, queryParams, result, price;
184
- var _a, _b;
185
- if (currency === void 0) { currency = "usd"; }
186
- if (chainId === void 0) { chainId = 1; }
187
- return __generator(this, function (_c) {
188
- switch (_c.label) {
189
- case 0: return [4 /*yield*/, this.getCoingeckoTokenId(contractAddress, chainId)];
190
- case 1:
191
- coingeckoTokenIdentifier = _c.sent();
192
- assert(date, "Requires date string");
193
- url = "coins/".concat(coingeckoTokenIdentifier, "/history");
194
- queryParams = {
195
- date: date,
196
- localization: "false",
197
- };
198
- return [4 /*yield*/, this.call("".concat(url, "?").concat(new URLSearchParams(queryParams).toString()))];
199
- case 2:
200
- result = _c.sent();
201
- 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];
202
- assert(price, "No price found for ".concat(contractAddress, " on ").concat(date));
203
- return [2 /*return*/, price];
204
- }
205
- });
206
- });
207
- };
208
- Coingecko.prototype.getContractDetails = function (contract_address, platform_id) {
209
- if (platform_id === void 0) { platform_id = "ethereum"; }
210
- return this.call("coins/".concat(platform_id, "/contract/").concat(contract_address.toLowerCase()));
211
- };
212
- Coingecko.prototype.getCurrentPriceByContract = function (contractAddress_1) {
213
- return __awaiter(this, arguments, void 0, function (contractAddress, currency, chainId) {
214
- var platform_id, priceCache, tokenPrice;
215
- if (currency === void 0) { currency = "usd"; }
216
- if (chainId === void 0) { chainId = 1; }
217
- return __generator(this, function (_a) {
218
- switch (_a.label) {
219
- case 0: return [4 /*yield*/, this.getPlatformId(chainId)];
220
- case 1:
221
- platform_id = _a.sent();
222
- priceCache = this.getPriceCache(currency, platform_id);
223
- tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
224
- if (!(tokenPrice === undefined)) return [3 /*break*/, 3];
225
- return [4 /*yield*/, this.getContractPrices([contractAddress], currency, platform_id)];
226
- case 2:
227
- _a.sent();
228
- tokenPrice = priceCache[contractAddress];
229
- _a.label = 3;
230
- case 3:
231
- assert(tokenPrice !== undefined);
232
- return [2 /*return*/, [tokenPrice.timestamp.toString(), tokenPrice.price]];
233
- }
234
- });
235
- });
236
- };
237
- Coingecko.prototype.getCurrentPriceById = function (contractAddress_1) {
238
- return __awaiter(this, arguments, void 0, function (contractAddress, currency, chainId) {
239
- var platform_id, priceCache, tokenPrice, coingeckoId, result, cgPrice, errMsg;
240
- if (currency === void 0) { currency = "usd"; }
241
- if (chainId === void 0) { chainId = 1; }
242
- return __generator(this, function (_a) {
243
- switch (_a.label) {
244
- case 0: return [4 /*yield*/, this.getPlatformId(chainId)];
245
- case 1:
246
- platform_id = _a.sent();
247
- priceCache = this.getPriceCache(currency, platform_id);
248
- tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
249
- if (!(tokenPrice === undefined)) return [3 /*break*/, 4];
250
- return [4 /*yield*/, this.getCoingeckoTokenId(contractAddress, chainId)];
251
- case 2:
252
- coingeckoId = _a.sent();
253
- return [4 /*yield*/, this.call("simple/price?ids=".concat(coingeckoId, "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
254
- case 3:
255
- result = _a.sent();
256
- cgPrice = result === null || result === void 0 ? void 0 : result[coingeckoId];
257
- if (cgPrice === undefined || !(cgPrice === null || cgPrice === void 0 ? void 0 : cgPrice[currency])) {
258
- errMsg = "No price found for ".concat(coingeckoId);
259
- this.logger.debug({
260
- at: "Coingecko#getCurrentPriceById",
261
- message: errMsg,
262
- });
263
- throw new Error(errMsg);
264
- }
265
- else {
266
- this.updatePriceCache(cgPrice, contractAddress, currency, platform_id);
267
- }
268
- _a.label = 4;
269
- case 4:
270
- tokenPrice = priceCache[contractAddress];
271
- assert(tokenPrice !== undefined);
272
- return [2 /*return*/, [tokenPrice.timestamp.toString(), tokenPrice.price]];
273
- }
274
- });
275
- });
276
- };
277
- Coingecko.prototype.getCurrentPriceBySymbol = function (symbol_1) {
278
- return __awaiter(this, arguments, void 0, function (symbol, currency) {
279
- var tokenPrice, result, cgPrice, errMsg;
280
- if (currency === void 0) { currency = "usd"; }
281
- return __generator(this, function (_a) {
282
- switch (_a.label) {
283
- case 0:
284
- tokenPrice = this.getCachedSymbolPrice(symbol, currency);
285
- if (!(tokenPrice === undefined)) return [3 /*break*/, 2];
286
- return [4 /*yield*/, this.call("simple/price?symbols=".concat(symbol, "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
287
- case 1:
288
- result = _a.sent();
289
- cgPrice = (result === null || result === void 0 ? void 0 : result[symbol.toLowerCase()]) || (result === null || result === void 0 ? void 0 : result[symbol.toUpperCase()]);
290
- if (cgPrice === undefined || !(cgPrice === null || cgPrice === void 0 ? void 0 : cgPrice[currency])) {
291
- errMsg = "Failed to retrieve ".concat(symbol, "/").concat(currency, " price via Coingecko API");
292
- this.logger.debug({
293
- at: "Coingecko#getCurrentPriceBySymbol",
294
- message: errMsg,
295
- });
296
- throw new Error(errMsg);
297
- }
298
- else {
299
- this.updatePriceCacheBySymbol(cgPrice, symbol, currency);
300
- }
301
- _a.label = 2;
302
- case 2:
303
- tokenPrice = this.getCachedSymbolPrice(symbol, currency);
304
- assert(tokenPrice !== undefined);
305
- return [2 /*return*/, [tokenPrice.timestamp.toString(), tokenPrice.price]];
306
- }
307
- });
308
- });
309
- };
136
+ async getContractHistoricDayPrice(contractAddress, date, currency = "usd", chainId = 1) {
137
+ const coingeckoTokenIdentifier = await this.getCoingeckoTokenId(contractAddress, chainId);
138
+ assert(date, "Requires date string");
139
+ // Build the path for the Coingecko API request
140
+ const url = `coins/${coingeckoTokenIdentifier}/history`;
141
+ // Build the query parameters for the Coingecko API request
142
+ const queryParams = {
143
+ date,
144
+ localization: "false",
145
+ };
146
+ // Grab the result - parse out price, market cap, total volume, and timestamp
147
+ const result = await this.call(`${url}?${new URLSearchParams(queryParams).toString()}`);
148
+ const price = result?.market_data?.current_price?.[currency];
149
+ assert(price, `No price found for ${contractAddress} on ${date}`);
150
+ return price;
151
+ }
152
+ getContractDetails(contract_address, platform_id = "ethereum") {
153
+ return this.call(`coins/${platform_id}/contract/${contract_address.toLowerCase()}`);
154
+ }
155
+ async getCurrentPriceByContract(contractAddress, currency = "usd", chainId = 1) {
156
+ const platform_id = await this.getPlatformId(chainId);
157
+ const priceCache = this.getPriceCache(currency, platform_id);
158
+ let tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
159
+ if (tokenPrice === undefined) {
160
+ await this.getContractPrices([contractAddress], currency, platform_id);
161
+ tokenPrice = priceCache[contractAddress];
162
+ }
163
+ assert(tokenPrice !== undefined);
164
+ return [tokenPrice.timestamp.toString(), tokenPrice.price];
165
+ }
166
+ async getCurrentPriceById(contractAddress, currency = "usd", chainId = 1) {
167
+ const platform_id = await this.getPlatformId(chainId);
168
+ const priceCache = this.getPriceCache(currency, platform_id);
169
+ let tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
170
+ if (tokenPrice === undefined) {
171
+ const coingeckoId = await this.getCoingeckoTokenId(contractAddress, chainId);
172
+ // Build the path for the Coingecko API request
173
+ const result = await this.call(`simple/price?ids=${coingeckoId}&vs_currencies=${currency}&include_last_updated_at=true`);
174
+ const cgPrice = result?.[coingeckoId];
175
+ if (cgPrice === undefined || !cgPrice?.[currency]) {
176
+ const errMsg = `No price found for ${coingeckoId}`;
177
+ this.logger.debug({
178
+ at: "Coingecko#getCurrentPriceById",
179
+ message: errMsg,
180
+ });
181
+ throw new Error(errMsg);
182
+ }
183
+ else {
184
+ this.updatePriceCache(cgPrice, contractAddress, currency, platform_id);
185
+ }
186
+ }
187
+ tokenPrice = priceCache[contractAddress];
188
+ assert(tokenPrice !== undefined);
189
+ return [tokenPrice.timestamp.toString(), tokenPrice.price];
190
+ }
191
+ async getCurrentPriceBySymbol(symbol, currency = "usd") {
192
+ let tokenPrice = this.getCachedSymbolPrice(symbol, currency);
193
+ if (tokenPrice === undefined) {
194
+ const result = await this.call(`simple/price?symbols=${symbol}&vs_currencies=${currency}&include_last_updated_at=true`);
195
+ const cgPrice = result?.[symbol.toLowerCase()] || result?.[symbol.toUpperCase()];
196
+ if (cgPrice === undefined || !cgPrice?.[currency]) {
197
+ const errMsg = `Failed to retrieve ${symbol}/${currency} price via Coingecko API`;
198
+ this.logger.debug({
199
+ at: "Coingecko#getCurrentPriceBySymbol",
200
+ message: errMsg,
201
+ });
202
+ throw new Error(errMsg);
203
+ }
204
+ else {
205
+ this.updatePriceCacheBySymbol(cgPrice, symbol, currency);
206
+ }
207
+ }
208
+ tokenPrice = this.getCachedSymbolPrice(symbol, currency);
209
+ assert(tokenPrice !== undefined);
210
+ return [tokenPrice.timestamp.toString(), tokenPrice.price];
211
+ }
310
212
  // Return an array of spot prices for an array of collateral addresses in one async call. Note we might in future
311
213
  // This was adapted from packages/merkle-distributor/kpi-options-helpers/calculate-uma-tvl.ts
312
- Coingecko.prototype.getContractPrices = function (addresses_1) {
313
- return __awaiter(this, arguments, void 0, function (addresses, currency, platform_id) {
314
- var priceCache, contract_addresses, result, err_1, errMsg;
315
- var _this = this;
316
- if (currency === void 0) { currency = "usd"; }
317
- if (platform_id === void 0) { platform_id = "ethereum"; }
318
- return __generator(this, function (_a) {
319
- switch (_a.label) {
320
- case 0:
321
- priceCache = this.getPriceCache(currency, platform_id);
322
- // Pre-populate price cache with requested token addresses
323
- addresses.forEach(function (addr) {
324
- if (priceCache[addr] === undefined) {
325
- priceCache[addr] = { address: addr, price: 0, timestamp: 0 };
326
- }
327
- });
328
- contract_addresses = Object.keys(priceCache);
329
- assert(contract_addresses.length > 0, "Must supply at least 1 contract address");
330
- this.logger.debug({
331
- at: "Coingecko#getContractPrices",
332
- message: "Updating ".concat(platform_id, "/").concat(currency, " token prices."),
333
- tokens: contract_addresses,
334
- });
335
- result = {};
336
- _a.label = 1;
337
- case 1:
338
- _a.trys.push([1, 3, , 4]);
339
- return [4 /*yield*/, this.call("simple/token_price/".concat(platform_id, "?contract_addresses=").concat(contract_addresses.join("%2C"), "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
340
- case 2:
341
- // Coingecko expects a comma-delimited (%2c) list.
342
- result = _a.sent();
343
- return [3 /*break*/, 4];
344
- case 3:
345
- err_1 = _a.sent();
346
- errMsg = "Failed to retrieve ".concat(platform_id, "/").concat(currency, " prices (").concat(err_1, ")");
347
- this.logger.debug({
348
- at: "Coingecko#getContractPrices",
349
- message: errMsg,
350
- tokens: contract_addresses,
351
- });
352
- throw new Error(errMsg);
353
- case 4:
354
- // Note: contract_addresses is a reliable reference for the price lookup.
355
- // priceCache might have been updated subsequently by concurrent price requests.
356
- contract_addresses.forEach(function (addr) {
357
- var cgPrice = result[addr.toLowerCase()];
358
- if (cgPrice === undefined) {
359
- _this.logger.debug({
360
- at: "Coingecko#getContractPrices",
361
- message: "Token ".concat(addr, " not included in CoinGecko response."),
362
- });
363
- }
364
- else {
365
- _this.updatePriceCache(cgPrice, addr, currency, platform_id);
366
- }
367
- });
368
- return [2 /*return*/, addresses.map(function (addr) { return priceCache[addr]; })];
369
- }
214
+ async getContractPrices(addresses, currency = "usd", platform_id = "ethereum") {
215
+ const priceCache = this.getPriceCache(currency, platform_id);
216
+ // Pre-populate price cache with requested token addresses
217
+ addresses.forEach((addr) => {
218
+ if (priceCache[addr] === undefined) {
219
+ priceCache[addr] = { address: addr, price: 0, timestamp: 0 };
220
+ }
221
+ });
222
+ // Collect all known token addresses (requested + other cached).
223
+ const contract_addresses = Object.keys(priceCache);
224
+ assert(contract_addresses.length > 0, "Must supply at least 1 contract address");
225
+ this.logger.debug({
226
+ at: "Coingecko#getContractPrices",
227
+ message: `Updating ${platform_id}/${currency} token prices.`,
228
+ tokens: contract_addresses,
229
+ });
230
+ let result = {};
231
+ try {
232
+ // Coingecko expects a comma-delimited (%2c) list.
233
+ result = await this.call(`simple/token_price/${platform_id}?contract_addresses=${contract_addresses.join("%2C")}&vs_currencies=${currency}&include_last_updated_at=true`);
234
+ }
235
+ catch (err) {
236
+ const errMsg = `Failed to retrieve ${platform_id}/${currency} prices (${err})`;
237
+ this.logger.debug({
238
+ at: "Coingecko#getContractPrices",
239
+ message: errMsg,
240
+ tokens: contract_addresses,
370
241
  });
242
+ throw new Error(errMsg);
243
+ }
244
+ // Note: contract_addresses is a reliable reference for the price lookup.
245
+ // priceCache might have been updated subsequently by concurrent price requests.
246
+ contract_addresses.forEach((addr) => {
247
+ const cgPrice = result[addr.toLowerCase()];
248
+ if (cgPrice === undefined) {
249
+ this.logger.debug({
250
+ at: "Coingecko#getContractPrices",
251
+ message: `Token ${addr} not included in CoinGecko response.`,
252
+ });
253
+ }
254
+ else {
255
+ this.updatePriceCache(cgPrice, addr, currency, platform_id);
256
+ }
371
257
  });
372
- };
373
- Coingecko.prototype.getPlatforms = function () {
258
+ return addresses.map((addr) => priceCache[addr]);
259
+ }
260
+ getPlatforms() {
374
261
  return this.call("asset_platforms");
375
- };
376
- Coingecko.prototype.call = function (path) {
377
- var _this = this;
378
- var sendRequest = function () { return __awaiter(_this, void 0, void 0, function () {
379
- var proHost, err_2;
380
- return __generator(this, function (_a) {
381
- switch (_a.label) {
382
- case 0:
383
- proHost = this.proHost;
384
- if (!(this.apiKey === undefined)) return [3 /*break*/, 2];
385
- return [4 /*yield*/, this._callBasic(path)];
386
- case 1: return [2 /*return*/, (_a.sent())];
387
- case 2:
388
- _a.trys.push([2, 4, , 6]);
389
- return [4 /*yield*/, this._callBasic(path, this.basicApiTimeout)];
390
- case 3: return [2 /*return*/, (_a.sent())];
391
- case 4:
392
- err_2 = _a.sent();
393
- this.logger.debug({
394
- at: "sdk/coingecko",
395
- message: "Basic CG url request failed, falling back to CG PRO host ".concat(proHost),
396
- errMessage: err_2.message,
397
- });
398
- return [4 /*yield*/, this._callPro(path)];
399
- case 5: return [2 /*return*/, _a.sent()];
400
- case 6: return [2 /*return*/];
401
- }
402
- });
403
- }); };
262
+ }
263
+ call(path) {
264
+ const sendRequest = async () => {
265
+ const { proHost } = this;
266
+ // If no pro api key, only send basic request:
267
+ if (this.apiKey === undefined) {
268
+ return (await this._callBasic(path));
269
+ }
270
+ // If pro api key, try basic and use pro as fallback.
271
+ try {
272
+ return (await this._callBasic(path, this.basicApiTimeout));
273
+ }
274
+ catch (err) {
275
+ this.logger.debug({
276
+ at: "sdk/coingecko",
277
+ message: `Basic CG url request failed, falling back to CG PRO host ${proHost}`,
278
+ errMessage: err.message,
279
+ });
280
+ return await this._callPro(path);
281
+ }
282
+ };
404
283
  // Note: If a pro API key is configured, there is no need to retry as the Pro API will act as the basic's fall back.
405
284
  return retry(sendRequest, this.apiKey === undefined ? this.numRetries : 0, this.retryDelay);
406
- };
407
- Coingecko.prototype.getPriceCache = function (currency, platform_id) {
285
+ }
286
+ getPriceCache(currency, platform_id) {
408
287
  if (this.prices[platform_id] === undefined)
409
288
  this.prices[platform_id] = {};
410
289
  if (this.prices[platform_id][currency] === undefined)
411
290
  this.prices[platform_id][currency] = {};
412
291
  return this.prices[platform_id][currency];
413
- };
414
- Coingecko.prototype.getPriceCacheBySymbol = function (symbol) {
292
+ }
293
+ getPriceCacheBySymbol(symbol) {
415
294
  if (this.pricesBySymbol[symbol] === undefined)
416
295
  this.pricesBySymbol[symbol] = {};
417
296
  return this.pricesBySymbol[symbol];
418
- };
419
- Coingecko.prototype.getCachedAddressPrice = function (contractAddress, currency, platform_id) {
420
- var priceCache = this.getPriceCache(currency, platform_id);
421
- var now = msToS(Date.now());
422
- var tokenPrice = priceCache[contractAddress];
297
+ }
298
+ getCachedAddressPrice(contractAddress, currency, platform_id) {
299
+ const priceCache = this.getPriceCache(currency, platform_id);
300
+ const now = msToS(Date.now());
301
+ const tokenPrice = priceCache[contractAddress];
423
302
  if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
424
303
  if (this.maxPriceAge > 0) {
425
304
  this.logger.debug({
426
305
  at: "Coingecko#getCachedAddressPrice",
427
- message: "Cache miss on ".concat(platform_id, "/").concat(currency, " for ").concat(contractAddress),
306
+ message: `Cache miss on ${platform_id}/${currency} for ${contractAddress}`,
428
307
  maxPriceAge: this.maxPriceAge,
429
308
  tokenPrice: tokenPrice,
430
309
  });
@@ -434,23 +313,23 @@ var Coingecko = /** @class */ (function () {
434
313
  else {
435
314
  this.logger.debug({
436
315
  at: "Coingecko#getCachedAddressPrice",
437
- message: "Cache hit on token ".concat(contractAddress, " (age ").concat(now - tokenPrice.timestamp, " S)."),
316
+ message: `Cache hit on token ${contractAddress} (age ${now - tokenPrice.timestamp} S).`,
438
317
  price: tokenPrice,
439
318
  });
440
319
  return tokenPrice;
441
320
  }
442
- };
443
- Coingecko.prototype.getCachedSymbolPrice = function (symbol, currency) {
444
- var priceCache = this.getPriceCacheBySymbol(symbol);
445
- var now = msToS(Date.now());
446
- var tokenPrice = priceCache[currency];
321
+ }
322
+ getCachedSymbolPrice(symbol, currency) {
323
+ const priceCache = this.getPriceCacheBySymbol(symbol);
324
+ const now = msToS(Date.now());
325
+ const tokenPrice = priceCache[currency];
447
326
  if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
448
327
  return undefined;
449
328
  }
450
329
  return tokenPrice;
451
- };
452
- Coingecko.prototype.updatePriceCache = function (cgPrice, contractAddress, currency, platform_id) {
453
- var priceCache = this.getPriceCache(currency, platform_id);
330
+ }
331
+ updatePriceCache(cgPrice, contractAddress, currency, platform_id) {
332
+ const priceCache = this.getPriceCache(currency, platform_id);
454
333
  if (priceCache[contractAddress] === undefined) {
455
334
  priceCache[contractAddress] = { address: contractAddress, price: 0, timestamp: 0 };
456
335
  }
@@ -462,19 +341,19 @@ var Coingecko = /** @class */ (function () {
462
341
  };
463
342
  this.logger.debug({
464
343
  at: "Coingecko#updatePriceCache",
465
- message: "Updated ".concat(platform_id, "/").concat(currency, "/").concat(contractAddress, " token price cache."),
344
+ message: `Updated ${platform_id}/${currency}/${contractAddress} token price cache.`,
466
345
  });
467
346
  }
468
347
  else {
469
348
  this.logger.debug({
470
349
  at: "Coingecko#updatePriceCache",
471
- message: "No new price available for token ".concat(contractAddress, "."),
350
+ message: `No new price available for token ${contractAddress}.`,
472
351
  token: cgPrice,
473
352
  });
474
353
  }
475
- };
476
- Coingecko.prototype.updatePriceCacheBySymbol = function (cgPrice, symbol, currency) {
477
- var priceCache = this.getPriceCacheBySymbol(symbol);
354
+ }
355
+ updatePriceCacheBySymbol(cgPrice, symbol, currency) {
356
+ const priceCache = this.getPriceCacheBySymbol(symbol);
478
357
  if (priceCache[currency] === undefined) {
479
358
  priceCache[currency] = { price: 0, timestamp: 0 };
480
359
  }
@@ -485,64 +364,40 @@ var Coingecko = /** @class */ (function () {
485
364
  };
486
365
  this.logger.debug({
487
366
  at: "Coingecko#updatePriceCacheBySymbol",
488
- message: "Updated ".concat(symbol, "/").concat(currency, " token price cache."),
367
+ message: `Updated ${symbol}/${currency} token price cache.`,
489
368
  });
490
369
  }
491
370
  else {
492
371
  this.logger.debug({
493
372
  at: "Coingecko#updatePriceCacheBySymbol",
494
- message: "No new price available for symbol ".concat(symbol, "."),
373
+ message: `No new price available for symbol ${symbol}.`,
495
374
  token: cgPrice,
496
375
  });
497
376
  }
498
- };
499
- Coingecko.prototype._callBasic = function (path, timeout) {
500
- return __awaiter(this, void 0, void 0, function () {
501
- var url, result, err_3, msg;
502
- return __generator(this, function (_a) {
503
- switch (_a.label) {
504
- case 0:
505
- url = "".concat(this.host, "/").concat(path);
506
- _a.label = 1;
507
- case 1:
508
- _a.trys.push([1, 3, , 4]);
509
- return [4 /*yield*/, axios(url, { timeout: timeout })];
510
- case 2:
511
- result = _a.sent();
512
- return [2 /*return*/, result.data];
513
- case 3:
514
- err_3 = _a.sent();
515
- msg = get(err_3, "response.data.error", get(err_3, "response.statusText", err_3.message));
516
- throw new Error(msg);
517
- case 4: return [2 /*return*/];
518
- }
519
- });
520
- });
521
- };
522
- Coingecko.prototype._callPro = function (path) {
523
- return __awaiter(this, void 0, void 0, function () {
524
- var url, result, err_4, msg;
525
- return __generator(this, function (_a) {
526
- switch (_a.label) {
527
- case 0:
528
- url = "".concat(this.proHost, "/").concat(path);
529
- _a.label = 1;
530
- case 1:
531
- _a.trys.push([1, 3, , 4]);
532
- return [4 /*yield*/, axios(url, { params: { x_cg_pro_api_key: this.apiKey } })];
533
- case 2:
534
- result = _a.sent();
535
- return [2 /*return*/, result.data];
536
- case 3:
537
- err_4 = _a.sent();
538
- msg = get(err_4, "response.data.error", get(err_4, "response.statusText", err_4.message));
539
- throw new Error(msg);
540
- case 4: return [2 /*return*/];
541
- }
542
- });
543
- });
544
- };
545
- return Coingecko;
546
- }());
547
- export { Coingecko };
377
+ }
378
+ async _callBasic(path, timeout) {
379
+ const url = `${this.host}/${path}`;
380
+ try {
381
+ // Don't use timeout if there is no pro API to fallback to.
382
+ const result = await axios(url, { timeout });
383
+ return result.data;
384
+ }
385
+ catch (err) {
386
+ const msg = get(err, "response.data.error", get(err, "response.statusText", err.message));
387
+ throw new Error(msg);
388
+ }
389
+ }
390
+ async _callPro(path) {
391
+ const url = `${this.proHost}/${path}`;
392
+ try {
393
+ // Don't use timeout if there is no pro API to fallback to.
394
+ const result = await axios(url, { params: { x_cg_pro_api_key: this.apiKey } });
395
+ return result.data;
396
+ }
397
+ catch (err) {
398
+ const msg = get(err, "response.data.error", get(err, "response.statusText", err.message));
399
+ throw new Error(msg);
400
+ }
401
+ }
402
+ }
548
403
  //# sourceMappingURL=Coingecko.js.map