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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/dist/cjs/addressAggregator/adapters/abstract.js +50 -64
  2. package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
  3. package/dist/cjs/addressAggregator/adapters/bybit.js +16 -29
  4. package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
  5. package/dist/cjs/addressAggregator/adapters/env.js +11 -15
  6. package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
  7. package/dist/cjs/addressAggregator/adapters/file.js +32 -45
  8. package/dist/cjs/addressAggregator/adapters/file.js.map +1 -1
  9. package/dist/cjs/addressAggregator/adapters/index.js +1 -1
  10. package/dist/cjs/addressAggregator/adapters/risklabs.js +22 -36
  11. package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
  12. package/dist/cjs/addressAggregator/index.js +57 -87
  13. package/dist/cjs/addressAggregator/index.js.map +1 -1
  14. package/dist/cjs/apiClient/abstractClient.js +9 -8
  15. package/dist/cjs/apiClient/abstractClient.js.map +1 -1
  16. package/dist/cjs/apiClient/index.js +1 -1
  17. package/dist/cjs/apiClient/mockedClient.js +23 -29
  18. package/dist/cjs/apiClient/mockedClient.js.map +1 -1
  19. package/dist/cjs/apiClient/productionClient.js +65 -103
  20. package/dist/cjs/apiClient/productionClient.js.map +1 -1
  21. package/dist/cjs/arch/evm/BlockUtils.js +122 -208
  22. package/dist/cjs/arch/evm/BlockUtils.js.map +1 -1
  23. package/dist/cjs/arch/evm/MessageUtils.js +1 -1
  24. package/dist/cjs/arch/evm/MessageUtils.js.map +1 -1
  25. package/dist/cjs/arch/evm/SpokeUtils.js +134 -288
  26. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  27. package/dist/cjs/arch/evm/index.js +1 -1
  28. package/dist/cjs/arch/evm/utils/index.js +1 -1
  29. package/dist/cjs/arch/evm/utils/wait.js +38 -49
  30. package/dist/cjs/arch/evm/utils/wait.js.map +1 -1
  31. package/dist/cjs/arch/index.js +1 -1
  32. package/dist/cjs/arch/svm/BlockUtils.js +102 -158
  33. package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
  34. package/dist/cjs/arch/svm/MessageUtils.js +2 -2
  35. package/dist/cjs/arch/svm/MessageUtils.js.map +1 -1
  36. package/dist/cjs/arch/svm/SpokeUtils.js +708 -1147
  37. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  38. package/dist/cjs/arch/svm/encoders.js +1 -1
  39. package/dist/cjs/arch/svm/encoders.js.map +1 -1
  40. package/dist/cjs/arch/svm/eventsClient.js +174 -236
  41. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  42. package/dist/cjs/arch/svm/index.js +1 -1
  43. package/dist/cjs/arch/svm/provider.js +3 -3
  44. package/dist/cjs/arch/svm/provider.js.map +1 -1
  45. package/dist/cjs/arch/svm/utils.js +166 -355
  46. package/dist/cjs/arch/svm/utils.js.map +1 -1
  47. package/dist/cjs/caching/Arweave/ArweaveClient.js +168 -246
  48. package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
  49. package/dist/cjs/caching/Arweave/index.js +1 -1
  50. package/dist/cjs/caching/IPFS/PinataIPFSClient.js +40 -49
  51. package/dist/cjs/caching/IPFS/PinataIPFSClient.js.map +1 -1
  52. package/dist/cjs/caching/IPFS/index.js +1 -1
  53. package/dist/cjs/caching/Memory/MemoryCacheClient.js +13 -18
  54. package/dist/cjs/caching/Memory/MemoryCacheClient.js.map +1 -1
  55. package/dist/cjs/caching/Memory/index.js +1 -1
  56. package/dist/cjs/caching/index.js +1 -1
  57. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +302 -381
  58. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  59. package/dist/cjs/clients/AcrossConfigStoreClient/index.js +1 -1
  60. package/dist/cjs/clients/BaseAbstractClient.js +58 -83
  61. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  62. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +709 -900
  63. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  64. package/dist/cjs/clients/BundleDataClient/index.js +1 -1
  65. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +95 -128
  66. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  67. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +48 -53
  68. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  69. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +10 -8
  70. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  71. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +67 -90
  72. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  73. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +46 -24
  74. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  75. package/dist/cjs/clients/BundleDataClient/utils/index.js +1 -1
  76. package/dist/cjs/clients/HubPoolClient.js +526 -708
  77. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  78. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -179
  79. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  80. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +124 -183
  81. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  82. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +357 -389
  83. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  84. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +9 -8
  85. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  86. package/dist/cjs/clients/SpokePoolClient/index.js +3 -3
  87. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  88. package/dist/cjs/clients/index.js +1 -1
  89. package/dist/cjs/clients/mocks/MockConfigStoreClient.js +58 -67
  90. package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
  91. package/dist/cjs/clients/mocks/MockEvents.js +47 -52
  92. package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
  93. package/dist/cjs/clients/mocks/MockHubPoolClient.js +142 -185
  94. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  95. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +208 -192
  96. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  97. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +140 -143
  98. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  99. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +57 -73
  100. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  101. package/dist/cjs/clients/mocks/index.js +1 -1
  102. package/dist/cjs/coingecko/Coingecko.js +285 -437
  103. package/dist/cjs/coingecko/Coingecko.js.map +1 -1
  104. package/dist/cjs/coingecko/index.js +1 -1
  105. package/dist/cjs/constants.js +23 -30
  106. package/dist/cjs/constants.js.map +1 -1
  107. package/dist/cjs/contracts/acrossConfigStore.js +27 -48
  108. package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
  109. package/dist/cjs/contracts/hubPool.js +36 -20
  110. package/dist/cjs/contracts/hubPool.js.map +1 -1
  111. package/dist/cjs/contracts/index.js +1 -1
  112. package/dist/cjs/contracts/utils.js +6 -8
  113. package/dist/cjs/contracts/utils.js.map +1 -1
  114. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +7 -16
  115. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  116. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +26 -45
  117. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  118. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +16 -28
  119. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  120. package/dist/cjs/gasPriceOracle/adapters/polygon.js +73 -112
  121. package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
  122. package/dist/cjs/gasPriceOracle/adapters/solana.js +20 -33
  123. package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
  124. package/dist/cjs/gasPriceOracle/oracle.js +77 -104
  125. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  126. package/dist/cjs/gasPriceOracle/types.js +3 -3
  127. package/dist/cjs/gasPriceOracle/types.js.map +1 -1
  128. package/dist/cjs/gasPriceOracle/util.js +8 -8
  129. package/dist/cjs/gasPriceOracle/util.js.map +1 -1
  130. package/dist/cjs/index.js +1 -1
  131. package/dist/cjs/interfaces/index.js +1 -1
  132. package/dist/cjs/lpFeeCalculator/index.js +1 -1
  133. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js +33 -35
  134. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  135. package/dist/cjs/lpFeeCalculator/rateModel.js +7 -9
  136. package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
  137. package/dist/cjs/merkleDistributor/MerkleDistributor.js +20 -18
  138. package/dist/cjs/merkleDistributor/MerkleDistributor.js.map +1 -1
  139. package/dist/cjs/merkleDistributor/index.js +1 -1
  140. package/dist/cjs/merkleDistributor/model/index.js +1 -1
  141. package/dist/cjs/pool/TransactionManager.js +45 -100
  142. package/dist/cjs/pool/TransactionManager.js.map +1 -1
  143. package/dist/cjs/pool/index.js +1 -1
  144. package/dist/cjs/pool/poolClient.js +464 -731
  145. package/dist/cjs/pool/poolClient.js.map +1 -1
  146. package/dist/cjs/pool/uma/across/index.js +1 -1
  147. package/dist/cjs/pool/uma/across/transactionManager.js +45 -100
  148. package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
  149. package/dist/cjs/pool/uma/clients/erc20/client.js +18 -16
  150. package/dist/cjs/pool/uma/clients/erc20/client.js.map +1 -1
  151. package/dist/cjs/pool/uma/clients/erc20/index.js +1 -1
  152. package/dist/cjs/pool/uma/clients/index.js +1 -1
  153. package/dist/cjs/pool/uma/index.js +1 -1
  154. package/dist/cjs/pool/uma/oracle/index.js +1 -1
  155. package/dist/cjs/pool/uma/oracle/utils.js +4 -5
  156. package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
  157. package/dist/cjs/pool/uma/utils.js +11 -30
  158. package/dist/cjs/pool/uma/utils.js.map +1 -1
  159. package/dist/cjs/priceClient/adapters/acrossApi.js +22 -39
  160. package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
  161. package/dist/cjs/priceClient/adapters/baseAdapter.js +49 -73
  162. package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
  163. package/dist/cjs/priceClient/adapters/coingecko.js +34 -61
  164. package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
  165. package/dist/cjs/priceClient/adapters/default.js +16 -31
  166. package/dist/cjs/priceClient/adapters/default.js.map +1 -1
  167. package/dist/cjs/priceClient/adapters/defiLlama.js +40 -74
  168. package/dist/cjs/priceClient/adapters/defiLlama.js.map +1 -1
  169. package/dist/cjs/priceClient/adapters/index.js +1 -1
  170. package/dist/cjs/priceClient/index.js +1 -1
  171. package/dist/cjs/priceClient/priceClient.js +110 -159
  172. package/dist/cjs/priceClient/priceClient.js.map +1 -1
  173. package/dist/cjs/providers/alchemy.js +17 -19
  174. package/dist/cjs/providers/alchemy.js.map +1 -1
  175. package/dist/cjs/providers/cachedProvider.js +88 -129
  176. package/dist/cjs/providers/cachedProvider.js.map +1 -1
  177. package/dist/cjs/providers/drpc.js +9 -11
  178. package/dist/cjs/providers/drpc.js.map +1 -1
  179. package/dist/cjs/providers/index.js +1 -1
  180. package/dist/cjs/providers/infura.js +10 -12
  181. package/dist/cjs/providers/infura.js.map +1 -1
  182. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +7 -15
  183. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  184. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +6 -14
  185. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  186. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +7 -15
  187. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  188. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +42 -66
  189. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  190. package/dist/cjs/providers/mocks/index.js +1 -1
  191. package/dist/cjs/providers/mocks/mockEthersProvider.js +29 -31
  192. package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
  193. package/dist/cjs/providers/quicknode.js +19 -21
  194. package/dist/cjs/providers/quicknode.js.map +1 -1
  195. package/dist/cjs/providers/rateLimitedProvider.js +64 -79
  196. package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
  197. package/dist/cjs/providers/retryProvider.js +163 -246
  198. package/dist/cjs/providers/retryProvider.js.map +1 -1
  199. package/dist/cjs/providers/solana/baseRpcFactories.js +14 -18
  200. package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
  201. package/dist/cjs/providers/solana/cachedRpcFactory.js +70 -112
  202. package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
  203. package/dist/cjs/providers/solana/defaultRpcFactory.js +8 -15
  204. package/dist/cjs/providers/solana/defaultRpcFactory.js.map +1 -1
  205. package/dist/cjs/providers/solana/index.js +1 -1
  206. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js +135 -191
  207. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  208. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +67 -90
  209. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  210. package/dist/cjs/providers/solana/retryRpcFactory.js +52 -79
  211. package/dist/cjs/providers/solana/retryRpcFactory.js.map +1 -1
  212. package/dist/cjs/providers/solana/utils.js +2 -2
  213. package/dist/cjs/providers/solana/utils.js.map +1 -1
  214. package/dist/cjs/providers/speedProvider.js +31 -53
  215. package/dist/cjs/providers/speedProvider.js.map +1 -1
  216. package/dist/cjs/providers/types.js +1 -1
  217. package/dist/cjs/providers/types.js.map +1 -1
  218. package/dist/cjs/providers/utils.js +26 -28
  219. package/dist/cjs/providers/utils.js.map +1 -1
  220. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +108 -162
  221. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  222. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +14 -26
  223. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  224. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +20 -29
  225. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  226. package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -1
  227. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +88 -137
  228. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  229. package/dist/cjs/relayFeeCalculator/index.js +1 -1
  230. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +199 -297
  231. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  232. package/dist/cjs/typeguards/error.js +5 -7
  233. package/dist/cjs/typeguards/error.js.map +1 -1
  234. package/dist/cjs/typeguards/index.js +1 -1
  235. package/dist/cjs/utils/AddressUtils.js +117 -144
  236. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  237. package/dist/cjs/utils/ArrayUtils.js +21 -78
  238. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  239. package/dist/cjs/utils/BigNumberUtils.js +9 -10
  240. package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
  241. package/dist/cjs/utils/BlockExplorerUtils.js +26 -30
  242. package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
  243. package/dist/cjs/utils/BlockFinder.js +2 -5
  244. package/dist/cjs/utils/BlockFinder.js.map +1 -1
  245. package/dist/cjs/utils/BlockUtils.js +24 -41
  246. package/dist/cjs/utils/BlockUtils.js.map +1 -1
  247. package/dist/cjs/utils/BundleUtils.js +21 -24
  248. package/dist/cjs/utils/BundleUtils.js.map +1 -1
  249. package/dist/cjs/utils/CCTPUtils.js +62 -126
  250. package/dist/cjs/utils/CCTPUtils.js.map +1 -1
  251. package/dist/cjs/utils/CachingUtils.js +20 -42
  252. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  253. package/dist/cjs/utils/ContractUtils.js +5 -5
  254. package/dist/cjs/utils/ContractUtils.js.map +1 -1
  255. package/dist/cjs/utils/DepositUtils.js +122 -99
  256. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  257. package/dist/cjs/utils/EventUtils.js +49 -70
  258. package/dist/cjs/utils/EventUtils.js.map +1 -1
  259. package/dist/cjs/utils/FormattingUtils.js +26 -32
  260. package/dist/cjs/utils/FormattingUtils.js.map +1 -1
  261. package/dist/cjs/utils/HyperLiquidUtils.js +10 -23
  262. package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
  263. package/dist/cjs/utils/IPFSUtils.js +16 -34
  264. package/dist/cjs/utils/IPFSUtils.js.map +1 -1
  265. package/dist/cjs/utils/JSONUtils.js +6 -6
  266. package/dist/cjs/utils/JSONUtils.js.map +1 -1
  267. package/dist/cjs/utils/LogUtils.js +10 -12
  268. package/dist/cjs/utils/LogUtils.js.map +1 -1
  269. package/dist/cjs/utils/Multicall.js +56 -115
  270. package/dist/cjs/utils/Multicall.js.map +1 -1
  271. package/dist/cjs/utils/NetworkUtils.js +12 -28
  272. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  273. package/dist/cjs/utils/NumberUtils.js +1 -3
  274. package/dist/cjs/utils/NumberUtils.js.map +1 -1
  275. package/dist/cjs/utils/ObjectUtils.js +27 -41
  276. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  277. package/dist/cjs/utils/Profiler.js +80 -83
  278. package/dist/cjs/utils/Profiler.js.map +1 -1
  279. package/dist/cjs/utils/ReviverUtils.js +5 -9
  280. package/dist/cjs/utils/ReviverUtils.js.map +1 -1
  281. package/dist/cjs/utils/SpokeUtils.js +84 -84
  282. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  283. package/dist/cjs/utils/TokenUtils.js +41 -64
  284. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  285. package/dist/cjs/utils/TypeGuards.js +1 -1
  286. package/dist/cjs/utils/TypeGuards.js.map +1 -1
  287. package/dist/cjs/utils/ValidatorUtils.js +7 -7
  288. package/dist/cjs/utils/ValidatorUtils.js.map +1 -1
  289. package/dist/cjs/utils/abi/contracts/index.js +1 -1
  290. package/dist/cjs/utils/abi/index.js +12 -22
  291. package/dist/cjs/utils/abi/index.js.map +1 -1
  292. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +9 -12
  293. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  294. package/dist/cjs/utils/abi/typechain/index.js +1 -1
  295. package/dist/cjs/utils/common.js +40 -53
  296. package/dist/cjs/utils/common.js.map +1 -1
  297. package/dist/cjs/utils/index.js +1 -1
  298. package/dist/esm/addressAggregator/adapters/abstract.js +48 -64
  299. package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
  300. package/dist/esm/addressAggregator/adapters/bybit.js +15 -29
  301. package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
  302. package/dist/esm/addressAggregator/adapters/env.js +9 -14
  303. package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
  304. package/dist/esm/addressAggregator/adapters/file.js +29 -43
  305. package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
  306. package/dist/esm/addressAggregator/adapters/risklabs.js +20 -35
  307. package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
  308. package/dist/esm/addressAggregator/index.js +52 -83
  309. package/dist/esm/addressAggregator/index.js.map +1 -1
  310. package/dist/esm/addressAggregator/types.js +1 -1
  311. package/dist/esm/addressAggregator/types.js.map +1 -1
  312. package/dist/esm/apiClient/abstractClient.js +15 -9
  313. package/dist/esm/apiClient/abstractClient.js.map +1 -1
  314. package/dist/esm/apiClient/mockedClient.js +21 -26
  315. package/dist/esm/apiClient/mockedClient.js.map +1 -1
  316. package/dist/esm/apiClient/productionClient.js +61 -101
  317. package/dist/esm/apiClient/productionClient.js.map +1 -1
  318. package/dist/esm/arch/evm/BlockUtils.js +139 -217
  319. package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
  320. package/dist/esm/arch/evm/SpokeUtils.js +146 -289
  321. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  322. package/dist/esm/arch/evm/utils/wait.js +34 -46
  323. package/dist/esm/arch/evm/utils/wait.js.map +1 -1
  324. package/dist/esm/arch/svm/BlockUtils.js +118 -166
  325. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  326. package/dist/esm/arch/svm/SpokeUtils.js +738 -1150
  327. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  328. package/dist/esm/arch/svm/constants.js +1 -1
  329. package/dist/esm/arch/svm/constants.js.map +1 -1
  330. package/dist/esm/arch/svm/eventsClient.js +172 -232
  331. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  332. package/dist/esm/arch/svm/provider.js +1 -1
  333. package/dist/esm/arch/svm/provider.js.map +1 -1
  334. package/dist/esm/arch/svm/utils.js +155 -345
  335. package/dist/esm/arch/svm/utils.js.map +1 -1
  336. package/dist/esm/caching/Arweave/ArweaveClient.js +182 -256
  337. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  338. package/dist/esm/caching/IPFS/PinataIPFSClient.js +47 -48
  339. package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
  340. package/dist/esm/caching/Memory/MemoryCacheClient.js +13 -19
  341. package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
  342. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +333 -408
  343. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  344. package/dist/esm/clients/BaseAbstractClient.js +66 -92
  345. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  346. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +927 -1054
  347. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  348. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +102 -131
  349. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  350. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +57 -59
  351. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  352. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +7 -5
  353. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  354. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +75 -94
  355. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  356. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +45 -23
  357. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  358. package/dist/esm/clients/HubPoolClient.js +581 -740
  359. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  360. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +133 -178
  361. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  362. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +126 -183
  363. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  364. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +372 -399
  365. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  366. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js +9 -9
  367. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  368. package/dist/esm/clients/SpokePoolClient/index.js +2 -2
  369. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  370. package/dist/esm/clients/SpokePoolClient/types.js +2 -2
  371. package/dist/esm/clients/SpokePoolClient/types.js.map +1 -1
  372. package/dist/esm/clients/mocks/MockConfigStoreClient.js +53 -64
  373. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  374. package/dist/esm/clients/mocks/MockEvents.js +42 -49
  375. package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
  376. package/dist/esm/clients/mocks/MockHubPoolClient.js +138 -182
  377. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  378. package/dist/esm/clients/mocks/MockSpokePoolClient.js +202 -188
  379. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  380. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +127 -132
  381. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  382. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +53 -69
  383. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  384. package/dist/esm/coingecko/Coingecko.js +298 -443
  385. package/dist/esm/coingecko/Coingecko.js.map +1 -1
  386. package/dist/esm/constants.js +40 -47
  387. package/dist/esm/constants.js.map +1 -1
  388. package/dist/esm/contracts/acrossConfigStore.js +24 -46
  389. package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
  390. package/dist/esm/contracts/hubPool.js +34 -18
  391. package/dist/esm/contracts/hubPool.js.map +1 -1
  392. package/dist/esm/contracts/utils.js +3 -5
  393. package/dist/esm/contracts/utils.js.map +1 -1
  394. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +6 -14
  395. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  396. package/dist/esm/gasPriceOracle/adapters/ethereum.js +22 -42
  397. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  398. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +13 -25
  399. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  400. package/dist/esm/gasPriceOracle/adapters/polygon.js +72 -108
  401. package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
  402. package/dist/esm/gasPriceOracle/adapters/solana.js +22 -31
  403. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
  404. package/dist/esm/gasPriceOracle/oracle.js +70 -96
  405. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  406. package/dist/esm/gasPriceOracle/types.js +2 -2
  407. package/dist/esm/gasPriceOracle/types.js.map +1 -1
  408. package/dist/esm/gasPriceOracle/util.js +4 -4
  409. package/dist/esm/gasPriceOracle/util.js.map +1 -1
  410. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js +30 -33
  411. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  412. package/dist/esm/lpFeeCalculator/rateModel.js +7 -9
  413. package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
  414. package/dist/esm/merkleDistributor/MerkleDistributor.js +18 -17
  415. package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
  416. package/dist/esm/pool/TransactionManager.js +45 -100
  417. package/dist/esm/pool/TransactionManager.js.map +1 -1
  418. package/dist/esm/pool/poolClient.js +479 -740
  419. package/dist/esm/pool/poolClient.js.map +1 -1
  420. package/dist/esm/pool/uma/across/constants.js +2 -2
  421. package/dist/esm/pool/uma/across/constants.js.map +1 -1
  422. package/dist/esm/pool/uma/across/transactionManager.js +45 -100
  423. package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
  424. package/dist/esm/pool/uma/clients/erc20/client.js +15 -13
  425. package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
  426. package/dist/esm/pool/uma/oracle/utils.js +2 -3
  427. package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
  428. package/dist/esm/pool/uma/utils.js +9 -28
  429. package/dist/esm/pool/uma/utils.js.map +1 -1
  430. package/dist/esm/priceClient/adapters/acrossApi.js +21 -40
  431. package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
  432. package/dist/esm/priceClient/adapters/baseAdapter.js +46 -72
  433. package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
  434. package/dist/esm/priceClient/adapters/coingecko.js +33 -61
  435. package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
  436. package/dist/esm/priceClient/adapters/default.js +15 -31
  437. package/dist/esm/priceClient/adapters/default.js.map +1 -1
  438. package/dist/esm/priceClient/adapters/defiLlama.js +38 -73
  439. package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
  440. package/dist/esm/priceClient/priceClient.js +109 -158
  441. package/dist/esm/priceClient/priceClient.js.map +1 -1
  442. package/dist/esm/providers/alchemy.js +16 -18
  443. package/dist/esm/providers/alchemy.js.map +1 -1
  444. package/dist/esm/providers/cachedProvider.js +99 -134
  445. package/dist/esm/providers/cachedProvider.js.map +1 -1
  446. package/dist/esm/providers/constants.js +3 -3
  447. package/dist/esm/providers/constants.js.map +1 -1
  448. package/dist/esm/providers/drpc.js +8 -10
  449. package/dist/esm/providers/drpc.js.map +1 -1
  450. package/dist/esm/providers/infura.js +9 -11
  451. package/dist/esm/providers/infura.js.map +1 -1
  452. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +6 -15
  453. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  454. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +5 -14
  455. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  456. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +6 -15
  457. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  458. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +41 -66
  459. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  460. package/dist/esm/providers/mocks/mockEthersProvider.js +27 -30
  461. package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
  462. package/dist/esm/providers/quicknode.js +18 -20
  463. package/dist/esm/providers/quicknode.js.map +1 -1
  464. package/dist/esm/providers/rateLimitedProvider.js +68 -80
  465. package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
  466. package/dist/esm/providers/retryProvider.js +186 -259
  467. package/dist/esm/providers/retryProvider.js.map +1 -1
  468. package/dist/esm/providers/solana/baseRpcFactories.js +13 -19
  469. package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
  470. package/dist/esm/providers/solana/cachedRpcFactory.js +75 -112
  471. package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
  472. package/dist/esm/providers/solana/defaultRpcFactory.js +6 -14
  473. package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
  474. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +149 -202
  475. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  476. package/dist/esm/providers/solana/rateLimitedRpcFactory.js +70 -90
  477. package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  478. package/dist/esm/providers/solana/retryRpcFactory.js +50 -74
  479. package/dist/esm/providers/solana/retryRpcFactory.js.map +1 -1
  480. package/dist/esm/providers/solana/utils.js +1 -1
  481. package/dist/esm/providers/solana/utils.js.map +1 -1
  482. package/dist/esm/providers/speedProvider.js +28 -51
  483. package/dist/esm/providers/speedProvider.js.map +1 -1
  484. package/dist/esm/providers/types.js +2 -2
  485. package/dist/esm/providers/types.js.map +1 -1
  486. package/dist/esm/providers/utils.js +17 -20
  487. package/dist/esm/providers/utils.js.map +1 -1
  488. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +98 -152
  489. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  490. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +13 -26
  491. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  492. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +9 -19
  493. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  494. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +83 -128
  495. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  496. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +211 -299
  497. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  498. package/dist/esm/typeguards/error.js +3 -5
  499. package/dist/esm/typeguards/error.js.map +1 -1
  500. package/dist/esm/utils/AddressUtils.js +115 -147
  501. package/dist/esm/utils/AddressUtils.js.map +1 -1
  502. package/dist/esm/utils/ArrayUtils.js +21 -78
  503. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  504. package/dist/esm/utils/BigNumberUtils.js +11 -12
  505. package/dist/esm/utils/BigNumberUtils.js.map +1 -1
  506. package/dist/esm/utils/BlockExplorerUtils.js +19 -23
  507. package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
  508. package/dist/esm/utils/BlockFinder.js +2 -6
  509. package/dist/esm/utils/BlockFinder.js.map +1 -1
  510. package/dist/esm/utils/BlockUtils.js +31 -40
  511. package/dist/esm/utils/BlockUtils.js.map +1 -1
  512. package/dist/esm/utils/BundleUtils.js +21 -24
  513. package/dist/esm/utils/BundleUtils.js.map +1 -1
  514. package/dist/esm/utils/CCTPUtils.js +62 -123
  515. package/dist/esm/utils/CCTPUtils.js.map +1 -1
  516. package/dist/esm/utils/CachingUtils.js +17 -38
  517. package/dist/esm/utils/CachingUtils.js.map +1 -1
  518. package/dist/esm/utils/ContractUtils.js +3 -3
  519. package/dist/esm/utils/ContractUtils.js.map +1 -1
  520. package/dist/esm/utils/DepositUtils.js +121 -98
  521. package/dist/esm/utils/DepositUtils.js.map +1 -1
  522. package/dist/esm/utils/EventUtils.js +52 -69
  523. package/dist/esm/utils/EventUtils.js.map +1 -1
  524. package/dist/esm/utils/FormattingUtils.js +20 -26
  525. package/dist/esm/utils/FormattingUtils.js.map +1 -1
  526. package/dist/esm/utils/HyperLiquidUtils.js +8 -22
  527. package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
  528. package/dist/esm/utils/IPFSUtils.js +16 -35
  529. package/dist/esm/utils/IPFSUtils.js.map +1 -1
  530. package/dist/esm/utils/JSONUtils.js +4 -4
  531. package/dist/esm/utils/JSONUtils.js.map +1 -1
  532. package/dist/esm/utils/LogUtils.js +8 -12
  533. package/dist/esm/utils/LogUtils.js.map +1 -1
  534. package/dist/esm/utils/Multicall.js +50 -110
  535. package/dist/esm/utils/Multicall.js.map +1 -1
  536. package/dist/esm/utils/NetworkUtils.js +12 -28
  537. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  538. package/dist/esm/utils/NumberUtils.js +1 -3
  539. package/dist/esm/utils/NumberUtils.js.map +1 -1
  540. package/dist/esm/utils/ObjectUtils.js +27 -41
  541. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  542. package/dist/esm/utils/Profiler.js +77 -82
  543. package/dist/esm/utils/Profiler.js.map +1 -1
  544. package/dist/esm/utils/ReviverUtils.js +3 -7
  545. package/dist/esm/utils/ReviverUtils.js.map +1 -1
  546. package/dist/esm/utils/SpokeUtils.js +83 -78
  547. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  548. package/dist/esm/utils/TokenUtils.js +33 -57
  549. package/dist/esm/utils/TokenUtils.js.map +1 -1
  550. package/dist/esm/utils/ValidatorUtils.js +4 -4
  551. package/dist/esm/utils/ValidatorUtils.js.map +1 -1
  552. package/dist/esm/utils/abi/index.js +10 -20
  553. package/dist/esm/utils/abi/index.js.map +1 -1
  554. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +8 -12
  555. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  556. package/dist/esm/utils/common.js +38 -52
  557. package/dist/esm/utils/common.js.map +1 -1
  558. package/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 +2 -2
  563. package/src/constants.ts +0 -1
  564. package/src/gasPriceOracle/oracle.ts +0 -1
  565. package/src/utils/Multicall.ts +0 -1
  566. package/src/utils/NetworkUtils.ts +1 -8
@@ -1,4 +1,3 @@
1
- import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
2
1
  import assert from "assert";
3
2
  import * as uma from "./uma";
4
3
  import { bnZero, toBNWei, fixedPointAdjustment, calcPeriodicCompoundInterest, calcApr, BigNumber, fromWei, } from "../utils";
@@ -9,247 +8,203 @@ import has from "lodash/has";
9
8
  import { calculateInstantaneousRate } from "../lpFeeCalculator";
10
9
  import { hubPool, acrossConfigStore } from "../contracts";
11
10
  import { AcceleratingDistributor__factory, MerkleDistributor__factory, } from "../typechain";
12
- var erc20 = uma.clients.erc20;
13
- var loop = uma.utils.loop;
14
- var TransactionManager = uma.across.TransactionManager;
15
- var _a = uma.across.constants, SECONDS_PER_YEAR = _a.SECONDS_PER_YEAR, DEFAULT_BLOCK_DELTA = _a.DEFAULT_BLOCK_DELTA;
16
- var AddressZero = ethers.constants.AddressZero;
17
- var PoolState = /** @class */ (function () {
18
- function PoolState(contract, address) {
11
+ const { erc20 } = uma.clients;
12
+ const { loop } = uma.utils;
13
+ const { TransactionManager } = uma.across;
14
+ const { SECONDS_PER_YEAR, DEFAULT_BLOCK_DELTA } = uma.across.constants;
15
+ const { AddressZero } = ethers.constants;
16
+ class PoolState {
17
+ contract;
18
+ address;
19
+ constructor(contract, address) {
19
20
  this.contract = contract;
20
21
  this.address = address;
21
22
  }
22
- PoolState.prototype.read = function (l1Token, latestBlock, previousBlock) {
23
- return __awaiter(this, void 0, void 0, function () {
24
- var exchangeRatePrevious, exchangeRateCurrent, pooledToken, liquidityUtilizationCurrent;
25
- return __generator(this, function (_a) {
26
- switch (_a.label) {
27
- case 0: return [4 /*yield*/, this.exchangeRateAtBlock(l1Token, previousBlock || latestBlock - 1)];
28
- case 1:
29
- exchangeRatePrevious = _a.sent();
30
- return [4 /*yield*/, this.contract.callStatic.exchangeRateCurrent(l1Token)];
31
- case 2:
32
- exchangeRateCurrent = _a.sent();
33
- return [4 /*yield*/, this.contract.pooledTokens(l1Token)];
34
- case 3:
35
- pooledToken = _a.sent();
36
- return [4 /*yield*/, this.contract.callStatic.liquidityUtilizationCurrent(l1Token)];
37
- case 4:
38
- liquidityUtilizationCurrent = _a.sent();
39
- return [2 /*return*/, __assign({ address: this.address, l1Token: l1Token, latestBlock: latestBlock, previousBlock: previousBlock, exchangeRatePrevious: exchangeRatePrevious, exchangeRateCurrent: exchangeRateCurrent, liquidityUtilizationCurrent: liquidityUtilizationCurrent }, pooledToken)];
40
- }
41
- });
42
- });
43
- };
44
- PoolState.prototype.exchangeRateAtBlock = function (l1Token, blockTag) {
45
- return this.contract.callStatic.exchangeRateCurrent(l1Token, { blockTag: blockTag });
46
- };
47
- return PoolState;
48
- }());
49
- var PoolEventState = /** @class */ (function () {
50
- function PoolEventState(contract, startBlock) {
51
- if (startBlock === void 0) { startBlock = 0; }
52
- var _this = this;
23
+ async read(l1Token, latestBlock, previousBlock) {
24
+ // typechain does not have complete types for call options, so we have to cast blockTag to any
25
+ const exchangeRatePrevious = await this.exchangeRateAtBlock(l1Token, previousBlock || latestBlock - 1);
26
+ const exchangeRateCurrent = await this.contract.callStatic.exchangeRateCurrent(l1Token);
27
+ const pooledToken = await this.contract.pooledTokens(l1Token);
28
+ const liquidityUtilizationCurrent = await this.contract.callStatic.liquidityUtilizationCurrent(l1Token);
29
+ return {
30
+ address: this.address,
31
+ l1Token,
32
+ latestBlock,
33
+ previousBlock,
34
+ exchangeRatePrevious,
35
+ exchangeRateCurrent,
36
+ liquidityUtilizationCurrent,
37
+ ...pooledToken,
38
+ };
39
+ }
40
+ exchangeRateAtBlock(l1Token, blockTag) {
41
+ return this.contract.callStatic.exchangeRateCurrent(l1Token, { blockTag });
42
+ }
43
+ }
44
+ export class PoolEventState {
45
+ contract;
46
+ startBlock;
47
+ seen = new Set();
48
+ iface;
49
+ // maintain ordered unique list of events so we can calculate state
50
+ events = [];
51
+ constructor(contract, startBlock = 0) {
53
52
  this.contract = contract;
54
53
  this.startBlock = startBlock;
55
- this.seen = new Set();
56
- // maintain ordered unique list of events so we can calculate state
57
- this.events = [];
58
- this.makeId = function (params) {
59
- return uma.oracle.utils.eventKey(params);
60
- };
61
- this.filterSeen = function (params) {
62
- var seen = _this.hasEvent(params);
63
- if (!seen)
64
- _this.addEvent(params);
65
- return !seen;
66
- };
67
- this.processEvent = function (event) {
68
- if (!_this.filterSeen(event))
69
- return;
70
- _this.events = uma.oracle.utils.insertOrderedAscending(_this.events, event, _this.makeId);
71
- };
72
- this.processEvents = function (events) {
73
- events.forEach(_this.processEvent);
74
- };
75
- this.makeEventFromLog = function (log) {
76
- var description = _this.iface.parseLog(log);
77
- return __assign(__assign(__assign({}, log), description), { event: description.name, eventSignature: description.signature });
78
- };
79
54
  this.iface = new ethers.utils.Interface(hubPool.Factory.abi);
80
55
  }
81
- PoolEventState.prototype.hasEvent = function (params) {
82
- return this.seen.has(this.makeId(params));
56
+ makeId = (params) => {
57
+ return uma.oracle.utils.eventKey(params);
83
58
  };
84
- PoolEventState.prototype.addEvent = function (params) {
59
+ hasEvent(params) {
60
+ return this.seen.has(this.makeId(params));
61
+ }
62
+ addEvent(params) {
85
63
  this.seen.add(this.makeId(params));
64
+ }
65
+ filterSeen = (params) => {
66
+ const seen = this.hasEvent(params);
67
+ if (!seen)
68
+ this.addEvent(params);
69
+ return !seen;
70
+ };
71
+ processEvent = (event) => {
72
+ if (!this.filterSeen(event))
73
+ return;
74
+ this.events = uma.oracle.utils.insertOrderedAscending(this.events, event, this.makeId);
75
+ };
76
+ processEvents = (events) => {
77
+ events.forEach(this.processEvent);
78
+ };
79
+ async read(endBlock, l1TokenAddress, userAddress) {
80
+ const events = await Promise.all([
81
+ ...(await this.contract.queryFilter(this.contract.filters.LiquidityAdded(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)),
82
+ ...(await this.contract.queryFilter(this.contract.filters.LiquidityRemoved(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)),
83
+ ]);
84
+ this.processEvents(events);
85
+ return hubPool.getEventState(this.events);
86
+ }
87
+ makeEventFromLog = (log) => {
88
+ const description = this.iface.parseLog(log);
89
+ return {
90
+ ...log,
91
+ ...description,
92
+ event: description.name,
93
+ eventSignature: description.signature,
94
+ };
86
95
  };
87
- PoolEventState.prototype.read = function (endBlock, l1TokenAddress, userAddress) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var events, _a, _b, _c, _d;
90
- return __generator(this, function (_e) {
91
- switch (_e.label) {
92
- case 0:
93
- _b = (_a = Promise).all;
94
- _c = [[]];
95
- return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.LiquidityAdded(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)];
96
- case 1:
97
- _d = [__spreadArray.apply(void 0, _c.concat([(_e.sent()), true]))];
98
- return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.LiquidityRemoved(l1TokenAddress, undefined, undefined, userAddress), this.startBlock, endBlock)];
99
- case 2: return [4 /*yield*/, _b.apply(_a, [__spreadArray.apply(void 0, _d.concat([(_e.sent()), true]))])];
100
- case 3:
101
- events = _e.sent();
102
- this.processEvents(events);
103
- return [2 /*return*/, hubPool.getEventState(this.events)];
104
- }
105
- });
106
- });
107
- };
108
- PoolEventState.prototype.getL1TokenFromReceipt = function (receipt) {
109
- var _this = this;
110
- var events = receipt.logs
111
- .filter(function (log) { return ethers.utils.getAddress(log.address) === ethers.utils.getAddress(_this.contract.address); })
96
+ getL1TokenFromReceipt(receipt) {
97
+ const events = receipt.logs
98
+ .filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
112
99
  .map(this.makeEventFromLog);
113
100
  // save these events
114
101
  this.processEvents(events);
115
102
  // only process token receipt events, because we just want the l1 token involved with this transfer
116
- var eventState = hubPool.getEventState(events);
103
+ const eventState = hubPool.getEventState(events);
117
104
  // event state is keyed by l1token address
118
- var l1Tokens = Object.keys(eventState);
105
+ const l1Tokens = Object.keys(eventState);
119
106
  assert(l1Tokens.length, "Token not found from events");
120
107
  assert(l1Tokens.length === 1, "Multiple tokens found from events");
121
108
  return l1Tokens[0];
122
- };
123
- PoolEventState.prototype.readTxReceipt = function (receipt) {
124
- var _this = this;
125
- var events = receipt.logs
126
- .filter(function (log) { return ethers.utils.getAddress(log.address) === ethers.utils.getAddress(_this.contract.address); })
109
+ }
110
+ readTxReceipt(receipt) {
111
+ const events = receipt.logs
112
+ .filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
127
113
  .map(this.makeEventFromLog);
128
114
  this.processEvents(events);
129
115
  return hubPool.getEventState(this.events);
130
- };
131
- return PoolEventState;
132
- }());
133
- export { PoolEventState };
134
- var UserState = /** @class */ (function () {
135
- function UserState(contract, userAddress, startBlock, acceleratingDistributorContractAddress) {
136
- if (startBlock === void 0) { startBlock = 0; }
137
- if (acceleratingDistributorContractAddress === void 0) { acceleratingDistributorContractAddress = ""; }
138
- var _this = this;
116
+ }
117
+ }
118
+ class UserState {
119
+ contract;
120
+ userAddress;
121
+ startBlock;
122
+ acceleratingDistributorContractAddress;
123
+ seen = new Set();
124
+ events = [];
125
+ constructor(contract, userAddress, startBlock = 0, acceleratingDistributorContractAddress = "") {
139
126
  this.contract = contract;
140
127
  this.userAddress = userAddress;
141
128
  this.startBlock = startBlock;
142
129
  this.acceleratingDistributorContractAddress = acceleratingDistributorContractAddress;
143
- this.seen = new Set();
144
- this.events = [];
145
- this.filterSeen = function (params) {
146
- var seen = _this.hasEvent(params);
147
- if (!seen)
148
- _this.addEvent(params);
149
- return !seen;
150
- };
151
130
  }
152
- UserState.prototype.makeId = function (params) {
131
+ makeId(params) {
153
132
  return uma.oracle.utils.eventKey(params);
154
- };
155
- UserState.prototype.hasEvent = function (params) {
133
+ }
134
+ hasEvent(params) {
156
135
  return this.seen.has(this.makeId(params));
157
- };
158
- UserState.prototype.addEvent = function (params) {
136
+ }
137
+ addEvent(params) {
159
138
  this.seen.add(this.makeId(params));
139
+ }
140
+ filterSeen = (params) => {
141
+ const seen = this.hasEvent(params);
142
+ if (!seen)
143
+ this.addEvent(params);
144
+ return !seen;
160
145
  };
161
146
  /**
162
147
  * readEvents. Fetch and cache events for the user.
163
148
  *
164
149
  * @param {number} endBlock
165
150
  */
166
- UserState.prototype.readEvents = function (endBlock) {
167
- return __awaiter(this, void 0, void 0, function () {
168
- var userAddress, events, _a, _b, _c, _d;
169
- var _this = this;
170
- return __generator(this, function (_e) {
171
- switch (_e.label) {
172
- case 0:
173
- if (endBlock <= this.startBlock)
174
- return [2 /*return*/, []];
175
- userAddress = this.userAddress;
176
- _b = (_a = Promise).all;
177
- _c = [[]];
178
- return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.Transfer(userAddress, undefined), this.startBlock, endBlock)];
179
- case 1:
180
- _d = [__spreadArray.apply(void 0, _c.concat([(_e.sent()), true]))];
181
- return [4 /*yield*/, this.contract.queryFilter(this.contract.filters.Transfer(undefined, userAddress), this.startBlock, endBlock)];
182
- case 2: return [4 /*yield*/, _b.apply(_a, [__spreadArray.apply(void 0, _d.concat([(_e.sent()), true]))])];
183
- case 3:
184
- events = (_e.sent())
185
- // filter out events we have seen
186
- .filter(this.filterSeen)
187
- // filter out mint/burn transfers
188
- .filter(function (event) {
189
- // ignore mint events
190
- return event.args.from !== AddressZero &&
191
- // ignore burn events
192
- event.args.to !== AddressZero &&
193
- // ignore AD transfer events in
194
- event.args.to !== _this.acceleratingDistributorContractAddress &&
195
- // ignore AD transfer events out
196
- event.args.from !== _this.acceleratingDistributorContractAddress &&
197
- // ignore self transfer events
198
- event.args.from !== event.args.to;
199
- })
200
- .flat();
201
- this.events = this.events.concat(events).sort(function (a, b) {
202
- if (a.blockNumber !== b.blockNumber)
203
- return a.blockNumber - b.blockNumber;
204
- if (a.transactionIndex !== b.transactionIndex)
205
- return a.transactionIndex - b.transactionIndex;
206
- if (a.logIndex !== b.logIndex)
207
- return a.logIndex - b.logIndex;
208
- throw new Error("Duplicate events at tx hash: " + a.transactionHash);
209
- });
210
- // ethers queries are inclusive [start,end] unless start === end, then exclusive (start,end). we increment to make sure we dont see same event twice
211
- this.startBlock = endBlock + 1;
212
- return [2 /*return*/, this.events];
213
- }
214
- });
151
+ async readEvents(endBlock) {
152
+ if (endBlock <= this.startBlock)
153
+ return [];
154
+ const { userAddress } = this;
155
+ const events = (await Promise.all([
156
+ ...(await this.contract.queryFilter(this.contract.filters.Transfer(userAddress, undefined), this.startBlock, endBlock)),
157
+ ...(await this.contract.queryFilter(this.contract.filters.Transfer(undefined, userAddress), this.startBlock, endBlock)),
158
+ ]))
159
+ // filter out events we have seen
160
+ .filter(this.filterSeen)
161
+ // filter out mint/burn transfers
162
+ .filter((event) =>
163
+ // ignore mint events
164
+ event.args.from !== AddressZero &&
165
+ // ignore burn events
166
+ event.args.to !== AddressZero &&
167
+ // ignore AD transfer events in
168
+ event.args.to !== this.acceleratingDistributorContractAddress &&
169
+ // ignore AD transfer events out
170
+ event.args.from !== this.acceleratingDistributorContractAddress &&
171
+ // ignore self transfer events
172
+ event.args.from !== event.args.to)
173
+ .flat();
174
+ this.events = this.events.concat(events).sort((a, b) => {
175
+ if (a.blockNumber !== b.blockNumber)
176
+ return a.blockNumber - b.blockNumber;
177
+ if (a.transactionIndex !== b.transactionIndex)
178
+ return a.transactionIndex - b.transactionIndex;
179
+ if (a.logIndex !== b.logIndex)
180
+ return a.logIndex - b.logIndex;
181
+ throw new Error("Duplicate events at tx hash: " + a.transactionHash);
215
182
  });
216
- };
183
+ // ethers queries are inclusive [start,end] unless start === end, then exclusive (start,end). we increment to make sure we dont see same event twice
184
+ this.startBlock = endBlock + 1;
185
+ return this.events;
186
+ }
217
187
  /**
218
188
  * read. Reads the state for the user, building state from events as well as contract calls.
219
189
  *
220
190
  * @param {number} endBlock
221
191
  */
222
- UserState.prototype.read = function (endBlock) {
223
- return __awaiter(this, void 0, void 0, function () {
224
- var userAddress, transferEvents, state, balanceTransferred;
225
- var _a;
226
- var _b;
227
- return __generator(this, function (_c) {
228
- switch (_c.label) {
229
- case 0:
230
- userAddress = this.userAddress;
231
- return [4 /*yield*/, this.readEvents(endBlock)];
232
- case 1:
233
- transferEvents = _c.sent();
234
- state = uma.clients.erc20.getEventState(transferEvents);
235
- balanceTransferred = ((_b = state === null || state === void 0 ? void 0 : state.balances) === null || _b === void 0 ? void 0 : _b[userAddress]) || "0";
236
- _a = {
237
- transferEvents: transferEvents,
238
- balanceTransferred: balanceTransferred,
239
- address: userAddress
240
- };
241
- return [4 /*yield*/, this.contract.balanceOf(userAddress)];
242
- case 2: return [2 /*return*/, (_a.balanceOf = _c.sent(),
243
- _a)];
244
- }
245
- });
246
- });
247
- };
248
- return UserState;
249
- }());
192
+ async read(endBlock) {
193
+ const { userAddress } = this;
194
+ const transferEvents = await this.readEvents(endBlock);
195
+ const state = uma.clients.erc20.getEventState(transferEvents);
196
+ const balanceTransferred = state?.balances?.[userAddress] || "0";
197
+ return {
198
+ transferEvents,
199
+ balanceTransferred,
200
+ address: userAddress,
201
+ balanceOf: await this.contract.balanceOf(userAddress),
202
+ };
203
+ }
204
+ }
250
205
  export function calculateRemoval(amountWei, percentWei) {
251
- var receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
252
- var remain = amountWei.sub(receive);
206
+ const receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
207
+ const remain = amountWei.sub(receive);
253
208
  return {
254
209
  receive: receive.toString(),
255
210
  remain: remain.toString(),
@@ -257,22 +212,25 @@ export function calculateRemoval(amountWei, percentWei) {
257
212
  }
258
213
  // params here mimic the user object type
259
214
  export function previewRemoval(values, percentFloat) {
260
- var percentWei = toBNWei(percentFloat);
215
+ const percentWei = toBNWei(percentFloat);
261
216
  return {
262
- position: __assign({}, calculateRemoval(BigNumber.from(values.totalDeposited), percentWei)),
263
- fees: __assign({}, calculateRemoval(BigNumber.from(values.feesEarned), percentWei)),
264
- total: __assign({}, calculateRemoval(BigNumber.from(values.positionValue), percentWei)),
217
+ position: {
218
+ ...calculateRemoval(BigNumber.from(values.totalDeposited), percentWei),
219
+ },
220
+ fees: {
221
+ ...calculateRemoval(BigNumber.from(values.feesEarned), percentWei),
222
+ },
223
+ total: {
224
+ ...calculateRemoval(BigNumber.from(values.positionValue), percentWei),
225
+ },
265
226
  };
266
227
  }
267
- function joinUserState(poolState, tokenEventState, userState, transferValue, cumulativeStakeBalance, cumulativeStakeClaimBalance) {
268
- if (transferValue === void 0) { transferValue = bnZero; }
269
- if (cumulativeStakeBalance === void 0) { cumulativeStakeBalance = bnZero; }
270
- if (cumulativeStakeClaimBalance === void 0) { cumulativeStakeClaimBalance = bnZero; }
271
- var positionValue = BigNumber.from(poolState.exchangeRateCurrent)
228
+ function joinUserState(poolState, tokenEventState, userState, transferValue = bnZero, cumulativeStakeBalance = bnZero, cumulativeStakeClaimBalance = bnZero) {
229
+ const positionValue = BigNumber.from(poolState.exchangeRateCurrent)
272
230
  .mul(userState.balanceOf.add(cumulativeStakeBalance))
273
231
  .div(fixedPointAdjustment);
274
- var totalDeposited = BigNumber.from((tokenEventState === null || tokenEventState === void 0 ? void 0 : tokenEventState.tokenBalances[userState.address]) || "0").add(cumulativeStakeClaimBalance);
275
- var feesEarned = positionValue.sub(totalDeposited.add(transferValue));
232
+ const totalDeposited = BigNumber.from(tokenEventState?.tokenBalances[userState.address] || "0").add(cumulativeStakeClaimBalance);
233
+ const feesEarned = positionValue.sub(totalDeposited.add(transferValue));
276
234
  return {
277
235
  address: userState.address,
278
236
  poolAddress: poolState.address,
@@ -283,15 +241,15 @@ function joinUserState(poolState, tokenEventState, userState, transferValue, cum
283
241
  };
284
242
  }
285
243
  function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
286
- var totalPoolSize = poolState.liquidReserves.add(poolState.utilizedReserves);
287
- var secondsElapsed = latestBlock.timestamp - previousBlock.timestamp;
288
- var blocksElapsed = latestBlock.number - previousBlock.number;
289
- var exchangeRatePrevious = poolState.exchangeRatePrevious.toString();
290
- var exchangeRateCurrent = poolState.exchangeRateCurrent.toString();
291
- var liquidityUtilizationCurrent = poolState.liquidityUtilizationCurrent.toString();
292
- var estimatedApy = calcPeriodicCompoundInterest(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
293
- var estimatedApr = calcApr(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
294
- var projectedApr = "";
244
+ const totalPoolSize = poolState.liquidReserves.add(poolState.utilizedReserves);
245
+ const secondsElapsed = latestBlock.timestamp - previousBlock.timestamp;
246
+ const blocksElapsed = latestBlock.number - previousBlock.number;
247
+ const exchangeRatePrevious = poolState.exchangeRatePrevious.toString();
248
+ const exchangeRateCurrent = poolState.exchangeRateCurrent.toString();
249
+ const liquidityUtilizationCurrent = poolState.liquidityUtilizationCurrent.toString();
250
+ const estimatedApy = calcPeriodicCompoundInterest(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
251
+ const estimatedApr = calcApr(exchangeRatePrevious, exchangeRateCurrent, secondsElapsed, SECONDS_PER_YEAR);
252
+ let projectedApr = "";
295
253
  if (rateModel) {
296
254
  projectedApr = fromWei(calculateInstantaneousRate(rateModel, liquidityUtilizationCurrent)
297
255
  .mul(liquidityUtilizationCurrent)
@@ -305,45 +263,55 @@ function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
305
263
  liquidReserves: poolState.liquidReserves.toString(),
306
264
  exchangeRateCurrent: poolState.exchangeRateCurrent.toString(),
307
265
  exchangeRatePrevious: poolState.exchangeRatePrevious.toString(),
308
- estimatedApy: estimatedApy,
309
- estimatedApr: estimatedApr,
310
- blocksElapsed: blocksElapsed,
311
- secondsElapsed: secondsElapsed,
312
- projectedApr: projectedApr,
266
+ estimatedApy,
267
+ estimatedApr,
268
+ blocksElapsed,
269
+ secondsElapsed,
270
+ projectedApr,
313
271
  utilizedReserves: poolState.utilizedReserves.toString(),
314
- liquidityUtilizationCurrent: liquidityUtilizationCurrent,
272
+ liquidityUtilizationCurrent,
315
273
  };
316
274
  }
317
- var ReadPoolClient = /** @class */ (function () {
318
- function ReadPoolClient(address, provider) {
275
+ export class ReadPoolClient {
276
+ address;
277
+ provider;
278
+ poolState;
279
+ contract;
280
+ constructor(address, provider) {
319
281
  this.address = address;
320
282
  this.provider = provider;
321
283
  this.contract = hubPool.connect(address, this.provider);
322
284
  this.poolState = new PoolState(this.contract, this.address);
323
285
  }
324
- ReadPoolClient.prototype.read = function (tokenAddress, latestBlock) {
286
+ read(tokenAddress, latestBlock) {
325
287
  return this.poolState.read(tokenAddress, latestBlock);
326
- };
327
- return ReadPoolClient;
328
- }());
329
- export { ReadPoolClient };
288
+ }
289
+ }
330
290
  export function validateWithdraw(pool, user, lpTokenAmount) {
331
- var l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
291
+ const l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
332
292
  assert(BigNumber.from(l1TokensToReturn).gt("0"), "Must withdraw amount greater than 0");
333
293
  assert(BigNumber.from(lpTokenAmount).lte(user.lpTokens), "You cannot withdraw more than you have");
334
- return { lpTokenAmount: lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
294
+ return { lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
335
295
  }
336
- var Client = /** @class */ (function () {
337
- function Client(config, deps, emit) {
296
+ export class Client {
297
+ config;
298
+ deps;
299
+ emit;
300
+ transactionManagers = {};
301
+ hubPool;
302
+ acceleratingDistributor;
303
+ merkleDistributor;
304
+ state = { pools: {}, users: {}, transactions: {} };
305
+ poolEvents;
306
+ erc20s = {};
307
+ intervalStarted = false;
308
+ configStoreClient;
309
+ exchangeRateTable = {};
310
+ userServices = {};
311
+ constructor(config, deps, emit) {
338
312
  this.config = config;
339
313
  this.deps = deps;
340
314
  this.emit = emit;
341
- this.transactionManagers = {};
342
- this.state = { pools: {}, users: {}, transactions: {} };
343
- this.erc20s = {};
344
- this.intervalStarted = false;
345
- this.exchangeRateTable = {};
346
- this.userServices = {};
347
315
  config.chainId = config.chainId || 1;
348
316
  this.hubPool = this.createHubPoolContract(deps.provider);
349
317
  this.acceleratingDistributor = this.createAcceleratingDistributorContract(deps.provider);
@@ -351,549 +319,320 @@ var Client = /** @class */ (function () {
351
319
  this.poolEvents = new PoolEventState(this.hubPool, this.config.hubPoolStartBlock);
352
320
  this.configStoreClient = new acrossConfigStore.Client(config.configStoreAddress, deps.provider);
353
321
  }
354
- Client.prototype.getOrCreateErc20Contract = function (address) {
322
+ getOrCreateErc20Contract(address) {
355
323
  if (this.erc20s[address])
356
324
  return this.erc20s[address];
357
325
  this.erc20s[address] = erc20.connect(address, this.deps.provider);
358
326
  return this.erc20s[address];
359
- };
360
- Client.prototype.getOrCreatePoolContract = function () {
327
+ }
328
+ getOrCreatePoolContract() {
361
329
  return this.hubPool;
362
- };
363
- Client.prototype.createHubPoolContract = function (signerOrProvider) {
330
+ }
331
+ createHubPoolContract(signerOrProvider) {
364
332
  return hubPool.connect(this.config.hubPoolAddress, signerOrProvider);
365
- };
366
- Client.prototype.getOrCreatePoolEvents = function () {
333
+ }
334
+ getOrCreatePoolEvents() {
367
335
  return this.poolEvents;
368
- };
369
- Client.prototype.createAcceleratingDistributorContract = function (signerOrProvider) {
336
+ }
337
+ createAcceleratingDistributorContract(signerOrProvider) {
370
338
  return AcceleratingDistributor__factory.connect(this.config.acceleratingDistributorAddress, signerOrProvider);
371
- };
372
- Client.prototype.createMerkleDistributorContract = function (signerOrProvider) {
339
+ }
340
+ createMerkleDistributorContract(signerOrProvider) {
373
341
  return MerkleDistributor__factory.connect(this.config.merkleDistributorAddress, signerOrProvider);
374
- };
375
- Client.prototype.getOrCreateAcceleratingDistributorContract = function () {
342
+ }
343
+ getOrCreateAcceleratingDistributorContract() {
376
344
  return this.acceleratingDistributor;
377
- };
378
- Client.prototype.getOrCreateMerkleDistributorContract = function () {
345
+ }
346
+ getOrCreateMerkleDistributorContract() {
379
347
  return this.merkleDistributor;
380
- };
381
- Client.prototype.getOrCreateUserService = function (userAddress, tokenAddress) {
348
+ }
349
+ getOrCreateUserService(userAddress, tokenAddress) {
382
350
  if (has(this.userServices, [tokenAddress, userAddress]))
383
351
  return get(this.userServices, [tokenAddress, userAddress]);
384
- var erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
385
- var userService = new UserState(erc20Contract, userAddress);
352
+ const erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
353
+ const userService = new UserState(erc20Contract, userAddress);
386
354
  // this service is stateful now, so needs to be cached
387
355
  set(this.userServices, [tokenAddress, userAddress], userService);
388
356
  return userService;
389
- };
390
- Client.prototype.updateExchangeRateTable = function (l1TokenAddress, exchangeRateTable) {
357
+ }
358
+ updateExchangeRateTable(l1TokenAddress, exchangeRateTable) {
391
359
  if (!this.exchangeRateTable[l1TokenAddress])
392
360
  this.exchangeRateTable[l1TokenAddress] = {};
393
- this.exchangeRateTable[l1TokenAddress] = __assign(__assign({}, this.exchangeRateTable[l1TokenAddress]), exchangeRateTable);
361
+ this.exchangeRateTable[l1TokenAddress] = { ...this.exchangeRateTable[l1TokenAddress], ...exchangeRateTable };
394
362
  return this.exchangeRateTable[l1TokenAddress];
395
- };
396
- Client.prototype.resolveStakingData = function (lpToken, l1TokenAddress, userState) {
397
- return __awaiter(this, void 0, void 0, function () {
398
- var acceleratingDistributorContract, merkleDistributorContract, poolContract, claimList, amountOfLPClaimed, cumulativeBalance;
399
- var _this = this;
400
- return __generator(this, function (_a) {
401
- switch (_a.label) {
402
- case 0:
403
- assert(this.config.acceleratingDistributorAddress, "Must have the accelerating distributor address");
404
- assert(this.config.merkleDistributorAddress, "Must have the merkle distributor address");
405
- acceleratingDistributorContract = this.getOrCreateAcceleratingDistributorContract();
406
- merkleDistributorContract = this.getOrCreateMerkleDistributorContract();
407
- poolContract = this.getOrCreatePoolContract();
408
- return [4 /*yield*/, merkleDistributorContract.queryFilter(merkleDistributorContract.filters.Claimed(undefined, undefined, userState.address, undefined, undefined, lpToken))];
409
- case 1:
410
- claimList = _a.sent();
411
- return [4 /*yield*/, Promise.all(claimList.map(function (claim) { return __awaiter(_this, void 0, void 0, function () {
412
- var _a, _b;
413
- return __generator(this, function (_c) {
414
- switch (_c.label) {
415
- case 0:
416
- _b = (_a = claim.args.amount).mul;
417
- return [4 /*yield*/, poolContract.callStatic.exchangeRateCurrent(l1TokenAddress, { blockTag: claim.blockNumber })];
418
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
419
- }
420
- });
421
- }); }))];
422
- case 2:
423
- amountOfLPClaimed = (_a.sent()).reduce(function (prev, acc) { return acc.add(prev); }, bnZero);
424
- return [4 /*yield*/, acceleratingDistributorContract.getUserStake(lpToken, userState.address)];
425
- case 3:
426
- cumulativeBalance = (_a.sent()).cumulativeBalance;
427
- return [2 /*return*/, {
428
- cumulativeBalance: cumulativeBalance,
429
- amountAirdropped: amountOfLPClaimed,
430
- }];
431
- }
432
- });
433
- });
434
- };
363
+ }
364
+ async resolveStakingData(lpToken, l1TokenAddress, userState) {
365
+ assert(this.config.acceleratingDistributorAddress, "Must have the accelerating distributor address");
366
+ assert(this.config.merkleDistributorAddress, "Must have the merkle distributor address");
367
+ // Define the contracts we need to interact with.
368
+ const acceleratingDistributorContract = this.getOrCreateAcceleratingDistributorContract();
369
+ const merkleDistributorContract = this.getOrCreateMerkleDistributorContract();
370
+ const poolContract = this.getOrCreatePoolContract();
371
+ // Get the list of all claims made by the user.
372
+ const claimList = await merkleDistributorContract.queryFilter(merkleDistributorContract.filters.Claimed(undefined, undefined, userState.address, undefined, undefined, lpToken));
373
+ // Calculate the total amount of LP tokens claimed by the user from the merkle
374
+ // distributor contract with the exchange rate at the time of the claim.
375
+ const amountOfLPClaimed = (await Promise.all(claimList.map(async (claim) => claim.args.amount.mul(await poolContract.callStatic.exchangeRateCurrent(l1TokenAddress, { blockTag: claim.blockNumber }))))).reduce((prev, acc) => acc.add(prev), bnZero);
376
+ // Get the cumulative balance of the user from the accelerating distributor contract.
377
+ const { cumulativeBalance } = await acceleratingDistributorContract.getUserStake(lpToken, userState.address);
378
+ return {
379
+ cumulativeBalance,
380
+ amountAirdropped: amountOfLPClaimed,
381
+ };
382
+ }
435
383
  // calculates the value of each LP token transfer at the block it was sent. this only works if we have archive node
436
- Client.prototype.calculateLpTransferValue = function (l1TokenAddress, userState) {
437
- return __awaiter(this, void 0, void 0, function () {
438
- var contract, pool, blockNumbers, exchangeRateTable, _a, _b, _c, _d;
439
- var _this = this;
440
- return __generator(this, function (_e) {
441
- switch (_e.label) {
442
- case 0:
443
- assert(this.config.hasArchive, "Can only calculate historical lp values with archive node");
444
- contract = this.getOrCreatePoolContract();
445
- pool = new PoolState(contract, this.config.hubPoolAddress);
446
- blockNumbers = userState.transferEvents
447
- .map(function (x) { return x.blockNumber; })
448
- // we are going to lookup exchange rates for block numbers only if we dont already have it
449
- // its possible these values do not exist, so to prevent crashing do optional chaining
450
- .filter(function (blockNumber) { var _a, _b; return !((_b = (_a = _this.exchangeRateTable) === null || _a === void 0 ? void 0 : _a[l1TokenAddress]) === null || _b === void 0 ? void 0 : _b[blockNumber]); });
451
- _a = this.updateExchangeRateTable;
452
- _b = [l1TokenAddress];
453
- _d = (_c = Object).fromEntries;
454
- return [4 /*yield*/, Promise.all(blockNumbers.map(function (blockNumber) { return __awaiter(_this, void 0, void 0, function () {
455
- var _a;
456
- return __generator(this, function (_b) {
457
- switch (_b.label) {
458
- case 0:
459
- _a = [blockNumber];
460
- return [4 /*yield*/, pool.exchangeRateAtBlock(l1TokenAddress, blockNumber)];
461
- case 1: return [2 /*return*/, _a.concat([_b.sent()])];
462
- }
463
- });
464
- }); }))];
465
- case 1:
466
- exchangeRateTable = _a.apply(this, _b.concat([_d.apply(_c, [_e.sent()])]));
467
- return [2 /*return*/, userState.transferEvents.reduce(function (result, transfer) {
468
- var exchangeRate = exchangeRateTable[transfer.blockNumber];
469
- if (transfer.args.to === userState.address) {
470
- return result.add(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
471
- }
472
- if (transfer.args.from === userState.address) {
473
- return result.sub(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
474
- }
475
- // we make sure to filter out any transfers where to/from is the same user
476
- return result;
477
- }, bnZero)];
478
- }
479
- });
480
- });
481
- };
482
- Client.prototype.getOrCreateTransactionManager = function (signer, address) {
483
- var _this = this;
384
+ async calculateLpTransferValue(l1TokenAddress, userState) {
385
+ assert(this.config.hasArchive, "Can only calculate historical lp values with archive node");
386
+ const contract = this.getOrCreatePoolContract();
387
+ const pool = new PoolState(contract, this.config.hubPoolAddress);
388
+ const blockNumbers = userState.transferEvents
389
+ .map((x) => x.blockNumber)
390
+ // we are going to lookup exchange rates for block numbers only if we dont already have it
391
+ // its possible these values do not exist, so to prevent crashing do optional chaining
392
+ .filter((blockNumber) => !this.exchangeRateTable?.[l1TokenAddress]?.[blockNumber]);
393
+ // new exchange rate lookups
394
+ const exchangeRateTable = this.updateExchangeRateTable(l1TokenAddress, Object.fromEntries(await Promise.all(blockNumbers.map(async (blockNumber) => {
395
+ return [blockNumber, await pool.exchangeRateAtBlock(l1TokenAddress, blockNumber)];
396
+ }))));
397
+ return userState.transferEvents.reduce((result, transfer) => {
398
+ const exchangeRate = exchangeRateTable[transfer.blockNumber];
399
+ if (transfer.args.to === userState.address) {
400
+ return result.add(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
401
+ }
402
+ if (transfer.args.from === userState.address) {
403
+ return result.sub(transfer.args.value.mul(exchangeRate).div(fixedPointAdjustment));
404
+ }
405
+ // we make sure to filter out any transfers where to/from is the same user
406
+ return result;
407
+ }, bnZero);
408
+ }
409
+ getOrCreateTransactionManager(signer, address) {
484
410
  if (this.transactionManagers[address])
485
411
  return this.transactionManagers[address];
486
- var txman = TransactionManager({ confirmations: this.config.confirmations }, signer, function (event, id, data) {
412
+ const txman = TransactionManager({ confirmations: this.config.confirmations }, signer, (event, id, data) => {
487
413
  if (event === "submitted") {
488
- _this.state.transactions[id].state = event;
489
- _this.state.transactions[id].hash = data;
490
- _this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
414
+ this.state.transactions[id].state = event;
415
+ this.state.transactions[id].hash = data;
416
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
491
417
  }
492
418
  if (event === "mined") {
493
- var txReceipt = data;
494
- _this.state.transactions[id].state = event;
495
- _this.state.transactions[id].receipt = txReceipt;
496
- _this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
419
+ const txReceipt = data;
420
+ this.state.transactions[id].state = event;
421
+ this.state.transactions[id].receipt = txReceipt;
422
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
497
423
  // trigger pool and user update for a known mined transaction
498
- var tx = _this.state.transactions[id];
499
- _this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch(function (err) {
500
- _this.emit(["error"], err);
424
+ const tx = this.state.transactions[id];
425
+ this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch((err) => {
426
+ this.emit(["error"], err);
501
427
  });
502
428
  }
503
429
  if (event === "error") {
504
- _this.state.transactions[id].state = event;
505
- _this.state.transactions[id].error = data;
506
- _this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
430
+ this.state.transactions[id].state = event;
431
+ this.state.transactions[id].error = data;
432
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
507
433
  }
508
434
  });
509
435
  this.transactionManagers[address] = txman;
510
436
  return txman;
511
- };
512
- Client.prototype.addEthLiquidity = function (signer_1, l1TokenAmount_1) {
513
- return __awaiter(this, arguments, void 0, function (signer, l1TokenAmount, overrides) {
514
- var _a, hubPoolAddress, l1Token, userAddress, contract, txman, request, id;
515
- if (overrides === void 0) { overrides = {}; }
516
- return __generator(this, function (_b) {
517
- switch (_b.label) {
518
- case 0:
519
- _a = this.config, hubPoolAddress = _a.hubPoolAddress, l1Token = _a.wethAddress;
520
- return [4 /*yield*/, signer.getAddress()];
521
- case 1:
522
- userAddress = _b.sent();
523
- contract = this.getOrCreatePoolContract();
524
- txman = this.getOrCreateTransactionManager(signer, userAddress);
525
- return [4 /*yield*/, contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, __assign(__assign({}, overrides), { value: l1TokenAmount }))];
526
- case 2:
527
- request = _b.sent();
528
- id = txman.request(request);
529
- this.state.transactions[id] = {
530
- id: id,
531
- state: "requested",
532
- toAddress: hubPoolAddress,
533
- fromAddress: userAddress,
534
- type: "Add Liquidity",
535
- description: "Adding ETH to pool",
536
- request: request,
537
- };
538
- this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
539
- return [4 /*yield*/, txman.update()];
540
- case 3:
541
- _b.sent();
542
- return [2 /*return*/, id];
543
- }
544
- });
545
- });
546
- };
547
- Client.prototype.addTokenLiquidity = function (signer_1, l1Token_1, l1TokenAmount_1) {
548
- return __awaiter(this, arguments, void 0, function (signer, l1Token, l1TokenAmount, overrides) {
549
- var hubPoolAddress, userAddress, contract, txman, request, id;
550
- if (overrides === void 0) { overrides = {}; }
551
- return __generator(this, function (_a) {
552
- switch (_a.label) {
553
- case 0:
554
- hubPoolAddress = this.config.hubPoolAddress;
555
- return [4 /*yield*/, signer.getAddress()];
556
- case 1:
557
- userAddress = _a.sent();
558
- contract = this.getOrCreatePoolContract();
559
- txman = this.getOrCreateTransactionManager(signer, userAddress);
560
- return [4 /*yield*/, contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, overrides)];
561
- case 2:
562
- request = _a.sent();
563
- return [4 /*yield*/, txman.request(request)];
564
- case 3:
565
- id = _a.sent();
566
- this.state.transactions[id] = {
567
- id: id,
568
- state: "requested",
569
- toAddress: hubPoolAddress,
570
- fromAddress: userAddress,
571
- type: "Add Liquidity",
572
- description: "Adding Tokens to pool",
573
- request: request,
574
- };
575
- this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
576
- return [4 /*yield*/, txman.update()];
577
- case 4:
578
- _a.sent();
579
- return [2 /*return*/, id];
580
- }
581
- });
582
- });
583
- };
584
- Client.prototype.validateWithdraw = function (l1Token, userAddress, lpAmount) {
585
- return __awaiter(this, void 0, void 0, function () {
586
- var poolState, userState;
587
- return __generator(this, function (_a) {
588
- switch (_a.label) {
589
- case 0: return [4 /*yield*/, this.updatePool(l1Token)];
590
- case 1:
591
- _a.sent();
592
- poolState = this.getPoolState(l1Token);
593
- if (!!this.hasUserState(l1Token, userAddress)) return [3 /*break*/, 3];
594
- return [4 /*yield*/, this.updateUser(l1Token, userAddress)];
595
- case 2:
596
- _a.sent();
597
- _a.label = 3;
598
- case 3:
599
- userState = this.getUserState(poolState.l1Token, userAddress);
600
- return [2 /*return*/, validateWithdraw(poolState, userState, lpAmount)];
601
- }
602
- });
603
- });
604
- };
605
- Client.prototype.removeTokenLiquidity = function (signer_1, l1Token_1, lpTokenAmount_1) {
606
- return __awaiter(this, arguments, void 0, function (signer, l1Token, lpTokenAmount, overrides) {
607
- var hubPoolAddress, userAddress, contract, txman, request, id;
608
- if (overrides === void 0) { overrides = {}; }
609
- return __generator(this, function (_a) {
610
- switch (_a.label) {
611
- case 0:
612
- hubPoolAddress = this.config.hubPoolAddress;
613
- return [4 /*yield*/, signer.getAddress()];
614
- case 1:
615
- userAddress = _a.sent();
616
- return [4 /*yield*/, this.validateWithdraw(l1Token, userAddress, lpTokenAmount)];
617
- case 2:
618
- _a.sent();
619
- contract = this.getOrCreatePoolContract();
620
- txman = this.getOrCreateTransactionManager(signer, userAddress);
621
- return [4 /*yield*/, contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, false, overrides)];
622
- case 3:
623
- request = _a.sent();
624
- return [4 /*yield*/, txman.request(request)];
625
- case 4:
626
- id = _a.sent();
627
- this.state.transactions[id] = {
628
- id: id,
629
- state: "requested",
630
- toAddress: hubPoolAddress,
631
- fromAddress: userAddress,
632
- type: "Remove Liquidity",
633
- description: "Withdrawing Tokens from pool",
634
- request: request,
635
- };
636
- this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
637
- return [4 /*yield*/, txman.update()];
638
- case 5:
639
- _a.sent();
640
- return [2 /*return*/, id];
641
- }
642
- });
643
- });
644
- };
645
- Client.prototype.removeEthliquidity = function (signer_1, lpTokenAmount_1) {
646
- return __awaiter(this, arguments, void 0, function (signer, lpTokenAmount, overrides) {
647
- var _a, hubPoolAddress, l1Token, userAddress, contract, txman, request, id;
648
- if (overrides === void 0) { overrides = {}; }
649
- return __generator(this, function (_b) {
650
- switch (_b.label) {
651
- case 0:
652
- _a = this.config, hubPoolAddress = _a.hubPoolAddress, l1Token = _a.wethAddress;
653
- return [4 /*yield*/, signer.getAddress()];
654
- case 1:
655
- userAddress = _b.sent();
656
- return [4 /*yield*/, this.validateWithdraw(l1Token, userAddress, lpTokenAmount)];
657
- case 2:
658
- _b.sent();
659
- contract = this.getOrCreatePoolContract();
660
- txman = this.getOrCreateTransactionManager(signer, userAddress);
661
- return [4 /*yield*/, contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, true, overrides)];
662
- case 3:
663
- request = _b.sent();
664
- return [4 /*yield*/, txman.request(request)];
665
- case 4:
666
- id = _b.sent();
667
- this.state.transactions[id] = {
668
- id: id,
669
- state: "requested",
670
- toAddress: hubPoolAddress,
671
- fromAddress: userAddress,
672
- type: "Remove Liquidity",
673
- description: "Withdrawing Eth from pool",
674
- request: request,
675
- };
676
- this.emit(["transactions", id], __assign({}, this.state.transactions[id]));
677
- return [4 /*yield*/, txman.update()];
678
- case 5:
679
- _b.sent();
680
- return [2 /*return*/, id];
681
- }
682
- });
437
+ }
438
+ async addEthLiquidity(signer, l1TokenAmount, overrides = {}) {
439
+ const { hubPoolAddress, wethAddress: l1Token } = this.config;
440
+ const userAddress = await signer.getAddress();
441
+ const contract = this.getOrCreatePoolContract();
442
+ const txman = this.getOrCreateTransactionManager(signer, userAddress);
443
+ // dont allow override value here
444
+ const request = await contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, {
445
+ ...overrides,
446
+ value: l1TokenAmount,
683
447
  });
684
- };
685
- Client.prototype.getPoolState = function (l1TokenAddress) {
448
+ const id = txman.request(request);
449
+ this.state.transactions[id] = {
450
+ id,
451
+ state: "requested",
452
+ toAddress: hubPoolAddress,
453
+ fromAddress: userAddress,
454
+ type: "Add Liquidity",
455
+ description: "Adding ETH to pool",
456
+ request,
457
+ };
458
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
459
+ await txman.update();
460
+ return id;
461
+ }
462
+ async addTokenLiquidity(signer, l1Token, l1TokenAmount, overrides = {}) {
463
+ const { hubPoolAddress } = this.config;
464
+ const userAddress = await signer.getAddress();
465
+ const contract = this.getOrCreatePoolContract();
466
+ const txman = this.getOrCreateTransactionManager(signer, userAddress);
467
+ const request = await contract.populateTransaction.addLiquidity(l1Token, l1TokenAmount, overrides);
468
+ const id = await txman.request(request);
469
+ this.state.transactions[id] = {
470
+ id,
471
+ state: "requested",
472
+ toAddress: hubPoolAddress,
473
+ fromAddress: userAddress,
474
+ type: "Add Liquidity",
475
+ description: "Adding Tokens to pool",
476
+ request,
477
+ };
478
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
479
+ await txman.update();
480
+ return id;
481
+ }
482
+ async validateWithdraw(l1Token, userAddress, lpAmount) {
483
+ await this.updatePool(l1Token);
484
+ const poolState = this.getPoolState(l1Token);
485
+ if (!this.hasUserState(l1Token, userAddress)) {
486
+ await this.updateUser(l1Token, userAddress);
487
+ }
488
+ const userState = this.getUserState(poolState.l1Token, userAddress);
489
+ return validateWithdraw(poolState, userState, lpAmount);
490
+ }
491
+ async removeTokenLiquidity(signer, l1Token, lpTokenAmount, overrides = {}) {
492
+ const { hubPoolAddress } = this.config;
493
+ const userAddress = await signer.getAddress();
494
+ await this.validateWithdraw(l1Token, userAddress, lpTokenAmount);
495
+ const contract = this.getOrCreatePoolContract();
496
+ const txman = this.getOrCreateTransactionManager(signer, userAddress);
497
+ const request = await contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, false, overrides);
498
+ const id = await txman.request(request);
499
+ this.state.transactions[id] = {
500
+ id,
501
+ state: "requested",
502
+ toAddress: hubPoolAddress,
503
+ fromAddress: userAddress,
504
+ type: "Remove Liquidity",
505
+ description: "Withdrawing Tokens from pool",
506
+ request,
507
+ };
508
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
509
+ await txman.update();
510
+ return id;
511
+ }
512
+ async removeEthliquidity(signer, lpTokenAmount, overrides = {}) {
513
+ const { hubPoolAddress, wethAddress: l1Token } = this.config;
514
+ const userAddress = await signer.getAddress();
515
+ await this.validateWithdraw(l1Token, userAddress, lpTokenAmount);
516
+ const contract = this.getOrCreatePoolContract();
517
+ const txman = this.getOrCreateTransactionManager(signer, userAddress);
518
+ const request = await contract.populateTransaction.removeLiquidity(l1Token, lpTokenAmount, true, overrides);
519
+ const id = await txman.request(request);
520
+ this.state.transactions[id] = {
521
+ id,
522
+ state: "requested",
523
+ toAddress: hubPoolAddress,
524
+ fromAddress: userAddress,
525
+ type: "Remove Liquidity",
526
+ description: "Withdrawing Eth from pool",
527
+ request,
528
+ };
529
+ this.emit(["transactions", id], { ...this.state.transactions[id] });
530
+ await txman.update();
531
+ return id;
532
+ }
533
+ getPoolState(l1TokenAddress) {
686
534
  return this.state.pools[l1TokenAddress];
687
- };
688
- Client.prototype.hasPoolState = function (l1TokenAddress) {
535
+ }
536
+ hasPoolState(l1TokenAddress) {
689
537
  return Boolean(this.state.pools[l1TokenAddress]);
690
- };
691
- Client.prototype.setUserState = function (l1TokenAddress, userAddress, state) {
538
+ }
539
+ setUserState(l1TokenAddress, userAddress, state) {
692
540
  set(this.state, ["users", userAddress, l1TokenAddress], state);
693
541
  return state;
694
- };
695
- Client.prototype.getUserState = function (l1TokenAddress, userAddress) {
542
+ }
543
+ getUserState(l1TokenAddress, userAddress) {
696
544
  return get(this.state, ["users", userAddress, l1TokenAddress]);
697
- };
698
- Client.prototype.hasUserState = function (l1TokenAddress, userAddress) {
545
+ }
546
+ hasUserState(l1TokenAddress, userAddress) {
699
547
  return has(this.state, ["users", userAddress, l1TokenAddress]);
700
- };
701
- Client.prototype.hasTxState = function (id) {
548
+ }
549
+ hasTxState(id) {
702
550
  return has(this.state, ["transactions", id]);
703
- };
704
- Client.prototype.getTxState = function (id) {
551
+ }
552
+ getTxState(id) {
705
553
  return get(this.state, ["transactions", id]);
706
- };
707
- Client.prototype.updateAndEmitUser = function (userState, poolState, poolEventState) {
708
- return __awaiter(this, void 0, void 0, function () {
709
- var l1TokenAddress, lpToken, userAddress, transferValue, _a, stakeData, tokenEventState, newUserState;
710
- return __generator(this, function (_b) {
711
- switch (_b.label) {
712
- case 0:
713
- l1TokenAddress = poolState.l1Token, lpToken = poolState.lpToken;
714
- userAddress = userState.address;
715
- if (!this.config.hasArchive) return [3 /*break*/, 2];
716
- return [4 /*yield*/, this.calculateLpTransferValue(l1TokenAddress, userState)];
717
- case 1:
718
- _a = _b.sent();
719
- return [3 /*break*/, 3];
720
- case 2:
721
- _a = bnZero;
722
- _b.label = 3;
723
- case 3:
724
- transferValue = _a;
725
- return [4 /*yield*/, this.resolveStakingData(lpToken, l1TokenAddress, userState)];
726
- case 4:
727
- stakeData = _b.sent();
728
- tokenEventState = poolEventState[l1TokenAddress];
729
- newUserState = this.setUserState(l1TokenAddress, userAddress, joinUserState(poolState, tokenEventState, userState, transferValue, stakeData.cumulativeBalance, stakeData.amountAirdropped));
730
- this.emit(["users", userAddress, l1TokenAddress], newUserState);
731
- return [2 /*return*/];
732
- }
733
- });
734
- });
735
- };
736
- Client.prototype.updateUserWithTransaction = function (userAddress, txReceipt) {
737
- return __awaiter(this, void 0, void 0, function () {
738
- var latestBlock, getPoolEventState, l1TokenAddress, poolState, poolEventState, lpToken, getUserState, userState;
739
- return __generator(this, function (_a) {
740
- switch (_a.label) {
741
- case 0: return [4 /*yield*/, this.deps.provider.getBlock("latest")];
742
- case 1:
743
- latestBlock = _a.sent();
744
- getPoolEventState = this.getOrCreatePoolEvents();
745
- l1TokenAddress = getPoolEventState.getL1TokenFromReceipt(txReceipt);
746
- return [4 /*yield*/, this.updatePool(l1TokenAddress, latestBlock)];
747
- case 2:
748
- _a.sent();
749
- poolState = this.getPoolState(l1TokenAddress);
750
- poolEventState = getPoolEventState.readTxReceipt(txReceipt);
751
- lpToken = poolState.lpToken;
752
- getUserState = this.getOrCreateUserService(userAddress, lpToken);
753
- return [4 /*yield*/, getUserState.read(latestBlock.number)];
754
- case 3:
755
- userState = _a.sent();
756
- return [4 /*yield*/, this.updateAndEmitUser(userState, poolState, poolEventState)];
757
- case 4:
758
- _a.sent();
759
- return [2 /*return*/];
760
- }
761
- });
762
- });
763
- };
764
- Client.prototype.updateUser = function (userAddress, l1TokenAddress) {
765
- return __awaiter(this, void 0, void 0, function () {
766
- var latestBlock, poolState, lpToken, getPoolEventState, poolEventState, getUserState, userState;
767
- return __generator(this, function (_a) {
768
- switch (_a.label) {
769
- case 0: return [4 /*yield*/, this.deps.provider.getBlock("latest")];
770
- case 1:
771
- latestBlock = _a.sent();
772
- return [4 /*yield*/, this.updatePool(l1TokenAddress, latestBlock)];
773
- case 2:
774
- _a.sent();
775
- poolState = this.getPoolState(l1TokenAddress);
776
- lpToken = poolState.lpToken;
777
- getPoolEventState = this.getOrCreatePoolEvents();
778
- return [4 /*yield*/, getPoolEventState.read(latestBlock.number, l1TokenAddress, userAddress)];
779
- case 3:
780
- poolEventState = _a.sent();
781
- getUserState = this.getOrCreateUserService(userAddress, lpToken);
782
- return [4 /*yield*/, getUserState.read(latestBlock.number)];
783
- case 4:
784
- userState = _a.sent();
785
- return [4 /*yield*/, this.updateAndEmitUser(userState, poolState, poolEventState)];
786
- case 5:
787
- _a.sent();
788
- return [2 /*return*/];
789
- }
790
- });
791
- });
792
- };
793
- Client.prototype.updatePool = function (l1TokenAddress, overrideLatestBlock) {
794
- return __awaiter(this, void 0, void 0, function () {
795
- var _a, blockDelta, contract, pool, latestBlock, _b, previousBlock, state, rateModel, err_1;
796
- return __generator(this, function (_c) {
797
- switch (_c.label) {
798
- case 0:
799
- _a = this.config.blockDelta, blockDelta = _a === void 0 ? DEFAULT_BLOCK_DELTA : _a;
800
- contract = this.getOrCreatePoolContract();
801
- pool = new PoolState(contract, this.config.hubPoolAddress);
802
- _b = overrideLatestBlock;
803
- if (_b) return [3 /*break*/, 2];
804
- return [4 /*yield*/, this.deps.provider.getBlock("latest")];
805
- case 1:
806
- _b = (_c.sent());
807
- _c.label = 2;
808
- case 2:
809
- latestBlock = _b;
810
- return [4 /*yield*/, this.deps.provider.getBlock(latestBlock.number - blockDelta)];
811
- case 3:
812
- previousBlock = _c.sent();
813
- return [4 /*yield*/, pool.read(l1TokenAddress, latestBlock.number, previousBlock.number)];
814
- case 4:
815
- state = _c.sent();
816
- rateModel = undefined;
817
- _c.label = 5;
818
- case 5:
819
- _c.trys.push([5, 7, , 8]);
820
- return [4 /*yield*/, this.configStoreClient.getRateModel(l1TokenAddress)];
821
- case 6:
822
- // Use the default rate model (i.e. not any of the routeRateModels to project the Pool's APR). This assumes
823
- // that the default rate model is the most often used, but this may change in future if many different
824
- // route rate models are set.
825
- rateModel = _c.sent();
826
- return [3 /*break*/, 8];
827
- case 7:
828
- err_1 = _c.sent();
829
- // we could swallow this error or just log it since getting the rate model is optional,
830
- // but we will just emit it to the caller and let them decide what to do with it.
831
- this.emit(["error"], err_1);
832
- return [3 /*break*/, 8];
833
- case 8:
834
- this.state.pools[l1TokenAddress] = joinPoolState(state, latestBlock, previousBlock, rateModel);
835
- this.emit(["pools", l1TokenAddress], this.state.pools[l1TokenAddress]);
836
- return [2 /*return*/];
837
- }
838
- });
839
- });
840
- };
841
- Client.prototype.updateTransactions = function () {
842
- return __awaiter(this, void 0, void 0, function () {
843
- var _i, _a, txMan, err_2;
844
- return __generator(this, function (_b) {
845
- switch (_b.label) {
846
- case 0:
847
- _i = 0, _a = Object.values(this.transactionManagers);
848
- _b.label = 1;
849
- case 1:
850
- if (!(_i < _a.length)) return [3 /*break*/, 6];
851
- txMan = _a[_i];
852
- _b.label = 2;
853
- case 2:
854
- _b.trys.push([2, 4, , 5]);
855
- return [4 /*yield*/, txMan.update()];
856
- case 3:
857
- _b.sent();
858
- return [3 /*break*/, 5];
859
- case 4:
860
- err_2 = _b.sent();
861
- this.emit(["error"], err_2);
862
- return [3 /*break*/, 5];
863
- case 5:
864
- _i++;
865
- return [3 /*break*/, 1];
866
- case 6: return [2 /*return*/];
867
- }
868
- });
869
- });
870
- };
554
+ }
555
+ async updateAndEmitUser(userState, poolState, poolEventState) {
556
+ const { l1Token: l1TokenAddress, lpToken } = poolState;
557
+ const { address: userAddress } = userState;
558
+ const transferValue = this.config.hasArchive
559
+ ? await this.calculateLpTransferValue(l1TokenAddress, userState)
560
+ : bnZero;
561
+ const stakeData = await this.resolveStakingData(lpToken, l1TokenAddress, userState);
562
+ const tokenEventState = poolEventState[l1TokenAddress];
563
+ const newUserState = this.setUserState(l1TokenAddress, userAddress, joinUserState(poolState, tokenEventState, userState, transferValue, stakeData.cumulativeBalance, stakeData.amountAirdropped));
564
+ this.emit(["users", userAddress, l1TokenAddress], newUserState);
565
+ }
566
+ async updateUserWithTransaction(userAddress, txReceipt) {
567
+ const latestBlock = await this.deps.provider.getBlock("latest");
568
+ const getPoolEventState = this.getOrCreatePoolEvents();
569
+ const l1TokenAddress = getPoolEventState.getL1TokenFromReceipt(txReceipt);
570
+ await this.updatePool(l1TokenAddress, latestBlock);
571
+ const poolState = this.getPoolState(l1TokenAddress);
572
+ const poolEventState = getPoolEventState.readTxReceipt(txReceipt);
573
+ const lpToken = poolState.lpToken;
574
+ const getUserState = this.getOrCreateUserService(userAddress, lpToken);
575
+ const userState = await getUserState.read(latestBlock.number);
576
+ await this.updateAndEmitUser(userState, poolState, poolEventState);
577
+ }
578
+ async updateUser(userAddress, l1TokenAddress) {
579
+ const latestBlock = await this.deps.provider.getBlock("latest");
580
+ await this.updatePool(l1TokenAddress, latestBlock);
581
+ const poolState = this.getPoolState(l1TokenAddress);
582
+ const lpToken = poolState.lpToken;
583
+ const getPoolEventState = this.getOrCreatePoolEvents();
584
+ const poolEventState = await getPoolEventState.read(latestBlock.number, l1TokenAddress, userAddress);
585
+ const getUserState = this.getOrCreateUserService(userAddress, lpToken);
586
+ const userState = await getUserState.read(latestBlock.number);
587
+ await this.updateAndEmitUser(userState, poolState, poolEventState);
588
+ }
589
+ async updatePool(l1TokenAddress, overrideLatestBlock) {
590
+ // default to 100 block delta unless specified otherwise in config
591
+ const { blockDelta = DEFAULT_BLOCK_DELTA } = this.config;
592
+ const contract = this.getOrCreatePoolContract();
593
+ const pool = new PoolState(contract, this.config.hubPoolAddress);
594
+ const latestBlock = overrideLatestBlock || (await this.deps.provider.getBlock("latest"));
595
+ const previousBlock = await this.deps.provider.getBlock(latestBlock.number - blockDelta);
596
+ const state = await pool.read(l1TokenAddress, latestBlock.number, previousBlock.number);
597
+ let rateModel = undefined;
598
+ try {
599
+ // Use the default rate model (i.e. not any of the routeRateModels to project the Pool's APR). This assumes
600
+ // that the default rate model is the most often used, but this may change in future if many different
601
+ // route rate models are set.
602
+ rateModel = await this.configStoreClient.getRateModel(l1TokenAddress);
603
+ }
604
+ catch (err) {
605
+ // we could swallow this error or just log it since getting the rate model is optional,
606
+ // but we will just emit it to the caller and let them decide what to do with it.
607
+ this.emit(["error"], err);
608
+ }
609
+ this.state.pools[l1TokenAddress] = joinPoolState(state, latestBlock, previousBlock, rateModel);
610
+ this.emit(["pools", l1TokenAddress], this.state.pools[l1TokenAddress]);
611
+ }
612
+ async updateTransactions() {
613
+ for (const txMan of Object.values(this.transactionManagers)) {
614
+ try {
615
+ await txMan.update();
616
+ }
617
+ catch (err) {
618
+ this.emit(["error"], err);
619
+ }
620
+ }
621
+ }
871
622
  // starts transaction checking intervals, defaults to 30 seconds
872
- Client.prototype.startInterval = function (delayMs) {
873
- var _this = this;
874
- if (delayMs === void 0) { delayMs = 30000; }
623
+ startInterval(delayMs = 30000) {
875
624
  assert(!this.intervalStarted, "Interval already started, try stopping first");
876
625
  this.intervalStarted = true;
877
- loop(function () { return __awaiter(_this, void 0, void 0, function () {
878
- return __generator(this, function (_a) {
879
- switch (_a.label) {
880
- case 0:
881
- assert(this.intervalStarted, "HubPool Interval Stopped");
882
- return [4 /*yield*/, this.updateTransactions()];
883
- case 1:
884
- _a.sent();
885
- return [2 /*return*/];
886
- }
887
- });
888
- }); }, delayMs).catch(function (err) {
889
- _this.emit(["error"], err);
626
+ loop(async () => {
627
+ assert(this.intervalStarted, "HubPool Interval Stopped");
628
+ await this.updateTransactions();
629
+ }, delayMs).catch((err) => {
630
+ this.emit(["error"], err);
890
631
  });
891
- };
632
+ }
892
633
  // starts transaction checking intervals
893
- Client.prototype.stopInterval = function () {
634
+ stopInterval() {
894
635
  this.intervalStarted = false;
895
- };
896
- return Client;
897
- }());
898
- export { Client };
636
+ }
637
+ }
899
638
  //# sourceMappingURL=poolClient.js.map