@gearbox-protocol/sdk 16.1.2 → 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 (517) 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/CreditAccountsServiceV310.js +2 -2
  21. package/dist/cjs/onchain/accounts/index.js +0 -2
  22. package/dist/cjs/onchain/accounts/intents/guards.js +42 -66
  23. package/dist/cjs/onchain/accounts/intents/index.js +38 -35
  24. package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
  25. package/dist/cjs/onchain/accounts/intents/math.js +19 -15
  26. package/dist/cjs/onchain/accounts/intents/open-strategy.js +44 -8
  27. package/dist/cjs/onchain/accounts/intents/plan.js +52 -48
  28. package/dist/cjs/onchain/accounts/intents/realize.js +26 -24
  29. package/dist/cjs/onchain/accounts/intents/tail.js +15 -12
  30. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +7 -0
  31. package/dist/cjs/onchain/accounts/intents/tests/finish-withdraw.fixtures.js +6 -6
  32. package/dist/cjs/onchain/accounts/intents/tests/withdraw.fixtures.js +12 -12
  33. package/dist/cjs/onchain/accounts/intents/view.js +1 -1
  34. package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +0 -1
  35. package/dist/cjs/onchain/index.js +122 -36
  36. package/dist/cjs/onchain/market/MarketSuite.js +7 -1
  37. package/dist/cjs/onchain/market/adapters/index.js +1 -0
  38. package/dist/cjs/onchain/market/credit/CreditSuite.js +47 -15
  39. package/dist/cjs/onchain/market/index.js +0 -6
  40. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +6 -6
  41. package/dist/cjs/onchain/market/oracle/index.js +0 -2
  42. package/dist/cjs/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
  43. package/dist/cjs/onchain/market/rwa/RWARegistry.js +3 -2
  44. package/dist/cjs/onchain/market/rwa/index.js +0 -4
  45. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +7 -7
  46. package/dist/cjs/onchain/market/rwa/securitize/constants.js +0 -2
  47. package/dist/cjs/onchain/market/rwa/securitize/index.js +1 -3
  48. package/dist/cjs/onchain/market/rwa/securitize/types.js +0 -29
  49. package/dist/cjs/onchain/market/rwa/types.js +0 -7
  50. package/dist/cjs/onchain/market/zapper/index.js +0 -1
  51. package/dist/cjs/onchain/pools/PoolService.js +10 -16
  52. package/dist/cjs/onchain/preview/index.js +41 -0
  53. package/dist/cjs/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
  54. package/dist/cjs/onchain/preview/parse/index.js +14 -0
  55. package/dist/cjs/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +3 -3
  56. package/dist/cjs/{preview → onchain/preview}/parse/parseOperationCalldata.js +16 -17
  57. package/dist/cjs/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
  58. package/dist/cjs/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +11 -12
  59. package/dist/cjs/{preview → onchain/preview}/parse/types.js +1 -1
  60. package/dist/cjs/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
  61. package/dist/cjs/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
  62. package/dist/cjs/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
  63. package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
  64. package/dist/cjs/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
  65. package/dist/cjs/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
  66. package/dist/cjs/onchain/preview/preview/index.js +26 -0
  67. package/dist/cjs/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +18 -22
  68. package/dist/cjs/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +22 -28
  69. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +60 -0
  70. package/dist/cjs/onchain/preview/preview/previewOperation.js +119 -0
  71. package/dist/cjs/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -32
  72. package/dist/cjs/onchain/preview/preview/replayInnerOperations.js +109 -0
  73. package/dist/cjs/onchain/preview/preview/replayMulticall.js +22 -0
  74. package/dist/cjs/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
  75. package/dist/cjs/onchain/validation/bundles/checkAccountQuotas.js +20 -0
  76. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +59 -0
  77. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +65 -0
  78. package/dist/cjs/onchain/validation/bundles/checkDraw.js +28 -0
  79. package/dist/cjs/onchain/validation/bundles/checkHealthFactors.js +27 -0
  80. package/dist/cjs/onchain/validation/bundles/checkLiquidationEligibility.js +33 -0
  81. package/dist/cjs/onchain/validation/bundles/checkLiquidationFunding.js +29 -0
  82. package/dist/cjs/onchain/validation/bundles/checkMarket.js +24 -0
  83. package/dist/cjs/onchain/validation/bundles/checkObtained.js +13 -0
  84. package/dist/cjs/onchain/validation/bundles/checkPoolFunding.js +22 -0
  85. package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +35 -0
  86. package/dist/cjs/onchain/validation/bundles/checkQuotasAsked.js +20 -0
  87. package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +33 -0
  88. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +24 -0
  89. package/dist/cjs/onchain/validation/bundles/checkWallet.js +22 -0
  90. package/dist/cjs/onchain/validation/bundles/checkWalletAllowance.js +32 -0
  91. package/dist/cjs/onchain/validation/bundles/checkWalletBalance.js +41 -0
  92. package/dist/cjs/onchain/validation/bundles/index.js +35 -0
  93. package/dist/cjs/onchain/validation/checkLiquidation.js +22 -0
  94. package/dist/cjs/onchain/validation/checkOperation.js +62 -0
  95. package/dist/cjs/onchain/validation/checkSimulation.js +60 -0
  96. package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +25 -0
  97. package/dist/cjs/onchain/validation/checks/checkCollateralised.js +26 -0
  98. package/dist/cjs/onchain/validation/checks/checkCreditAccountFrozen.js +10 -0
  99. package/dist/cjs/onchain/validation/checks/checkCreditManagerPaused.js +10 -0
  100. package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +18 -0
  101. package/dist/cjs/onchain/validation/checks/checkEmergencyLiquidator.js +13 -0
  102. package/dist/cjs/onchain/validation/checks/checkForbiddenToken.js +10 -0
  103. package/dist/cjs/onchain/validation/checks/checkLeverage.js +13 -0
  104. package/dist/cjs/onchain/validation/checks/checkLiquidatorEligible.js +10 -0
  105. package/dist/cjs/onchain/validation/checks/checkMarketExpired.js +10 -0
  106. package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +25 -0
  107. package/dist/cjs/onchain/validation/checks/checkPoolPaused.js +10 -0
  108. package/dist/cjs/onchain/validation/checks/checkPoolSunset.js +10 -0
  109. package/dist/cjs/onchain/validation/checks/checkQuotaCount.js +10 -0
  110. package/dist/cjs/onchain/validation/checks/checkQuotaLimit.js +18 -0
  111. package/dist/cjs/onchain/validation/checks/index.js +31 -0
  112. package/dist/cjs/onchain/validation/helpers/amount.js +12 -0
  113. package/dist/cjs/onchain/validation/helpers/health-factor-limits.js +25 -0
  114. package/dist/cjs/onchain/validation/helpers/index.js +11 -0
  115. package/dist/cjs/onchain/validation/{token.js → helpers/token.js} +4 -4
  116. package/dist/cjs/onchain/validation/index.js +85 -27
  117. package/dist/cjs/onchain/validation/raise.js +33 -0
  118. package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
  119. package/dist/cjs/sdk/index.js +6 -9
  120. package/dist/cjs/sdk/liquidations/LiquidationsNamespace.js +9 -0
  121. package/dist/cjs/sdk/prepare/PrepareApi.js +55 -48
  122. package/dist/cjs/sdk/prepare/index.js +7 -9
  123. package/dist/cjs/sdk/prepare/types.js +0 -4
  124. package/dist/cjs/sdk/preview/PreviewNamespace.js +24 -13
  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 +1 -1
  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 +46 -10
  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/withdrawal-compressor/index.js +0 -1
  158. package/dist/esm/onchain/index.js +61 -10
  159. package/dist/esm/onchain/market/MarketSuite.js +7 -1
  160. package/dist/esm/onchain/market/adapters/index.js +1 -0
  161. package/dist/esm/onchain/market/credit/CreditSuite.js +47 -15
  162. package/dist/esm/onchain/market/index.js +3 -5
  163. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  164. package/dist/esm/onchain/market/oracle/index.js +1 -2
  165. package/dist/esm/onchain/market/pool/PoolQuotaKeeperV310Contract.js +8 -0
  166. package/dist/esm/onchain/market/rwa/RWARegistry.js +2 -1
  167. package/dist/esm/onchain/market/rwa/index.js +3 -4
  168. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +2 -2
  169. package/dist/esm/onchain/market/rwa/securitize/constants.js +1 -2
  170. package/dist/esm/onchain/market/rwa/securitize/index.js +3 -3
  171. package/dist/esm/onchain/market/rwa/securitize/types.js +1 -29
  172. package/dist/esm/onchain/market/rwa/types.js +1 -7
  173. package/dist/esm/onchain/market/zapper/index.js +0 -1
  174. package/dist/esm/onchain/pools/PoolService.js +10 -16
  175. package/dist/esm/onchain/preview/index.js +20 -0
  176. package/dist/esm/{preview → onchain/preview}/parse/classifyInnerOperations.js +2 -3
  177. package/dist/esm/{preview → onchain/preview}/parse/index.js +0 -1
  178. package/dist/esm/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.js +1 -1
  179. package/dist/esm/{preview → onchain/preview}/parse/parseOperationCalldata.js +10 -11
  180. package/dist/esm/{preview → onchain/preview}/parse/parsePoolOperationCalldata.js +3 -3
  181. package/dist/esm/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.js +8 -9
  182. package/dist/esm/{preview → onchain/preview}/parse/types.js +1 -1
  183. package/dist/esm/{preview → onchain/preview}/preview/CreditAccountState.js +3 -4
  184. package/dist/esm/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.js +10 -11
  185. package/dist/esm/{preview → onchain/preview}/preview/detectCloseOrRepay.js +2 -3
  186. package/dist/esm/{preview → onchain/preview}/preview/detectDelayedClaim.js +4 -5
  187. package/dist/esm/{preview → onchain/preview}/preview/detectDelayedOperation.js +5 -6
  188. package/dist/esm/{preview → onchain/preview}/preview/estimateClaimableAt.js +1 -1
  189. package/dist/esm/{preview → onchain/preview}/preview/index.js +3 -4
  190. package/dist/esm/{preview → onchain/preview}/preview/previewAdjustStrategyPosition.js +17 -21
  191. package/dist/esm/{preview → onchain/preview}/preview/previewExitOrRepayStrategyPosition.js +20 -26
  192. package/dist/esm/{preview → onchain/preview}/preview/previewOpenStrategyPosition.js +25 -15
  193. package/dist/esm/{preview → onchain/preview}/preview/previewOperation.js +54 -35
  194. package/dist/esm/{preview/simulate/simulatePoolOperation.js → onchain/preview/preview/previewPoolPositionOperation.js} +46 -30
  195. package/dist/esm/onchain/preview/preview/replayInnerOperations.js +107 -0
  196. package/dist/esm/onchain/preview/preview/replayMulticall.js +21 -0
  197. package/dist/esm/{preview → onchain/preview}/preview/unwrapNativeCollateral.js +11 -14
  198. package/dist/esm/onchain/validation/bundles/checkAccountQuotas.js +19 -0
  199. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +58 -0
  200. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +64 -0
  201. package/dist/esm/onchain/validation/bundles/checkDraw.js +27 -0
  202. package/dist/esm/onchain/validation/bundles/checkHealthFactors.js +26 -0
  203. package/dist/esm/onchain/validation/bundles/checkLiquidationEligibility.js +32 -0
  204. package/dist/esm/onchain/validation/bundles/checkLiquidationFunding.js +28 -0
  205. package/dist/esm/onchain/validation/bundles/checkMarket.js +23 -0
  206. package/dist/esm/onchain/validation/bundles/checkObtained.js +12 -0
  207. package/dist/esm/onchain/validation/bundles/checkPoolFunding.js +21 -0
  208. package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +34 -0
  209. package/dist/esm/onchain/validation/bundles/checkQuotasAsked.js +19 -0
  210. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +32 -0
  211. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +23 -0
  212. package/dist/esm/onchain/validation/bundles/checkWallet.js +21 -0
  213. package/dist/esm/onchain/validation/bundles/checkWalletAllowance.js +31 -0
  214. package/dist/esm/onchain/validation/bundles/checkWalletBalance.js +40 -0
  215. package/dist/esm/onchain/validation/bundles/index.js +18 -0
  216. package/dist/esm/onchain/validation/checkLiquidation.js +21 -0
  217. package/dist/esm/onchain/validation/checkOperation.js +61 -0
  218. package/dist/esm/onchain/validation/checkSimulation.js +59 -0
  219. package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +24 -0
  220. package/dist/esm/onchain/validation/checks/checkCollateralised.js +25 -0
  221. package/dist/esm/onchain/validation/checks/checkCreditAccountFrozen.js +9 -0
  222. package/dist/esm/onchain/validation/checks/checkCreditManagerPaused.js +9 -0
  223. package/dist/esm/onchain/validation/checks/checkDebtLimits.js +17 -0
  224. package/dist/esm/onchain/validation/checks/checkEmergencyLiquidator.js +12 -0
  225. package/dist/esm/onchain/validation/checks/checkForbiddenToken.js +9 -0
  226. package/dist/esm/onchain/validation/checks/checkLeverage.js +12 -0
  227. package/dist/esm/onchain/validation/checks/checkLiquidatorEligible.js +9 -0
  228. package/dist/esm/onchain/validation/checks/checkMarketExpired.js +9 -0
  229. package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +24 -0
  230. package/dist/esm/onchain/validation/checks/checkPoolPaused.js +9 -0
  231. package/dist/esm/onchain/validation/checks/checkPoolSunset.js +9 -0
  232. package/dist/esm/onchain/validation/checks/checkQuotaCount.js +9 -0
  233. package/dist/esm/onchain/validation/checks/checkQuotaLimit.js +17 -0
  234. package/dist/esm/onchain/validation/checks/index.js +16 -0
  235. package/dist/esm/onchain/validation/helpers/amount.js +11 -0
  236. package/dist/esm/onchain/validation/helpers/health-factor-limits.js +21 -0
  237. package/dist/esm/onchain/validation/helpers/index.js +4 -0
  238. package/dist/esm/onchain/validation/{token.js → helpers/token.js} +3 -3
  239. package/dist/esm/onchain/validation/index.js +43 -4
  240. package/dist/esm/onchain/validation/raise.js +31 -0
  241. package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
  242. package/dist/esm/sdk/index.js +2 -3
  243. package/dist/esm/sdk/liquidations/LiquidationsNamespace.js +9 -0
  244. package/dist/esm/sdk/prepare/PrepareApi.js +43 -36
  245. package/dist/esm/sdk/prepare/index.js +3 -3
  246. package/dist/esm/sdk/prepare/types.js +1 -2
  247. package/dist/esm/sdk/preview/PreviewNamespace.js +24 -13
  248. package/dist/types/history/assembleOperations.d.ts +4 -5
  249. package/dist/types/history/classifyMulticallOperations.d.ts +3 -4
  250. package/dist/types/history/index.d.ts +8 -2
  251. package/dist/types/history/mapOperations.d.ts +1 -1
  252. package/dist/types/{preview → history}/trace/errors.d.ts +1 -1
  253. package/dist/types/{preview → history}/trace/extractAdapterCallTraces.d.ts +1 -1
  254. package/dist/types/{preview → history}/trace/extractTransfers.d.ts +2 -3
  255. package/dist/types/{preview → history}/trace/findFacadeCalls.d.ts +1 -1
  256. package/dist/types/{preview → history}/trace/types.d.ts +1 -1
  257. package/dist/types/history/types.d.ts +2 -3
  258. package/dist/types/model/errors/base.d.ts +28 -0
  259. package/dist/types/model/errors/index.d.ts +7 -0
  260. package/dist/types/model/errors/liquidation-errors.d.ts +45 -0
  261. package/dist/types/model/errors/operation-errors.d.ts +216 -0
  262. package/dist/types/{onchain/market/oracle/errors.d.ts → model/errors/oracle-errors.d.ts} +3 -5
  263. package/dist/types/model/errors/prepare-errors.d.ts +131 -0
  264. package/dist/types/model/errors/preview-errors.d.ts +72 -0
  265. package/dist/types/model/index.d.ts +11 -4
  266. package/dist/types/model/opportunities.d.ts +3 -2
  267. package/dist/types/model/positions.d.ts +2 -2
  268. package/dist/types/model/previews.d.ts +52 -113
  269. package/dist/types/model/result.d.ts +4 -8
  270. package/dist/types/model/rwa.d.ts +143 -0
  271. package/dist/types/onchain/accounts/CreditAccountsServiceV310.d.ts +3 -1
  272. package/dist/types/onchain/accounts/index.d.ts +2 -4
  273. package/dist/types/onchain/accounts/intents/guards.d.ts +8 -18
  274. package/dist/types/onchain/accounts/intents/index.d.ts +20 -19
  275. package/dist/types/onchain/accounts/intents/leverage-band.d.ts +1 -1
  276. package/dist/types/onchain/accounts/intents/math.d.ts +6 -6
  277. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +34 -3
  278. package/dist/types/onchain/accounts/intents/operations.d.ts +2 -2
  279. package/dist/types/onchain/accounts/intents/plan.d.ts +9 -9
  280. package/dist/types/onchain/accounts/intents/tail.d.ts +2 -2
  281. package/dist/types/onchain/accounts/intents/testing/expect.d.ts +3 -3
  282. package/dist/types/onchain/accounts/intents/tests/finish-withdraw.fixtures.d.ts +6 -6
  283. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  284. package/dist/types/onchain/accounts/intents/tests/withdraw.fixtures.d.ts +12 -12
  285. package/dist/types/onchain/accounts/intents/types.d.ts +32 -30
  286. package/dist/types/onchain/accounts/types.d.ts +4 -2
  287. package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +1 -1
  288. package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -2
  289. package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +1 -1
  290. package/dist/types/onchain/index.d.ts +68 -13
  291. package/dist/types/onchain/market/MarketSuite.d.ts +5 -1
  292. package/dist/types/onchain/market/adapters/index.d.ts +2 -1
  293. package/dist/types/onchain/market/adapters/transfers.d.ts +0 -7
  294. package/dist/types/onchain/market/credit/CreditSuite.d.ts +20 -8
  295. package/dist/types/onchain/market/credit/index.d.ts +2 -2
  296. package/dist/types/onchain/market/credit/types.d.ts +11 -1
  297. package/dist/types/onchain/market/index.d.ts +6 -7
  298. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +1 -1
  299. package/dist/types/onchain/market/oracle/index.d.ts +1 -2
  300. package/dist/types/onchain/market/oracle/types.d.ts +1 -1
  301. package/dist/types/onchain/market/pool/PoolQuotaKeeperV310Contract.d.ts +5 -0
  302. package/dist/types/onchain/market/rwa/index.d.ts +4 -4
  303. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +3 -2
  304. package/dist/types/onchain/market/rwa/securitize/constants.d.ts +1 -2
  305. package/dist/types/onchain/market/rwa/securitize/index.d.ts +3 -3
  306. package/dist/types/onchain/market/rwa/securitize/types.d.ts +4 -110
  307. package/dist/types/onchain/market/rwa/types.d.ts +6 -32
  308. package/dist/types/onchain/market/zapper/ZapperContract.d.ts +1 -1
  309. package/dist/types/onchain/market/zapper/index.d.ts +1 -2
  310. package/dist/types/onchain/market/zapper/types.d.ts +1 -1
  311. package/dist/types/onchain/pools/types.d.ts +2 -2
  312. package/dist/types/onchain/preview/index.d.ts +24 -0
  313. package/dist/types/{preview → onchain/preview}/parse/classifyInnerOperations.d.ts +4 -4
  314. package/dist/types/{preview → onchain/preview}/parse/index.d.ts +2 -4
  315. package/dist/types/{preview → onchain/preview}/parse/parseFacadeOperationCalldata.d.ts +4 -4
  316. package/dist/types/onchain/preview/parse/parseOperationCalldata.d.ts +18 -0
  317. package/dist/types/{preview → onchain/preview}/parse/parsePoolOperationCalldata.d.ts +7 -7
  318. package/dist/types/{preview → onchain/preview}/parse/parseRWAFactoryOperationCalldata.d.ts +4 -4
  319. package/dist/types/{preview → onchain/preview}/parse/types-adapters.d.ts +5 -16
  320. package/dist/types/{preview → onchain/preview}/parse/types-facades.d.ts +3 -3
  321. package/dist/types/{preview → onchain/preview}/parse/types-pools.d.ts +1 -1
  322. package/dist/types/{preview → onchain/preview}/parse/types-rwa.d.ts +3 -3
  323. package/dist/types/{preview → onchain/preview}/parse/types.d.ts +3 -3
  324. package/dist/types/{preview → onchain/preview}/preview/CreditAccountState.d.ts +5 -5
  325. package/dist/types/{preview → onchain/preview}/preview/buildDelayedStrategyPositionOperationPreview.d.ts +5 -5
  326. package/dist/types/{preview → onchain/preview}/preview/detectCloseOrRepay.d.ts +1 -1
  327. package/dist/types/{preview → onchain/preview}/preview/detectDelayedClaim.d.ts +8 -8
  328. package/dist/types/{preview → onchain/preview}/preview/detectDelayedOperation.d.ts +9 -9
  329. package/dist/types/{preview → onchain/preview}/preview/estimateClaimableAt.d.ts +6 -6
  330. package/dist/types/{preview → onchain/preview}/preview/index.d.ts +3 -4
  331. package/dist/types/onchain/preview/preview/previewAdjustStrategyPosition.d.ts +20 -0
  332. package/dist/types/onchain/preview/preview/previewExitOrRepayStrategyPosition.d.ts +21 -0
  333. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +14 -0
  334. package/dist/types/onchain/preview/preview/previewOperation.d.ts +32 -0
  335. package/dist/types/onchain/preview/preview/previewPoolPositionOperation.d.ts +13 -0
  336. package/dist/types/{preview → onchain/preview}/preview/replayInnerOperations.d.ts +11 -11
  337. package/dist/types/{preview → onchain/preview}/preview/replayMulticall.d.ts +10 -10
  338. package/dist/types/{preview → onchain/preview}/preview/unwrapNativeCollateral.d.ts +10 -20
  339. package/dist/types/onchain/validation/bundles/checkAccountQuotas.d.ts +16 -0
  340. package/dist/types/onchain/validation/bundles/checkCollateralFunding.d.ts +22 -0
  341. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +31 -0
  342. package/dist/types/onchain/validation/bundles/checkDraw.d.ts +20 -0
  343. package/dist/types/onchain/validation/bundles/checkHealthFactors.d.ts +39 -0
  344. package/dist/types/onchain/validation/bundles/checkLiquidationEligibility.d.ts +20 -0
  345. package/dist/types/onchain/validation/bundles/checkLiquidationFunding.d.ts +18 -0
  346. package/dist/types/onchain/validation/bundles/checkMarket.d.ts +15 -0
  347. package/dist/types/onchain/validation/bundles/checkObtained.d.ts +9 -0
  348. package/dist/types/onchain/validation/bundles/checkPoolFunding.d.ts +19 -0
  349. package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +31 -0
  350. package/dist/types/onchain/validation/bundles/checkQuotasAsked.d.ts +10 -0
  351. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +21 -0
  352. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +19 -0
  353. package/dist/types/onchain/validation/bundles/checkWallet.d.ts +23 -0
  354. package/dist/types/onchain/validation/bundles/checkWalletAllowance.d.ts +18 -0
  355. package/dist/types/onchain/validation/bundles/checkWalletBalance.d.ts +17 -0
  356. package/dist/types/onchain/validation/bundles/index.d.ts +18 -0
  357. package/dist/types/onchain/validation/checkLiquidation.d.ts +23 -0
  358. package/dist/types/onchain/validation/checkOperation.d.ts +32 -0
  359. package/dist/types/onchain/validation/checkSimulation.d.ts +56 -0
  360. package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +21 -0
  361. package/dist/types/onchain/validation/checks/checkCollateralised.d.ts +25 -0
  362. package/dist/types/onchain/validation/checks/checkCreditAccountFrozen.d.ts +12 -0
  363. package/dist/types/onchain/validation/checks/checkCreditManagerPaused.d.ts +12 -0
  364. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +21 -0
  365. package/dist/types/onchain/validation/checks/checkEmergencyLiquidator.d.ts +17 -0
  366. package/dist/types/onchain/validation/checks/checkForbiddenToken.d.ts +12 -0
  367. package/dist/types/onchain/validation/checks/checkLeverage.d.ts +12 -0
  368. package/dist/types/onchain/validation/checks/checkLiquidatorEligible.d.ts +13 -0
  369. package/dist/types/onchain/validation/checks/checkMarketExpired.d.ts +14 -0
  370. package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +20 -0
  371. package/dist/types/onchain/validation/checks/checkPoolPaused.d.ts +12 -0
  372. package/dist/types/onchain/validation/checks/checkPoolSunset.d.ts +13 -0
  373. package/dist/types/onchain/validation/checks/checkQuotaCount.d.ts +11 -0
  374. package/dist/types/onchain/validation/checks/checkQuotaLimit.d.ts +18 -0
  375. package/dist/types/onchain/validation/checks/index.d.ts +16 -0
  376. package/dist/types/onchain/validation/helpers/amount.d.ts +7 -0
  377. package/dist/types/onchain/validation/helpers/health-factor-limits.d.ts +21 -0
  378. package/dist/types/onchain/validation/helpers/index.d.ts +4 -0
  379. package/dist/types/onchain/validation/{token.d.ts → helpers/token.d.ts} +4 -4
  380. package/dist/types/onchain/validation/index.d.ts +43 -4
  381. package/dist/types/onchain/validation/raise.d.ts +33 -0
  382. package/dist/types/sdk/execute/types.d.ts +2 -2
  383. package/dist/types/sdk/index.d.ts +5 -6
  384. package/dist/types/sdk/liquidations/LiquidationsNamespace.d.ts +5 -0
  385. package/dist/types/sdk/liquidations/types.d.ts +8 -0
  386. package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -5
  387. package/dist/types/sdk/prepare/index.d.ts +5 -5
  388. package/dist/types/sdk/prepare/types.d.ts +65 -23
  389. package/dist/types/sdk/preview/PreviewNamespace.d.ts +13 -3
  390. package/dist/types/sdk/preview/index.d.ts +2 -2
  391. package/dist/types/sdk/preview/types.d.ts +30 -7
  392. package/package.json +1 -6
  393. package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -1
  394. package/dist/cjs/onchain/market/zapper/errors.js +0 -1
  395. package/dist/cjs/onchain/validation/checks.js +0 -258
  396. package/dist/cjs/onchain/validation/refusal.js +0 -39
  397. package/dist/cjs/preview/index.js +0 -86
  398. package/dist/cjs/preview/package.json +0 -1
  399. package/dist/cjs/preview/parse/errors.js +0 -1
  400. package/dist/cjs/preview/parse/index.js +0 -15
  401. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -38
  402. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -52
  403. package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -52
  404. package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -53
  405. package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +0 -63
  406. package/dist/cjs/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -19
  407. package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +0 -76
  408. package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +0 -39
  409. package/dist/cjs/preview/prerequisites/checkPrerequisites.js +0 -74
  410. package/dist/cjs/preview/prerequisites/helpers.js +0 -23
  411. package/dist/cjs/preview/prerequisites/index.js +0 -12
  412. package/dist/cjs/preview/preview/errors.js +0 -85
  413. package/dist/cjs/preview/preview/index.js +0 -33
  414. package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +0 -50
  415. package/dist/cjs/preview/preview/previewOperation.js +0 -100
  416. package/dist/cjs/preview/preview/previewPoolPositionOperation.js +0 -49
  417. package/dist/cjs/preview/preview/replayInnerOperations.js +0 -109
  418. package/dist/cjs/preview/preview/replayMulticall.js +0 -19
  419. package/dist/cjs/preview/simulate/errors.js +0 -73
  420. package/dist/cjs/preview/simulate/index.js +0 -11
  421. package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -15
  422. package/dist/cjs/preview/simulate/simulateOperation.js +0 -29
  423. package/dist/cjs/preview/simulate/simulateRWAOperation.js +0 -15
  424. package/dist/cjs/preview/simulate/types.js +0 -1
  425. package/dist/cjs/preview/trace/index.js +0 -14
  426. package/dist/cjs/preview/trace/types.js +0 -1
  427. package/dist/cjs/preview/types.js +0 -1
  428. package/dist/cjs/preview/validate/checkOperation.js +0 -187
  429. package/dist/cjs/preview/validate/checkSimulation.js +0 -39
  430. package/dist/cjs/preview/validate/index.js +0 -8
  431. package/dist/cjs/sdk/prepare/errors.js +0 -93
  432. package/dist/esm/onchain/accounts/withdrawal-compressor/errors.js +0 -1
  433. package/dist/esm/onchain/market/zapper/errors.js +0 -1
  434. package/dist/esm/onchain/validation/checks.js +0 -238
  435. package/dist/esm/onchain/validation/refusal.js +0 -36
  436. package/dist/esm/preview/index.js +0 -38
  437. package/dist/esm/preview/package.json +0 -1
  438. package/dist/esm/preview/parse/errors.js +0 -1
  439. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -37
  440. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -51
  441. package/dist/esm/preview/prerequisites/Prerequisite.js +0 -51
  442. package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +0 -52
  443. package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +0 -62
  444. package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +0 -18
  445. package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +0 -75
  446. package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +0 -38
  447. package/dist/esm/preview/prerequisites/checkPrerequisites.js +0 -73
  448. package/dist/esm/preview/prerequisites/helpers.js +0 -22
  449. package/dist/esm/preview/prerequisites/index.js +0 -7
  450. package/dist/esm/preview/preview/errors.js +0 -79
  451. package/dist/esm/preview/preview/previewPoolPositionOperation.js +0 -48
  452. package/dist/esm/preview/preview/replayInnerOperations.js +0 -107
  453. package/dist/esm/preview/preview/replayMulticall.js +0 -18
  454. package/dist/esm/preview/simulate/errors.js +0 -71
  455. package/dist/esm/preview/simulate/index.js +0 -6
  456. package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -14
  457. package/dist/esm/preview/simulate/simulateOperation.js +0 -28
  458. package/dist/esm/preview/simulate/simulateRWAOperation.js +0 -14
  459. package/dist/esm/preview/simulate/types.js +0 -1
  460. package/dist/esm/preview/trace/types.js +0 -1
  461. package/dist/esm/preview/types.js +0 -1
  462. package/dist/esm/preview/validate/checkOperation.js +0 -183
  463. package/dist/esm/preview/validate/checkSimulation.js +0 -38
  464. package/dist/esm/preview/validate/index.js +0 -3
  465. package/dist/esm/sdk/prepare/errors.js +0 -89
  466. package/dist/types/model/errors.d.ts +0 -46
  467. package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +0 -20
  468. package/dist/types/onchain/market/zapper/errors.d.ts +0 -18
  469. package/dist/types/onchain/validation/checks.d.ts +0 -164
  470. package/dist/types/onchain/validation/refusal.d.ts +0 -242
  471. package/dist/types/preview/index.d.ts +0 -47
  472. package/dist/types/preview/parse/errors.d.ts +0 -29
  473. package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -18
  474. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -26
  475. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -29
  476. package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -26
  477. package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +0 -55
  478. package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +0 -20
  479. package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +0 -12
  480. package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +0 -12
  481. package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +0 -26
  482. package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +0 -28
  483. package/dist/types/preview/prerequisites/helpers.d.ts +0 -10
  484. package/dist/types/preview/prerequisites/index.d.ts +0 -7
  485. package/dist/types/preview/prerequisites/types.d.ts +0 -53
  486. package/dist/types/preview/preview/errors.d.ts +0 -44
  487. package/dist/types/preview/preview/previewAdjustStrategyPosition.d.ts +0 -19
  488. package/dist/types/preview/preview/previewExitOrRepayStrategyPosition.d.ts +0 -18
  489. package/dist/types/preview/preview/previewOpenStrategyPosition.d.ts +0 -12
  490. package/dist/types/preview/preview/previewOperation.d.ts +0 -32
  491. package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +0 -13
  492. package/dist/types/preview/simulate/errors.d.ts +0 -52
  493. package/dist/types/preview/simulate/index.d.ts +0 -7
  494. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -16
  495. package/dist/types/preview/simulate/simulateOperation.d.ts +0 -12
  496. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -42
  497. package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -16
  498. package/dist/types/preview/simulate/types.d.ts +0 -48
  499. package/dist/types/preview/types.d.ts +0 -65
  500. package/dist/types/preview/validate/checkOperation.d.ts +0 -71
  501. package/dist/types/preview/validate/checkSimulation.d.ts +0 -32
  502. package/dist/types/preview/validate/index.d.ts +0 -3
  503. package/dist/types/sdk/prepare/errors.d.ts +0 -319
  504. /package/dist/cjs/{preview/prerequisites → history/trace}/types.js +0 -0
  505. /package/dist/cjs/model/{errors.js → errors/base.js} +0 -0
  506. /package/dist/cjs/{preview → onchain/preview}/parse/types-adapters.js +0 -0
  507. /package/dist/cjs/{preview → onchain/preview}/parse/types-facades.js +0 -0
  508. /package/dist/cjs/{preview → onchain/preview}/parse/types-pools.js +0 -0
  509. /package/dist/cjs/{preview → onchain/preview}/parse/types-rwa.js +0 -0
  510. /package/dist/esm/{preview → history}/trace/index.js +0 -0
  511. /package/dist/esm/{preview/prerequisites → history/trace}/types.js +0 -0
  512. /package/dist/esm/model/{errors.js → errors/base.js} +0 -0
  513. /package/dist/esm/{preview → onchain/preview}/parse/types-adapters.js +0 -0
  514. /package/dist/esm/{preview → onchain/preview}/parse/types-facades.js +0 -0
  515. /package/dist/esm/{preview → onchain/preview}/parse/types-pools.js +0 -0
  516. /package/dist/esm/{preview → onchain/preview}/parse/types-rwa.js +0 -0
  517. /package/dist/types/{preview → history}/trace/index.d.ts +0 -0
@@ -1,9 +1,12 @@
1
1
  import { MAX_UINT256, PERCENTAGE_FACTOR } from "../../constants/math.js";
2
2
  import "../../constants/index.js";
3
- import { IntentPreviewError } from "../../validation/refusal.js";
4
- import { toToken, toTokenAmount } from "../../validation/token.js";
3
+ import { debtOutOfRange, insufficientBalance, leverageOutOfRange } from "../../../model/errors/operation-errors.js";
4
+ import { noDelayedRoute, unsupportedCollateralToken } from "../../../model/errors/prepare-errors.js";
5
+ import "../../../model/index.js";
6
+ import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
7
+ import { IntentPreviewError } from "../../validation/raise.js";
5
8
  import { eq } from "./utils/common.js";
6
- import { assertDebtInBand, assertLeverageAtLeastOne, debtForLeverage, proportionalDebt } from "./math.js";
9
+ import { assertDebtLimits, assertLeverageAtLeastOne, debtForLeverage, proportionalDebt } from "./math.js";
7
10
  //#region src/onchain/accounts/intents/plan.ts
8
11
  /** Whatever the previous convert produced. */
9
12
  const RAISED = { raised: true };
@@ -15,7 +18,7 @@ function planAddCollateral(intent) {
15
18
  /** Intent 4: one asset out at fixed debt. */
16
19
  function planWithdrawAsset(intent, view) {
17
20
  assertPositive(intent.amount, "withdrawAsset");
18
- return payout(view, intent.token, intent.amount, intent.to);
21
+ return withdraw(view, intent.token, intent.amount, intent.to);
19
22
  }
20
23
  /** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
21
24
  function planAdjustLeverage(intent, view) {
@@ -24,21 +27,22 @@ function planAdjustLeverage(intent, view) {
24
27
  const T = intent.token ?? positionToken(view, "adjustLeverage");
25
28
  if (delta > 0n) return [borrow(delta), convert(U, T, delta)];
26
29
  const shortfall = -delta - view.balanceOf(U);
27
- if (shortfall > 0n && eq(T, U)) throw new IntentPreviewError("insufficientSourceBalance", {
30
+ if (shortfall > 0n && eq(T, U)) throw new IntentPreviewError(insufficientBalance({
28
31
  required: toTokenAmount(view.sdk, U, -delta),
29
- held: toTokenAmount(view.sdk, U, view.balanceOf(U))
30
- }, `adjustLeverage: needs ${-delta} underlying, account holds ${view.balanceOf(U)}`);
32
+ held: toTokenAmount(view.sdk, U, view.balanceOf(U)),
33
+ holderKind: "creditAccount"
34
+ }), `adjustLeverage: needs ${-delta} underlying, account holds ${view.balanceOf(U)}`);
31
35
  return [...shortfall > 0n ? [convert(T, U, view.price(U, T, shortfall))] : [], repay(-delta)];
32
36
  }
33
37
  /** Intents 1.1 / 1.2: collateral grows by `a`, debt grows to match. */
34
38
  function planDeposit(intent, view) {
35
39
  assertPositive(intent.amount, "deposit");
36
40
  const U = view.underlying;
37
- if (!eq(intent.token, U) && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError("unsupportedCollateralToken", { token: toToken(view.sdk, intent.token) }, `deposit: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be deposited, got ${intent.token}`);
41
+ if (!eq(intent.token, U) && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, intent.token)), `deposit: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be deposited, got ${intent.token}`);
38
42
  const aU = view.price(intent.token, U, intent.amount);
39
43
  const debtDelta = intent.targetLeverage === void 0 ? proportionalDebt(view, aU) : debtForLeverage(view.collateral + aU, intent.targetLeverage) - view.debt;
40
- if (debtDelta < 0n) throw new IntentPreviewError("leverageOutOfRange", void 0, `deposit: target leverage ${intent.targetLeverage} would require repaying debt`);
41
- assertDebtInBand(view.sdk, view.debt + debtDelta, view.band, U);
44
+ if (debtDelta < 0n) throw new IntentPreviewError(leverageOutOfRange(), `deposit: target leverage ${intent.targetLeverage} would require repaying debt`);
45
+ assertDebtLimits(view.sdk, view.debt + debtDelta, view.debtLimits, U);
42
46
  const T = intent.positionToken ?? positionToken(view, "deposit");
43
47
  const depositStays = eq(intent.token, T);
44
48
  return [
@@ -65,15 +69,15 @@ function planRepay(intent, view) {
65
69
  assertPositive(intent.amount, "repay");
66
70
  const U = view.underlying;
67
71
  const fundsInU = eq(intent.token, U);
68
- if (!fundsInU && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError("unsupportedCollateralToken", { token: toToken(view.sdk, intent.token) }, `repay: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be repaid with, got ${intent.token}`);
69
- if (view.debt <= 0n) throw new IntentPreviewError("debtOutOfRange", {
72
+ if (!fundsInU && !(view.rwaAsset && eq(intent.token, view.rwaAsset))) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, intent.token)), `repay: only ${U}${view.rwaAsset ? ` or ${view.rwaAsset}` : ""} can be repaid with, got ${intent.token}`);
73
+ if (view.debt <= 0n) throw new IntentPreviewError(debtOutOfRange({
70
74
  requested: toTokenAmount(view.sdk, U, view.debt),
71
- minDebt: toTokenAmount(view.sdk, U, view.band.minDebt),
72
- maxDebt: toTokenAmount(view.sdk, U, view.band.maxDebt)
73
- }, "repay: the account owes nothing");
75
+ minDebt: toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
76
+ maxDebt: toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
77
+ }), "repay: the account owes nothing");
74
78
  const funding = everything(intent.amount) ? view.price(U, intent.token, withMargin(view.debt)) : intent.amount;
75
79
  const repaid = min(view.price(intent.token, U, funding), view.debt);
76
- assertDebtInBand(view.sdk, view.debt - repaid, view.band, view.underlying);
80
+ assertDebtLimits(view.sdk, view.debt - repaid, view.debtLimits, view.underlying);
77
81
  return [
78
82
  add(intent.token, funding, intent.value),
79
83
  ...fundsInU ? [] : [convert(intent.token, U, funding)],
@@ -99,21 +103,21 @@ function planWithdraw(intent, view) {
99
103
  if (eq(T, U)) return [
100
104
  convert(S, U, view.price(U, S, WU + dD)),
101
105
  repay(dD, intent.amount),
102
- ...payout(view, U, intent.amount, intent.to)
106
+ ...withdraw(view, U, intent.amount, intent.to)
103
107
  ];
104
108
  return [
105
109
  convert(S, U, view.price(U, S, dD)),
106
110
  repay(dD),
107
111
  convert(S, T, view.price(U, S, WU)),
108
- ...payout(view, T, RAISED, intent.to)
112
+ ...withdraw(view, T, RAISED, intent.to)
109
113
  ];
110
114
  }
111
115
  /**
112
116
  * Intent 2.1 against a source that cannot be sold on a DEX.
113
117
  *
114
118
  * Some collateral only converts through its issuer — a Securitize dsToken, a
115
- * Mellow share — which answers a redemption request now and pays out days
116
- * later. The trade is unchanged; what changes is that the proceeds do not exist
119
+ * Mellow share — which answers a redemption request now and settles days
120
+ * later. The trade is unchanged; what changes is that the money does not exist
117
121
  * yet, so this half only requests the redemption:
118
122
  *
119
123
  * ```
@@ -129,7 +133,7 @@ function planWithdrawDelayed(intent, view) {
129
133
  const { U, T, S, WU, dD, all } = withdrawShape(intent, view);
130
134
  if (all) {
131
135
  const held = view.balanceOf(S);
132
- if (held <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, `withdraw: account holds no ${S} to redeem`);
136
+ if (held <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: account holds no ${S} to redeem`);
133
137
  return [{
134
138
  kind: "request",
135
139
  token: S,
@@ -141,13 +145,13 @@ function planWithdrawDelayed(intent, view) {
141
145
  }
142
146
  }];
143
147
  }
144
- if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError("noDelayedRoute", { token: toToken(view.sdk, T) }, `withdraw: a delayed route cannot pay out in ${T}`);
145
- const payoutIsSource = eq(T, S);
148
+ if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(noDelayedRoute(toToken(view.sdk, T)), `withdraw: a delayed route cannot withdraw in ${T}`);
149
+ const tokenOutIsSource = eq(T, S);
146
150
  return [{
147
151
  kind: "request",
148
152
  token: S,
149
- amount: view.price(U, S, payoutIsSource ? dD : WU + dD),
150
- reserve: payoutIsSource ? intent.amount : 0n,
153
+ amount: view.price(U, S, tokenOutIsSource ? dD : WU + dD),
154
+ reserve: tokenOutIsSource ? intent.amount : 0n,
151
155
  record: {
152
156
  type: "WITHDRAW_COLLATERAL",
153
157
  to: intent.to,
@@ -167,9 +171,9 @@ function planWithdrawDelayed(intent, view) {
167
171
  */
168
172
  function planAdjustLeverageDelayed(intent, view) {
169
173
  const { U, delta } = leverageShape(intent, view);
170
- if (delta >= 0n) throw new IntentPreviewError("noDelayedRoute", void 0, "adjustLeverage: only deleveraging can settle with a delay");
174
+ if (delta >= 0n) throw new IntentPreviewError(noDelayedRoute(), "adjustLeverage: only deleveraging can settle with a delay");
171
175
  const shortfall = -delta - view.balanceOf(U);
172
- if (shortfall <= 0n) throw new IntentPreviewError("noDelayedRoute", void 0, "adjustLeverage: idle underlying covers the repayment, nothing to redeem");
176
+ if (shortfall <= 0n) throw new IntentPreviewError(noDelayedRoute(), "adjustLeverage: idle underlying covers the repayment, nothing to redeem");
173
177
  const T = intent.token ?? positionToken(view, "adjustLeverage");
174
178
  return [{
175
179
  kind: "request",
@@ -188,20 +192,20 @@ function planFinishDecreaseLeverage(claimable, claimed, view) {
188
192
  ];
189
193
  }
190
194
  /**
191
- * The claim is split between the promised payout `W` and the debt the leading
192
- * half deferred: the payout is served first, the debt gets what is left, so a
193
- * routing shortfall shows as leverage a touch above target rather than as a
194
- * payout the wallet was promised and did not get.
195
+ * The claim is split between the promised withdrawal `W` and the debt the
196
+ * leading half deferred: `W` is served first, the debt gets what is left, so a
197
+ * bad quote shows as leverage a touch above target rather than as a wallet paid
198
+ * less than it was promised.
195
199
  */
196
200
  function planFinishWithdraw(intent, claimable, claimed, view) {
197
201
  const U = view.underlying;
198
202
  const T = intent.withdrawToken;
199
203
  const W = intent.withdrawAmount;
200
- if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError("noDelayedRoute", { token: toToken(view.sdk, T) }, `finishWithdraw: cannot pay out in ${T}`);
204
+ if (!eq(T, U) && !(view.rwaAsset && eq(T, view.rwaAsset))) throw new IntentPreviewError(noDelayedRoute(toToken(view.sdk, T)), `finishWithdraw: cannot withdraw in ${T}`);
201
205
  if (intent.debtRepaid === 0n) return [
202
206
  claim(claimable),
203
207
  convert(claimed.token, T, claimed.amount),
204
- ...payout(view, T, {
208
+ ...withdraw(view, T, {
205
209
  raised: true,
206
210
  max: W
207
211
  }, intent.to)
@@ -213,13 +217,13 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
213
217
  raised: true,
214
218
  max: intent.debtRepaid
215
219
  }),
216
- ...payout(view, T, W, intent.to)
220
+ ...withdraw(view, T, W, intent.to)
217
221
  ];
218
222
  if (eq(T, U)) return [
219
223
  claim(claimable),
220
224
  convert(claimed.token, U, claimed.amount),
221
225
  repay(intent.debtRepaid, W),
222
- ...payout(view, U, {
226
+ ...withdraw(view, U, {
223
227
  raised: true,
224
228
  max: W
225
229
  }, intent.to)
@@ -233,7 +237,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
233
237
  max: intent.debtRepaid
234
238
  }),
235
239
  convert(claimed.token, T, reserved),
236
- ...payout(view, T, {
240
+ ...withdraw(view, T, {
237
241
  raised: true,
238
242
  max: W
239
243
  }, intent.to)
@@ -241,7 +245,7 @@ function planFinishWithdraw(intent, claimable, claimed, view) {
241
245
  }
242
246
  /**
243
247
  * The tail of an exit: the claim lands, everything the account holds is sold
244
- * into the underlying, the loan is settled out of the proceeds and the rest
248
+ * into the underlying, the loan is settled out of what it sells for and the rest
245
249
  * goes to the wallet. The account survives it, empty and owing nothing.
246
250
  *
247
251
  * Nothing is quoted from the request — the same shape {@link planWithdraw}
@@ -267,7 +271,7 @@ function planFinishClaimOnly(claimable) {
267
271
  return [claim(claimable)];
268
272
  }
269
273
  /**
270
- * What a withdrawal comes down to: the payout `W` of `T` priced in the
274
+ * What a withdrawal comes down to: the withdrawal `W` of `T` priced in the
271
275
  * underlying, the debt `dD` that keeps leverage flat, and the source `S` both
272
276
  * are funded from. Shared so that the instant and the delayed leading half
273
277
  * cannot disagree on the amounts.
@@ -289,7 +293,7 @@ function withdrawShape(intent, view) {
289
293
  };
290
294
  }
291
295
  const WU = view.price(T, U, intent.amount);
292
- if (WU <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, `withdraw: cannot price ${intent.amount} of ${T}`);
296
+ if (WU <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: cannot price ${intent.amount} of ${T}`);
293
297
  if (WU >= view.collateral) {
294
298
  assertHasValue(view);
295
299
  return {
@@ -302,7 +306,7 @@ function withdrawShape(intent, view) {
302
306
  };
303
307
  }
304
308
  const dD = proportionalDebt(view, WU);
305
- assertDebtInBand(view.sdk, view.debt - dD, view.band, view.underlying);
309
+ assertDebtLimits(view.sdk, view.debt - dD, view.debtLimits, view.underlying);
306
310
  return {
307
311
  U,
308
312
  T,
@@ -319,9 +323,9 @@ function withdrawShape(intent, view) {
319
323
  */
320
324
  function leverageShape(intent, view) {
321
325
  assertLeverageAtLeastOne(intent.targetLeverage);
322
- if (view.collateral <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, "adjustLeverage: account has no collateral to lever");
326
+ if (view.collateral <= 0n) throw new IntentPreviewError(insufficientBalance(), "adjustLeverage: account has no collateral to lever");
323
327
  const target = debtForLeverage(view.collateral, intent.targetLeverage);
324
- assertDebtInBand(view.sdk, target, view.band, view.underlying);
328
+ assertDebtLimits(view.sdk, target, view.debtLimits, view.underlying);
325
329
  return {
326
330
  U: view.underlying,
327
331
  delta: target - view.debt
@@ -371,7 +375,7 @@ const min = (a, b) => a < b ? a : b;
371
375
  * Hands `amount` of `token` to `to`. The wrapped underlying of an RWA market
372
376
  * cannot leave the account, so it is unwrapped into the raw asset on the way.
373
377
  */
374
- function payout(view, token, amount, to) {
378
+ function withdraw(view, token, amount, to) {
375
379
  if (view.rwaAsset && eq(token, view.underlying)) return [convert(view.underlying, view.rwaAsset, amount), {
376
380
  kind: "withdraw",
377
381
  token: view.rwaAsset,
@@ -387,20 +391,20 @@ function payout(view, token, amount, to) {
387
391
  }
388
392
  function positionToken(view, flow) {
389
393
  const pick = view.fattest([view.underlying]);
390
- if (!pick) throw new IntentPreviewError("insufficientSourceBalance", void 0, `${flow}: no position token on the account`);
394
+ if (!pick) throw new IntentPreviewError(insufficientBalance(), `${flow}: no position token on the account`);
391
395
  return pick;
392
396
  }
393
397
  function sourceToken(view) {
394
398
  const pick = view.fattest();
395
- if (!pick) throw new IntentPreviewError("insufficientSourceBalance", void 0, "withdraw: account has no spendable balance");
399
+ if (!pick) throw new IntentPreviewError(insufficientBalance(), "withdraw: account has no spendable balance");
396
400
  return pick;
397
401
  }
398
402
  /** An account whose debt has eaten its collateral has nothing to hand over. */
399
403
  function assertHasValue(view) {
400
- if (view.collateral <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, `withdraw: nothing to withdraw, net value is ${view.collateral}`);
404
+ if (view.collateral <= 0n) throw new IntentPreviewError(insufficientBalance(), `withdraw: nothing to withdraw, net value is ${view.collateral}`);
401
405
  }
402
406
  function assertPositive(amount, flow) {
403
- if (amount <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, `${flow}: amount must be positive`);
407
+ if (amount <= 0n) throw new IntentPreviewError(insufficientBalance(), `${flow}: amount must be positive`);
404
408
  }
405
409
  //#endregion
406
410
  export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
@@ -1,8 +1,11 @@
1
- import { IntentPreviewError } from "../../validation/refusal.js";
2
- import { toToken, toTokenAmount } from "../../validation/token.js";
1
+ import { insufficientBalance } from "../../../model/errors/operation-errors.js";
2
+ import { multipleDelayedWithdrawals, noDelayedRoute, withdrawalInProgress } from "../../../model/errors/prepare-errors.js";
3
+ import "../../../model/index.js";
4
+ import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
5
+ import { IntentPreviewError } from "../../validation/raise.js";
3
6
  import { eq, toTargetDecimals } from "./utils/common.js";
4
7
  import { isRedemptionPhantomToken } from "./utils/pick-token.js";
5
- import { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertQuotaHeadroom } from "./guards.js";
8
+ import { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertQuotaAvailable } from "./guards.js";
6
9
  import { OperationLedger } from "./utils/ledger.js";
7
10
  import { collectPriceImpact } from "./utils/price-impact.js";
8
11
  import { clearedQuotas, getQuotasForUpdate, quotasAfterUpdate } from "./utils/quotas-for-update.js";
@@ -41,8 +44,8 @@ async function realize(steps, props) {
41
44
  * The floor: every routed leg counted at the amount it guarantees. This is
42
45
  * what the calls are built from — a repayment may only spend underlying the
43
46
  * route promises to have raised — and what the guards are answered on, since
44
- * a floor that does not clear the facade's bar is a transaction that can
45
- * revert.
47
+ * a floor that does not clear the facade's threshold is a transaction that
48
+ * can revert.
46
49
  */
47
50
  const ledger = new OperationLedger(start);
48
51
  /**
@@ -77,14 +80,16 @@ async function realize(steps, props) {
77
80
  * Whether anything leaves the account, which is what makes the credit manager
78
81
  * judge the closing collateral check at safe prices.
79
82
  */
80
- let paysOut = false;
83
+ let withdrawsCollateral = false;
81
84
  const amountOf = (a) => typeof a === "bigint" ? a : min(raised, a.max ?? raised);
82
85
  const assertHolds = (token, amount, what) => {
83
86
  const held = ledger.balanceOf(token);
84
- if (amount <= 0n || held < amount) throw new IntentPreviewError("insufficientSourceBalance", {
87
+ if (amount <= 0n || held < amount) throw new IntentPreviewError(insufficientBalance({
85
88
  required: toTokenAmount(sdk, token, amount),
86
- held: toTokenAmount(sdk, token, held)
87
- }, `${what}: needs ${amount} of ${token}, account holds ${held}`);
89
+ held: toTokenAmount(sdk, token, held),
90
+ holderKind: "creditAccount",
91
+ holder: creditAccount.creditAccount
92
+ }), `${what}: needs ${amount} of ${token}, account holds ${held}`);
88
93
  };
89
94
  for (const step of steps) switch (step.kind) {
90
95
  case "add":
@@ -173,7 +178,7 @@ async function realize(steps, props) {
173
178
  case "closeAll": {
174
179
  const balances = ledger.snapshot().assets.filter((a) => !eq(a.token, underlying) && a.balance > DUST);
175
180
  const pending = balances.find((a) => isRedemptionPhantomToken(sdk, a.token));
176
- if (pending) throw new IntentPreviewError("withdrawalInProgress", { inFlight: toTokenAmount(sdk, pending.token, pending.balance) }, `closeAll: ${pending.token} is a pending withdrawal, claim it first`);
181
+ if (pending) throw new IntentPreviewError(withdrawalInProgress(toTokenAmount(sdk, pending.token, pending.balance)), `closeAll: ${pending.token} is a pending withdrawal, claim it first`);
177
182
  if (balances.length > 0) {
178
183
  const leg = await paths.closeAll({ balances });
179
184
  if (leg.probe) probes.push(leg.probe);
@@ -200,7 +205,7 @@ async function realize(steps, props) {
200
205
  case "withdraw": {
201
206
  const amount = amountOf(step.amount);
202
207
  assertHolds(step.token, amount, "withdraw");
203
- paysOut = true;
208
+ withdrawsCollateral = true;
204
209
  push(buildWithdrawCollateralOperation({
205
210
  token: step.token,
206
211
  amount,
@@ -212,7 +217,7 @@ async function realize(steps, props) {
212
217
  }
213
218
  case "request": {
214
219
  const asset = await delayedConfig(sdk, creditAccount, step.token);
215
- if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new IntentPreviewError("withdrawalInProgress", { inFlight: toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken)) }, `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
220
+ if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new IntentPreviewError(withdrawalInProgress(toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
216
221
  assertHolds(step.token, step.amount + step.reserve, "request");
217
222
  const preview = await sdk.accounts.previewDelayedWithdrawal({
218
223
  creditAccount: creditAccount.creditAccount,
@@ -248,7 +253,7 @@ async function realize(steps, props) {
248
253
  raised = instantOutput(step.claimable.outputs)?.amount ?? 0n;
249
254
  break;
250
255
  case "sweep": {
251
- paysOut = true;
256
+ withdrawsCollateral = true;
252
257
  const wrapped = ledger.balanceOf(underlying);
253
258
  if (rwaAsset && wrapped > 0n) push(await buildUnwrapRwaCollateralOperation({
254
259
  tokenIn: underlying,
@@ -259,7 +264,7 @@ async function realize(steps, props) {
259
264
  sdk
260
265
  }));
261
266
  for (const { token, balance } of ledger.snapshot().assets) {
262
- const payout = buildWithdrawCollateralOperation({
267
+ const withdrawal = buildWithdrawCollateralOperation({
263
268
  token,
264
269
  amount: balance,
265
270
  to: step.to,
@@ -267,8 +272,8 @@ async function realize(steps, props) {
267
272
  creditAccount,
268
273
  sdk
269
274
  });
270
- push(payout, {
271
- ...payout,
275
+ push(withdrawal, {
276
+ ...withdrawal,
272
277
  amount: expected.balanceOf(token)
273
278
  });
274
279
  }
@@ -297,7 +302,7 @@ async function realize(steps, props) {
297
302
  convert: price
298
303
  });
299
304
  if (!cleared && quotas.quotaIncrease.length + quotas.quotaDecrease.length > 0) {
300
- assertQuotaHeadroom(sdk, market, quotas.quotaIncrease);
305
+ assertQuotaAvailable(sdk, market, quotas.quotaIncrease);
301
306
  push(buildQuotaUpdateOperation({
302
307
  update: quotas,
303
308
  creditAccount,
@@ -318,7 +323,7 @@ async function realize(steps, props) {
318
323
  ...snapshot,
319
324
  assets,
320
325
  totalValue: floor.totalValue
321
- }, { safePrices: paysOut }), paysOut);
326
+ }, { safePrices: withdrawsCollateral }), withdrawsCollateral);
322
327
  const priceImpact = await collectPriceImpact(probes, {
323
328
  totalValue: projected.totalValue,
324
329
  netValue: projected.totalValue - debt,
@@ -347,13 +352,10 @@ async function realize(steps, props) {
347
352
  */
348
353
  async function delayedConfig(sdk, creditAccount, token) {
349
354
  const compressor = sdk.withdrawalCompressor;
350
- if (!compressor) throw new IntentPreviewError("noDelayedRoute", { token: toToken(sdk, token) }, "request: chain has no withdrawal compressor");
355
+ if (!compressor) throw new IntentPreviewError(noDelayedRoute(toToken(sdk, token)), "request: chain has no withdrawal compressor");
351
356
  const assets = await compressor.findWithdrawableAssets(creditAccount.creditManager, token);
352
- if (assets.length === 0) throw new IntentPreviewError("noDelayedRoute", { token: toToken(sdk, token) }, `request: ${token} has no delayed withdrawal config`);
353
- if (assets.length > 1) throw new IntentPreviewError("multipleDelayedWithdrawals", {
354
- token: toToken(sdk, token),
355
- venues: assets.length
356
- }, `request: ${token} has ${assets.length} delayed withdrawal configs`);
357
+ if (assets.length === 0) throw new IntentPreviewError(noDelayedRoute(toToken(sdk, token)), `request: ${token} has no delayed withdrawal config`);
358
+ if (assets.length > 1) throw new IntentPreviewError(multipleDelayedWithdrawals(toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
357
359
  return assets[0];
358
360
  }
359
361
  const callsOf = (operations) => operations.flatMap((op) => op.calls);
@@ -1,5 +1,8 @@
1
- import { IntentPreviewError } from "../../validation/refusal.js";
2
- import { toTokenAmount } from "../../validation/token.js";
1
+ import { insufficientBalance } from "../../../model/errors/operation-errors.js";
2
+ import { noRecordedIntent } from "../../../model/errors/prepare-errors.js";
3
+ import "../../../model/index.js";
4
+ import { toTokenAmount } from "../../validation/helpers/token.js";
5
+ import { IntentPreviewError } from "../../validation/raise.js";
3
6
  import { toTargetDecimals } from "./utils/common.js";
4
7
  import { createOraclePaths } from "./utils/router-path.js";
5
8
  import { planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw } from "./plan.js";
@@ -16,14 +19,14 @@ import { accountView } from "./view.js";
16
19
  * tail as it is projected the moment the request is made.
17
20
  *
18
21
  * A claim that brought only part of what was queued is served in proportion,
19
- * see {@link partialTail}: the intent's payout and its repayment are cut to the
22
+ * see {@link partialTail}: the intent's withdrawal and its repayment are cut to the
20
23
  * share that arrived, and the rest of both is handed to the next claim.
21
24
  */
22
25
  function planTail(args) {
23
26
  const { intent, claimable, view } = args;
24
27
  const claimed = () => {
25
28
  const output = instantOutput(claimable.outputs);
26
- if (!output) throw new IntentPreviewError("insufficientSourceBalance", void 0, "finishIntent: the claim credits nothing to spend");
29
+ if (!output) throw new IntentPreviewError(insufficientBalance(), "finishIntent: the claim credits nothing to spend");
27
30
  return output;
28
31
  };
29
32
  const queued = claimable.outputs.find((o) => o.isDelayed && o.amount > 0n);
@@ -51,12 +54,12 @@ const whole = (steps) => ({
51
54
  /**
52
55
  * The tail of a claim that settled only part of the withdrawal it matured.
53
56
  *
54
- * Only a legacy Mellow multivault answers one this way — it pays out what its
57
+ * Only a legacy Mellow multivault answers one this way — it hands over what its
55
58
  * subvaults hold liquid and queues the rest — and the engine cannot finish an
56
59
  * intent it has been given a fraction of the funds for. So the fraction is what
57
- * it serves: the payout and the repayment are cut in the proportion that
60
+ * it serves: the withdrawal and the repayment are cut in the proportion that
58
61
  * arrived, which keeps the withdrawal at the fixed leverage it was asked for
59
- * instead of paying the wallet out first and deleveraging a claim later, and
62
+ * instead of paying the wallet first and deleveraging a claim later, and
60
63
  * the untouched half of each is carried to the next claim by the remainder.
61
64
  *
62
65
  * Two intents cannot be served in part at all. An exit sells the account whole,
@@ -123,7 +126,7 @@ function partialTail(args) {
123
126
  * How much of the redemption this claim was: what it credited, over that plus
124
127
  * what it left queued.
125
128
  *
126
- * The phantom stands for its payout one for one — the same reading the request
129
+ * The phantom stands for its claim one for one — the same reading the request
127
130
  * side takes when it names the claim it expects — so only the decimals of the
128
131
  * two have to be reconciled before they can be added up.
129
132
  */
@@ -143,7 +146,7 @@ function part(amount, share) {
143
146
  *
144
147
  * A request is only half a withdrawal, so the state it lands in is not the
145
148
  * answer to "what does this do to my position": the debt is still there, the
146
- * payout has not been made, and the position sits in a phantom token. What the
149
+ * withdrawal has not been made, and the position sits in a phantom token. What the
147
150
  * caller means is the far side — and that side can be walked now, because the
148
151
  * request already fixes the claim it will be finished from.
149
152
  *
@@ -160,7 +163,7 @@ async function projectTail(args) {
160
163
  const { request, delayed, creditAccount, sdk, quotaReserve } = args;
161
164
  const { claim } = delayed;
162
165
  const queued = request.outputs.find((o) => o.isDelayed);
163
- if (!queued || !claim) throw new IntentPreviewError("noRecordedIntent", void 0, "projectTail: the request queued nothing to claim");
166
+ if (!queued || !claim) throw new IntentPreviewError(noRecordedIntent(), "projectTail: the request queued nothing to claim");
164
167
  const next = sliceAfter(creditAccount, delayed.afterRequest);
165
168
  const { steps } = planTail({
166
169
  intent: delayed.record,
@@ -184,7 +187,7 @@ async function projectTail(args) {
184
187
  }
185
188
  /**
186
189
  * The matured withdrawal the tail will be built from, as the request implies
187
- * it: the phantom it created is burned and the venue's payout takes its place.
190
+ * it: the phantom it created is burned and the claim takes its place.
188
191
  * It carries no claim calls — those are read from the chain when the claim is
189
192
  * real, and nothing here is going to be sent.
190
193
  */
@@ -122,6 +122,7 @@ function buildMockSdk(args) {
122
122
  const quotaOf = (token) => args.quotas[token.toLowerCase()] ?? args.quotas[token];
123
123
  const quotas = {
124
124
  values: () => Object.values(args.quotas).map(fullQuota),
125
+ has: (token) => quotaOf(token) !== void 0,
125
126
  get: (token) => {
126
127
  const q = quotaOf(token);
127
128
  return q === void 0 ? void 0 : fullQuota(q);
@@ -158,6 +159,10 @@ function buildMockSdk(args) {
158
159
  hasActiveQuota: (token) => {
159
160
  const q = quotaOf(token);
160
161
  return !!q?.isActive && q.limit > 0n;
162
+ },
163
+ quotaAvailable: (token) => {
164
+ const q = quotas.get(token);
165
+ return q === void 0 ? 0n : q.limit - q.totalQuoted;
161
166
  }
162
167
  },
163
168
  pool: {
@@ -191,6 +196,8 @@ function buildMockSdk(args) {
191
196
  liquidationFees: () => MOCK_LIQUIDATION_FEES,
192
197
  totalLiquidationDiscount: CreditSuite.prototype.totalLiquidationDiscount,
193
198
  creditOperationMarket: CreditSuite.prototype.creditOperationMarket,
199
+ isForbidden: CreditSuite.prototype.isForbidden,
200
+ maxBorrowAmount: CreditSuite.prototype.maxBorrowAmount,
194
201
  creditManager: {
195
202
  address: args.creditManager,
196
203
  liquidationThresholds,
@@ -109,11 +109,11 @@ const M4_LT = 9200n;
109
109
  const m4QuotaOf = (balance) => balance * M4_LT / 10000n;
110
110
  /** Matrix baseline debt: 8U. */
111
111
  const M4_DEBT = 800000000n;
112
- /** Matrix payout W: 1U. */
112
+ /** Matrix withdrawal W: 1U. */
113
113
  const M4_W = 100000000n;
114
114
  /** Proportional repayment `dD = D0 * W / C0` = 4U. */
115
115
  const M4_DD = 400000000n;
116
- /** Payout plus repayment: 5U redeemed by the leading half. */
116
+ /** Withdrawal plus repayment: 5U redeemed by the leading half. */
117
117
  const M4_SPEND = 500000000n;
118
118
  /** Quotable withdrawal phantom: `POS2`, 1:1 with `POS`. */
119
119
  const M4_PHANTOM = POS2;
@@ -153,10 +153,10 @@ function m4PhantomQuotaResetOp() {
153
153
  /**
154
154
  * Matrix 4.3 tail — the claim pays `UND` directly.
155
155
  *
156
- * MATRIX MISMATCH: the matrix pays out first — `claim →
156
+ * MATRIX MISMATCH: the matrix withdraws first — `claim →
157
157
  * withdrawCollateral(min(W, claim.amount)) → decreaseDebt(rest) →
158
- * changeQuota`. The engine repays before paying out (`repay(debtRepaid,
159
- * keep: W)` precedes the payout leg in `planFinishWithdraw`):
158
+ * changeQuota`. The engine repays before withdrawing (`repay(debtRepaid,
159
+ * keep: W)` precedes the withdrawal leg in `planFinishWithdraw`):
160
160
  * `claim → decreaseDebt(dD) → withdrawCollateral(W) → changeQuota`.
161
161
  * Amounts are identical; only the order differs.
162
162
  */
@@ -216,7 +216,7 @@ const case_matrix_4_4_tail = {
216
216
  ]
217
217
  };
218
218
  /**
219
- * Matrix 4.5 tail — 4.3 on the RWA market: unwrap before the payout.
219
+ * Matrix 4.5 tail — 4.3 on the RWA market: unwrap before the withdrawal.
220
220
  *
221
221
  * MATRIX MISMATCH: same ordering divergence as 4.3 — the matrix expects
222
222
  * `claim → unwrapRwaCollateral → withdrawCollateral(RWA) → decreaseDebt →
@@ -15,7 +15,7 @@ const LT = 9200n;
15
15
  const quotaOf = (balance) => balance * LT / 10000n;
16
16
  /** 100 UND of value leaving the account. */
17
17
  const W = 10000000000n;
18
- /** Payout plus proportional repayment. */
18
+ /** Withdrawal plus proportional repayment. */
19
19
  const SPEND = 2n * W;
20
20
  const TVL_BEFORE = 200000000000n;
21
21
  const DEBT_BEFORE = 100000000000n;
@@ -49,7 +49,7 @@ const case_und_und = {
49
49
  to: WALLET
50
50
  }]
51
51
  };
52
- /** Row 2 — S = U, T = POS: repay, then route the payout out of the underlying. */
52
+ /** Row 2 — S = U, T = POS: repay, then route the withdrawal out of the underlying. */
53
53
  const case_und_pos = {
54
54
  ...base,
55
55
  intent: {
@@ -215,8 +215,8 @@ const case_pos_pos2 = {
215
215
  }
216
216
  ]
217
217
  };
218
- /** RWA market: the underlying payout is force-unwrapped to the asset. */
219
- const case_rwa_payout = {
218
+ /** RWA market: the underlying withdrawal is force-unwrapped to the asset. */
219
+ const case_rwa_pos_und = {
220
220
  ...base,
221
221
  intent: {
222
222
  type: "WITHDRAW",
@@ -267,18 +267,18 @@ const case_rwa_payout = {
267
267
  /** Matrix baseline: 10A of position against 8U of debt (2U collateral at 5x). */
268
268
  const M4_BALANCE = 1000000000n;
269
269
  const M4_DEBT = 800000000n;
270
- /** Matrix payout W: 1U. */
270
+ /** Matrix withdrawal W: 1U. */
271
271
  const M4_W = 100000000n;
272
272
  /** Proportional repayment `dD = D0 * W / C0` = 4U. */
273
273
  const M4_DD = 400000000n;
274
- /** Payout plus repayment: 5U liquidated in total. */
274
+ /** Withdrawal plus repayment: 5U liquidated in total. */
275
275
  const M4_SPEND = 500000000n;
276
276
  /**
277
- * Matrix 4.1 — withdraw 1U, source `POS`, payout `UND`.
277
+ * Matrix 4.1 — withdraw 1U, source `POS`, tokenOut `UND`.
278
278
  *
279
- * MATRIX MISMATCH: the matrix pays out first — `swap → withdrawCollateral →
280
- * decreaseDebt → changeQuota`. The engine repays before paying out
281
- * (`repay(dD, keep: W)` precedes the payout leg in `planWithdraw`):
279
+ * MATRIX MISMATCH: the matrix withdraws first — `swap → withdrawCollateral →
280
+ * decreaseDebt → changeQuota`. The engine repays before withdrawing
281
+ * (`repay(dD, keep: W)` precedes the withdrawal leg in `planWithdraw`):
282
282
  * `swap → decreaseDebt → withdrawCollateral → changeQuota`. Amounts are
283
283
  * identical; only the order differs.
284
284
  */
@@ -325,7 +325,7 @@ const case_matrix_4_1 = {
325
325
  ]
326
326
  };
327
327
  /**
328
- * Matrix 4.2 — 4.1 on the RWA market: the payout is unwrapped on the way out.
328
+ * Matrix 4.2 — 4.1 on the RWA market: the withdrawal is unwrapped on the way out.
329
329
  *
330
330
  * MATRIX MISMATCH: same ordering divergence as 4.1 — the matrix expects
331
331
  * `swap → unwrapRwaCollateral → withdrawCollateral(RWA) → decreaseDebt →
@@ -399,4 +399,4 @@ function buildWithdrawProps(c, sdk) {
399
399
  };
400
400
  }
401
401
  //#endregion
402
- export { DEBT_AFTER, DEBT_BEFORE, M4_BALANCE, M4_DD, M4_DEBT, M4_SPEND, M4_W, QUOTA_AFTER, QUOTA_BEFORE, QUOTA_DELTA, SPEND, TVL_AFTER, TVL_BEFORE, W, buildWithdrawProps, buildWithdrawSdk, case_matrix_4_1, case_matrix_4_2, case_pos_pos, case_pos_pos2, case_pos_und, case_rwa_payout, case_und_pos, case_und_und };
402
+ export { DEBT_AFTER, DEBT_BEFORE, M4_BALANCE, M4_DD, M4_DEBT, M4_SPEND, M4_W, QUOTA_AFTER, QUOTA_BEFORE, QUOTA_DELTA, SPEND, TVL_AFTER, TVL_BEFORE, W, buildWithdrawProps, buildWithdrawSdk, case_matrix_4_1, case_matrix_4_2, case_pos_pos, case_pos_pos2, case_pos_und, case_rwa_pos_und, case_und_pos, case_und_und };
@@ -21,7 +21,7 @@ function accountView(creditAccount, sdk) {
21
21
  rwaAsset: sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset,
22
22
  debt: creditAccount.totalDebt,
23
23
  collateral: totalValue - creditAccount.totalDebt,
24
- band: {
24
+ debtLimits: {
25
25
  minDebt: creditFacade.minDebt,
26
26
  maxDebt: creditFacade.maxDebt
27
27
  },
@@ -8,5 +8,4 @@ import { WithdrawalCompressorV311Contract } from "./WithdrawalCompressorV311Cont
8
8
  import { toWithdrawalStatus } from "./types.js";
9
9
  import { WithdrawalCompressorV313Contract } from "./WithdrawalCompressorV313Contract.js";
10
10
  import { createWithdrawalCompressor } from "./createWithdrawalCompressor.js";
11
- import "./errors.js";
12
11
  export { AbstractWithdrawalCompressorContract, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, getWithdrawalCompressorAddress, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };