@across-protocol/sdk 4.3.111-alpha.4 → 4.3.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/dist/cjs/addressAggregator/adapters/abstract.js +64 -50
  2. package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
  3. package/dist/cjs/addressAggregator/adapters/bybit.js +29 -16
  4. package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
  5. package/dist/cjs/addressAggregator/adapters/env.js +15 -11
  6. package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
  7. package/dist/cjs/addressAggregator/adapters/file.js +45 -32
  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 +36 -22
  11. package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
  12. package/dist/cjs/addressAggregator/index.js +87 -57
  13. package/dist/cjs/addressAggregator/index.js.map +1 -1
  14. package/dist/cjs/apiClient/abstractClient.js +8 -9
  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 +29 -23
  18. package/dist/cjs/apiClient/mockedClient.js.map +1 -1
  19. package/dist/cjs/apiClient/productionClient.js +103 -65
  20. package/dist/cjs/apiClient/productionClient.js.map +1 -1
  21. package/dist/cjs/arch/evm/BlockUtils.js +208 -122
  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 +288 -134
  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 +49 -38
  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 +158 -102
  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 +1147 -708
  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 +236 -174
  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 +355 -166
  46. package/dist/cjs/arch/svm/utils.js.map +1 -1
  47. package/dist/cjs/caching/Arweave/ArweaveClient.js +246 -168
  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 +49 -40
  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 +18 -13
  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 +381 -302
  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 +83 -58
  61. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  62. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +900 -709
  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 +128 -95
  66. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  67. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +53 -48
  68. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  69. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +8 -10
  70. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  71. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +90 -67
  72. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  73. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +24 -46
  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 +708 -526
  77. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  78. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +179 -133
  79. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  80. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -124
  81. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  82. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +389 -357
  83. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  84. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +8 -9
  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 +67 -58
  90. package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
  91. package/dist/cjs/clients/mocks/MockEvents.js +52 -47
  92. package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
  93. package/dist/cjs/clients/mocks/MockHubPoolClient.js +185 -142
  94. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  95. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +192 -208
  96. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  97. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +143 -140
  98. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  99. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +73 -57
  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 +437 -285
  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 +30 -23
  106. package/dist/cjs/constants.js.map +1 -1
  107. package/dist/cjs/contracts/acrossConfigStore.js +48 -27
  108. package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
  109. package/dist/cjs/contracts/hubPool.js +20 -36
  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 +8 -6
  113. package/dist/cjs/contracts/utils.js.map +1 -1
  114. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +16 -7
  115. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  116. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +45 -26
  117. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  118. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +28 -16
  119. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  120. package/dist/cjs/gasPriceOracle/adapters/polygon.js +112 -73
  121. package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
  122. package/dist/cjs/gasPriceOracle/adapters/solana.js +33 -20
  123. package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
  124. package/dist/cjs/gasPriceOracle/oracle.js +104 -77
  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 +35 -33
  134. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  135. package/dist/cjs/lpFeeCalculator/rateModel.js +9 -7
  136. package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
  137. package/dist/cjs/merkleDistributor/MerkleDistributor.js +18 -20
  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 +100 -45
  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 +731 -464
  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 +100 -45
  148. package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
  149. package/dist/cjs/pool/uma/clients/erc20/client.js +16 -18
  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 +5 -4
  156. package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
  157. package/dist/cjs/pool/uma/utils.js +30 -11
  158. package/dist/cjs/pool/uma/utils.js.map +1 -1
  159. package/dist/cjs/priceClient/adapters/acrossApi.js +39 -22
  160. package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
  161. package/dist/cjs/priceClient/adapters/baseAdapter.js +73 -49
  162. package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
  163. package/dist/cjs/priceClient/adapters/coingecko.js +61 -34
  164. package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
  165. package/dist/cjs/priceClient/adapters/default.js +31 -16
  166. package/dist/cjs/priceClient/adapters/default.js.map +1 -1
  167. package/dist/cjs/priceClient/adapters/defiLlama.js +74 -40
  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 +159 -110
  172. package/dist/cjs/priceClient/priceClient.js.map +1 -1
  173. package/dist/cjs/providers/alchemy.js +19 -17
  174. package/dist/cjs/providers/alchemy.js.map +1 -1
  175. package/dist/cjs/providers/cachedProvider.js +129 -88
  176. package/dist/cjs/providers/cachedProvider.js.map +1 -1
  177. package/dist/cjs/providers/drpc.js +11 -9
  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 +12 -10
  181. package/dist/cjs/providers/infura.js.map +1 -1
  182. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +15 -7
  183. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  184. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -6
  185. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  186. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +15 -7
  187. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  188. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +66 -42
  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 +31 -29
  192. package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
  193. package/dist/cjs/providers/quicknode.js +21 -19
  194. package/dist/cjs/providers/quicknode.js.map +1 -1
  195. package/dist/cjs/providers/rateLimitedProvider.js +79 -64
  196. package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
  197. package/dist/cjs/providers/retryProvider.js +246 -163
  198. package/dist/cjs/providers/retryProvider.js.map +1 -1
  199. package/dist/cjs/providers/solana/baseRpcFactories.js +18 -14
  200. package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
  201. package/dist/cjs/providers/solana/cachedRpcFactory.js +112 -70
  202. package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
  203. package/dist/cjs/providers/solana/defaultRpcFactory.js +15 -8
  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 +191 -135
  207. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  208. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +90 -67
  209. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  210. package/dist/cjs/providers/solana/retryRpcFactory.js +79 -52
  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 +53 -31
  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 +28 -26
  219. package/dist/cjs/providers/utils.js.map +1 -1
  220. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +162 -108
  221. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  222. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +26 -14
  223. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  224. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +29 -20
  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 +137 -88
  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 +297 -199
  231. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  232. package/dist/cjs/typeguards/error.js +7 -5
  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 +144 -117
  236. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  237. package/dist/cjs/utils/ArrayUtils.js +78 -21
  238. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  239. package/dist/cjs/utils/BigNumberUtils.js +10 -9
  240. package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
  241. package/dist/cjs/utils/BlockExplorerUtils.js +30 -26
  242. package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
  243. package/dist/cjs/utils/BlockFinder.js +5 -2
  244. package/dist/cjs/utils/BlockFinder.js.map +1 -1
  245. package/dist/cjs/utils/BlockUtils.js +41 -24
  246. package/dist/cjs/utils/BlockUtils.js.map +1 -1
  247. package/dist/cjs/utils/BundleUtils.js +24 -21
  248. package/dist/cjs/utils/BundleUtils.js.map +1 -1
  249. package/dist/cjs/utils/CCTPUtils.js +126 -62
  250. package/dist/cjs/utils/CCTPUtils.js.map +1 -1
  251. package/dist/cjs/utils/CachingUtils.js +42 -20
  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 +99 -122
  256. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  257. package/dist/cjs/utils/EventUtils.js +70 -49
  258. package/dist/cjs/utils/EventUtils.js.map +1 -1
  259. package/dist/cjs/utils/FormattingUtils.js +32 -26
  260. package/dist/cjs/utils/FormattingUtils.js.map +1 -1
  261. package/dist/cjs/utils/HyperLiquidUtils.js +23 -10
  262. package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
  263. package/dist/cjs/utils/IPFSUtils.js +34 -16
  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 +12 -10
  268. package/dist/cjs/utils/LogUtils.js.map +1 -1
  269. package/dist/cjs/utils/Multicall.js +115 -56
  270. package/dist/cjs/utils/Multicall.js.map +1 -1
  271. package/dist/cjs/utils/NetworkUtils.js +28 -12
  272. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  273. package/dist/cjs/utils/NumberUtils.js +3 -1
  274. package/dist/cjs/utils/NumberUtils.js.map +1 -1
  275. package/dist/cjs/utils/ObjectUtils.js +41 -27
  276. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  277. package/dist/cjs/utils/Profiler.js +83 -80
  278. package/dist/cjs/utils/Profiler.js.map +1 -1
  279. package/dist/cjs/utils/ReviverUtils.js +9 -5
  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 +64 -41
  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 +22 -12
  291. package/dist/cjs/utils/abi/index.js.map +1 -1
  292. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +12 -9
  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 +53 -40
  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 +64 -48
  299. package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
  300. package/dist/esm/addressAggregator/adapters/bybit.js +29 -15
  301. package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
  302. package/dist/esm/addressAggregator/adapters/env.js +14 -9
  303. package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
  304. package/dist/esm/addressAggregator/adapters/file.js +43 -29
  305. package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
  306. package/dist/esm/addressAggregator/adapters/risklabs.js +35 -20
  307. package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
  308. package/dist/esm/addressAggregator/index.js +83 -52
  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 +9 -15
  313. package/dist/esm/apiClient/abstractClient.js.map +1 -1
  314. package/dist/esm/apiClient/mockedClient.js +26 -21
  315. package/dist/esm/apiClient/mockedClient.js.map +1 -1
  316. package/dist/esm/apiClient/productionClient.js +101 -61
  317. package/dist/esm/apiClient/productionClient.js.map +1 -1
  318. package/dist/esm/arch/evm/BlockUtils.js +217 -139
  319. package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
  320. package/dist/esm/arch/evm/SpokeUtils.js +289 -146
  321. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  322. package/dist/esm/arch/evm/utils/wait.js +46 -34
  323. package/dist/esm/arch/evm/utils/wait.js.map +1 -1
  324. package/dist/esm/arch/svm/BlockUtils.js +166 -118
  325. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  326. package/dist/esm/arch/svm/SpokeUtils.js +1150 -738
  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 +232 -172
  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 +345 -155
  335. package/dist/esm/arch/svm/utils.js.map +1 -1
  336. package/dist/esm/caching/Arweave/ArweaveClient.js +256 -182
  337. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  338. package/dist/esm/caching/IPFS/PinataIPFSClient.js +48 -47
  339. package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
  340. package/dist/esm/caching/Memory/MemoryCacheClient.js +19 -13
  341. package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
  342. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +408 -333
  343. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  344. package/dist/esm/clients/BaseAbstractClient.js +92 -66
  345. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  346. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +1054 -927
  347. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  348. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +131 -102
  349. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  350. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +59 -57
  351. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  352. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -7
  353. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  354. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +94 -75
  355. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  356. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +23 -45
  357. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  358. package/dist/esm/clients/HubPoolClient.js +740 -581
  359. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  360. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +178 -133
  361. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  362. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -126
  363. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  364. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +399 -372
  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 +64 -53
  373. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  374. package/dist/esm/clients/mocks/MockEvents.js +49 -42
  375. package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
  376. package/dist/esm/clients/mocks/MockHubPoolClient.js +182 -138
  377. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  378. package/dist/esm/clients/mocks/MockSpokePoolClient.js +188 -202
  379. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  380. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +132 -127
  381. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  382. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +69 -53
  383. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  384. package/dist/esm/coingecko/Coingecko.js +443 -298
  385. package/dist/esm/coingecko/Coingecko.js.map +1 -1
  386. package/dist/esm/constants.js +47 -40
  387. package/dist/esm/constants.js.map +1 -1
  388. package/dist/esm/contracts/acrossConfigStore.js +46 -24
  389. package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
  390. package/dist/esm/contracts/hubPool.js +18 -34
  391. package/dist/esm/contracts/hubPool.js.map +1 -1
  392. package/dist/esm/contracts/utils.js +5 -3
  393. package/dist/esm/contracts/utils.js.map +1 -1
  394. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +14 -6
  395. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  396. package/dist/esm/gasPriceOracle/adapters/ethereum.js +42 -22
  397. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  398. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +25 -13
  399. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  400. package/dist/esm/gasPriceOracle/adapters/polygon.js +108 -72
  401. package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
  402. package/dist/esm/gasPriceOracle/adapters/solana.js +31 -22
  403. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
  404. package/dist/esm/gasPriceOracle/oracle.js +96 -70
  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 +33 -30
  411. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  412. package/dist/esm/lpFeeCalculator/rateModel.js +9 -7
  413. package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
  414. package/dist/esm/merkleDistributor/MerkleDistributor.js +17 -18
  415. package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
  416. package/dist/esm/pool/TransactionManager.js +100 -45
  417. package/dist/esm/pool/TransactionManager.js.map +1 -1
  418. package/dist/esm/pool/poolClient.js +740 -479
  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 +100 -45
  423. package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
  424. package/dist/esm/pool/uma/clients/erc20/client.js +13 -15
  425. package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
  426. package/dist/esm/pool/uma/oracle/utils.js +3 -2
  427. package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
  428. package/dist/esm/pool/uma/utils.js +28 -9
  429. package/dist/esm/pool/uma/utils.js.map +1 -1
  430. package/dist/esm/priceClient/adapters/acrossApi.js +40 -21
  431. package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
  432. package/dist/esm/priceClient/adapters/baseAdapter.js +72 -46
  433. package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
  434. package/dist/esm/priceClient/adapters/coingecko.js +61 -33
  435. package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
  436. package/dist/esm/priceClient/adapters/default.js +31 -15
  437. package/dist/esm/priceClient/adapters/default.js.map +1 -1
  438. package/dist/esm/priceClient/adapters/defiLlama.js +73 -38
  439. package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
  440. package/dist/esm/priceClient/priceClient.js +158 -109
  441. package/dist/esm/priceClient/priceClient.js.map +1 -1
  442. package/dist/esm/providers/alchemy.js +18 -16
  443. package/dist/esm/providers/alchemy.js.map +1 -1
  444. package/dist/esm/providers/cachedProvider.js +134 -99
  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 +10 -8
  449. package/dist/esm/providers/drpc.js.map +1 -1
  450. package/dist/esm/providers/infura.js +11 -9
  451. package/dist/esm/providers/infura.js.map +1 -1
  452. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +15 -6
  453. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  454. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -5
  455. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  456. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +15 -6
  457. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  458. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +66 -41
  459. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  460. package/dist/esm/providers/mocks/mockEthersProvider.js +30 -27
  461. package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
  462. package/dist/esm/providers/quicknode.js +20 -18
  463. package/dist/esm/providers/quicknode.js.map +1 -1
  464. package/dist/esm/providers/rateLimitedProvider.js +80 -68
  465. package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
  466. package/dist/esm/providers/retryProvider.js +259 -186
  467. package/dist/esm/providers/retryProvider.js.map +1 -1
  468. package/dist/esm/providers/solana/baseRpcFactories.js +19 -13
  469. package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
  470. package/dist/esm/providers/solana/cachedRpcFactory.js +112 -75
  471. package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
  472. package/dist/esm/providers/solana/defaultRpcFactory.js +14 -6
  473. package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
  474. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +202 -149
  475. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  476. package/dist/esm/providers/solana/rateLimitedRpcFactory.js +90 -70
  477. package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  478. package/dist/esm/providers/solana/retryRpcFactory.js +74 -50
  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 +51 -28
  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 +20 -17
  487. package/dist/esm/providers/utils.js.map +1 -1
  488. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +152 -98
  489. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  490. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +26 -13
  491. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  492. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +19 -9
  493. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  494. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +128 -83
  495. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  496. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +299 -211
  497. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  498. package/dist/esm/typeguards/error.js +5 -3
  499. package/dist/esm/typeguards/error.js.map +1 -1
  500. package/dist/esm/utils/AddressUtils.js +147 -115
  501. package/dist/esm/utils/AddressUtils.js.map +1 -1
  502. package/dist/esm/utils/ArrayUtils.js +78 -21
  503. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  504. package/dist/esm/utils/BigNumberUtils.js +12 -11
  505. package/dist/esm/utils/BigNumberUtils.js.map +1 -1
  506. package/dist/esm/utils/BlockExplorerUtils.js +23 -19
  507. package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
  508. package/dist/esm/utils/BlockFinder.js +6 -2
  509. package/dist/esm/utils/BlockFinder.js.map +1 -1
  510. package/dist/esm/utils/BlockUtils.js +40 -31
  511. package/dist/esm/utils/BlockUtils.js.map +1 -1
  512. package/dist/esm/utils/BundleUtils.js +24 -21
  513. package/dist/esm/utils/BundleUtils.js.map +1 -1
  514. package/dist/esm/utils/CCTPUtils.js +123 -62
  515. package/dist/esm/utils/CCTPUtils.js.map +1 -1
  516. package/dist/esm/utils/CachingUtils.js +38 -17
  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 +98 -121
  521. package/dist/esm/utils/DepositUtils.js.map +1 -1
  522. package/dist/esm/utils/EventUtils.js +69 -52
  523. package/dist/esm/utils/EventUtils.js.map +1 -1
  524. package/dist/esm/utils/FormattingUtils.js +26 -20
  525. package/dist/esm/utils/FormattingUtils.js.map +1 -1
  526. package/dist/esm/utils/HyperLiquidUtils.js +22 -8
  527. package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
  528. package/dist/esm/utils/IPFSUtils.js +35 -16
  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 +12 -8
  533. package/dist/esm/utils/LogUtils.js.map +1 -1
  534. package/dist/esm/utils/Multicall.js +110 -50
  535. package/dist/esm/utils/Multicall.js.map +1 -1
  536. package/dist/esm/utils/NetworkUtils.js +28 -12
  537. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  538. package/dist/esm/utils/NumberUtils.js +3 -1
  539. package/dist/esm/utils/NumberUtils.js.map +1 -1
  540. package/dist/esm/utils/ObjectUtils.js +41 -27
  541. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  542. package/dist/esm/utils/Profiler.js +82 -77
  543. package/dist/esm/utils/Profiler.js.map +1 -1
  544. package/dist/esm/utils/ReviverUtils.js +7 -3
  545. package/dist/esm/utils/ReviverUtils.js.map +1 -1
  546. package/dist/esm/utils/SpokeUtils.js +78 -83
  547. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  548. package/dist/esm/utils/TokenUtils.js +57 -33
  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 +20 -10
  553. package/dist/esm/utils/abi/index.js.map +1 -1
  554. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +12 -8
  555. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  556. package/dist/esm/utils/common.js +52 -38
  557. package/dist/esm/utils/common.js.map +1 -1
  558. package/dist/types/constants.d.ts.map +1 -1
  559. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  560. package/dist/types/utils/Multicall.d.ts.map +1 -1
  561. package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
  562. package/package.json +3 -3
  563. package/src/constants.ts +1 -0
  564. package/src/gasPriceOracle/oracle.ts +1 -0
  565. package/src/utils/Multicall.ts +1 -0
  566. package/src/utils/NetworkUtils.ts +8 -1
@@ -1,3 +1,4 @@
1
+ import { __awaiter, __generator } from "tslib";
1
2
  import axios from "axios";
2
3
  import assert from "assert";
3
4
  import get from "lodash.get";
@@ -6,125 +7,169 @@ export function msToS(ms) {
6
7
  return Math.floor(ms / 1000);
7
8
  }
8
9
  // Singleton Coingecko class.
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) {
10
+ var Coingecko = /** @class */ (function () {
11
+ function Coingecko(host, proHost, logger, apiKey, customPlatformIdMap) {
42
12
  this.host = host;
43
13
  this.proHost = proHost;
44
14
  this.logger = logger;
45
15
  this.apiKey = apiKey;
46
16
  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":}
47
24
  this.prices = {};
48
25
  this.pricesBySymbol = {};
49
26
  }
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);
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, "."),
61
41
  });
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",
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
+ }
68
79
  });
69
- throw new Error(`Coingecko does not support chain with id ${chainId}`);
70
- }
71
- return id;
72
- }
80
+ });
81
+ };
73
82
  // for tokens not found in our constants, we can attempt to fetch the id from coingecko itself
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...`,
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
+ }
84
120
  });
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,
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
+ }
98
144
  });
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
- }
145
+ });
146
+ };
113
147
  // Fetch historic prices for a `contract` denominated in `currency` between timestamp `from` and `to`. Note timestamps
114
148
  // are assumed to be js timestamps and are converted to unixtimestamps by dividing by 1000.
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
- }
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
+ };
128
173
  /**
129
174
  * Get the current price of a token denominated in `currency`.
130
175
  * @param contractAddress The L1 token address to fetch the price for.
@@ -133,177 +178,253 @@ export class Coingecko {
133
178
  * @returns The price of the token at the given date.
134
179
  * @throws If today is selected and it is before 3am UTC or if the price is not found.
135
180
  */
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
- }
212
- // Return an array of spot prices for an array of collateral addresses in one async call. Note we might in future
213
- // This was adapted from packages/merkle-distributor/kpi-options-helpers/calculate-uma-tvl.ts
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
- }
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
+ });
221
206
  });
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,
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
+ });
229
235
  });
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,
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
+ }
241
274
  });
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
- }
257
275
  });
258
- return addresses.map((addr) => priceCache[addr]);
259
- }
260
- getPlatforms() {
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
+ };
310
+ // Return an array of spot prices for an array of collateral addresses in one async call. Note we might in future
311
+ // 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
+ }
370
+ });
371
+ });
372
+ };
373
+ Coingecko.prototype.getPlatforms = function () {
261
374
  return this.call("asset_platforms");
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
- };
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
+ }); };
283
404
  // 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.
284
405
  return retry(sendRequest, this.apiKey === undefined ? this.numRetries : 0, this.retryDelay);
285
- }
286
- getPriceCache(currency, platform_id) {
406
+ };
407
+ Coingecko.prototype.getPriceCache = function (currency, platform_id) {
287
408
  if (this.prices[platform_id] === undefined)
288
409
  this.prices[platform_id] = {};
289
410
  if (this.prices[platform_id][currency] === undefined)
290
411
  this.prices[platform_id][currency] = {};
291
412
  return this.prices[platform_id][currency];
292
- }
293
- getPriceCacheBySymbol(symbol) {
413
+ };
414
+ Coingecko.prototype.getPriceCacheBySymbol = function (symbol) {
294
415
  if (this.pricesBySymbol[symbol] === undefined)
295
416
  this.pricesBySymbol[symbol] = {};
296
417
  return this.pricesBySymbol[symbol];
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];
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];
302
423
  if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
303
424
  if (this.maxPriceAge > 0) {
304
425
  this.logger.debug({
305
426
  at: "Coingecko#getCachedAddressPrice",
306
- message: `Cache miss on ${platform_id}/${currency} for ${contractAddress}`,
427
+ message: "Cache miss on ".concat(platform_id, "/").concat(currency, " for ").concat(contractAddress),
307
428
  maxPriceAge: this.maxPriceAge,
308
429
  tokenPrice: tokenPrice,
309
430
  });
@@ -313,23 +434,23 @@ export class Coingecko {
313
434
  else {
314
435
  this.logger.debug({
315
436
  at: "Coingecko#getCachedAddressPrice",
316
- message: `Cache hit on token ${contractAddress} (age ${now - tokenPrice.timestamp} S).`,
437
+ message: "Cache hit on token ".concat(contractAddress, " (age ").concat(now - tokenPrice.timestamp, " S)."),
317
438
  price: tokenPrice,
318
439
  });
319
440
  return tokenPrice;
320
441
  }
321
- }
322
- getCachedSymbolPrice(symbol, currency) {
323
- const priceCache = this.getPriceCacheBySymbol(symbol);
324
- const now = msToS(Date.now());
325
- const tokenPrice = priceCache[currency];
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];
326
447
  if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
327
448
  return undefined;
328
449
  }
329
450
  return tokenPrice;
330
- }
331
- updatePriceCache(cgPrice, contractAddress, currency, platform_id) {
332
- const priceCache = this.getPriceCache(currency, platform_id);
451
+ };
452
+ Coingecko.prototype.updatePriceCache = function (cgPrice, contractAddress, currency, platform_id) {
453
+ var priceCache = this.getPriceCache(currency, platform_id);
333
454
  if (priceCache[contractAddress] === undefined) {
334
455
  priceCache[contractAddress] = { address: contractAddress, price: 0, timestamp: 0 };
335
456
  }
@@ -341,19 +462,19 @@ export class Coingecko {
341
462
  };
342
463
  this.logger.debug({
343
464
  at: "Coingecko#updatePriceCache",
344
- message: `Updated ${platform_id}/${currency}/${contractAddress} token price cache.`,
465
+ message: "Updated ".concat(platform_id, "/").concat(currency, "/").concat(contractAddress, " token price cache."),
345
466
  });
346
467
  }
347
468
  else {
348
469
  this.logger.debug({
349
470
  at: "Coingecko#updatePriceCache",
350
- message: `No new price available for token ${contractAddress}.`,
471
+ message: "No new price available for token ".concat(contractAddress, "."),
351
472
  token: cgPrice,
352
473
  });
353
474
  }
354
- }
355
- updatePriceCacheBySymbol(cgPrice, symbol, currency) {
356
- const priceCache = this.getPriceCacheBySymbol(symbol);
475
+ };
476
+ Coingecko.prototype.updatePriceCacheBySymbol = function (cgPrice, symbol, currency) {
477
+ var priceCache = this.getPriceCacheBySymbol(symbol);
357
478
  if (priceCache[currency] === undefined) {
358
479
  priceCache[currency] = { price: 0, timestamp: 0 };
359
480
  }
@@ -364,40 +485,64 @@ export class Coingecko {
364
485
  };
365
486
  this.logger.debug({
366
487
  at: "Coingecko#updatePriceCacheBySymbol",
367
- message: `Updated ${symbol}/${currency} token price cache.`,
488
+ message: "Updated ".concat(symbol, "/").concat(currency, " token price cache."),
368
489
  });
369
490
  }
370
491
  else {
371
492
  this.logger.debug({
372
493
  at: "Coingecko#updatePriceCacheBySymbol",
373
- message: `No new price available for symbol ${symbol}.`,
494
+ message: "No new price available for symbol ".concat(symbol, "."),
374
495
  token: cgPrice,
375
496
  });
376
497
  }
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
- }
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 };
403
548
  //# sourceMappingURL=Coingecko.js.map