@gearbox-protocol/sdk 16.2.0 → 16.3.0-next.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 (528) hide show
  1. package/dist/cjs/history/assembleOperations.js +3 -3
  2. package/dist/cjs/history/classifyMulticallOperations.js +7 -7
  3. package/dist/cjs/history/index.js +13 -0
  4. package/dist/cjs/history/parseCreditAccountTransaction.js +5 -5
  5. package/dist/cjs/{preview → history}/trace/errors.js +1 -1
  6. package/dist/cjs/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
  7. package/dist/cjs/{preview → history}/trace/extractTransfers.js +3 -3
  8. package/dist/cjs/{preview → history}/trace/findFacadeCalls.js +3 -3
  9. package/dist/cjs/history/trace/index.js +14 -0
  10. package/dist/cjs/model/errors/index.js +37 -0
  11. package/dist/cjs/model/errors/liquidation-errors.js +32 -0
  12. package/dist/cjs/model/errors/operation-errors.js +135 -0
  13. package/dist/cjs/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
  14. package/dist/cjs/model/errors/prepare-errors.js +108 -0
  15. package/dist/cjs/model/errors/preview-errors.js +12 -0
  16. package/dist/cjs/model/index.js +40 -2
  17. package/dist/cjs/model/positions.js +1 -1
  18. package/dist/cjs/model/result.js +0 -8
  19. package/dist/cjs/model/rwa.js +40 -0
  20. package/dist/cjs/onchain/accounts/index.js +0 -2
  21. package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
  22. package/dist/cjs/onchain/accounts/intents/index.js +38 -35
  23. package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
  24. package/dist/cjs/onchain/accounts/intents/math.js +19 -15
  25. package/dist/cjs/onchain/accounts/intents/open-strategy.js +6 -4
  26. package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
  27. package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
  28. package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
  29. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
  30. package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
  31. package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
  32. package/dist/cjs/onchain/accounts/intents/view.js +1 -1
  33. package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
  34. package/dist/cjs/onchain/index.js +122 -36
  35. package/dist/cjs/onchain/market/MarketSuite.js +7 -1
  36. package/dist/cjs/onchain/market/adapters/index.js +1 -0
  37. package/dist/cjs/onchain/market/credit/CreditSuite.js +47 -15
  38. package/dist/cjs/onchain/market/index.js +0 -6
  39. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
  40. package/dist/cjs/onchain/market/oracle/index.js +0 -2
  41. package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
  42. package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
  43. package/dist/cjs/onchain/market/rwa/index.js +0 -4
  44. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +7 -7
  45. package/dist/cjs/onchain/market/rwa/securitize/constants.js +0 -2
  46. package/dist/cjs/onchain/market/rwa/securitize/index.js +1 -3
  47. package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
  48. package/dist/cjs/onchain/market/rwa/types.js +0 -7
  49. package/dist/cjs/onchain/market/zapper/index.js +0 -1
  50. package/dist/cjs/onchain/pools/PoolService.js +10 -16
  51. package/dist/cjs/onchain/preview/index.js +41 -0
  52. package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
  53. package/dist/cjs/onchain/preview/parse/index.js +14 -0
  54. package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
  55. package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
  56. package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
  57. package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
  58. package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
  59. package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
  60. package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
  61. package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
  62. package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
  63. package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
  64. package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
  65. package/dist/cjs/onchain/preview/preview/index.js +26 -0
  66. package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
  67. package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
  68. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
  69. package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
  70. package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
  71. package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
  72. package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
  73. package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
  74. package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
  75. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
  76. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
  77. package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
  78. package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
  79. package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
  80. package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
  81. package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
  82. package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
  83. package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
  84. package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
  85. package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
  86. package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
  87. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
  88. package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
  89. package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
  90. package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
  91. package/dist/cjs/onchain/validation/bundles/index.js +35 -0
  92. package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
  93. package/dist/cjs/onchain/validation/checkOperation.js +62 -0
  94. package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
  95. package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
  96. package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
  97. package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
  98. package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
  99. package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
  100. package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
  101. package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
  102. package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
  103. package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
  104. package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
  105. package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
  106. package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
  107. package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
  108. package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
  109. package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
  110. package/dist/cjs/onchain/validation/checks/index.js +31 -0
  111. package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
  112. package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
  113. package/dist/cjs/onchain/validation/helpers/index.js +11 -0
  114. package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
  115. package/dist/cjs/onchain/validation/index.js +85 -27
  116. package/dist/cjs/onchain/validation/raise.js +33 -0
  117. package/dist/cjs/sdk/index.js +6 -11
  118. package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
  119. package/dist/cjs/sdk/prepare/PrepareApi.js +40 -50
  120. package/dist/cjs/sdk/prepare/index.js +7 -11
  121. package/dist/cjs/sdk/prepare/types.js +0 -4
  122. package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
  123. package/dist/esm/dev/AccountOpener.js +1 -1
  124. package/dist/esm/dev/withdrawalUtils.js +1 -1
  125. package/dist/esm/history/assembleOperations.js +2 -2
  126. package/dist/esm/history/classifyMulticallOperations.js +2 -2
  127. package/dist/esm/history/index.js +6 -1
  128. package/dist/esm/history/parseCreditAccountTransaction.js +3 -3
  129. package/dist/esm/{preview → history}/trace/errors.js +1 -1
  130. package/dist/esm/{preview → history}/trace/extractAdapterCallTraces.js +1 -1
  131. package/dist/esm/{preview → history}/trace/extractTransfers.js +2 -2
  132. package/dist/esm/{preview → history}/trace/findFacadeCalls.js +1 -1
  133. package/dist/esm/model/errors/index.js +7 -0
  134. package/dist/esm/model/errors/liquidation-errors.js +29 -0
  135. package/dist/esm/model/errors/operation-errors.js +121 -0
  136. package/dist/esm/{onchain/market/oracle/errors.js → model/errors/oracle-errors.js} +1 -1
  137. package/dist/esm/model/errors/prepare-errors.js +97 -0
  138. package/dist/esm/model/errors/preview-errors.js +11 -0
  139. package/dist/esm/model/index.js +9 -3
  140. package/dist/esm/model/positions.js +1 -1
  141. package/dist/esm/model/result.js +1 -8
  142. package/dist/esm/model/rwa.js +37 -0
  143. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  144. package/dist/esm/onchain/accounts/index.js +1 -2
  145. package/dist/esm/onchain/accounts/intents/guards.js +29 -52
  146. package/dist/esm/onchain/accounts/intents/index.js +39 -35
  147. package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
  148. package/dist/esm/onchain/accounts/intents/math.js +18 -14
  149. package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -6
  150. package/dist/esm/onchain/accounts/intents/plan.js +51 -47
  151. package/dist/esm/onchain/accounts/intents/realize.js +26 -24
  152. package/dist/esm/onchain/accounts/intents/tail.js +14 -11
  153. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +7 -0
  154. package/dist/esm/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
  155. package/dist/esm/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
  156. package/dist/esm/onchain/accounts/intents/view.js +1 -1
  157. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  158. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  159. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  160. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  161. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  162. package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +0 -1
  163. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  164. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  165. package/dist/esm/onchain/index.js +61 -10
  166. package/dist/esm/onchain/market/MarketSuite.js +7 -1
  167. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  168. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  169. package/dist/esm/onchain/market/adapters/index.js +1 -0
  170. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  171. package/dist/esm/onchain/market/credit/CreditSuite.js +47 -15
  172. package/dist/esm/onchain/market/index.js +3 -5
  173. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  174. package/dist/esm/onchain/market/oracle/index.js +1 -2
  175. package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
  176. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  177. package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
  178. package/dist/esm/onchain/market/rwa/index.js +3 -4
  179. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +2 -2
  180. package/dist/esm/onchain/market/rwa/securitize/constants.js +1 -2
  181. package/dist/esm/onchain/market/rwa/securitize/index.js +3 -3
  182. package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
  183. package/dist/esm/onchain/market/rwa/types.js +1 -7
  184. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  185. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  186. package/dist/esm/onchain/market/zapper/index.js +0 -1
  187. package/dist/esm/onchain/pools/PoolService.js +10 -16
  188. package/dist/esm/onchain/preview/index.js +20 -0
  189. package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
  190. package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
  191. package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
  192. package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
  193. package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
  194. package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
  195. package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
  196. package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
  197. package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
  198. package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
  199. package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
  200. package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
  201. package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
  202. package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
  203. package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
  204. package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
  205. package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
  206. package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
  207. package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
  208. package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
  209. package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
  210. package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
  211. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  212. package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
  213. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
  214. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
  215. package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
  216. package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
  217. package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
  218. package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
  219. package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
  220. package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
  221. package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
  222. package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
  223. package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
  224. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
  225. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
  226. package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
  227. package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
  228. package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
  229. package/dist/esm/onchain/validation/bundles/index.js +18 -0
  230. package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
  231. package/dist/esm/onchain/validation/checkOperation.js +61 -0
  232. package/dist/esm/onchain/validation/checkSimulation.js +59 -0
  233. package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
  234. package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
  235. package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
  236. package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
  237. package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
  238. package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
  239. package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
  240. package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
  241. package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
  242. package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
  243. package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
  244. package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
  245. package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
  246. package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
  247. package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
  248. package/dist/esm/onchain/validation/checks/index.js +16 -0
  249. package/dist/esm/onchain/validation/helpers/amount.js +11 -0
  250. package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
  251. package/dist/esm/onchain/validation/helpers/index.js +4 -0
  252. package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
  253. package/dist/esm/onchain/validation/index.js +43 -4
  254. package/dist/esm/onchain/validation/raise.js +31 -0
  255. package/dist/esm/sdk/index.js +2 -3
  256. package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
  257. package/dist/esm/sdk/prepare/PrepareApi.js +25 -35
  258. package/dist/esm/sdk/prepare/index.js +3 -3
  259. package/dist/esm/sdk/prepare/types.js +1 -2
  260. package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
  261. package/dist/types/history/assembleOperations.d.ts +4 -5
  262. package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
  263. package/dist/types/history/index.d.ts +8 -2
  264. package/dist/types/history/mapOperations.d.ts +1 -1
  265. package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
  266. package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
  267. package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
  268. package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
  269. package/dist/types/{preview → history}/trace/types.d.ts +1 -1
  270. package/dist/types/history/types.d.ts +2 -3
  271. package/dist/types/model/errors/base.d.ts +28 -0
  272. package/dist/types/model/errors/index.d.ts +7 -0
  273. package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
  274. package/dist/types/model/errors/operation-errors.d.ts +216 -0
  275. package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
  276. package/dist/types/model/errors/prepare-errors.d.ts +131 -0
  277. package/dist/types/model/errors/preview-errors.d.ts +72 -0
  278. package/dist/types/model/index.d.ts +11 -4
  279. package/dist/types/model/opportunities.d.ts +3 -2
  280. package/dist/types/model/positions.d.ts +2 -2
  281. package/dist/types/model/previews.d.ts +52 -113
  282. package/dist/types/model/result.d.ts +4 -8
  283. package/dist/types/model/rwa.d.ts +143 -0
  284. package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
  285. package/dist/types/onchain/accounts/index.d.ts +2 -4
  286. package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
  287. package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
  288. package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
  289. package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
  290. package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
  291. package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
  292. package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
  293. package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
  294. package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
  295. package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
  296. package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
  297. package/dist/types/onchain/accounts/types.d.ts +2 -1
  298. package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
  299. package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
  300. package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
  301. package/dist/types/onchain/index.d.ts +68 -13
  302. package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
  303. package/dist/types/onchain/market/adapters/index.d.ts +2 -1
  304. package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
  305. package/dist/types/onchain/market/credit/CreditSuite.d.ts +20 -8
  306. package/dist/types/onchain/market/credit/index.d.ts +2 -2
  307. package/dist/types/onchain/market/credit/types.d.ts +11 -1
  308. package/dist/types/onchain/market/index.d.ts +6 -7
  309. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
  310. package/dist/types/onchain/market/oracle/index.d.ts +1 -2
  311. package/dist/types/onchain/market/oracle/types.d.ts +1 -1
  312. package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
  313. package/dist/types/onchain/market/rwa/index.d.ts +4 -4
  314. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +3 -2
  315. package/dist/types/onchain/market/rwa/securitize/constants.d.ts +1 -2
  316. package/dist/types/onchain/market/rwa/securitize/index.d.ts +3 -3
  317. package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
  318. package/dist/types/onchain/market/rwa/types.d.ts +6 -32
  319. package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
  320. package/dist/types/onchain/market/zapper/index.d.ts +1 -2
  321. package/dist/types/onchain/market/zapper/types.d.ts +1 -1
  322. package/dist/types/onchain/pools/types.d.ts +2 -2
  323. package/dist/types/onchain/preview/index.d.ts +24 -0
  324. package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
  325. package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
  326. package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
  327. package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
  328. package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
  329. package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
  330. package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
  331. package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
  332. package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
  333. package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
  334. package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
  335. package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
  336. package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
  337. package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
  338. package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
  339. package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
  340. package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
  341. package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
  342. package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
  343. package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
  344. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
  345. package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
  346. package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
  347. package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
  348. package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
  349. package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
  350. package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
  351. package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
  352. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
  353. package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
  354. package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
  355. package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
  356. package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
  357. package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
  358. package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
  359. package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
  360. package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
  361. package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
  362. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
  363. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
  364. package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
  365. package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
  366. package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
  367. package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
  368. package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
  369. package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
  370. package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
  371. package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
  372. package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
  373. package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
  374. package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
  375. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
  376. package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
  377. package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
  378. package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
  379. package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
  380. package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
  381. package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
  382. package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
  383. package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
  384. package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
  385. package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
  386. package/dist/types/onchain/validation/checks/index.d.ts +16 -0
  387. package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
  388. package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
  389. package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
  390. package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
  391. package/dist/types/onchain/validation/index.d.ts +43 -4
  392. package/dist/types/onchain/validation/raise.d.ts +33 -0
  393. package/dist/types/sdk/execute/types.d.ts +2 -2
  394. package/dist/types/sdk/index.d.ts +5 -6
  395. package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
  396. package/dist/types/sdk/liquidations/types.d.ts +8 -0
  397. package/dist/types/sdk/prepare/PrepareApi.d.ts +5 -4
  398. package/dist/types/sdk/prepare/index.d.ts +5 -5
  399. package/dist/types/sdk/prepare/types.d.ts +41 -22
  400. package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
  401. package/dist/types/sdk/preview/index.d.ts +2 -2
  402. package/dist/types/sdk/preview/types.d.ts +30 -7
  403. package/package.json +1 -6
  404. package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
  405. package/dist/cjs/onchain/market/zapper/errors.js +0 -1
  406. package/dist/cjs/onchain/validation/checks.js +0 -258
  407. package/dist/cjs/onchain/validation/refusal.js +0 -39
  408. package/dist/cjs/preview/index.js +0 -86
  409. package/dist/cjs/preview/package.json +0 -1
  410. package/dist/cjs/preview/parse/errors.js +0 -1
  411. package/dist/cjs/preview/parse/index.js +0 -15
  412. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
  413. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
  414. package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
  415. package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
  416. package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
  417. package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
  418. package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
  419. package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
  420. package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
  421. package/dist/cjs/preview/prerequisites/helpers.js +0 -23
  422. package/dist/cjs/preview/prerequisites/index.js +0 -12
  423. package/dist/cjs/preview/preview/errors.js +0 -85
  424. package/dist/cjs/preview/preview/index.js +0 -33
  425. package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
  426. package/dist/cjs/preview/preview/previewOperation.js +0 -100
  427. package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
  428. package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
  429. package/dist/cjs/preview/preview/replayMulticall.js +0 -19
  430. package/dist/cjs/preview/simulate/errors.js +0 -73
  431. package/dist/cjs/preview/simulate/index.js +0 -11
  432. package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
  433. package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
  434. package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
  435. package/dist/cjs/preview/simulate/types.js +0 -1
  436. package/dist/cjs/preview/trace/index.js +0 -14
  437. package/dist/cjs/preview/trace/types.js +0 -1
  438. package/dist/cjs/preview/types.js +0 -1
  439. package/dist/cjs/preview/validate/checkOperation.js +0 -187
  440. package/dist/cjs/preview/validate/checkSimulation.js +0 -39
  441. package/dist/cjs/preview/validate/index.js +0 -8
  442. package/dist/cjs/sdk/prepare/errors.js +0 -114
  443. package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
  444. package/dist/esm/onchain/market/zapper/errors.js +0 -1
  445. package/dist/esm/onchain/validation/checks.js +0 -238
  446. package/dist/esm/onchain/validation/refusal.js +0 -36
  447. package/dist/esm/preview/index.js +0 -38
  448. package/dist/esm/preview/package.json +0 -1
  449. package/dist/esm/preview/parse/errors.js +0 -1
  450. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
  451. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
  452. package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
  453. package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
  454. package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
  455. package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
  456. package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
  457. package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
  458. package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
  459. package/dist/esm/preview/prerequisites/helpers.js +0 -22
  460. package/dist/esm/preview/prerequisites/index.js +0 -7
  461. package/dist/esm/preview/preview/errors.js +0 -79
  462. package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
  463. package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
  464. package/dist/esm/preview/preview/replayMulticall.js +0 -18
  465. package/dist/esm/preview/simulate/errors.js +0 -71
  466. package/dist/esm/preview/simulate/index.js +0 -6
  467. package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
  468. package/dist/esm/preview/simulate/simulateOperation.js +0 -28
  469. package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
  470. package/dist/esm/preview/simulate/types.js +0 -1
  471. package/dist/esm/preview/trace/types.js +0 -1
  472. package/dist/esm/preview/types.js +0 -1
  473. package/dist/esm/preview/validate/checkOperation.js +0 -183
  474. package/dist/esm/preview/validate/checkSimulation.js +0 -38
  475. package/dist/esm/preview/validate/index.js +0 -3
  476. package/dist/esm/sdk/prepare/errors.js +0 -108
  477. package/dist/types/model/errors.d.ts +0 -46
  478. package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
  479. package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
  480. package/dist/types/onchain/validation/checks.d.ts +0 -164
  481. package/dist/types/onchain/validation/refusal.d.ts +0 -242
  482. package/dist/types/preview/index.d.ts +0 -47
  483. package/dist/types/preview/parse/errors.d.ts +0 -29
  484. package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
  485. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
  486. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
  487. package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
  488. package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
  489. package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
  490. package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
  491. package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
  492. package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
  493. package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
  494. package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
  495. package/dist/types/preview/prerequisites/index.d.ts +0 -7
  496. package/dist/types/preview/prerequisites/types.d.ts +0 -53
  497. package/dist/types/preview/preview/errors.d.ts +0 -44
  498. package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
  499. package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
  500. package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
  501. package/dist/types/preview/preview/previewOperation.d.ts +0 -32
  502. package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
  503. package/dist/types/preview/simulate/errors.d.ts +0 -52
  504. package/dist/types/preview/simulate/index.d.ts +0 -7
  505. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
  506. package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
  507. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
  508. package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
  509. package/dist/types/preview/simulate/types.d.ts +0 -48
  510. package/dist/types/preview/types.d.ts +0 -65
  511. package/dist/types/preview/validate/checkOperation.d.ts +0 -71
  512. package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
  513. package/dist/types/preview/validate/index.d.ts +0 -3
  514. package/dist/types/sdk/prepare/errors.d.ts +0 -343
  515. /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
  516. /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
  517. /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
  518. /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
  519. /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
  520. /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
  521. /package/dist/esm/{preview → history}/trace/index.js +0 -0
  522. /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
  523. /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
  524. /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
  525. /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
  526. /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
  527. /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
  528. /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
@@ -1,183 +0,0 @@
1
- import { checkBorrowLimit, checkCollateralised, checkCreditManagerPaused, checkDebtInBand, checkForbiddenToken, checkFunding, checkMarketExpired, checkPoolPaused, checkPoolPayout, checkPoolSunset, checkPreviewError, checkQuotaCount, checkQuotaLimit } from "../../onchain/validation/checks.js";
2
- import { toToken } from "../../onchain/validation/token.js";
3
- import { borrowable } from "../../onchain/accounts/intents/guards.js";
4
- import "../../onchain/index.js";
5
- import { isAddressEqual } from "viem";
6
- //#region src/preview/validate/checkOperation.ts
7
- /**
8
- * Whether a parsed operation may be signed at all — the protocol state that
9
- * `checkPrerequisites` leaves out, since that one covers only what the sender
10
- * can fix themselves.
11
- *
12
- * Synchronous: the preview carries the numbers and the market is attached.
13
- * Reports the most fundamental issue it finds and stops there, which is the one
14
- * a caller acts on.
15
- */
16
- function checkOperation(input, options = {}) {
17
- const { sdk, preview } = input;
18
- const malformed = checkPreviewError("warning" in preview ? preview.warning : void 0);
19
- if (malformed) return malformed;
20
- switch (preview.operation) {
21
- case "Deposit":
22
- case "Mint": return poolIssues(sdk, preview, options, true);
23
- case "Withdraw":
24
- case "Redeem": return poolIssues(sdk, preview, options, false);
25
- case "DelayedCreditAccountOperation": return checkOperation({
26
- sdk,
27
- preview: preview.instantPreview
28
- }, options);
29
- case "OpenCreditAccount":
30
- case "RWAOpenCreditAccount":
31
- case "AdjustCreditAccount": return creditIssues(sdk, preview, options);
32
- case "CloseCreditAccount":
33
- case "RepayCreditAccount": return marketIssues(sdk.marketRegister.findCreditManager(preview.creditManager));
34
- }
35
- }
36
- function poolIssues(sdk, preview, options, isDeposit) {
37
- const market = sdk.marketRegister.findByPool(preview.pool);
38
- return checkPoolPaused({
39
- isPaused: market.pool.pool.isPaused,
40
- pool: preview.pool
41
- }) || checkPoolSunset({
42
- isSunset: market.sunset,
43
- isDeposit,
44
- pool: preview.pool
45
- }) || (isDeposit ? null : checkPoolPayout({
46
- requested: preview.tokenOut.value,
47
- available: market.pool.pool.availableLiquidity,
48
- underlying: preview.tokenOut.token
49
- })) || fundingIssue(options, [preview.tokenIn]);
50
- }
51
- /** What the market itself refuses, whatever the operation does. */
52
- function marketIssues(suite) {
53
- const creditManager = suite.creditManager.address;
54
- return checkCreditManagerPaused({
55
- isPaused: suite.isPaused,
56
- creditManager
57
- }) || checkMarketExpired({
58
- isExpired: suite.isExpired,
59
- creditManager,
60
- expirationDate: suite.creditFacade.expirationDate
61
- });
62
- }
63
- function creditIssues(sdk, preview, options) {
64
- const suite = sdk.marketRegister.findCreditManager(preview.creditManager);
65
- const market = suite.market;
66
- const underlying = toToken(sdk, market.pool.underlying);
67
- const isOpening = preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount";
68
- return marketIssues(suite) || checkDebtInBand({
69
- debt: preview.totalDebt.value,
70
- minDebt: suite.creditFacade.minDebt,
71
- maxDebt: suite.creditFacade.maxDebt,
72
- underlying,
73
- allowZero: !isOpening
74
- }) || borrowIssue(suite, preview, underlying) || forbiddenIssue(suite, preview) || quotaCountIssue(suite, preview) || quotaIssue(market, preview, underlying) || collateralIssue({
75
- totalDebt: preview.totalDebt,
76
- healthFactor: preview.estHealthFactor,
77
- safeHealthFactor: preview.estSafeHealthFactor
78
- }, options) || fundingIssue(options, preview.collateralAdded);
79
- }
80
- /**
81
- * A bar that reads nothing but the projected account, so a parsed transaction
82
- * and a simulated one are held to it by the same code.
83
- *
84
- * These stay separate functions rather than one block because the order the
85
- * checks run in is the answer: `checkOperation` interleaves the checks that
86
- * need an operation's *delta* between them, and the caller acts on the first
87
- * issue reported.
88
- */
89
- function quotaCountIssue(suite, account) {
90
- return checkQuotaCount({
91
- count: account.quotas.filter((q) => q.value > 0n).length,
92
- max: suite.creditManager.maxEnabledTokens
93
- });
94
- }
95
- /**
96
- * What the transaction draws, against what the market can lend right now.
97
- *
98
- * Only a draw is weighed: repaying, or leaving the debt alone, can never exceed
99
- * a ceiling. Opening borrows the whole debt; adjusting borrows
100
- * `totalDebtChange`.
101
- *
102
- * The engine holds every simulation to this already (`assertCanBorrow`), so
103
- * this is here for the transactions it never saw — a pasted calldata reaches
104
- * the confirm screen with nothing else standing between it and a revert.
105
- */
106
- function borrowIssue(suite, preview, underlying) {
107
- const drawn = preview.operation === "AdjustCreditAccount" ? preview.totalDebtChange.value : preview.totalDebt.value;
108
- if (drawn <= 0n) return null;
109
- const { limit, binding } = borrowable(suite);
110
- return checkBorrowLimit({
111
- requested: drawn,
112
- available: limit,
113
- binding,
114
- underlying
115
- });
116
- }
117
- /**
118
- * The account against whichever bars the caller holds it to.
119
- *
120
- * A loan-free account is nothing to weigh: the health factor reports its
121
- * zero-debt sentinel and no bar applies.
122
- *
123
- * {@inheritDoc quotaCountIssue}
124
- */
125
- function collateralIssue(account, options) {
126
- const { minHealthFactor, minSafeHealthFactor, currentHealthFactor } = options;
127
- if (account.totalDebt.value === 0n) return null;
128
- return (minHealthFactor === void 0 ? null : checkCollateralised({
129
- healthFactor: account.healthFactor,
130
- required: minHealthFactor,
131
- safePrices: false,
132
- improvesFrom: currentHealthFactor
133
- })) || (minSafeHealthFactor === void 0 ? null : checkCollateralised({
134
- healthFactor: account.safeHealthFactor,
135
- required: minSafeHealthFactor,
136
- safePrices: true
137
- }));
138
- }
139
- /** The wallet's side of the operation, against the balances it was given. */
140
- function fundingIssue(options, puts) {
141
- const { balances } = options;
142
- if (!balances) return null;
143
- for (const { token, value } of puts) {
144
- const issue = checkFunding({
145
- token,
146
- required: value,
147
- held: balances.get(token.address) ?? 0n
148
- });
149
- if (issue) return issue;
150
- }
151
- return null;
152
- }
153
- function forbiddenIssue(suite, preview) {
154
- const obtained = preview.operation === "AdjustCreditAccount" ? preview.assetsChange : preview.estAssets;
155
- const forbidden = suite.forbiddenTokens;
156
- for (const asset of obtained) {
157
- if (asset.value <= 0n) continue;
158
- const issue = checkForbiddenToken({
159
- token: asset.token,
160
- isForbidden: forbidden.some((f) => isAddressEqual(f, asset.token.address))
161
- });
162
- if (issue) return issue;
163
- }
164
- return null;
165
- }
166
- function quotaIssue(market, preview, underlying) {
167
- const increases = preview.operation === "AdjustCreditAccount" ? preview.quotasChange : preview.quotas;
168
- const { pqk } = market.pool;
169
- for (const q of increases) {
170
- if (q.value <= 0n) continue;
171
- const quota = pqk.hasActiveQuota(q.token.address) ? pqk.quotas.get(q.token.address) : void 0;
172
- const issue = checkQuotaLimit({
173
- token: q.token,
174
- requested: quota ? q.value : void 0,
175
- available: (quota?.limit ?? 0n) - (quota?.totalQuoted ?? 0n),
176
- underlying
177
- });
178
- if (issue) return issue;
179
- }
180
- return null;
181
- }
182
- //#endregion
183
- export { checkOperation, collateralIssue, marketIssues, quotaCountIssue };
@@ -1,38 +0,0 @@
1
- import { checkDebtInBand } from "../../onchain/validation/checks.js";
2
- import { toToken } from "../../onchain/validation/token.js";
3
- import "../../onchain/index.js";
4
- import { collateralIssue, marketIssues, quotaCountIssue } from "./checkOperation.js";
5
- //#region src/preview/validate/checkSimulation.ts
6
- /**
7
- * Whether a simulated operation clears the caller's own bars.
8
- *
9
- * The engine holds an account to the facade's `1.0`, because its guards answer
10
- * "would this revert". A form is wiser to ask for more, and the engine's own
11
- * note says so — a caller wanting the stricter bar applies it itself. This is
12
- * that second opinion, over the numbers the engine already reported.
13
- *
14
- * Three of the checks below the engine does not make at all: both health-factor
15
- * bars are its own `1.0`, and the quota count it never weighs. The other two run
16
- * against the same numbers the engine used, and are here so that a change in the
17
- * engine cannot pass silently.
18
- *
19
- * What is deliberately absent: the forbidden-token, quota-limit and funding
20
- * checks all need the *delta* an operation applies, and `OperationState` reports
21
- * only the state after it. Weighing them against absolutes would refuse a
22
- * forbidden token the account merely holds, or a quota the operation never
23
- * touched. The engine performed all three during the walk, so a simulation that
24
- * came back `ok` has already passed them.
25
- */
26
- function checkSimulation(input, options = {}) {
27
- const { sdk, state } = input;
28
- const suite = sdk.marketRegister.findCreditManager(state.creditManager);
29
- return marketIssues(suite) || checkDebtInBand({
30
- debt: state.totalDebt.value,
31
- minDebt: suite.creditFacade.minDebt,
32
- maxDebt: suite.creditFacade.maxDebt,
33
- underlying: toToken(sdk, suite.market.pool.underlying),
34
- allowZero: true
35
- }) || quotaCountIssue(suite, state) || collateralIssue(state, options);
36
- }
37
- //#endregion
38
- export { checkSimulation };
@@ -1,3 +0,0 @@
1
- import { checkOperation, collateralIssue, marketIssues, quotaCountIssue } from "./checkOperation.js";
2
- import { checkSimulation } from "./checkSimulation.js";
3
- export { checkOperation, checkSimulation, collateralIssue, marketIssues, quotaCountIssue };
@@ -1,108 +0,0 @@
1
- //#region src/sdk/prepare/errors.ts
2
- /**
3
- * One sentence per refusal, naming what was ruled out rather than restating the
4
- * numbers the error already carries.
5
- *
6
- * English and loggable, not a string to put on a screen: a form renders the
7
- * code and the amounts in its own words, see {@link IGearboxError.message}.
8
- **/
9
- const MESSAGES = {
10
- debtOutOfRange: "The debt this request implies is outside the market's band.",
11
- leverageOutOfRange: "The leverage asked for cannot be expressed as a plan.",
12
- insufficientSourceBalance: "Neither the account nor the wallet holds enough to fund this request.",
13
- unsupportedCollateralToken: "This flow does not accept that token.",
14
- unsupportedTokenPair: "No route exists between these two tokens.",
15
- noDelayedRoute: "This request cannot be served as a delayed redemption.",
16
- multipleDelayedWithdrawals: "The source asset has several redemption venues and none was named.",
17
- withdrawalInProgress: "A redemption of this asset is already in flight on the account.",
18
- noRecordedIntent: "The claim names no operation to resume.",
19
- marketPaused: "The market is paused.",
20
- marketExpired: "The market is past its expiration date.",
21
- insufficientPoolLiquidity: "The pool cannot lend what this plan draws.",
22
- quotaLimitReached: "The market takes no more quota for a token this plan holds.",
23
- forbiddenToken: "This plan would increase the balance of a forbidden token.",
24
- insufficientCollateral: "The account would end this transaction under-collateralised.",
25
- poolSunset: "The pool is winding down and takes no more deposits.",
26
- quotaCountExceeded: "The account would hold more quoted tokens than the facade enables at once.",
27
- malformedTransaction: "The transaction could not be replayed."
28
- };
29
- /**
30
- * The engine's refusal, as the error the namespace answers with.
31
- *
32
- * One place does the lifting, so the two shapes cannot drift: `reason` becomes
33
- * `code`, the detail is spread onto the error, and the sentence comes from
34
- * {@link MESSAGES}. A malformed transaction is spelled out rather than spread,
35
- * because its detail names a `code` and a `message` of its own and they are not
36
- * the envelope's.
37
- *
38
- * Generic over the issue it is handed, so a call site that already knows the
39
- * reason gets that reason's error back rather than a union to narrow again.
40
- **/
41
- function toRefusalError(issue) {
42
- if (issue.reason === "malformedTransaction") return {
43
- code: "malformedTransaction",
44
- message: MESSAGES.malformedTransaction,
45
- previewCode: issue.detail.code,
46
- detail: issue.detail.message
47
- };
48
- return {
49
- code: issue.reason,
50
- message: MESSAGES[issue.reason],
51
- ...issue.detail
52
- };
53
- }
54
- /**
55
- * {@inheritDoc NoStrategyTargetCollateralError}
56
- **/
57
- function noStrategyTargetCollateral(creditManager) {
58
- return {
59
- code: "noStrategyTargetCollateral",
60
- message: `Credit manager ${creditManager} has no strategy target collateral, and none was named.`,
61
- creditManager
62
- };
63
- }
64
- /**
65
- * {@inheritDoc CreditAccountNotEmptyError}
66
- **/
67
- function creditAccountNotEmpty(creditAccount) {
68
- return {
69
- code: "creditAccountNotEmpty",
70
- message: `Credit account ${creditAccount} carries debt or quotas.`,
71
- creditAccount
72
- };
73
- }
74
- /**
75
- * {@inheritDoc CreditAccountNotFoundError}
76
- **/
77
- function creditAccountNotFound(creditAccount) {
78
- return {
79
- code: "creditAccountNotFound",
80
- message: `Credit account not found: ${creditAccount}.`,
81
- creditAccount
82
- };
83
- }
84
- /**
85
- * {@inheritDoc EmptyOpenTakesNothingError}
86
- **/
87
- function emptyOpenTakesNothing() {
88
- return {
89
- code: "emptyOpenTakesNothing",
90
- message: "An empty opening takes no collateral, no account to reuse and no leverage."
91
- };
92
- }
93
- /**
94
- * {@inheritDoc UnexpectedFailureError}
95
- *
96
- * Takes what was thrown, whatever that is: a `throw` is not obliged to raise an
97
- * `Error`, and `cause` promises one.
98
- **/
99
- function unexpectedFailure(thrown) {
100
- const cause = thrown instanceof Error ? thrown : new Error(String(thrown));
101
- return {
102
- code: "unexpectedFailure",
103
- message: `The SDK could not prepare this operation: ${cause.message}`,
104
- cause
105
- };
106
- }
107
- //#endregion
108
- export { creditAccountNotEmpty, creditAccountNotFound, emptyOpenTakesNothing, noStrategyTargetCollateral, toRefusalError, unexpectedFailure };
@@ -1,46 +0,0 @@
1
- //#region src/model/errors.d.ts
2
- /**
3
- * The failure vocabulary the SDK answers in.
4
- *
5
- * A request that the protocol, the market or the request's own numbers rule out
6
- * is not an exception: it is an answer, and a screen shows it the way it shows
7
- * any other. So a method that can be refused returns an {@link SDKReturn}
8
- * envelope rather than throwing, and what it puts in the failure half is one of
9
- * these — never a bare string, never a boolean the caller has to interpret.
10
- *
11
- * A thrown exception still means what it always did: the SDK could not do its
12
- * job (a read failed, a contract reverted unexpectedly, an argument is wrong).
13
- * Those are bugs and outages, not refusals of the request.
14
- **/
15
- /**
16
- * What every error the SDK reports has.
17
- *
18
- * `code` is the discriminant: switch on it and the error narrows to the shape
19
- * carrying that failure's own numbers, so a caller reads `available` and
20
- * `required` off the error rather than re-deriving them from the request.
21
- *
22
- * The codes themselves are per namespace — there is no SDK-wide enumeration of
23
- * them, because the set a method can answer with is part of that method's
24
- * contract, see the `E` of {@link SDKReturn}.
25
- **/
26
- interface IGearboxError {
27
- /**
28
- * Machine-readable identity of the failure, and the discriminant of the
29
- * union a method returns.
30
- **/
31
- code: string;
32
- /**
33
- * One sentence naming what was refused, in English, safe to log. Not a
34
- * message to show a user as-is: a screen renders the code and the numbers
35
- * beside it in its own words and its own language.
36
- **/
37
- message: string;
38
- /**
39
- * The failure this one was raised for, where one error stands in front of
40
- * another. Absent for a refusal that is its own reason, which is most of
41
- * them.
42
- **/
43
- cause?: IGearboxError | Error;
44
- }
45
- //#endregion
46
- export { IGearboxError };
@@ -1,20 +0,0 @@
1
- import { IGearboxError } from "../../../model/errors.js";
2
- import "../../../model/index.js";
3
- import { Hex } from "viem";
4
- //#region src/onchain/accounts/withdrawal-compressor/errors.d.ts
5
- /**
6
- * Refusal answered when a delayed-withdrawal request or redemption log carries
7
- * non-empty `extraData` that cannot be decoded as a `DelayedIntent`.
8
- * Requests produced by our stack always encode a valid intent, so garbage
9
- * here means a malformed/foreign transaction that must not be previewed as
10
- * if it were fine. A plain returned object — not a thrown `Error`.
11
- */
12
- interface InvalidDelayedIntentError extends IGearboxError {
13
- code: "invalidDelayedIntent";
14
- /** Raw `extraData` that failed to decode. */
15
- extraData: Hex;
16
- /** The decoding failure this refusal stands in front of. */
17
- cause?: Error;
18
- }
19
- //#endregion
20
- export { InvalidDelayedIntentError };
@@ -1,18 +0,0 @@
1
- import { IGearboxError } from "../../../model/errors.js";
2
- import "../../../model/index.js";
3
- import { Address } from "viem";
4
- //#region src/onchain/market/zapper/errors.d.ts
5
- /**
6
- * Refusal answered when a zapper call uses a function other than a known
7
- * `deposit`/`redeem` variant. A plain returned object per the SDK's refusal
8
- * vocabulary — not a thrown `Error`.
9
- */
10
- interface UnsupportedZapperFunctionError extends IGearboxError {
11
- code: "unsupportedZapperFunction";
12
- /** Zapper contract the call targets. */
13
- zapper: Address;
14
- /** Decoded function name the SDK cannot preview. */
15
- functionName: string;
16
- }
17
- //#endregion
18
- export { UnsupportedZapperFunctionError };
@@ -1,164 +0,0 @@
1
- import { Bps, Token, TokenAmount } from "../../model/primitives.js";
2
- import { IGearboxError } from "../../model/errors.js";
3
- import { MalformedPreviewError } from "../../model/previews.js";
4
- import "../../model/index.js";
5
- import { BorrowLimitBinding, PreviewIssue } from "./refusal.js";
6
- import { Address } from "viem";
7
- //#region src/onchain/validation/checks.d.ts
8
- /**
9
- * Every refusal the protocol can pass on an operation, as values.
10
- *
11
- * Each check is handed the numbers it compares — never a suite, a market or an
12
- * SDK — so the engine, `checkOperation` and the strategy lists share one
13
- * implementation.
14
- *
15
- * Ladders stay with the caller because they differ deliberately: the engine
16
- * reports the tightest ceiling it found, the account-opening path the first one
17
- * exceeded in its own order.
18
- */
19
- /** A factor at or below this is refused; kept for the callers that size on it. */
20
- declare const MIN_HF_LIMITED = 10100n;
21
- /** The same bar as a `required` argument — the lowest factor that passes. */
22
- declare const MIN_HEALTH_FACTOR_FORM = 10101;
23
- /** The bar the facade itself enforces: an account may end exactly at 1.0. */
24
- declare const MIN_HEALTH_FACTOR_FACADE = 10000;
25
- /**
26
- * The safe-price bar a form holds an account to. A step above the facade's,
27
- * because a factor of exactly 1.0 at safe prices is already a refusal.
28
- */
29
- declare const MIN_SAFE_HEALTH_FACTOR_FORM = 10001;
30
- /** A refusal names what a limit was measured in, never what it is worth. */
31
- declare function amountOf(token: Token, value: bigint): TokenAmount;
32
- /** The credit manager takes no multicall while it is paused. */
33
- declare function checkCreditManagerPaused(args: {
34
- isPaused: boolean;
35
- creditManager: Address;
36
- }): PreviewIssue | null;
37
- /** Past its expiration date the facade takes no more multicalls. */
38
- declare function checkMarketExpired(args: {
39
- isExpired: boolean;
40
- creditManager: Address;
41
- /** Unix seconds, as the facade reports it. */
42
- expirationDate: number;
43
- }): PreviewIssue | null;
44
- /** A paused pool neither takes deposits nor pays out. */
45
- declare function checkPoolPaused(args: {
46
- isPaused: boolean;
47
- pool: Address;
48
- }): PreviewIssue | null;
49
- /**
50
- * A pool winding down still pays out, so only what puts money in is refused.
51
- */
52
- declare function checkPoolSunset(args: {
53
- isSunset: boolean;
54
- isDeposit: boolean;
55
- pool: Address;
56
- }): PreviewIssue | null;
57
- /**
58
- * What the pool will hand over, against what is asked for.
59
- *
60
- * `binding` and `available` are the caller's answer to "which ceiling stands in
61
- * the way", not this check's: see the ladder note above. `solutionAmount` is
62
- * the largest position still openable, left out when none is.
63
- */
64
- declare function checkBorrowLimit(args: {
65
- requested: bigint;
66
- available: bigint;
67
- binding: BorrowLimitBinding;
68
- underlying: Token;
69
- solutionAmount?: bigint;
70
- }): PreviewIssue | null;
71
- /**
72
- * What the pool can pay out, against what is being taken out.
73
- *
74
- * The operator is not `checkBorrowLimit`'s: a pool holding exactly the amount
75
- * asked for still cannot serve it, so equality is already a refusal. That is
76
- * the rule the legacy withdrawal validator enforced and it is preserved to the
77
- * unit.
78
- */
79
- declare function checkPoolPayout(args: {
80
- requested: bigint;
81
- available: bigint;
82
- underlying: Token;
83
- }): PreviewIssue | null;
84
- /**
85
- * A debt the facade would revert on.
86
- *
87
- * `allowZero` is the one place the two callers genuinely disagree: an account
88
- * being adjusted may end owing nothing, while one being opened may not — so the
89
- * exemption is stated rather than assumed.
90
- */
91
- declare function checkDebtInBand(args: {
92
- debt: bigint;
93
- minDebt: bigint;
94
- maxDebt: bigint;
95
- underlying: Token;
96
- allowZero: boolean;
97
- }): PreviewIssue | null;
98
- /** Leverage below 1x is not a position, it is a withdrawal. */
99
- declare function checkLeverageAtLeastOne(args: {
100
- leverage: bigint;
101
- min: bigint;
102
- }): PreviewIssue | null;
103
- /**
104
- * The account against its debt, at whichever bar the caller holds it to.
105
- *
106
- * An unread factor counts as failing: a check that cannot see the number is not
107
- * evidence that the number is fine.
108
- */
109
- declare function checkCollateralised(args: {
110
- healthFactor: Bps | undefined;
111
- /** The lowest acceptable factor — a factor equal to it passes. */
112
- required: Bps;
113
- safePrices: boolean;
114
- /**
115
- * The factor the account stands at now. Given, an operation that raises it
116
- * passes even from under the bar: an account already below is rescued by
117
- * exactly the top-ups a flat bar would refuse.
118
- */
119
- improvesFrom?: Bps;
120
- }): PreviewIssue | null;
121
- /** A token the market will not let the account hold. */
122
- declare function checkForbiddenToken(args: {
123
- token: Token;
124
- isForbidden: boolean;
125
- }): PreviewIssue | null;
126
- /**
127
- * The room the keeper still has for a token's quota, in the underlying.
128
- *
129
- * `requested` is absent for a token the market opened no quota for at all —
130
- * nothing was weighed against a limit, the token simply counts as no collateral.
131
- */
132
- declare function checkQuotaLimit(args: {
133
- token: Token;
134
- requested: bigint | undefined;
135
- available: bigint;
136
- underlying: Token;
137
- }): PreviewIssue | null;
138
- /** How many quoted tokens the facade enables at once. */
139
- declare function checkQuotaCount(args: {
140
- count: number;
141
- max: number;
142
- }): PreviewIssue | null;
143
- /** What the operation is funded from, against what is there. */
144
- declare function checkFunding(args: {
145
- token: Token;
146
- required: bigint;
147
- held: bigint;
148
- }): PreviewIssue | null;
149
- /**
150
- * The SDK could not replay the transaction.
151
- *
152
- * Only a {@link MalformedPreviewError} lands here. An `unpriceableToken`
153
- * warning says the transaction is fine and the SDK could not fully evaluate
154
- * it, which is a caveat on the numbers rather than a reason to refuse — it
155
- * stays on the preview for the caller to surface.
156
- */
157
- declare function checkPreviewError(warning: IGearboxError | undefined): PreviewIssue | null;
158
- /**
159
- * Whether the preview warning means the transaction itself is malformed,
160
- * rather than that only the evaluation was incomplete.
161
- */
162
- declare function isMalformedPreviewError(warning: IGearboxError): warning is MalformedPreviewError;
163
- //#endregion
164
- export { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, amountOf, checkBorrowLimit, checkCollateralised, checkCreditManagerPaused, checkDebtInBand, checkForbiddenToken, checkFunding, checkLeverageAtLeastOne, checkMarketExpired, checkPoolPaused, checkPoolPayout, checkPoolSunset, checkPreviewError, checkQuotaCount, checkQuotaLimit, isMalformedPreviewError };