@across-protocol/sdk 4.3.111-alpha.3 → 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,49 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HubPoolClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const assert_1 = tslib_1.__importDefault(require("assert"));
6
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
- const constants_1 = require("../constants");
8
- const lpFeeCalculator = tslib_1.__importStar(require("../lpFeeCalculator"));
9
- const evm_1 = require("../arch/evm");
10
- const utils_1 = require("../utils");
11
- const BaseAbstractClient_1 = require("./BaseAbstractClient");
12
- class HubPoolClient extends BaseAbstractClient_1.BaseAbstractClient {
13
- logger;
14
- hubPool;
15
- configStoreClient;
16
- deploymentBlock;
17
- chainId;
18
- configOverride;
19
- l1Tokens = [];
20
- lpTokens = {};
21
- proposedRootBundles = [];
22
- canceledRootBundles = [];
23
- disputedRootBundles = [];
24
- executedRootBundles = [];
25
- crossChainContracts = {};
26
- l1TokensToDestinationTokensWithBlock = {};
27
- pendingRootBundle;
28
- currentTime;
29
- blockFinder;
30
- constructor(logger, hubPool, configStoreClient, deploymentBlock = 0, chainId = 1, eventSearchConfig = { from: 0, maxLookBack: 0 }, configOverride = {
31
- ignoredHubExecutedBundles: [],
32
- ignoredHubProposedBundles: [],
33
- }, cachingMechanism) {
34
- super(eventSearchConfig, cachingMechanism);
35
- this.logger = logger;
36
- this.hubPool = hubPool;
37
- this.configStoreClient = configStoreClient;
38
- this.deploymentBlock = deploymentBlock;
39
- this.chainId = chainId;
40
- this.configOverride = configOverride;
41
- this.latestHeightSearched = Math.min(deploymentBlock - 1, 0);
42
- this.firstHeightToSearch = eventSearchConfig.from;
43
- const provider = this.hubPool.provider;
44
- this.blockFinder = new evm_1.EVMBlockFinder(provider);
45
- }
46
- hubPoolEventFilters() {
4
+ var tslib_1 = require("tslib");
5
+ var assert_1 = tslib_1.__importDefault(require("assert"));
6
+ var lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ var constants_1 = require("../constants");
8
+ var lpFeeCalculator = tslib_1.__importStar(require("../lpFeeCalculator"));
9
+ var evm_1 = require("../arch/evm");
10
+ var utils_1 = require("../utils");
11
+ var BaseAbstractClient_1 = require("./BaseAbstractClient");
12
+ var HubPoolClient = (function (_super) {
13
+ tslib_1.__extends(HubPoolClient, _super);
14
+ function HubPoolClient(logger, hubPool, configStoreClient, deploymentBlock, chainId, eventSearchConfig, configOverride, cachingMechanism) {
15
+ if (deploymentBlock === void 0) { deploymentBlock = 0; }
16
+ if (chainId === void 0) { chainId = 1; }
17
+ if (eventSearchConfig === void 0) { eventSearchConfig = { from: 0, maxLookBack: 0 }; }
18
+ if (configOverride === void 0) { configOverride = {
19
+ ignoredHubExecutedBundles: [],
20
+ ignoredHubProposedBundles: [],
21
+ }; }
22
+ var _this = _super.call(this, eventSearchConfig, cachingMechanism) || this;
23
+ _this.logger = logger;
24
+ _this.hubPool = hubPool;
25
+ _this.configStoreClient = configStoreClient;
26
+ _this.deploymentBlock = deploymentBlock;
27
+ _this.chainId = chainId;
28
+ _this.configOverride = configOverride;
29
+ _this.l1Tokens = [];
30
+ _this.lpTokens = {};
31
+ _this.proposedRootBundles = [];
32
+ _this.canceledRootBundles = [];
33
+ _this.disputedRootBundles = [];
34
+ _this.executedRootBundles = [];
35
+ _this.crossChainContracts = {};
36
+ _this.l1TokensToDestinationTokensWithBlock = {};
37
+ _this.latestHeightSearched = Math.min(deploymentBlock - 1, 0);
38
+ _this.firstHeightToSearch = eventSearchConfig.from;
39
+ var provider = _this.hubPool.provider;
40
+ _this.blockFinder = new evm_1.EVMBlockFinder(provider);
41
+ return _this;
42
+ }
43
+ HubPoolClient.prototype.hubPoolEventFilters = function () {
47
44
  return {
48
45
  SetPoolRebalanceRoute: this.hubPool.filters.SetPoolRebalanceRoute(),
49
46
  L1TokenEnabledForLiquidityProvision: this.hubPool.filters.L1TokenEnabledForLiquidityProvision(),
@@ -53,241 +50,376 @@ class HubPoolClient extends BaseAbstractClient_1.BaseAbstractClient {
53
50
  RootBundleExecuted: this.hubPool.filters.RootBundleExecuted(),
54
51
  CrossChainContractsSet: this.hubPool.filters.CrossChainContractsSet(),
55
52
  };
56
- }
57
- hasPendingProposal() {
53
+ };
54
+ HubPoolClient.prototype.hasPendingProposal = function () {
58
55
  return this.pendingRootBundle !== undefined;
59
- }
60
- getPendingRootBundle() {
56
+ };
57
+ HubPoolClient.prototype.getPendingRootBundle = function () {
61
58
  return this.pendingRootBundle;
62
- }
63
- getProposedRootBundles() {
59
+ };
60
+ HubPoolClient.prototype.getProposedRootBundles = function () {
64
61
  return this.proposedRootBundles;
65
- }
66
- getCancelledRootBundles() {
62
+ };
63
+ HubPoolClient.prototype.getCancelledRootBundles = function () {
67
64
  return this.canceledRootBundles;
68
- }
69
- getDisputedRootBundles() {
65
+ };
66
+ HubPoolClient.prototype.getDisputedRootBundles = function () {
70
67
  return this.disputedRootBundles;
71
- }
72
- getExecutedRootBundles() {
68
+ };
69
+ HubPoolClient.prototype.getExecutedRootBundles = function () {
73
70
  return this.executedRootBundles;
74
- }
75
- getSpokePoolForBlock(chain, block = Number.MAX_SAFE_INTEGER) {
71
+ };
72
+ HubPoolClient.prototype.getSpokePoolForBlock = function (chain, block) {
73
+ if (block === void 0) { block = Number.MAX_SAFE_INTEGER; }
76
74
  if (!this.crossChainContracts[chain]) {
77
- throw new Error(`No cross chain contracts set for ${chain}`);
75
+ throw new Error("No cross chain contracts set for ".concat(chain));
78
76
  }
79
- const mostRecentSpokePoolUpdateBeforeBlock = (0, utils_1.sortEventsDescending)(this.crossChainContracts[chain]).find((crossChainContract) => crossChainContract.blockNumber <= block);
77
+ var mostRecentSpokePoolUpdateBeforeBlock = (0, utils_1.sortEventsDescending)(this.crossChainContracts[chain]).find(function (crossChainContract) { return crossChainContract.blockNumber <= block; });
80
78
  if (!mostRecentSpokePoolUpdateBeforeBlock) {
81
- throw new Error(`No cross chain contract found before block ${block} for chain ${chain}`);
79
+ throw new Error("No cross chain contract found before block ".concat(block, " for chain ").concat(chain));
82
80
  }
83
81
  else {
84
82
  return mostRecentSpokePoolUpdateBeforeBlock.spokePool;
85
83
  }
86
- }
87
- getSpokePoolActivationBlock(chain, spokePool) {
88
- const mostRecentSpokePoolUpdateBeforeBlock = this.crossChainContracts[chain].find((crossChainContract) => crossChainContract.spokePool.eq(spokePool));
89
- return mostRecentSpokePoolUpdateBeforeBlock?.blockNumber;
90
- }
91
- getL2TokenForL1TokenAtBlock(l1Token, destinationChainId, latestHubBlock = Number.MAX_SAFE_INTEGER) {
92
- if (!this.l1TokensToDestinationTokensWithBlock?.[l1Token.toNative()]?.[destinationChainId]) {
84
+ };
85
+ HubPoolClient.prototype.getSpokePoolActivationBlock = function (chain, spokePool) {
86
+ var mostRecentSpokePoolUpdateBeforeBlock = this.crossChainContracts[chain].find(function (crossChainContract) {
87
+ return crossChainContract.spokePool.eq(spokePool);
88
+ });
89
+ return mostRecentSpokePoolUpdateBeforeBlock === null || mostRecentSpokePoolUpdateBeforeBlock === void 0 ? void 0 : mostRecentSpokePoolUpdateBeforeBlock.blockNumber;
90
+ };
91
+ HubPoolClient.prototype.getL2TokenForL1TokenAtBlock = function (l1Token, destinationChainId, latestHubBlock) {
92
+ var _a, _b;
93
+ if (latestHubBlock === void 0) { latestHubBlock = Number.MAX_SAFE_INTEGER; }
94
+ if (!((_b = (_a = this.l1TokensToDestinationTokensWithBlock) === null || _a === void 0 ? void 0 : _a[l1Token.toNative()]) === null || _b === void 0 ? void 0 : _b[destinationChainId])) {
93
95
  return undefined;
94
96
  }
95
- const l2Token = this.l1TokensToDestinationTokensWithBlock[l1Token.toNative()][destinationChainId].find((mapping) => mapping.blockNumber <= latestHubBlock);
97
+ var l2Token = this.l1TokensToDestinationTokensWithBlock[l1Token.toNative()][destinationChainId].find(function (mapping) { return mapping.blockNumber <= latestHubBlock; });
96
98
  return !(0, utils_1.isDefined)(l2Token) || l2Token.l2Token.isZeroAddress() ? undefined : l2Token.l2Token;
97
- }
98
- getL1TokenForL2TokenAtBlock(l2Token, destinationChainId, latestHubBlock = Number.MAX_SAFE_INTEGER) {
99
- const l2Tokens = Object.keys(this.l1TokensToDestinationTokensWithBlock).flatMap((l1Token) => {
100
- const sortedL2Tokens = (0, utils_1.sortEventsDescending)((this.l1TokensToDestinationTokensWithBlock[l1Token][destinationChainId] ?? []).filter((dstTokenWithBlock) => dstTokenWithBlock.blockNumber <= latestHubBlock));
99
+ };
100
+ HubPoolClient.prototype.getL1TokenForL2TokenAtBlock = function (l2Token, destinationChainId, latestHubBlock) {
101
+ var _this = this;
102
+ if (latestHubBlock === void 0) { latestHubBlock = Number.MAX_SAFE_INTEGER; }
103
+ var l2Tokens = Object.keys(this.l1TokensToDestinationTokensWithBlock).flatMap(function (l1Token) {
104
+ var _a;
105
+ var sortedL2Tokens = (0, utils_1.sortEventsDescending)(((_a = _this.l1TokensToDestinationTokensWithBlock[l1Token][destinationChainId]) !== null && _a !== void 0 ? _a : []).filter(function (dstTokenWithBlock) { return dstTokenWithBlock.blockNumber <= latestHubBlock; }));
101
106
  return sortedL2Tokens.length > 0 && sortedL2Tokens[0].l2Token.truncateToBytes20() === l2Token.truncateToBytes20()
102
107
  ? sortedL2Tokens[0]
103
108
  : [];
104
109
  });
105
110
  return l2Tokens.length === 0 ? undefined : (0, utils_1.sortEventsDescending)(l2Tokens)[0].l1Token;
106
- }
107
- getL1TokenForDeposit(deposit) {
111
+ };
112
+ HubPoolClient.prototype.getL1TokenForDeposit = function (deposit) {
108
113
  return this.getL1TokenForL2TokenAtBlock(deposit.inputToken, deposit.originChainId, deposit.quoteBlockNumber);
109
- }
110
- l2TokenEnabledForL1Token(l1Token, destinationChainId) {
114
+ };
115
+ HubPoolClient.prototype.l2TokenEnabledForL1Token = function (l1Token, destinationChainId) {
111
116
  return this.l2TokenEnabledForL1TokenAtBlock(l1Token, destinationChainId, Number.MAX_SAFE_INTEGER);
112
- }
113
- l2TokenEnabledForL1TokenAtBlock(l1Token, destinationChainId, hubBlockNumber) {
114
- const l2Token = (0, utils_1.sortEventsDescending)(this.l1TokensToDestinationTokensWithBlock?.[l1Token.toNative()]?.[destinationChainId] ?? []).find((mapping) => mapping.blockNumber <= hubBlockNumber);
117
+ };
118
+ HubPoolClient.prototype.l2TokenEnabledForL1TokenAtBlock = function (l1Token, destinationChainId, hubBlockNumber) {
119
+ var _a, _b, _c;
120
+ var l2Token = (0, utils_1.sortEventsDescending)((_c = (_b = (_a = this.l1TokensToDestinationTokensWithBlock) === null || _a === void 0 ? void 0 : _a[l1Token.toNative()]) === null || _b === void 0 ? void 0 : _b[destinationChainId]) !== null && _c !== void 0 ? _c : []).find(function (mapping) { return mapping.blockNumber <= hubBlockNumber; });
115
121
  return (0, utils_1.isDefined)(l2Token) && !l2Token.l2Token.isZeroAddress();
116
- }
117
- l2TokenHasPoolRebalanceRoute(l2Token, l2ChainId, hubPoolBlock = this.latestHeightSearched) {
118
- const l1Token = this.getL1TokenForL2TokenAtBlock(l2Token, l2ChainId, hubPoolBlock);
122
+ };
123
+ HubPoolClient.prototype.l2TokenHasPoolRebalanceRoute = function (l2Token, l2ChainId, hubPoolBlock) {
124
+ if (hubPoolBlock === void 0) { hubPoolBlock = this.latestHeightSearched; }
125
+ var l1Token = this.getL1TokenForL2TokenAtBlock(l2Token, l2ChainId, hubPoolBlock);
119
126
  return (0, utils_1.isDefined)(l1Token);
120
- }
121
- getTokenInfoForAddress(address, chainId) {
122
- const tokenInfo = (0, utils_1.getTokenInfo)(address, chainId);
127
+ };
128
+ HubPoolClient.prototype.getTokenInfoForAddress = function (address, chainId) {
129
+ var _a;
130
+ var tokenInfo = (0, utils_1.getTokenInfo)(address, chainId);
123
131
  if (tokenInfo.symbol.toLowerCase() === "usdc" && chainId !== this.chainId) {
124
- tokenInfo.symbol = (0, utils_1.getUsdcSymbol)(address, chainId) ?? "UNKNOWN USDC";
132
+ tokenInfo.symbol = (_a = (0, utils_1.getUsdcSymbol)(address, chainId)) !== null && _a !== void 0 ? _a : "UNKNOWN USDC";
125
133
  }
126
134
  return tokenInfo;
127
- }
128
- getBlockNumber(timestamp) {
129
- const hints = { lowBlock: this.deploymentBlock };
135
+ };
136
+ HubPoolClient.prototype.getBlockNumber = function (timestamp) {
137
+ var hints = { lowBlock: this.deploymentBlock };
130
138
  return (0, utils_1.getCachedBlockForTimestamp)(this.chainId, timestamp, this.blockFinder, this.cachingMechanism, hints);
131
- }
132
- async getBlockNumbers(timestamps) {
133
- const sortedTimestamps = (0, utils_1.dedupArray)(timestamps).sort((x, y) => x - y);
134
- const blockNumbers = {};
135
- for (const timestamp of sortedTimestamps) {
136
- blockNumbers[timestamp] = await this.getBlockNumber(timestamp);
137
- }
138
- return blockNumbers;
139
- }
140
- async getCurrentPoolUtilization(l1Token) {
141
- const blockNumber = this.latestHeightSearched ?? (await this.hubPool.provider.getBlockNumber());
142
- return await this.getUtilization(l1Token, blockNumber, utils_1.bnZero, (0, utils_1.getCurrentTime)(), 0);
143
- }
144
- async getUtilization(hubPoolToken, blockNumber, depositAmount, timestamp, timeToCache) {
145
- const resolver = () => {
146
- const overrides = { blockTag: blockNumber };
147
- const token = hubPoolToken.toNative();
148
- return depositAmount.eq(utils_1.bnZero)
149
- ? this.hubPool.callStatic.liquidityUtilizationCurrent(token, overrides)
150
- : this.hubPool.callStatic.liquidityUtilizationPostRelay(token, depositAmount, overrides);
151
- };
152
- const cache = this.cachingMechanism;
153
- if (!cache || !(0, utils_1.shouldCache)((0, utils_1.getCurrentTime)(), timestamp, timeToCache)) {
154
- return resolver();
155
- }
156
- const key = depositAmount.eq(utils_1.bnZero)
157
- ? `utilization_${hubPoolToken.toNative()}_${blockNumber}`
158
- : `utilization_${hubPoolToken.toNative()}_${blockNumber}_${depositAmount.toString()}`;
159
- const result = await cache.get(key);
160
- if ((0, utils_1.isDefined)(result)) {
161
- return utils_1.BigNumber.from(result);
162
- }
163
- const utilization = await resolver();
164
- if (cache && (0, utils_1.shouldCache)((0, utils_1.getCurrentTime)(), timestamp, timeToCache)) {
165
- await cache.set(key, `${utilization.toString()}`, constants_1.DEFAULT_CACHING_TTL);
166
- }
167
- return utilization;
168
- }
169
- async computeRealizedLpFeePct(deposit) {
170
- const [lpFee] = await this.batchComputeRealizedLpFeePct([deposit]);
171
- return lpFee;
172
- }
173
- async batchComputeRealizedLpFeePct(deposits) {
174
- (0, assert_1.default)(deposits.length > 0, "No deposits supplied to batchComputeRealizedLpFeePct");
175
- if (!(0, utils_1.isDefined)(this.currentTime)) {
176
- throw new Error("HubPoolClient has not set a currentTime");
177
- }
178
- const utilizationTimestamps = {};
179
- let utilization = {};
180
- let quoteBlocks = {};
181
- const hubPoolTokens = {};
182
- const getHubPoolToken = (deposit, quoteBlockNumber) => {
183
- const tokenKey = `${deposit.originChainId}-${deposit.inputToken}`;
184
- const l1Token = this.getL1TokenForDeposit({ ...deposit, quoteBlockNumber });
185
- if (!(0, utils_1.isDefined)(l1Token)) {
186
- return undefined;
187
- }
188
- return (hubPoolTokens[tokenKey] ??= l1Token);
189
- };
190
- const getHubPoolTokens = () => (0, utils_1.dedupArray)(Object.values(hubPoolTokens)
191
- .filter(utils_1.isDefined)
192
- .map((token) => token.toNative())).map((token) => utils_1.EvmAddress.from(token));
193
- const resolveUniqueQuoteTimestamps = (deposit) => {
194
- const { quoteTimestamp } = deposit;
195
- const quoteBlockNumber = quoteBlocks[quoteTimestamp];
196
- const hubPoolToken = getHubPoolToken(deposit, quoteBlockNumber);
197
- if (!hubPoolToken) {
198
- return;
199
- }
200
- const token = hubPoolToken.toNative();
201
- utilizationTimestamps[token] ??= [];
202
- if (!utilizationTimestamps[token].includes(quoteTimestamp)) {
203
- utilizationTimestamps[token].push(quoteTimestamp);
204
- }
205
- };
206
- const resolveUtilization = async (hubPoolToken) => {
207
- return Object.fromEntries(await (0, utils_1.mapAsync)(utilizationTimestamps[hubPoolToken.toNative()], async (quoteTimestamp) => {
208
- const blockNumber = quoteBlocks[quoteTimestamp];
209
- const utilization = await this.getUtilization(hubPoolToken, blockNumber, utils_1.bnZero, quoteTimestamp, timeToCache);
210
- return [blockNumber, utilization];
211
- }));
212
- };
213
- const computeRealizedLpFeePct = async (deposit) => {
214
- const { originChainId, paymentChainId, inputAmount, quoteTimestamp } = deposit;
215
- const quoteBlock = quoteBlocks[quoteTimestamp];
216
- if (paymentChainId === undefined || paymentChainId === originChainId) {
217
- return { quoteBlock, realizedLpFeePct: utils_1.bnZero };
218
- }
219
- const hubPoolToken = getHubPoolToken(deposit, quoteBlock);
220
- if (hubPoolToken === undefined) {
221
- throw new Error(`Cannot computeRealizedLpFeePct for deposit with no pool rebalance route for input token ${deposit.inputToken} on ${originChainId}`);
222
- }
223
- const rateModel = this.configStoreClient.getRateModelForBlockNumber(hubPoolToken, originChainId, paymentChainId, quoteBlock);
224
- const preUtilization = utilization[hubPoolToken.toNative()][quoteBlock];
225
- const postUtilization = await this.getUtilization(hubPoolToken, quoteBlock, inputAmount, quoteTimestamp, timeToCache);
226
- const realizedLpFeePct = lpFeeCalculator.calculateRealizedLpFeePct(rateModel, preUtilization, postUtilization);
227
- return { quoteBlock, realizedLpFeePct };
228
- };
229
- const timeToCache = this.configOverride.timeToCache ?? constants_1.DEFAULT_CACHING_SAFE_LAG;
230
- const quoteTimestamps = (0, utils_1.dedupArray)(deposits.map(({ quoteTimestamp }) => quoteTimestamp));
231
- quoteBlocks = await this.getBlockNumbers(quoteTimestamps);
232
- deposits.forEach((deposit) => resolveUniqueQuoteTimestamps(deposit));
233
- utilization = Object.fromEntries(await (0, utils_1.mapAsync)(getHubPoolTokens(), async (hubPoolToken) => [
234
- hubPoolToken.toNative(),
235
- await resolveUtilization(hubPoolToken),
236
- ]));
237
- return await (0, utils_1.mapAsync)(deposits, async (deposit) => {
238
- const quoteBlock = quoteBlocks[deposit.quoteTimestamp];
239
- if (this.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, quoteBlock)) {
240
- return await computeRealizedLpFeePct(deposit);
241
- }
242
- else {
243
- return {
244
- quoteBlock,
245
- realizedLpFeePct: utils_1.bnZero,
246
- };
247
- }
139
+ };
140
+ HubPoolClient.prototype.getBlockNumbers = function (timestamps) {
141
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
142
+ var sortedTimestamps, blockNumbers, _i, sortedTimestamps_1, timestamp, _a, _b;
143
+ return tslib_1.__generator(this, function (_c) {
144
+ switch (_c.label) {
145
+ case 0:
146
+ sortedTimestamps = (0, utils_1.dedupArray)(timestamps).sort(function (x, y) { return x - y; });
147
+ blockNumbers = {};
148
+ _i = 0, sortedTimestamps_1 = sortedTimestamps;
149
+ _c.label = 1;
150
+ case 1:
151
+ if (!(_i < sortedTimestamps_1.length)) return [3, 4];
152
+ timestamp = sortedTimestamps_1[_i];
153
+ _a = blockNumbers;
154
+ _b = timestamp;
155
+ return [4, this.getBlockNumber(timestamp)];
156
+ case 2:
157
+ _a[_b] = _c.sent();
158
+ _c.label = 3;
159
+ case 3:
160
+ _i++;
161
+ return [3, 1];
162
+ case 4: return [2, blockNumbers];
163
+ }
164
+ });
248
165
  });
249
- }
250
- getL1Tokens() {
166
+ };
167
+ HubPoolClient.prototype.getCurrentPoolUtilization = function (l1Token) {
168
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
169
+ var blockNumber, _a;
170
+ var _b;
171
+ return tslib_1.__generator(this, function (_c) {
172
+ switch (_c.label) {
173
+ case 0:
174
+ if (!((_b = this.latestHeightSearched) !== null && _b !== void 0)) return [3, 1];
175
+ _a = _b;
176
+ return [3, 3];
177
+ case 1: return [4, this.hubPool.provider.getBlockNumber()];
178
+ case 2:
179
+ _a = (_c.sent());
180
+ _c.label = 3;
181
+ case 3:
182
+ blockNumber = _a;
183
+ return [4, this.getUtilization(l1Token, blockNumber, utils_1.bnZero, (0, utils_1.getCurrentTime)(), 0)];
184
+ case 4: return [2, _c.sent()];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ HubPoolClient.prototype.getUtilization = function (hubPoolToken, blockNumber, depositAmount, timestamp, timeToCache) {
190
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
191
+ var resolver, cache, key, result, utilization;
192
+ var _this = this;
193
+ return tslib_1.__generator(this, function (_a) {
194
+ switch (_a.label) {
195
+ case 0:
196
+ resolver = function () {
197
+ var overrides = { blockTag: blockNumber };
198
+ var token = hubPoolToken.toNative();
199
+ return depositAmount.eq(utils_1.bnZero)
200
+ ? _this.hubPool.callStatic.liquidityUtilizationCurrent(token, overrides)
201
+ : _this.hubPool.callStatic.liquidityUtilizationPostRelay(token, depositAmount, overrides);
202
+ };
203
+ cache = this.cachingMechanism;
204
+ if (!cache || !(0, utils_1.shouldCache)((0, utils_1.getCurrentTime)(), timestamp, timeToCache)) {
205
+ return [2, resolver()];
206
+ }
207
+ key = depositAmount.eq(utils_1.bnZero)
208
+ ? "utilization_".concat(hubPoolToken.toNative(), "_").concat(blockNumber)
209
+ : "utilization_".concat(hubPoolToken.toNative(), "_").concat(blockNumber, "_").concat(depositAmount.toString());
210
+ return [4, cache.get(key)];
211
+ case 1:
212
+ result = _a.sent();
213
+ if ((0, utils_1.isDefined)(result)) {
214
+ return [2, utils_1.BigNumber.from(result)];
215
+ }
216
+ return [4, resolver()];
217
+ case 2:
218
+ utilization = _a.sent();
219
+ if (!(cache && (0, utils_1.shouldCache)((0, utils_1.getCurrentTime)(), timestamp, timeToCache))) return [3, 4];
220
+ return [4, cache.set(key, "".concat(utilization.toString()), constants_1.DEFAULT_CACHING_TTL)];
221
+ case 3:
222
+ _a.sent();
223
+ _a.label = 4;
224
+ case 4: return [2, utilization];
225
+ }
226
+ });
227
+ });
228
+ };
229
+ HubPoolClient.prototype.computeRealizedLpFeePct = function (deposit) {
230
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
231
+ var lpFee;
232
+ return tslib_1.__generator(this, function (_a) {
233
+ switch (_a.label) {
234
+ case 0: return [4, this.batchComputeRealizedLpFeePct([deposit])];
235
+ case 1:
236
+ lpFee = (_a.sent())[0];
237
+ return [2, lpFee];
238
+ }
239
+ });
240
+ });
241
+ };
242
+ HubPoolClient.prototype.batchComputeRealizedLpFeePct = function (deposits) {
243
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
244
+ var utilizationTimestamps, utilization, quoteBlocks, hubPoolTokens, getHubPoolToken, getHubPoolTokens, resolveUniqueQuoteTimestamps, resolveUtilization, computeRealizedLpFeePct, timeToCache, quoteTimestamps, _a, _b;
245
+ var _this = this;
246
+ var _c;
247
+ return tslib_1.__generator(this, function (_d) {
248
+ switch (_d.label) {
249
+ case 0:
250
+ (0, assert_1.default)(deposits.length > 0, "No deposits supplied to batchComputeRealizedLpFeePct");
251
+ if (!(0, utils_1.isDefined)(this.currentTime)) {
252
+ throw new Error("HubPoolClient has not set a currentTime");
253
+ }
254
+ utilizationTimestamps = {};
255
+ utilization = {};
256
+ quoteBlocks = {};
257
+ hubPoolTokens = {};
258
+ getHubPoolToken = function (deposit, quoteBlockNumber) {
259
+ var _a;
260
+ var tokenKey = "".concat(deposit.originChainId, "-").concat(deposit.inputToken);
261
+ var l1Token = _this.getL1TokenForDeposit(tslib_1.__assign(tslib_1.__assign({}, deposit), { quoteBlockNumber: quoteBlockNumber }));
262
+ if (!(0, utils_1.isDefined)(l1Token)) {
263
+ return undefined;
264
+ }
265
+ return ((_a = hubPoolTokens[tokenKey]) !== null && _a !== void 0 ? _a : (hubPoolTokens[tokenKey] = l1Token));
266
+ };
267
+ getHubPoolTokens = function () {
268
+ return (0, utils_1.dedupArray)(Object.values(hubPoolTokens)
269
+ .filter(utils_1.isDefined)
270
+ .map(function (token) { return token.toNative(); })).map(function (token) { return utils_1.EvmAddress.from(token); });
271
+ };
272
+ resolveUniqueQuoteTimestamps = function (deposit) {
273
+ var _a;
274
+ var quoteTimestamp = deposit.quoteTimestamp;
275
+ var quoteBlockNumber = quoteBlocks[quoteTimestamp];
276
+ var hubPoolToken = getHubPoolToken(deposit, quoteBlockNumber);
277
+ if (!hubPoolToken) {
278
+ return;
279
+ }
280
+ var token = hubPoolToken.toNative();
281
+ (_a = utilizationTimestamps[token]) !== null && _a !== void 0 ? _a : (utilizationTimestamps[token] = []);
282
+ if (!utilizationTimestamps[token].includes(quoteTimestamp)) {
283
+ utilizationTimestamps[token].push(quoteTimestamp);
284
+ }
285
+ };
286
+ resolveUtilization = function (hubPoolToken) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
287
+ var _a, _b;
288
+ var _this = this;
289
+ return tslib_1.__generator(this, function (_c) {
290
+ switch (_c.label) {
291
+ case 0:
292
+ _b = (_a = Object).fromEntries;
293
+ return [4, (0, utils_1.mapAsync)(utilizationTimestamps[hubPoolToken.toNative()], function (quoteTimestamp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
294
+ var blockNumber, utilization;
295
+ return tslib_1.__generator(this, function (_a) {
296
+ switch (_a.label) {
297
+ case 0:
298
+ blockNumber = quoteBlocks[quoteTimestamp];
299
+ return [4, this.getUtilization(hubPoolToken, blockNumber, utils_1.bnZero, quoteTimestamp, timeToCache)];
300
+ case 1:
301
+ utilization = _a.sent();
302
+ return [2, [blockNumber, utilization]];
303
+ }
304
+ });
305
+ }); })];
306
+ case 1: return [2, _b.apply(_a, [_c.sent()])];
307
+ }
308
+ });
309
+ }); };
310
+ computeRealizedLpFeePct = function (deposit) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
311
+ var originChainId, paymentChainId, inputAmount, quoteTimestamp, quoteBlock, hubPoolToken, rateModel, preUtilization, postUtilization, realizedLpFeePct;
312
+ return tslib_1.__generator(this, function (_a) {
313
+ switch (_a.label) {
314
+ case 0:
315
+ originChainId = deposit.originChainId, paymentChainId = deposit.paymentChainId, inputAmount = deposit.inputAmount, quoteTimestamp = deposit.quoteTimestamp;
316
+ quoteBlock = quoteBlocks[quoteTimestamp];
317
+ if (paymentChainId === undefined || paymentChainId === originChainId) {
318
+ return [2, { quoteBlock: quoteBlock, realizedLpFeePct: utils_1.bnZero }];
319
+ }
320
+ hubPoolToken = getHubPoolToken(deposit, quoteBlock);
321
+ if (hubPoolToken === undefined) {
322
+ throw new Error("Cannot computeRealizedLpFeePct for deposit with no pool rebalance route for input token ".concat(deposit.inputToken, " on ").concat(originChainId));
323
+ }
324
+ rateModel = this.configStoreClient.getRateModelForBlockNumber(hubPoolToken, originChainId, paymentChainId, quoteBlock);
325
+ preUtilization = utilization[hubPoolToken.toNative()][quoteBlock];
326
+ return [4, this.getUtilization(hubPoolToken, quoteBlock, inputAmount, quoteTimestamp, timeToCache)];
327
+ case 1:
328
+ postUtilization = _a.sent();
329
+ realizedLpFeePct = lpFeeCalculator.calculateRealizedLpFeePct(rateModel, preUtilization, postUtilization);
330
+ return [2, { quoteBlock: quoteBlock, realizedLpFeePct: realizedLpFeePct }];
331
+ }
332
+ });
333
+ }); };
334
+ timeToCache = (_c = this.configOverride.timeToCache) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_CACHING_SAFE_LAG;
335
+ quoteTimestamps = (0, utils_1.dedupArray)(deposits.map(function (_a) {
336
+ var quoteTimestamp = _a.quoteTimestamp;
337
+ return quoteTimestamp;
338
+ }));
339
+ return [4, this.getBlockNumbers(quoteTimestamps)];
340
+ case 1:
341
+ quoteBlocks = _d.sent();
342
+ deposits.forEach(function (deposit) { return resolveUniqueQuoteTimestamps(deposit); });
343
+ _b = (_a = Object).fromEntries;
344
+ return [4, (0, utils_1.mapAsync)(getHubPoolTokens(), function (hubPoolToken) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
345
+ var _a;
346
+ return tslib_1.__generator(this, function (_b) {
347
+ switch (_b.label) {
348
+ case 0:
349
+ _a = [hubPoolToken.toNative()];
350
+ return [4, resolveUtilization(hubPoolToken)];
351
+ case 1: return [2, _a.concat([
352
+ _b.sent()
353
+ ])];
354
+ }
355
+ });
356
+ }); })];
357
+ case 2:
358
+ utilization = _b.apply(_a, [_d.sent()]);
359
+ return [4, (0, utils_1.mapAsync)(deposits, function (deposit) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
360
+ var quoteBlock;
361
+ return tslib_1.__generator(this, function (_a) {
362
+ switch (_a.label) {
363
+ case 0:
364
+ quoteBlock = quoteBlocks[deposit.quoteTimestamp];
365
+ if (!this.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, quoteBlock)) return [3, 2];
366
+ return [4, computeRealizedLpFeePct(deposit)];
367
+ case 1: return [2, _a.sent()];
368
+ case 2: return [2, {
369
+ quoteBlock: quoteBlock,
370
+ realizedLpFeePct: utils_1.bnZero,
371
+ }];
372
+ }
373
+ });
374
+ }); })];
375
+ case 3: return [2, _d.sent()];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ HubPoolClient.prototype.getL1Tokens = function () {
251
381
  return this.l1Tokens;
252
- }
253
- getTokenInfoForL1Token(l1Token) {
254
- return this.l1Tokens.find((token) => token.address.eq(l1Token));
255
- }
256
- getLpTokenInfoForL1Token(l1Token) {
382
+ };
383
+ HubPoolClient.prototype.getTokenInfoForL1Token = function (l1Token) {
384
+ return this.l1Tokens.find(function (token) { return token.address.eq(l1Token); });
385
+ };
386
+ HubPoolClient.prototype.getLpTokenInfoForL1Token = function (l1Token) {
257
387
  return this.lpTokens[l1Token.toNative()];
258
- }
259
- areTokensEquivalent(tokenA, chainIdA, tokenB, chainIdB, hubPoolBlock = this.latestHeightSearched) {
388
+ };
389
+ HubPoolClient.prototype.areTokensEquivalent = function (tokenA, chainIdA, tokenB, chainIdB, hubPoolBlock) {
390
+ if (hubPoolBlock === void 0) { hubPoolBlock = this.latestHeightSearched; }
260
391
  if (!this.l2TokenHasPoolRebalanceRoute(tokenA, chainIdA, hubPoolBlock) ||
261
392
  !this.l2TokenHasPoolRebalanceRoute(tokenB, chainIdB, hubPoolBlock)) {
262
393
  return false;
263
394
  }
264
- const l1TokenA = this.getL1TokenForL2TokenAtBlock(tokenA, chainIdA, hubPoolBlock);
265
- const l1TokenB = this.getL1TokenForL2TokenAtBlock(tokenB, chainIdB, hubPoolBlock);
395
+ var l1TokenA = this.getL1TokenForL2TokenAtBlock(tokenA, chainIdA, hubPoolBlock);
396
+ var l1TokenB = this.getL1TokenForL2TokenAtBlock(tokenB, chainIdB, hubPoolBlock);
266
397
  if (!(0, utils_1.isDefined)(l1TokenA) || !(0, utils_1.isDefined)(l1TokenB) || !l1TokenA.eq(l1TokenB)) {
267
398
  return false;
268
399
  }
269
- const _tokenA = this.getL2TokenForL1TokenAtBlock(l1TokenA, chainIdA, hubPoolBlock);
270
- const _tokenB = this.getL2TokenForL1TokenAtBlock(l1TokenB, chainIdB, hubPoolBlock);
400
+ var _tokenA = this.getL2TokenForL1TokenAtBlock(l1TokenA, chainIdA, hubPoolBlock);
401
+ var _tokenB = this.getL2TokenForL1TokenAtBlock(l1TokenB, chainIdB, hubPoolBlock);
271
402
  return (0, utils_1.isDefined)(_tokenA) && (0, utils_1.isDefined)(_tokenB) && tokenA.eq(_tokenA) && tokenB.eq(_tokenB);
272
- }
273
- getSpokeActivationBlockForChain(chainId) {
274
- return this.getSpokePoolActivationBlock(chainId, this.getSpokePoolForBlock(chainId)) ?? 0;
275
- }
276
- isRootBundleValid(rootBundle, latestMainnetBlock) {
277
- const nextRootBundle = this.getFollowingRootBundle(rootBundle);
278
- const executedLeafCount = this.getExecutedLeavesForRootBundle(rootBundle, nextRootBundle ? Math.min(nextRootBundle.blockNumber, latestMainnetBlock) : latestMainnetBlock);
403
+ };
404
+ HubPoolClient.prototype.getSpokeActivationBlockForChain = function (chainId) {
405
+ var _a;
406
+ return (_a = this.getSpokePoolActivationBlock(chainId, this.getSpokePoolForBlock(chainId))) !== null && _a !== void 0 ? _a : 0;
407
+ };
408
+ HubPoolClient.prototype.isRootBundleValid = function (rootBundle, latestMainnetBlock) {
409
+ var nextRootBundle = this.getFollowingRootBundle(rootBundle);
410
+ var executedLeafCount = this.getExecutedLeavesForRootBundle(rootBundle, nextRootBundle ? Math.min(nextRootBundle.blockNumber, latestMainnetBlock) : latestMainnetBlock);
279
411
  return executedLeafCount.length === rootBundle.poolRebalanceLeafCount;
280
- }
281
- getRootBundleEvalBlockNumberContainingBlock(latestMainnetBlock, block, chain, chainIdListOverride) {
282
- const chainIdList = chainIdListOverride ?? this.configStoreClient.getChainIdIndicesForBlock(latestMainnetBlock);
283
- let endingBlockNumber;
284
- for (let i = this.proposedRootBundles.length - 1; i >= 0; i--) {
285
- const rootBundle = this.proposedRootBundles[i];
286
- const nextRootBundle = this.getFollowingRootBundle(rootBundle);
412
+ };
413
+ HubPoolClient.prototype.getRootBundleEvalBlockNumberContainingBlock = function (latestMainnetBlock, block, chain, chainIdListOverride) {
414
+ var chainIdList = chainIdListOverride !== null && chainIdListOverride !== void 0 ? chainIdListOverride : this.configStoreClient.getChainIdIndicesForBlock(latestMainnetBlock);
415
+ var endingBlockNumber;
416
+ for (var i = this.proposedRootBundles.length - 1; i >= 0; i--) {
417
+ var rootBundle = this.proposedRootBundles[i];
418
+ var nextRootBundle = this.getFollowingRootBundle(rootBundle);
287
419
  if (!this.isRootBundleValid(rootBundle, nextRootBundle ? nextRootBundle.blockNumber : latestMainnetBlock)) {
288
420
  continue;
289
421
  }
290
- const bundleEvalBlockNumber = this.getBundleEndBlockForChain(rootBundle, chain, chainIdList);
422
+ var bundleEvalBlockNumber = this.getBundleEndBlockForChain(rootBundle, chain, chainIdList);
291
423
  if (bundleEvalBlockNumber <= block) {
292
424
  if (bundleEvalBlockNumber === block) {
293
425
  endingBlockNumber = bundleEvalBlockNumber;
@@ -297,359 +429,408 @@ class HubPoolClient extends BaseAbstractClient_1.BaseAbstractClient {
297
429
  endingBlockNumber = bundleEvalBlockNumber;
298
430
  }
299
431
  return endingBlockNumber;
300
- }
301
- getProposedRootBundlesInBlockRange(startingBlock, endingBlock) {
302
- return this.proposedRootBundles.filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
303
- }
304
- getCancelledRootBundlesInBlockRange(startingBlock, endingBlock) {
305
- return (0, utils_1.sortEventsDescending)(this.canceledRootBundles).filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
306
- }
307
- getDisputedRootBundlesInBlockRange(startingBlock, endingBlock) {
308
- return (0, utils_1.sortEventsDescending)(this.disputedRootBundles).filter((bundle) => bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock);
309
- }
310
- getTokenMappingsModifiedInBlockRange(startingBlock, endingBlock) {
432
+ };
433
+ HubPoolClient.prototype.getProposedRootBundlesInBlockRange = function (startingBlock, endingBlock) {
434
+ return this.proposedRootBundles.filter(function (bundle) { return bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock; });
435
+ };
436
+ HubPoolClient.prototype.getCancelledRootBundlesInBlockRange = function (startingBlock, endingBlock) {
437
+ return (0, utils_1.sortEventsDescending)(this.canceledRootBundles).filter(function (bundle) { return bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock; });
438
+ };
439
+ HubPoolClient.prototype.getDisputedRootBundlesInBlockRange = function (startingBlock, endingBlock) {
440
+ return (0, utils_1.sortEventsDescending)(this.disputedRootBundles).filter(function (bundle) { return bundle.blockNumber >= startingBlock && bundle.blockNumber <= endingBlock; });
441
+ };
442
+ HubPoolClient.prototype.getTokenMappingsModifiedInBlockRange = function (startingBlock, endingBlock) {
311
443
  return (Object.values(this.l1TokensToDestinationTokensWithBlock)
312
- .flatMap((destinationTokens) => Object.entries(destinationTokens).flatMap(([destinationChainId, tokensWithBlock]) => tokensWithBlock.map((token) => ({
313
- ...token,
314
- l2ChainId: Number(destinationChainId),
315
- }))))
316
- .filter((token) => token.blockNumber >= startingBlock && token.blockNumber <= endingBlock));
317
- }
318
- getLatestProposedRootBundle() {
444
+ .flatMap(function (destinationTokens) {
445
+ return Object.entries(destinationTokens).flatMap(function (_a) {
446
+ var destinationChainId = _a[0], tokensWithBlock = _a[1];
447
+ return tokensWithBlock.map(function (token) { return (tslib_1.__assign(tslib_1.__assign({}, token), { l2ChainId: Number(destinationChainId) })); });
448
+ });
449
+ })
450
+ .filter(function (token) { return token.blockNumber >= startingBlock && token.blockNumber <= endingBlock; }));
451
+ };
452
+ HubPoolClient.prototype.getLatestProposedRootBundle = function () {
319
453
  return this.proposedRootBundles[this.proposedRootBundles.length - 1];
320
- }
321
- getFollowingRootBundle(currentRootBundle) {
322
- const index = lodash_1.default.findLastIndex(this.proposedRootBundles, (bundle) => bundle.blockNumber === currentRootBundle.blockNumber);
454
+ };
455
+ HubPoolClient.prototype.getFollowingRootBundle = function (currentRootBundle) {
456
+ var index = lodash_1.default.findLastIndex(this.proposedRootBundles, function (bundle) { return bundle.blockNumber === currentRootBundle.blockNumber; });
323
457
  if (index === -1 || index === this.proposedRootBundles.length - 1) {
324
458
  return undefined;
325
459
  }
326
460
  return this.proposedRootBundles[index + 1];
327
- }
328
- getExecutedLeavesForRootBundle(rootBundle, latestMainnetBlockToSearch) {
329
- return this.executedRootBundles.filter((executedLeaf) => executedLeaf.blockNumber <= latestMainnetBlockToSearch &&
330
- executedLeaf.blockNumber > rootBundle.blockNumber);
331
- }
332
- getValidatedRootBundles(latestMainnetBlock = Number.MAX_SAFE_INTEGER) {
333
- return this.proposedRootBundles.filter((rootBundle) => {
461
+ };
462
+ HubPoolClient.prototype.getExecutedLeavesForRootBundle = function (rootBundle, latestMainnetBlockToSearch) {
463
+ return this.executedRootBundles.filter(function (executedLeaf) {
464
+ return executedLeaf.blockNumber <= latestMainnetBlockToSearch &&
465
+ executedLeaf.blockNumber > rootBundle.blockNumber;
466
+ });
467
+ };
468
+ HubPoolClient.prototype.getValidatedRootBundles = function (latestMainnetBlock) {
469
+ var _this = this;
470
+ if (latestMainnetBlock === void 0) { latestMainnetBlock = Number.MAX_SAFE_INTEGER; }
471
+ return this.proposedRootBundles.filter(function (rootBundle) {
334
472
  if (rootBundle.blockNumber > latestMainnetBlock) {
335
473
  return false;
336
474
  }
337
- return this.isRootBundleValid(rootBundle, latestMainnetBlock);
475
+ return _this.isRootBundleValid(rootBundle, latestMainnetBlock);
338
476
  });
339
- }
340
- getLatestFullyExecutedRootBundle(latestMainnetBlock) {
341
- return lodash_1.default.findLast(this.proposedRootBundles, (rootBundle) => {
477
+ };
478
+ HubPoolClient.prototype.getLatestFullyExecutedRootBundle = function (latestMainnetBlock) {
479
+ var _this = this;
480
+ return lodash_1.default.findLast(this.proposedRootBundles, function (rootBundle) {
342
481
  if (rootBundle.blockNumber > latestMainnetBlock) {
343
482
  return false;
344
483
  }
345
- return this.isRootBundleValid(rootBundle, latestMainnetBlock);
484
+ return _this.isRootBundleValid(rootBundle, latestMainnetBlock);
346
485
  });
347
- }
348
- getEarliestFullyExecutedRootBundle(latestMainnetBlock, startBlock = 0) {
349
- return this.proposedRootBundles.find((rootBundle) => {
486
+ };
487
+ HubPoolClient.prototype.getEarliestFullyExecutedRootBundle = function (latestMainnetBlock, startBlock) {
488
+ var _this = this;
489
+ if (startBlock === void 0) { startBlock = 0; }
490
+ return this.proposedRootBundles.find(function (rootBundle) {
350
491
  if (rootBundle.blockNumber > latestMainnetBlock) {
351
492
  return false;
352
493
  }
353
494
  if (rootBundle.blockNumber < startBlock) {
354
495
  return false;
355
496
  }
356
- return this.isRootBundleValid(rootBundle, latestMainnetBlock);
497
+ return _this.isRootBundleValid(rootBundle, latestMainnetBlock);
357
498
  });
358
- }
359
- getNthFullyExecutedRootBundle(n, startBlock) {
499
+ };
500
+ HubPoolClient.prototype.getNthFullyExecutedRootBundle = function (n, startBlock) {
360
501
  if (n === 0) {
361
502
  throw new Error("n cannot be 0");
362
503
  }
363
504
  if (!this.latestHeightSearched) {
364
505
  throw new Error("HubPoolClient::getNthFullyExecutedRootBundle client not updated");
365
506
  }
366
- let bundleToReturn;
507
+ var bundleToReturn;
367
508
  if (n < 0) {
368
- let nextLatestMainnetBlock = startBlock ?? this.latestHeightSearched;
369
- for (let i = 0; i < Math.abs(n); i++) {
509
+ var nextLatestMainnetBlock = startBlock !== null && startBlock !== void 0 ? startBlock : this.latestHeightSearched;
510
+ for (var i = 0; i < Math.abs(n); i++) {
370
511
  bundleToReturn = this.getLatestFullyExecutedRootBundle(nextLatestMainnetBlock);
371
- const bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
512
+ var bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
372
513
  nextLatestMainnetBlock = Math.max(0, bundleBlockNumber - 1);
373
514
  }
374
515
  }
375
516
  else {
376
- let nextStartBlock = startBlock ?? 0;
377
- for (let i = 0; i < n; i++) {
517
+ var nextStartBlock = startBlock !== null && startBlock !== void 0 ? startBlock : 0;
518
+ for (var i = 0; i < n; i++) {
378
519
  bundleToReturn = this.getEarliestFullyExecutedRootBundle(this.latestHeightSearched, nextStartBlock);
379
- const bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
520
+ var bundleBlockNumber = bundleToReturn ? bundleToReturn.blockNumber : 0;
380
521
  nextStartBlock = Math.min(bundleBlockNumber + 1, this.latestHeightSearched);
381
522
  }
382
523
  }
383
524
  return bundleToReturn;
384
- }
385
- getLatestBundleEndBlockForChain(chainIdList, latestMainnetBlock, chainId) {
386
- const latestFullyExecutedPoolRebalanceRoot = this.getLatestFullyExecutedRootBundle(latestMainnetBlock);
525
+ };
526
+ HubPoolClient.prototype.getLatestBundleEndBlockForChain = function (chainIdList, latestMainnetBlock, chainId) {
527
+ var latestFullyExecutedPoolRebalanceRoot = this.getLatestFullyExecutedRootBundle(latestMainnetBlock);
387
528
  if (!latestFullyExecutedPoolRebalanceRoot) {
388
529
  return 0;
389
530
  }
390
531
  return this.getBundleEndBlockForChain(latestFullyExecutedPoolRebalanceRoot, chainId, chainIdList);
391
- }
392
- getNextBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId) {
393
- const endBlock = this.getLatestBundleEndBlockForChain(chainIdList, latestMainnetBlock, chainId);
532
+ };
533
+ HubPoolClient.prototype.getNextBundleStartBlockNumber = function (chainIdList, latestMainnetBlock, chainId) {
534
+ var endBlock = this.getLatestBundleEndBlockForChain(chainIdList, latestMainnetBlock, chainId);
394
535
  return endBlock > 0 ? endBlock + 1 : 0;
395
- }
396
- getOptimisticBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId) {
536
+ };
537
+ HubPoolClient.prototype.getOptimisticBundleStartBlockNumber = function (chainIdList, latestMainnetBlock, chainId) {
397
538
  if (!this.hasPendingProposal()) {
398
539
  return this.getNextBundleStartBlockNumber(chainIdList, latestMainnetBlock, chainId);
399
540
  }
400
- const latestProposedBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
541
+ var latestProposedBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
401
542
  if (!(0, utils_1.isDefined)(latestProposedBundle)) {
402
543
  return 0;
403
544
  }
404
- const optimisticEndBlock = this.getBundleEndBlockForChain(latestProposedBundle, chainId, chainIdList);
545
+ var optimisticEndBlock = this.getBundleEndBlockForChain(latestProposedBundle, chainId, chainIdList);
405
546
  return optimisticEndBlock > 0 ? optimisticEndBlock + 1 : 0;
406
- }
407
- getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token) {
408
- return (0, utils_1.sortEventsDescending)(this.executedRootBundles).find((executedLeaf) => {
547
+ };
548
+ HubPoolClient.prototype.getLatestExecutedRootBundleContainingL1Token = function (block, chain, l1Token) {
549
+ return (0, utils_1.sortEventsDescending)(this.executedRootBundles).find(function (executedLeaf) {
409
550
  return (executedLeaf.blockNumber <= block &&
410
551
  executedLeaf.chainId === chain &&
411
- executedLeaf.l1Tokens.some((token) => token.eq(l1Token)));
552
+ executedLeaf.l1Tokens.some(function (token) { return token.eq(l1Token); }));
412
553
  });
413
- }
414
- getRunningBalanceBeforeBlockForChain(block, chain, l1Token) {
415
- const executedRootBundle = this.getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token);
554
+ };
555
+ HubPoolClient.prototype.getRunningBalanceBeforeBlockForChain = function (block, chain, l1Token) {
556
+ var executedRootBundle = this.getLatestExecutedRootBundleContainingL1Token(block, chain, l1Token);
416
557
  return this.getRunningBalanceForToken(l1Token, executedRootBundle);
417
- }
418
- getRunningBalanceForToken(l1Token, executedRootBundle) {
419
- let runningBalance = (0, utils_1.toBN)(0);
558
+ };
559
+ HubPoolClient.prototype.getRunningBalanceForToken = function (l1Token, executedRootBundle) {
560
+ var runningBalance = (0, utils_1.toBN)(0);
420
561
  if (executedRootBundle) {
421
- const indexOfL1Token = executedRootBundle.l1Tokens.findIndex((tokenInBundle) => tokenInBundle.eq(l1Token));
562
+ var indexOfL1Token = executedRootBundle.l1Tokens.findIndex(function (tokenInBundle) { return tokenInBundle.eq(l1Token); });
422
563
  if (indexOfL1Token !== -1) {
423
564
  runningBalance = executedRootBundle.runningBalances[indexOfL1Token];
424
565
  }
425
566
  }
426
- return { runningBalance };
427
- }
428
- async _update(eventNames) {
429
- const hubPoolEvents = this.hubPoolEventFilters();
430
- const searchConfig = await this.updateSearchConfig(this.hubPool.provider);
431
- if ((0, BaseAbstractClient_1.isUpdateFailureReason)(searchConfig)) {
432
- return { success: false, reason: searchConfig };
433
- }
434
- const supportedEvents = Object.keys(hubPoolEvents);
435
- if (eventNames.some((eventName) => !supportedEvents.includes(eventName))) {
436
- return { success: false, reason: BaseAbstractClient_1.UpdateFailureReason.BadRequest };
437
- }
438
- const eventSearchConfigs = eventNames.map((eventName) => {
439
- const _searchConfig = { ...searchConfig };
440
- const overrideEvents = ["CrossChainContractsSet", "L1TokenEnabledForLiquidityProvision", "SetPoolRebalanceRoute"];
441
- if (overrideEvents.includes(eventName) && !this.isUpdated) {
442
- _searchConfig.from = this.deploymentBlock;
443
- }
444
- return {
445
- eventName,
446
- filter: hubPoolEvents[eventName],
447
- searchConfig: _searchConfig,
448
- };
449
- });
450
- this.logger.debug({
451
- at: "HubPoolClient",
452
- message: "Updating HubPool client",
453
- searchConfig: eventSearchConfigs.map(({ eventName, searchConfig }) => ({ eventName, searchConfig })),
454
- });
455
- const timerStart = Date.now();
456
- const { hubPool } = this;
457
- const multicallFunctions = ["getCurrentTime", "rootBundleProposal"];
458
- const [multicallOutput, ...events] = await Promise.all([
459
- hubPool.callStatic.multicall(multicallFunctions.map((f) => hubPool.interface.encodeFunctionData(f)), { blockTag: searchConfig.to }),
460
- ...eventSearchConfigs.map((config) => (0, utils_1.paginatedEventQuery)(hubPool, config.filter, config.searchConfig)),
461
- ]);
462
- const [currentTime, pendingRootBundleProposal] = multicallFunctions.map((fn, idx) => {
463
- const output = hubPool.interface.decodeFunctionResult(fn, multicallOutput[idx]);
464
- return output.length > 1 ? output : output[0];
465
- });
466
- this.logger.debug({
467
- at: "HubPoolClient#_update",
468
- message: `Time to query new events from RPC for ${this.chainId}: ${Date.now() - timerStart} ms`,
469
- });
470
- const _events = Object.fromEntries(eventNames.map((eventName, idx) => [eventName, events[idx]]));
471
- return {
472
- success: true,
473
- currentTime,
474
- pendingRootBundleProposal: {
475
- ...pendingRootBundleProposal,
476
- proposer: utils_1.EvmAddress.from(pendingRootBundleProposal.proposer),
477
- },
478
- searchEndBlock: searchConfig.to,
479
- events: _events,
480
- };
481
- }
482
- async update(eventsToQuery = Object.keys(this.hubPoolEventFilters())) {
483
- if (!this.configStoreClient.isUpdated) {
484
- throw new Error("ConfigStoreClient not updated");
485
- }
486
- const update = await this._update(eventsToQuery);
487
- if (!update.success) {
488
- if (update.reason !== BaseAbstractClient_1.UpdateFailureReason.AlreadyUpdated) {
489
- throw new Error(`Unable to update HubPoolClient: ${update.reason}`);
490
- }
491
- return;
492
- }
493
- const { events, currentTime, pendingRootBundleProposal, searchEndBlock } = update;
494
- if (eventsToQuery.includes("CrossChainContractsSet")) {
495
- for (const event of events["CrossChainContractsSet"]) {
496
- const args = (0, utils_1.spreadEventWithBlockNumber)(event);
497
- const dataToAdd = {
498
- spokePool: utils_1.EvmAddress.from(args.spokePool),
499
- blockNumber: args.blockNumber,
500
- txnRef: args.txnRef,
501
- logIndex: args.logIndex,
502
- txnIndex: args.txnIndex,
503
- l2ChainId: args.l2ChainId,
504
- };
505
- if ((0, utils_1.chainIsSvm)(args.l2ChainId)) {
506
- const solanaSpokePool = (0, utils_1.getDeployedAddress)("SvmSpoke", args.l2ChainId);
507
- if (!solanaSpokePool) {
508
- throw new Error(`SVM spoke pool not found for chain ${args.l2ChainId}`);
509
- }
510
- const svmSpoke = utils_1.SvmAddress.from(solanaSpokePool);
511
- const truncatedAddress = svmSpoke.truncateToBytes20();
512
- if (args.spokePool.toLowerCase() !== truncatedAddress.toLowerCase()) {
513
- throw new Error(`SVM spoke pool address mismatch for chain ${args.l2ChainId}. ` +
514
- `Expected ${truncatedAddress}, got ${args.spokePool}`);
515
- }
516
- dataToAdd.spokePool = svmSpoke;
517
- }
518
- (0, utils_1.assign)(this.crossChainContracts, [args.l2ChainId], [dataToAdd]);
519
- }
520
- }
521
- if (eventsToQuery.includes("SetPoolRebalanceRoute")) {
522
- for (const event of events["SetPoolRebalanceRoute"]) {
523
- const args = (0, utils_1.spreadEventWithBlockNumber)(event);
524
- let destinationToken = utils_1.EvmAddress.from(args.destinationToken);
525
- if ((0, utils_1.chainIsSvm)(args.destinationChainId)) {
526
- const usdcTokenSol = constants_1.TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
527
- const svmUsdc = utils_1.SvmAddress.from(usdcTokenSol);
528
- if (destinationToken.truncateToBytes20() !== svmUsdc.truncateToBytes20()) {
529
- throw new Error(`SVM USDC address mismatch for chain ${args.destinationChainId}. ` +
530
- `Expected ${svmUsdc.truncateToBytes20()}, got ${destinationToken}`);
531
- }
532
- destinationToken = svmUsdc;
533
- }
534
- const newRoute = {
535
- l1Token: utils_1.EvmAddress.from(args.l1Token),
536
- l2Token: destinationToken,
537
- blockNumber: args.blockNumber,
538
- txnIndex: args.txnIndex,
539
- logIndex: args.logIndex,
540
- txnRef: args.txnRef,
541
- };
542
- if (this.l1TokensToDestinationTokensWithBlock[args.l1Token]?.[args.destinationChainId]) {
543
- this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId] = (0, utils_1.sortEventsDescending)([
544
- ...this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId],
545
- newRoute,
546
- ]);
547
- }
548
- else {
549
- (0, utils_1.assign)(this.l1TokensToDestinationTokensWithBlock, [args.l1Token, args.destinationChainId], [newRoute]);
550
- }
551
- }
552
- }
553
- if (eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) {
554
- const uniqueL1Tokens = (0, utils_1.dedupArray)(events["L1TokenEnabledForLiquidityProvision"].map((event) => String(event.args["l1Token"])));
555
- const [tokenInfo, lpTokenInfo] = await Promise.all([
556
- Promise.all(uniqueL1Tokens.map(async (l1Token) => {
557
- const tokenInfo = await (0, utils_1.fetchTokenInfo)(l1Token, this.hubPool.provider);
558
- return {
559
- ...tokenInfo,
560
- address: utils_1.EvmAddress.from(l1Token),
561
- };
562
- })),
563
- Promise.all(uniqueL1Tokens.map(async (l1Token) => await this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock }))),
564
- ]);
565
- for (const info of tokenInfo) {
566
- if (!this.l1Tokens.find((token) => token.address.eq(info.address))) {
567
- if (info.decimals > 0 && info.decimals <= 18) {
568
- this.l1Tokens.push(info);
569
- }
570
- else {
571
- throw new Error(`Unsupported HubPool token: ${JSON.stringify(info)}`);
572
- }
567
+ return { runningBalance: runningBalance };
568
+ };
569
+ HubPoolClient.prototype._update = function (eventNames) {
570
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
571
+ var hubPoolEvents, searchConfig, supportedEvents, eventSearchConfigs, timerStart, hubPool, multicallFunctions, _a, multicallOutput, events, _b, currentTime, pendingRootBundleProposal, _events;
572
+ var _this = this;
573
+ return tslib_1.__generator(this, function (_c) {
574
+ switch (_c.label) {
575
+ case 0:
576
+ hubPoolEvents = this.hubPoolEventFilters();
577
+ return [4, this.updateSearchConfig(this.hubPool.provider)];
578
+ case 1:
579
+ searchConfig = _c.sent();
580
+ if ((0, BaseAbstractClient_1.isUpdateFailureReason)(searchConfig)) {
581
+ return [2, { success: false, reason: searchConfig }];
582
+ }
583
+ supportedEvents = Object.keys(hubPoolEvents);
584
+ if (eventNames.some(function (eventName) { return !supportedEvents.includes(eventName); })) {
585
+ return [2, { success: false, reason: BaseAbstractClient_1.UpdateFailureReason.BadRequest }];
586
+ }
587
+ eventSearchConfigs = eventNames.map(function (eventName) {
588
+ var _searchConfig = tslib_1.__assign({}, searchConfig);
589
+ var overrideEvents = ["CrossChainContractsSet", "L1TokenEnabledForLiquidityProvision", "SetPoolRebalanceRoute"];
590
+ if (overrideEvents.includes(eventName) && !_this.isUpdated) {
591
+ _searchConfig.from = _this.deploymentBlock;
592
+ }
593
+ return {
594
+ eventName: eventName,
595
+ filter: hubPoolEvents[eventName],
596
+ searchConfig: _searchConfig,
597
+ };
598
+ });
599
+ this.logger.debug({
600
+ at: "HubPoolClient",
601
+ message: "Updating HubPool client",
602
+ searchConfig: eventSearchConfigs.map(function (_a) {
603
+ var eventName = _a.eventName, searchConfig = _a.searchConfig;
604
+ return ({ eventName: eventName, searchConfig: searchConfig });
605
+ }),
606
+ });
607
+ timerStart = Date.now();
608
+ hubPool = this.hubPool;
609
+ multicallFunctions = ["getCurrentTime", "rootBundleProposal"];
610
+ return [4, Promise.all(tslib_1.__spreadArray([
611
+ hubPool.callStatic.multicall(multicallFunctions.map(function (f) { return hubPool.interface.encodeFunctionData(f); }), { blockTag: searchConfig.to })
612
+ ], eventSearchConfigs.map(function (config) { return (0, utils_1.paginatedEventQuery)(hubPool, config.filter, config.searchConfig); }), true))];
613
+ case 2:
614
+ _a = _c.sent(), multicallOutput = _a[0], events = _a.slice(1);
615
+ _b = multicallFunctions.map(function (fn, idx) {
616
+ var output = hubPool.interface.decodeFunctionResult(fn, multicallOutput[idx]);
617
+ return output.length > 1 ? output : output[0];
618
+ }), currentTime = _b[0], pendingRootBundleProposal = _b[1];
619
+ this.logger.debug({
620
+ at: "HubPoolClient#_update",
621
+ message: "Time to query new events from RPC for ".concat(this.chainId, ": ").concat(Date.now() - timerStart, " ms"),
622
+ });
623
+ _events = Object.fromEntries(eventNames.map(function (eventName, idx) { return [eventName, events[idx]]; }));
624
+ return [2, {
625
+ success: true,
626
+ currentTime: currentTime,
627
+ pendingRootBundleProposal: tslib_1.__assign(tslib_1.__assign({}, pendingRootBundleProposal), { proposer: utils_1.EvmAddress.from(pendingRootBundleProposal.proposer) }),
628
+ searchEndBlock: searchConfig.to,
629
+ events: _events,
630
+ }];
573
631
  }
574
- }
575
- uniqueL1Tokens.forEach((token, i) => {
576
- this.lpTokens[token] = {
577
- lastLpFeeUpdate: lpTokenInfo[i].lastLpFeeUpdate,
578
- liquidReserves: lpTokenInfo[i].liquidReserves,
579
- };
580
632
  });
581
- }
582
- if (eventsToQuery.includes("ProposeRootBundle")) {
583
- this.proposedRootBundles.push(...events["ProposeRootBundle"]
584
- .filter((event) => !this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber))
585
- .map((_event) => {
586
- const args = (0, utils_1.spreadEventWithBlockNumber)(_event);
587
- return {
588
- ...args,
589
- proposer: utils_1.EvmAddress.from(args.proposer),
590
- };
591
- }));
592
- }
593
- if (eventsToQuery.includes("RootBundleCanceled")) {
594
- this.canceledRootBundles.push(...events["RootBundleCanceled"].map((event) => (0, utils_1.spreadEventWithBlockNumber)(event)));
595
- }
596
- if (eventsToQuery.includes("RootBundleDisputed")) {
597
- this.disputedRootBundles.push(...events["RootBundleDisputed"].map((event) => (0, utils_1.spreadEventWithBlockNumber)(event)));
598
- }
599
- if (eventsToQuery.includes("RootBundleExecuted")) {
600
- for (const event of events["RootBundleExecuted"]) {
601
- if (this.configOverride.ignoredHubExecutedBundles.includes(event.blockNumber)) {
602
- continue;
603
- }
604
- const executedRootBundle = (0, utils_1.spreadEventWithBlockNumber)(event);
605
- const { l1Tokens, runningBalances } = executedRootBundle;
606
- const nTokens = l1Tokens.length;
607
- if (![nTokens, nTokens * 2].includes(runningBalances.length)) {
608
- throw new Error(`Invalid runningBalances length: ${runningBalances.length}.` +
609
- ` Expected ${nTokens} or ${nTokens * 2} for chain ${this.chainId} transaction ${event.transactionHash}`);
610
- }
611
- executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
612
- this.executedRootBundles.push({
613
- ...executedRootBundle,
614
- l1Tokens: l1Tokens.map((l1Token) => utils_1.EvmAddress.from(l1Token)),
615
- });
616
- }
617
- }
618
- if (eventsToQuery.includes("ProposeRootBundle")) {
619
- if (pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount > 0) {
620
- const mostRecentProposedRootBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
621
- this.pendingRootBundle = {
622
- poolRebalanceRoot: pendingRootBundleProposal.poolRebalanceRoot,
623
- relayerRefundRoot: pendingRootBundleProposal.relayerRefundRoot,
624
- slowRelayRoot: pendingRootBundleProposal.slowRelayRoot,
625
- proposer: pendingRootBundleProposal.proposer,
626
- unclaimedPoolRebalanceLeafCount: pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount,
627
- challengePeriodEndTimestamp: pendingRootBundleProposal.challengePeriodEndTimestamp,
628
- bundleEvaluationBlockNumbers: mostRecentProposedRootBundle.bundleEvaluationBlockNumbers.map((block) => {
629
- try {
630
- return block.toNumber();
633
+ });
634
+ };
635
+ HubPoolClient.prototype.update = function () {
636
+ return tslib_1.__awaiter(this, arguments, void 0, function (eventsToQuery) {
637
+ var update, events, currentTime, pendingRootBundleProposal, searchEndBlock, _i, _a, event_1, args, dataToAdd, solanaSpokePool, svmSpoke, truncatedAddress, _b, _c, event_2, args, destinationToken, usdcTokenSol, svmUsdc, newRoute, uniqueL1Tokens, _d, tokenInfo, lpTokenInfo_1, _loop_1, this_1, _e, tokenInfo_1, info, _f, _g, event_3, executedRootBundle, l1Tokens, runningBalances, nTokens, mostRecentProposedRootBundle;
638
+ var _h, _j, _k;
639
+ var _this = this;
640
+ var _l;
641
+ if (eventsToQuery === void 0) { eventsToQuery = Object.keys(this.hubPoolEventFilters()); }
642
+ return tslib_1.__generator(this, function (_m) {
643
+ switch (_m.label) {
644
+ case 0:
645
+ if (!this.configStoreClient.isUpdated) {
646
+ throw new Error("ConfigStoreClient not updated");
631
647
  }
632
- catch {
633
- return 0;
648
+ return [4, this._update(eventsToQuery)];
649
+ case 1:
650
+ update = _m.sent();
651
+ if (!update.success) {
652
+ if (update.reason !== BaseAbstractClient_1.UpdateFailureReason.AlreadyUpdated) {
653
+ throw new Error("Unable to update HubPoolClient: ".concat(update.reason));
654
+ }
655
+ return [2];
634
656
  }
635
- }),
636
- proposalBlockNumber: mostRecentProposedRootBundle.blockNumber,
637
- };
638
- }
639
- else {
640
- this.pendingRootBundle = undefined;
641
- }
642
- }
643
- this.currentTime = currentTime;
644
- this.latestHeightSearched = searchEndBlock;
645
- this.firstHeightToSearch = update.searchEndBlock + 1;
646
- this.eventSearchConfig.to = undefined;
647
- this.isUpdated = true;
648
- this.logger.debug({ at: "HubPoolClient::update", message: "HubPool client updated!", searchEndBlock, currentTime });
649
- }
650
- getBundleEndBlockForChain(proposeRootBundleEvent, chainId, chainIdList) {
651
- const bundleEvaluationBlockNumbers = proposeRootBundleEvent.bundleEvaluationBlockNumbers;
652
- const chainIdIndex = chainIdList.indexOf(chainId);
657
+ events = update.events, currentTime = update.currentTime, pendingRootBundleProposal = update.pendingRootBundleProposal, searchEndBlock = update.searchEndBlock;
658
+ if (eventsToQuery.includes("CrossChainContractsSet")) {
659
+ for (_i = 0, _a = events["CrossChainContractsSet"]; _i < _a.length; _i++) {
660
+ event_1 = _a[_i];
661
+ args = (0, utils_1.spreadEventWithBlockNumber)(event_1);
662
+ dataToAdd = {
663
+ spokePool: utils_1.EvmAddress.from(args.spokePool),
664
+ blockNumber: args.blockNumber,
665
+ txnRef: args.txnRef,
666
+ logIndex: args.logIndex,
667
+ txnIndex: args.txnIndex,
668
+ l2ChainId: args.l2ChainId,
669
+ };
670
+ if ((0, utils_1.chainIsSvm)(args.l2ChainId)) {
671
+ solanaSpokePool = (0, utils_1.getDeployedAddress)("SvmSpoke", args.l2ChainId);
672
+ if (!solanaSpokePool) {
673
+ throw new Error("SVM spoke pool not found for chain ".concat(args.l2ChainId));
674
+ }
675
+ svmSpoke = utils_1.SvmAddress.from(solanaSpokePool);
676
+ truncatedAddress = svmSpoke.truncateToBytes20();
677
+ if (args.spokePool.toLowerCase() !== truncatedAddress.toLowerCase()) {
678
+ throw new Error("SVM spoke pool address mismatch for chain ".concat(args.l2ChainId, ". ") +
679
+ "Expected ".concat(truncatedAddress, ", got ").concat(args.spokePool));
680
+ }
681
+ dataToAdd.spokePool = svmSpoke;
682
+ }
683
+ (0, utils_1.assign)(this.crossChainContracts, [args.l2ChainId], [dataToAdd]);
684
+ }
685
+ }
686
+ if (eventsToQuery.includes("SetPoolRebalanceRoute")) {
687
+ for (_b = 0, _c = events["SetPoolRebalanceRoute"]; _b < _c.length; _b++) {
688
+ event_2 = _c[_b];
689
+ args = (0, utils_1.spreadEventWithBlockNumber)(event_2);
690
+ destinationToken = utils_1.EvmAddress.from(args.destinationToken);
691
+ if ((0, utils_1.chainIsSvm)(args.destinationChainId)) {
692
+ usdcTokenSol = constants_1.TOKEN_SYMBOLS_MAP.USDC.addresses[args.destinationChainId];
693
+ svmUsdc = utils_1.SvmAddress.from(usdcTokenSol);
694
+ if (destinationToken.truncateToBytes20() !== svmUsdc.truncateToBytes20()) {
695
+ throw new Error("SVM USDC address mismatch for chain ".concat(args.destinationChainId, ". ") +
696
+ "Expected ".concat(svmUsdc.truncateToBytes20(), ", got ").concat(destinationToken));
697
+ }
698
+ destinationToken = svmUsdc;
699
+ }
700
+ newRoute = {
701
+ l1Token: utils_1.EvmAddress.from(args.l1Token),
702
+ l2Token: destinationToken,
703
+ blockNumber: args.blockNumber,
704
+ txnIndex: args.txnIndex,
705
+ logIndex: args.logIndex,
706
+ txnRef: args.txnRef,
707
+ };
708
+ if ((_l = this.l1TokensToDestinationTokensWithBlock[args.l1Token]) === null || _l === void 0 ? void 0 : _l[args.destinationChainId]) {
709
+ this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId] = (0, utils_1.sortEventsDescending)(tslib_1.__spreadArray(tslib_1.__spreadArray([], this.l1TokensToDestinationTokensWithBlock[args.l1Token][args.destinationChainId], true), [
710
+ newRoute,
711
+ ], false));
712
+ }
713
+ else {
714
+ (0, utils_1.assign)(this.l1TokensToDestinationTokensWithBlock, [args.l1Token, args.destinationChainId], [newRoute]);
715
+ }
716
+ }
717
+ }
718
+ if (!eventsToQuery.includes("L1TokenEnabledForLiquidityProvision")) return [3, 3];
719
+ uniqueL1Tokens = (0, utils_1.dedupArray)(events["L1TokenEnabledForLiquidityProvision"].map(function (event) { return String(event.args["l1Token"]); }));
720
+ return [4, Promise.all([
721
+ Promise.all(uniqueL1Tokens.map(function (l1Token) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
722
+ var tokenInfo;
723
+ return tslib_1.__generator(this, function (_a) {
724
+ switch (_a.label) {
725
+ case 0: return [4, (0, utils_1.fetchTokenInfo)(l1Token, this.hubPool.provider)];
726
+ case 1:
727
+ tokenInfo = _a.sent();
728
+ return [2, tslib_1.__assign(tslib_1.__assign({}, tokenInfo), { address: utils_1.EvmAddress.from(l1Token) })];
729
+ }
730
+ });
731
+ }); })),
732
+ Promise.all(uniqueL1Tokens.map(function (l1Token) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
733
+ switch (_a.label) {
734
+ case 0: return [4, this.hubPool.pooledTokens(l1Token, { blockTag: update.searchEndBlock })];
735
+ case 1: return [2, _a.sent()];
736
+ }
737
+ }); }); })),
738
+ ])];
739
+ case 2:
740
+ _d = _m.sent(), tokenInfo = _d[0], lpTokenInfo_1 = _d[1];
741
+ _loop_1 = function (info) {
742
+ if (!this_1.l1Tokens.find(function (token) { return token.address.eq(info.address); })) {
743
+ if (info.decimals > 0 && info.decimals <= 18) {
744
+ this_1.l1Tokens.push(info);
745
+ }
746
+ else {
747
+ throw new Error("Unsupported HubPool token: ".concat(JSON.stringify(info)));
748
+ }
749
+ }
750
+ };
751
+ this_1 = this;
752
+ for (_e = 0, tokenInfo_1 = tokenInfo; _e < tokenInfo_1.length; _e++) {
753
+ info = tokenInfo_1[_e];
754
+ _loop_1(info);
755
+ }
756
+ uniqueL1Tokens.forEach(function (token, i) {
757
+ _this.lpTokens[token] = {
758
+ lastLpFeeUpdate: lpTokenInfo_1[i].lastLpFeeUpdate,
759
+ liquidReserves: lpTokenInfo_1[i].liquidReserves,
760
+ };
761
+ });
762
+ _m.label = 3;
763
+ case 3:
764
+ if (eventsToQuery.includes("ProposeRootBundle")) {
765
+ (_h = this.proposedRootBundles).push.apply(_h, events["ProposeRootBundle"]
766
+ .filter(function (event) { return !_this.configOverride.ignoredHubProposedBundles.includes(event.blockNumber); })
767
+ .map(function (_event) {
768
+ var args = (0, utils_1.spreadEventWithBlockNumber)(_event);
769
+ return tslib_1.__assign(tslib_1.__assign({}, args), { proposer: utils_1.EvmAddress.from(args.proposer) });
770
+ }));
771
+ }
772
+ if (eventsToQuery.includes("RootBundleCanceled")) {
773
+ (_j = this.canceledRootBundles).push.apply(_j, events["RootBundleCanceled"].map(function (event) { return (0, utils_1.spreadEventWithBlockNumber)(event); }));
774
+ }
775
+ if (eventsToQuery.includes("RootBundleDisputed")) {
776
+ (_k = this.disputedRootBundles).push.apply(_k, events["RootBundleDisputed"].map(function (event) { return (0, utils_1.spreadEventWithBlockNumber)(event); }));
777
+ }
778
+ if (eventsToQuery.includes("RootBundleExecuted")) {
779
+ for (_f = 0, _g = events["RootBundleExecuted"]; _f < _g.length; _f++) {
780
+ event_3 = _g[_f];
781
+ if (this.configOverride.ignoredHubExecutedBundles.includes(event_3.blockNumber)) {
782
+ continue;
783
+ }
784
+ executedRootBundle = (0, utils_1.spreadEventWithBlockNumber)(event_3);
785
+ l1Tokens = executedRootBundle.l1Tokens, runningBalances = executedRootBundle.runningBalances;
786
+ nTokens = l1Tokens.length;
787
+ if (![nTokens, nTokens * 2].includes(runningBalances.length)) {
788
+ throw new Error("Invalid runningBalances length: ".concat(runningBalances.length, ".") +
789
+ " Expected ".concat(nTokens, " or ").concat(nTokens * 2, " for chain ").concat(this.chainId, " transaction ").concat(event_3.transactionHash));
790
+ }
791
+ executedRootBundle.runningBalances = runningBalances.slice(0, nTokens);
792
+ this.executedRootBundles.push(tslib_1.__assign(tslib_1.__assign({}, executedRootBundle), { l1Tokens: l1Tokens.map(function (l1Token) { return utils_1.EvmAddress.from(l1Token); }) }));
793
+ }
794
+ }
795
+ if (eventsToQuery.includes("ProposeRootBundle")) {
796
+ if (pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount > 0) {
797
+ mostRecentProposedRootBundle = this.proposedRootBundles[this.proposedRootBundles.length - 1];
798
+ this.pendingRootBundle = {
799
+ poolRebalanceRoot: pendingRootBundleProposal.poolRebalanceRoot,
800
+ relayerRefundRoot: pendingRootBundleProposal.relayerRefundRoot,
801
+ slowRelayRoot: pendingRootBundleProposal.slowRelayRoot,
802
+ proposer: pendingRootBundleProposal.proposer,
803
+ unclaimedPoolRebalanceLeafCount: pendingRootBundleProposal.unclaimedPoolRebalanceLeafCount,
804
+ challengePeriodEndTimestamp: pendingRootBundleProposal.challengePeriodEndTimestamp,
805
+ bundleEvaluationBlockNumbers: mostRecentProposedRootBundle.bundleEvaluationBlockNumbers.map(function (block) {
806
+ try {
807
+ return block.toNumber();
808
+ }
809
+ catch (_a) {
810
+ return 0;
811
+ }
812
+ }),
813
+ proposalBlockNumber: mostRecentProposedRootBundle.blockNumber,
814
+ };
815
+ }
816
+ else {
817
+ this.pendingRootBundle = undefined;
818
+ }
819
+ }
820
+ this.currentTime = currentTime;
821
+ this.latestHeightSearched = searchEndBlock;
822
+ this.firstHeightToSearch = update.searchEndBlock + 1;
823
+ this.eventSearchConfig.to = undefined;
824
+ this.isUpdated = true;
825
+ this.logger.debug({ at: "HubPoolClient::update", message: "HubPool client updated!", searchEndBlock: searchEndBlock, currentTime: currentTime });
826
+ return [2];
827
+ }
828
+ });
829
+ });
830
+ };
831
+ HubPoolClient.prototype.getBundleEndBlockForChain = function (proposeRootBundleEvent, chainId, chainIdList) {
832
+ var bundleEvaluationBlockNumbers = proposeRootBundleEvent.bundleEvaluationBlockNumbers;
833
+ var chainIdIndex = chainIdList.indexOf(chainId);
653
834
  if (chainIdIndex === -1) {
654
835
  return 0;
655
836
  }
@@ -657,7 +838,8 @@ class HubPoolClient extends BaseAbstractClient_1.BaseAbstractClient {
657
838
  return 0;
658
839
  }
659
840
  return bundleEvaluationBlockNumbers[chainIdIndex].toNumber();
660
- }
661
- }
841
+ };
842
+ return HubPoolClient;
843
+ }(BaseAbstractClient_1.BaseAbstractClient));
662
844
  exports.HubPoolClient = HubPoolClient;
663
845
  //# sourceMappingURL=HubPoolClient.js.map