@gearbox-protocol/sdk 3.0.0-next.5 → 3.0.0-next.50

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 (264) hide show
  1. package/contracts/IAirdropDistributor.sol +55 -0
  2. package/contracts/IDegenDistributor.sol +28 -0
  3. package/contracts/IOffchainOracle.sol +17 -0
  4. package/contracts/IWETHGateway.sol +33 -0
  5. package/contracts/IwstETHGateway.sol +24 -0
  6. package/contracts/index.sol +11 -3
  7. package/lib/apy/curveAPY.js +2 -1
  8. package/lib/apy/index.d.ts +2 -2
  9. package/lib/apy/yearnAPY.js +1 -1
  10. package/lib/config.d.ts +0 -1
  11. package/lib/config.js +1 -2
  12. package/lib/core/assets.d.ts +4 -4
  13. package/lib/core/assets.js +28 -17
  14. package/lib/core/creditAccount.d.ts +31 -6
  15. package/lib/core/creditAccount.js +101 -37
  16. package/lib/core/creditAccount.spec.js +693 -10
  17. package/lib/core/creditManager.d.ts +22 -8
  18. package/lib/core/creditManager.js +86 -30
  19. package/lib/core/events.js +14 -14
  20. package/lib/core/gauge.d.ts +26 -0
  21. package/lib/core/gauge.js +63 -0
  22. package/lib/core/gaugeMath.d.ts +40 -0
  23. package/lib/core/gaugeMath.js +108 -0
  24. package/lib/core/gaugeMath.spec.d.ts +1 -0
  25. package/lib/core/gaugeMath.spec.js +388 -0
  26. package/lib/core/{pool/data.d.ts → pool.d.ts} +18 -10
  27. package/lib/core/{pool/data.js → pool.js} +69 -24
  28. package/lib/core/strategy.js +2 -2
  29. package/lib/core/trade.d.ts +5 -23
  30. package/lib/core/trade.js +4 -61
  31. package/lib/core/transactions.d.ts +50 -3
  32. package/lib/core/transactions.js +136 -105
  33. package/lib/index.d.ts +3 -0
  34. package/lib/index.js +3 -0
  35. package/lib/parsers/abstractParser.js +1 -2
  36. package/lib/parsers/creditFacadeParser.d.ts +2 -1
  37. package/lib/parsers/creditFacadeParser.js +17 -5
  38. package/lib/parsers/creditFacadeParser.spec.js +2 -3
  39. package/lib/parsers/curveAdapterParser.js +2 -3
  40. package/lib/parsers/txParser.d.ts +4 -4
  41. package/lib/parsers/txParser.js +9 -3
  42. package/lib/parsers/uniV2AdapterParser.js +2 -2
  43. package/lib/parsers/uniV3AdapterParser.js +3 -3
  44. package/lib/pathfinder/core.d.ts +4 -4
  45. package/lib/pathfinder/pathOptions.d.ts +2 -1
  46. package/lib/pathfinder/pathOptions.js +20 -1
  47. package/lib/pathfinder/pathOptions.spec.js +2 -2
  48. package/lib/pathfinder/pathfinder.js +4 -3
  49. package/lib/pathfinder/pathfinder.spec.js +3 -1
  50. package/lib/payload/creditAccount.d.ts +2 -2
  51. package/lib/payload/gauge.d.ts +12 -0
  52. package/lib/payload/pool.d.ts +6 -1
  53. package/lib/types/IAirdropDistributor.sol/IAirdropDistributor.d.ts +124 -0
  54. package/lib/types/IAirdropDistributor.sol/IAirdropDistributorEvents.d.ts +73 -0
  55. package/lib/types/IAirdropDistributor.sol/index.d.ts +2 -0
  56. package/lib/types/IConvexToken.d.ts +9 -1
  57. package/lib/types/IConvexV1BaseRewardPoolAdapter.d.ts +17 -1
  58. package/lib/types/{IConvexV1BoosterAdapter.d.ts → IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapter.d.ts} +19 -4
  59. package/lib/types/IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapterEvents.d.ts +43 -0
  60. package/lib/types/IConvexV1BoosterAdapter.sol/index.d.ts +2 -0
  61. package/lib/types/ICreditConfiguratorV3.sol/ICreditConfiguratorV3.d.ts +716 -0
  62. package/lib/types/ICreditConfiguratorV3.sol/ICreditConfiguratorV3Events.d.ts +275 -0
  63. package/lib/types/ICreditConfiguratorV3.sol/index.d.ts +2 -0
  64. package/lib/types/ICreditFacadeV2.sol/ICreditFacadeV2Extended.d.ts +7 -11
  65. package/lib/types/ICreditFacadeV3.sol/ICreditFacadeV3.d.ts +165 -20
  66. package/lib/types/ICreditFacadeV3.sol/ICreditFacadeV3Events.d.ts +5 -7
  67. package/lib/types/ICreditFacadeV3Multicall.d.ts +35 -12
  68. package/lib/types/ICreditManagerV3.sol/ICreditManagerV3.d.ts +273 -39
  69. package/lib/types/IDataCompressorV2_10.d.ts +43 -9
  70. package/lib/types/IDataCompressorV3_00.d.ts +140 -10
  71. package/lib/types/IDegenDistributor.sol/IDegenDistributor.d.ts +96 -0
  72. package/lib/types/IDegenDistributor.sol/IDegenDistributorEvents.d.ts +53 -0
  73. package/lib/types/IDegenDistributor.sol/index.d.ts +2 -0
  74. package/lib/types/{draft-IERC20Permit.sol/IERC20Permit.d.ts → IERC20Permit.d.ts} +1 -1
  75. package/lib/types/IERC20ZapperDeposits.d.ts +117 -0
  76. package/lib/types/IETHZapperDeposits.d.ts +66 -0
  77. package/lib/types/IGasPricer.d.ts +44 -0
  78. package/lib/types/IGearStakingV3.sol/IGearStakingV3.d.ts +408 -0
  79. package/lib/types/IGearStakingV3.sol/IGearStakingV3Events.d.ts +117 -0
  80. package/lib/types/IGearStakingV3.sol/index.d.ts +2 -0
  81. package/lib/types/{ILidoV1Adapter.sol/ILidoV1Adapter.d.ts → ILidoV1Adapter.d.ts} +5 -40
  82. package/lib/types/ILidoV1Adapter.js +2 -0
  83. package/lib/types/IOffchainOracle.d.ts +58 -0
  84. package/lib/types/IOffchainOracle.js +2 -0
  85. package/lib/types/IPoolV3.sol/IPoolV3.d.ts +43 -11
  86. package/lib/types/IPoolV3.sol/index.d.ts +0 -1
  87. package/lib/types/IWETHGateway.d.ts +90 -0
  88. package/lib/types/IWETHGateway.js +2 -0
  89. package/lib/types/IZapper.d.ts +130 -0
  90. package/lib/types/IZapper.js +2 -0
  91. package/lib/types/IwstETHGateway.sol/IwstETHGateWay.d.ts +70 -0
  92. package/lib/types/IwstETHGateway.sol/IwstETHGateWay.js +2 -0
  93. package/lib/types/IwstETHGateway.sol/index.d.ts +1 -0
  94. package/lib/types/IwstETHGateway.sol/index.js +2 -0
  95. package/lib/types/factories/AddressProvider__factory.d.ts +1 -1
  96. package/lib/types/factories/AddressProvider__factory.js +1 -1
  97. package/lib/types/factories/Balances.sol/BalanceOps__factory.d.ts +1 -1
  98. package/lib/types/factories/Balances.sol/BalanceOps__factory.js +1 -1
  99. package/lib/types/factories/Claimable__factory.d.ts +1 -1
  100. package/lib/types/factories/Claimable__factory.js +1 -1
  101. package/lib/types/factories/Errors__factory.d.ts +1 -1
  102. package/lib/types/factories/Errors__factory.js +1 -1
  103. package/lib/types/factories/IAirdropDistributor.sol/IAirdropDistributorEvents__factory.d.ts +63 -0
  104. package/lib/types/factories/IAirdropDistributor.sol/IAirdropDistributorEvents__factory.js +88 -0
  105. package/lib/types/factories/IAirdropDistributor.sol/IAirdropDistributor__factory.d.ts +119 -0
  106. package/lib/types/factories/IAirdropDistributor.sol/IAirdropDistributor__factory.js +161 -0
  107. package/lib/types/factories/IAirdropDistributor.sol/index.d.ts +2 -0
  108. package/lib/types/factories/IAirdropDistributor.sol/index.js +10 -0
  109. package/lib/types/factories/IConvexToken__factory.d.ts +10 -0
  110. package/lib/types/factories/IConvexToken__factory.js +13 -0
  111. package/lib/types/factories/IConvexV1BaseRewardPoolAdapter__factory.d.ts +20 -0
  112. package/lib/types/factories/IConvexV1BaseRewardPoolAdapter__factory.js +26 -0
  113. package/lib/types/factories/IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapterEvents__factory.d.ts +23 -0
  114. package/lib/types/factories/IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapterEvents__factory.js +38 -0
  115. package/lib/types/factories/{IConvexV1BoosterAdapter__factory.d.ts → IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapter__factory.d.ts} +16 -1
  116. package/lib/types/factories/{IConvexV1BoosterAdapter__factory.js → IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapter__factory.js} +19 -0
  117. package/lib/types/factories/IConvexV1BoosterAdapter.sol/index.d.ts +2 -0
  118. package/lib/types/factories/IConvexV1BoosterAdapter.sol/index.js +10 -0
  119. package/lib/types/factories/ICreditConfiguratorV3.sol/ICreditConfiguratorV3Events__factory.d.ts +273 -0
  120. package/lib/types/factories/ICreditConfiguratorV3.sol/ICreditConfiguratorV3Events__factory.js +357 -0
  121. package/lib/types/factories/ICreditConfiguratorV3.sol/ICreditConfiguratorV3__factory.d.ts +605 -0
  122. package/lib/types/factories/ICreditConfiguratorV3.sol/ICreditConfiguratorV3__factory.js +785 -0
  123. package/lib/types/factories/ICreditConfiguratorV3.sol/index.d.ts +2 -0
  124. package/lib/types/factories/ICreditConfiguratorV3.sol/index.js +10 -0
  125. package/lib/types/factories/ICreditFacadeV2.sol/ICreditFacadeV2Extended__factory.d.ts +0 -4
  126. package/lib/types/factories/ICreditFacadeV2.sol/ICreditFacadeV2Extended__factory.js +0 -5
  127. package/lib/types/factories/ICreditFacadeV3.sol/ICreditFacadeV3Events__factory.d.ts +1 -6
  128. package/lib/types/factories/ICreditFacadeV3.sol/ICreditFacadeV3Events__factory.js +1 -7
  129. package/lib/types/factories/ICreditFacadeV3.sol/ICreditFacadeV3__factory.d.ts +144 -13
  130. package/lib/types/factories/ICreditFacadeV3.sol/ICreditFacadeV3__factory.js +185 -15
  131. package/lib/types/factories/ICreditFacadeV3Multicall__factory.d.ts +35 -5
  132. package/lib/types/factories/ICreditFacadeV3Multicall__factory.js +43 -5
  133. package/lib/types/factories/ICreditManagerV3.sol/ICreditManagerV3__factory.d.ts +199 -25
  134. package/lib/types/factories/ICreditManagerV3.sol/ICreditManagerV3__factory.js +252 -28
  135. package/lib/types/factories/IDataCompressorV2_10__factory.d.ts +110 -12
  136. package/lib/types/factories/IDataCompressorV2_10__factory.js +138 -14
  137. package/lib/types/factories/IDataCompressorV3_00__factory.d.ts +400 -16
  138. package/lib/types/factories/IDataCompressorV3_00__factory.js +508 -19
  139. package/lib/types/factories/IDegenDistributor.sol/IDegenDistributorEvents__factory.d.ts +38 -0
  140. package/lib/types/factories/{AaveV2_WrappedAToken.sol/IWrappedATokenEvents__factory.js → IDegenDistributor.sol/IDegenDistributorEvents__factory.js} +13 -25
  141. package/lib/types/factories/IDegenDistributor.sol/IDegenDistributor__factory.d.ts +84 -0
  142. package/lib/types/factories/{IPoolV3.sol/IPoolBase__factory.js → IDegenDistributor.sol/IDegenDistributor__factory.js} +46 -41
  143. package/lib/types/factories/IDegenDistributor.sol/index.d.ts +2 -0
  144. package/lib/types/factories/IDegenDistributor.sol/index.js +10 -0
  145. package/lib/types/factories/{draft-IERC20Permit.sol/IERC20Permit__factory.d.ts → IERC20Permit__factory.d.ts} +1 -1
  146. package/lib/types/factories/IERC20ZapperDeposits__factory.d.ts +120 -0
  147. package/lib/types/factories/IERC20ZapperDeposits__factory.js +165 -0
  148. package/lib/types/factories/IETHZapperDeposits__factory.d.ts +40 -0
  149. package/lib/types/factories/IETHZapperDeposits__factory.js +62 -0
  150. package/lib/types/factories/IGasPricer__factory.d.ts +22 -0
  151. package/lib/types/factories/{ILidoV1Adapter.sol/ILidoV1AdapterEvents__factory.js → IGasPricer__factory.js} +14 -8
  152. package/lib/types/factories/IGearStakingV3.sol/IGearStakingV3Events__factory.d.ts +113 -0
  153. package/lib/types/factories/IGearStakingV3.sol/IGearStakingV3Events__factory.js +152 -0
  154. package/lib/types/factories/IGearStakingV3.sol/IGearStakingV3__factory.d.ts +504 -0
  155. package/lib/types/factories/IGearStakingV3.sol/IGearStakingV3__factory.js +660 -0
  156. package/lib/types/factories/IGearStakingV3.sol/index.d.ts +2 -0
  157. package/lib/types/factories/IGearStakingV3.sol/index.js +10 -0
  158. package/lib/types/factories/{ILidoV1Adapter.sol/ILidoV1Adapter__factory.d.ts → ILidoV1Adapter__factory.d.ts} +1 -35
  159. package/lib/types/factories/{ILidoV1Adapter.sol/ILidoV1Adapter__factory.js → ILidoV1Adapter__factory.js} +0 -44
  160. package/lib/types/factories/IOffchainOracle__factory.d.ts +48 -0
  161. package/lib/types/factories/IOffchainOracle__factory.js +72 -0
  162. package/lib/types/factories/IPoolV3.sol/IPoolV3__factory.d.ts +62 -14
  163. package/lib/types/factories/IPoolV3.sol/IPoolV3__factory.js +79 -17
  164. package/lib/types/factories/IPoolV3.sol/index.d.ts +0 -1
  165. package/lib/types/factories/IPoolV3.sol/index.js +1 -3
  166. package/lib/types/factories/IWETHGateway__factory.d.ts +58 -0
  167. package/lib/types/factories/IWETHGateway__factory.js +83 -0
  168. package/lib/types/factories/{WERC20ZapperBase__factory.d.ts → IZapper__factory.d.ts} +57 -61
  169. package/lib/types/factories/{WERC20ZapperBase__factory.js → IZapper__factory.js} +65 -71
  170. package/lib/types/factories/{ZapperBase__factory.d.ts → IwstETHGateway.sol/IwstETHGateWay__factory.d.ts} +22 -34
  171. package/lib/types/factories/{ZapperBase__factory.js → IwstETHGateway.sol/IwstETHGateWay__factory.js} +22 -39
  172. package/lib/types/factories/IwstETHGateway.sol/index.d.ts +1 -0
  173. package/lib/types/factories/IwstETHGateway.sol/index.js +8 -0
  174. package/lib/types/factories/SafeERC20__factory.d.ts +1 -1
  175. package/lib/types/factories/SafeERC20__factory.js +1 -1
  176. package/lib/types/factories/index.d.ts +15 -13
  177. package/lib/types/factories/index.js +25 -25
  178. package/lib/types/factories/{IRouter__factory.d.ts → interfaces/IRouter__factory.d.ts} +15 -1
  179. package/lib/types/factories/{IRouter__factory.js → interfaces/IRouter__factory.js} +19 -0
  180. package/lib/types/factories/interfaces/index.d.ts +1 -0
  181. package/lib/types/factories/interfaces/index.js +8 -0
  182. package/lib/types/index.d.ts +62 -48
  183. package/lib/types/index.js +52 -46
  184. package/lib/types/{IRouter.d.ts → interfaces/IRouter.d.ts} +12 -2
  185. package/lib/types/interfaces/IRouter.js +2 -0
  186. package/lib/types/interfaces/index.d.ts +1 -0
  187. package/lib/types/interfaces/index.js +2 -0
  188. package/lib/utils/formatter.d.ts +0 -3
  189. package/lib/utils/formatter.js +1 -67
  190. package/lib/utils/math.d.ts +2 -0
  191. package/lib/utils/math.js +2 -0
  192. package/lib/utils/types.d.ts +1 -0
  193. package/lib/watchers/creditAccountWatcher.d.ts +3 -2
  194. package/lib/watchers/creditAccountWatcher.js +19 -13
  195. package/lib/watchers/creditAccountWatcher.spec.js +18 -18
  196. package/lib/watchers/creditManagerWatcher.d.ts +5 -3
  197. package/lib/watchers/creditManagerWatcher.js +32 -10
  198. package/lib/watchers/creditManagerWatcher.spec.js +12 -4
  199. package/package.json +10 -9
  200. package/contracts/IRouter.sol +0 -100
  201. package/lib/core/pool/index.d.ts +0 -1
  202. package/lib/core/pool/index.js +0 -17
  203. package/lib/types/AaveV2_WrappedAToken.sol/IWrappedATokenEvents.d.ts +0 -60
  204. package/lib/types/AaveV2_WrappedAToken.sol/WrappedAToken.d.ts +0 -332
  205. package/lib/types/AaveV2_WrappedAToken.sol/index.d.ts +0 -2
  206. package/lib/types/ERC20.d.ts +0 -198
  207. package/lib/types/IAToken.d.ts +0 -182
  208. package/lib/types/ILendingPool.d.ts +0 -140
  209. package/lib/types/ILidoV1Adapter.sol/ILidoV1AdapterEvents.d.ts +0 -39
  210. package/lib/types/ILidoV1Adapter.sol/ILidoV1AdapterExceptions.d.ts +0 -27
  211. package/lib/types/ILidoV1Adapter.sol/index.d.ts +0 -3
  212. package/lib/types/IPoolV3.sol/IPoolBase.d.ts +0 -102
  213. package/lib/types/WATokenZapper.d.ts +0 -134
  214. package/lib/types/WERC20ZapperBase.d.ts +0 -134
  215. package/lib/types/WETHZapper.d.ts +0 -122
  216. package/lib/types/WstETHZapper.d.ts +0 -134
  217. package/lib/types/ZapperBase.d.ts +0 -70
  218. package/lib/types/draft-IERC20Permit.sol/index.d.ts +0 -1
  219. package/lib/types/factories/AaveV2_WrappedAToken.sol/IWrappedATokenEvents__factory.d.ts +0 -48
  220. package/lib/types/factories/AaveV2_WrappedAToken.sol/WrappedAToken__factory.d.ts +0 -397
  221. package/lib/types/factories/AaveV2_WrappedAToken.sol/WrappedAToken__factory.js +0 -535
  222. package/lib/types/factories/AaveV2_WrappedAToken.sol/index.d.ts +0 -2
  223. package/lib/types/factories/AaveV2_WrappedAToken.sol/index.js +0 -10
  224. package/lib/types/factories/ERC20__factory.d.ts +0 -239
  225. package/lib/types/factories/ERC20__factory.js +0 -328
  226. package/lib/types/factories/IAToken__factory.d.ts +0 -198
  227. package/lib/types/factories/IAToken__factory.js +0 -267
  228. package/lib/types/factories/ILendingPool__factory.d.ts +0 -134
  229. package/lib/types/factories/ILendingPool__factory.js +0 -183
  230. package/lib/types/factories/ILidoV1Adapter.sol/ILidoV1AdapterEvents__factory.d.ts +0 -18
  231. package/lib/types/factories/ILidoV1Adapter.sol/ILidoV1AdapterExceptions__factory.d.ts +0 -12
  232. package/lib/types/factories/ILidoV1Adapter.sol/ILidoV1AdapterExceptions__factory.js +0 -24
  233. package/lib/types/factories/ILidoV1Adapter.sol/index.d.ts +0 -3
  234. package/lib/types/factories/ILidoV1Adapter.sol/index.js +0 -12
  235. package/lib/types/factories/IPoolV3.sol/IPoolBase__factory.d.ts +0 -80
  236. package/lib/types/factories/WATokenZapper__factory.d.ts +0 -161
  237. package/lib/types/factories/WATokenZapper__factory.js +0 -227
  238. package/lib/types/factories/WETHZapper__factory.d.ts +0 -138
  239. package/lib/types/factories/WETHZapper__factory.js +0 -198
  240. package/lib/types/factories/WstETHZapper__factory.d.ts +0 -161
  241. package/lib/types/factories/WstETHZapper__factory.js +0 -227
  242. package/lib/types/factories/draft-IERC20Permit.sol/index.d.ts +0 -1
  243. package/lib/types/factories/draft-IERC20Permit.sol/index.js +0 -8
  244. /package/lib/{types/AaveV2_WrappedAToken.sol/IWrappedATokenEvents.js → payload/gauge.js} +0 -0
  245. /package/lib/types/{AaveV2_WrappedAToken.sol/WrappedAToken.js → IAirdropDistributor.sol/IAirdropDistributor.js} +0 -0
  246. /package/lib/types/{AaveV2_WrappedAToken.sol/index.js → IAirdropDistributor.sol/IAirdropDistributorEvents.js} +0 -0
  247. /package/lib/types/{ILidoV1Adapter.sol → IAirdropDistributor.sol}/index.js +0 -0
  248. /package/lib/types/{IConvexV1BoosterAdapter.js → IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapter.js} +0 -0
  249. /package/lib/types/{ERC20.js → IConvexV1BoosterAdapter.sol/IConvexV1BoosterAdapterEvents.js} +0 -0
  250. /package/lib/types/{draft-IERC20Permit.sol → IConvexV1BoosterAdapter.sol}/index.js +0 -0
  251. /package/lib/types/{IAToken.js → ICreditConfiguratorV3.sol/ICreditConfiguratorV3.js} +0 -0
  252. /package/lib/types/{ILendingPool.js → ICreditConfiguratorV3.sol/ICreditConfiguratorV3Events.js} +0 -0
  253. /package/lib/types/{ILidoV1Adapter.sol/ILidoV1Adapter.js → ICreditConfiguratorV3.sol/index.js} +0 -0
  254. /package/lib/types/{ILidoV1Adapter.sol/ILidoV1AdapterEvents.js → IDegenDistributor.sol/IDegenDistributor.js} +0 -0
  255. /package/lib/types/{ILidoV1Adapter.sol/ILidoV1AdapterExceptions.js → IDegenDistributor.sol/IDegenDistributorEvents.js} +0 -0
  256. /package/lib/types/{IPoolV3.sol/IPoolBase.js → IDegenDistributor.sol/index.js} +0 -0
  257. /package/lib/types/{draft-IERC20Permit.sol/IERC20Permit.js → IERC20Permit.js} +0 -0
  258. /package/lib/types/{IRouter.js → IERC20ZapperDeposits.js} +0 -0
  259. /package/lib/types/{WATokenZapper.js → IETHZapperDeposits.js} +0 -0
  260. /package/lib/types/{WERC20ZapperBase.js → IGasPricer.js} +0 -0
  261. /package/lib/types/{WETHZapper.js → IGearStakingV3.sol/IGearStakingV3.js} +0 -0
  262. /package/lib/types/{WstETHZapper.js → IGearStakingV3.sol/IGearStakingV3Events.js} +0 -0
  263. /package/lib/types/{ZapperBase.js → IGearStakingV3.sol/index.js} +0 -0
  264. /package/lib/types/factories/{draft-IERC20Permit.sol/IERC20Permit__factory.js → IERC20Permit__factory.js} +0 -0
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreditAccountData = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
- const apy_1 = require("../apy");
6
5
  const formatter_1 = require("../utils/formatter");
6
+ const math_1 = require("../utils/math");
7
7
  const price_1 = require("../utils/price");
8
8
  class CreditAccountData {
9
+ isSuccessful;
9
10
  addr;
10
11
  borrower;
11
12
  creditManager;
@@ -14,6 +15,7 @@ class CreditAccountData {
14
15
  since;
15
16
  expirationDate;
16
17
  version;
18
+ cmName;
17
19
  enabledTokenMask;
18
20
  healthFactor;
19
21
  isDeleting;
@@ -27,7 +29,6 @@ class CreditAccountData {
27
29
  totalValue;
28
30
  totalValueUSD;
29
31
  twvUSD;
30
- cumulativeIndexNow;
31
32
  cumulativeIndexLastUpdate;
32
33
  cumulativeQuotaInterest;
33
34
  activeBots;
@@ -39,6 +40,7 @@ class CreditAccountData {
39
40
  quotedTokens = {};
40
41
  schedultedWithdrawals;
41
42
  constructor(payload) {
43
+ this.isSuccessful = payload.isSuccessful;
42
44
  this.addr = payload.addr.toLowerCase();
43
45
  this.borrower = payload.borrower.toLowerCase();
44
46
  this.creditManager = payload.creditManager.toLowerCase();
@@ -47,16 +49,17 @@ class CreditAccountData {
47
49
  this.since = Number((0, sdk_gov_1.toBigInt)(payload.since));
48
50
  this.expirationDate = Number((0, sdk_gov_1.toBigInt)(payload.expirationDate));
49
51
  this.version = payload.cfVersion?.toNumber();
50
- this.healthFactor = Number((0, sdk_gov_1.toBigInt)(payload.healthFactor));
52
+ this.cmName = payload.cmName;
53
+ this.healthFactor = Number((0, sdk_gov_1.toBigInt)(payload.healthFactor || 0n));
51
54
  this.enabledTokenMask = (0, sdk_gov_1.toBigInt)(payload.enabledTokensMask);
52
55
  this.isDeleting = false;
53
56
  this.borrowedAmount = (0, sdk_gov_1.toBigInt)(payload.debt);
54
- this.accruedInterest = (0, sdk_gov_1.toBigInt)(payload.accruedInterest);
55
- this.accruedFees = (0, sdk_gov_1.toBigInt)(payload.accruedFees);
57
+ this.accruedInterest = (0, sdk_gov_1.toBigInt)(payload.accruedInterest || 0n);
58
+ this.accruedFees = (0, sdk_gov_1.toBigInt)(payload.accruedFees || 0n);
56
59
  this.borrowedAmountPlusInterestAndFees =
57
60
  this.borrowedAmount + this.accruedInterest + this.accruedFees;
58
61
  this.totalDebtUSD = (0, sdk_gov_1.toBigInt)(payload.totalDebtUSD);
59
- this.totalValue = (0, sdk_gov_1.toBigInt)(payload.totalValue);
62
+ this.totalValue = (0, sdk_gov_1.toBigInt)(payload.totalValue || 0n);
60
63
  this.totalValueUSD = (0, sdk_gov_1.toBigInt)(payload.totalValueUSD);
61
64
  this.twvUSD = (0, sdk_gov_1.toBigInt)(payload.twvUSD);
62
65
  this.baseBorrowRate = (0, formatter_1.rayToNumber)((0, sdk_gov_1.toBigInt)(payload.baseBorrowRate) *
@@ -65,7 +68,6 @@ class CreditAccountData {
65
68
  this.borrowRate = (0, formatter_1.rayToNumber)((0, sdk_gov_1.toBigInt)(payload.aggregatedBorrowRate) *
66
69
  sdk_gov_1.PERCENTAGE_DECIMALS *
67
70
  sdk_gov_1.PERCENTAGE_FACTOR);
68
- this.cumulativeIndexNow = (0, sdk_gov_1.toBigInt)(payload.cumulativeIndexNow);
69
71
  this.cumulativeIndexLastUpdate = (0, sdk_gov_1.toBigInt)(payload.cumulativeIndexLastUpdate);
70
72
  this.cumulativeQuotaInterest = (0, sdk_gov_1.toBigInt)(payload.cumulativeQuotaInterest);
71
73
  this.activeBots = payload.activeBots.map(b => b.toLowerCase());
@@ -79,7 +81,8 @@ class CreditAccountData {
79
81
  isEnabled: b.isEnabled,
80
82
  isQuoted: b.isQuoted,
81
83
  quota: (0, sdk_gov_1.toBigInt)(b.quota),
82
- quotaRate: b.quotaRate,
84
+ quotaRate: Number((0, sdk_gov_1.toBigInt)(b.quotaRate) * sdk_gov_1.PERCENTAGE_DECIMALS),
85
+ quotaCumulativeIndexLU: (0, sdk_gov_1.toBigInt)(b.quotaCumulativeIndexLU),
83
86
  };
84
87
  if (!b.isForbidden) {
85
88
  this.balances[token] = balance.balance;
@@ -103,9 +106,6 @@ class CreditAccountData {
103
106
  setDeleteInProgress(d) {
104
107
  this.isDeleting = d;
105
108
  }
106
- balancesSorted(prices, tokens) {
107
- return CreditAccountData.sortBalances(this.balances, prices, tokens).map(([token, balance]) => ({ token, balance }));
108
- }
109
109
  static sortBalances(balances, prices, tokens) {
110
110
  return Object.entries(balances).sort(([addr1, amount1], [addr2, amount2]) => {
111
111
  const addr1Lc = addr1.toLowerCase();
@@ -147,41 +147,42 @@ class CreditAccountData {
147
147
  static calcMaxDebtIncrease(healthFactor, borrowAmountPlusInterest, underlyingLT, minHf = Number(sdk_gov_1.PERCENTAGE_FACTOR)) {
148
148
  const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHf)) /
149
149
  BigInt(minHf - underlyingLT);
150
- return result < 0 ? 0n : result;
150
+ return math_1.BigIntMath.max(0n, result);
151
151
  }
152
- static calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }) {
152
+ static calcOverallAPY({ caAssets, lpAPY, prices, quotas, quotaRates, totalValue, debt, baseBorrowRate, underlyingToken, }) {
153
153
  if (!lpAPY ||
154
154
  !totalValue ||
155
155
  totalValue <= 0n ||
156
156
  !debt ||
157
157
  totalValue <= debt)
158
158
  return undefined;
159
+ const underlyingTokenAddressLC = underlyingToken.toLowerCase();
160
+ const underlyingTokenSymbol = sdk_gov_1.tokenSymbolByAddress[underlyingTokenAddressLC] || "";
161
+ const underlyingTokenDecimals = sdk_gov_1.decimals[underlyingTokenSymbol] || 18;
162
+ const underlyingPrice = prices[underlyingTokenAddressLC];
159
163
  const assetAPYMoney = caAssets.reduce((acc, { token: tokenAddress, balance: amount }) => {
160
164
  const tokenAddressLC = tokenAddress.toLowerCase();
161
- const symbol = sdk_gov_1.tokenSymbolByAddress[tokenAddressLC];
162
- if (!(0, apy_1.isTokenWithAPY)(symbol))
163
- return acc;
165
+ const symbol = sdk_gov_1.tokenSymbolByAddress[tokenAddressLC] || "";
164
166
  const apy = lpAPY[symbol] || 0;
165
167
  const price = prices[tokenAddressLC] || 0n;
166
168
  const tokenDecimals = sdk_gov_1.decimals[symbol];
167
169
  const money = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
168
170
  const apyMoney = money * BigInt(apy);
169
- return acc + apyMoney;
171
+ const { rate: quotaAPY = 0, isActive = false } = quotaRates?.[tokenAddressLC] || {};
172
+ const { balance: quotaBalance = 0n } = quotas[tokenAddressLC] || {};
173
+ const quotaAmount = isActive ? quotaBalance : 0n;
174
+ const quotaMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice || 0n, quotaAmount, underlyingTokenDecimals);
175
+ const quotaAPYMoney = quotaMoney * BigInt(quotaAPY);
176
+ return acc + apyMoney - quotaAPYMoney;
170
177
  }, 0n);
171
- const underlyingTokenAddressLC = underlyingToken.toLowerCase();
172
- const underlyingTokenSymbol = sdk_gov_1.tokenSymbolByAddress[underlyingTokenAddressLC] || "";
173
- const underlyingTokenDecimals = sdk_gov_1.decimals[underlyingTokenSymbol] || 18;
174
- const underlyingPrice = prices[underlyingTokenAddressLC] || sdk_gov_1.PRICE_DECIMALS;
175
178
  const assetAPYAmountInUnderlying = price_1.PriceUtils.convertByPrice(assetAPYMoney, {
176
- price: underlyingPrice,
179
+ price: underlyingPrice || sdk_gov_1.PRICE_DECIMALS,
177
180
  decimals: underlyingTokenDecimals,
178
181
  });
179
- const debtAPY = debt * BigInt(borrowRate);
182
+ const debtAPY = debt * BigInt(baseBorrowRate);
180
183
  const yourAssets = totalValue - debt;
181
- const apyInPercent = ((assetAPYAmountInUnderlying - debtAPY) * sdk_gov_1.WAD) /
182
- yourAssets /
183
- sdk_gov_1.PERCENTAGE_FACTOR;
184
- return Number((0, formatter_1.toSignificant)(apyInPercent, sdk_gov_1.WAD_DECIMALS_POW));
184
+ const apyInPercent = (assetAPYAmountInUnderlying - debtAPY) / yourAssets;
185
+ return apyInPercent;
185
186
  }
186
187
  hash() {
187
188
  return CreditAccountData.hash(this.creditManager, this.borrower);
@@ -189,22 +190,85 @@ class CreditAccountData {
189
190
  static hash(creditManager, borrower) {
190
191
  return `${creditManager.toLowerCase()}:${borrower.toLowerCase()}`;
191
192
  }
192
- static calcHealthFactor({ assets, prices, liquidationThresholds, underlyingToken, borrowed, }) {
193
+ static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, borrowed, prices, }) {
194
+ const [, underlyingDecimals] = (0, sdk_gov_1.extractTokenData)(underlyingToken);
195
+ const underlyingPrice = prices[underlyingToken] || 0n;
193
196
  const assetLTMoney = assets.reduce((acc, { token: tokenAddress, balance: amount }) => {
194
- const tokenSymbol = sdk_gov_1.tokenSymbolByAddress[tokenAddress.toLowerCase()];
195
- const tokenDecimals = sdk_gov_1.decimals[tokenSymbol];
196
- const lt = liquidationThresholds[tokenAddress.toLowerCase()] || 0n;
197
- const price = prices[tokenAddress.toLowerCase()] || 0n;
198
- const money = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
197
+ const [, tokenDecimals] = (0, sdk_gov_1.extractTokenData)(tokenAddress);
198
+ const lt = liquidationThresholds[tokenAddress] || 0n;
199
+ const price = prices[tokenAddress] || 0n;
200
+ const tokenMoney = price_1.PriceUtils.calcTotalPrice(price, amount, tokenDecimals);
201
+ const { isActive = false } = quotasInfo?.[tokenAddress] || {};
202
+ const quota = quotas[tokenAddress];
203
+ const quotaBalance = isActive ? quota?.balance || 0n : 0n;
204
+ const quotaMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice, quotaBalance, underlyingDecimals);
205
+ // if quota is undefined, then it is not a quoted token
206
+ const money = quota
207
+ ? math_1.BigIntMath.min(quotaMoney, tokenMoney)
208
+ : tokenMoney;
199
209
  const ltMoney = money * lt;
200
210
  return acc + ltMoney;
201
211
  }, 0n);
202
- const underlyingSymbol = sdk_gov_1.tokenSymbolByAddress[underlyingToken.toLowerCase()];
203
- const underlyingDecimals = sdk_gov_1.decimals[underlyingSymbol];
204
- const underlyingPrice = prices[underlyingToken.toLowerCase()] || sdk_gov_1.PRICE_DECIMALS;
205
- const borrowedMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice, borrowed, underlyingDecimals);
212
+ const borrowedMoney = price_1.PriceUtils.calcTotalPrice(underlyingPrice || sdk_gov_1.PRICE_DECIMALS, borrowed, underlyingDecimals);
206
213
  const hfInPercent = borrowedMoney > 0n ? assetLTMoney / borrowedMoney : 0n;
207
214
  return Number(hfInPercent);
208
215
  }
216
+ static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, allowedToSpend, allowedToObtain, }) {
217
+ const r = Object.values(quotas).reduce((acc, cmQuota) => {
218
+ const { token, isActive } = cmQuota;
219
+ const { quota: initialQuota = 0n } = initialQuotas[token] || {};
220
+ if (!isActive) {
221
+ acc.desiredQuota[token] = {
222
+ balance: initialQuota,
223
+ token,
224
+ };
225
+ return acc;
226
+ }
227
+ const after = assetsAfterUpdate[token];
228
+ const { amountInTarget = 0n } = after || {};
229
+ const desiredQuota = (amountInTarget * 101n) / 100n;
230
+ const quotaChange = desiredQuota - initialQuota;
231
+ const correctIncrease = after && allowedToObtain[token] && quotaChange > 0;
232
+ const correctDecrease = after && allowedToSpend[token] && quotaChange < 0;
233
+ if (correctIncrease || correctDecrease) {
234
+ acc.desiredQuota[token] = {
235
+ balance: desiredQuota,
236
+ token,
237
+ };
238
+ }
239
+ else {
240
+ acc.desiredQuota[token] = {
241
+ balance: initialQuota,
242
+ token,
243
+ };
244
+ }
245
+ if (correctIncrease) {
246
+ acc.quotaIncrease.push({
247
+ balance: quotaChange,
248
+ token,
249
+ });
250
+ }
251
+ if (correctDecrease) {
252
+ acc.quotaDecrease.push({
253
+ balance: quotaChange,
254
+ token,
255
+ });
256
+ }
257
+ return acc;
258
+ }, { desiredQuota: {}, quotaIncrease: [], quotaDecrease: [] });
259
+ return r;
260
+ }
261
+ static calcQuotaBorrowRate({ quotas, quotaRates, borrowAmount, }) {
262
+ if (borrowAmount <= 0)
263
+ return 0;
264
+ const totalRateBalance = Object.values(quotas).reduce((acc, { token, balance }) => {
265
+ const { rate = 0, isActive = false } = quotaRates?.[token] || {};
266
+ const quotaBalance = isActive ? balance : 0n;
267
+ const rateBalance = quotaBalance * BigInt(rate);
268
+ return acc + rateBalance;
269
+ }, 0n);
270
+ const quotaBorrowRate = Number(totalRateBalance / borrowAmount);
271
+ return quotaBorrowRate;
272
+ }
209
273
  }
210
274
  exports.CreditAccountData = CreditAccountData;