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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/dist/cjs/addressAggregator/adapters/abstract.js +64 -50
  2. package/dist/cjs/addressAggregator/adapters/abstract.js.map +1 -1
  3. package/dist/cjs/addressAggregator/adapters/bybit.js +29 -16
  4. package/dist/cjs/addressAggregator/adapters/bybit.js.map +1 -1
  5. package/dist/cjs/addressAggregator/adapters/env.js +15 -11
  6. package/dist/cjs/addressAggregator/adapters/env.js.map +1 -1
  7. package/dist/cjs/addressAggregator/adapters/file.js +45 -32
  8. package/dist/cjs/addressAggregator/adapters/file.js.map +1 -1
  9. package/dist/cjs/addressAggregator/adapters/index.js +1 -1
  10. package/dist/cjs/addressAggregator/adapters/risklabs.js +36 -22
  11. package/dist/cjs/addressAggregator/adapters/risklabs.js.map +1 -1
  12. package/dist/cjs/addressAggregator/index.js +87 -57
  13. package/dist/cjs/addressAggregator/index.js.map +1 -1
  14. package/dist/cjs/apiClient/abstractClient.js +8 -9
  15. package/dist/cjs/apiClient/abstractClient.js.map +1 -1
  16. package/dist/cjs/apiClient/index.js +1 -1
  17. package/dist/cjs/apiClient/mockedClient.js +29 -23
  18. package/dist/cjs/apiClient/mockedClient.js.map +1 -1
  19. package/dist/cjs/apiClient/productionClient.js +103 -65
  20. package/dist/cjs/apiClient/productionClient.js.map +1 -1
  21. package/dist/cjs/arch/evm/BlockUtils.js +208 -122
  22. package/dist/cjs/arch/evm/BlockUtils.js.map +1 -1
  23. package/dist/cjs/arch/evm/MessageUtils.js +1 -1
  24. package/dist/cjs/arch/evm/MessageUtils.js.map +1 -1
  25. package/dist/cjs/arch/evm/SpokeUtils.js +288 -134
  26. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  27. package/dist/cjs/arch/evm/index.js +1 -1
  28. package/dist/cjs/arch/evm/utils/index.js +1 -1
  29. package/dist/cjs/arch/evm/utils/wait.js +49 -38
  30. package/dist/cjs/arch/evm/utils/wait.js.map +1 -1
  31. package/dist/cjs/arch/index.js +1 -1
  32. package/dist/cjs/arch/svm/BlockUtils.js +158 -102
  33. package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
  34. package/dist/cjs/arch/svm/MessageUtils.js +2 -2
  35. package/dist/cjs/arch/svm/MessageUtils.js.map +1 -1
  36. package/dist/cjs/arch/svm/SpokeUtils.js +1147 -708
  37. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  38. package/dist/cjs/arch/svm/encoders.js +1 -1
  39. package/dist/cjs/arch/svm/encoders.js.map +1 -1
  40. package/dist/cjs/arch/svm/eventsClient.js +236 -174
  41. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  42. package/dist/cjs/arch/svm/index.js +1 -1
  43. package/dist/cjs/arch/svm/provider.js +3 -3
  44. package/dist/cjs/arch/svm/provider.js.map +1 -1
  45. package/dist/cjs/arch/svm/utils.js +355 -166
  46. package/dist/cjs/arch/svm/utils.js.map +1 -1
  47. package/dist/cjs/caching/Arweave/ArweaveClient.js +246 -168
  48. package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
  49. package/dist/cjs/caching/Arweave/index.js +1 -1
  50. package/dist/cjs/caching/IPFS/PinataIPFSClient.js +49 -40
  51. package/dist/cjs/caching/IPFS/PinataIPFSClient.js.map +1 -1
  52. package/dist/cjs/caching/IPFS/index.js +1 -1
  53. package/dist/cjs/caching/Memory/MemoryCacheClient.js +18 -13
  54. package/dist/cjs/caching/Memory/MemoryCacheClient.js.map +1 -1
  55. package/dist/cjs/caching/Memory/index.js +1 -1
  56. package/dist/cjs/caching/index.js +1 -1
  57. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +381 -302
  58. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  59. package/dist/cjs/clients/AcrossConfigStoreClient/index.js +1 -1
  60. package/dist/cjs/clients/BaseAbstractClient.js +83 -58
  61. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  62. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +900 -709
  63. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  64. package/dist/cjs/clients/BundleDataClient/index.js +1 -1
  65. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +128 -95
  66. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  67. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +53 -48
  68. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  69. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +8 -10
  70. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  71. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +90 -67
  72. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  73. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +24 -46
  74. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  75. package/dist/cjs/clients/BundleDataClient/utils/index.js +1 -1
  76. package/dist/cjs/clients/HubPoolClient.js +708 -526
  77. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  78. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +179 -133
  79. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  80. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -124
  81. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  82. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +389 -357
  83. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  84. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +8 -9
  85. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  86. package/dist/cjs/clients/SpokePoolClient/index.js +3 -3
  87. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  88. package/dist/cjs/clients/index.js +1 -1
  89. package/dist/cjs/clients/mocks/MockConfigStoreClient.js +67 -58
  90. package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
  91. package/dist/cjs/clients/mocks/MockEvents.js +52 -47
  92. package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
  93. package/dist/cjs/clients/mocks/MockHubPoolClient.js +185 -142
  94. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  95. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +192 -208
  96. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  97. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +143 -140
  98. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  99. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +73 -57
  100. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  101. package/dist/cjs/clients/mocks/index.js +1 -1
  102. package/dist/cjs/coingecko/Coingecko.js +437 -285
  103. package/dist/cjs/coingecko/Coingecko.js.map +1 -1
  104. package/dist/cjs/coingecko/index.js +1 -1
  105. package/dist/cjs/constants.js +30 -23
  106. package/dist/cjs/constants.js.map +1 -1
  107. package/dist/cjs/contracts/acrossConfigStore.js +48 -27
  108. package/dist/cjs/contracts/acrossConfigStore.js.map +1 -1
  109. package/dist/cjs/contracts/hubPool.js +20 -36
  110. package/dist/cjs/contracts/hubPool.js.map +1 -1
  111. package/dist/cjs/contracts/index.js +1 -1
  112. package/dist/cjs/contracts/utils.js +8 -6
  113. package/dist/cjs/contracts/utils.js.map +1 -1
  114. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +16 -7
  115. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  116. package/dist/cjs/gasPriceOracle/adapters/ethereum.js +45 -26
  117. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  118. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +28 -16
  119. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  120. package/dist/cjs/gasPriceOracle/adapters/polygon.js +112 -73
  121. package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
  122. package/dist/cjs/gasPriceOracle/adapters/solana.js +33 -20
  123. package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -1
  124. package/dist/cjs/gasPriceOracle/oracle.js +104 -77
  125. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  126. package/dist/cjs/gasPriceOracle/types.js +3 -3
  127. package/dist/cjs/gasPriceOracle/types.js.map +1 -1
  128. package/dist/cjs/gasPriceOracle/util.js +8 -8
  129. package/dist/cjs/gasPriceOracle/util.js.map +1 -1
  130. package/dist/cjs/index.js +1 -1
  131. package/dist/cjs/interfaces/index.js +1 -1
  132. package/dist/cjs/lpFeeCalculator/index.js +1 -1
  133. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js +35 -33
  134. package/dist/cjs/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  135. package/dist/cjs/lpFeeCalculator/rateModel.js +9 -7
  136. package/dist/cjs/lpFeeCalculator/rateModel.js.map +1 -1
  137. package/dist/cjs/merkleDistributor/MerkleDistributor.js +18 -20
  138. package/dist/cjs/merkleDistributor/MerkleDistributor.js.map +1 -1
  139. package/dist/cjs/merkleDistributor/index.js +1 -1
  140. package/dist/cjs/merkleDistributor/model/index.js +1 -1
  141. package/dist/cjs/pool/TransactionManager.js +100 -45
  142. package/dist/cjs/pool/TransactionManager.js.map +1 -1
  143. package/dist/cjs/pool/index.js +1 -1
  144. package/dist/cjs/pool/poolClient.js +731 -464
  145. package/dist/cjs/pool/poolClient.js.map +1 -1
  146. package/dist/cjs/pool/uma/across/index.js +1 -1
  147. package/dist/cjs/pool/uma/across/transactionManager.js +100 -45
  148. package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -1
  149. package/dist/cjs/pool/uma/clients/erc20/client.js +16 -18
  150. package/dist/cjs/pool/uma/clients/erc20/client.js.map +1 -1
  151. package/dist/cjs/pool/uma/clients/erc20/index.js +1 -1
  152. package/dist/cjs/pool/uma/clients/index.js +1 -1
  153. package/dist/cjs/pool/uma/index.js +1 -1
  154. package/dist/cjs/pool/uma/oracle/index.js +1 -1
  155. package/dist/cjs/pool/uma/oracle/utils.js +5 -4
  156. package/dist/cjs/pool/uma/oracle/utils.js.map +1 -1
  157. package/dist/cjs/pool/uma/utils.js +30 -11
  158. package/dist/cjs/pool/uma/utils.js.map +1 -1
  159. package/dist/cjs/priceClient/adapters/acrossApi.js +39 -22
  160. package/dist/cjs/priceClient/adapters/acrossApi.js.map +1 -1
  161. package/dist/cjs/priceClient/adapters/baseAdapter.js +73 -49
  162. package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
  163. package/dist/cjs/priceClient/adapters/coingecko.js +61 -34
  164. package/dist/cjs/priceClient/adapters/coingecko.js.map +1 -1
  165. package/dist/cjs/priceClient/adapters/default.js +31 -16
  166. package/dist/cjs/priceClient/adapters/default.js.map +1 -1
  167. package/dist/cjs/priceClient/adapters/defiLlama.js +74 -40
  168. package/dist/cjs/priceClient/adapters/defiLlama.js.map +1 -1
  169. package/dist/cjs/priceClient/adapters/index.js +1 -1
  170. package/dist/cjs/priceClient/index.js +1 -1
  171. package/dist/cjs/priceClient/priceClient.js +159 -110
  172. package/dist/cjs/priceClient/priceClient.js.map +1 -1
  173. package/dist/cjs/providers/alchemy.js +19 -17
  174. package/dist/cjs/providers/alchemy.js.map +1 -1
  175. package/dist/cjs/providers/cachedProvider.js +129 -88
  176. package/dist/cjs/providers/cachedProvider.js.map +1 -1
  177. package/dist/cjs/providers/drpc.js +11 -9
  178. package/dist/cjs/providers/drpc.js.map +1 -1
  179. package/dist/cjs/providers/index.js +1 -1
  180. package/dist/cjs/providers/infura.js +12 -10
  181. package/dist/cjs/providers/infura.js.map +1 -1
  182. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +15 -7
  183. package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  184. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -6
  185. package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  186. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js +15 -7
  187. package/dist/cjs/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  188. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +66 -42
  189. package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  190. package/dist/cjs/providers/mocks/index.js +1 -1
  191. package/dist/cjs/providers/mocks/mockEthersProvider.js +31 -29
  192. package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -1
  193. package/dist/cjs/providers/quicknode.js +21 -19
  194. package/dist/cjs/providers/quicknode.js.map +1 -1
  195. package/dist/cjs/providers/rateLimitedProvider.js +79 -64
  196. package/dist/cjs/providers/rateLimitedProvider.js.map +1 -1
  197. package/dist/cjs/providers/retryProvider.js +246 -163
  198. package/dist/cjs/providers/retryProvider.js.map +1 -1
  199. package/dist/cjs/providers/solana/baseRpcFactories.js +18 -14
  200. package/dist/cjs/providers/solana/baseRpcFactories.js.map +1 -1
  201. package/dist/cjs/providers/solana/cachedRpcFactory.js +112 -70
  202. package/dist/cjs/providers/solana/cachedRpcFactory.js.map +1 -1
  203. package/dist/cjs/providers/solana/defaultRpcFactory.js +15 -8
  204. package/dist/cjs/providers/solana/defaultRpcFactory.js.map +1 -1
  205. package/dist/cjs/providers/solana/index.js +1 -1
  206. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js +191 -135
  207. package/dist/cjs/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  208. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js +90 -67
  209. package/dist/cjs/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  210. package/dist/cjs/providers/solana/retryRpcFactory.js +79 -52
  211. package/dist/cjs/providers/solana/retryRpcFactory.js.map +1 -1
  212. package/dist/cjs/providers/solana/utils.js +2 -2
  213. package/dist/cjs/providers/solana/utils.js.map +1 -1
  214. package/dist/cjs/providers/speedProvider.js +53 -31
  215. package/dist/cjs/providers/speedProvider.js.map +1 -1
  216. package/dist/cjs/providers/types.js +1 -1
  217. package/dist/cjs/providers/types.js.map +1 -1
  218. package/dist/cjs/providers/utils.js +28 -26
  219. package/dist/cjs/providers/utils.js.map +1 -1
  220. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +162 -108
  221. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  222. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js +26 -14
  223. package/dist/cjs/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  224. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +29 -20
  225. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  226. package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -1
  227. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +137 -88
  228. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  229. package/dist/cjs/relayFeeCalculator/index.js +1 -1
  230. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +297 -199
  231. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  232. package/dist/cjs/typeguards/error.js +7 -5
  233. package/dist/cjs/typeguards/error.js.map +1 -1
  234. package/dist/cjs/typeguards/index.js +1 -1
  235. package/dist/cjs/utils/AddressUtils.js +144 -117
  236. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  237. package/dist/cjs/utils/ArrayUtils.js +78 -21
  238. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  239. package/dist/cjs/utils/BigNumberUtils.js +10 -9
  240. package/dist/cjs/utils/BigNumberUtils.js.map +1 -1
  241. package/dist/cjs/utils/BlockExplorerUtils.js +30 -26
  242. package/dist/cjs/utils/BlockExplorerUtils.js.map +1 -1
  243. package/dist/cjs/utils/BlockFinder.js +5 -2
  244. package/dist/cjs/utils/BlockFinder.js.map +1 -1
  245. package/dist/cjs/utils/BlockUtils.js +41 -24
  246. package/dist/cjs/utils/BlockUtils.js.map +1 -1
  247. package/dist/cjs/utils/BundleUtils.js +24 -21
  248. package/dist/cjs/utils/BundleUtils.js.map +1 -1
  249. package/dist/cjs/utils/CCTPUtils.js +126 -62
  250. package/dist/cjs/utils/CCTPUtils.js.map +1 -1
  251. package/dist/cjs/utils/CachingUtils.js +42 -20
  252. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  253. package/dist/cjs/utils/ContractUtils.js +5 -5
  254. package/dist/cjs/utils/ContractUtils.js.map +1 -1
  255. package/dist/cjs/utils/DepositUtils.js +99 -122
  256. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  257. package/dist/cjs/utils/EventUtils.js +70 -49
  258. package/dist/cjs/utils/EventUtils.js.map +1 -1
  259. package/dist/cjs/utils/FormattingUtils.js +32 -26
  260. package/dist/cjs/utils/FormattingUtils.js.map +1 -1
  261. package/dist/cjs/utils/HyperLiquidUtils.js +23 -10
  262. package/dist/cjs/utils/HyperLiquidUtils.js.map +1 -1
  263. package/dist/cjs/utils/IPFSUtils.js +34 -16
  264. package/dist/cjs/utils/IPFSUtils.js.map +1 -1
  265. package/dist/cjs/utils/JSONUtils.js +6 -6
  266. package/dist/cjs/utils/JSONUtils.js.map +1 -1
  267. package/dist/cjs/utils/LogUtils.js +12 -10
  268. package/dist/cjs/utils/LogUtils.js.map +1 -1
  269. package/dist/cjs/utils/Multicall.js +115 -56
  270. package/dist/cjs/utils/Multicall.js.map +1 -1
  271. package/dist/cjs/utils/NetworkUtils.js +28 -12
  272. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  273. package/dist/cjs/utils/NumberUtils.js +3 -1
  274. package/dist/cjs/utils/NumberUtils.js.map +1 -1
  275. package/dist/cjs/utils/ObjectUtils.js +41 -27
  276. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  277. package/dist/cjs/utils/Profiler.js +83 -80
  278. package/dist/cjs/utils/Profiler.js.map +1 -1
  279. package/dist/cjs/utils/ReviverUtils.js +9 -5
  280. package/dist/cjs/utils/ReviverUtils.js.map +1 -1
  281. package/dist/cjs/utils/SpokeUtils.js +84 -84
  282. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  283. package/dist/cjs/utils/TokenUtils.js +64 -41
  284. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  285. package/dist/cjs/utils/TypeGuards.js +1 -1
  286. package/dist/cjs/utils/TypeGuards.js.map +1 -1
  287. package/dist/cjs/utils/ValidatorUtils.js +7 -7
  288. package/dist/cjs/utils/ValidatorUtils.js.map +1 -1
  289. package/dist/cjs/utils/abi/contracts/index.js +1 -1
  290. package/dist/cjs/utils/abi/index.js +22 -12
  291. package/dist/cjs/utils/abi/index.js.map +1 -1
  292. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js +12 -9
  293. package/dist/cjs/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  294. package/dist/cjs/utils/abi/typechain/index.js +1 -1
  295. package/dist/cjs/utils/common.js +53 -40
  296. package/dist/cjs/utils/common.js.map +1 -1
  297. package/dist/cjs/utils/index.js +1 -1
  298. package/dist/esm/addressAggregator/adapters/abstract.js +64 -48
  299. package/dist/esm/addressAggregator/adapters/abstract.js.map +1 -1
  300. package/dist/esm/addressAggregator/adapters/bybit.js +29 -15
  301. package/dist/esm/addressAggregator/adapters/bybit.js.map +1 -1
  302. package/dist/esm/addressAggregator/adapters/env.js +14 -9
  303. package/dist/esm/addressAggregator/adapters/env.js.map +1 -1
  304. package/dist/esm/addressAggregator/adapters/file.js +43 -29
  305. package/dist/esm/addressAggregator/adapters/file.js.map +1 -1
  306. package/dist/esm/addressAggregator/adapters/risklabs.js +35 -20
  307. package/dist/esm/addressAggregator/adapters/risklabs.js.map +1 -1
  308. package/dist/esm/addressAggregator/index.js +83 -52
  309. package/dist/esm/addressAggregator/index.js.map +1 -1
  310. package/dist/esm/addressAggregator/types.js +1 -1
  311. package/dist/esm/addressAggregator/types.js.map +1 -1
  312. package/dist/esm/apiClient/abstractClient.js +9 -15
  313. package/dist/esm/apiClient/abstractClient.js.map +1 -1
  314. package/dist/esm/apiClient/mockedClient.js +26 -21
  315. package/dist/esm/apiClient/mockedClient.js.map +1 -1
  316. package/dist/esm/apiClient/productionClient.js +101 -61
  317. package/dist/esm/apiClient/productionClient.js.map +1 -1
  318. package/dist/esm/arch/evm/BlockUtils.js +217 -139
  319. package/dist/esm/arch/evm/BlockUtils.js.map +1 -1
  320. package/dist/esm/arch/evm/SpokeUtils.js +289 -146
  321. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  322. package/dist/esm/arch/evm/utils/wait.js +46 -34
  323. package/dist/esm/arch/evm/utils/wait.js.map +1 -1
  324. package/dist/esm/arch/svm/BlockUtils.js +166 -118
  325. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  326. package/dist/esm/arch/svm/SpokeUtils.js +1150 -738
  327. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  328. package/dist/esm/arch/svm/constants.js +1 -1
  329. package/dist/esm/arch/svm/constants.js.map +1 -1
  330. package/dist/esm/arch/svm/eventsClient.js +232 -172
  331. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  332. package/dist/esm/arch/svm/provider.js +1 -1
  333. package/dist/esm/arch/svm/provider.js.map +1 -1
  334. package/dist/esm/arch/svm/utils.js +345 -155
  335. package/dist/esm/arch/svm/utils.js.map +1 -1
  336. package/dist/esm/caching/Arweave/ArweaveClient.js +256 -182
  337. package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
  338. package/dist/esm/caching/IPFS/PinataIPFSClient.js +48 -47
  339. package/dist/esm/caching/IPFS/PinataIPFSClient.js.map +1 -1
  340. package/dist/esm/caching/Memory/MemoryCacheClient.js +19 -13
  341. package/dist/esm/caching/Memory/MemoryCacheClient.js.map +1 -1
  342. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +408 -333
  343. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  344. package/dist/esm/clients/BaseAbstractClient.js +92 -66
  345. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  346. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +1054 -927
  347. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  348. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +131 -102
  349. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  350. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +59 -57
  351. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  352. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -7
  353. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  354. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +94 -75
  355. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  356. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +23 -45
  357. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  358. package/dist/esm/clients/HubPoolClient.js +740 -581
  359. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  360. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +178 -133
  361. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  362. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +183 -126
  363. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  364. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +399 -372
  365. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  366. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js +9 -9
  367. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -1
  368. package/dist/esm/clients/SpokePoolClient/index.js +2 -2
  369. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  370. package/dist/esm/clients/SpokePoolClient/types.js +2 -2
  371. package/dist/esm/clients/SpokePoolClient/types.js.map +1 -1
  372. package/dist/esm/clients/mocks/MockConfigStoreClient.js +64 -53
  373. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  374. package/dist/esm/clients/mocks/MockEvents.js +49 -42
  375. package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
  376. package/dist/esm/clients/mocks/MockHubPoolClient.js +182 -138
  377. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  378. package/dist/esm/clients/mocks/MockSpokePoolClient.js +188 -202
  379. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  380. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +132 -127
  381. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  382. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +69 -53
  383. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  384. package/dist/esm/coingecko/Coingecko.js +443 -298
  385. package/dist/esm/coingecko/Coingecko.js.map +1 -1
  386. package/dist/esm/constants.js +47 -40
  387. package/dist/esm/constants.js.map +1 -1
  388. package/dist/esm/contracts/acrossConfigStore.js +46 -24
  389. package/dist/esm/contracts/acrossConfigStore.js.map +1 -1
  390. package/dist/esm/contracts/hubPool.js +18 -34
  391. package/dist/esm/contracts/hubPool.js.map +1 -1
  392. package/dist/esm/contracts/utils.js +5 -3
  393. package/dist/esm/contracts/utils.js.map +1 -1
  394. package/dist/esm/gasPriceOracle/adapters/arbitrum.js +14 -6
  395. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  396. package/dist/esm/gasPriceOracle/adapters/ethereum.js +42 -22
  397. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  398. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +25 -13
  399. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  400. package/dist/esm/gasPriceOracle/adapters/polygon.js +108 -72
  401. package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
  402. package/dist/esm/gasPriceOracle/adapters/solana.js +31 -22
  403. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -1
  404. package/dist/esm/gasPriceOracle/oracle.js +96 -70
  405. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  406. package/dist/esm/gasPriceOracle/types.js +2 -2
  407. package/dist/esm/gasPriceOracle/types.js.map +1 -1
  408. package/dist/esm/gasPriceOracle/util.js +4 -4
  409. package/dist/esm/gasPriceOracle/util.js.map +1 -1
  410. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js +33 -30
  411. package/dist/esm/lpFeeCalculator/lpFeeCalculator.js.map +1 -1
  412. package/dist/esm/lpFeeCalculator/rateModel.js +9 -7
  413. package/dist/esm/lpFeeCalculator/rateModel.js.map +1 -1
  414. package/dist/esm/merkleDistributor/MerkleDistributor.js +17 -18
  415. package/dist/esm/merkleDistributor/MerkleDistributor.js.map +1 -1
  416. package/dist/esm/pool/TransactionManager.js +100 -45
  417. package/dist/esm/pool/TransactionManager.js.map +1 -1
  418. package/dist/esm/pool/poolClient.js +740 -479
  419. package/dist/esm/pool/poolClient.js.map +1 -1
  420. package/dist/esm/pool/uma/across/constants.js +2 -2
  421. package/dist/esm/pool/uma/across/constants.js.map +1 -1
  422. package/dist/esm/pool/uma/across/transactionManager.js +100 -45
  423. package/dist/esm/pool/uma/across/transactionManager.js.map +1 -1
  424. package/dist/esm/pool/uma/clients/erc20/client.js +13 -15
  425. package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -1
  426. package/dist/esm/pool/uma/oracle/utils.js +3 -2
  427. package/dist/esm/pool/uma/oracle/utils.js.map +1 -1
  428. package/dist/esm/pool/uma/utils.js +28 -9
  429. package/dist/esm/pool/uma/utils.js.map +1 -1
  430. package/dist/esm/priceClient/adapters/acrossApi.js +40 -21
  431. package/dist/esm/priceClient/adapters/acrossApi.js.map +1 -1
  432. package/dist/esm/priceClient/adapters/baseAdapter.js +72 -46
  433. package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
  434. package/dist/esm/priceClient/adapters/coingecko.js +61 -33
  435. package/dist/esm/priceClient/adapters/coingecko.js.map +1 -1
  436. package/dist/esm/priceClient/adapters/default.js +31 -15
  437. package/dist/esm/priceClient/adapters/default.js.map +1 -1
  438. package/dist/esm/priceClient/adapters/defiLlama.js +73 -38
  439. package/dist/esm/priceClient/adapters/defiLlama.js.map +1 -1
  440. package/dist/esm/priceClient/priceClient.js +158 -109
  441. package/dist/esm/priceClient/priceClient.js.map +1 -1
  442. package/dist/esm/providers/alchemy.js +18 -16
  443. package/dist/esm/providers/alchemy.js.map +1 -1
  444. package/dist/esm/providers/cachedProvider.js +134 -99
  445. package/dist/esm/providers/cachedProvider.js.map +1 -1
  446. package/dist/esm/providers/constants.js +3 -3
  447. package/dist/esm/providers/constants.js.map +1 -1
  448. package/dist/esm/providers/drpc.js +10 -8
  449. package/dist/esm/providers/drpc.js.map +1 -1
  450. package/dist/esm/providers/infura.js +11 -9
  451. package/dist/esm/providers/infura.js.map +1 -1
  452. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +15 -6
  453. package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -1
  454. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +14 -5
  455. package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -1
  456. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js +15 -6
  457. package/dist/esm/providers/mocks/MockRetrySolanaRpcFactory.js.map +1 -1
  458. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +66 -41
  459. package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -1
  460. package/dist/esm/providers/mocks/mockEthersProvider.js +30 -27
  461. package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -1
  462. package/dist/esm/providers/quicknode.js +20 -18
  463. package/dist/esm/providers/quicknode.js.map +1 -1
  464. package/dist/esm/providers/rateLimitedProvider.js +80 -68
  465. package/dist/esm/providers/rateLimitedProvider.js.map +1 -1
  466. package/dist/esm/providers/retryProvider.js +259 -186
  467. package/dist/esm/providers/retryProvider.js.map +1 -1
  468. package/dist/esm/providers/solana/baseRpcFactories.js +19 -13
  469. package/dist/esm/providers/solana/baseRpcFactories.js.map +1 -1
  470. package/dist/esm/providers/solana/cachedRpcFactory.js +112 -75
  471. package/dist/esm/providers/solana/cachedRpcFactory.js.map +1 -1
  472. package/dist/esm/providers/solana/defaultRpcFactory.js +14 -6
  473. package/dist/esm/providers/solana/defaultRpcFactory.js.map +1 -1
  474. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js +202 -149
  475. package/dist/esm/providers/solana/quorumFallbackRpcFactory.js.map +1 -1
  476. package/dist/esm/providers/solana/rateLimitedRpcFactory.js +90 -70
  477. package/dist/esm/providers/solana/rateLimitedRpcFactory.js.map +1 -1
  478. package/dist/esm/providers/solana/retryRpcFactory.js +74 -50
  479. package/dist/esm/providers/solana/retryRpcFactory.js.map +1 -1
  480. package/dist/esm/providers/solana/utils.js +1 -1
  481. package/dist/esm/providers/solana/utils.js.map +1 -1
  482. package/dist/esm/providers/speedProvider.js +51 -28
  483. package/dist/esm/providers/speedProvider.js.map +1 -1
  484. package/dist/esm/providers/types.js +2 -2
  485. package/dist/esm/providers/types.js.map +1 -1
  486. package/dist/esm/providers/utils.js +20 -17
  487. package/dist/esm/providers/utils.js.map +1 -1
  488. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +152 -98
  489. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  490. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js +26 -13
  491. package/dist/esm/relayFeeCalculator/chain-queries/customGasToken.js.map +1 -1
  492. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +19 -9
  493. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  494. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +128 -83
  495. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  496. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +299 -211
  497. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  498. package/dist/esm/typeguards/error.js +5 -3
  499. package/dist/esm/typeguards/error.js.map +1 -1
  500. package/dist/esm/utils/AddressUtils.js +147 -115
  501. package/dist/esm/utils/AddressUtils.js.map +1 -1
  502. package/dist/esm/utils/ArrayUtils.js +78 -21
  503. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  504. package/dist/esm/utils/BigNumberUtils.js +12 -11
  505. package/dist/esm/utils/BigNumberUtils.js.map +1 -1
  506. package/dist/esm/utils/BlockExplorerUtils.js +23 -19
  507. package/dist/esm/utils/BlockExplorerUtils.js.map +1 -1
  508. package/dist/esm/utils/BlockFinder.js +6 -2
  509. package/dist/esm/utils/BlockFinder.js.map +1 -1
  510. package/dist/esm/utils/BlockUtils.js +40 -31
  511. package/dist/esm/utils/BlockUtils.js.map +1 -1
  512. package/dist/esm/utils/BundleUtils.js +24 -21
  513. package/dist/esm/utils/BundleUtils.js.map +1 -1
  514. package/dist/esm/utils/CCTPUtils.js +123 -62
  515. package/dist/esm/utils/CCTPUtils.js.map +1 -1
  516. package/dist/esm/utils/CachingUtils.js +38 -17
  517. package/dist/esm/utils/CachingUtils.js.map +1 -1
  518. package/dist/esm/utils/ContractUtils.js +3 -3
  519. package/dist/esm/utils/ContractUtils.js.map +1 -1
  520. package/dist/esm/utils/DepositUtils.js +98 -121
  521. package/dist/esm/utils/DepositUtils.js.map +1 -1
  522. package/dist/esm/utils/EventUtils.js +69 -52
  523. package/dist/esm/utils/EventUtils.js.map +1 -1
  524. package/dist/esm/utils/FormattingUtils.js +26 -20
  525. package/dist/esm/utils/FormattingUtils.js.map +1 -1
  526. package/dist/esm/utils/HyperLiquidUtils.js +22 -8
  527. package/dist/esm/utils/HyperLiquidUtils.js.map +1 -1
  528. package/dist/esm/utils/IPFSUtils.js +35 -16
  529. package/dist/esm/utils/IPFSUtils.js.map +1 -1
  530. package/dist/esm/utils/JSONUtils.js +4 -4
  531. package/dist/esm/utils/JSONUtils.js.map +1 -1
  532. package/dist/esm/utils/LogUtils.js +12 -8
  533. package/dist/esm/utils/LogUtils.js.map +1 -1
  534. package/dist/esm/utils/Multicall.js +110 -50
  535. package/dist/esm/utils/Multicall.js.map +1 -1
  536. package/dist/esm/utils/NetworkUtils.js +28 -12
  537. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  538. package/dist/esm/utils/NumberUtils.js +3 -1
  539. package/dist/esm/utils/NumberUtils.js.map +1 -1
  540. package/dist/esm/utils/ObjectUtils.js +41 -27
  541. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  542. package/dist/esm/utils/Profiler.js +82 -77
  543. package/dist/esm/utils/Profiler.js.map +1 -1
  544. package/dist/esm/utils/ReviverUtils.js +7 -3
  545. package/dist/esm/utils/ReviverUtils.js.map +1 -1
  546. package/dist/esm/utils/SpokeUtils.js +78 -83
  547. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  548. package/dist/esm/utils/TokenUtils.js +57 -33
  549. package/dist/esm/utils/TokenUtils.js.map +1 -1
  550. package/dist/esm/utils/ValidatorUtils.js +4 -4
  551. package/dist/esm/utils/ValidatorUtils.js.map +1 -1
  552. package/dist/esm/utils/abi/index.js +20 -10
  553. package/dist/esm/utils/abi/index.js.map +1 -1
  554. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js +12 -8
  555. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  556. package/dist/esm/utils/common.js +52 -38
  557. package/dist/esm/utils/common.js.map +1 -1
  558. package/dist/types/constants.d.ts.map +1 -1
  559. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  560. package/dist/types/utils/Multicall.d.ts.map +1 -1
  561. package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
  562. package/package.json +3 -3
  563. package/src/constants.ts +1 -0
  564. package/src/gasPriceOracle/oracle.ts +1 -0
  565. package/src/utils/Multicall.ts +1 -0
  566. package/src/utils/NetworkUtils.ts +8 -1
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __generator, __spreadArray } from "tslib";
1
2
  import assert from "assert";
2
3
  import * as uma from "./uma";
3
4
  import { bnZero, toBNWei, fixedPointAdjustment, calcPeriodicCompoundInterest, calcApr, BigNumber, fromWei, } from "../utils";
@@ -8,203 +9,247 @@ import has from "lodash/has";
8
9
  import { calculateInstantaneousRate } from "../lpFeeCalculator";
9
10
  import { hubPool, acrossConfigStore } from "../contracts";
10
11
  import { AcceleratingDistributor__factory, MerkleDistributor__factory, } from "../typechain";
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) {
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) {
20
19
  this.contract = contract;
21
20
  this.address = address;
22
21
  }
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) {
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;
52
53
  this.contract = contract;
53
54
  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
+ };
54
79
  this.iface = new ethers.utils.Interface(hubPool.Factory.abi);
55
80
  }
56
- makeId = (params) => {
57
- return uma.oracle.utils.eventKey(params);
58
- };
59
- hasEvent(params) {
81
+ PoolEventState.prototype.hasEvent = function (params) {
60
82
  return this.seen.has(this.makeId(params));
61
- }
62
- addEvent(params) {
83
+ };
84
+ PoolEventState.prototype.addEvent = function (params) {
63
85
  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
- };
95
86
  };
96
- getL1TokenFromReceipt(receipt) {
97
- const events = receipt.logs
98
- .filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
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); })
99
112
  .map(this.makeEventFromLog);
100
113
  // save these events
101
114
  this.processEvents(events);
102
115
  // only process token receipt events, because we just want the l1 token involved with this transfer
103
- const eventState = hubPool.getEventState(events);
116
+ var eventState = hubPool.getEventState(events);
104
117
  // event state is keyed by l1token address
105
- const l1Tokens = Object.keys(eventState);
118
+ var l1Tokens = Object.keys(eventState);
106
119
  assert(l1Tokens.length, "Token not found from events");
107
120
  assert(l1Tokens.length === 1, "Multiple tokens found from events");
108
121
  return l1Tokens[0];
109
- }
110
- readTxReceipt(receipt) {
111
- const events = receipt.logs
112
- .filter((log) => ethers.utils.getAddress(log.address) === ethers.utils.getAddress(this.contract.address))
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); })
113
127
  .map(this.makeEventFromLog);
114
128
  this.processEvents(events);
115
129
  return hubPool.getEventState(this.events);
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 = "") {
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;
126
139
  this.contract = contract;
127
140
  this.userAddress = userAddress;
128
141
  this.startBlock = startBlock;
129
142
  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
+ };
130
151
  }
131
- makeId(params) {
152
+ UserState.prototype.makeId = function (params) {
132
153
  return uma.oracle.utils.eventKey(params);
133
- }
134
- hasEvent(params) {
154
+ };
155
+ UserState.prototype.hasEvent = function (params) {
135
156
  return this.seen.has(this.makeId(params));
136
- }
137
- addEvent(params) {
157
+ };
158
+ UserState.prototype.addEvent = function (params) {
138
159
  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;
145
160
  };
146
161
  /**
147
162
  * readEvents. Fetch and cache events for the user.
148
163
  *
149
164
  * @param {number} endBlock
150
165
  */
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);
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
+ });
182
215
  });
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
- }
216
+ };
187
217
  /**
188
218
  * read. Reads the state for the user, building state from events as well as contract calls.
189
219
  *
190
220
  * @param {number} endBlock
191
221
  */
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
- }
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
+ }());
205
250
  export function calculateRemoval(amountWei, percentWei) {
206
- const receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
207
- const remain = amountWei.sub(receive);
251
+ var receive = amountWei.mul(percentWei).div(fixedPointAdjustment);
252
+ var remain = amountWei.sub(receive);
208
253
  return {
209
254
  receive: receive.toString(),
210
255
  remain: remain.toString(),
@@ -212,25 +257,22 @@ export function calculateRemoval(amountWei, percentWei) {
212
257
  }
213
258
  // params here mimic the user object type
214
259
  export function previewRemoval(values, percentFloat) {
215
- const percentWei = toBNWei(percentFloat);
260
+ var percentWei = toBNWei(percentFloat);
216
261
  return {
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
- },
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)),
226
265
  };
227
266
  }
228
- function joinUserState(poolState, tokenEventState, userState, transferValue = bnZero, cumulativeStakeBalance = bnZero, cumulativeStakeClaimBalance = bnZero) {
229
- const positionValue = BigNumber.from(poolState.exchangeRateCurrent)
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)
230
272
  .mul(userState.balanceOf.add(cumulativeStakeBalance))
231
273
  .div(fixedPointAdjustment);
232
- const totalDeposited = BigNumber.from(tokenEventState?.tokenBalances[userState.address] || "0").add(cumulativeStakeClaimBalance);
233
- const feesEarned = positionValue.sub(totalDeposited.add(transferValue));
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));
234
276
  return {
235
277
  address: userState.address,
236
278
  poolAddress: poolState.address,
@@ -241,15 +283,15 @@ function joinUserState(poolState, tokenEventState, userState, transferValue = bn
241
283
  };
242
284
  }
243
285
  function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
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 = "";
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 = "";
253
295
  if (rateModel) {
254
296
  projectedApr = fromWei(calculateInstantaneousRate(rateModel, liquidityUtilizationCurrent)
255
297
  .mul(liquidityUtilizationCurrent)
@@ -263,55 +305,45 @@ function joinPoolState(poolState, latestBlock, previousBlock, rateModel) {
263
305
  liquidReserves: poolState.liquidReserves.toString(),
264
306
  exchangeRateCurrent: poolState.exchangeRateCurrent.toString(),
265
307
  exchangeRatePrevious: poolState.exchangeRatePrevious.toString(),
266
- estimatedApy,
267
- estimatedApr,
268
- blocksElapsed,
269
- secondsElapsed,
270
- projectedApr,
308
+ estimatedApy: estimatedApy,
309
+ estimatedApr: estimatedApr,
310
+ blocksElapsed: blocksElapsed,
311
+ secondsElapsed: secondsElapsed,
312
+ projectedApr: projectedApr,
271
313
  utilizedReserves: poolState.utilizedReserves.toString(),
272
- liquidityUtilizationCurrent,
314
+ liquidityUtilizationCurrent: liquidityUtilizationCurrent,
273
315
  };
274
316
  }
275
- export class ReadPoolClient {
276
- address;
277
- provider;
278
- poolState;
279
- contract;
280
- constructor(address, provider) {
317
+ var ReadPoolClient = /** @class */ (function () {
318
+ function ReadPoolClient(address, provider) {
281
319
  this.address = address;
282
320
  this.provider = provider;
283
321
  this.contract = hubPool.connect(address, this.provider);
284
322
  this.poolState = new PoolState(this.contract, this.address);
285
323
  }
286
- read(tokenAddress, latestBlock) {
324
+ ReadPoolClient.prototype.read = function (tokenAddress, latestBlock) {
287
325
  return this.poolState.read(tokenAddress, latestBlock);
288
- }
289
- }
326
+ };
327
+ return ReadPoolClient;
328
+ }());
329
+ export { ReadPoolClient };
290
330
  export function validateWithdraw(pool, user, lpTokenAmount) {
291
- const l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
331
+ var l1TokensToReturn = BigNumber.from(lpTokenAmount).mul(pool.exchangeRateCurrent).div(fixedPointAdjustment);
292
332
  assert(BigNumber.from(l1TokensToReturn).gt("0"), "Must withdraw amount greater than 0");
293
333
  assert(BigNumber.from(lpTokenAmount).lte(user.lpTokens), "You cannot withdraw more than you have");
294
- return { lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
334
+ return { lpTokenAmount: lpTokenAmount, l1TokensToReturn: l1TokensToReturn.toString() };
295
335
  }
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) {
336
+ var Client = /** @class */ (function () {
337
+ function Client(config, deps, emit) {
312
338
  this.config = config;
313
339
  this.deps = deps;
314
340
  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 = {};
315
347
  config.chainId = config.chainId || 1;
316
348
  this.hubPool = this.createHubPoolContract(deps.provider);
317
349
  this.acceleratingDistributor = this.createAcceleratingDistributorContract(deps.provider);
@@ -319,320 +351,549 @@ export class Client {
319
351
  this.poolEvents = new PoolEventState(this.hubPool, this.config.hubPoolStartBlock);
320
352
  this.configStoreClient = new acrossConfigStore.Client(config.configStoreAddress, deps.provider);
321
353
  }
322
- getOrCreateErc20Contract(address) {
354
+ Client.prototype.getOrCreateErc20Contract = function (address) {
323
355
  if (this.erc20s[address])
324
356
  return this.erc20s[address];
325
357
  this.erc20s[address] = erc20.connect(address, this.deps.provider);
326
358
  return this.erc20s[address];
327
- }
328
- getOrCreatePoolContract() {
359
+ };
360
+ Client.prototype.getOrCreatePoolContract = function () {
329
361
  return this.hubPool;
330
- }
331
- createHubPoolContract(signerOrProvider) {
362
+ };
363
+ Client.prototype.createHubPoolContract = function (signerOrProvider) {
332
364
  return hubPool.connect(this.config.hubPoolAddress, signerOrProvider);
333
- }
334
- getOrCreatePoolEvents() {
365
+ };
366
+ Client.prototype.getOrCreatePoolEvents = function () {
335
367
  return this.poolEvents;
336
- }
337
- createAcceleratingDistributorContract(signerOrProvider) {
368
+ };
369
+ Client.prototype.createAcceleratingDistributorContract = function (signerOrProvider) {
338
370
  return AcceleratingDistributor__factory.connect(this.config.acceleratingDistributorAddress, signerOrProvider);
339
- }
340
- createMerkleDistributorContract(signerOrProvider) {
371
+ };
372
+ Client.prototype.createMerkleDistributorContract = function (signerOrProvider) {
341
373
  return MerkleDistributor__factory.connect(this.config.merkleDistributorAddress, signerOrProvider);
342
- }
343
- getOrCreateAcceleratingDistributorContract() {
374
+ };
375
+ Client.prototype.getOrCreateAcceleratingDistributorContract = function () {
344
376
  return this.acceleratingDistributor;
345
- }
346
- getOrCreateMerkleDistributorContract() {
377
+ };
378
+ Client.prototype.getOrCreateMerkleDistributorContract = function () {
347
379
  return this.merkleDistributor;
348
- }
349
- getOrCreateUserService(userAddress, tokenAddress) {
380
+ };
381
+ Client.prototype.getOrCreateUserService = function (userAddress, tokenAddress) {
350
382
  if (has(this.userServices, [tokenAddress, userAddress]))
351
383
  return get(this.userServices, [tokenAddress, userAddress]);
352
- const erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
353
- const userService = new UserState(erc20Contract, userAddress);
384
+ var erc20Contract = this.getOrCreateErc20Contract(tokenAddress);
385
+ var userService = new UserState(erc20Contract, userAddress);
354
386
  // this service is stateful now, so needs to be cached
355
387
  set(this.userServices, [tokenAddress, userAddress], userService);
356
388
  return userService;
357
- }
358
- updateExchangeRateTable(l1TokenAddress, exchangeRateTable) {
389
+ };
390
+ Client.prototype.updateExchangeRateTable = function (l1TokenAddress, exchangeRateTable) {
359
391
  if (!this.exchangeRateTable[l1TokenAddress])
360
392
  this.exchangeRateTable[l1TokenAddress] = {};
361
- this.exchangeRateTable[l1TokenAddress] = { ...this.exchangeRateTable[l1TokenAddress], ...exchangeRateTable };
393
+ this.exchangeRateTable[l1TokenAddress] = __assign(__assign({}, this.exchangeRateTable[l1TokenAddress]), exchangeRateTable);
362
394
  return this.exchangeRateTable[l1TokenAddress];
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
- }
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
+ };
383
435
  // calculates the value of each LP token transfer at the block it was sent. this only works if we have archive node
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) {
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;
410
484
  if (this.transactionManagers[address])
411
485
  return this.transactionManagers[address];
412
- const txman = TransactionManager({ confirmations: this.config.confirmations }, signer, (event, id, data) => {
486
+ var txman = TransactionManager({ confirmations: this.config.confirmations }, signer, function (event, id, data) {
413
487
  if (event === "submitted") {
414
- this.state.transactions[id].state = event;
415
- this.state.transactions[id].hash = data;
416
- this.emit(["transactions", id], { ...this.state.transactions[id] });
488
+ _this.state.transactions[id].state = event;
489
+ _this.state.transactions[id].hash = data;
490
+ _this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
417
491
  }
418
492
  if (event === "mined") {
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] });
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]));
423
497
  // trigger pool and user update for a known mined transaction
424
- const tx = this.state.transactions[id];
425
- this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch((err) => {
426
- this.emit(["error"], err);
498
+ var tx = _this.state.transactions[id];
499
+ _this.updateUserWithTransaction(tx.fromAddress, txReceipt).catch(function (err) {
500
+ _this.emit(["error"], err);
427
501
  });
428
502
  }
429
503
  if (event === "error") {
430
- this.state.transactions[id].state = event;
431
- this.state.transactions[id].error = data;
432
- this.emit(["transactions", id], { ...this.state.transactions[id] });
504
+ _this.state.transactions[id].state = event;
505
+ _this.state.transactions[id].error = data;
506
+ _this.emit(["transactions", id], __assign({}, _this.state.transactions[id]));
433
507
  }
434
508
  });
435
509
  this.transactionManagers[address] = txman;
436
510
  return txman;
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,
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
+ });
447
545
  });
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) {
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
+ });
683
+ });
684
+ };
685
+ Client.prototype.getPoolState = function (l1TokenAddress) {
534
686
  return this.state.pools[l1TokenAddress];
535
- }
536
- hasPoolState(l1TokenAddress) {
687
+ };
688
+ Client.prototype.hasPoolState = function (l1TokenAddress) {
537
689
  return Boolean(this.state.pools[l1TokenAddress]);
538
- }
539
- setUserState(l1TokenAddress, userAddress, state) {
690
+ };
691
+ Client.prototype.setUserState = function (l1TokenAddress, userAddress, state) {
540
692
  set(this.state, ["users", userAddress, l1TokenAddress], state);
541
693
  return state;
542
- }
543
- getUserState(l1TokenAddress, userAddress) {
694
+ };
695
+ Client.prototype.getUserState = function (l1TokenAddress, userAddress) {
544
696
  return get(this.state, ["users", userAddress, l1TokenAddress]);
545
- }
546
- hasUserState(l1TokenAddress, userAddress) {
697
+ };
698
+ Client.prototype.hasUserState = function (l1TokenAddress, userAddress) {
547
699
  return has(this.state, ["users", userAddress, l1TokenAddress]);
548
- }
549
- hasTxState(id) {
700
+ };
701
+ Client.prototype.hasTxState = function (id) {
550
702
  return has(this.state, ["transactions", id]);
551
- }
552
- getTxState(id) {
703
+ };
704
+ Client.prototype.getTxState = function (id) {
553
705
  return get(this.state, ["transactions", id]);
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
- }
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
+ };
622
871
  // starts transaction checking intervals, defaults to 30 seconds
623
- startInterval(delayMs = 30000) {
872
+ Client.prototype.startInterval = function (delayMs) {
873
+ var _this = this;
874
+ if (delayMs === void 0) { delayMs = 30000; }
624
875
  assert(!this.intervalStarted, "Interval already started, try stopping first");
625
876
  this.intervalStarted = true;
626
- loop(async () => {
627
- assert(this.intervalStarted, "HubPool Interval Stopped");
628
- await this.updateTransactions();
629
- }, delayMs).catch((err) => {
630
- this.emit(["error"], err);
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);
631
890
  });
632
- }
891
+ };
633
892
  // starts transaction checking intervals
634
- stopInterval() {
893
+ Client.prototype.stopInterval = function () {
635
894
  this.intervalStarted = false;
636
- }
637
- }
895
+ };
896
+ return Client;
897
+ }());
898
+ export { Client };
638
899
  //# sourceMappingURL=poolClient.js.map