@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,54 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BundleDataClient = exports.INFINITE_FILL_DEADLINE = 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 interfaces_1 = require("../../interfaces");
8
- const evm_1 = require("../../arch/evm");
9
- const svm_1 = require("../../arch/svm");
10
- const utils_1 = require("../../utils");
11
- const utils_2 = require("./utils");
12
- const SpokePoolClient_1 = require("../SpokePoolClient");
13
- const SpokePoolClientManager_1 = require("../SpokePoolClient/SpokePoolClientManager");
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 interfaces_1 = require("../../interfaces");
8
+ var evm_1 = require("../../arch/evm");
9
+ var svm_1 = require("../../arch/svm");
10
+ var utils_1 = require("../../utils");
11
+ var utils_2 = require("./utils");
12
+ var SpokePoolClient_1 = require("../SpokePoolClient");
13
+ var SpokePoolClientManager_1 = require("../SpokePoolClient/SpokePoolClientManager");
14
14
  exports.INFINITE_FILL_DEADLINE = utils_1.bnUint32Max;
15
15
  function updateExpiredDepositsV3(dict, deposit) {
16
+ var _a, _b;
17
+ var _c, _d;
16
18
  if (!deposit.depositor.isValidOn(deposit.originChainId)) {
17
19
  return;
18
20
  }
19
- const { originChainId, inputToken } = deposit;
20
- dict[originChainId] ??= {};
21
- dict[originChainId][inputToken.toBytes32()] ??= [];
21
+ var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
22
+ (_a = dict[originChainId]) !== null && _a !== void 0 ? _a : (dict[originChainId] = {});
23
+ (_b = (_c = dict[originChainId])[_d = inputToken.toBytes32()]) !== null && _b !== void 0 ? _b : (_c[_d] = []);
22
24
  dict[originChainId][inputToken.toBytes32()].push(deposit);
23
25
  }
24
26
  function updateBundleDepositsV3(dict, deposit) {
25
- const { originChainId, inputToken } = deposit;
26
- dict[originChainId] ??= {};
27
- dict[originChainId][inputToken.toBytes32()] ??= [];
27
+ var _a, _b;
28
+ var _c, _d;
29
+ var originChainId = deposit.originChainId, inputToken = deposit.inputToken;
30
+ (_a = dict[originChainId]) !== null && _a !== void 0 ? _a : (dict[originChainId] = {});
31
+ (_b = (_c = dict[originChainId])[_d = inputToken.toBytes32()]) !== null && _b !== void 0 ? _b : (_c[_d] = []);
28
32
  dict[originChainId][inputToken.toBytes32()].push(deposit);
29
33
  }
30
34
  function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentToken, repaymentAddress) {
35
+ var _a, _b, _c;
36
+ var _d, _e;
31
37
  if (!fill.relayer.isValidOn(repaymentChainId)) {
32
38
  return;
33
39
  }
34
- dict[repaymentChainId] ??= {};
35
- dict[repaymentChainId][repaymentToken.toBytes32()] ??= {
40
+ (_a = dict[repaymentChainId]) !== null && _a !== void 0 ? _a : (dict[repaymentChainId] = {});
41
+ (_b = (_d = dict[repaymentChainId])[_e = repaymentToken.toBytes32()]) !== null && _b !== void 0 ? _b : (_d[_e] = {
36
42
  fills: [],
37
43
  totalRefundAmount: utils_1.bnZero,
38
44
  realizedLpFees: utils_1.bnZero,
39
45
  refunds: {},
40
- };
41
- const bundleFill = { ...fill, lpFeePct, relayer: repaymentAddress };
46
+ });
47
+ var bundleFill = tslib_1.__assign(tslib_1.__assign({}, fill), { lpFeePct: lpFeePct, relayer: repaymentAddress });
42
48
  (0, utils_1.assign)(dict, [repaymentChainId, repaymentToken.toBytes32(), "fills"], [bundleFill]);
43
- const refundObj = dict[repaymentChainId][repaymentToken.toBytes32()];
44
- const realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
49
+ var refundObj = dict[repaymentChainId][repaymentToken.toBytes32()];
50
+ var realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(utils_1.fixedPointAdjustment);
45
51
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
46
52
  if (!(0, utils_1.isSlowFill)(bundleFill)) {
47
- const refundAmount = bundleFill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
53
+ var refundAmount = bundleFill.inputAmount.mul(utils_1.fixedPointAdjustment.sub(lpFeePct)).div(utils_1.fixedPointAdjustment);
48
54
  refundObj.totalRefundAmount = refundObj.totalRefundAmount
49
55
  ? refundObj.totalRefundAmount.add(refundAmount)
50
56
  : refundAmount;
51
- refundObj.refunds ??= {};
57
+ (_c = refundObj.refunds) !== null && _c !== void 0 ? _c : (refundObj.refunds = {});
52
58
  if (refundObj.refunds[bundleFill.relayer.toBytes32()]) {
53
59
  refundObj.refunds[bundleFill.relayer.toBytes32()] =
54
60
  refundObj.refunds[bundleFill.relayer.toBytes32()].add(refundAmount);
@@ -59,739 +65,924 @@ function updateBundleFillsV3(dict, fill, lpFeePct, repaymentChainId, repaymentTo
59
65
  }
60
66
  }
61
67
  function updateBundleExcessSlowFills(dict, deposit) {
62
- const { destinationChainId, outputToken } = deposit;
63
- dict[destinationChainId] ??= {};
64
- dict[destinationChainId][outputToken.toBytes32()] ??= [];
68
+ var _a, _b;
69
+ var _c, _d;
70
+ var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
71
+ (_a = dict[destinationChainId]) !== null && _a !== void 0 ? _a : (dict[destinationChainId] = {});
72
+ (_b = (_c = dict[destinationChainId])[_d = outputToken.toBytes32()]) !== null && _b !== void 0 ? _b : (_c[_d] = []);
65
73
  dict[destinationChainId][outputToken.toBytes32()].push(deposit);
66
74
  }
67
75
  function updateBundleSlowFills(dict, deposit) {
76
+ var _a, _b;
77
+ var _c, _d;
68
78
  if (!deposit.recipient.isValidOn(deposit.destinationChainId)) {
69
79
  return;
70
80
  }
71
- const { destinationChainId, outputToken } = deposit;
72
- dict[destinationChainId] ??= {};
73
- dict[destinationChainId][outputToken.toBytes32()] ??= [];
81
+ var destinationChainId = deposit.destinationChainId, outputToken = deposit.outputToken;
82
+ (_a = dict[destinationChainId]) !== null && _a !== void 0 ? _a : (dict[destinationChainId] = {});
83
+ (_b = (_c = dict[destinationChainId])[_d = outputToken.toBytes32()]) !== null && _b !== void 0 ? _b : (_c[_d] = []);
74
84
  dict[destinationChainId][outputToken.toBytes32()].push(deposit);
75
85
  }
76
- class BundleDataClient {
77
- logger;
78
- clients;
79
- chainIdListForBundleEvaluationBlockNumbers;
80
- blockRangeEndBlockBuffer;
81
- loadDataCache = {};
82
- arweaveDataCache = {};
83
- bundleTimestampCache = {};
84
- spokePoolClientManager;
85
- constructor(logger, clients, spokePoolClients, chainIdListForBundleEvaluationBlockNumbers, blockRangeEndBlockBuffer = {}) {
86
+ var BundleDataClient = (function () {
87
+ function BundleDataClient(logger, clients, spokePoolClients, chainIdListForBundleEvaluationBlockNumbers, blockRangeEndBlockBuffer) {
88
+ if (blockRangeEndBlockBuffer === void 0) { blockRangeEndBlockBuffer = {}; }
86
89
  this.logger = logger;
87
90
  this.clients = clients;
88
91
  this.chainIdListForBundleEvaluationBlockNumbers = chainIdListForBundleEvaluationBlockNumbers;
89
92
  this.blockRangeEndBlockBuffer = blockRangeEndBlockBuffer;
93
+ this.loadDataCache = {};
94
+ this.arweaveDataCache = {};
95
+ this.bundleTimestampCache = {};
90
96
  this.spokePoolClientManager = new SpokePoolClientManager_1.SpokePoolManager(logger, spokePoolClients);
91
97
  }
92
- clearCache() {
98
+ BundleDataClient.prototype.clearCache = function () {
93
99
  this.loadDataCache = {};
94
- }
95
- async loadDataFromCache(key) {
96
- return lodash_1.default.cloneDeep(await this.loadDataCache[key]);
97
- }
98
- getBundleTimestampsFromCache(key) {
100
+ };
101
+ BundleDataClient.prototype.loadDataFromCache = function (key) {
102
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
103
+ var _a, _b;
104
+ return tslib_1.__generator(this, function (_c) {
105
+ switch (_c.label) {
106
+ case 0:
107
+ _b = (_a = lodash_1.default).cloneDeep;
108
+ return [4, this.loadDataCache[key]];
109
+ case 1: return [2, _b.apply(_a, [_c.sent()])];
110
+ }
111
+ });
112
+ });
113
+ };
114
+ BundleDataClient.prototype.getBundleTimestampsFromCache = function (key) {
99
115
  if (this.bundleTimestampCache[key]) {
100
116
  return lodash_1.default.cloneDeep(this.bundleTimestampCache[key]);
101
117
  }
102
118
  return undefined;
103
- }
104
- setBundleTimestampsInCache(key, timestamps) {
119
+ };
120
+ BundleDataClient.prototype.setBundleTimestampsInCache = function (key, timestamps) {
105
121
  this.bundleTimestampCache[key] = timestamps;
106
- }
107
- static getArweaveClientKey(blockRangesForChains) {
122
+ };
123
+ BundleDataClient.getArweaveClientKey = function (blockRangesForChains) {
108
124
  return blockRangesForChains[0][1].toString();
109
- }
110
- getArweaveBundleDataClientKey(blockRangesForChains) {
111
- return `bundles-${BundleDataClient.getArweaveClientKey(blockRangesForChains)}`;
112
- }
113
- async loadPersistedDataFromArweave(blockRangesForChains) {
114
- if (!(0, utils_1.isDefined)(this.clients?.arweaveClient)) {
115
- return undefined;
116
- }
117
- const start = performance.now();
118
- const persistedData = await this.clients.arweaveClient.getByTopic(this.getArweaveBundleDataClientKey(blockRangesForChains), utils_2.BundleDataSS);
119
- if (!(0, utils_1.isDefined)(persistedData) || persistedData.length < 1) {
120
- return undefined;
121
- }
122
- const convertTypedStringRecordIntoNumericRecord = (data) => Object.keys(data).reduce((acc, chainId) => {
123
- acc[Number(chainId)] = data[chainId];
124
- return acc;
125
- }, {});
126
- const convertSortableEventFieldsIntoRequiredFields = (data) => {
127
- return data.map((item) => {
128
- if ((item.txnIndex !== undefined && item.transactionIndex !== undefined) ||
129
- (item.txnIndex === undefined && item.transactionIndex === undefined)) {
130
- throw new Error("Either txnIndex or transactionIndex must be defined, but not both.");
131
- }
132
- if ((item.txnRef !== undefined && item.transactionHash !== undefined) ||
133
- (item.txnRef === undefined && item.transactionHash === undefined)) {
134
- throw new Error("Either txnRef or transactionHash must be defined, but not both.");
125
+ };
126
+ BundleDataClient.prototype.getArweaveBundleDataClientKey = function (blockRangesForChains) {
127
+ return "bundles-".concat(BundleDataClient.getArweaveClientKey(blockRangesForChains));
128
+ };
129
+ BundleDataClient.prototype.loadPersistedDataFromArweave = function (blockRangesForChains) {
130
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
131
+ var start, persistedData, convertTypedStringRecordIntoNumericRecord, convertSortableEventFieldsIntoRequiredFields, convertEmbeddedSortableEventFieldsIntoRequiredFields, data, bundleData;
132
+ var _a;
133
+ return tslib_1.__generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ if (!(0, utils_1.isDefined)((_a = this.clients) === null || _a === void 0 ? void 0 : _a.arweaveClient)) {
137
+ return [2, undefined];
138
+ }
139
+ start = performance.now();
140
+ return [4, this.clients.arweaveClient.getByTopic(this.getArweaveBundleDataClientKey(blockRangesForChains), utils_2.BundleDataSS)];
141
+ case 1:
142
+ persistedData = _b.sent();
143
+ if (!(0, utils_1.isDefined)(persistedData) || persistedData.length < 1) {
144
+ return [2, undefined];
145
+ }
146
+ convertTypedStringRecordIntoNumericRecord = function (data) {
147
+ return Object.keys(data).reduce(function (acc, chainId) {
148
+ acc[Number(chainId)] = data[chainId];
149
+ return acc;
150
+ }, {});
151
+ };
152
+ convertSortableEventFieldsIntoRequiredFields = function (data) {
153
+ return data.map(function (item) {
154
+ if ((item.txnIndex !== undefined && item.transactionIndex !== undefined) ||
155
+ (item.txnIndex === undefined && item.transactionIndex === undefined)) {
156
+ throw new Error("Either txnIndex or transactionIndex must be defined, but not both.");
157
+ }
158
+ if ((item.txnRef !== undefined && item.transactionHash !== undefined) ||
159
+ (item.txnRef === undefined && item.transactionHash === undefined)) {
160
+ throw new Error("Either txnRef or transactionHash must be defined, but not both.");
161
+ }
162
+ var txnIndex = item.txnIndex, transactionIndex = item.transactionIndex, txnRef = item.txnRef, transactionHash = item.transactionHash, rest = tslib_1.__rest(item, ["txnIndex", "transactionIndex", "txnRef", "transactionHash"]);
163
+ return tslib_1.__assign(tslib_1.__assign({}, rest), { txnIndex: txnIndex !== null && txnIndex !== void 0 ? txnIndex : transactionIndex, txnRef: txnRef !== null && txnRef !== void 0 ? txnRef : transactionHash });
164
+ });
165
+ };
166
+ convertEmbeddedSortableEventFieldsIntoRequiredFields = function (data) {
167
+ return Object.fromEntries(Object.entries(data).map(function (_a) {
168
+ var chainId = _a[0], tokenData = _a[1];
169
+ return [
170
+ chainId,
171
+ Object.fromEntries(Object.entries(tokenData).map(function (_a) {
172
+ var token = _a[0], data = _a[1];
173
+ return [
174
+ token,
175
+ convertSortableEventFieldsIntoRequiredFields(data),
176
+ ];
177
+ })),
178
+ ];
179
+ }));
180
+ };
181
+ data = persistedData[0].data;
182
+ bundleData = {
183
+ bundleFillsV3: convertTypedStringRecordIntoNumericRecord(Object.fromEntries(Object.entries(data.bundleFillsV3).map(function (_a) {
184
+ var chainId = _a[0], tokenData = _a[1];
185
+ return [
186
+ chainId,
187
+ Object.fromEntries(Object.entries(tokenData).map(function (_a) {
188
+ var token = _a[0], data = _a[1];
189
+ return [
190
+ token,
191
+ {
192
+ refunds: Object.fromEntries(Object.entries(data.refunds).map(function (_a) {
193
+ var refundAddress = _a[0], refund = _a[1];
194
+ return [(0, utils_1.toBytes32)(refundAddress), refund];
195
+ })),
196
+ totalRefundAmount: data.totalRefundAmount,
197
+ realizedLpFees: data.realizedLpFees,
198
+ fills: convertSortableEventFieldsIntoRequiredFields(data.fills),
199
+ },
200
+ ];
201
+ })),
202
+ ];
203
+ }))),
204
+ expiredDepositsToRefundV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.expiredDepositsToRefundV3)),
205
+ bundleDepositsV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleDepositsV3)),
206
+ unexecutableSlowFills: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.unexecutableSlowFills)),
207
+ bundleSlowFillsV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleSlowFillsV3)),
208
+ };
209
+ this.logger.debug({
210
+ at: "BundleDataClient#loadPersistedDataFromArweave",
211
+ message: "Loaded persisted data from Arweave in ".concat(Math.round(performance.now() - start) / 1000, "s."),
212
+ blockRanges: JSON.stringify(blockRangesForChains),
213
+ bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
214
+ });
215
+ return [2, bundleData];
135
216
  }
136
- const { txnIndex, transactionIndex, txnRef, transactionHash, ...rest } = item;
137
- return {
138
- ...rest,
139
- txnIndex: txnIndex ?? transactionIndex,
140
- txnRef: txnRef ?? transactionHash,
141
- };
142
217
  });
143
- };
144
- const convertEmbeddedSortableEventFieldsIntoRequiredFields = (data) => {
145
- return Object.fromEntries(Object.entries(data).map(([chainId, tokenData]) => [
146
- chainId,
147
- Object.fromEntries(Object.entries(tokenData).map(([token, data]) => [
148
- token,
149
- convertSortableEventFieldsIntoRequiredFields(data),
150
- ])),
151
- ]));
152
- };
153
- const data = persistedData[0].data;
154
- const bundleData = {
155
- bundleFillsV3: convertTypedStringRecordIntoNumericRecord(Object.fromEntries(Object.entries(data.bundleFillsV3).map(([chainId, tokenData]) => [
156
- chainId,
157
- Object.fromEntries(Object.entries(tokenData).map(([token, data]) => [
158
- token,
159
- {
160
- refunds: Object.fromEntries(Object.entries(data.refunds).map(([refundAddress, refund]) => [(0, utils_1.toBytes32)(refundAddress), refund])),
161
- totalRefundAmount: data.totalRefundAmount,
162
- realizedLpFees: data.realizedLpFees,
163
- fills: convertSortableEventFieldsIntoRequiredFields(data.fills),
164
- },
165
- ])),
166
- ]))),
167
- expiredDepositsToRefundV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.expiredDepositsToRefundV3)),
168
- bundleDepositsV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleDepositsV3)),
169
- unexecutableSlowFills: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.unexecutableSlowFills)),
170
- bundleSlowFillsV3: convertTypedStringRecordIntoNumericRecord(convertEmbeddedSortableEventFieldsIntoRequiredFields(data.bundleSlowFillsV3)),
171
- };
172
- this.logger.debug({
173
- at: "BundleDataClient#loadPersistedDataFromArweave",
174
- message: `Loaded persisted data from Arweave in ${Math.round(performance.now() - start) / 1000}s.`,
175
- blockRanges: JSON.stringify(blockRangesForChains),
176
- bundleData: (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleData.bundleDepositsV3, bundleData.bundleFillsV3, bundleData.bundleSlowFillsV3, bundleData.expiredDepositsToRefundV3, bundleData.unexecutableSlowFills),
177
218
  });
178
- return bundleData;
179
- }
180
- async loadArweaveData(blockRangesForChains) {
181
- const arweaveKey = this.getArweaveBundleDataClientKey(blockRangesForChains);
182
- if (!this.arweaveDataCache[arweaveKey]) {
183
- this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains);
184
- }
185
- const arweaveData = lodash_1.default.cloneDeep(await this.arweaveDataCache[arweaveKey]);
186
- return arweaveData;
187
- }
188
- async loadData(blockRangesForChains, spokePoolClients, attemptArweaveLoad = false) {
189
- const key = JSON.stringify(blockRangesForChains);
190
- if (!this.loadDataCache[key]) {
191
- let arweaveData;
192
- if (attemptArweaveLoad) {
193
- arweaveData = await this.loadArweaveData(blockRangesForChains);
194
- }
195
- else {
196
- arweaveData = undefined;
197
- }
198
- const data = (0, utils_1.isDefined)(arweaveData)
199
- ?
200
- Promise.resolve(arweaveData)
201
- : this.loadDataFromScratch(blockRangesForChains, spokePoolClients);
202
- this.loadDataCache[key] = data;
203
- }
204
- return this.loadDataFromCache(key);
205
- }
206
- async loadDataFromScratch(blockRangesForChains, spokePoolClients) {
207
- let start = performance.now();
208
- const key = JSON.stringify(blockRangesForChains);
209
- if (!this.clients.configStoreClient.isUpdated) {
210
- throw new Error("ConfigStoreClient not updated");
211
- }
212
- else if (!this.clients.hubPoolClient.isUpdated) {
213
- throw new Error("HubPoolClient not updated");
214
- }
215
- const [bundleStartBlockForMainnet, bundleEndBlockForMainnet] = blockRangesForChains[0];
216
- const chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(bundleStartBlockForMainnet);
217
- if (blockRangesForChains.length > chainIds.length) {
218
- throw new Error(`Unexpected block range list length of ${blockRangesForChains.length}, should be <= ${chainIds.length}`);
219
- }
220
- const bundleDepositsV3 = {};
221
- const bundleFillsV3 = {};
222
- const bundleInvalidFillsV3 = [];
223
- const bundleUnrepayableFillsV3 = [];
224
- const bundleInvalidSlowFillRequests = [];
225
- const bundleSlowFillsV3 = {};
226
- const expiredDepositsToRefundV3 = {};
227
- const unexecutableSlowFills = {};
228
- const _canCreateSlowFillLeaf = (deposit) => {
229
- return (this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, bundleEndBlockForMainnet) &&
230
- !deposit.fromLiteChain &&
231
- !deposit.toLiteChain);
232
- };
233
- const _depositIsExpired = (deposit) => {
234
- return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
235
- };
236
- const _getFillStatusForDeposit = (deposit, queryBlock) => {
237
- return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit, Math.min(queryBlock, spokePoolClients[deposit.destinationChainId].latestHeightSearched));
238
- };
239
- const allChainIds = blockRangesForChains
240
- .map((_blockRange, index) => chainIds[index])
241
- .filter((chainId) => !(0, utils_2.isChainDisabledAtBlock)(chainId, bundleStartBlockForMainnet, this.clients.configStoreClient) &&
242
- spokePoolClients[chainId] !== undefined);
243
- allChainIds.forEach((chainId) => {
244
- const spokePoolClient = spokePoolClients[chainId];
245
- if (!spokePoolClient.isUpdated) {
246
- throw new Error(`SpokePoolClient for chain ${chainId} not updated.`);
247
- }
219
+ };
220
+ BundleDataClient.prototype.loadArweaveData = function (blockRangesForChains) {
221
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
222
+ var arweaveKey, arweaveData, _a, _b;
223
+ return tslib_1.__generator(this, function (_c) {
224
+ switch (_c.label) {
225
+ case 0:
226
+ arweaveKey = this.getArweaveBundleDataClientKey(blockRangesForChains);
227
+ if (!this.arweaveDataCache[arweaveKey]) {
228
+ this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains);
229
+ }
230
+ _b = (_a = lodash_1.default).cloneDeep;
231
+ return [4, this.arweaveDataCache[arweaveKey]];
232
+ case 1:
233
+ arweaveData = _b.apply(_a, [_c.sent()]);
234
+ return [2, arweaveData];
235
+ }
236
+ });
248
237
  });
249
- const _cachedBundleTimestamps = this.getBundleTimestampsFromCache(key);
250
- let bundleBlockTimestamps = {};
251
- if (!_cachedBundleTimestamps) {
252
- bundleBlockTimestamps = await this.getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients);
253
- this.setBundleTimestampsInCache(key, bundleBlockTimestamps);
254
- this.logger.debug({
255
- at: "BundleDataClient#loadData",
256
- message: "Bundle block timestamps",
257
- bundleBlockTimestamps,
258
- blockRangesForChains: JSON.stringify(blockRangesForChains),
238
+ };
239
+ BundleDataClient.prototype.loadData = function (blockRangesForChains_1, spokePoolClients_1) {
240
+ return tslib_1.__awaiter(this, arguments, void 0, function (blockRangesForChains, spokePoolClients, attemptArweaveLoad) {
241
+ var key, arweaveData, data;
242
+ if (attemptArweaveLoad === void 0) { attemptArweaveLoad = false; }
243
+ return tslib_1.__generator(this, function (_a) {
244
+ switch (_a.label) {
245
+ case 0:
246
+ key = JSON.stringify(blockRangesForChains);
247
+ if (!!this.loadDataCache[key]) return [3, 4];
248
+ arweaveData = void 0;
249
+ if (!attemptArweaveLoad) return [3, 2];
250
+ return [4, this.loadArweaveData(blockRangesForChains)];
251
+ case 1:
252
+ arweaveData = _a.sent();
253
+ return [3, 3];
254
+ case 2:
255
+ arweaveData = undefined;
256
+ _a.label = 3;
257
+ case 3:
258
+ data = (0, utils_1.isDefined)(arweaveData)
259
+ ?
260
+ Promise.resolve(arweaveData)
261
+ : this.loadDataFromScratch(blockRangesForChains, spokePoolClients);
262
+ this.loadDataCache[key] = data;
263
+ _a.label = 4;
264
+ case 4: return [2, this.loadDataFromCache(key)];
265
+ }
259
266
  });
260
- }
261
- else {
262
- bundleBlockTimestamps = _cachedBundleTimestamps;
263
- }
264
- const v3RelayHashes = {};
265
- const bundleDepositHashes = [];
266
- const olderDepositHashes = [];
267
- const decodeBundleDepositHash = (depositHash) => {
268
- const [relayDataHash, i] = depositHash.split("@");
269
- return { relayDataHash, index: Number(i) };
270
- };
271
- for (const originChainId of allChainIds) {
272
- const originClient = spokePoolClients[originChainId];
273
- const originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
274
- for (const destinationChainId of allChainIds) {
275
- originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach((deposit) => {
276
- if (deposit.blockNumber > originChainBlockRange[1] || (0, utils_1.isZeroValueDeposit)(deposit)) {
277
- return;
278
- }
279
- const relayDataHash = (0, utils_1.getRelayEventKey)(deposit);
280
- if (!v3RelayHashes[relayDataHash]) {
281
- v3RelayHashes[relayDataHash] = {
282
- deposits: [deposit],
283
- fill: undefined,
284
- slowFillRequest: undefined,
285
- };
286
- }
287
- else {
288
- const { deposits } = v3RelayHashes[relayDataHash];
289
- (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
290
- deposits.push(deposit);
291
- }
292
- const { deposits } = v3RelayHashes[relayDataHash];
293
- (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
294
- const newBundleDepositHash = `${relayDataHash}@${deposits.length - 1}`;
295
- const decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
296
- (0, assert_1.default)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
297
- decodedBundleDepositHash.index === deposits.length - 1, "Not using correct bundle deposit hash key");
298
- if (deposit.blockNumber >= originChainBlockRange[0]) {
299
- if (bundleDepositsV3?.[originChainId]?.[deposit.inputToken.toBytes32()]?.find((d) => (0, utils_1.duplicateEvent)(deposit, d))) {
300
- this.logger.debug({
301
- at: "BundleDataClient#loadData",
302
- message: "Duplicate deposit detected",
303
- deposit: (0, utils_1.convertRelayDataParamsToBytes32)(deposit),
304
- });
305
- throw new Error("Duplicate deposit detected");
306
- }
307
- bundleDepositHashes.push(newBundleDepositHash);
308
- updateBundleDepositsV3(bundleDepositsV3, deposit);
309
- }
310
- else if (deposit.blockNumber < originChainBlockRange[0]) {
311
- olderDepositHashes.push(newBundleDepositHash);
312
- }
313
- });
314
- }
315
- }
316
- this.logger.debug({
317
- at: "BundleDataClient#loadData",
318
- message: `Processed ${bundleDepositHashes.length + olderDepositHashes.length} deposits in ${performance.now() - start}ms.`,
319
267
  });
320
- start = performance.now();
321
- const validatedBundleV3Fills = [];
322
- const validatedBundleSlowFills = [];
323
- const validatedBundleUnexecutableSlowFills = [];
324
- let fillCounter = 0;
325
- for (const originChainId of allChainIds) {
326
- const originClient = spokePoolClients[originChainId];
327
- for (const destinationChainId of allChainIds) {
328
- const destinationClient = spokePoolClients[destinationChainId];
329
- const destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
330
- const originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
331
- const fastFillsReplacingSlowFills = [];
332
- await (0, utils_1.forEachAsync)(destinationClient
333
- .getFillsForOriginChain(originChainId)
334
- .filter((fill) => fill.blockNumber <= destinationChainBlockRange[1] &&
335
- !(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill) &&
336
- !(0, utils_1.invalidOutputToken)(fill)), async (fill) => {
337
- fillCounter++;
338
- const relayDataHash = (0, utils_1.getRelayEventKey)(fill);
339
- if (v3RelayHashes[relayDataHash]) {
340
- if (!v3RelayHashes[relayDataHash].fill) {
341
- const { deposits } = v3RelayHashes[relayDataHash];
342
- (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
343
- v3RelayHashes[relayDataHash].fill = fill;
344
- if (fill.blockNumber >= destinationChainBlockRange[0]) {
345
- let provider;
346
- if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
347
- provider = destinationClient.spokePool.provider;
348
- }
349
- else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
350
- provider = destinationClient.svmEventsClient.getRpc();
351
- }
352
- const fillToRefund = await (0, utils_2.verifyFillRepayment)(fill, provider, deposits[0], this.clients.hubPoolClient, bundleEndBlockForMainnet);
353
- if (!(0, utils_1.isDefined)(fillToRefund)) {
354
- bundleUnrepayableFillsV3.push(fill);
355
- }
356
- else {
357
- v3RelayHashes[relayDataHash].fill = fillToRefund;
358
- validatedBundleV3Fills.push({
359
- ...fillToRefund,
360
- quoteTimestamp: deposits[0].quoteTimestamp,
361
- });
362
- const duplicateDeposits = deposits.slice(1);
363
- duplicateDeposits.forEach((duplicateDeposit) => {
364
- if ((0, utils_1.isSlowFill)(fill)) {
365
- updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
366
- }
367
- else {
368
- validatedBundleV3Fills.push({
369
- ...fillToRefund,
370
- quoteTimestamp: duplicateDeposit.quoteTimestamp,
371
- });
372
- }
373
- });
374
- }
375
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
376
- _canCreateSlowFillLeaf(deposits[0])) {
377
- fastFillsReplacingSlowFills.push(relayDataHash);
378
- }
379
- }
380
- }
381
- else {
382
- this.logger.debug({
383
- at: "BundleDataClient#loadData",
384
- message: "Duplicate fill detected",
385
- fill: (0, utils_1.convertFillParamsToBytes32)(fill),
386
- });
387
- throw new Error("Duplicate fill detected");
268
+ };
269
+ BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
270
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
271
+ var start, key, _a, bundleStartBlockForMainnet, bundleEndBlockForMainnet, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleUnrepayableFillsV3, bundleInvalidSlowFillRequests, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, decodeBundleDepositHash, _loop_1, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_2, _b, allChainIds_2, originChainId, promises, _c, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable, invalidFillsWithPartialMatchedDeposits_1, preFillsForNextBundle_1, unknownReasonInvalidFills_1;
272
+ var _this = this;
273
+ return tslib_1.__generator(this, function (_d) {
274
+ switch (_d.label) {
275
+ case 0:
276
+ start = performance.now();
277
+ key = JSON.stringify(blockRangesForChains);
278
+ if (!this.clients.configStoreClient.isUpdated) {
279
+ throw new Error("ConfigStoreClient not updated");
388
280
  }
389
- return;
390
- }
391
- v3RelayHashes[relayDataHash] = {
392
- deposits: undefined,
393
- fill,
394
- slowFillRequest: undefined,
395
- };
396
- if (fill.blockNumber >= destinationChainBlockRange[0]) {
397
- if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
398
- bundleInvalidFillsV3.push(fill);
399
- return;
281
+ else if (!this.clients.hubPoolClient.isUpdated) {
282
+ throw new Error("HubPoolClient not updated");
400
283
  }
401
- const historicalDeposit = await (0, utils_1.queryHistoricalDepositForFill)(originClient, fill);
402
- if (!historicalDeposit.found) {
403
- bundleInvalidFillsV3.push(fill);
284
+ _a = blockRangesForChains[0], bundleStartBlockForMainnet = _a[0], bundleEndBlockForMainnet = _a[1];
285
+ chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(bundleStartBlockForMainnet);
286
+ if (blockRangesForChains.length > chainIds.length) {
287
+ throw new Error("Unexpected block range list length of ".concat(blockRangesForChains.length, ", should be <= ").concat(chainIds.length));
404
288
  }
405
- else {
406
- const matchedDeposit = historicalDeposit.deposit;
407
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
408
- bundleInvalidFillsV3.push(fill);
409
- return;
410
- }
411
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
412
- let provider;
413
- if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
414
- provider = destinationClient.spokePool.provider;
415
- }
416
- else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
417
- provider = destinationClient.svmEventsClient.getRpc();
418
- }
419
- const fillToRefund = await (0, utils_2.verifyFillRepayment)(fill, provider, matchedDeposit, this.clients.hubPoolClient, bundleEndBlockForMainnet);
420
- if (!(0, utils_1.isDefined)(fillToRefund)) {
421
- bundleUnrepayableFillsV3.push(fill);
289
+ bundleDepositsV3 = {};
290
+ bundleFillsV3 = {};
291
+ bundleInvalidFillsV3 = [];
292
+ bundleUnrepayableFillsV3 = [];
293
+ bundleInvalidSlowFillRequests = [];
294
+ bundleSlowFillsV3 = {};
295
+ expiredDepositsToRefundV3 = {};
296
+ unexecutableSlowFills = {};
297
+ _canCreateSlowFillLeaf = function (deposit) {
298
+ return (_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, bundleEndBlockForMainnet) &&
299
+ !deposit.fromLiteChain &&
300
+ !deposit.toLiteChain);
301
+ };
302
+ _depositIsExpired = function (deposit) {
303
+ return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
304
+ };
305
+ _getFillStatusForDeposit = function (deposit, queryBlock) {
306
+ return spokePoolClients[deposit.destinationChainId].relayFillStatus(deposit, Math.min(queryBlock, spokePoolClients[deposit.destinationChainId].latestHeightSearched));
307
+ };
308
+ allChainIds = blockRangesForChains
309
+ .map(function (_blockRange, index) { return chainIds[index]; })
310
+ .filter(function (chainId) {
311
+ return !(0, utils_2.isChainDisabledAtBlock)(chainId, bundleStartBlockForMainnet, _this.clients.configStoreClient) &&
312
+ spokePoolClients[chainId] !== undefined;
313
+ });
314
+ allChainIds.forEach(function (chainId) {
315
+ var spokePoolClient = spokePoolClients[chainId];
316
+ if (!spokePoolClient.isUpdated) {
317
+ throw new Error("SpokePoolClient for chain ".concat(chainId, " not updated."));
422
318
  }
423
- else {
424
- (0, assert_1.default)((0, utils_1.getRelayEventKey)(matchedDeposit) === relayDataHash, "Relay hashes should match.");
425
- validatedBundleV3Fills.push({
426
- ...fillToRefund,
427
- quoteTimestamp: matchedDeposit.quoteTimestamp,
319
+ });
320
+ _cachedBundleTimestamps = this.getBundleTimestampsFromCache(key);
321
+ bundleBlockTimestamps = {};
322
+ if (!!_cachedBundleTimestamps) return [3, 2];
323
+ return [4, this.getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients)];
324
+ case 1:
325
+ bundleBlockTimestamps = _d.sent();
326
+ this.setBundleTimestampsInCache(key, bundleBlockTimestamps);
327
+ this.logger.debug({
328
+ at: "BundleDataClient#loadData",
329
+ message: "Bundle block timestamps",
330
+ bundleBlockTimestamps: bundleBlockTimestamps,
331
+ blockRangesForChains: JSON.stringify(blockRangesForChains),
332
+ });
333
+ return [3, 3];
334
+ case 2:
335
+ bundleBlockTimestamps = _cachedBundleTimestamps;
336
+ _d.label = 3;
337
+ case 3:
338
+ v3RelayHashes = {};
339
+ bundleDepositHashes = [];
340
+ olderDepositHashes = [];
341
+ decodeBundleDepositHash = function (depositHash) {
342
+ var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
343
+ return { relayDataHash: relayDataHash, index: Number(i) };
344
+ };
345
+ _loop_1 = function (originChainId) {
346
+ var originClient = spokePoolClients[originChainId];
347
+ var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
348
+ for (var _e = 0, allChainIds_3 = allChainIds; _e < allChainIds_3.length; _e++) {
349
+ var destinationChainId = allChainIds_3[_e];
350
+ originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
351
+ var _a, _b;
352
+ if (deposit.blockNumber > originChainBlockRange[1] || (0, utils_1.isZeroValueDeposit)(deposit)) {
353
+ return;
354
+ }
355
+ var relayDataHash = (0, utils_1.getRelayEventKey)(deposit);
356
+ if (!v3RelayHashes[relayDataHash]) {
357
+ v3RelayHashes[relayDataHash] = {
358
+ deposits: [deposit],
359
+ fill: undefined,
360
+ slowFillRequest: undefined,
361
+ };
362
+ }
363
+ else {
364
+ var deposits_1 = v3RelayHashes[relayDataHash].deposits;
365
+ (0, assert_1.default)((0, utils_1.isDefined)(deposits_1) && deposits_1.length > 0, "Deposit should exist in relay hash dictionary.");
366
+ deposits_1.push(deposit);
367
+ }
368
+ var deposits = v3RelayHashes[relayDataHash].deposits;
369
+ (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
370
+ var newBundleDepositHash = "".concat(relayDataHash, "@").concat(deposits.length - 1);
371
+ var decodedBundleDepositHash = decodeBundleDepositHash(newBundleDepositHash);
372
+ (0, assert_1.default)(decodedBundleDepositHash.relayDataHash === relayDataHash &&
373
+ decodedBundleDepositHash.index === deposits.length - 1, "Not using correct bundle deposit hash key");
374
+ if (deposit.blockNumber >= originChainBlockRange[0]) {
375
+ if ((_b = (_a = bundleDepositsV3 === null || bundleDepositsV3 === void 0 ? void 0 : bundleDepositsV3[originChainId]) === null || _a === void 0 ? void 0 : _a[deposit.inputToken.toBytes32()]) === null || _b === void 0 ? void 0 : _b.find(function (d) {
376
+ return (0, utils_1.duplicateEvent)(deposit, d);
377
+ })) {
378
+ _this.logger.debug({
379
+ at: "BundleDataClient#loadData",
380
+ message: "Duplicate deposit detected",
381
+ deposit: (0, utils_1.convertRelayDataParamsToBytes32)(deposit),
382
+ });
383
+ throw new Error("Duplicate deposit detected");
384
+ }
385
+ bundleDepositHashes.push(newBundleDepositHash);
386
+ updateBundleDepositsV3(bundleDepositsV3, deposit);
387
+ }
388
+ else if (deposit.blockNumber < originChainBlockRange[0]) {
389
+ olderDepositHashes.push(newBundleDepositHash);
390
+ }
428
391
  });
429
- v3RelayHashes[relayDataHash].fill = fillToRefund;
430
- }
431
- if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
432
- _canCreateSlowFillLeaf(matchedDeposit)) {
433
- fastFillsReplacingSlowFills.push(relayDataHash);
434
392
  }
393
+ };
394
+ for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
395
+ originChainId = allChainIds_1[_i];
396
+ _loop_1(originChainId);
435
397
  }
436
- }
437
- });
438
- await (0, utils_1.forEachAsync)(destinationClient
439
- .getSlowFillRequestsForOriginChain(originChainId)
440
- .filter((request) => request.blockNumber <= destinationChainBlockRange[1] &&
441
- !(0, utils_1.isZeroValueFillOrSlowFillRequest)(request) &&
442
- !(0, utils_1.invalidOutputToken)(request)), async (slowFillRequest) => {
443
- const relayDataHash = (0, utils_1.getRelayEventKey)(slowFillRequest);
444
- if (v3RelayHashes[relayDataHash]) {
445
- if (!v3RelayHashes[relayDataHash].slowFillRequest) {
446
- v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
447
- const { deposits, fill } = v3RelayHashes[relayDataHash];
448
- if (fill) {
449
- return;
450
- }
398
+ this.logger.debug({
399
+ at: "BundleDataClient#loadData",
400
+ message: "Processed ".concat(bundleDepositHashes.length + olderDepositHashes.length, " deposits in ").concat(performance.now() - start, "ms."),
401
+ });
402
+ start = performance.now();
403
+ validatedBundleV3Fills = [];
404
+ validatedBundleSlowFills = [];
405
+ validatedBundleUnexecutableSlowFills = [];
406
+ fillCounter = 0;
407
+ _loop_2 = function (originChainId) {
408
+ var originClient, _loop_3, _f, allChainIds_4, destinationChainId;
409
+ return tslib_1.__generator(this, function (_g) {
410
+ switch (_g.label) {
411
+ case 0:
412
+ originClient = spokePoolClients[originChainId];
413
+ _loop_3 = function (destinationChainId) {
414
+ var destinationClient, destinationChainBlockRange, originChainBlockRange, fastFillsReplacingSlowFills;
415
+ return tslib_1.__generator(this, function (_h) {
416
+ switch (_h.label) {
417
+ case 0:
418
+ destinationClient = spokePoolClients[destinationChainId];
419
+ destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
420
+ originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
421
+ fastFillsReplacingSlowFills = [];
422
+ return [4, (0, utils_1.forEachAsync)(destinationClient
423
+ .getFillsForOriginChain(originChainId)
424
+ .filter(function (fill) {
425
+ return fill.blockNumber <= destinationChainBlockRange[1] &&
426
+ !(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill) &&
427
+ !(0, utils_1.invalidOutputToken)(fill);
428
+ }), function (fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
429
+ var relayDataHash, deposits, provider, fillToRefund_1, duplicateDeposits, historicalDeposit, matchedDeposit, provider, fillToRefund;
430
+ return tslib_1.__generator(this, function (_a) {
431
+ switch (_a.label) {
432
+ case 0:
433
+ fillCounter++;
434
+ relayDataHash = (0, utils_1.getRelayEventKey)(fill);
435
+ if (!v3RelayHashes[relayDataHash]) return [3, 5];
436
+ if (!!v3RelayHashes[relayDataHash].fill) return [3, 3];
437
+ deposits = v3RelayHashes[relayDataHash].deposits;
438
+ (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
439
+ v3RelayHashes[relayDataHash].fill = fill;
440
+ if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
441
+ provider = void 0;
442
+ if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
443
+ provider = destinationClient.spokePool.provider;
444
+ }
445
+ else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
446
+ provider = destinationClient.svmEventsClient.getRpc();
447
+ }
448
+ return [4, (0, utils_2.verifyFillRepayment)(fill, provider, deposits[0], this.clients.hubPoolClient, bundleEndBlockForMainnet)];
449
+ case 1:
450
+ fillToRefund_1 = _a.sent();
451
+ if (!(0, utils_1.isDefined)(fillToRefund_1)) {
452
+ bundleUnrepayableFillsV3.push(fill);
453
+ }
454
+ else {
455
+ v3RelayHashes[relayDataHash].fill = fillToRefund_1;
456
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: deposits[0].quoteTimestamp }));
457
+ duplicateDeposits = deposits.slice(1);
458
+ duplicateDeposits.forEach(function (duplicateDeposit) {
459
+ if ((0, utils_1.isSlowFill)(fill)) {
460
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, duplicateDeposit);
461
+ }
462
+ else {
463
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund_1), { quoteTimestamp: duplicateDeposit.quoteTimestamp }));
464
+ }
465
+ });
466
+ }
467
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
468
+ _canCreateSlowFillLeaf(deposits[0])) {
469
+ fastFillsReplacingSlowFills.push(relayDataHash);
470
+ }
471
+ _a.label = 2;
472
+ case 2: return [3, 4];
473
+ case 3:
474
+ this.logger.debug({
475
+ at: "BundleDataClient#loadData",
476
+ message: "Duplicate fill detected",
477
+ fill: (0, utils_1.convertFillParamsToBytes32)(fill),
478
+ });
479
+ throw new Error("Duplicate fill detected");
480
+ case 4: return [2];
481
+ case 5:
482
+ v3RelayHashes[relayDataHash] = {
483
+ deposits: undefined,
484
+ fill: fill,
485
+ slowFillRequest: undefined,
486
+ };
487
+ if (!(fill.blockNumber >= destinationChainBlockRange[0])) return [3, 9];
488
+ if (!exports.INFINITE_FILL_DEADLINE.eq(fill.fillDeadline)) {
489
+ bundleInvalidFillsV3.push(fill);
490
+ return [2];
491
+ }
492
+ return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, fill)];
493
+ case 6:
494
+ historicalDeposit = _a.sent();
495
+ if (!!historicalDeposit.found) return [3, 7];
496
+ bundleInvalidFillsV3.push(fill);
497
+ return [3, 9];
498
+ case 7:
499
+ matchedDeposit = historicalDeposit.deposit;
500
+ if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
501
+ bundleInvalidFillsV3.push(fill);
502
+ return [2];
503
+ }
504
+ v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
505
+ provider = void 0;
506
+ if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
507
+ provider = destinationClient.spokePool.provider;
508
+ }
509
+ else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
510
+ provider = destinationClient.svmEventsClient.getRpc();
511
+ }
512
+ return [4, (0, utils_2.verifyFillRepayment)(fill, provider, matchedDeposit, this.clients.hubPoolClient, bundleEndBlockForMainnet)];
513
+ case 8:
514
+ fillToRefund = _a.sent();
515
+ if (!(0, utils_1.isDefined)(fillToRefund)) {
516
+ bundleUnrepayableFillsV3.push(fill);
517
+ }
518
+ else {
519
+ (0, assert_1.default)((0, utils_1.getRelayEventKey)(matchedDeposit) === relayDataHash, "Relay hashes should match.");
520
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: matchedDeposit.quoteTimestamp }));
521
+ v3RelayHashes[relayDataHash].fill = fillToRefund;
522
+ }
523
+ if (fill.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill &&
524
+ _canCreateSlowFillLeaf(matchedDeposit)) {
525
+ fastFillsReplacingSlowFills.push(relayDataHash);
526
+ }
527
+ _a.label = 9;
528
+ case 9: return [2];
529
+ }
530
+ });
531
+ }); })];
532
+ case 1:
533
+ _h.sent();
534
+ return [4, (0, utils_1.forEachAsync)(destinationClient
535
+ .getSlowFillRequestsForOriginChain(originChainId)
536
+ .filter(function (request) {
537
+ return request.blockNumber <= destinationChainBlockRange[1] &&
538
+ !(0, utils_1.isZeroValueFillOrSlowFillRequest)(request) &&
539
+ !(0, utils_1.invalidOutputToken)(request);
540
+ }), function (slowFillRequest) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
541
+ var relayDataHash, _a, deposits, fill, matchedDeposit, historicalDeposit, matchedDeposit;
542
+ return tslib_1.__generator(this, function (_b) {
543
+ switch (_b.label) {
544
+ case 0:
545
+ relayDataHash = (0, utils_1.getRelayEventKey)(slowFillRequest);
546
+ if (v3RelayHashes[relayDataHash]) {
547
+ if (!v3RelayHashes[relayDataHash].slowFillRequest) {
548
+ v3RelayHashes[relayDataHash].slowFillRequest = slowFillRequest;
549
+ _a = v3RelayHashes[relayDataHash], deposits = _a.deposits, fill = _a.fill;
550
+ if (fill) {
551
+ return [2];
552
+ }
553
+ (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
554
+ matchedDeposit = deposits[0];
555
+ if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
556
+ _canCreateSlowFillLeaf(matchedDeposit) &&
557
+ !_depositIsExpired(matchedDeposit)) {
558
+ validatedBundleSlowFills.push(matchedDeposit);
559
+ }
560
+ }
561
+ else {
562
+ this.logger.debug({
563
+ at: "BundleDataClient#loadData",
564
+ message: "Duplicate slow fill request detected",
565
+ slowFillRequest: slowFillRequest,
566
+ });
567
+ throw new Error("Duplicate slow fill request detected.");
568
+ }
569
+ return [2];
570
+ }
571
+ v3RelayHashes[relayDataHash] = {
572
+ deposits: undefined,
573
+ fill: undefined,
574
+ slowFillRequest: slowFillRequest,
575
+ };
576
+ if (!(slowFillRequest.blockNumber >= destinationChainBlockRange[0])) return [3, 2];
577
+ if (!exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline)) {
578
+ bundleInvalidSlowFillRequests.push(slowFillRequest);
579
+ return [2];
580
+ }
581
+ return [4, (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest)];
582
+ case 1:
583
+ historicalDeposit = _b.sent();
584
+ if (!historicalDeposit.found) {
585
+ bundleInvalidSlowFillRequests.push(slowFillRequest);
586
+ return [2];
587
+ }
588
+ matchedDeposit = historicalDeposit.deposit;
589
+ if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
590
+ bundleInvalidSlowFillRequests.push(slowFillRequest);
591
+ return [2];
592
+ }
593
+ (0, assert_1.default)((0, utils_1.getRelayEventKey)(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
594
+ v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
595
+ if (!_canCreateSlowFillLeaf(matchedDeposit) || _depositIsExpired(matchedDeposit)) {
596
+ return [2];
597
+ }
598
+ validatedBundleSlowFills.push(matchedDeposit);
599
+ _b.label = 2;
600
+ case 2: return [2];
601
+ }
602
+ });
603
+ }); })];
604
+ case 2:
605
+ _h.sent();
606
+ return [4, (0, utils_1.mapAsync)(bundleDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
607
+ var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, provider, fillToRefund, fillStatus, prefill, provider, verifiedFill;
608
+ return tslib_1.__generator(this, function (_c) {
609
+ switch (_c.label) {
610
+ case 0:
611
+ _a = decodeBundleDepositHash(depositHash), relayDataHash = _a.relayDataHash, index = _a.index;
612
+ _b = v3RelayHashes[relayDataHash], deposits = _b.deposits, fill = _b.fill, slowFillRequest = _b.slowFillRequest;
613
+ if (!deposits || deposits.length === 0) {
614
+ throw new Error("Deposits should exist in relay hash dictionary.");
615
+ }
616
+ deposit = deposits[index];
617
+ if (!deposit)
618
+ throw new Error("Deposit should exist in relay hash dictionary.");
619
+ if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
620
+ return [2];
621
+ }
622
+ if (!fill) return [3, 3];
623
+ if (!(fill.blockNumber < destinationChainBlockRange[0])) return [3, 2];
624
+ provider = void 0;
625
+ if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
626
+ provider = destinationClient.spokePool.provider;
627
+ }
628
+ else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
629
+ provider = destinationClient.svmEventsClient.getRpc();
630
+ }
631
+ return [4, (0, utils_2.verifyFillRepayment)(fill, provider, deposits[0], this.clients.hubPoolClient, bundleEndBlockForMainnet)];
632
+ case 1:
633
+ fillToRefund = _c.sent();
634
+ if (!(0, utils_1.isDefined)(fillToRefund)) {
635
+ bundleUnrepayableFillsV3.push(fill);
636
+ }
637
+ else if (!(0, utils_1.isSlowFill)(fill)) {
638
+ v3RelayHashes[relayDataHash].fill = fillToRefund;
639
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, fillToRefund), { quoteTimestamp: deposit.quoteTimestamp }));
640
+ }
641
+ else {
642
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
643
+ }
644
+ _c.label = 2;
645
+ case 2: return [2];
646
+ case 3:
647
+ if (slowFillRequest) {
648
+ if (_depositIsExpired(deposit)) {
649
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
650
+ }
651
+ else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
652
+ _canCreateSlowFillLeaf(deposit) &&
653
+ validatedBundleSlowFills.every(function (d) { return (0, utils_1.getRelayEventKey)(d) !== relayDataHash; })) {
654
+ validatedBundleSlowFills.push(deposit);
655
+ }
656
+ return [2];
657
+ }
658
+ return [4, _getFillStatusForDeposit(deposit, destinationChainBlockRange[1])];
659
+ case 4:
660
+ fillStatus = _c.sent();
661
+ if (!(fillStatus === interfaces_1.FillStatus.Filled)) return [3, 7];
662
+ return [4, this.findMatchingFillEvent(deposit, destinationClient)];
663
+ case 5:
664
+ prefill = _c.sent();
665
+ (0, assert_1.default)((0, utils_1.isDefined)(prefill), "findFillEvent# Cannot find prefill: ".concat(relayDataHash));
666
+ (0, assert_1.default)((0, utils_1.getRelayEventKey)(prefill) === relayDataHash, "Relay hashes should match.");
667
+ provider = void 0;
668
+ if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
669
+ provider = destinationClient.spokePool.provider;
670
+ }
671
+ else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
672
+ provider = destinationClient.svmEventsClient.getRpc();
673
+ }
674
+ return [4, (0, utils_2.verifyFillRepayment)(prefill, provider, deposit, this.clients.hubPoolClient, bundleEndBlockForMainnet)];
675
+ case 6:
676
+ verifiedFill = _c.sent();
677
+ if (!(0, utils_1.isDefined)(verifiedFill)) {
678
+ bundleUnrepayableFillsV3.push(prefill);
679
+ }
680
+ else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
681
+ validatedBundleV3Fills.push(tslib_1.__assign(tslib_1.__assign({}, verifiedFill), { quoteTimestamp: deposit.quoteTimestamp }));
682
+ }
683
+ else {
684
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
685
+ }
686
+ return [3, 8];
687
+ case 7:
688
+ if (_depositIsExpired(deposit)) {
689
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
690
+ }
691
+ else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill &&
692
+ validatedBundleSlowFills.every(function (d) { return (0, utils_1.getRelayEventKey)(d) !== relayDataHash; })) {
693
+ if (_canCreateSlowFillLeaf(deposit)) {
694
+ validatedBundleSlowFills.push(deposit);
695
+ }
696
+ }
697
+ _c.label = 8;
698
+ case 8: return [2];
699
+ }
700
+ });
701
+ }); })];
702
+ case 3:
703
+ _h.sent();
704
+ fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
705
+ var _a = v3RelayHashes[relayDataHash], deposits = _a.deposits, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
706
+ (0, assert_1.default)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
707
+ if (!deposits || deposits.length < 1) {
708
+ throw new Error("Deposit should exist in relay hash dictionary.");
709
+ }
710
+ (0, assert_1.default)(_canCreateSlowFillLeaf(deposits[0]), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
711
+ var destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
712
+ var originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
713
+ var matchedDeposit = deposits[0];
714
+ if (matchedDeposit.blockNumber < originBlockRange[0] &&
715
+ (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
716
+ validatedBundleUnexecutableSlowFills.push(deposits[0]);
717
+ }
718
+ });
719
+ return [2];
720
+ }
721
+ });
722
+ };
723
+ _f = 0, allChainIds_4 = allChainIds;
724
+ _g.label = 1;
725
+ case 1:
726
+ if (!(_f < allChainIds_4.length)) return [3, 4];
727
+ destinationChainId = allChainIds_4[_f];
728
+ return [5, _loop_3(destinationChainId)];
729
+ case 2:
730
+ _g.sent();
731
+ _g.label = 3;
732
+ case 3:
733
+ _f++;
734
+ return [3, 1];
735
+ case 4: return [2];
736
+ }
737
+ });
738
+ };
739
+ _b = 0, allChainIds_2 = allChainIds;
740
+ _d.label = 4;
741
+ case 4:
742
+ if (!(_b < allChainIds_2.length)) return [3, 7];
743
+ originChainId = allChainIds_2[_b];
744
+ return [5, _loop_2(originChainId)];
745
+ case 5:
746
+ _d.sent();
747
+ _d.label = 6;
748
+ case 6:
749
+ _b++;
750
+ return [3, 4];
751
+ case 7:
752
+ this.logger.debug({
753
+ at: "BundleDataClient#loadData",
754
+ message: "Processed ".concat(fillCounter, " fills in ").concat(performance.now() - start, "ms."),
755
+ });
756
+ start = performance.now();
757
+ return [4, (0, utils_1.forEachAsync)(olderDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
758
+ var _a, relayDataHash, index, _b, deposits, slowFillRequest, fill, deposit, destinationChainId, destinationBlockRange, fillStatus;
759
+ return tslib_1.__generator(this, function (_c) {
760
+ switch (_c.label) {
761
+ case 0:
762
+ _a = decodeBundleDepositHash(depositHash), relayDataHash = _a.relayDataHash, index = _a.index;
763
+ _b = v3RelayHashes[relayDataHash], deposits = _b.deposits, slowFillRequest = _b.slowFillRequest, fill = _b.fill;
764
+ if (!deposits || deposits.length < 1) {
765
+ throw new Error("Deposit should exist in relay hash dictionary.");
766
+ }
767
+ deposit = deposits[index];
768
+ destinationChainId = deposit.destinationChainId;
769
+ destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
770
+ if (!(!fill &&
771
+ (0, utils_1.isDefined)(deposit) &&
772
+ _depositIsExpired(deposit) &&
773
+ deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
774
+ spokePoolClients[destinationChainId] !== undefined)) return [3, 2];
775
+ return [4, _getFillStatusForDeposit(deposit, destinationBlockRange[1])];
776
+ case 1:
777
+ fillStatus = _c.sent();
778
+ if (fillStatus !== interfaces_1.FillStatus.Filled) {
779
+ updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
780
+ }
781
+ if (fillStatus !== interfaces_1.FillStatus.RequestedSlowFill || !_canCreateSlowFillLeaf(deposit)) {
782
+ return [2];
783
+ }
784
+ if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
785
+ validatedBundleUnexecutableSlowFills.push(deposit);
786
+ }
787
+ _c.label = 2;
788
+ case 2: return [2];
789
+ }
790
+ });
791
+ }); })];
792
+ case 8:
793
+ _d.sent();
794
+ start = performance.now();
795
+ promises = [
796
+ validatedBundleV3Fills.length > 0
797
+ ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map(function (fill) {
798
+ var deposits = v3RelayHashes[(0, utils_1.getRelayEventKey)(fill)].deposits;
799
+ (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
800
+ var matchedDeposit = deposits[0];
801
+ (0, assert_1.default)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
802
+ var paymentChainId = (0, utils_2.getRefundInformationFromFill)(tslib_1.__assign(tslib_1.__assign({}, fill), { fromLiteChain: matchedDeposit.fromLiteChain }), _this.clients.hubPoolClient, bundleEndBlockForMainnet).chainToSendRefundTo;
803
+ return tslib_1.__assign(tslib_1.__assign({}, fill), { paymentChainId: paymentChainId });
804
+ }))
805
+ : [],
806
+ validatedBundleSlowFills.length > 0
807
+ ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleSlowFills.map(function (deposit) {
808
+ return tslib_1.__assign(tslib_1.__assign({}, deposit), { paymentChainId: deposit.destinationChainId });
809
+ }))
810
+ : [],
811
+ validatedBundleUnexecutableSlowFills.length > 0
812
+ ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleUnexecutableSlowFills.map(function (deposit) {
813
+ return tslib_1.__assign(tslib_1.__assign({}, deposit), { paymentChainId: deposit.destinationChainId });
814
+ }))
815
+ : [],
816
+ ];
817
+ return [4, Promise.all(promises)];
818
+ case 9:
819
+ _c = _d.sent(), v3FillLpFees = _c[0], v3SlowFillLpFees = _c[1], v3UnexecutableSlowFillLpFees = _c[2];
820
+ this.logger.debug({
821
+ at: "BundleDataClient#loadData",
822
+ message: "Computed batch async LP fees in ".concat(performance.now() - start, "ms."),
823
+ });
824
+ v3FillLpFees.forEach(function (_a, idx) {
825
+ var realizedLpFeePct = _a.realizedLpFeePct;
826
+ var fill = validatedBundleV3Fills[idx];
827
+ var deposits = v3RelayHashes[(0, utils_1.getRelayEventKey)(fill)].deposits;
451
828
  (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
452
- const matchedDeposit = deposits[0];
453
- if (slowFillRequest.blockNumber >= destinationChainBlockRange[0] &&
454
- _canCreateSlowFillLeaf(matchedDeposit) &&
455
- !_depositIsExpired(matchedDeposit)) {
456
- validatedBundleSlowFills.push(matchedDeposit);
829
+ var associatedDeposit = deposits[0];
830
+ (0, assert_1.default)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
831
+ var _b = (0, utils_2.getRefundInformationFromFill)(tslib_1.__assign(tslib_1.__assign({}, fill), { fromLiteChain: associatedDeposit.fromLiteChain }), _this.clients.hubPoolClient, bundleEndBlockForMainnet), chainToSendRefundTo = _b.chainToSendRefundTo, repaymentToken = _b.repaymentToken;
832
+ updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
833
+ });
834
+ v3SlowFillLpFees.forEach(function (_a, idx) {
835
+ var lpFeePct = _a.realizedLpFeePct;
836
+ var deposit = validatedBundleSlowFills[idx];
837
+ var relayDataHash = (0, utils_1.getRelayEventKey)(deposit);
838
+ if (validatedBundleSlowFills.slice(0, idx).some(function (d) { return (0, utils_1.getRelayEventKey)(d) === relayDataHash; })) {
839
+ return;
457
840
  }
458
- }
459
- else {
841
+ (0, assert_1.default)(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
842
+ updateBundleSlowFills(bundleSlowFillsV3, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
843
+ });
844
+ v3UnexecutableSlowFillLpFees.forEach(function (_a, idx) {
845
+ var lpFeePct = _a.realizedLpFeePct;
846
+ var deposit = validatedBundleUnexecutableSlowFills[idx];
847
+ updateBundleExcessSlowFills(unexecutableSlowFills, tslib_1.__assign(tslib_1.__assign({}, deposit), { lpFeePct: lpFeePct }));
848
+ });
849
+ v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
850
+ if (bundleInvalidFillsV3.length > 0) {
851
+ invalidFillsWithPartialMatchedDeposits_1 = [];
852
+ preFillsForNextBundle_1 = [];
853
+ unknownReasonInvalidFills_1 = [];
854
+ bundleInvalidFillsV3.forEach(function (fill) {
855
+ var originClient = spokePoolClients[fill.originChainId];
856
+ var fullyMatchedDeposit = originClient.getDepositForFill(fill);
857
+ if (!(0, utils_1.isDefined)(fullyMatchedDeposit)) {
858
+ var partiallyMatchedDeposit = originClient.getDeposit(fill.depositId);
859
+ if ((0, utils_1.isDefined)(partiallyMatchedDeposit)) {
860
+ invalidFillsWithPartialMatchedDeposits_1.push(fill);
861
+ }
862
+ else {
863
+ unknownReasonInvalidFills_1.push(fill);
864
+ }
865
+ }
866
+ else {
867
+ var originBundleBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, fill.originChainId, chainIds);
868
+ if (fullyMatchedDeposit.blockNumber <= originBundleBlockRange[1]) {
869
+ throw new Error("Detected invalid fill that matches fully with a deposit in current or prior bundle");
870
+ }
871
+ preFillsForNextBundle_1.push(fill);
872
+ }
873
+ });
460
874
  this.logger.debug({
461
875
  at: "BundleDataClient#loadData",
462
- message: "Duplicate slow fill request detected",
463
- slowFillRequest,
876
+ message: "Finished loading V3 spoke pool data and found some invalid fills in range",
877
+ blockRangesForChains: blockRangesForChains,
878
+ invalidFillsWithPartialMatchedDeposits: invalidFillsWithPartialMatchedDeposits_1.map(function (invalidFill) {
879
+ return (0, utils_1.convertFillParamsToBytes32)(invalidFill);
880
+ }),
881
+ preFillsForNextBundle: preFillsForNextBundle_1.map(function (preFill) { return (0, utils_1.convertFillParamsToBytes32)(preFill); }),
882
+ unknownReasonInvalidFills: unknownReasonInvalidFills_1.map(function (invalidFill) {
883
+ return (0, utils_1.convertFillParamsToBytes32)(invalidFill);
884
+ }),
464
885
  });
465
- throw new Error("Duplicate slow fill request detected.");
466
- }
467
- return;
468
- }
469
- v3RelayHashes[relayDataHash] = {
470
- deposits: undefined,
471
- fill: undefined,
472
- slowFillRequest: slowFillRequest,
473
- };
474
- if (slowFillRequest.blockNumber >= destinationChainBlockRange[0]) {
475
- if (!exports.INFINITE_FILL_DEADLINE.eq(slowFillRequest.fillDeadline)) {
476
- bundleInvalidSlowFillRequests.push(slowFillRequest);
477
- return;
478
- }
479
- const historicalDeposit = await (0, utils_1.queryHistoricalDepositForFill)(originClient, slowFillRequest);
480
- if (!historicalDeposit.found) {
481
- bundleInvalidSlowFillRequests.push(slowFillRequest);
482
- return;
483
- }
484
- const matchedDeposit = historicalDeposit.deposit;
485
- if (matchedDeposit.blockNumber > originChainBlockRange[1]) {
486
- bundleInvalidSlowFillRequests.push(slowFillRequest);
487
- return;
488
- }
489
- (0, assert_1.default)((0, utils_1.getRelayEventKey)(matchedDeposit) === relayDataHash, "Deposit relay hashes should match.");
490
- v3RelayHashes[relayDataHash].deposits = [matchedDeposit];
491
- if (!_canCreateSlowFillLeaf(matchedDeposit) || _depositIsExpired(matchedDeposit)) {
492
- return;
493
- }
494
- validatedBundleSlowFills.push(matchedDeposit);
495
- }
496
- });
497
- await (0, utils_1.mapAsync)(bundleDepositHashes, async (depositHash) => {
498
- const { relayDataHash, index } = decodeBundleDepositHash(depositHash);
499
- const { deposits, fill, slowFillRequest } = v3RelayHashes[relayDataHash];
500
- if (!deposits || deposits.length === 0) {
501
- throw new Error("Deposits should exist in relay hash dictionary.");
502
- }
503
- const deposit = deposits[index];
504
- if (!deposit)
505
- throw new Error("Deposit should exist in relay hash dictionary.");
506
- if (deposit.originChainId !== originChainId || deposit.destinationChainId !== destinationChainId) {
507
- return;
508
- }
509
- if (fill) {
510
- if (fill.blockNumber < destinationChainBlockRange[0]) {
511
- let provider;
512
- if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
513
- provider = destinationClient.spokePool.provider;
514
- }
515
- else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
516
- provider = destinationClient.svmEventsClient.getRpc();
517
- }
518
- const fillToRefund = await (0, utils_2.verifyFillRepayment)(fill, provider, deposits[0], this.clients.hubPoolClient, bundleEndBlockForMainnet);
519
- if (!(0, utils_1.isDefined)(fillToRefund)) {
520
- bundleUnrepayableFillsV3.push(fill);
521
- }
522
- else if (!(0, utils_1.isSlowFill)(fill)) {
523
- v3RelayHashes[relayDataHash].fill = fillToRefund;
524
- validatedBundleV3Fills.push({
525
- ...fillToRefund,
526
- quoteTimestamp: deposit.quoteTimestamp,
527
- });
528
- }
529
- else {
530
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
531
- }
532
- }
533
- return;
534
- }
535
- if (slowFillRequest) {
536
- if (_depositIsExpired(deposit)) {
537
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
538
- }
539
- else if (slowFillRequest.blockNumber < destinationChainBlockRange[0] &&
540
- _canCreateSlowFillLeaf(deposit) &&
541
- validatedBundleSlowFills.every((d) => (0, utils_1.getRelayEventKey)(d) !== relayDataHash)) {
542
- validatedBundleSlowFills.push(deposit);
543
- }
544
- return;
545
- }
546
- const fillStatus = await _getFillStatusForDeposit(deposit, destinationChainBlockRange[1]);
547
- if (fillStatus === interfaces_1.FillStatus.Filled) {
548
- const prefill = await this.findMatchingFillEvent(deposit, destinationClient);
549
- (0, assert_1.default)((0, utils_1.isDefined)(prefill), `findFillEvent# Cannot find prefill: ${relayDataHash}`);
550
- (0, assert_1.default)((0, utils_1.getRelayEventKey)(prefill) === relayDataHash, "Relay hashes should match.");
551
- let provider;
552
- if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(destinationClient)) {
553
- provider = destinationClient.spokePool.provider;
554
- }
555
- else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(destinationClient)) {
556
- provider = destinationClient.svmEventsClient.getRpc();
557
886
  }
558
- const verifiedFill = await (0, utils_2.verifyFillRepayment)(prefill, provider, deposit, this.clients.hubPoolClient, bundleEndBlockForMainnet);
559
- if (!(0, utils_1.isDefined)(verifiedFill)) {
560
- bundleUnrepayableFillsV3.push(prefill);
561
- }
562
- else if (!(0, utils_1.isSlowFill)(verifiedFill)) {
563
- validatedBundleV3Fills.push({
564
- ...verifiedFill,
565
- quoteTimestamp: deposit.quoteTimestamp,
887
+ if (bundleUnrepayableFillsV3.length > 0) {
888
+ this.logger.debug({
889
+ at: "BundleDataClient#loadData",
890
+ message: "Finished loading V3 spoke pool data and found some unrepayable fills in range",
891
+ blockRangesForChains: blockRangesForChains,
892
+ bundleUnrepayableFillsV3: bundleUnrepayableFillsV3,
566
893
  });
567
894
  }
568
- else {
569
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
570
- }
571
- }
572
- else if (_depositIsExpired(deposit)) {
573
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
574
- }
575
- else if (fillStatus === interfaces_1.FillStatus.RequestedSlowFill &&
576
- validatedBundleSlowFills.every((d) => (0, utils_1.getRelayEventKey)(d) !== relayDataHash)) {
577
- if (_canCreateSlowFillLeaf(deposit)) {
578
- validatedBundleSlowFills.push(deposit);
895
+ if (bundleInvalidSlowFillRequests.length > 0) {
896
+ this.logger.debug({
897
+ at: "BundleDataClient#loadData",
898
+ message: "Finished loading V3 spoke pool data and found some invalid slow fill requests in range",
899
+ blockRangesForChains: blockRangesForChains,
900
+ bundleInvalidSlowFillRequests: bundleInvalidSlowFillRequests,
901
+ });
579
902
  }
580
- }
581
- });
582
- fastFillsReplacingSlowFills.forEach((relayDataHash) => {
583
- const { deposits, slowFillRequest, fill } = v3RelayHashes[relayDataHash];
584
- (0, assert_1.default)(fill?.relayExecutionInfo.fillType === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
585
- if (!deposits || deposits.length < 1) {
586
- throw new Error("Deposit should exist in relay hash dictionary.");
587
- }
588
- (0, assert_1.default)(_canCreateSlowFillLeaf(deposits[0]), "fastFillsReplacingSlowFills should contain only deposits that can be slow filled");
589
- const destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
590
- const originBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
591
- const matchedDeposit = deposits[0];
592
- if (matchedDeposit.blockNumber < originBlockRange[0] &&
593
- (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0])) {
594
- validatedBundleUnexecutableSlowFills.push(deposits[0]);
595
- }
596
- });
597
- }
598
- }
599
- this.logger.debug({
600
- at: "BundleDataClient#loadData",
601
- message: `Processed ${fillCounter} fills in ${performance.now() - start}ms.`,
602
- });
603
- start = performance.now();
604
- await (0, utils_1.forEachAsync)(olderDepositHashes, async (depositHash) => {
605
- const { relayDataHash, index } = decodeBundleDepositHash(depositHash);
606
- const { deposits, slowFillRequest, fill } = v3RelayHashes[relayDataHash];
607
- if (!deposits || deposits.length < 1) {
608
- throw new Error("Deposit should exist in relay hash dictionary.");
609
- }
610
- const deposit = deposits[index];
611
- const { destinationChainId } = deposit;
612
- const destinationBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
613
- if (!fill &&
614
- (0, utils_1.isDefined)(deposit) &&
615
- _depositIsExpired(deposit) &&
616
- deposit.fillDeadline >= bundleBlockTimestamps[destinationChainId][0] &&
617
- spokePoolClients[destinationChainId] !== undefined) {
618
- const fillStatus = await _getFillStatusForDeposit(deposit, destinationBlockRange[1]);
619
- if (fillStatus !== interfaces_1.FillStatus.Filled) {
620
- updateExpiredDepositsV3(expiredDepositsToRefundV3, deposit);
903
+ this.logger.debug({
904
+ at: "BundleDataClient#loadDataFromScratch",
905
+ message: "Computed bundle data in ".concat(Math.round(performance.now() - start) / 1000, "s."),
906
+ blockRangesForChains: JSON.stringify(blockRangesForChains),
907
+ v3SpokeEventsReadable: v3SpokeEventsReadable,
908
+ });
909
+ return [2, {
910
+ bundleDepositsV3: bundleDepositsV3,
911
+ expiredDepositsToRefundV3: expiredDepositsToRefundV3,
912
+ bundleFillsV3: bundleFillsV3,
913
+ unexecutableSlowFills: unexecutableSlowFills,
914
+ bundleSlowFillsV3: bundleSlowFillsV3,
915
+ }];
621
916
  }
622
- if (fillStatus !== interfaces_1.FillStatus.RequestedSlowFill || !_canCreateSlowFillLeaf(deposit)) {
623
- return;
624
- }
625
- if (!slowFillRequest || slowFillRequest.blockNumber < destinationBlockRange[0]) {
626
- validatedBundleUnexecutableSlowFills.push(deposit);
627
- }
628
- }
629
- });
630
- start = performance.now();
631
- const promises = [
632
- validatedBundleV3Fills.length > 0
633
- ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleV3Fills.map((fill) => {
634
- const { deposits } = v3RelayHashes[(0, utils_1.getRelayEventKey)(fill)];
635
- (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
636
- const matchedDeposit = deposits[0];
637
- (0, assert_1.default)((0, utils_1.isDefined)(matchedDeposit), "Deposit should exist in relay hash dictionary.");
638
- const { chainToSendRefundTo: paymentChainId } = (0, utils_2.getRefundInformationFromFill)({
639
- ...fill,
640
- fromLiteChain: matchedDeposit.fromLiteChain,
641
- }, this.clients.hubPoolClient, bundleEndBlockForMainnet);
642
- return {
643
- ...fill,
644
- paymentChainId,
645
- };
646
- }))
647
- : [],
648
- validatedBundleSlowFills.length > 0
649
- ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleSlowFills.map((deposit) => {
650
- return {
651
- ...deposit,
652
- paymentChainId: deposit.destinationChainId,
653
- };
654
- }))
655
- : [],
656
- validatedBundleUnexecutableSlowFills.length > 0
657
- ? this.clients.hubPoolClient.batchComputeRealizedLpFeePct(validatedBundleUnexecutableSlowFills.map((deposit) => {
658
- return {
659
- ...deposit,
660
- paymentChainId: deposit.destinationChainId,
661
- };
662
- }))
663
- : [],
664
- ];
665
- const [v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees] = await Promise.all(promises);
666
- this.logger.debug({
667
- at: "BundleDataClient#loadData",
668
- message: `Computed batch async LP fees in ${performance.now() - start}ms.`,
669
- });
670
- v3FillLpFees.forEach(({ realizedLpFeePct }, idx) => {
671
- const fill = validatedBundleV3Fills[idx];
672
- const { deposits } = v3RelayHashes[(0, utils_1.getRelayEventKey)(fill)];
673
- (0, assert_1.default)((0, utils_1.isDefined)(deposits) && deposits.length > 0, "Deposit should exist in relay hash dictionary.");
674
- const associatedDeposit = deposits[0];
675
- (0, assert_1.default)((0, utils_1.isDefined)(associatedDeposit), "Deposit should exist in relay hash dictionary.");
676
- const { chainToSendRefundTo, repaymentToken } = (0, utils_2.getRefundInformationFromFill)({
677
- ...fill,
678
- fromLiteChain: associatedDeposit.fromLiteChain,
679
- }, this.clients.hubPoolClient, bundleEndBlockForMainnet);
680
- updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
681
- });
682
- v3SlowFillLpFees.forEach(({ realizedLpFeePct: lpFeePct }, idx) => {
683
- const deposit = validatedBundleSlowFills[idx];
684
- const relayDataHash = (0, utils_1.getRelayEventKey)(deposit);
685
- if (validatedBundleSlowFills.slice(0, idx).some((d) => (0, utils_1.getRelayEventKey)(d) === relayDataHash)) {
686
- return;
687
- }
688
- (0, assert_1.default)(!_depositIsExpired(deposit), "Cannot create slow fill leaf for expired deposit.");
689
- updateBundleSlowFills(bundleSlowFillsV3, { ...deposit, lpFeePct });
690
- });
691
- v3UnexecutableSlowFillLpFees.forEach(({ realizedLpFeePct: lpFeePct }, idx) => {
692
- const deposit = validatedBundleUnexecutableSlowFills[idx];
693
- updateBundleExcessSlowFills(unexecutableSlowFills, { ...deposit, lpFeePct });
917
+ });
694
918
  });
695
- const v3SpokeEventsReadable = (0, utils_2.prettyPrintV3SpokePoolEvents)(bundleDepositsV3, bundleFillsV3, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills);
696
- if (bundleInvalidFillsV3.length > 0) {
697
- const invalidFillsWithPartialMatchedDeposits = [];
698
- const preFillsForNextBundle = [];
699
- const unknownReasonInvalidFills = [];
700
- bundleInvalidFillsV3.forEach((fill) => {
701
- const originClient = spokePoolClients[fill.originChainId];
702
- const fullyMatchedDeposit = originClient.getDepositForFill(fill);
703
- if (!(0, utils_1.isDefined)(fullyMatchedDeposit)) {
704
- const partiallyMatchedDeposit = originClient.getDeposit(fill.depositId);
705
- if ((0, utils_1.isDefined)(partiallyMatchedDeposit)) {
706
- invalidFillsWithPartialMatchedDeposits.push(fill);
707
- }
708
- else {
709
- unknownReasonInvalidFills.push(fill);
710
- }
711
- }
712
- else {
713
- const originBundleBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, fill.originChainId, chainIds);
714
- if (fullyMatchedDeposit.blockNumber <= originBundleBlockRange[1]) {
715
- throw new Error("Detected invalid fill that matches fully with a deposit in current or prior bundle");
716
- }
717
- preFillsForNextBundle.push(fill);
919
+ };
920
+ BundleDataClient.prototype.findMatchingFillEvent = function (deposit, spokePoolClient) {
921
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
922
+ return tslib_1.__generator(this, function (_a) {
923
+ switch (_a.label) {
924
+ case 0:
925
+ if (!(0, SpokePoolClient_1.isSVMSpokePoolClient)(spokePoolClient)) return [3, 2];
926
+ return [4, (0, svm_1.findFillEvent)(deposit, spokePoolClient.chainId, spokePoolClient.svmEventsClient, spokePoolClient.deploymentBlock, spokePoolClient.latestHeightSearched, spokePoolClient.logger)];
927
+ case 1: return [2, _a.sent()];
928
+ case 2:
929
+ if (!(0, SpokePoolClient_1.isEVMSpokePoolClient)(spokePoolClient)) return [3, 4];
930
+ return [4, (0, evm_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestHeightSearched)];
931
+ case 3: return [2, _a.sent()];
932
+ case 4: throw new Error("Unsupported spoke pool client type");
718
933
  }
719
934
  });
720
- this.logger.debug({
721
- at: "BundleDataClient#loadData",
722
- message: "Finished loading V3 spoke pool data and found some invalid fills in range",
723
- blockRangesForChains,
724
- invalidFillsWithPartialMatchedDeposits: invalidFillsWithPartialMatchedDeposits.map((invalidFill) => (0, utils_1.convertFillParamsToBytes32)(invalidFill)),
725
- preFillsForNextBundle: preFillsForNextBundle.map((preFill) => (0, utils_1.convertFillParamsToBytes32)(preFill)),
726
- unknownReasonInvalidFills: unknownReasonInvalidFills.map((invalidFill) => (0, utils_1.convertFillParamsToBytes32)(invalidFill)),
727
- });
728
- }
729
- if (bundleUnrepayableFillsV3.length > 0) {
730
- this.logger.debug({
731
- at: "BundleDataClient#loadData",
732
- message: "Finished loading V3 spoke pool data and found some unrepayable fills in range",
733
- blockRangesForChains,
734
- bundleUnrepayableFillsV3,
735
- });
736
- }
737
- if (bundleInvalidSlowFillRequests.length > 0) {
738
- this.logger.debug({
739
- at: "BundleDataClient#loadData",
740
- message: "Finished loading V3 spoke pool data and found some invalid slow fill requests in range",
741
- blockRangesForChains,
742
- bundleInvalidSlowFillRequests,
935
+ });
936
+ };
937
+ BundleDataClient.prototype.getBundleBlockTimestamps = function (chainIds, blockRangesForChains, spokePoolClients) {
938
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
939
+ var _a, _b;
940
+ var _this = this;
941
+ return tslib_1.__generator(this, function (_c) {
942
+ switch (_c.label) {
943
+ case 0:
944
+ _b = (_a = Object).fromEntries;
945
+ return [4, (0, utils_1.mapAsync)(chainIds, function (chainId, index) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
946
+ var blockRangeForChain, _startBlockForChain, _endBlockForChain, spokePoolClient, startBlockForChain, endBlockForChain, _a, startTime, _endTime, _b, endBlockDelta, endTime;
947
+ return tslib_1.__generator(this, function (_c) {
948
+ switch (_c.label) {
949
+ case 0:
950
+ blockRangeForChain = blockRangesForChains[index];
951
+ if (!(0, utils_1.isDefined)(blockRangeForChain) ||
952
+ (0, utils_2.isChainDisabledAtBlock)(chainId, blockRangesForChains[0][0], this.clients.configStoreClient)) {
953
+ return [2];
954
+ }
955
+ _startBlockForChain = blockRangeForChain[0], _endBlockForChain = blockRangeForChain[1];
956
+ spokePoolClient = spokePoolClients[chainId];
957
+ if (!(0, utils_1.isDefined)(spokePoolClient)) {
958
+ return [2];
959
+ }
960
+ startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestHeightSearched);
961
+ endBlockForChain = Math.min(_endBlockForChain + 1, spokePoolClient.latestHeightSearched);
962
+ return [4, spokePoolClient.getTimestampForBlock(startBlockForChain)];
963
+ case 1:
964
+ _b = [
965
+ _c.sent()
966
+ ];
967
+ return [4, spokePoolClient.getTimestampForBlock(endBlockForChain)];
968
+ case 2:
969
+ _a = _b.concat([
970
+ _c.sent()
971
+ ]), startTime = _a[0], _endTime = _a[1];
972
+ endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
973
+ endTime = Math.max(0, _endTime - endBlockDelta);
974
+ (0, assert_1.default)(endTime >= startTime, "End time for block ".concat(endBlockForChain, " should be greater than start time for block ").concat(startBlockForChain, ": ").concat(endTime, " >= ").concat(startTime, "."));
975
+ (0, assert_1.default)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
976
+ return [2, [chainId, [startTime, endTime]]];
977
+ }
978
+ });
979
+ }); })];
980
+ case 1: return [2, _b.apply(_a, [(_c.sent()).filter(utils_1.isDefined)])];
981
+ }
743
982
  });
744
- }
745
- this.logger.debug({
746
- at: "BundleDataClient#loadDataFromScratch",
747
- message: `Computed bundle data in ${Math.round(performance.now() - start) / 1000}s.`,
748
- blockRangesForChains: JSON.stringify(blockRangesForChains),
749
- v3SpokeEventsReadable,
750
983
  });
751
- return {
752
- bundleDepositsV3,
753
- expiredDepositsToRefundV3,
754
- bundleFillsV3,
755
- unexecutableSlowFills,
756
- bundleSlowFillsV3,
757
- };
758
- }
759
- async findMatchingFillEvent(deposit, spokePoolClient) {
760
- if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(spokePoolClient)) {
761
- return await (0, svm_1.findFillEvent)(deposit, spokePoolClient.chainId, spokePoolClient.svmEventsClient, spokePoolClient.deploymentBlock, spokePoolClient.latestHeightSearched, spokePoolClient.logger);
762
- }
763
- else if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(spokePoolClient)) {
764
- return await (0, evm_1.findFillEvent)(spokePoolClient.spokePool, deposit, spokePoolClient.deploymentBlock, spokePoolClient.latestHeightSearched);
765
- }
766
- else {
767
- throw new Error("Unsupported spoke pool client type");
768
- }
769
- }
770
- async getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients) {
771
- return Object.fromEntries((await (0, utils_1.mapAsync)(chainIds, async (chainId, index) => {
772
- const blockRangeForChain = blockRangesForChains[index];
773
- if (!(0, utils_1.isDefined)(blockRangeForChain) ||
774
- (0, utils_2.isChainDisabledAtBlock)(chainId, blockRangesForChains[0][0], this.clients.configStoreClient)) {
775
- return;
776
- }
777
- const [_startBlockForChain, _endBlockForChain] = blockRangeForChain;
778
- const spokePoolClient = spokePoolClients[chainId];
779
- if (!(0, utils_1.isDefined)(spokePoolClient)) {
780
- return;
781
- }
782
- const startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestHeightSearched);
783
- const endBlockForChain = Math.min(_endBlockForChain + 1, spokePoolClient.latestHeightSearched);
784
- const [startTime, _endTime] = [
785
- await spokePoolClient.getTimestampForBlock(startBlockForChain),
786
- await spokePoolClient.getTimestampForBlock(endBlockForChain),
787
- ];
788
- const endBlockDelta = endBlockForChain > startBlockForChain ? 1 : 0;
789
- const endTime = Math.max(0, _endTime - endBlockDelta);
790
- (0, assert_1.default)(endTime >= startTime, `End time for block ${endBlockForChain} should be greater than start time for block ${startBlockForChain}: ${endTime} >= ${startTime}.`);
791
- (0, assert_1.default)(startBlockForChain === 0 || startTime > 0, "Start timestamp must be greater than 0 if the start block is greater than 0.");
792
- return [chainId, [startTime, endTime]];
793
- })).filter(utils_1.isDefined));
794
- }
795
- }
984
+ };
985
+ return BundleDataClient;
986
+ }());
796
987
  exports.BundleDataClient = BundleDataClient;
797
988
  //# sourceMappingURL=BundleDataClient.js.map