@gearbox-protocol/sdk 1.22.4 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/lib/apy/convexAPY.d.ts +10 -10
  2. package/lib/apy/convexAPY.js +100 -121
  3. package/lib/apy/curveAPY.d.ts +3 -4
  4. package/lib/apy/curveAPY.js +57 -111
  5. package/lib/apy/index.js +4 -6
  6. package/lib/apy/lidoAPY.d.ts +1 -2
  7. package/lib/apy/lidoAPY.js +14 -62
  8. package/lib/apy/yearnAPY.d.ts +2 -3
  9. package/lib/apy/yearnAPY.js +26 -82
  10. package/lib/contracts/contracts.js +9 -22
  11. package/lib/contracts/contractsRegister.js +39 -51
  12. package/lib/contracts/protocols.js +10 -11
  13. package/lib/core/adapter.js +9 -4
  14. package/lib/core/assets.d.ts +6 -7
  15. package/lib/core/assets.js +60 -70
  16. package/lib/core/chains.js +30 -80
  17. package/lib/core/constants.d.ts +9 -10
  18. package/lib/core/constants.js +9 -12
  19. package/lib/core/creditAccount.d.ts +20 -20
  20. package/lib/core/creditAccount.js +123 -134
  21. package/lib/core/creditAccount.spec.js +50 -52
  22. package/lib/core/creditManager.d.ts +26 -26
  23. package/lib/core/creditManager.js +172 -136
  24. package/lib/core/creditManager.spec.js +59 -61
  25. package/lib/core/creditSession.d.ts +12 -13
  26. package/lib/core/creditSession.js +120 -77
  27. package/lib/core/errors.d.ts +2 -3
  28. package/lib/core/errors.js +11 -27
  29. package/lib/core/eventOrTx.js +35 -73
  30. package/lib/core/events.d.ts +19 -20
  31. package/lib/core/events.js +698 -711
  32. package/lib/core/operations.js +11 -5
  33. package/lib/core/pool/data.d.ts +29 -29
  34. package/lib/core/pool/data.js +153 -112
  35. package/lib/core/pool/operation.d.ts +1 -2
  36. package/lib/core/pool/operation.js +23 -35
  37. package/lib/core/priceOracle.d.ts +6 -6
  38. package/lib/core/priceOracle.js +23 -29
  39. package/lib/core/rewardClaimer.d.ts +3 -3
  40. package/lib/core/rewardClaimer.js +5 -48
  41. package/lib/core/rewardConvex.d.ts +1 -1
  42. package/lib/core/rewardConvex.js +58 -118
  43. package/lib/core/rewardConvex.spec.js +56 -58
  44. package/lib/core/strategy.d.ts +5 -6
  45. package/lib/core/strategy.js +67 -69
  46. package/lib/core/strategy.spec.js +32 -34
  47. package/lib/core/tokenDistributor.d.ts +1 -2
  48. package/lib/core/trade.d.ts +6 -6
  49. package/lib/core/trade.js +70 -115
  50. package/lib/core/transactions.d.ts +21 -22
  51. package/lib/core/transactions.js +285 -308
  52. package/lib/index.d.ts +0 -2
  53. package/lib/index.js +0 -2
  54. package/lib/oracles/oracles.d.ts +1 -2
  55. package/lib/oracles/priceFeeds.js +2 -3
  56. package/lib/parsers/ERC20Parser.js +20 -38
  57. package/lib/parsers/abstractParser.js +33 -31
  58. package/lib/parsers/addressProviderParser.js +12 -30
  59. package/lib/parsers/airdropDistributorParser.js +12 -30
  60. package/lib/parsers/convexBaseRewardPoolAdapterParser.js +24 -42
  61. package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.js +11 -11
  62. package/lib/parsers/convexBoosterAdapterParser.js +26 -44
  63. package/lib/parsers/convexBoosterAdapterParser.spec.js +10 -10
  64. package/lib/parsers/convextRewardPoolParser.js +12 -30
  65. package/lib/parsers/creditFacadeParser.js +26 -45
  66. package/lib/parsers/creditFacadeParser.spec.js +13 -13
  67. package/lib/parsers/creditManagerParser.js +12 -30
  68. package/lib/parsers/curveAdapterParser.js +60 -78
  69. package/lib/parsers/curveAdapterParser.spec.js +20 -27
  70. package/lib/parsers/dataCompressorParser.js +12 -30
  71. package/lib/parsers/lidoAdapterParser.js +15 -33
  72. package/lib/parsers/lidoAdapterParser.spec.js +9 -9
  73. package/lib/parsers/lidoOracleParser.js +12 -30
  74. package/lib/parsers/lidoSTETHParser.js +19 -37
  75. package/lib/parsers/multicallParser.js +16 -34
  76. package/lib/parsers/offchainOracleParser.js +13 -31
  77. package/lib/parsers/poolParser.js +11 -29
  78. package/lib/parsers/priceOracleParser.js +13 -31
  79. package/lib/parsers/txParser.js +86 -96
  80. package/lib/parsers/uniV2AdapterParser.js +35 -55
  81. package/lib/parsers/uniV2AdapterParser.spec.js +15 -16
  82. package/lib/parsers/uniV3AdapterParser.js +56 -74
  83. package/lib/parsers/uniV3AdapterParser.spec.js +23 -24
  84. package/lib/parsers/wstETHAdapterParser.js +25 -43
  85. package/lib/parsers/wstETHAdapterParser.spec.js +11 -11
  86. package/lib/parsers/yearnAdapterParser.spec.js +17 -17
  87. package/lib/parsers/yearnV2AdapterParser.js +25 -43
  88. package/lib/pathfinder/core.d.ts +3 -4
  89. package/lib/pathfinder/pathOptions.js +52 -101
  90. package/lib/pathfinder/pathOptions.spec.js +55 -57
  91. package/lib/pathfinder/pathfinder.d.ts +3 -3
  92. package/lib/pathfinder/pathfinder.js +109 -202
  93. package/lib/pathfinder/pathfinder.spec.js +13 -13
  94. package/lib/strategies/convex.js +111 -123
  95. package/lib/strategies/creditFacade.js +34 -37
  96. package/lib/strategies/curve.js +74 -80
  97. package/lib/strategies/lido.js +26 -32
  98. package/lib/strategies/uniswapV2.js +21 -24
  99. package/lib/strategies/uniswapV3.js +33 -36
  100. package/lib/strategies/yearn.js +47 -59
  101. package/lib/tokens/balancer.js +3 -5
  102. package/lib/tokens/convex.js +14 -29
  103. package/lib/tokens/curveLP.js +22 -28
  104. package/lib/tokens/gear.js +1 -1
  105. package/lib/tokens/normal.js +3 -5
  106. package/lib/tokens/token.js +29 -35
  107. package/lib/tokens/tokenData.d.ts +0 -9
  108. package/lib/tokens/tokenData.js +17 -15
  109. package/lib/tokens/yearn.js +3 -5
  110. package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface__factory.js +9 -12
  111. package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface__factory.js +9 -12
  112. package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface__factory.js +9 -12
  113. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACLEvents__factory.js +9 -12
  114. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACLExceptions__factory.js +9 -12
  115. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACL__factory.js +9 -12
  116. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactoryEvents__factory.js +9 -12
  117. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactoryGetters__factory.js +9 -12
  118. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactory__factory.js +9 -12
  119. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAddressProvider.sol/IAddressProviderEvents__factory.js +9 -12
  120. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAddressProvider.sol/IAddressProvider__factory.js +9 -12
  121. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAirdropDistributor.sol/IAirdropDistributorEvents__factory.js +9 -12
  122. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAirdropDistributor.sol/IAirdropDistributor__factory.js +9 -12
  123. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IContractsRegister.sol/IContractsRegisterEvents__factory.js +9 -12
  124. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IContractsRegister.sol/IContractsRegister__factory.js +9 -12
  125. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditAccount.sol/ICrediAccountExceptions__factory.js +9 -12
  126. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditAccount.sol/ICreditAccount__factory.js +9 -12
  127. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfiguratorEvents__factory.js +9 -12
  128. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfiguratorExceptions__factory.js +9 -12
  129. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfigurator__factory.js +9 -12
  130. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeEvents__factory.js +9 -12
  131. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExceptions__factory.js +9 -12
  132. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExtended__factory.js +9 -12
  133. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacade__factory.js +9 -12
  134. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2Events__factory.js +9 -12
  135. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2Exceptions__factory.js +9 -12
  136. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2__factory.js +9 -12
  137. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressorExceptions__factory.js +9 -12
  138. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor__factory.js +9 -12
  139. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenDistributor.sol/IDegenDistributorEvents__factory.js +9 -12
  140. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenDistributor.sol/IDegenDistributor__factory.js +9 -12
  141. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFTEvents__factory.js +9 -12
  142. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFTExceptions__factory.js +9 -12
  143. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFT__factory.js +9 -12
  144. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDieselToken.sol/IDieselTokenExceptions__factory.js +9 -12
  145. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDieselToken.sol/IDieselToken__factory.js +9 -12
  146. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IInterestRateModel__factory.js +9 -12
  147. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeedEvents__factory.js +9 -12
  148. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeedExceptions__factory.js +9 -12
  149. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeed__factory.js +9 -12
  150. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPhantomERC20__factory.js +9 -12
  151. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPoolService.sol/IPoolServiceEvents__factory.js +9 -12
  152. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPoolService.sol/IPoolService__factory.js +9 -12
  153. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceFeedType__factory.js +9 -12
  154. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Events__factory.js +9 -12
  155. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Exceptions__factory.js +9 -12
  156. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Ext__factory.js +9 -12
  157. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2__factory.js +9 -12
  158. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IVersion__factory.js +9 -12
  159. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IWETHGateway__factory.js +9 -12
  160. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/V1/ICreditFilter__factory.js +9 -12
  161. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/V1/ICreditManager__factory.js +9 -12
  162. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IAdapter.sol/IAdapterExceptions__factory.js +9 -12
  163. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IAdapter.sol/IAdapter__factory.js +9 -12
  164. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IUniversalAdapter.sol/IUniversalAdapterExceptions__factory.js +9 -12
  165. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IUniversalAdapter.sol/IUniversalAdapter__factory.js +9 -12
  166. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/external/IWETH__factory.js +9 -12
  167. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/pool/PoolService__factory.js +27 -50
  168. package/lib/types/factories/@gearbox-protocol/core-v2/contracts/test/interfaces/ITokenTestSuite__factory.js +9 -12
  169. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool__factory.js +9 -12
  170. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBooster__factory.js +9 -12
  171. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IClaimZap__factory.js +9 -12
  172. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IConvexToken__factory.js +9 -12
  173. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IRewards.sol/IBasicRewards__factory.js +9 -12
  174. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IRewards.sol/IRewards__factory.js +9 -12
  175. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICrvDeposit__factory.js +9 -12
  176. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICurveGauge__factory.js +9 -12
  177. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICurveVoteEscrow__factory.js +9 -12
  178. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IDeposit__factory.js +9 -12
  179. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IFeeDistro__factory.js +9 -12
  180. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IMinter__factory.js +9 -12
  181. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IPools__factory.js +9 -12
  182. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRegistry__factory.js +9 -12
  183. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRewardFactory__factory.js +9 -12
  184. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRewards__factory.js +9 -12
  185. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStaker__factory.js +9 -12
  186. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStashFactory__factory.js +9 -12
  187. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStash__factory.js +9 -12
  188. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ITokenFactory__factory.js +9 -12
  189. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ITokenMinter__factory.js +9 -12
  190. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IVestedEscrow__factory.js +9 -12
  191. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IVoting__factory.js +9 -12
  192. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IWalletChecker__factory.js +9 -12
  193. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePoolStETH__factory.js +9 -12
  194. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_2.sol/ICurvePool2Assets__factory.js +9 -12
  195. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_3.sol/ICurvePool3Assets__factory.js +9 -12
  196. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_4.sol/ICurvePool4Assets__factory.js +9 -12
  197. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool__factory.js +9 -12
  198. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurveRegistry__factory.js +9 -12
  199. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/ILidoOracle__factory.js +9 -12
  200. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IstETH.sol/IstETHGetters__factory.js +9 -12
  201. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IstETH.sol/IstETH__factory.js +9 -12
  202. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETH.sol/IwstETHGetters__factory.js +9 -12
  203. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETH.sol/IwstETH__factory.js +9 -12
  204. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETHGateway.sol/IwstETHGateWay__factory.js +9 -12
  205. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IQuoter__factory.js +9 -12
  206. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV2Router01__factory.js +9 -12
  207. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV2Router02__factory.js +9 -12
  208. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV3.sol/ISwapRouter__factory.js +9 -12
  209. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/yearn/IYVault__factory.js +9 -12
  210. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BaseRewardPoolAdapter.sol/IConvexV1BaseRewardPoolAdapterErrors__factory.js +9 -12
  211. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BaseRewardPoolAdapter.sol/IConvexV1BaseRewardPoolAdapter__factory.js +9 -12
  212. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BoosterAdapter__factory.js +9 -12
  213. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1Adapter.sol/ICurveV1AdapterExceptions__factory.js +9 -12
  214. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1Adapter.sol/ICurveV1Adapter__factory.js +9 -12
  215. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_2AssetsAdapter__factory.js +9 -12
  216. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_3AssetsAdapter__factory.js +9 -12
  217. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_4AssetsAdapter__factory.js +9 -12
  218. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1AdapterEvents__factory.js +9 -12
  219. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1AdapterExceptions__factory.js +9 -12
  220. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1Adapter__factory.js +9 -12
  221. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/IwstETHV1Adapter__factory.js +9 -12
  222. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapPathChecker__factory.js +9 -12
  223. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV2Adapter.sol/IUniswapV2AdapterExceptions__factory.js +9 -12
  224. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV2Adapter.sol/IUniswapV2Adapter__factory.js +9 -12
  225. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV3Adapter.sol/IUniswapV3AdapterExceptions__factory.js +9 -12
  226. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV3Adapter.sol/IUniswapV3Adapter__factory.js +9 -12
  227. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/yearn/IYearnV2Adapter__factory.js +9 -12
  228. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/test/config/SupportedContracts.sol/ISupportedContracts__factory.js +9 -12
  229. package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/test/mocks/integrations/LidoMock.sol/ILidoMockEvents__factory.js +9 -12
  230. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IClosePathResolver__factory.js +9 -12
  231. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IDepositor.sol/IDepositorOptions__factory.js +9 -12
  232. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IDepositor.sol/IDepositor__factory.js +9 -12
  233. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IGasPricer__factory.js +9 -12
  234. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ILPWorker.sol/ILPWorkerOptions__factory.js +9 -12
  235. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ILPWorker.sol/ILPWorker__factory.js +9 -12
  236. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IPathResolver__factory.js +9 -12
  237. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IRouterComponent__factory.js +9 -12
  238. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IRouter__factory.js +9 -12
  239. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ISwapAggregator__factory.js +9 -12
  240. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ISwapper__factory.js +9 -12
  241. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWithdrawer.sol/IWithdrawerOptions__factory.js +9 -12
  242. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWithdrawer.sol/IWithdrawer__factory.js +9 -12
  243. package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWrapper__factory.js +9 -12
  244. package/lib/types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.js +9 -12
  245. package/lib/types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata__factory.js +9 -12
  246. package/lib/types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.js +9 -12
  247. package/lib/types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.js +9 -12
  248. package/lib/types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.js +9 -12
  249. package/lib/types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.js +9 -12
  250. package/lib/types/factories/contracts/IGas__factory.js +9 -12
  251. package/lib/types/factories/contracts/IGnosisSafeSignatureValidator__factory.js +9 -12
  252. package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributorEvents__factory.js +9 -12
  253. package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributorExceptions__factory.js +9 -12
  254. package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributor__factory.js +9 -12
  255. package/lib/types/factories/contracts/support/IOffchainOracle__factory.js +9 -12
  256. package/lib/types/factories/contracts/support/MultiCall.sol/Multicall2__factory.js +27 -50
  257. package/lib/utils/errors.js +1 -1
  258. package/lib/utils/extracter.js +4 -4
  259. package/lib/utils/formatter.d.ts +8 -8
  260. package/lib/utils/formatter.js +73 -87
  261. package/lib/utils/loading.js +3 -3
  262. package/lib/utils/mappers.js +7 -34
  263. package/lib/utils/math.d.ts +10 -7
  264. package/lib/utils/math.js +22 -25
  265. package/lib/utils/multicall.js +32 -98
  266. package/lib/utils/price.d.ts +3 -4
  267. package/lib/utils/price.js +8 -20
  268. package/lib/utils/repeater.js +12 -53
  269. package/lib/utils/validate.js +2 -2
  270. package/lib/watchers/creditAccountWatcher.js +136 -237
  271. package/lib/watchers/creditAccountWatcher.spec.js +51 -68
  272. package/lib/watchers/creditManagerWatcher.js +21 -71
  273. package/lib/watchers/creditManagerWatcher.spec.js +20 -23
  274. package/package.json +2 -2
  275. package/lib/core/history.d.ts +0 -42
  276. package/lib/core/history.js +0 -2
  277. package/lib/core/wcOperation/abstractOperations.d.ts +0 -23
  278. package/lib/core/wcOperation/abstractOperations.js +0 -39
  279. package/lib/core/wcOperation/index.d.ts +0 -11
  280. package/lib/core/wcOperation/index.js +0 -30
  281. package/lib/core/wcOperation/operations.d.ts +0 -88
  282. package/lib/core/wcOperation/operations.js +0 -146
  283. package/lib/core/wcOperation/types.d.ts +0 -15
  284. package/lib/core/wcOperation/types.js +0 -2
@@ -1,93 +1,91 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Strategy = void 0;
4
- var ethers_1 = require("ethers");
5
- var decimals_1 = require("../tokens/decimals");
6
- var token_1 = require("../tokens/token");
7
- var price_1 = require("../utils/price");
8
- var constants_1 = require("./constants");
9
- var Strategy = /** @class */ (function () {
10
- function Strategy(payload) {
4
+ const decimals_1 = require("../tokens/decimals");
5
+ const token_1 = require("../tokens/token");
6
+ const price_1 = require("../utils/price");
7
+ const constants_1 = require("./constants");
8
+ class Strategy {
9
+ apy;
10
+ name;
11
+ lpToken;
12
+ pools;
13
+ unleveragableCollateral;
14
+ leveragableCollateral;
15
+ baseAssets;
16
+ constructor(payload) {
11
17
  this.apy = payload.apy;
12
18
  this.name = payload.name;
13
19
  this.lpToken = payload.lpToken.toLowerCase();
14
- this.pools = payload.pools.map(function (addr) { return addr.toLowerCase(); });
15
- this.unleveragableCollateral = payload.unleveragableCollateral.map(function (addr) {
16
- return addr.toLowerCase();
17
- });
18
- this.leveragableCollateral = payload.leveragableCollateral.map(function (addr) {
19
- return addr.toLowerCase();
20
- });
21
- this.baseAssets = payload.baseAssets.map(function (addr) { return addr.toLowerCase(); });
20
+ this.pools = payload.pools.map(addr => addr.toLowerCase());
21
+ this.unleveragableCollateral = payload.unleveragableCollateral.map(addr => addr.toLowerCase());
22
+ this.leveragableCollateral = payload.leveragableCollateral.map(addr => addr.toLowerCase());
23
+ this.baseAssets = payload.baseAssets.map(addr => addr.toLowerCase());
22
24
  }
23
- Strategy.maxLeverage = function (lpToken, cms) {
24
- var maxThreshold = maxLeverageThreshold(lpToken, cms)[0];
25
- var ONE = ethers_1.BigNumber.from(constants_1.PERCENTAGE_FACTOR);
26
- var maxLeverage = ONE.mul(constants_1.LEVERAGE_DECIMALS).div(ONE.sub(maxThreshold));
27
- return maxLeverage.sub(constants_1.LEVERAGE_DECIMALS).toNumber();
28
- };
29
- Strategy.prototype.maxAPY = function (baseAPY, maxLeverage, borrowAPY) {
25
+ static maxLeverage(lpToken, cms) {
26
+ const [maxThreshold] = maxLeverageThreshold(lpToken, cms);
27
+ const maxLeverage = (constants_1.PERCENTAGE_FACTOR * constants_1.LEVERAGE_DECIMALS) /
28
+ (constants_1.PERCENTAGE_FACTOR - maxThreshold);
29
+ return Number(maxLeverage - constants_1.LEVERAGE_DECIMALS);
30
+ }
31
+ maxAPY(baseAPY, maxLeverage, borrowAPY) {
30
32
  return (baseAPY +
31
- ((baseAPY - borrowAPY) * (maxLeverage - constants_1.LEVERAGE_DECIMALS)) /
32
- constants_1.LEVERAGE_DECIMALS);
33
- };
34
- Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
35
- var farmLev = this.farmLev(leverage, depositCollateral);
36
- return roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
37
- };
38
- Strategy.liquidationPrice = function (_a) {
39
- var prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, borrowed = _a.borrowed, underlyingToken = _a.underlyingToken, lpAmount = _a.lpAmount, lpToken = _a.lpToken;
40
- var underlyingTokenAddressLC = underlyingToken.toLowerCase();
41
- var underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC];
42
- var underlyingTokenDecimals = decimals_1.decimals[underlyingTokenSymbol];
43
- var underlyingPrice = prices[underlyingTokenAddressLC] || constants_1.PRICE_DECIMALS;
44
- var borrowedMoney = (0, price_1.calcTotalPrice)(underlyingPrice, borrowed, underlyingTokenDecimals);
45
- var lpTokenAddressLC = lpToken.toLowerCase();
46
- var lpTokenSymbol = token_1.tokenSymbolByAddress[lpTokenAddressLC];
47
- var lpTokenDecimals = decimals_1.decimals[lpTokenSymbol];
48
- var lpLT = liquidationThresholds[lpTokenAddressLC] || ethers_1.BigNumber.from(0);
49
- var lpPrice = prices[lpTokenAddressLC] || constants_1.PRICE_DECIMALS;
50
- var lpMoney = (0, price_1.calcTotalPrice)(lpPrice, lpAmount, lpTokenDecimals);
51
- var lpLTMoney = lpMoney.mul(lpLT).div(constants_1.PERCENTAGE_FACTOR);
52
- if (lpLTMoney.gt(0)) {
53
- var lqPrice = borrowedMoney.mul(constants_1.WAD).div(lpLTMoney);
54
- return lqPrice.gte(0) ? lqPrice : ethers_1.BigNumber.from(0);
33
+ ((baseAPY - borrowAPY) * (maxLeverage - Number(constants_1.LEVERAGE_DECIMALS))) /
34
+ Number(constants_1.LEVERAGE_DECIMALS));
35
+ }
36
+ overallAPY(apy, leverage, depositCollateral, borrowAPY) {
37
+ const farmLev = this.farmLev(leverage, depositCollateral);
38
+ return roi(apy, farmLev, leverage - Number(constants_1.LEVERAGE_DECIMALS), borrowAPY);
39
+ }
40
+ static liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }) {
41
+ const underlyingTokenAddressLC = underlyingToken.toLowerCase();
42
+ const underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC];
43
+ const underlyingTokenDecimals = decimals_1.decimals[underlyingTokenSymbol];
44
+ const underlyingPrice = prices[underlyingTokenAddressLC] || constants_1.PRICE_DECIMALS;
45
+ const borrowedMoney = (0, price_1.calcTotalPrice)(underlyingPrice, borrowed, underlyingTokenDecimals);
46
+ const lpTokenAddressLC = lpToken.toLowerCase();
47
+ const lpTokenSymbol = token_1.tokenSymbolByAddress[lpTokenAddressLC];
48
+ const lpTokenDecimals = decimals_1.decimals[lpTokenSymbol];
49
+ const lpLT = liquidationThresholds[lpTokenAddressLC] || 0n;
50
+ const lpPrice = prices[lpTokenAddressLC] || constants_1.PRICE_DECIMALS;
51
+ const lpMoney = (0, price_1.calcTotalPrice)(lpPrice, lpAmount, lpTokenDecimals);
52
+ const lpLTMoney = (lpMoney * lpLT) / constants_1.PERCENTAGE_FACTOR;
53
+ if (lpLTMoney > 0) {
54
+ const lqPrice = (borrowedMoney * constants_1.WAD) / lpLTMoney;
55
+ return lqPrice >= 0 ? lqPrice : 0n;
55
56
  }
56
- return ethers_1.BigNumber.from(0);
57
- };
58
- Strategy.prototype.farmLev = function (leverage, depositCollateral) {
57
+ return 0n;
58
+ }
59
+ farmLev(leverage, depositCollateral) {
59
60
  return this.inBaseAssets(depositCollateral) ||
60
61
  this.inLeveragableAssets(depositCollateral)
61
62
  ? leverage
62
- : leverage - constants_1.LEVERAGE_DECIMALS;
63
- };
64
- Strategy.prototype.inBaseAssets = function (depositCollateral) {
65
- return this.baseAssets.some(function (c) { return c === depositCollateral.toLowerCase(); });
66
- };
67
- Strategy.prototype.inLeveragableAssets = function (depositCollateral) {
68
- return this.leveragableCollateral.some(function (c) { return c === depositCollateral.toLowerCase(); });
69
- };
70
- return Strategy;
71
- }());
63
+ : leverage - Number(constants_1.LEVERAGE_DECIMALS);
64
+ }
65
+ inBaseAssets(depositCollateral) {
66
+ return this.baseAssets.some(c => c === depositCollateral.toLowerCase());
67
+ }
68
+ inLeveragableAssets(depositCollateral) {
69
+ return this.leveragableCollateral.some(c => c === depositCollateral.toLowerCase());
70
+ }
71
+ }
72
72
  exports.Strategy = Strategy;
73
73
  function roi(apy, farmLev, debtLev, borrowAPY) {
74
- return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
74
+ return (apy * farmLev - borrowAPY * debtLev) / Number(constants_1.LEVERAGE_DECIMALS);
75
75
  }
76
76
  function maxLeverageThreshold(lpToken, cms) {
77
- var lpTokenLC = lpToken.toLowerCase();
78
- var ltByCM = cms.map(function (cm) {
79
- var lt = cm.liquidationThresholds[lpTokenLC] || ethers_1.BigNumber.from(0);
77
+ const lpTokenLC = lpToken.toLowerCase();
78
+ const ltByCM = cms.map(cm => {
79
+ const lt = cm.liquidationThresholds[lpTokenLC] || 0n;
80
80
  return [cm.address, lt];
81
81
  });
82
- var sorted = ltByCM.sort(function (_a, _b) {
83
- var ltA = _a[1];
84
- var ltB = _b[1];
85
- if (ltA.gt(ltB))
82
+ const sorted = ltByCM.sort(([, ltA], [, ltB]) => {
83
+ if (ltA > ltB)
86
84
  return 1;
87
- if (ltB.gt(ltA))
85
+ if (ltB > ltA)
88
86
  return -1;
89
87
  return 0;
90
88
  });
91
- var _a = sorted[0] || [], _b = _a[0], cm = _b === void 0 ? "" : _b, _c = _a[1], lt = _c === void 0 ? ethers_1.BigNumber.from(0) : _c;
89
+ const [cm = "", lt = 0n] = sorted[0] || [];
92
90
  return [lt, cm];
93
91
  }
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
- var _a, _b;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- var chai_1 = require("chai");
5
- var ethers_1 = require("ethers");
6
- var decimals_1 = require("../tokens/decimals");
7
- var token_1 = require("../tokens/token");
8
- var formatter_1 = require("../utils/formatter");
9
- var constants_1 = require("./constants");
10
- var strategy_1 = require("./strategy");
11
- var lidoPayload = {
3
+ const chai_1 = require("chai");
4
+ const decimals_1 = require("../tokens/decimals");
5
+ const token_1 = require("../tokens/token");
6
+ const formatter_1 = require("../utils/formatter");
7
+ const constants_1 = require("./constants");
8
+ const strategy_1 = require("./strategy");
9
+ const lidoPayload = {
12
10
  name: "Lido",
13
11
  lpToken: token_1.tokenDataByNetwork.Mainnet.STETH,
14
12
  apy: 38434,
@@ -21,8 +19,8 @@ var lidoPayload = {
21
19
  leveragableCollateral: [],
22
20
  baseAssets: [token_1.tokenDataByNetwork.Mainnet.WETH],
23
21
  };
24
- var lidoStrategy = new strategy_1.Strategy(lidoPayload);
25
- var pools = {
22
+ const lidoStrategy = new strategy_1.Strategy(lidoPayload);
23
+ const pools = {
26
24
  "0x1": {
27
25
  borrowRate: 27543,
28
26
  },
@@ -30,29 +28,29 @@ var pools = {
30
28
  borrowRate: 5736,
31
29
  },
32
30
  };
33
- var prices = (_a = {},
34
- _a[token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()] = (0, formatter_1.toBN)("1738.11830000", constants_1.PRICE_DECIMALS_POW),
35
- _a[token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()] = (0, formatter_1.toBN)("0.99941103", constants_1.PRICE_DECIMALS_POW),
36
- _a[token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()] = (0, formatter_1.toBN)("1703.87588096", constants_1.PRICE_DECIMALS_POW),
37
- _a);
38
- var liquidationThresholds = (_b = {},
39
- _b[token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()] = ethers_1.BigNumber.from("9300"),
40
- _b[token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()] = ethers_1.BigNumber.from("8500"),
41
- _b[token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()] = ethers_1.BigNumber.from("9000"),
42
- _b);
43
- describe("Strategy test", function () {
44
- it("maxAPY calculation is correct", function () {
45
- var result = lidoStrategy.maxAPY(53203, 10 * constants_1.LEVERAGE_DECIMALS, pools["0x1"].borrowRate);
31
+ const prices = {
32
+ [token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: (0, formatter_1.toBN)("1738.11830000", constants_1.PRICE_DECIMALS_POW),
33
+ [token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: (0, formatter_1.toBN)("0.99941103", constants_1.PRICE_DECIMALS_POW),
34
+ [token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()]: (0, formatter_1.toBN)("1703.87588096", constants_1.PRICE_DECIMALS_POW),
35
+ };
36
+ const liquidationThresholds = {
37
+ [token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: 9300n,
38
+ [token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: 8500n,
39
+ [token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()]: 9000n,
40
+ };
41
+ describe("Strategy test", () => {
42
+ it("maxAPY calculation is correct", () => {
43
+ const result = lidoStrategy.maxAPY(53203, 10 * Number(constants_1.LEVERAGE_DECIMALS), pools["0x1"].borrowRate);
46
44
  (0, chai_1.expect)(result).to.be.eq(284143);
47
45
  });
48
- it("overallAPY calculation is correct", function () {
49
- var result = lidoStrategy.overallAPY(lidoStrategy.apy || 0, 10 * constants_1.LEVERAGE_DECIMALS, token_1.tokenDataByNetwork.Mainnet.WETH, pools["0x2"].borrowRate);
46
+ it("overallAPY calculation is correct", () => {
47
+ const result = lidoStrategy.overallAPY(lidoStrategy.apy || 0, 10 * Number(constants_1.LEVERAGE_DECIMALS), token_1.tokenDataByNetwork.Mainnet.WETH, pools["0x2"].borrowRate);
50
48
  (0, chai_1.expect)(result).to.be.eq(332716);
51
49
  });
52
- it("liquidationPrice calculation is correct", function () {
53
- var result = strategy_1.Strategy.liquidationPrice({
54
- liquidationThresholds: liquidationThresholds,
55
- prices: prices,
50
+ it("liquidationPrice calculation is correct", () => {
51
+ const result = strategy_1.Strategy.liquidationPrice({
52
+ liquidationThresholds,
53
+ prices,
56
54
  borrowed: (0, formatter_1.toBN)("350", decimals_1.decimals.WETH),
57
55
  underlyingToken: token_1.tokenDataByNetwork.Mainnet.WETH,
58
56
  lpAmount: (0, formatter_1.toBN)("400", decimals_1.decimals.STETH),
@@ -60,10 +58,10 @@ describe("Strategy test", function () {
60
58
  });
61
59
  (0, chai_1.expect)(Number((0, formatter_1.toSignificant)(result, constants_1.WAD_DECIMALS_POW)).toFixed(3)).to.be.eq("0.992");
62
60
  });
63
- it("maxLeverage is correct", function () {
64
- var result = strategy_1.Strategy.maxLeverage(token_1.tokenDataByNetwork.Mainnet.STETH, [
65
- { address: "0x1", liquidationThresholds: liquidationThresholds },
61
+ it("maxLeverage is correct", () => {
62
+ const result = strategy_1.Strategy.maxLeverage(token_1.tokenDataByNetwork.Mainnet.STETH, [
63
+ { address: "0x1", liquidationThresholds },
66
64
  ]);
67
- (0, chai_1.expect)(result).to.be.eq(9 * constants_1.LEVERAGE_DECIMALS);
65
+ (0, chai_1.expect)(result).to.be.eq(9 * Number(constants_1.LEVERAGE_DECIMALS));
68
66
  });
69
67
  });
@@ -1,7 +1,6 @@
1
- import { BigNumber } from "ethers";
2
1
  export interface TokenShare {
3
2
  holder: string;
4
- amount: BigNumber;
3
+ amount: bigint;
5
4
  share: number;
6
5
  isCompany: boolean;
7
6
  }
@@ -1,4 +1,4 @@
1
- import { BigNumber, Signer } from "ethers";
1
+ import { Signer } from "ethers";
2
2
  import { AdapterInterface } from "../contracts/adapters";
3
3
  import { MultiCall, PathFinderResult, SwapOperation } from "../pathfinder/core";
4
4
  import { ICreditFacade } from "../types";
@@ -6,8 +6,8 @@ import { BaseAdapter } from "./adapter";
6
6
  import { EVMTx } from "./eventOrTx";
7
7
  interface BaseTradeInterface {
8
8
  swapType: SwapOperation;
9
- sourceAmount: BigNumber;
10
- expectedAmount: BigNumber;
9
+ sourceAmount: bigint;
10
+ expectedAmount: bigint;
11
11
  tokenFrom: string;
12
12
  tokenTo: string;
13
13
  operationName: TradeOperations;
@@ -23,9 +23,9 @@ export declare class Trade implements BaseTradeInterface {
23
23
  readonly tradePath: PathFinderResult;
24
24
  readonly creditFacade: string;
25
25
  readonly swapType: SwapOperation;
26
- readonly sourceAmount: BigNumber;
27
- readonly expectedAmount: BigNumber;
28
- readonly rate: BigNumber;
26
+ readonly sourceAmount: bigint;
27
+ readonly expectedAmount: bigint;
28
+ readonly rate: bigint;
29
29
  readonly tokenFrom: string;
30
30
  readonly tokenTo: string;
31
31
  readonly operationName: TradeOperations;
package/lib/core/trade.js CHANGED
@@ -1,122 +1,87 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.Trade = void 0;
40
- var decimals_1 = require("../tokens/decimals");
41
- var token_1 = require("../tokens/token");
42
- var types_1 = require("../types");
43
- var formatter_1 = require("../utils/formatter");
44
- var constants_1 = require("./constants");
45
- var transactions_1 = require("./transactions");
46
- var OPERATION_NAMES = {
4
+ const decimals_1 = require("../tokens/decimals");
5
+ const token_1 = require("../tokens/token");
6
+ const types_1 = require("../types");
7
+ const formatter_1 = require("../utils/formatter");
8
+ const constants_1 = require("./constants");
9
+ const transactions_1 = require("./transactions");
10
+ const OPERATION_NAMES = {
47
11
  farmWithdraw: "Farm withdraw",
48
12
  farmDeposit: "Farm deposit",
49
13
  swap: "Swap",
50
14
  unknownOperation: "Unknown operation",
51
15
  };
52
- var Trade = /** @class */ (function () {
53
- function Trade(props) {
16
+ class Trade {
17
+ helper;
18
+ tradePath;
19
+ creditFacade;
20
+ swapType;
21
+ sourceAmount;
22
+ expectedAmount;
23
+ rate;
24
+ tokenFrom;
25
+ tokenTo;
26
+ operationName;
27
+ constructor(props) {
54
28
  this.helper = props.adapter;
55
29
  this.tradePath = props.tradePath;
56
30
  this.creditFacade = props.creditFacade;
57
31
  this.swapType = props.swapType;
58
32
  this.sourceAmount = props.sourceAmount;
59
33
  this.expectedAmount = props.expectedAmount;
60
- this.rate = constants_1.WAD.mul(props.expectedAmount).div(props.sourceAmount);
34
+ this.rate = (constants_1.WAD * props.expectedAmount) / props.sourceAmount;
61
35
  this.tokenFrom = props.tokenFrom;
62
36
  this.tokenTo = props.tokenTo;
63
37
  this.operationName = props.operationName;
64
38
  }
65
- Trade.prototype.getName = function () {
39
+ getName() {
66
40
  return this.helper.name;
67
- };
68
- Trade.prototype.getAdapterInterface = function () {
41
+ }
42
+ getAdapterInterface() {
69
43
  return this.helper.adapterInterface;
70
- };
71
- Trade.prototype.getContractAddress = function () {
44
+ }
45
+ getContractAddress() {
72
46
  return this.helper.contractAddress;
73
- };
74
- Trade.prototype.getAdapterAddress = function () {
47
+ }
48
+ getAdapterAddress() {
75
49
  return this.helper.adapterAddress;
76
- };
77
- Trade.prototype.execute = function (signer) {
78
- return __awaiter(this, void 0, void 0, function () {
79
- var receipt;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
82
- case 0: return [4 /*yield*/, Trade.executeMulticallPath(this.creditFacade, signer, this.tradePath.calls)];
83
- case 1:
84
- receipt = _a.sent();
85
- return [2 /*return*/, new transactions_1.TXSwap({
86
- txHash: receipt.hash,
87
- protocol: this.helper.contractAddress,
88
- operation: OPERATION_NAMES[this.operationName],
89
- amountFrom: this.sourceAmount,
90
- amountTo: this.expectedAmount,
91
- tokenFrom: this.tokenFrom,
92
- tokenTo: this.tokenTo,
93
- creditManager: this.helper.creditManager,
94
- timestamp: 0,
95
- })];
96
- }
97
- });
50
+ }
51
+ async execute(signer) {
52
+ const receipt = await Trade.executeMulticallPath(this.creditFacade, signer, this.tradePath.calls);
53
+ return new transactions_1.TXSwap({
54
+ txHash: receipt.hash,
55
+ protocol: this.helper.contractAddress,
56
+ operation: OPERATION_NAMES[this.operationName],
57
+ amountFrom: this.sourceAmount,
58
+ amountTo: this.expectedAmount,
59
+ tokenFrom: this.tokenFrom,
60
+ tokenTo: this.tokenTo,
61
+ creditManager: this.helper.creditManager,
62
+ timestamp: 0,
98
63
  });
99
- };
100
- Trade.prototype.toString = function () {
101
- var symbolFrom = token_1.tokenSymbolByAddress[this.tokenFrom.toLowerCase()];
102
- var symbolTo = token_1.tokenSymbolByAddress[this.tokenTo.toLowerCase()];
64
+ }
65
+ toString() {
66
+ const symbolFrom = token_1.tokenSymbolByAddress[this.tokenFrom.toLowerCase()];
67
+ const symbolTo = token_1.tokenSymbolByAddress[this.tokenTo.toLowerCase()];
103
68
  if (!symbolFrom)
104
- throw new Error("Unknown token: ".concat(this.tokenFrom));
69
+ throw new Error(`Unknown token: ${this.tokenFrom}`);
105
70
  if (!symbolTo)
106
- throw new Error("Unknown token: ".concat(this.tokenTo));
107
- var decimalsFrom = decimals_1.decimals[symbolFrom];
108
- var decimalsTo = decimals_1.decimals[symbolTo];
109
- return "".concat(this.operationName, " ").concat((0, formatter_1.formatBN)(this.sourceAmount, decimalsFrom), " ").concat(symbolFrom, " \u21D2 ").concat((0, formatter_1.formatBN)(this.expectedAmount, decimalsTo), " ").concat(symbolTo, " on ").concat(this.helper.name);
110
- };
111
- Trade.getOperationName = function (tokenInAddress, tokenOutAddress) {
112
- var tokenInSymbol = token_1.tokenSymbolByAddress[tokenInAddress];
113
- var tokenOutSymbol = token_1.tokenSymbolByAddress[tokenOutAddress];
114
- var tokenInIsLp = (0, token_1.isLPToken)(tokenInSymbol);
115
- var tokenOutIsLp = (0, token_1.isLPToken)(tokenOutSymbol);
71
+ throw new Error(`Unknown token: ${this.tokenTo}`);
72
+ const decimalsFrom = decimals_1.decimals[symbolFrom];
73
+ const decimalsTo = decimals_1.decimals[symbolTo];
74
+ return `${this.operationName} ${(0, formatter_1.formatBN)(this.sourceAmount, decimalsFrom)} ${symbolFrom} ${(0, formatter_1.formatBN)(this.expectedAmount, decimalsTo)} ${symbolTo} on ${this.helper.name}`;
75
+ }
76
+ static getOperationName(tokenInAddress, tokenOutAddress) {
77
+ const tokenInSymbol = token_1.tokenSymbolByAddress[tokenInAddress];
78
+ const tokenOutSymbol = token_1.tokenSymbolByAddress[tokenOutAddress];
79
+ const tokenInIsLp = (0, token_1.isLPToken)(tokenInSymbol);
80
+ const tokenOutIsLp = (0, token_1.isLPToken)(tokenOutSymbol);
116
81
  if (!tokenInSymbol)
117
- throw new Error("Unknown token: ".concat(tokenInAddress));
82
+ throw new Error(`Unknown token: ${tokenInAddress}`);
118
83
  if (!tokenOutSymbol)
119
- throw new Error("Unknown token: ".concat(tokenOutAddress));
84
+ throw new Error(`Unknown token: ${tokenOutAddress}`);
120
85
  if (tokenInIsLp && !tokenOutIsLp)
121
86
  return "farmWithdraw";
122
87
  if (!tokenInIsLp && tokenOutIsLp)
@@ -124,27 +89,17 @@ var Trade = /** @class */ (function () {
124
89
  if (!tokenInIsLp && !tokenOutIsLp)
125
90
  return "swap";
126
91
  return "unknownOperation";
127
- };
128
- Trade.executeMulticallPath = function (creditFacade, signer, calls) {
129
- return __awaiter(this, void 0, void 0, function () {
130
- var safeCreditFacade;
131
- return __generator(this, function (_a) {
132
- if (calls.length < 1)
133
- throw new Error("No path to execute");
134
- safeCreditFacade = typeof creditFacade === "string"
135
- ? types_1.ICreditFacade__factory.connect(creditFacade, signer)
136
- : creditFacade;
137
- return [2 /*return*/, this.executeOnCreditFacade(calls, safeCreditFacade)];
138
- });
139
- });
140
- };
141
- Trade.executeOnCreditFacade = function (calls, creditFacade) {
142
- return __awaiter(this, void 0, void 0, function () {
143
- return __generator(this, function (_a) {
144
- return [2 /*return*/, creditFacade.multicall(calls)];
145
- });
146
- });
147
- };
148
- return Trade;
149
- }());
92
+ }
93
+ static async executeMulticallPath(creditFacade, signer, calls) {
94
+ if (calls.length < 1)
95
+ throw new Error("No path to execute");
96
+ const safeCreditFacade = typeof creditFacade === "string"
97
+ ? types_1.ICreditFacade__factory.connect(creditFacade, signer)
98
+ : creditFacade;
99
+ return this.executeOnCreditFacade(calls, safeCreditFacade);
100
+ }
101
+ static async executeOnCreditFacade(calls, creditFacade) {
102
+ return creditFacade.multicall(calls);
103
+ }
104
+ }
150
105
  exports.Trade = Trade;