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

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 (436) 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 +137 -0
  9. package/dist/cjs/dev/comparePositions.js +183 -0
  10. package/dist/cjs/dev/fieldDiff.js +241 -0
  11. package/dist/cjs/model/charts.js +147 -0
  12. package/dist/cjs/model/charts.schema.js +240 -0
  13. package/dist/cjs/model/index.js +35 -22
  14. package/dist/cjs/model/liquidations.schema.js +1 -1
  15. package/dist/cjs/model/notices.schema.js +25 -0
  16. package/dist/cjs/model/opportunities.schema.js +1 -1
  17. package/dist/cjs/model/positions.schema.js +48 -2
  18. package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
  19. package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
  20. package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
  21. package/dist/cjs/new-sdk/execute/index.js +3 -0
  22. package/dist/cjs/new-sdk/index.js +7 -0
  23. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  24. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
  25. package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
  26. package/dist/cjs/new-sdk/simulate/index.js +4 -0
  27. package/dist/cjs/new-sdk/utils/index.js +0 -1
  28. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  29. package/dist/cjs/offchain/GearboxAPI.js +7 -0
  30. package/dist/cjs/offchain/index.js +3 -0
  31. package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
  32. package/dist/cjs/offchain/notices/index.js +3 -0
  33. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  34. package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
  35. package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
  36. package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
  37. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
  38. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
  39. package/dist/cjs/preview/preview/previewOperation.js +1 -1
  40. package/dist/cjs/sdk/MultichainSDK.js +3 -4
  41. package/dist/cjs/sdk/OnchainSDK.js +42 -13
  42. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
  43. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  44. package/dist/cjs/sdk/accounts/index.js +5 -2
  45. package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
  46. package/dist/cjs/sdk/accounts/intents/index.js +216 -358
  47. package/dist/cjs/sdk/accounts/intents/math.js +56 -0
  48. package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
  49. package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
  50. package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
  51. package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
  52. package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
  53. package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
  54. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
  55. package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
  56. package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
  57. package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
  58. package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
  59. package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
  60. package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
  61. package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
  62. package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
  63. package/dist/cjs/sdk/accounts/intents/types.js +16 -0
  64. package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
  65. package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
  66. package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
  67. package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
  68. package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
  69. package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
  70. package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
  71. package/dist/cjs/sdk/accounts/intents/view.js +38 -0
  72. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
  73. package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  74. package/dist/cjs/sdk/base/BaseContract.js +1 -1
  75. package/dist/cjs/sdk/base/TokensMeta.js +78 -27
  76. package/dist/cjs/sdk/index.js +30 -7
  77. package/dist/cjs/sdk/market/MarketRegister.js +16 -7
  78. package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
  79. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
  80. package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
  81. package/dist/cjs/sdk/market/credit/index.js +3 -0
  82. package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
  83. package/dist/cjs/sdk/market/index.js +17 -0
  84. package/dist/cjs/sdk/market/math.js +65 -45
  85. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  86. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
  87. package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
  88. package/dist/cjs/sdk/opportunities/index.js +0 -13
  89. package/dist/cjs/sdk/options.js +1 -5
  90. package/dist/cjs/sdk/pools/PoolService.js +133 -4
  91. package/dist/cjs/sdk/pools/index.js +2 -0
  92. package/dist/cjs/sdk/positions/PositionsService.js +218 -1
  93. package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
  94. package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
  95. package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
  96. package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
  97. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
  98. package/dist/cjs/sdk/positions/index.js +12 -1
  99. package/dist/cjs/sdk/positions/types.js +31 -0
  100. package/dist/cjs/sdk/utils/abi-decode.js +2 -2
  101. package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
  102. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  103. package/dist/esm/abi/iExpirable.js +14 -0
  104. package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  105. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  106. package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  107. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
  108. package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  109. package/dist/esm/dev/AccountOpener.js +0 -1
  110. package/dist/esm/dev/compareOpportunities.js +135 -0
  111. package/dist/esm/dev/comparePositions.js +181 -0
  112. package/dist/esm/dev/fieldDiff.js +224 -0
  113. package/dist/esm/model/charts.js +140 -0
  114. package/dist/esm/model/charts.schema.js +226 -0
  115. package/dist/esm/model/index.js +9 -7
  116. package/dist/esm/model/liquidations.schema.js +1 -1
  117. package/dist/esm/model/notices.schema.js +23 -0
  118. package/dist/esm/model/opportunities.schema.js +1 -1
  119. package/dist/esm/model/positions.schema.js +46 -4
  120. package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
  121. package/dist/esm/new-sdk/GearboxSDK.js +72 -4
  122. package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
  123. package/dist/esm/new-sdk/execute/index.js +2 -0
  124. package/dist/esm/new-sdk/index.js +6 -2
  125. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  126. package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
  127. package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
  128. package/dist/esm/new-sdk/simulate/index.js +3 -0
  129. package/dist/esm/new-sdk/utils/index.js +0 -1
  130. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  131. package/dist/esm/offchain/GearboxAPI.js +7 -0
  132. package/dist/esm/offchain/index.js +3 -1
  133. package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
  134. package/dist/esm/offchain/notices/index.js +2 -0
  135. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  136. package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
  137. package/dist/esm/preview/preview/CreditAccountState.js +14 -1
  138. package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
  139. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
  140. package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
  141. package/dist/esm/preview/preview/previewOperation.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 +2 -8
  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 +0 -3
  175. package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  176. package/dist/esm/sdk/base/BaseContract.js +1 -1
  177. package/dist/esm/sdk/base/TokensMeta.js +78 -27
  178. package/dist/esm/sdk/index.js +13 -4
  179. package/dist/esm/sdk/market/MarketRegister.js +16 -7
  180. package/dist/esm/sdk/market/ZapperRegister.js +56 -25
  181. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
  182. package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
  183. package/dist/esm/sdk/market/credit/index.js +2 -1
  184. package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
  185. package/dist/esm/sdk/market/index.js +3 -1
  186. package/dist/esm/sdk/market/math.js +60 -41
  187. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  188. package/dist/esm/sdk/market/pool/PoolV310Contract.js +16 -2
  189. package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
  190. package/dist/esm/sdk/opportunities/index.js +1 -2
  191. package/dist/esm/sdk/options.js +1 -5
  192. package/dist/esm/sdk/pools/PoolService.js +133 -6
  193. package/dist/esm/sdk/pools/index.js +2 -2
  194. package/dist/esm/sdk/positions/PositionsService.js +218 -1
  195. package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
  196. package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
  197. package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
  198. package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
  199. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
  200. package/dist/esm/sdk/positions/index.js +7 -2
  201. package/dist/esm/sdk/positions/types.js +31 -1
  202. package/dist/esm/sdk/utils/abi-decode.js +2 -2
  203. package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
  204. package/dist/esm/sdk/utils/viem/index.js +2 -1
  205. package/dist/types/abi/iExpirable.d.ts +14 -0
  206. package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
  207. package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
  208. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
  209. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
  210. package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
  211. package/dist/types/dev/compareOpportunities.d.ts +105 -0
  212. package/dist/types/dev/comparePositions.d.ts +149 -0
  213. package/dist/types/dev/fieldDiff.d.ts +167 -0
  214. package/dist/types/model/charts.d.ts +349 -0
  215. package/dist/types/model/charts.schema.d.ts +364 -0
  216. package/dist/types/model/index.d.ts +8 -6
  217. package/dist/types/model/notices.d.ts +29 -0
  218. package/dist/types/model/notices.schema.d.ts +23 -0
  219. package/dist/types/model/opportunities.d.ts +9 -9
  220. package/dist/types/model/positions.d.ts +133 -7
  221. package/dist/types/model/positions.schema.d.ts +128 -1
  222. package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
  223. package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
  224. package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
  225. package/dist/types/new-sdk/execute/index.d.ts +2 -0
  226. package/dist/types/new-sdk/index.d.ts +8 -4
  227. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
  228. package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
  229. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  230. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  231. package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
  232. package/dist/types/new-sdk/simulate/index.d.ts +3 -0
  233. package/dist/types/new-sdk/simulate/types.d.ts +508 -0
  234. package/dist/types/new-sdk/types.d.ts +35 -1
  235. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  236. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  237. package/dist/types/offchain/GearboxAPI.d.ts +6 -0
  238. package/dist/types/offchain/index.d.ts +4 -2
  239. package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
  240. package/dist/types/offchain/notices/index.d.ts +2 -0
  241. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  242. package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
  243. package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
  244. package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
  245. package/dist/types/preview/preview/types.d.ts +4 -2
  246. package/dist/types/sdk/MultichainSDK.d.ts +0 -5
  247. package/dist/types/sdk/OnchainSDK.d.ts +1 -5
  248. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
  249. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
  250. package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
  251. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
  252. package/dist/types/sdk/accounts/index.d.ts +7 -5
  253. package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
  254. package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
  255. package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
  256. package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
  257. package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
  258. package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
  259. package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
  260. package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
  261. package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
  262. package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
  263. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
  264. package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
  265. package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
  266. package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
  267. package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
  268. package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
  269. package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
  270. package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
  271. package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
  272. package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
  273. package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
  274. package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
  275. package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
  276. package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
  277. package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
  278. package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
  279. package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
  280. package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
  281. package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
  282. package/dist/types/sdk/accounts/types.d.ts +17 -14
  283. package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
  284. package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
  285. package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
  286. package/dist/types/sdk/base/index.d.ts +2 -2
  287. package/dist/types/sdk/base/token-types.d.ts +12 -1
  288. package/dist/types/sdk/index.d.ts +28 -19
  289. package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
  290. package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
  291. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
  292. package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
  293. package/dist/types/sdk/market/credit/index.d.ts +2 -1
  294. package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
  295. package/dist/types/sdk/market/credit/types.d.ts +2 -9
  296. package/dist/types/sdk/market/index.d.ts +4 -2
  297. package/dist/types/sdk/market/math.d.ts +46 -34
  298. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
  299. package/dist/types/sdk/market/oracle/types.d.ts +10 -2
  300. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
  301. package/dist/types/sdk/market/pool/types.d.ts +5 -0
  302. package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
  303. package/dist/types/sdk/market/types.d.ts +5 -1
  304. package/dist/types/sdk/opportunities/index.d.ts +1 -2
  305. package/dist/types/sdk/options.d.ts +0 -1
  306. package/dist/types/sdk/pools/PoolService.d.ts +32 -2
  307. package/dist/types/sdk/pools/index.d.ts +3 -3
  308. package/dist/types/sdk/pools/types.d.ts +109 -4
  309. package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
  310. package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
  311. package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
  312. package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
  313. package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
  314. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
  315. package/dist/types/sdk/positions/index.d.ts +7 -2
  316. package/dist/types/sdk/positions/types.d.ts +58 -1
  317. package/dist/types/sdk/types/state.d.ts +6 -0
  318. package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
  319. package/dist/types/sdk/utils/viem/index.d.ts +3 -2
  320. package/package.json +2 -1
  321. package/dist/cjs/model/history.js +0 -53
  322. package/dist/cjs/model/history.schema.js +0 -128
  323. package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
  324. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
  325. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
  326. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
  327. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
  328. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
  329. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
  330. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
  331. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
  332. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
  333. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
  334. package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
  335. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
  336. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
  337. package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
  338. package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
  339. package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
  340. package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
  341. package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
  342. package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
  343. package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
  344. package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
  345. package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
  346. package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
  347. package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
  348. package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
  349. package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
  350. package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
  351. package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
  352. package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
  353. package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
  354. package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
  355. package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
  356. package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
  357. package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
  358. package/dist/esm/model/history.js +0 -49
  359. package/dist/esm/model/history.schema.js +0 -116
  360. package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
  361. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
  362. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
  363. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
  364. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
  365. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
  366. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
  367. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
  368. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
  369. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
  370. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
  371. package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
  372. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
  373. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
  374. package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
  375. package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
  376. package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
  377. package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
  378. package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
  379. package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
  380. package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
  381. package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
  382. package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
  383. package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
  384. package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
  385. package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
  386. package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
  387. package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
  388. package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
  389. package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
  390. package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
  391. package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
  392. package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
  393. package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
  394. package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
  395. package/dist/types/model/history.d.ts +0 -153
  396. package/dist/types/model/history.schema.d.ts +0 -95
  397. package/dist/types/new-sdk/utils/history.d.ts +0 -18
  398. package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
  399. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
  400. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
  401. package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
  402. package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
  403. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
  404. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
  405. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
  406. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
  407. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
  408. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
  409. package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
  410. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
  411. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
  412. package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
  413. package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
  414. package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
  415. package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
  416. package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
  417. package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
  418. package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
  419. package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
  420. package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
  421. package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
  422. package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
  423. package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
  424. package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
  425. package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
  426. package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
  427. package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
  428. package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
  429. package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
  430. package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
  431. package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
  432. package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
  433. /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
  434. /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
  435. /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
  436. /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
@@ -0,0 +1,90 @@
1
+ import { ChainId } from "../../model/primitives.js";
2
+ import { DataResponse } from "../../model/response.js";
3
+ import "../../model/index.js";
4
+ import { OnchainSDK } from "../../sdk/OnchainSDK.js";
5
+ import { MultichainSDK } from "../../sdk/MultichainSDK.js";
6
+ import { ChainQueryOneProps, MultichainConstruct } from "../../sdk/base/MultichainConstruct.js";
7
+ import "../../sdk/index.js";
8
+ import { EnsureFreshChains } from "../types.js";
9
+ import { AddCollateralParams, AdjustLeverageParams, DelayedSimulate, DepositStrategyParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesSimulate, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
10
+ //#region src/new-sdk/simulate/SimulateApi.d.ts
11
+ /**
12
+ * The chain's SDK, resolved on the spot.
13
+ *
14
+ * The LP simulations need it synchronously, because they only do arithmetic on
15
+ * loaded state and have nothing to await; the execute namespace resolves its
16
+ * chain the same way.
17
+ **/
18
+ type ChainOf = (chainId: ChainId) => OnchainSDK;
19
+ /**
20
+ * {@inheritDoc OpportunitiesSimulate}
21
+ *
22
+ * Holds no state of its own: it owns the mapping from the public,
23
+ * read-model-shaped request to the engine's intent, and nothing else. All
24
+ * protocol knowledge stays in `CreditAccountOperationsService` and
25
+ * `PoolService`.
26
+ *
27
+ * A simulation names one chain, so it reads through
28
+ * {@link MultichainConstruct.queryChain}: there is no second source to fall back
29
+ * to, hence a chain the SDK does not cover, or one that fails the read, throws
30
+ * rather than answering with empty metadata.
31
+ **/
32
+ declare class SimulateApi extends MultichainConstruct implements OpportunitiesSimulate {
33
+ #private;
34
+ constructor(sdk: MultichainSDK, ensureFresh?: EnsureFreshChains);
35
+ protected queryChain<T>(props: ChainQueryOneProps<T>): Promise<DataResponse<T>>;
36
+ /**
37
+ * {@inheritDoc OpportunitiesSimulate.delayed}
38
+ **/
39
+ readonly delayed: DelayedSimulate;
40
+ /**
41
+ * {@inheritDoc OpportunitiesSimulate.deposit}
42
+ **/
43
+ deposit(pool: PoolInput, params: LpParams): LpSimulate;
44
+ /**
45
+ * {@inheritDoc OpportunitiesSimulate.withdraw}
46
+ **/
47
+ withdraw(pool: PoolInput, params: LpParams): LpSimulate;
48
+ /**
49
+ * {@inheritDoc OpportunitiesSimulate.redeem}
50
+ **/
51
+ redeem(pool: PoolInput, params: LpRedeemParams): LpSimulate;
52
+ /**
53
+ * {@inheritDoc OpportunitiesSimulate.openNewStrategy}
54
+ **/
55
+ openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<DataResponse<OpenStrategySimulate>>;
56
+ /**
57
+ * {@inheritDoc OpportunitiesSimulate.depositStrategy}
58
+ **/
59
+ depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<DataResponse<StrategySimulate>>;
60
+ /**
61
+ * {@inheritDoc OpportunitiesSimulate.withdrawStrategy}
62
+ **/
63
+ withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<StrategyRoutesSimulate>>;
64
+ /**
65
+ * {@inheritDoc OpportunitiesSimulate.maxWithdraw}
66
+ **/
67
+ maxWithdraw(position: PositionInput): Promise<DataResponse<bigint>>;
68
+ /**
69
+ * {@inheritDoc OpportunitiesSimulate.repayStrategy}
70
+ **/
71
+ repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<DataResponse<StrategySimulate>>;
72
+ /**
73
+ * {@inheritDoc OpportunitiesSimulate.maxRepay}
74
+ **/
75
+ maxRepay(position: PositionInput): Promise<DataResponse<bigint>>;
76
+ /**
77
+ * {@inheritDoc OpportunitiesSimulate.adjustLeverage}
78
+ **/
79
+ adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<StrategyRoutesSimulate>>;
80
+ /**
81
+ * {@inheritDoc OpportunitiesSimulate.addCollateral}
82
+ **/
83
+ addCollateral(position: PositionInput, params: AddCollateralParams): Promise<DataResponse<StrategySimulate>>;
84
+ /**
85
+ * {@inheritDoc OpportunitiesSimulate.withdrawCollateral}
86
+ **/
87
+ withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<DataResponse<StrategySimulate>>;
88
+ }
89
+ //#endregion
90
+ export { ChainOf, SimulateApi };
@@ -0,0 +1,3 @@
1
+ import { AddCollateralParams, AdjustLeverageParams, DelayedSimulate, DelayedStrategySimulate, DepositStrategyParams, FinishDelayedParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesSimulate, PoolInput, PositionInput, RepayStrategyParams, SimulateOptions, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
2
+ import { ChainOf, SimulateApi } from "./SimulateApi.js";
3
+ export { AddCollateralParams, AdjustLeverageParams, ChainOf, DelayedSimulate, DelayedStrategySimulate, DepositStrategyParams, FinishDelayedParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesSimulate, PoolInput, PositionInput, RepayStrategyParams, SimulateApi, SimulateOptions, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams };
@@ -0,0 +1,508 @@
1
+ import { ClaimableWithdrawal } from "../../sdk/accounts/withdrawal-compressor/types.js";
2
+ import { Asset } from "../../sdk/base/types.js";
3
+ import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
4
+ import { StrategyPositionKey } from "../../model/positions.js";
5
+ import { DataResponse } from "../../model/response.js";
6
+ import "../../model/index.js";
7
+ import { MultiCall } from "../../sdk/types/transactions.js";
8
+ import { PoolSimulation } from "../../sdk/pools/types.js";
9
+ import { OpenStrategyPreview } from "../../sdk/accounts/intents/open-strategy.js";
10
+ import { DelayedStart, OperationState, PreviewErrorReason, ResumableIntent, RouteRefusals } from "../../sdk/accounts/intents/types.js";
11
+ import { AccountCalculatorOperation } from "../../sdk/accounts/intents/operations.js";
12
+ import "../../sdk/index.js";
13
+ import { Address } from "viem";
14
+ //#region src/new-sdk/simulate/types.d.ts
15
+ /**
16
+ * What a pool deposit or withdrawal would yield.
17
+ *
18
+ * Shaped like {@link StrategySimulate} so both kinds of simulation are consumed
19
+ * the same way, with the pool's own numbers as the preview: the ERC-4626
20
+ * conversion applied to the amount, at the rate of the block the market was
21
+ * loaded at.
22
+ **/
23
+ type LpSimulate = {
24
+ ok: true;
25
+ /**
26
+ * Always empty: a pool operation is a single transaction, so there is no
27
+ * chain of steps to show. Present so callers can treat both simulations
28
+ * alike.
29
+ **/
30
+ operations: [];
31
+ /**
32
+ * What the wallet parts with and what it receives, plus the zapper the
33
+ * transaction goes through when one is involved.
34
+ **/
35
+ preview: PoolSimulation;
36
+ /**
37
+ * The transaction implementing the operation: exactly one, since a pool
38
+ * operation is a single call on the pool or on its zapper.
39
+ **/
40
+ calls: MultiCall[];
41
+ } | {
42
+ ok: false;
43
+ reason: PreviewErrorReason;
44
+ };
45
+ /**
46
+ * What an operation on an existing credit account would yield.
47
+ *
48
+ * `ok: false` means the request itself is not viable — not that a call failed —
49
+ * so the reason is a value rather than an exception: too much leverage, too
50
+ * little of the source token, a token the flow does not accept.
51
+ **/
52
+ type StrategySimulate = {
53
+ ok: true;
54
+ /**
55
+ * The logical steps, each carrying the amounts it was computed from.
56
+ * Useful for showing the user what will happen, and for pinning behaviour
57
+ * in tests.
58
+ **/
59
+ operations: AccountCalculatorOperation[];
60
+ /**
61
+ * Projected account state once the operations execute: TVL, debt,
62
+ * balances and quotas.
63
+ **/
64
+ preview: OperationState;
65
+ /**
66
+ * Credit-facade multicall implementing the operations, ready to be sent
67
+ * through `sdk.accounts`.
68
+ **/
69
+ calls: MultiCall[];
70
+ } | {
71
+ ok: false;
72
+ reason: PreviewErrorReason;
73
+ };
74
+ /**
75
+ * What the leading half of a delayed operation would yield: the request
76
+ * transaction, plus what it recorded for the tail.
77
+ *
78
+ * Shaped like {@link StrategySimulate} with one field more, so the instant and
79
+ * the delayed route of the same request are compared side by side.
80
+ **/
81
+ type DelayedStrategySimulate = {
82
+ ok: true;
83
+ /**
84
+ * {@inheritDoc StrategySimulate.operations}
85
+ **/
86
+ operations: AccountCalculatorOperation[];
87
+ /**
88
+ * State once the request executes: the source token is gone and the
89
+ * withdrawal position stands in its place, with debt untouched — the
90
+ * repayment belongs to the tail.
91
+ **/
92
+ preview: OperationState;
93
+ /**
94
+ * {@inheritDoc StrategySimulate.calls}
95
+ **/
96
+ calls: MultiCall[];
97
+ /**
98
+ * When the tail can be run, and what the request recorded for it, see
99
+ * {@link DelayedStart}.
100
+ **/
101
+ delayed: DelayedStart;
102
+ } | {
103
+ ok: false;
104
+ reason: PreviewErrorReason;
105
+ };
106
+ /**
107
+ * What one of the two flows that sell a position asset —
108
+ * {@link OpportunitiesSimulate.withdrawStrategy} and
109
+ * {@link OpportunitiesSimulate.adjustLeverage} — would yield each way it can be
110
+ * served.
111
+ *
112
+ * Whether the account can sell that asset on the router, redeem it through its
113
+ * issuer, or both, is not something the caller can know up front, so both routes
114
+ * are quoted from one request. A route the account cannot take is `undefined`
115
+ * with its refusal in `refused`, which is what lets a form offer exactly the
116
+ * routes that exist; `ok: false` means neither does.
117
+ **/
118
+ type StrategyRoutesSimulate = {
119
+ ok: true;
120
+ /**
121
+ * The router route: one transaction, settled on the spot. `undefined`
122
+ * when the asset cannot be sold, see `refused.instant`.
123
+ **/
124
+ instant: Extract<StrategySimulate, {
125
+ ok: true;
126
+ }> | undefined;
127
+ /**
128
+ * The request half of the redemption route, which
129
+ * {@link DelayedSimulate.finish} completes once it matures. `undefined`
130
+ * when the route does not exist — no redemption venue for the asset, or a
131
+ * request that settles at once anyway — see `refused.delayed`.
132
+ **/
133
+ delayed: Extract<DelayedStrategySimulate, {
134
+ ok: true;
135
+ }> | undefined;
136
+ /**
137
+ * Why a missing route was refused, see {@link RouteRefusals}.
138
+ **/
139
+ refused: RouteRefusals;
140
+ } | {
141
+ ok: false;
142
+ /**
143
+ * The instant route's refusal, which is the one a caller can usually act
144
+ * on; the delayed route's when the instant one did not even get that far.
145
+ **/
146
+ reason: PreviewErrorReason;
147
+ /**
148
+ * {@inheritDoc StrategyRoutesSimulate.refused}
149
+ **/
150
+ refused: RouteRefusals;
151
+ };
152
+ /**
153
+ * What opening a new leveraged position would yield.
154
+ *
155
+ * The only simulation that reports both an expected and a floor branch: opening
156
+ * takes both from a single pathfinder call, and `openCA` consumes both.
157
+ **/
158
+ type OpenStrategySimulate = {
159
+ ok: true;
160
+ preview: OpenStrategyPreview;
161
+ } | {
162
+ ok: false;
163
+ reason: PreviewErrorReason;
164
+ };
165
+ /**
166
+ * Shared knobs. Both default to the SDK's own defaults when omitted.
167
+ **/
168
+ interface SimulateOptions {
169
+ /** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
170
+ slippage?: number;
171
+ /**
172
+ * Extra quota headroom in PERCENTAGE_FORMAT, to survive price drift between
173
+ * the simulation and execution.
174
+ **/
175
+ quotaReserve?: number;
176
+ }
177
+ /**
178
+ * Position to simulate against. A `StrategyPosition` from
179
+ * `sdk.positions.list()` satisfies this, as does a bare key.
180
+ **/
181
+ type PositionInput = StrategyPositionKey;
182
+ /**
183
+ * Pool to simulate against. A `PoolOpportunity` from
184
+ * `sdk.opportunities.list()` satisfies this, as does a bare key.
185
+ **/
186
+ type PoolInput = PoolOpportunityKey;
187
+ /**
188
+ * Market to open a new position in. A `StrategyOpportunity` from
189
+ * `sdk.opportunities.list()` satisfies this, as does a bare key.
190
+ **/
191
+ type StrategyInput = StrategyOpportunityKey;
192
+ interface DepositStrategyParams extends SimulateOptions {
193
+ /**
194
+ * Collateral to add: the market underlying, or its unwrapped asset on an RWA
195
+ * market (USDC rather than dcUSDC).
196
+ **/
197
+ token: Address;
198
+ amount: bigint;
199
+ /** Native value to attach when paying a wrapped-native market in the coin. */
200
+ value?: bigint;
201
+ /**
202
+ * Token the position ends up in. Defaults to the account's most valuable
203
+ * non-phantom, non-underlying balance.
204
+ **/
205
+ positionToken?: Address;
206
+ /**
207
+ * Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x). Omit to
208
+ * keep the account's current leverage.
209
+ **/
210
+ targetLeverage?: bigint;
211
+ }
212
+ interface WithdrawStrategyParams extends SimulateOptions {
213
+ /**
214
+ * Amount the wallet receives, denominated in `tokenOut`. `MAX_UINT256`, or
215
+ * anything at or above the account's net value, turns the flow into an exit,
216
+ * see {@link OpportunitiesSimulate.withdrawStrategy}.
217
+ **/
218
+ amount: bigint;
219
+ /** Wallet receiving the payout. */
220
+ to: Address;
221
+ /**
222
+ * Token the wallet receives. Defaults to the market underlying, force-unwrapped
223
+ * to the RWA asset on an RWA market.
224
+ **/
225
+ tokenOut?: Address;
226
+ /**
227
+ * Token liquidated to fund the withdrawal. Defaults to the account's most
228
+ * valuable non-phantom balance.
229
+ **/
230
+ sourceToken?: Address;
231
+ }
232
+ interface RepayStrategyParams extends SimulateOptions {
233
+ /**
234
+ * Funding token: the market underlying, which needs no conversion and is
235
+ * repaid where it lands, or — on an RWA market — the unwrapped asset behind
236
+ * it (USDC rather than dcUSDC), which this flow wraps on the way in.
237
+ **/
238
+ token: Address;
239
+ /**
240
+ * Amount taken from the wallet. Anything above the outstanding debt settles
241
+ * it in full and stays on the account as collateral, so a caller clearing the
242
+ * account can add a buffer for the interest that accrues before the
243
+ * transaction lands, see {@link OpportunitiesSimulate.maxRepay}.
244
+ * `MAX_UINT256` settles the debt and sizes that buffer itself.
245
+ **/
246
+ amount: bigint;
247
+ /** Native value to attach when paying a wrapped-native market in the coin. */
248
+ value?: bigint;
249
+ }
250
+ interface AdjustLeverageParams extends SimulateOptions {
251
+ /**
252
+ * Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x); 100n means
253
+ * no debt.
254
+ **/
255
+ targetLeverage: bigint;
256
+ /**
257
+ * Position token to buy into or sell out of. Defaults to the account's most
258
+ * valuable non-phantom, non-underlying balance.
259
+ **/
260
+ token?: Address;
261
+ }
262
+ interface AddCollateralParams extends SimulateOptions {
263
+ /** Position token to deposit; nothing else is accepted. */
264
+ token: Address;
265
+ amount: bigint;
266
+ /** Native value to attach when paying a wrapped-native market in the coin. */
267
+ value?: bigint;
268
+ }
269
+ interface WithdrawCollateralParams extends SimulateOptions {
270
+ /** Token to move out; must already sit on the account. */
271
+ token: Address;
272
+ amount: bigint;
273
+ /** Wallet receiving the tokens. */
274
+ to: Address;
275
+ }
276
+ interface OpenStrategyParams extends SimulateOptions {
277
+ /** Collateral coming from the wallet, in their own tokens. */
278
+ collateral: Asset[];
279
+ /**
280
+ * Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x).
281
+ **/
282
+ leverage: bigint;
283
+ /**
284
+ * Token the position ends up in. Defaults to the opportunity's target
285
+ * collateral.
286
+ **/
287
+ targetToken?: Address;
288
+ /** Collateral to leave unswapped; everything else is routed into the target. */
289
+ leftoverBalances?: Asset[];
290
+ }
291
+ interface LpParams {
292
+ /**
293
+ * On deposit: amount of `tokenIn`. On withdraw: amount of `tokenOut`, which
294
+ * the pool's `withdraw` takes as is and prices in shares itself.
295
+ **/
296
+ amount: bigint;
297
+ /**
298
+ * Wallet funding the deposit or receiving the withdrawal. Required because it
299
+ * is baked into the calldata.
300
+ **/
301
+ wallet: Address;
302
+ /**
303
+ * Token the user parts with. Defaults to the pool underlying on deposit and to
304
+ * the pool shares on withdrawal.
305
+ **/
306
+ tokenIn?: Address;
307
+ /**
308
+ * Token the user receives. Defaults to the only route available for `tokenIn`;
309
+ * required when the pool offers several, otherwise the simulation reports
310
+ * `unsupportedTokenPair`.
311
+ **/
312
+ tokenOut?: Address;
313
+ }
314
+ /**
315
+ * Same shape as {@link LpParams}, but {@link OpportunitiesSimulate.redeem}
316
+ * treats `amount` as the pool shares to burn rather than the underlying to
317
+ * receive.
318
+ **/
319
+ interface LpRedeemParams {
320
+ /**
321
+ * Amount of `tokenIn` — pool shares, or the zapper token that wraps them —
322
+ * to redeem.
323
+ **/
324
+ amount: bigint;
325
+ wallet: Address;
326
+ tokenIn?: Address;
327
+ tokenOut?: Address;
328
+ }
329
+ interface FinishDelayedParams extends SimulateOptions {
330
+ /**
331
+ * The matured withdrawal to claim, from
332
+ * `sdk.onchain.chain(chainId).withdrawalCompressor.getCurrentWithdrawals()`.
333
+ **/
334
+ claimable: ClaimableWithdrawal;
335
+ /**
336
+ * The operation to resume. Defaults to the one the request recorded in the
337
+ * withdrawal's `extraData`, which is what {@link ClaimableWithdrawal.intent}
338
+ * decodes; pass it explicitly when the compressor is too old to report it.
339
+ **/
340
+ intent?: ResumableIntent;
341
+ }
342
+ /**
343
+ * The delayed route of the two operations that can take it: a source that only
344
+ * redeems through its issuer — a Securitize dsToken, a Mellow share — instead of
345
+ * through the router.
346
+ *
347
+ * Two transactions rather than one: the request, then the tail once the
348
+ * redemption matures, which is days later. In between, nothing has to be kept on
349
+ * the client — the request writes the operation into the withdrawal's
350
+ * `extraData`, and reading the claimable decodes it back.
351
+ **/
352
+ interface DelayedSimulate {
353
+ /**
354
+ * The delayed counterpart of {@link OpportunitiesSimulate.withdrawStrategy},
355
+ * on its own: that flow already quotes this route alongside the instant one,
356
+ * so reach for this when the delayed route is the only one of interest.
357
+ *
358
+ * Reports `noDelayedRoute` when the account has no redemption venue for the
359
+ * source at all.
360
+ **/
361
+ withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<DelayedStrategySimulate>>;
362
+ /**
363
+ * The delayed counterpart of {@link OpportunitiesSimulate.adjustLeverage} on
364
+ * its own, which only deleveraging reaches: raising leverage buys the position
365
+ * token and never redeems it. That flow already quotes this route alongside
366
+ * the instant one, so reach for this when it is the only one of interest.
367
+ **/
368
+ adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<DelayedStrategySimulate>>;
369
+ /**
370
+ * The tail: claim the matured withdrawal, then whatever the recorded
371
+ * operation still owes — repaying debt and paying the wallet out for a
372
+ * withdrawal, repaying alone for a deleveraging, nothing beyond the claim for
373
+ * the rest.
374
+ *
375
+ * Answers like the instant flows, so both halves are consumed the same way.
376
+ * Reports `noRecordedIntent` when the claim names no operation to resume.
377
+ **/
378
+ finish(position: PositionInput, params: FinishDelayedParams): Promise<DataResponse<StrategySimulate>>;
379
+ }
380
+ /**
381
+ * Simulations of everything a wallet can do to a pool or a credit account.
382
+ *
383
+ * On-chain only: every method reads live state and, for strategies, asks the
384
+ * pathfinder for real swap paths. Nothing is executed and nothing is signed —
385
+ * the result is the numbers plus the calldata that would produce them.
386
+ *
387
+ * Not to be confused with `src/preview/simulate`, which goes the other way: it
388
+ * takes calldata that already exists and reports what it would do.
389
+ **/
390
+ interface OpportunitiesSimulate {
391
+ /**
392
+ * Depositing into a pool: underlying in, shares out.
393
+ *
394
+ * Synchronous, unlike every strategy simulation below: the answer is the
395
+ * pool's share rate applied to the amount, and that rate is already loaded.
396
+ **/
397
+ deposit(pool: PoolInput, params: LpParams): LpSimulate;
398
+ /**
399
+ * Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
400
+ * wants back, and the pool burns whatever shares that costs.
401
+ *
402
+ * The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
403
+ * which act on credit accounts.
404
+ **/
405
+ withdraw(pool: PoolInput, params: LpParams): LpSimulate;
406
+ /**
407
+ * Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
408
+ * and the preview is the underlying it converts to.
409
+ **/
410
+ redeem(pool: PoolInput, params: LpRedeemParams): LpSimulate;
411
+ /**
412
+ * Opening a leveraged position from wallet collateral.
413
+ *
414
+ * The one flow with no account yet, so the result carries no operation list —
415
+ * it feeds `sdk.accounts.openCA` instead.
416
+ **/
417
+ openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<DataResponse<OpenStrategySimulate>>;
418
+ /**
419
+ * Growing a position: collateral in, debt drawn on top, both converted into
420
+ * the position token.
421
+ *
422
+ * Leverage stays put unless `targetLeverage` asks for more.
423
+ **/
424
+ depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<DataResponse<StrategySimulate>>;
425
+ /**
426
+ * Shrinking a position: part of its net value goes to the wallet and debt is
427
+ * repaid in the same proportion, so leverage is unchanged.
428
+ *
429
+ * Answers with both routes the withdrawal can take — sold through the router
430
+ * now, or redeemed through the source's issuer and finished days later — since
431
+ * the source token decides which of them exist, see
432
+ * {@link StrategyRoutesSimulate}.
433
+ *
434
+ * `MAX_UINT256` — or any amount at or above the account's net value — is an
435
+ * exit instead: the quotas are dropped, the position is sold whole in one
436
+ * many-to-one route, the debt is settled in full and every balance left goes
437
+ * to `to`. `tokenOut` is ignored, since the proceeds are already the
438
+ * underlying (unwrapped on an RWA market). The account stays open with
439
+ * nothing on it. An exit has no delayed route.
440
+ *
441
+ * @see withdrawCollateral to move an asset out without touching debt, which
442
+ * raises leverage instead.
443
+ **/
444
+ withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<StrategyRoutesSimulate>>;
445
+ /**
446
+ * Largest partial withdrawal {@link withdrawStrategy} accepts, in underlying
447
+ * units: the amount whose proportional repayment leaves the debt at the
448
+ * credit manager's `minDebt`. Between this and the account's net value the
449
+ * flow refuses — the leftover loan would sit below `minDebt` — and at the net
450
+ * value it turns into an exit.
451
+ *
452
+ * Taking everything out needs none of this arithmetic: send `MAX_UINT256` to
453
+ * {@link withdrawStrategy} and the exit is what runs.
454
+ **/
455
+ maxWithdraw(position: PositionInput): Promise<DataResponse<bigint>>;
456
+ /**
457
+ * Paying debt down with funds from the wallet: collateral stays where it is,
458
+ * so net value grows by what was repaid, leverage falls and the health factor
459
+ * rises. The flow to reach for when a position is close to liquidation.
460
+ *
461
+ * A partial repayment is two calls and nothing else: the funding lands and
462
+ * the debt shrinks, quotas untouched — they still back a loan.
463
+ *
464
+ * A repayment that covers the whole debt clears the account's quotas with it,
465
+ * which the facade requires of a loan going to zero, and asks for the full
466
+ * outstanding amount, so nothing is left owing because interest moved between
467
+ * this simulation and the transaction. `MAX_UINT256` is how to ask for that
468
+ * settlement without naming a figure: the wallet is charged the debt plus a
469
+ * 10bps margin for the interest still to come, and whatever the facade does
470
+ * not take stays on the account.
471
+ **/
472
+ repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<DataResponse<StrategySimulate>>;
473
+ /**
474
+ * Debt {@link repayStrategy} would have to cover to clear the account, in
475
+ * underlying units: principal, interest and fees as of this read. Interest
476
+ * keeps accruing, so a wallet meaning to settle sends this with a buffer.
477
+ **/
478
+ maxRepay(position: PositionInput): Promise<DataResponse<bigint>>;
479
+ /**
480
+ * Retargeting leverage at fixed collateral: debt moves, own funds do not.
481
+ *
482
+ * Answers with both routes, like {@link withdrawStrategy}, since deleveraging
483
+ * sells the position token and may only be able to redeem it. Raising leverage
484
+ * buys instead, so there the delayed route is always absent with
485
+ * `refused.delayed: "noDelayedRoute"`.
486
+ **/
487
+ adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<StrategyRoutesSimulate>>;
488
+ /**
489
+ * Putting the position token onto the account at fixed debt, which lowers
490
+ * leverage and raises the health factor.
491
+ **/
492
+ addCollateral(position: PositionInput, params: AddCollateralParams): Promise<DataResponse<StrategySimulate>>;
493
+ /**
494
+ * Moving one asset that already sits on the account out to the wallet, at
495
+ * fixed debt — so TVL falls and leverage rises.
496
+ *
497
+ * @see withdrawStrategy for the deleveraging withdrawal, which repays debt in
498
+ * proportion and leaves leverage unchanged.
499
+ **/
500
+ withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<DataResponse<StrategySimulate>>;
501
+ /**
502
+ * The same requests routed through a delayed redemption instead of the
503
+ * router, and the tail that finishes them, see {@link DelayedSimulate}.
504
+ **/
505
+ readonly delayed: DelayedSimulate;
506
+ }
507
+ //#endregion
508
+ export { AddCollateralParams, AdjustLeverageParams, DelayedSimulate, DelayedStrategySimulate, DepositStrategyParams, FinishDelayedParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesSimulate, PoolInput, PositionInput, RepayStrategyParams, SimulateOptions, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams };
@@ -1,5 +1,9 @@
1
1
  import { ILogger } from "../sdk/types/logger.js";
2
+ import { ChainId } from "../model/primitives.js";
2
3
  import { NetworkType } from "../sdk/chain/chains.js";
4
+ import { Notice, NoticeSubject } from "../model/notices.js";
5
+ import { DataResponse } from "../model/response.js";
6
+ import "../model/index.js";
3
7
  import { MultichainAttachOptions, MultichainSDK, MultichainSDKOptions } from "../sdk/MultichainSDK.js";
4
8
  import "../sdk/index.js";
5
9
  import { GearboxAPIOptions } from "../offchain/types.js";
@@ -54,6 +58,12 @@ interface GearboxSDKOptions<M extends Mode = Mode> {
54
58
  * `both` mode, see {@link DEFAULT_MAX_OFFCHAIN_LAG}.
55
59
  **/
56
60
  maxOffchainLagSeconds?: number;
61
+ /**
62
+ * How old the loaded on-chain state may be, in seconds, before a read syncs
63
+ * the chains it touches first, see {@link DEFAULT_MAX_STATE_AGE}. A read
64
+ * inside the window is served from loaded state.
65
+ **/
66
+ maxStateAgeSeconds?: number;
57
67
  /**
58
68
  * Options passed to {@link MultichainSDK.attach}, used only when the SDK
59
69
  * builds the on-chain source itself.
@@ -61,6 +71,15 @@ interface GearboxSDKOptions<M extends Mode = Mode> {
61
71
  attach?: MultichainAttachOptions;
62
72
  logger?: ILogger;
63
73
  }
74
+ /**
75
+ * What a namespace asks of the on-chain state before it reads it: attached,
76
+ * and no older than the SDK's `maxStateAgeSeconds` on the chains the read
77
+ * touches. Owned by {@link GearboxSDK}, which shares one attach and one
78
+ * in-flight sync per chain across every namespace.
79
+ *
80
+ * @internal
81
+ **/
82
+ type EnsureFreshChains = (chainIds?: readonly ChainId[]) => Promise<void>;
64
83
  /**
65
84
  * What a {@link GearboxSDK} hands every namespace it builds.
66
85
  **/
@@ -70,6 +89,11 @@ interface NamespaceOptions {
70
89
  * {@link GearboxSDKOptions.maxOffchainLagSeconds}.
71
90
  **/
72
91
  maxOffchainLagSeconds: number;
92
+ /**
93
+ * Awaited before every on-chain leg of an async read, see
94
+ * {@link EnsureFreshChains}. Absent when the SDK reads no chain.
95
+ **/
96
+ ensureFresh?: EnsureFreshChains;
73
97
  logger?: ILogger;
74
98
  }
75
99
  /**
@@ -82,6 +106,16 @@ interface OnchainByMode {
82
106
  offchain: undefined;
83
107
  both: MultichainSDK;
84
108
  }
109
+ /**
110
+ * `sdk.notices` per mode: a backend read, absent when the SDK reads no backend.
111
+ *
112
+ * @internal
113
+ **/
114
+ interface NoticesByMode {
115
+ onchain: undefined;
116
+ offchain: (subject: NoticeSubject) => Promise<DataResponse<Notice[]>>;
117
+ both: (subject: NoticeSubject) => Promise<DataResponse<Notice[]>>;
118
+ }
85
119
  /**
86
120
  * Off-chain escape hatch per mode: absent when the SDK reads no backend.
87
121
  *
@@ -93,4 +127,4 @@ interface OffchainByMode {
93
127
  both: GearboxAPI;
94
128
  }
95
129
  //#endregion
96
- export { GearboxSDKOptions, Mode, NamespaceOptions, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, PlainMultichainSDKOptions };
130
+ export { EnsureFreshChains, GearboxSDKOptions, Mode, NamespaceOptions, NoticesByMode, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, PlainMultichainSDKOptions };
@@ -1,5 +1,4 @@
1
1
  import { EntityMerger, FilterResult, ListMerger, MergeListResult } from "./types.js";
2
2
  import { filterResponse } from "./filterResponse.js";
3
- import { HistoryReader } from "./history.js";
4
3
  import { DEFAULT_MAX_OFFCHAIN_LAG, mergeChainList, mergeChainOne } from "./mergeChains.js";
5
- export { DEFAULT_MAX_OFFCHAIN_LAG, type EntityMerger, type FilterResult, HistoryReader, type ListMerger, type MergeListResult, filterResponse, mergeChainList, mergeChainOne };
4
+ export { DEFAULT_MAX_OFFCHAIN_LAG, type EntityMerger, type FilterResult, type ListMerger, type MergeListResult, filterResponse, mergeChainList, mergeChainOne };