@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
@@ -0,0 +1,133 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_formatter = require("../../../utils/formatter.js");
3
+ require("../../../index.js");
4
+ const require_market = require("../testing/market.js");
5
+ //#region src/sdk/accounts/intents/tests/open-strategy.fixtures.ts
6
+ /**
7
+ * Open-strategy fixtures.
8
+ *
9
+ * `POS` is the target throughout: it is 1:1 with `UND`, so the mock router's
10
+ * oracle-priced output stays readable while the `ANY` leg (18 decimals, half the
11
+ * price) still exercises the rescaling.
12
+ */
13
+ const LT = 9200n;
14
+ /** Quota bought for a projected balance: value in UND scaled by its LT. */
15
+ function quotaFor(amount, token) {
16
+ return require_market.valueInUnd(amount, token) * LT / 10000n;
17
+ }
18
+ /** 1000 UND of margin. */
19
+ const MARGIN_UND = require_sdk_utils_formatter.toBN("1000", 8);
20
+ /** 500 UND. */
21
+ const HALF_UND = require_sdk_utils_formatter.toBN("500", 8);
22
+ /** 1000 ANY = 500 UND at fixture prices. */
23
+ const COLLATERAL_ANY = require_sdk_utils_formatter.toBN("1000", 18);
24
+ /** ANY balance to keep unswapped: 400 ANY = 200 UND. */
25
+ const KEEP_ANY = require_sdk_utils_formatter.toBN("400", 18);
26
+ const LEVERAGE_1X = 100n;
27
+ const LEVERAGE_2X = 200n;
28
+ const LEVERAGE_3X = 300n;
29
+ /** Plain 3x on underlying margin: everything routes into the position token. */
30
+ const case_underlying_3x = {
31
+ collateral: [{
32
+ token: require_market.UND,
33
+ balance: MARGIN_UND
34
+ }],
35
+ targetToken: require_market.POS,
36
+ leverage: LEVERAGE_3X,
37
+ expectedCollateral: MARGIN_UND,
38
+ expectedDebt: MARGIN_UND * 2n,
39
+ expectedAssets: [{
40
+ token: require_market.POS,
41
+ balance: MARGIN_UND * 3n
42
+ }],
43
+ expectedRouterBalances: [{
44
+ token: require_market.UND,
45
+ balance: MARGIN_UND * 3n
46
+ }]
47
+ };
48
+ /** 1x — no loan at all, just a spot conversion of the margin. */
49
+ const case_underlying_1x = {
50
+ collateral: [{
51
+ token: require_market.UND,
52
+ balance: MARGIN_UND
53
+ }],
54
+ targetToken: require_market.POS,
55
+ leverage: LEVERAGE_1X,
56
+ expectedCollateral: MARGIN_UND,
57
+ expectedDebt: 0n,
58
+ expectedAssets: [{
59
+ token: require_market.POS,
60
+ balance: MARGIN_UND
61
+ }],
62
+ expectedRouterBalances: [{
63
+ token: require_market.UND,
64
+ balance: MARGIN_UND
65
+ }]
66
+ };
67
+ /**
68
+ * Mixed margin with a leftover: 500 UND + 1000 ANY (= 500 UND) at 2x.
69
+ *
70
+ * 400 ANY stays put, so only 600 ANY (= 300 UND) plus the whole 1500 UND is
71
+ * routed, and the kept ANY needs a quota of its own.
72
+ */
73
+ const case_mixed_with_leftover = {
74
+ collateral: [{
75
+ token: require_market.UND,
76
+ balance: HALF_UND
77
+ }, {
78
+ token: require_market.ANY,
79
+ balance: COLLATERAL_ANY
80
+ }],
81
+ targetToken: require_market.POS,
82
+ leverage: LEVERAGE_2X,
83
+ leftoverBalances: [{
84
+ token: require_market.ANY,
85
+ balance: KEEP_ANY
86
+ }],
87
+ expectedCollateral: MARGIN_UND,
88
+ expectedDebt: MARGIN_UND,
89
+ expectedAssets: [{
90
+ token: require_market.ANY,
91
+ balance: KEEP_ANY
92
+ }, {
93
+ token: require_market.POS,
94
+ balance: HALF_UND + MARGIN_UND + require_market.valueInUnd(COLLATERAL_ANY - KEEP_ANY, require_market.ANY)
95
+ }],
96
+ expectedRouterBalances: [{
97
+ token: require_market.UND,
98
+ balance: HALF_UND + MARGIN_UND
99
+ }, {
100
+ token: require_market.ANY,
101
+ balance: COLLATERAL_ANY
102
+ }]
103
+ };
104
+ function buildOpenStrategySdk(extras) {
105
+ return require_market.buildMarketSdk(extras);
106
+ }
107
+ function buildOpenStrategyProps(c, sdk) {
108
+ return {
109
+ sdk,
110
+ creditManager: require_market.CREDIT_MANAGER,
111
+ collateral: c.collateral,
112
+ targetToken: c.targetToken,
113
+ leverage: c.leverage,
114
+ leftoverBalances: c.leftoverBalances,
115
+ slippage: void 0,
116
+ quotaReserve: void 0
117
+ };
118
+ }
119
+ //#endregion
120
+ exports.COLLATERAL_ANY = COLLATERAL_ANY;
121
+ exports.HALF_UND = HALF_UND;
122
+ exports.KEEP_ANY = KEEP_ANY;
123
+ exports.LEVERAGE_1X = LEVERAGE_1X;
124
+ exports.LEVERAGE_2X = LEVERAGE_2X;
125
+ exports.LEVERAGE_3X = LEVERAGE_3X;
126
+ exports.LT = LT;
127
+ exports.MARGIN_UND = MARGIN_UND;
128
+ exports.buildOpenStrategyProps = buildOpenStrategyProps;
129
+ exports.buildOpenStrategySdk = buildOpenStrategySdk;
130
+ exports.case_mixed_with_leftover = case_mixed_with_leftover;
131
+ exports.case_underlying_1x = case_underlying_1x;
132
+ exports.case_underlying_3x = case_underlying_3x;
133
+ exports.quotaFor = quotaFor;
@@ -0,0 +1,131 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_market = require("../testing/market.js");
3
+ //#region src/sdk/accounts/intents/tests/withdraw-asset.fixtures.ts
4
+ /**
5
+ * Start withdraw-asset fixtures (intent 4), covering the cases from the spec's
6
+ * "withdraw collateral intent" section.
7
+ *
8
+ * Debt never moves, so every case is `withdrawCollateral` plus the quota
9
+ * decrease implied by the smaller balance. The one branch is the RWA market
10
+ * forced unwrap when the withdrawn token is the wrapped underlying.
11
+ */
12
+ const LT_ANY = 9200n;
13
+ /** 2000 ANY = 1000 UND at fixture prices. */
14
+ const HELD_ANY = 2000000000000000000000n;
15
+ /** 1000 UND. */
16
+ const HELD_UND = 100000000000n;
17
+ const DEBT = 50000000000n;
18
+ /** Half the ANY position. */
19
+ const OUT_ANY = 1000000000000000000000n;
20
+ /**
21
+ * 300 of the 1000 UND held. Not half: the underlying is weighted at 98% in this
22
+ * fixture, so leaving 500 against 500 of debt would end below water and the
23
+ * facade would refuse the withdrawal.
24
+ */
25
+ const OUT_UND = 30000000000n;
26
+ const QUOTA_ANY_BEFORE = require_market.valueInUnd(HELD_ANY, require_market.ANY) * LT_ANY / 10000n;
27
+ const QUOTA_ANY_AFTER = require_market.valueInUnd(HELD_ANY - OUT_ANY, require_market.ANY) * LT_ANY / 10000n;
28
+ /** Quota ops carry signed deltas, so a release is negative. */
29
+ const QUOTA_ANY_DELTA = QUOTA_ANY_AFTER - QUOTA_ANY_BEFORE;
30
+ /** Quota token out: withdraw, then release the freed quota. */
31
+ const case_any_token = {
32
+ intent: {
33
+ type: "WITHDRAW_ASSET",
34
+ token: require_market.ANY,
35
+ amount: OUT_ANY,
36
+ to: require_market.WALLET
37
+ },
38
+ tokens: [require_market.caToken(require_market.UND, HELD_UND), require_market.caToken(require_market.ANY, HELD_ANY, QUOTA_ANY_BEFORE)],
39
+ accountDebt: DEBT,
40
+ totalValue: HELD_UND + require_market.valueInUnd(HELD_ANY - OUT_ANY, require_market.ANY),
41
+ ops: [{
42
+ type: "withdrawCollateral",
43
+ token: require_market.ANY,
44
+ amount: OUT_ANY,
45
+ to: require_market.WALLET
46
+ }, {
47
+ type: "changeQuota",
48
+ quotaIncrease: [],
49
+ quotaDecrease: [{
50
+ token: require_market.ANY,
51
+ balance: QUOTA_ANY_DELTA
52
+ }],
53
+ desiredQuota: {}
54
+ }]
55
+ };
56
+ /** Underlying out on a plain market: no quota, no unwrap. */
57
+ const case_underlying = {
58
+ intent: {
59
+ type: "WITHDRAW_ASSET",
60
+ token: require_market.UND,
61
+ amount: OUT_UND,
62
+ to: require_market.WALLET
63
+ },
64
+ tokens: [require_market.caToken(require_market.UND, HELD_UND)],
65
+ accountDebt: DEBT,
66
+ totalValue: HELD_UND - OUT_UND,
67
+ ops: [{
68
+ type: "withdrawCollateral",
69
+ token: require_market.UND,
70
+ amount: OUT_UND,
71
+ to: require_market.WALLET
72
+ }]
73
+ };
74
+ /**
75
+ * Underlying out on an RWA market: the wrapper cannot leave the account, so it
76
+ * is force-unwrapped and the rwa asset is withdrawn instead.
77
+ */
78
+ const case_rwa_underlying = {
79
+ intent: {
80
+ type: "WITHDRAW_ASSET",
81
+ token: require_market.UND,
82
+ amount: OUT_UND,
83
+ to: require_market.WALLET
84
+ },
85
+ tokens: [require_market.caToken(require_market.UND, HELD_UND)],
86
+ accountDebt: DEBT,
87
+ totalValue: HELD_UND - OUT_UND,
88
+ ops: [{
89
+ type: "unwrapRwaCollateral",
90
+ tokenIn: require_market.UND,
91
+ amount: OUT_UND,
92
+ tokenOut: require_market.RWA_ASSET,
93
+ amountOut: OUT_UND
94
+ }, {
95
+ type: "withdrawCollateral",
96
+ token: require_market.RWA_ASSET,
97
+ amount: OUT_UND,
98
+ to: require_market.WALLET
99
+ }],
100
+ rwaAssets: { [require_market.UND]: require_market.RWA_ASSET }
101
+ };
102
+ function buildWithdrawAssetSdk(c) {
103
+ return require_market.buildMarketSdk({ rwaAssets: c.rwaAssets });
104
+ }
105
+ function buildWithdrawAssetProps(c, sdk) {
106
+ return {
107
+ intent: c.intent,
108
+ creditAccount: require_market.buildFixtureCreditAccount({
109
+ accountDebt: c.accountDebt,
110
+ tokens: c.tokens
111
+ }),
112
+ sdk,
113
+ quotaReserve: void 0,
114
+ slippage: void 0
115
+ };
116
+ }
117
+ //#endregion
118
+ exports.DEBT = DEBT;
119
+ exports.HELD_ANY = HELD_ANY;
120
+ exports.HELD_UND = HELD_UND;
121
+ exports.LT_ANY = LT_ANY;
122
+ exports.OUT_ANY = OUT_ANY;
123
+ exports.OUT_UND = OUT_UND;
124
+ exports.QUOTA_ANY_AFTER = QUOTA_ANY_AFTER;
125
+ exports.QUOTA_ANY_BEFORE = QUOTA_ANY_BEFORE;
126
+ exports.QUOTA_ANY_DELTA = QUOTA_ANY_DELTA;
127
+ exports.buildWithdrawAssetProps = buildWithdrawAssetProps;
128
+ exports.buildWithdrawAssetSdk = buildWithdrawAssetSdk;
129
+ exports.case_any_token = case_any_token;
130
+ exports.case_rwa_underlying = case_rwa_underlying;
131
+ exports.case_underlying = case_underlying;
@@ -0,0 +1,426 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_market = require("../testing/market.js");
3
+ //#region src/sdk/accounts/intents/tests/withdraw.fixtures.ts
4
+ /**
5
+ * Start withdraw fixtures (intent 2.1) — one per row of the S/T matrix.
6
+ *
7
+ * Every case starts from 2000 UND of TVL against 1000 UND of debt: 1000 UND of
8
+ * collateral at 2x. Withdrawing 100 UND of value therefore repays 100 of debt
9
+ * (`dD = D0 * W / C0`), so 200 UND of value must be liquidated in total and the
10
+ * account settles at 1800 TVL / 900 debt — still 2x.
11
+ *
12
+ * `POS` and `POS2` both convert 1:1 with `UND`, keeping swap amounts honest
13
+ * against the mock router, which echoes its input amount.
14
+ */
15
+ const LT = 9200n;
16
+ const quotaOf = (balance) => balance * LT / 10000n;
17
+ /** 100 UND of value leaving the account. */
18
+ const W = 10000000000n;
19
+ /** Payout plus proportional repayment. */
20
+ const SPEND = 2n * W;
21
+ const TVL_BEFORE = 200000000000n;
22
+ const DEBT_BEFORE = 100000000000n;
23
+ const TVL_AFTER = TVL_BEFORE - SPEND;
24
+ const DEBT_AFTER = DEBT_BEFORE - W;
25
+ const QUOTA_BEFORE = quotaOf(TVL_BEFORE);
26
+ const QUOTA_AFTER = quotaOf(TVL_AFTER);
27
+ /** Quota ops carry signed deltas. */
28
+ const QUOTA_DELTA = QUOTA_AFTER - QUOTA_BEFORE;
29
+ const base = {
30
+ accountDebt: DEBT_BEFORE,
31
+ totalValue: TVL_AFTER,
32
+ accountDebtAfter: DEBT_AFTER
33
+ };
34
+ /** Row 1 — S = U, T = U: repay, then hand over the underlying. */
35
+ const case_und_und = {
36
+ ...base,
37
+ intent: {
38
+ type: "WITHDRAW",
39
+ amount: W,
40
+ to: require_market.WALLET
41
+ },
42
+ tokens: [require_market.caToken(require_market.UND, TVL_BEFORE)],
43
+ ops: [{
44
+ type: "decreaseDebt",
45
+ amount: W
46
+ }, {
47
+ type: "withdrawCollateral",
48
+ token: require_market.UND,
49
+ amount: W,
50
+ to: require_market.WALLET
51
+ }]
52
+ };
53
+ /** Row 2 — S = U, T = POS: repay, then route the payout out of the underlying. */
54
+ const case_und_pos = {
55
+ ...base,
56
+ intent: {
57
+ type: "WITHDRAW",
58
+ amount: W,
59
+ to: require_market.WALLET,
60
+ tokenOut: require_market.POS
61
+ },
62
+ tokens: [require_market.caToken(require_market.UND, TVL_BEFORE)],
63
+ ops: [
64
+ {
65
+ type: "decreaseDebt",
66
+ amount: W
67
+ },
68
+ {
69
+ type: "swap",
70
+ from: [{
71
+ token: require_market.UND,
72
+ balance: W
73
+ }],
74
+ tokenOut: require_market.POS,
75
+ amountOut: W
76
+ },
77
+ {
78
+ type: "withdrawCollateral",
79
+ token: require_market.POS,
80
+ amount: W,
81
+ to: require_market.WALLET
82
+ }
83
+ ]
84
+ };
85
+ /** Row 3 — S = POS, T = U: both legs land in the underlying, so one swap covers them. */
86
+ const case_pos_und = {
87
+ ...base,
88
+ intent: {
89
+ type: "WITHDRAW",
90
+ amount: W,
91
+ to: require_market.WALLET,
92
+ sourceToken: require_market.POS
93
+ },
94
+ tokens: [require_market.caToken(require_market.POS, TVL_BEFORE, QUOTA_BEFORE)],
95
+ ops: [
96
+ {
97
+ type: "swap",
98
+ from: [{
99
+ token: require_market.POS,
100
+ balance: SPEND
101
+ }],
102
+ tokenOut: require_market.UND,
103
+ amountOut: SPEND
104
+ },
105
+ {
106
+ type: "decreaseDebt",
107
+ amount: W
108
+ },
109
+ {
110
+ type: "withdrawCollateral",
111
+ token: require_market.UND,
112
+ amount: W,
113
+ to: require_market.WALLET
114
+ },
115
+ {
116
+ type: "changeQuota",
117
+ quotaIncrease: [],
118
+ quotaDecrease: [{
119
+ token: require_market.POS,
120
+ balance: QUOTA_DELTA
121
+ }],
122
+ desiredQuota: {}
123
+ }
124
+ ]
125
+ };
126
+ /** Row 4 — S = T = POS: only the repayment needs routing. */
127
+ const case_pos_pos = {
128
+ ...base,
129
+ intent: {
130
+ type: "WITHDRAW",
131
+ amount: W,
132
+ to: require_market.WALLET,
133
+ sourceToken: require_market.POS,
134
+ tokenOut: require_market.POS
135
+ },
136
+ tokens: [require_market.caToken(require_market.POS, TVL_BEFORE, QUOTA_BEFORE)],
137
+ ops: [
138
+ {
139
+ type: "swap",
140
+ from: [{
141
+ token: require_market.POS,
142
+ balance: W
143
+ }],
144
+ tokenOut: require_market.UND,
145
+ amountOut: W
146
+ },
147
+ {
148
+ type: "decreaseDebt",
149
+ amount: W
150
+ },
151
+ {
152
+ type: "withdrawCollateral",
153
+ token: require_market.POS,
154
+ amount: W,
155
+ to: require_market.WALLET
156
+ },
157
+ {
158
+ type: "changeQuota",
159
+ quotaIncrease: [],
160
+ quotaDecrease: [{
161
+ token: require_market.POS,
162
+ balance: QUOTA_DELTA
163
+ }],
164
+ desiredQuota: {}
165
+ }
166
+ ]
167
+ };
168
+ /** Row 5 — S = POS, T = POS2: two independent legs out of the same source. */
169
+ const case_pos_pos2 = {
170
+ ...base,
171
+ intent: {
172
+ type: "WITHDRAW",
173
+ amount: W,
174
+ to: require_market.WALLET,
175
+ sourceToken: require_market.POS,
176
+ tokenOut: require_market.POS2
177
+ },
178
+ tokens: [require_market.caToken(require_market.POS, TVL_BEFORE, QUOTA_BEFORE)],
179
+ ops: [
180
+ {
181
+ type: "swap",
182
+ from: [{
183
+ token: require_market.POS,
184
+ balance: W
185
+ }],
186
+ tokenOut: require_market.UND,
187
+ amountOut: W
188
+ },
189
+ {
190
+ type: "decreaseDebt",
191
+ amount: W
192
+ },
193
+ {
194
+ type: "swap",
195
+ from: [{
196
+ token: require_market.POS,
197
+ balance: W
198
+ }],
199
+ tokenOut: require_market.POS2,
200
+ amountOut: W
201
+ },
202
+ {
203
+ type: "withdrawCollateral",
204
+ token: require_market.POS2,
205
+ amount: W,
206
+ to: require_market.WALLET
207
+ },
208
+ {
209
+ type: "changeQuota",
210
+ quotaIncrease: [],
211
+ quotaDecrease: [{
212
+ token: require_market.POS,
213
+ balance: QUOTA_DELTA
214
+ }],
215
+ desiredQuota: {}
216
+ }
217
+ ]
218
+ };
219
+ /** RWA market: the underlying payout is force-unwrapped to the asset. */
220
+ const case_rwa_payout = {
221
+ ...base,
222
+ intent: {
223
+ type: "WITHDRAW",
224
+ amount: W,
225
+ to: require_market.WALLET,
226
+ sourceToken: require_market.POS
227
+ },
228
+ tokens: [require_market.caToken(require_market.POS, TVL_BEFORE, QUOTA_BEFORE)],
229
+ ops: [
230
+ {
231
+ type: "swap",
232
+ from: [{
233
+ token: require_market.POS,
234
+ balance: SPEND
235
+ }],
236
+ tokenOut: require_market.UND,
237
+ amountOut: SPEND
238
+ },
239
+ {
240
+ type: "decreaseDebt",
241
+ amount: W
242
+ },
243
+ {
244
+ type: "unwrapRwaCollateral",
245
+ tokenIn: require_market.UND,
246
+ amount: W,
247
+ tokenOut: require_market.RWA_ASSET,
248
+ amountOut: W
249
+ },
250
+ {
251
+ type: "withdrawCollateral",
252
+ token: require_market.RWA_ASSET,
253
+ amount: W,
254
+ to: require_market.WALLET
255
+ },
256
+ {
257
+ type: "changeQuota",
258
+ quotaIncrease: [],
259
+ quotaDecrease: [{
260
+ token: require_market.POS,
261
+ balance: QUOTA_DELTA
262
+ }],
263
+ desiredQuota: {}
264
+ }
265
+ ],
266
+ rwaAssets: { [require_market.UND]: require_market.RWA_ASSET }
267
+ };
268
+ /** Matrix baseline: 10A of position against 8U of debt (2U collateral at 5x). */
269
+ const M4_BALANCE = 1000000000n;
270
+ const M4_DEBT = 800000000n;
271
+ /** Matrix payout W: 1U. */
272
+ const M4_W = 100000000n;
273
+ /** Proportional repayment `dD = D0 * W / C0` = 4U. */
274
+ const M4_DD = 400000000n;
275
+ /** Payout plus repayment: 5U liquidated in total. */
276
+ const M4_SPEND = 500000000n;
277
+ /**
278
+ * Matrix 4.1 — withdraw 1U, source `POS`, payout `UND`.
279
+ *
280
+ * MATRIX MISMATCH: the matrix pays out first — `swap → withdrawCollateral →
281
+ * decreaseDebt → changeQuota`. The engine repays before paying out
282
+ * (`repay(dD, keep: W)` precedes the payout leg in `planWithdraw`):
283
+ * `swap → decreaseDebt → withdrawCollateral → changeQuota`. Amounts are
284
+ * identical; only the order differs.
285
+ */
286
+ const case_matrix_4_1 = {
287
+ intent: {
288
+ type: "WITHDRAW",
289
+ amount: M4_W,
290
+ to: require_market.WALLET,
291
+ sourceToken: require_market.POS
292
+ },
293
+ tokens: [require_market.caToken(require_market.POS, M4_BALANCE, quotaOf(M4_BALANCE))],
294
+ accountDebt: M4_DEBT,
295
+ totalValue: M4_SPEND,
296
+ accountDebtAfter: M4_DD,
297
+ ops: [
298
+ {
299
+ type: "swap",
300
+ from: [{
301
+ token: require_market.POS,
302
+ balance: M4_SPEND
303
+ }],
304
+ tokenOut: require_market.UND,
305
+ amountOut: M4_SPEND
306
+ },
307
+ {
308
+ type: "decreaseDebt",
309
+ amount: M4_DD
310
+ },
311
+ {
312
+ type: "withdrawCollateral",
313
+ token: require_market.UND,
314
+ amount: M4_W,
315
+ to: require_market.WALLET
316
+ },
317
+ {
318
+ type: "changeQuota",
319
+ quotaIncrease: [],
320
+ quotaDecrease: [{
321
+ token: require_market.POS,
322
+ balance: quotaOf(M4_SPEND) - quotaOf(M4_BALANCE)
323
+ }],
324
+ desiredQuota: {}
325
+ }
326
+ ]
327
+ };
328
+ /**
329
+ * Matrix 4.2 — 4.1 on the RWA market: the payout is unwrapped on the way out.
330
+ *
331
+ * MATRIX MISMATCH: same ordering divergence as 4.1 — the matrix expects
332
+ * `swap → unwrapRwaCollateral → withdrawCollateral(RWA) → decreaseDebt →
333
+ * changeQuota`, the engine repays first:
334
+ * `swap → decreaseDebt → unwrapRwaCollateral → withdrawCollateral(RWA) →
335
+ * changeQuota`.
336
+ */
337
+ const case_matrix_4_2 = {
338
+ intent: {
339
+ type: "WITHDRAW",
340
+ amount: M4_W,
341
+ to: require_market.WALLET,
342
+ sourceToken: require_market.POS
343
+ },
344
+ tokens: [require_market.caToken(require_market.POS, M4_BALANCE, quotaOf(M4_BALANCE))],
345
+ accountDebt: M4_DEBT,
346
+ totalValue: M4_SPEND,
347
+ accountDebtAfter: M4_DD,
348
+ ops: [
349
+ {
350
+ type: "swap",
351
+ from: [{
352
+ token: require_market.POS,
353
+ balance: M4_SPEND
354
+ }],
355
+ tokenOut: require_market.UND,
356
+ amountOut: M4_SPEND
357
+ },
358
+ {
359
+ type: "decreaseDebt",
360
+ amount: M4_DD
361
+ },
362
+ {
363
+ type: "unwrapRwaCollateral",
364
+ tokenIn: require_market.UND,
365
+ amount: M4_W,
366
+ tokenOut: require_market.RWA_ASSET,
367
+ amountOut: M4_W
368
+ },
369
+ {
370
+ type: "withdrawCollateral",
371
+ token: require_market.RWA_ASSET,
372
+ amount: M4_W,
373
+ to: require_market.WALLET
374
+ },
375
+ {
376
+ type: "changeQuota",
377
+ quotaIncrease: [],
378
+ quotaDecrease: [{
379
+ token: require_market.POS,
380
+ balance: quotaOf(M4_SPEND) - quotaOf(M4_BALANCE)
381
+ }],
382
+ desiredQuota: {}
383
+ }
384
+ ],
385
+ rwaAssets: { [require_market.UND]: require_market.RWA_ASSET }
386
+ };
387
+ function buildWithdrawSdk(c) {
388
+ return require_market.buildMarketSdk({ rwaAssets: c.rwaAssets });
389
+ }
390
+ function buildWithdrawProps(c, sdk) {
391
+ return {
392
+ intent: c.intent,
393
+ creditAccount: require_market.buildFixtureCreditAccount({
394
+ accountDebt: c.accountDebt,
395
+ tokens: c.tokens
396
+ }),
397
+ sdk,
398
+ quotaReserve: void 0,
399
+ slippage: void 0
400
+ };
401
+ }
402
+ //#endregion
403
+ exports.DEBT_AFTER = DEBT_AFTER;
404
+ exports.DEBT_BEFORE = DEBT_BEFORE;
405
+ exports.M4_BALANCE = M4_BALANCE;
406
+ exports.M4_DD = M4_DD;
407
+ exports.M4_DEBT = M4_DEBT;
408
+ exports.M4_SPEND = M4_SPEND;
409
+ exports.M4_W = M4_W;
410
+ exports.QUOTA_AFTER = QUOTA_AFTER;
411
+ exports.QUOTA_BEFORE = QUOTA_BEFORE;
412
+ exports.QUOTA_DELTA = QUOTA_DELTA;
413
+ exports.SPEND = SPEND;
414
+ exports.TVL_AFTER = TVL_AFTER;
415
+ exports.TVL_BEFORE = TVL_BEFORE;
416
+ exports.W = W;
417
+ exports.buildWithdrawProps = buildWithdrawProps;
418
+ exports.buildWithdrawSdk = buildWithdrawSdk;
419
+ exports.case_matrix_4_1 = case_matrix_4_1;
420
+ exports.case_matrix_4_2 = case_matrix_4_2;
421
+ exports.case_pos_pos = case_pos_pos;
422
+ exports.case_pos_pos2 = case_pos_pos2;
423
+ exports.case_pos_und = case_pos_und;
424
+ exports.case_rwa_payout = case_rwa_payout;
425
+ exports.case_und_pos = case_und_pos;
426
+ exports.case_und_und = case_und_und;
@@ -1 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/sdk/accounts/intents/types.ts
3
+ /**
4
+ * Validation failure that maps onto {@link PreviewErrorReason} rather than
5
+ * crashing the caller: thrown by builders, converted to `{ ok: false }` by
6
+ * `CreditAccountOperationsService.startIntent`.
7
+ */
8
+ var IntentPreviewError = class extends Error {
9
+ reason;
10
+ constructor(reason, message) {
11
+ super(message ?? reason);
12
+ this.name = "IntentPreviewError";
13
+ this.reason = reason;
14
+ }
15
+ };
16
+ //#endregion
17
+ exports.IntentPreviewError = IntentPreviewError;