@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.10

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 (444) hide show
  1. package/dist/cjs/abi/iExpirable.js +15 -0
  2. package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  3. package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  4. package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  5. package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
  6. package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  7. package/dist/cjs/dev/AccountOpener.js +0 -1
  8. package/dist/cjs/dev/compareOpportunities.js +218 -0
  9. package/dist/cjs/model/charts.js +147 -0
  10. package/dist/cjs/model/charts.schema.js +240 -0
  11. package/dist/cjs/model/index.js +35 -22
  12. package/dist/cjs/model/liquidations.schema.js +1 -1
  13. package/dist/cjs/model/notices.schema.js +25 -0
  14. package/dist/cjs/model/opportunities.schema.js +1 -1
  15. package/dist/cjs/model/positions.schema.js +48 -2
  16. package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
  17. package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
  18. package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
  19. package/dist/cjs/new-sdk/execute/index.js +3 -0
  20. package/dist/cjs/new-sdk/index.js +7 -0
  21. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  22. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
  23. package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
  24. package/dist/cjs/new-sdk/simulate/index.js +4 -0
  25. package/dist/cjs/new-sdk/utils/index.js +0 -1
  26. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  27. package/dist/cjs/offchain/GearboxAPI.js +7 -0
  28. package/dist/cjs/offchain/index.js +3 -0
  29. package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
  30. package/dist/cjs/offchain/notices/index.js +3 -0
  31. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  32. package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
  33. package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
  34. package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
  35. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
  36. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
  37. package/dist/cjs/preview/preview/previewOperation.js +1 -1
  38. package/dist/cjs/sdk/MultichainSDK.js +3 -4
  39. package/dist/cjs/sdk/OnchainSDK.js +42 -13
  40. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
  41. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  42. package/dist/cjs/sdk/accounts/index.js +5 -2
  43. package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
  44. package/dist/cjs/sdk/accounts/intents/index.js +216 -358
  45. package/dist/cjs/sdk/accounts/intents/math.js +56 -0
  46. package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
  47. package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
  48. package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
  49. package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
  50. package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
  51. package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
  52. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
  53. package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
  54. package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
  55. package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
  56. package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
  57. package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
  58. package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
  59. package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
  60. package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
  61. package/dist/cjs/sdk/accounts/intents/types.js +16 -0
  62. package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
  63. package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
  64. package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
  65. package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
  66. package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
  67. package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
  68. package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
  69. package/dist/cjs/sdk/accounts/intents/view.js +38 -0
  70. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
  71. package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  72. package/dist/cjs/sdk/base/BaseContract.js +1 -1
  73. package/dist/cjs/sdk/base/TokensMeta.js +78 -27
  74. package/dist/cjs/sdk/index.js +30 -7
  75. package/dist/cjs/sdk/market/MarketRegister.js +16 -7
  76. package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
  77. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
  78. package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
  79. package/dist/cjs/sdk/market/credit/index.js +3 -0
  80. package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
  81. package/dist/cjs/sdk/market/index.js +17 -0
  82. package/dist/cjs/sdk/market/math.js +57 -44
  83. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  84. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
  85. package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
  86. package/dist/cjs/sdk/opportunities/index.js +0 -13
  87. package/dist/cjs/sdk/options.js +1 -5
  88. package/dist/cjs/sdk/pools/PoolService.js +132 -3
  89. package/dist/cjs/sdk/pools/index.js +2 -0
  90. package/dist/cjs/sdk/positions/PositionsService.js +213 -1
  91. package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
  92. package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
  93. package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
  94. package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
  95. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
  96. package/dist/cjs/sdk/positions/index.js +12 -1
  97. package/dist/cjs/sdk/positions/types.js +31 -0
  98. package/dist/cjs/sdk/utils/abi-decode.js +2 -2
  99. package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
  100. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  101. package/dist/esm/abi/iExpirable.js +14 -0
  102. package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  103. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  104. package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  105. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
  106. package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  107. package/dist/esm/dev/AccountOpener.js +1 -2
  108. package/dist/esm/dev/compareOpportunities.js +216 -0
  109. package/dist/esm/dev/withdrawalUtils.js +1 -1
  110. package/dist/esm/model/charts.js +140 -0
  111. package/dist/esm/model/charts.schema.js +226 -0
  112. package/dist/esm/model/index.js +9 -7
  113. package/dist/esm/model/liquidations.schema.js +1 -1
  114. package/dist/esm/model/notices.schema.js +23 -0
  115. package/dist/esm/model/opportunities.schema.js +1 -1
  116. package/dist/esm/model/positions.schema.js +46 -4
  117. package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
  118. package/dist/esm/new-sdk/GearboxSDK.js +72 -4
  119. package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
  120. package/dist/esm/new-sdk/execute/index.js +2 -0
  121. package/dist/esm/new-sdk/index.js +6 -2
  122. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  123. package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
  124. package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
  125. package/dist/esm/new-sdk/simulate/index.js +3 -0
  126. package/dist/esm/new-sdk/utils/index.js +0 -1
  127. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  128. package/dist/esm/offchain/GearboxAPI.js +7 -0
  129. package/dist/esm/offchain/index.js +3 -1
  130. package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
  131. package/dist/esm/offchain/notices/index.js +2 -0
  132. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  133. package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
  134. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  135. package/dist/esm/preview/preview/CreditAccountState.js +14 -1
  136. package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
  137. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
  138. package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
  139. package/dist/esm/preview/preview/previewOperation.js +1 -1
  140. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  141. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  142. package/dist/esm/sdk/MultichainSDK.js +3 -4
  143. package/dist/esm/sdk/OnchainSDK.js +42 -13
  144. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +4 -10
  145. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  146. package/dist/esm/sdk/accounts/index.js +3 -2
  147. package/dist/esm/sdk/accounts/intents/guards.js +108 -0
  148. package/dist/esm/sdk/accounts/intents/index.js +214 -358
  149. package/dist/esm/sdk/accounts/intents/math.js +51 -0
  150. package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
  151. package/dist/esm/sdk/accounts/intents/operations.js +153 -0
  152. package/dist/esm/sdk/accounts/intents/plan.js +361 -0
  153. package/dist/esm/sdk/accounts/intents/realize.js +300 -0
  154. package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
  155. package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
  156. package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
  157. package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
  158. package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
  159. package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
  160. package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
  161. package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
  162. package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
  163. package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
  164. package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
  165. package/dist/esm/sdk/accounts/intents/types.js +16 -1
  166. package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
  167. package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
  168. package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
  169. package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
  170. package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
  171. package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
  172. package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
  173. package/dist/esm/sdk/accounts/intents/view.js +37 -0
  174. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
  175. package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  176. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  177. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  178. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  179. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  180. package/dist/esm/sdk/base/BaseContract.js +1 -1
  181. package/dist/esm/sdk/base/TokensMeta.js +80 -29
  182. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  183. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  184. package/dist/esm/sdk/index.js +13 -4
  185. package/dist/esm/sdk/market/MarketRegister.js +16 -7
  186. package/dist/esm/sdk/market/ZapperRegister.js +56 -25
  187. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  188. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
  189. package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
  190. package/dist/esm/sdk/market/credit/index.js +2 -1
  191. package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
  192. package/dist/esm/sdk/market/index.js +3 -1
  193. package/dist/esm/sdk/market/math.js +52 -40
  194. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  195. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -3
  196. package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
  197. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  198. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  199. package/dist/esm/sdk/opportunities/index.js +1 -2
  200. package/dist/esm/sdk/options.js +1 -5
  201. package/dist/esm/sdk/pools/PoolService.js +133 -6
  202. package/dist/esm/sdk/pools/index.js +2 -2
  203. package/dist/esm/sdk/positions/PositionsService.js +213 -1
  204. package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
  205. package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
  206. package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
  207. package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
  208. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
  209. package/dist/esm/sdk/positions/index.js +7 -2
  210. package/dist/esm/sdk/positions/types.js +31 -1
  211. package/dist/esm/sdk/utils/abi-decode.js +2 -2
  212. package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
  213. package/dist/esm/sdk/utils/viem/index.js +2 -1
  214. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  215. package/dist/types/abi/iExpirable.d.ts +14 -0
  216. package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
  217. package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
  218. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
  219. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
  220. package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
  221. package/dist/types/dev/compareOpportunities.d.ts +153 -0
  222. package/dist/types/model/charts.d.ts +349 -0
  223. package/dist/types/model/charts.schema.d.ts +364 -0
  224. package/dist/types/model/index.d.ts +8 -6
  225. package/dist/types/model/notices.d.ts +29 -0
  226. package/dist/types/model/notices.schema.d.ts +23 -0
  227. package/dist/types/model/opportunities.d.ts +9 -9
  228. package/dist/types/model/positions.d.ts +133 -7
  229. package/dist/types/model/positions.schema.d.ts +128 -1
  230. package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
  231. package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
  232. package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
  233. package/dist/types/new-sdk/execute/index.d.ts +2 -0
  234. package/dist/types/new-sdk/index.d.ts +8 -4
  235. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
  236. package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
  237. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  238. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  239. package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
  240. package/dist/types/new-sdk/simulate/index.d.ts +3 -0
  241. package/dist/types/new-sdk/simulate/types.d.ts +508 -0
  242. package/dist/types/new-sdk/types.d.ts +35 -1
  243. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  244. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  245. package/dist/types/offchain/GearboxAPI.d.ts +6 -0
  246. package/dist/types/offchain/index.d.ts +4 -2
  247. package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
  248. package/dist/types/offchain/notices/index.d.ts +2 -0
  249. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  250. package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
  251. package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
  252. package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
  253. package/dist/types/preview/preview/types.d.ts +4 -2
  254. package/dist/types/sdk/MultichainSDK.d.ts +0 -5
  255. package/dist/types/sdk/OnchainSDK.d.ts +1 -5
  256. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
  257. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
  258. package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
  259. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
  260. package/dist/types/sdk/accounts/index.d.ts +7 -5
  261. package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
  262. package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
  263. package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
  264. package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
  265. package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
  266. package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
  267. package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
  268. package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
  269. package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
  270. package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
  271. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
  272. package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
  273. package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
  274. package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
  275. package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
  276. package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
  277. package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
  278. package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
  279. package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
  280. package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
  281. package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
  282. package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
  283. package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
  284. package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
  285. package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
  286. package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
  287. package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
  288. package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
  289. package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
  290. package/dist/types/sdk/accounts/types.d.ts +17 -14
  291. package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
  292. package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
  293. package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
  294. package/dist/types/sdk/base/index.d.ts +2 -2
  295. package/dist/types/sdk/base/token-types.d.ts +12 -1
  296. package/dist/types/sdk/index.d.ts +28 -19
  297. package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
  298. package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
  299. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
  300. package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
  301. package/dist/types/sdk/market/credit/index.d.ts +2 -1
  302. package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
  303. package/dist/types/sdk/market/credit/types.d.ts +2 -9
  304. package/dist/types/sdk/market/index.d.ts +4 -2
  305. package/dist/types/sdk/market/math.d.ts +44 -34
  306. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
  307. package/dist/types/sdk/market/oracle/types.d.ts +10 -2
  308. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
  309. package/dist/types/sdk/market/pool/types.d.ts +5 -0
  310. package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
  311. package/dist/types/sdk/market/types.d.ts +5 -1
  312. package/dist/types/sdk/opportunities/index.d.ts +1 -2
  313. package/dist/types/sdk/options.d.ts +0 -1
  314. package/dist/types/sdk/pools/PoolService.d.ts +32 -2
  315. package/dist/types/sdk/pools/index.d.ts +3 -3
  316. package/dist/types/sdk/pools/types.d.ts +109 -4
  317. package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
  318. package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
  319. package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
  320. package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
  321. package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
  322. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
  323. package/dist/types/sdk/positions/index.d.ts +7 -2
  324. package/dist/types/sdk/positions/types.d.ts +58 -1
  325. package/dist/types/sdk/types/state.d.ts +6 -0
  326. package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
  327. package/dist/types/sdk/utils/viem/index.d.ts +3 -2
  328. package/package.json +2 -1
  329. package/dist/cjs/model/history.js +0 -53
  330. package/dist/cjs/model/history.schema.js +0 -128
  331. package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
  332. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
  333. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
  334. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
  335. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
  336. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
  337. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
  338. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
  339. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
  340. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
  341. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
  342. package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
  343. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
  344. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
  345. package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
  346. package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
  347. package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
  348. package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
  349. package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
  350. package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
  351. package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
  352. package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
  353. package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
  354. package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
  355. package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
  356. package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
  357. package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
  358. package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
  359. package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
  360. package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
  361. package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
  362. package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
  363. package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
  364. package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
  365. package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
  366. package/dist/esm/model/history.js +0 -49
  367. package/dist/esm/model/history.schema.js +0 -116
  368. package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
  369. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
  370. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
  371. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
  372. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
  373. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
  374. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
  375. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
  376. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
  377. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
  378. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
  379. package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
  380. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
  381. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
  382. package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
  383. package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
  384. package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
  385. package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
  386. package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
  387. package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
  388. package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
  389. package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
  390. package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
  391. package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
  392. package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
  393. package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
  394. package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
  395. package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
  396. package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
  397. package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
  398. package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
  399. package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
  400. package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
  401. package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
  402. package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
  403. package/dist/types/model/history.d.ts +0 -153
  404. package/dist/types/model/history.schema.d.ts +0 -95
  405. package/dist/types/new-sdk/utils/history.d.ts +0 -18
  406. package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
  407. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
  408. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
  409. package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
  410. package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
  411. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
  412. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
  413. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
  414. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
  415. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
  416. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
  417. package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
  418. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
  419. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
  420. package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
  421. package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
  422. package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
  423. package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
  424. package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
  425. package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
  426. package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
  427. package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
  428. package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
  429. package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
  430. package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
  431. package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
  432. package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
  433. package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
  434. package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
  435. package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
  436. package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
  437. package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
  438. package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
  439. package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
  440. package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
  441. /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
  442. /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
  443. /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
  444. /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
@@ -1,14 +1,17 @@
1
- import { DelayedIntent, RequestableWithdrawal } from "../withdrawal-compressor/types.js";
1
+ import { Leverage } from "../../../model/primitives.js";
2
+ import { ClaimableWithdrawal, DelayedIntent } from "../withdrawal-compressor/types.js";
2
3
  import { Asset } from "../../base/types.js";
4
+ import { PositionMetrics } from "../../../model/positions.js";
5
+ import "../../../model/index.js";
3
6
  import { RouterCASlice } from "../../router/types.js";
4
7
  import { MultiCall } from "../../types/transactions.js";
5
- import { AccountCalculatorOperation } from "./operations/types.js";
6
- import "./operations/index.js";
8
+ import { OnchainSDK } from "../../OnchainSDK.js";
9
+ import { AccountCalculatorOperation } from "./operations.js";
7
10
  import "../../index.js";
8
11
  import { Address } from "viem";
9
12
  //#region src/sdk/accounts/intents/types.d.ts
10
13
  /**
11
- * Minimal credit-account data needed by resume previews:
14
+ * Minimal credit-account data an intent is previewed against:
12
15
  * account address, CM lookup, underlying for conversion, debt, token balances
13
16
  * and initial quotas.
14
17
  */
@@ -16,60 +19,383 @@ type CreditAccountSlice = Omit<RouterCASlice, "debt"> & {
16
19
  /** either base debt or debt plus interest and fees */
17
20
  accountDebt: bigint;
18
21
  };
19
- /** Post-adjust CA metrics. */
20
- type AdjustState = {
21
- kind: "adjust";
22
+ /** Projected account metrics once the operations execute. */
23
+ interface OperationState extends PositionMetrics {
22
24
  /** Account TVL after operation */
23
25
  totalValue: bigint;
24
26
  /** Account debt after operation */
25
27
  accountDebt: bigint;
28
+ /**
29
+ * Leverage after operation in the read model's convention — `debt / equity`,
30
+ * as `Position.leverage` reports it — not the calculator's `TVL / collateral`.
31
+ */
32
+ leverage: Leverage;
26
33
  /** Account assets after operation */
27
34
  assets: Asset[];
28
35
  /** Account quotas after operation */
29
36
  quotas: Record<Address, Asset>;
30
- };
31
- /** Close state result. */
32
- type CloseState = {
33
- kind: "close";
34
- /** Received amount */
35
- amount: bigint;
36
- /** Conservative receive (min branch / pathfinder floor). */
37
- minAmount: bigint;
38
- /** Pathfinder underlying on CA after close path; 0n when unknown (instant). */
39
- underlyingBalance: bigint;
40
- };
41
- type OperationState = AdjustState | CloseState;
42
- type DelayedBranchKind = "instantSettle" | "partialSettle" | "delayedSettle";
43
- type DelayedBranchResult = {
44
- kind: DelayedBranchKind;
37
+ }
38
+ /**
39
+ * Why a preview could not be produced.
40
+ *
41
+ * Every member is thrown by the engine as an {@link IntentPreviewError}, with
42
+ * the exception of `unsupportedTokenPair` and `noRecordedIntent`, which the
43
+ * simulate namespace reports for a request it can refuse before planning: a
44
+ * route the market does not offer, a claim naming no operation.
45
+ */
46
+ type PreviewErrorReason = "debtOutOfRange" | "leverageOutOfRange" | "insufficientSourceBalance" |
47
+ /** Input token is not accepted by the flow (e.g. deposit of a non-underlying). */
48
+ "unsupportedCollateralToken" |
49
+ /** No pool route between the requested pair, or several and none was picked. */
50
+ "unsupportedTokenPair" |
51
+ /**
52
+ * The intent cannot settle with a delay: the source has no redemption config,
53
+ * the chain has no compressor, or the payout is one the tail cannot serve.
54
+ */
55
+ "noDelayedRoute" |
56
+ /** Several redemption venues for the source, and nothing says which. */
57
+ "multipleDelayedWithdrawals" |
58
+ /** A redemption of the same asset is already in flight. */
59
+ "withdrawalInProgress" |
60
+ /**
61
+ * The claim names no operation to resume: requested without an intent, read
62
+ * through a compressor too old to report one, or a full close, which the
63
+ * engine no longer previews.
64
+ */
65
+ "noRecordedIntent" |
66
+ /** The facade or the pool behind it is paused: nothing can be done at all. */
67
+ "marketPaused" |
68
+ /** The facade is past its expiration date and takes no more multicalls. */
69
+ "marketExpired" |
70
+ /**
71
+ * The pool cannot lend what the plan draws right now — its free liquidity,
72
+ * the manager's debt limit or the per-block cap stands in the way.
73
+ */
74
+ "insufficientPoolLiquidity" |
75
+ /** The market takes no more quota for a token the plan wants to hold. */
76
+ "quotaLimitReached" |
77
+ /** The plan would increase the balance of a token the market forbids. */
78
+ "forbiddenToken" |
79
+ /**
80
+ * The account would end the transaction owing more than its collateral is
81
+ * worth under liquidation thresholds, which the facade refuses to allow.
82
+ */
83
+ "insufficientCollateral";
84
+ /**
85
+ * What a preview yields: the operation chain, the state it projects, and the
86
+ * calldata that realises it — or the reason the request is not viable.
87
+ */
88
+ type IntentPreviewResult = {
89
+ ok: true;
45
90
  operations: AccountCalculatorOperation[];
46
- preview: {
47
- min: OperationState;
48
- };
91
+ preview: OperationState;
49
92
  calls: MultiCall[];
50
- intent: DelayedIntent;
51
- request?: RequestableWithdrawal;
93
+ } | {
94
+ ok: false;
95
+ reason: PreviewErrorReason;
52
96
  };
53
- type DelayedErrorReason = "multipleDelayedWithdrawals" | "withdrawalInProgress";
54
- type InstantBranchResult = {
97
+ /** What the request recorded, and when the tail can be run. */
98
+ interface DelayedStart {
99
+ /**
100
+ * The intent written into the request, and decoded back from the claimable
101
+ * withdrawal at claim time. Feed it to
102
+ * `CreditAccountOperationsService.finishIntent`.
103
+ */
104
+ record: DelayedIntent;
105
+ /** Unix seconds after which the delayed outputs can be claimed. */
106
+ claimableAt: bigint;
107
+ /**
108
+ * `instant` when the venue served the whole request on the spot, so no claim
109
+ * will ever arrive to carry the tail. The intent is then left half-done —
110
+ * nothing repaid, nothing paid out — and the caller wants `startIntent`
111
+ * instead, which settles all of it in one transaction.
112
+ */
113
+ settlement: "instant" | "delayed";
114
+ }
115
+ /**
116
+ * What the leading half of a delayed intent yields: the request transaction,
117
+ * plus what it recorded for the tail.
118
+ */
119
+ type DelayedStartResult = {
120
+ ok: true;
55
121
  operations: AccountCalculatorOperation[];
56
- preview: {
57
- min: OperationState;
58
- };
122
+ preview: OperationState;
59
123
  calls: MultiCall[];
60
- };
61
- type InstantErrorReason = "pathNotFound";
62
- type PreviewErrorResult = {
124
+ delayed: DelayedStart;
125
+ } | {
63
126
  ok: false;
64
- reason: "unsupportedFieldPair" | "debtOutOfRange" | "leverageOutOfRange" | "multipleDelayedWithdrawals" | "unsupportedMixedDelayedWithdrawal" | "unsupportedCloseClaimOutput" | "insufficientSourceBalance";
127
+ reason: PreviewErrorReason;
65
128
  };
66
- interface IntentPreviewSuccessResult {
129
+ /** An intent previewed through the router: one transaction, settled now. */
130
+ type InstantRoute = Extract<IntentPreviewResult, {
131
+ ok: true;
132
+ }>;
133
+ /** An intent previewed as a redemption: the request now, the tail later. */
134
+ type DelayedRoute = Extract<DelayedStartResult, {
135
+ ok: true;
136
+ }>;
137
+ /**
138
+ * Why a route is missing from an {@link IntentRoutesResult}.
139
+ *
140
+ * A reason is the engine's refusal — `noDelayedRoute` for a source with no
141
+ * redemption venue or for a leverage move that settles at once,
142
+ * `insufficientSourceBalance` for a payout the account cannot fund. `undefined`
143
+ * next to a missing route means the route could not be quoted at all: the
144
+ * pathfinder found no way out of the source, or the read behind it failed.
145
+ */
146
+ interface RouteRefusals {
147
+ instant: PreviewErrorReason | undefined;
148
+ delayed: PreviewErrorReason | undefined;
149
+ }
150
+ /**
151
+ * Both ways one intent can be served, previewed side by side: traded through
152
+ * the router, which settles in a single transaction, or redeemed through the
153
+ * source's issuer, which answers now and pays out days later.
154
+ *
155
+ * Which of them an account can take depends on the intent and the token it
156
+ * sells, so both are quoted and a route it cannot take comes back `undefined`
157
+ * with its refusal in `refused`. Only when neither answers is the request itself
158
+ * unviable, and then `reason` is the instant route's refusal — the route every
159
+ * account is expected to have — falling back to the delayed one's.
160
+ */
161
+ type IntentRoutesResult = {
67
162
  ok: true;
68
- instant: InstantBranchResult | undefined;
69
- instantError: InstantErrorReason | undefined;
70
- delayedBranch: DelayedBranchResult | undefined;
71
- delayedError: DelayedErrorReason | undefined;
163
+ instant: InstantRoute | undefined;
164
+ delayed: DelayedRoute | undefined;
165
+ refused: RouteRefusals;
166
+ } | {
167
+ ok: false;
168
+ reason: PreviewErrorReason;
169
+ refused: RouteRefusals;
170
+ };
171
+ /**
172
+ * The intents the engine previews.
173
+ *
174
+ * Naming avoids the `withdrawCollateral` collision that exists elsewhere in the
175
+ * repo. Mapping to the public simulate API:
176
+ *
177
+ * | Intent type | Public name | Debt |
178
+ * | ------------------ | -------------------------- | ------- |
179
+ * | `ADD_COLLATERAL` | `simulate.addCollateral` | fixed |
180
+ * | `WITHDRAW_ASSET` | `simulate.withdrawCollateral` | fixed |
181
+ * | `ADJUST_LEVERAGE` | `simulate.adjustLeverage` | changes |
182
+ * | `DEPOSIT` | `simulate.depositStrategy` | grows |
183
+ * | `WITHDRAW` | `simulate.withdrawStrategy` | shrinks |
184
+ * | `REPAY` | `simulate.repayStrategy` | shrinks |
185
+ */
186
+ /** Shared inputs for every start intent. */
187
+ type StartIntentProps = {
188
+ creditAccount: CreditAccountSlice;
189
+ sdk: OnchainSDK;
190
+ /**
191
+ * Extra quota headroom in PERCENTAGE_FORMAT, to survive price drift between
192
+ * preview and execution.
193
+ */
194
+ quotaReserve: number | undefined;
195
+ /** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
196
+ slippage: number | undefined;
197
+ };
198
+ /**
199
+ * Intent 5 — put the position token straight onto the account.
200
+ *
201
+ * Only the position token is accepted (e.g. ACRED): there is no swap and no
202
+ * RWA wrap leg, so whatever is sent lands as-is. Debt is untouched, therefore
203
+ * leverage drops and the health factor improves.
204
+ */
205
+ interface AddCollateralIntent {
206
+ type: "ADD_COLLATERAL";
207
+ /** Position token to deposit. */
208
+ token: Address;
209
+ amount: bigint;
210
+ /**
211
+ * Native value to attach when the deposited token is the market's wrapped
212
+ * native token and the caller is paying in the native coin.
213
+ */
214
+ value?: bigint;
215
+ }
216
+ /**
217
+ * Intent 4 — move one asset that already sits on the account to the wallet.
218
+ *
219
+ * Atomic: no swaps, no debt change, so leverage rises. The only special case is
220
+ * withdrawing the wrapped underlying of an RWA market, which is force-unwrapped
221
+ * to `rwa.asset` first because the wrapper itself cannot leave the account.
222
+ *
223
+ * @see AdjustLeverageIntent and the `WITHDRAW` intent for the deleveraging
224
+ * withdrawals, which do change debt.
225
+ */
226
+ interface WithdrawAssetIntent {
227
+ type: "WITHDRAW_ASSET";
228
+ /** Token to withdraw; must already be on the account. */
229
+ token: Address;
230
+ amount: bigint;
231
+ /** Wallet receiving the tokens. */
232
+ to: Address;
233
+ }
234
+ /**
235
+ * Intent 6 — retarget leverage while collateral (own funds) stays fixed.
236
+ *
237
+ * Because collateral is the invariant, the target leverage pins the new debt:
238
+ * raising it borrows more and buys the position token, lowering it sells the
239
+ * position token and repays. TVL moves with the debt; net value does not.
240
+ */
241
+ interface AdjustLeverageIntent {
242
+ type: "ADJUST_LEVERAGE";
243
+ /**
244
+ * Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x). 100n (1x)
245
+ * means "no debt".
246
+ */
247
+ targetLeverage: bigint;
248
+ /**
249
+ * Position token to buy into or sell out of. Defaults to the most valuable
250
+ * non-phantom, non-underlying balance on the account.
251
+ */
252
+ token?: Address;
253
+ }
254
+ /**
255
+ * Intents 1.1 / 1.2 — deposit into a strategy, growing the position.
256
+ *
257
+ * Fresh collateral arrives, debt is drawn on top of it, and the combined
258
+ * underlying is converted into the position token. The two spec variants differ
259
+ * only in how much debt is drawn:
260
+ *
261
+ * - 1.1, `targetLeverage` omitted: debt grows in proportion, leverage unchanged
262
+ * - 1.2, `targetLeverage` set: debt grows to hit the new, higher leverage
263
+ *
264
+ * Only the market underlying may be deposited. Two exceptions: a wrapped-native
265
+ * market also accepts the native coin (pass the wrapped token plus `value`), and
266
+ * an RWA market takes the unwrapped asset (USDC rather than dcUSDC), which this
267
+ * flow wraps for you.
268
+ */
269
+ interface DepositStrategyIntent {
270
+ type: "DEPOSIT";
271
+ /** Collateral token: the market underlying, or `rwa.asset` on an RWA market. */
272
+ token: Address;
273
+ amount: bigint;
274
+ /** Native value to attach when paying with the native coin. */
275
+ value?: bigint;
276
+ /**
277
+ * Token the position ends up in. Defaults to the most valuable non-phantom,
278
+ * non-underlying balance already on the account.
279
+ */
280
+ positionToken?: Address;
281
+ /**
282
+ * Target total leverage scaled by `LEVERAGE_DECIMALS`. Omit to preserve the
283
+ * account's current leverage.
284
+ */
285
+ targetLeverage?: bigint;
286
+ }
287
+ /**
288
+ * Intent 3 — repay debt with funds from the wallet.
289
+ *
290
+ * The mirror of {@link DepositStrategyIntent}: money arrives from outside and
291
+ * nothing on the account is sold, so collateral value stands still while debt
292
+ * shrinks. Net value grows by what was repaid, leverage falls, and the health
293
+ * factor improves — this is the flow that rescues an account, and the only one
294
+ * that lowers debt without touching the position.
295
+ *
296
+ * The market underlying is what a loan is denominated in, so sending it needs
297
+ * no conversion: it lands and is repaid. Two more forms are accepted, as for a
298
+ * deposit: a wrapped-native market also takes the native coin (pass the wrapped
299
+ * token plus `value`), and an RWA market takes the unwrapped asset behind its
300
+ * underlying, which this flow wraps for you.
301
+ */
302
+ interface RepayStrategyIntent {
303
+ type: "REPAY";
304
+ /** Funding token: the market underlying, or `rwa.asset` on an RWA market. */
305
+ token: Address;
306
+ /**
307
+ * Amount of `token` taken from the wallet. More than the outstanding debt is
308
+ * allowed — the debt is settled in full and the excess stays on the account
309
+ * as collateral — which is what lets a caller cover the interest that accrues
310
+ * between this preview and the transaction.
311
+ *
312
+ * `MAX_UINT256` asks for exactly that settlement without naming a figure: the
313
+ * wallet is charged the debt plus a small margin for the interest still to
314
+ * come, the facade is told to repay everything outstanding, and the quotas go
315
+ * with the loan.
316
+ */
317
+ amount: bigint;
318
+ /** Native value to attach when paying with the native coin. */
319
+ value?: bigint;
320
+ }
321
+ /**
322
+ * Intent 2.1 — withdraw part of the position's net value at fixed leverage.
323
+ *
324
+ * The requested amount leaves the account, and debt is repaid in the same
325
+ * proportion so leverage is unchanged: `dD = D0 * W / C0`. Both the payout and
326
+ * the repayment are funded by liquidating the source token, which means the
327
+ * account must give up `W + dD` of value in total.
328
+ *
329
+ * The payout leg and the repayment leg are quoted separately and do not share a
330
+ * pool, so a shortfall on the payout leg does not eat into the repayment.
331
+ *
332
+ * Asking for the whole net value is the exit instead — there is no leverage
333
+ * left to hold — and the shape changes with it: the quotas are dropped, the
334
+ * position is sold whole in one many-to-one route, the loan is settled in full
335
+ * and every remaining balance goes to the wallet. The account survives it,
336
+ * empty and owing nothing.
337
+ *
338
+ * @see WithdrawAssetIntent for moving a single asset out at fixed debt, and
339
+ * AdjustLeverageIntent for changing leverage without withdrawing.
340
+ */
341
+ interface WithdrawStrategyIntent {
342
+ type: "WITHDRAW";
343
+ /**
344
+ * Amount the wallet receives, denominated in `tokenOut`. At or above the
345
+ * account's net value this is an exit, which pays out the underlying the
346
+ * position was sold into rather than in `tokenOut`.
347
+ *
348
+ * `MAX_UINT256` is that exit stated outright, and the amount a "close
349
+ * position" form sends: no net value has to be read to name it, and no
350
+ * rounding can turn it back into a withdrawal that leaves dust behind.
351
+ */
352
+ amount: bigint;
353
+ /** Wallet receiving the payout. */
354
+ to: Address;
355
+ /**
356
+ * Token the wallet receives. Defaults to the market underlying — which, on an
357
+ * RWA market, is force-unwrapped to `rwa.asset` on the way out.
358
+ */
359
+ tokenOut?: Address;
360
+ /**
361
+ * Token liquidated to fund the withdrawal. Defaults to the most valuable
362
+ * non-phantom balance on the account, and is ignored by an exit — that sells
363
+ * every balance there is.
364
+ */
365
+ sourceToken?: Address;
366
+ }
367
+ type StartIntent = AddCollateralIntent | WithdrawAssetIntent | AdjustLeverageIntent | DepositStrategyIntent | RepayStrategyIntent | WithdrawStrategyIntent;
368
+ /**
369
+ * The intents that can be started as a redemption rather than a swap: the two
370
+ * that sell a position asset. The others buy one, and buying settles at once.
371
+ */
372
+ type DelayableIntent = AdjustLeverageIntent | WithdrawStrategyIntent;
373
+ /**
374
+ * A delayed intent this engine knows how to finish.
375
+ *
376
+ * `CLOSE_ACCOUNT` is absent on purpose: closing goes through the facade's own
377
+ * entry point, which this engine no longer builds.
378
+ */
379
+ type ResumableIntent = Exclude<DelayedIntent, {
380
+ type: "CLOSE_ACCOUNT";
381
+ }>;
382
+ /** Shared inputs plus the matured withdrawal the tail is built around. */
383
+ type FinishIntentProps = StartIntentProps & {
384
+ intent: ResumableIntent;
385
+ /**
386
+ * The matured withdrawal, as reported by
387
+ * `sdk.accounts.getPendingWithdrawals`.
388
+ */
389
+ claimable: ClaimableWithdrawal;
390
+ };
391
+ /**
392
+ * Validation failure that maps onto {@link PreviewErrorReason} rather than
393
+ * crashing the caller: thrown by builders, converted to `{ ok: false }` by
394
+ * `CreditAccountOperationsService.startIntent`.
395
+ */
396
+ declare class IntentPreviewError extends Error {
397
+ readonly reason: PreviewErrorReason;
398
+ constructor(reason: PreviewErrorReason, message?: string);
72
399
  }
73
- type IntentPreviewResult = IntentPreviewSuccessResult | PreviewErrorResult;
74
400
  //#endregion
75
- export { AdjustState, CloseState, CreditAccountSlice, IntentPreviewResult, OperationState };
401
+ export { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewError, IntentPreviewResult, IntentRoutesResult, OperationState, PreviewErrorReason, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent };
@@ -0,0 +1,13 @@
1
+ import { AccountSnapshot } from "../../../positions/types.js";
2
+ import "../../../positions/index.js";
3
+ import { OperationState } from "../types.js";
4
+ import { Address } from "viem";
5
+ //#region src/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts
6
+ /**
7
+ * Maps an intents {@link OperationState} onto the {@link AccountSnapshot} that
8
+ * position-metric functions take. `accountDebt` is treated as total debt
9
+ * (principal plus accrued interest and fees).
10
+ **/
11
+ declare function adjustStateToSnapshot(creditManager: Address, state: OperationState): AccountSnapshot;
12
+ //#endregion
13
+ export { adjustStateToSnapshot };
@@ -1,5 +1,5 @@
1
1
  import { MultiCall } from "../../../types/transactions.js";
2
- import { AccountCalculatorOperation } from "../operations/types.js";
2
+ import { AccountCalculatorOperation } from "../operations.js";
3
3
  import "../../../index.js";
4
4
  //#region src/sdk/accounts/intents/utils/assemble-operation-calls.d.ts
5
5
  interface Props {
@@ -0,0 +1,29 @@
1
+ import { CreditAccountDataPayload } from "../../../base/types.js";
2
+ import { OnchainSDK } from "../../../OnchainSDK.js";
3
+ import { CreditAccountSlice } from "../types.js";
4
+ import "../../../index.js";
5
+ import { Address } from "viem";
6
+ //#region src/sdk/accounts/intents/utils/credit-account-slice.d.ts
7
+ /**
8
+ * Narrows full account data down to the slice the intent engine operates on.
9
+ *
10
+ * `accountDebt` is the total repayable debt (principal + accrued interest +
11
+ * accrued fees) rather than the principal, because every debt-touching intent
12
+ * settles the full outstanding amount.
13
+ *
14
+ * Addresses are lowercased so that `eq` comparisons and `AddressMap` lookups
15
+ * behave consistently everywhere downstream.
16
+ */
17
+ declare function toCreditAccountSlice(ca: CreditAccountDataPayload): CreditAccountSlice;
18
+ /**
19
+ * Reads an account by address and narrows it to {@link CreditAccountSlice}.
20
+ *
21
+ * The shared read model's `StrategyPosition` carries neither `tokens` nor
22
+ * `enabledTokensMask` / `creditFacade` / `totalDebtUSD`, so simulating against
23
+ * an existing position costs one account read.
24
+ *
25
+ * @throws When the account is not found in the connected markets.
26
+ */
27
+ declare function fetchCreditAccountSlice(sdk: OnchainSDK, creditAccount: Address): Promise<CreditAccountSlice>;
28
+ //#endregion
29
+ export { fetchCreditAccountSlice, toCreditAccountSlice };
@@ -1,9 +1,11 @@
1
+ import { fetchCreditAccountSlice, toCreditAccountSlice } from "./credit-account-slice.js";
2
+ import { adjustStateToSnapshot } from "./adjust-state-to-snapshot.js";
1
3
  import { assembleOperationCalls } from "./assemble-operation-calls.js";
2
4
  import { calcBorrowedAmountPlusInterestAndFees } from "./borrowed-amount-plus-interest-and-fees.js";
3
5
  import { eq, toRouterCaSlice, toTargetDecimals } from "./common.js";
4
6
  import { convertAmount } from "./convert-amount.js";
5
- import { ConvertFn, simulateOperationAssets } from "./simulate-assets.js";
6
- import { getQuotasForUpdate } from "./quotas-for-update.js";
7
- import { SimulateStateReturn, simulateState } from "./simulate-adjust-state.js";
8
- import { getOperationsWithQuotaUpdate } from "./with-quota-update.js";
9
- export { ConvertFn, SimulateStateReturn, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, convertAmount, eq, getOperationsWithQuotaUpdate, getQuotasForUpdate, simulateOperationAssets, simulateState, toRouterCaSlice, toTargetDecimals };
7
+ import { ConvertFn, LedgerSnapshot, OperationLedger } from "./ledger.js";
8
+ import { CandidateToken, isPhantomToken, isRedemptionPhantomToken, pickFattestNonPhantomToken, rankAccountTokens } from "./pick-token.js";
9
+ import { clearedQuotas, getQuotasForUpdate } from "./quotas-for-update.js";
10
+ import { OpenStrategyLeg, RouterPaths, SwapLeg, createRouterPaths } from "./router-path.js";
11
+ export { CandidateToken, ConvertFn, LedgerSnapshot, OpenStrategyLeg, OperationLedger, RouterPaths, SwapLeg, adjustStateToSnapshot, assembleOperationCalls, calcBorrowedAmountPlusInterestAndFees, clearedQuotas, convertAmount, createRouterPaths, eq, fetchCreditAccountSlice, getQuotasForUpdate, isPhantomToken, isRedemptionPhantomToken, pickFattestNonPhantomToken, rankAccountTokens, toCreditAccountSlice, toRouterCaSlice, toTargetDecimals };
@@ -0,0 +1,41 @@
1
+ import { Asset } from "../../../base/types.js";
2
+ import { AccountCalculatorOperation } from "../operations.js";
3
+ import "../../../index.js";
4
+ import { Address } from "viem";
5
+ //#region src/sdk/accounts/intents/utils/ledger.d.ts
6
+ type ConvertFn = (token: Address, to: Address, amount: bigint) => bigint;
7
+ /** Account state at one point in an operation chain. */
8
+ interface LedgerSnapshot {
9
+ /** Non-zero balances only, lowercased, in insertion order. */
10
+ assets: Asset[];
11
+ /** Sum of `assets` priced in the underlying. */
12
+ totalValue: bigint;
13
+ debt: bigint;
14
+ }
15
+ /**
16
+ * Running account state, advanced one operation at a time.
17
+ *
18
+ * Exists because the amounts an operation is built from depend on the balances
19
+ * the previous ones left behind: a swap has to know how much of its input token
20
+ * is genuinely swap input, so the router does not sweep collateral that must
21
+ * stay put. Applying each op as it is built keeps that a single forward pass —
22
+ * a builder that re-simulated the chain from the start for every leg would be
23
+ * quadratic in the number of legs and easy to desynchronise.
24
+ */
25
+ declare class OperationLedger {
26
+ #private;
27
+ constructor(args: {
28
+ initialAssets: readonly Asset[] | Asset[];
29
+ underlying: Address;
30
+ debt: bigint;
31
+ convert: ConvertFn;
32
+ });
33
+ get debt(): bigint;
34
+ balanceOf(token: Address): bigint;
35
+ applyAll(operations: readonly AccountCalculatorOperation[]): this;
36
+ snapshot(): LedgerSnapshot;
37
+ /** Advances the state by one operation; quota changes move no balance. */
38
+ apply(op: AccountCalculatorOperation): this;
39
+ }
40
+ //#endregion
41
+ export { ConvertFn, LedgerSnapshot, OperationLedger };
@@ -0,0 +1,55 @@
1
+ import { OnchainSDK } from "../../../OnchainSDK.js";
2
+ import { CreditAccountSlice } from "../types.js";
3
+ import "../../../index.js";
4
+ import { Address } from "viem";
5
+ //#region src/sdk/accounts/intents/utils/pick-token.d.ts
6
+ /**
7
+ * Whether `token` is a phantom (a non-transferable position marker such as a
8
+ * pending delayed withdrawal).
9
+ *
10
+ * Reads `contractType` directly instead of going through
11
+ * `TokensMeta.isPhantomToken`, which throws when extended token data has not
12
+ * been loaded. Here an unknown token is simply treated as non-phantom.
13
+ */
14
+ declare function isPhantomToken(sdk: OnchainSDK, token: Address): boolean;
15
+ /**
16
+ * Whether `token` is the phantom of a redemption in flight, rather than one of
17
+ * the phantoms a position is simply held in (Convex, Infrared, staking
18
+ * rewards), which the router sells like any other balance.
19
+ *
20
+ * Only the former stands between an account and being emptied: it cannot be
21
+ * sold and it cannot leave until its claim has landed.
22
+ */
23
+ declare function isRedemptionPhantomToken(sdk: OnchainSDK, token: Address): boolean;
24
+ interface CandidateToken {
25
+ token: Address;
26
+ balance: bigint;
27
+ /** Balance priced in the market underlying, used for the ranking. */
28
+ valueInUnderlying: bigint;
29
+ }
30
+ /**
31
+ * Account balances that can actually back an operation, richest first.
32
+ *
33
+ * Phantoms are dropped because a pending delayed withdrawal cannot be spent:
34
+ * it has to be claimed first, in a transaction of its own.
35
+ */
36
+ declare function rankAccountTokens(args: {
37
+ creditAccount: CreditAccountSlice;
38
+ sdk: OnchainSDK;
39
+ /** Tokens to skip, e.g. the operation's own target. */
40
+ exclude?: Address[];
41
+ }): CandidateToken[];
42
+ /**
43
+ * Default working token for flows that do not get one from the caller: the
44
+ * most valuable non-phantom balance on the account.
45
+ *
46
+ * Used for the source of a partial withdraw and the position leg of a leverage
47
+ * adjustment, both of which the caller may override explicitly.
48
+ */
49
+ declare function pickFattestNonPhantomToken(args: {
50
+ creditAccount: CreditAccountSlice;
51
+ sdk: OnchainSDK;
52
+ exclude?: Address[];
53
+ }): CandidateToken | undefined;
54
+ //#endregion
55
+ export { CandidateToken, isPhantomToken, isRedemptionPhantomToken, pickFattestNonPhantomToken, rankAccountTokens };
@@ -1,9 +1,8 @@
1
1
  import { AddressMap } from "../../../utils/AddressMap.js";
2
2
  import { Asset } from "../../../base/types.js";
3
- import { QuotaUpdateState } from "../operations/quota-update/index.js";
4
- import "../operations/index.js";
3
+ import { QuotaUpdateState } from "../operations.js";
5
4
  import "../../../index.js";
6
- import { ConvertFn } from "./simulate-assets.js";
5
+ import { ConvertFn } from "./ledger.js";
7
6
  import { Address } from "viem";
8
7
  //#region src/sdk/accounts/intents/utils/quotas-for-update.d.ts
9
8
  interface InitialQuota {
@@ -31,5 +30,17 @@ interface GetQuotasForUpdateProps {
31
30
  convert: ConvertFn;
32
31
  }
33
32
  declare function getQuotasForUpdate({ assetsBefore, assetsAfter, initialQuotas, quotaReserve, liquidationThresholds: liquidationThresholdsMap, quotas: quotasMap, maxDebt, underlyingToken, convert }: GetQuotasForUpdateProps): QuotaUpdateState;
33
+ /**
34
+ * The update that leaves the account holding no quota at all.
35
+ *
36
+ * Sits beside {@link getQuotasForUpdate} rather than inside it because the two
37
+ * answer different questions: that one sizes quotas to the balances an
38
+ * operation leaves behind, this one is asked for by a plan that ends the loan,
39
+ * where the right size is none whatever the balances are.
40
+ *
41
+ * `MIN_INT96` is the protocol's "reset" sentinel, which is how a decrease says
42
+ * "all of it" instead of naming an amount that interest may have moved.
43
+ */
44
+ declare function clearedQuotas(initialQuotas: Array<InitialQuota> | readonly InitialQuota[]): QuotaUpdateState;
34
45
  //#endregion
35
- export { getQuotasForUpdate };
46
+ export { clearedQuotas, getQuotasForUpdate };