@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
@@ -69,7 +69,7 @@ async function previewMulticallOperation(input, operation, options) {
69
69
  creditManager: operation.creditManager,
70
70
  intent: delayed.intent,
71
71
  instantPreview,
72
- delayedPreview: buildDelayedPreview(after.account, before, delayed, convert, receivedToken)
72
+ delayedPreview: buildDelayedPreview(after.account, before, delayed, convert, receivedToken, sdk)
73
73
  };
74
74
  }
75
75
  //#endregion
@@ -1,5 +1,5 @@
1
- import { iPoolV310Abi } from "../../abi/310/generated.js";
2
1
  import { iZapperAbi } from "../../abi/iZapper.js";
2
+ import { iPoolV310Abi } from "../../abi/310/generated.js";
3
3
  import { asPreviewSimulationError } from "./errors.js";
4
4
  //#region src/preview/simulate/simulatePoolOperation.ts
5
5
  function previewRead(operation) {
@@ -1,6 +1,6 @@
1
+ import { ierc20Abi } from "../../abi/iERC20.js";
1
2
  import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../sdk/utils/AddressMap.js";
3
- import { ierc20Abi } from "../../abi/iERC20.js";
4
4
  import "../../sdk/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
6
6
  import { getAddress, isAddressEqual, parseEventLogs } from "viem";
@@ -68,7 +68,6 @@ var MultichainSDK = class {
68
68
  const perChainOpts = options?.perChain?.[network] ?? {};
69
69
  return sdk.attach({
70
70
  ...perChainOpts,
71
- loadZappers: perChainOpts.loadZappers ?? options?.loadZappers,
72
71
  redstone: {
73
72
  ...options?.redstone,
74
73
  cache: this.#redstoneCache,
@@ -88,7 +87,7 @@ var MultichainSDK = class {
88
87
  * state and `allowMissingChains` is not set.
89
88
  */
90
89
  hydrate(state, options) {
91
- if (state.version !== 1) throw new SdkStateVersionMismatchError(1, state.version);
90
+ if (state.version !== 2) throw new SdkStateVersionMismatchError(2, state.version);
92
91
  if (options?.redstone) this.#redstoneCache = new PriceUpdatesCache({
93
92
  ttl: options.redstone.cacheTTL ?? 225e3,
94
93
  historical: !!options.redstone.historicTimestamp
@@ -168,7 +167,7 @@ var MultichainSDK = class {
168
167
  **/
169
168
  get state() {
170
169
  return {
171
- version: 1,
170
+ version: 2,
172
171
  chains: [...this.#chains.values()].map((sdk) => sdk.state)
173
172
  };
174
173
  }
@@ -178,7 +177,7 @@ var MultichainSDK = class {
178
177
  */
179
178
  stateHuman(raw) {
180
179
  return {
181
- version: 1,
180
+ version: 2,
182
181
  chains: [...this.#chains.values()].map((sdk) => sdk.stateHuman(raw))
183
182
  };
184
183
  }
@@ -7,6 +7,7 @@ import "./constants/index.js";
7
7
  import { formatTimestamp } from "./utils/formatter.js";
8
8
  import { toAddress } from "./utils/toAddress.js";
9
9
  import "./utils/index.js";
10
+ import { executeMulticallBatches } from "./utils/viem/executeMulticallBatches.js";
10
11
  import { ChainContractsRegister } from "./base/ChainContractsRegister.js";
11
12
  import "./base/index.js";
12
13
  import { executeDelegatedMulticalls } from "./utils/viem/executeDelegatedMulticalls.js";
@@ -40,7 +41,7 @@ import { createPublicClient, fallback, http, parseEventLogs } from "viem";
40
41
  * Serialised state format version, checked during hydration to detect
41
42
  * incompatible snapshots.
42
43
  **/
43
- const STATE_VERSION = 1;
44
+ const STATE_VERSION = 2;
44
45
  /**
45
46
  * @internal
46
47
  * Creates a viem `PublicClient` from the given connection options.
@@ -150,7 +151,7 @@ var OnchainSDK = class extends ChainContractsRegister {
150
151
  */
151
152
  async attach(options) {
152
153
  if (this.#attached) throw new SdkAlreadyAttachedError();
153
- const { addressProvider = ADDRESS_PROVIDER_V310, blockNumber, ignoreUpdateablePrices, ignoreMarkets, marketConfigurators: mcs, redstone, loadZappers } = options ?? {};
154
+ const { addressProvider = ADDRESS_PROVIDER_V310, blockNumber, ignoreUpdateablePrices, ignoreMarkets, marketConfigurators: mcs, redstone } = options ?? {};
154
155
  const marketConfigurators = mcs ?? TypedObjectUtils.keys(this.client.chain.defaultMarketConfigurators);
155
156
  const rwaFactories = options?.rwaFactories ?? this.client.chain.rwaFactories;
156
157
  this.logger?.info({
@@ -174,19 +175,15 @@ var OnchainSDK = class extends ChainContractsRegister {
174
175
  this.#marketRegister = new MarketRegister(this, ignoreMarkets);
175
176
  if (!marketConfigurators.length) this.logger?.warn("no market configurators provided, skipping market loading");
176
177
  else {
178
+ const priceUpdates = await this.#getPriceUpdateTxs(marketConfigurators, ignoreUpdateablePrices);
179
+ this.logger?.debug({ configurators: marketConfigurators }, `calling getMarkets with ${priceUpdates.length} price updates in block ${this.currentBlock}`);
177
180
  const delegated = [...this.#marketRegister.getLoadMulticalls(marketConfigurators), ...this.#rwa.getLoadMulticalls(marketConfigurators, rwaFactories)];
178
- let txs = [];
179
- if (!ignoreUpdateablePrices) {
180
- const updatables = await this.#priceFeeds.getPartialUpdatablePriceFeeds(marketConfigurators);
181
- txs = (await this.#priceFeeds.generatePriceFeedsUpdateTxs(updatables)).txs;
182
- }
183
- this.logger?.debug({ configurators: marketConfigurators }, `calling getMarkets with ${txs.length} price updates in block ${this.currentBlock}`);
184
181
  await executeDelegatedMulticalls(this.client, delegated, {
185
- priceUpdates: txs,
182
+ priceUpdates,
186
183
  blockNumber: this.currentBlock,
187
184
  gas: this.gasLimit
188
185
  });
189
- if (loadZappers) await this.#marketRegister.loadZappers();
186
+ await this.#warmup();
190
187
  }
191
188
  const pluginsList = TypedObjectUtils.entries(this.plugins);
192
189
  (await Promise.allSettled(pluginsList.map(([name, plugin]) => {
@@ -203,6 +200,36 @@ var OnchainSDK = class extends ChainContractsRegister {
203
200
  this.#attached = true;
204
201
  }
205
202
  /**
203
+ * @internal
204
+ * Pass 0 of attach: resolves the price updates that the market reads of
205
+ * pass 1 are simulated with.
206
+ *
207
+ * @param configurators - Market configurators whose feeds are considered.
208
+ * @param ignoreUpdateablePrices - When `true`, no updates are fetched.
209
+ **/
210
+ async #getPriceUpdateTxs(configurators, ignoreUpdateablePrices) {
211
+ if (ignoreUpdateablePrices) return [];
212
+ const updatables = await this.priceFeeds.getPartialUpdatablePriceFeeds(configurators);
213
+ const { txs } = await this.priceFeeds.generatePriceFeedsUpdateTxs(updatables);
214
+ return txs;
215
+ }
216
+ /**
217
+ * @internal
218
+ * Pass 2 of attach: loads the data that is read synchronously afterwards
219
+ * (zappers, withdrawable assets, extended token data) in a single multicall.
220
+ *
221
+ * Also re-run after a sync that reloaded the markets these caches derive from.
222
+ *
223
+ * @param force - Reload caches that are already populated.
224
+ **/
225
+ async #warmup(force = false) {
226
+ await executeMulticallBatches(this.client, [
227
+ this.marketRegister.getLoadZappersMulticall(force),
228
+ ...this.#withdrawalCompressor ? [this.#withdrawalCompressor.getLoadWithdrawableAssetsMulticall(force)] : [],
229
+ this.tokensMeta.getLoadTokenDataMulticall()
230
+ ], { blockNumber: this.currentBlock });
231
+ }
232
+ /**
206
233
  * Restores SDK state from a previously serialised {@link GearboxState}
207
234
  * snapshot, without making any on-chain calls.
208
235
  *
@@ -214,7 +241,7 @@ var OnchainSDK = class extends ChainContractsRegister {
214
241
  */
215
242
  hydrate(state, options) {
216
243
  if (this.#attached) throw new SdkAlreadyAttachedError();
217
- if (state.version !== 1) throw new SdkStateVersionMismatchError(1, state.version);
244
+ if (state.version !== 2) throw new SdkStateVersionMismatchError(2, state.version);
218
245
  if (state.network !== this.networkType) throw new SdkChainMismatchError(this.networkType, state.network);
219
246
  const { ignoreMarkets, redstone } = options ?? {};
220
247
  this.logger?.info({ networkType: this.networkType }, "hydrating sdk state");
@@ -228,6 +255,7 @@ var OnchainSDK = class extends ChainContractsRegister {
228
255
  this.#rwa = new RWARegistry(this);
229
256
  this.#rwa.setState(state.rwa);
230
257
  if (state.withdrawals) this.#withdrawalCompressor?.hydrate(state.withdrawals);
258
+ if (state.tokens) this.tokensMeta.hydrate(state.tokens);
231
259
  for (const [name, plugin] of TypedObjectUtils.entries(this.plugins)) {
232
260
  const pluginState = state.plugins[name];
233
261
  if (plugin.hydrate && pluginState) {
@@ -273,13 +301,14 @@ var OnchainSDK = class extends ChainContractsRegister {
273
301
  /** Serialisable snapshot of the current SDK state. */
274
302
  get state() {
275
303
  return {
276
- version: 1,
304
+ version: 2,
277
305
  network: this.networkType,
278
306
  chainId: this.chainId,
279
307
  currentBlock: this.currentBlock,
280
308
  timestamp: this.timestamp,
281
309
  addressProvider: this.addressProvider.state,
282
310
  ...this.marketRegister.state,
311
+ tokens: this.tokensMeta.state,
283
312
  rwa: this.#rwa.state,
284
313
  withdrawals: this.#withdrawalCompressor?.state,
285
314
  plugins: Object.fromEntries(TypedObjectUtils.entries(this.plugins).map(([name, plugin]) => [name, plugin.loaded ? {
@@ -338,7 +367,7 @@ var OnchainSDK = class extends ChainContractsRegister {
338
367
  }
339
368
  this.#currentBlock = blockNumber;
340
369
  this.#timestamp = timestamp;
341
- await this.marketRegister.syncState(ignoreUpdateablePrices);
370
+ if (await this.marketRegister.syncState(ignoreUpdateablePrices, this.#rwa.getSyncMulticalls())) await this.#warmup(true);
342
371
  const pluginsList = TypedObjectUtils.entries(this.plugins);
343
372
  (await Promise.allSettled(pluginsList.map(([name, plugin]) => {
344
373
  if (plugin.syncState) {
@@ -1,3 +1,5 @@
1
+ import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
+ import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
1
3
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
2
4
  import { ADDRESS_0X0 } from "../constants/addresses.js";
3
5
  import { MAX_UINT256 } from "../constants/math.js";
@@ -8,8 +10,6 @@ import "../base/index.js";
8
10
  import { AccountBotsService } from "./bots/AccountBotsService.js";
9
11
  import "./bots/index.js";
10
12
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
11
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
13
13
  import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
14
  import "../market/index.js";
15
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
@@ -56,12 +56,6 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
56
56
  return this.#compressor.getBorrowerCreditAccounts(borrower, options, blockNumber);
57
57
  }
58
58
  /**
59
- * {@inheritDoc ICreditAccountsService.listPositions}
60
- **/
61
- async listPositions(props) {
62
- return this.#compressor.listPositions(props);
63
- }
64
- /**
65
59
  * {@inheritDoc ICreditAccountsService.getRewards}
66
60
  **/
67
61
  async getRewards(creditAccount) {
@@ -382,7 +376,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
382
376
  calls.push(facade.prepareIncreaseDebt(op.amount));
383
377
  break;
384
378
  case "decreaseDebt":
385
- calls.push(facade.prepareChangeDebt(op.amount, true));
379
+ calls.push(op.full ? facade.prepareDecreaseDebtFull() : facade.prepareChangeDebt(op.amount, true));
386
380
  break;
387
381
  case "addCollateral":
388
382
  calls.push(...facade.prepareAddCollateral([{
@@ -391,7 +385,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
391
385
  }], {}));
392
386
  break;
393
387
  case "withdrawCollateral":
394
- calls.push(facade.prepareWithdrawCollateral(op.token, op.amount, op.to));
388
+ calls.push(facade.prepareWithdrawCollateral(op.token, op.all ? MAX_UINT256 : op.amount, op.to));
395
389
  break;
396
390
  case "swap":
397
391
  case "wrapRwaCollateral":
@@ -1,4 +1,3 @@
1
- import { AddressMap } from "../../utils/AddressMap.js";
2
1
  import { AddressSet } from "../../utils/AddressSet.js";
3
2
  import { AP_CREDIT_ACCOUNT_COMPRESSOR } from "../../constants/address-provider.js";
4
3
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -9,11 +8,8 @@ import { hexEq } from "../../utils/hex.js";
9
8
  import "../../utils/index.js";
10
9
  import { SDKConstruct } from "../../base/SDKConstruct.js";
11
10
  import "../../base/index.js";
12
- import { borrowApyBps, healthFactorBps, positionLeverage, usdToNumber } from "../../market/math.js";
13
- import { dominantCollateral } from "../../market/credit/dominantCollateral.js";
14
11
  import { simulateWithPriceUpdates } from "../../utils/viem/simulateWithPriceUpdates.js";
15
12
  import "../../utils/viem/index.js";
16
- import "../../market/index.js";
17
13
  import { iRWAFactoryAbi } from "../../../abi/rwa/iRWAFactory.js";
18
14
  import { CreditAccountCompressorV310Contract } from "./CreditAccountCompressorV310Contract.js";
19
15
  //#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
@@ -21,9 +17,8 @@ import { CreditAccountCompressorV310Contract } from "./CreditAccountCompressorV3
21
17
  * Reads credit accounts of the current chain.
22
18
  *
23
19
  * Stitches the credit account compressor together with the RWA factories (for
24
- * accounts owned via an investor EOA) and with the withdrawal compressor (for
25
- * assets that are on their way out of an account), and describes the result
26
- * either as raw account data or as {@link StrategyPosition}s.
20
+ * accounts owned via an investor EOA), and describes the result as raw
21
+ * account data.
27
22
  *
28
23
  * TODO: create and deploy new compressor contract onchain to avoid all this stitching
29
24
  **/
@@ -173,89 +168,6 @@ var CreditAccountCompressor = class extends SDKConstruct {
173
168
  return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
174
169
  }
175
170
  /**
176
- * Describes all credit accounts of a wallet as strategy positions.
177
- *
178
- * @param props - {@link ListStrategyPositionsProps}
179
- **/
180
- async listPositions(props) {
181
- const { owner, includeZeroDebt, blockNumber } = props;
182
- const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber), this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber)]);
183
- const describable = accounts.filter((ca) => {
184
- if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
185
- return ca.success;
186
- });
187
- const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
188
- return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
189
- }
190
- /**
191
- * Builds one strategy position from an account snapshot.
192
- *
193
- * @param withdrawals - Delayed withdrawals of the account, keyed by the
194
- * phantom token that represents them on it.
195
- **/
196
- #toStrategyPosition(ca, withdrawals) {
197
- const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
198
- const { market } = suite;
199
- const { priceOracle } = market;
200
- const { pool } = market.pool;
201
- const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
202
- const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
203
- const collateral = dominantCollateral(ca, market);
204
- return {
205
- kind: "strategy",
206
- chainId: this.sdk.chainId,
207
- creditManager: ca.creditManager,
208
- creditAccount: ca.creditAccount,
209
- name: collateral ? suite.strategyName(collateral) : token.symbol,
210
- targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
211
- leverage: positionLeverage(totalDebtValue, ca.totalValue),
212
- borrowApy: borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
213
- totalDebt: {
214
- token,
215
- value: totalDebtValue,
216
- valueUsd: usdToNumber(ca.totalDebtUSD)
217
- },
218
- totalValue: {
219
- token,
220
- value: ca.totalValue,
221
- valueUsd: usdToNumber(ca.totalValueUSD)
222
- },
223
- healthFactor: healthFactorBps(ca.healthFactor),
224
- collaterals: ca.tokens.flatMap((t) => {
225
- if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
226
- return [{
227
- collateral: priceOracle.toTokenAmount(t.token, t.balance),
228
- quota: priceOracle.toTokenAmount(market.underlying, t.quota),
229
- withdrawals: withdrawals.get(t.token) ?? []
230
- }];
231
- })
232
- };
233
- }
234
- /**
235
- * Delayed withdrawals of one account, keyed by the phantom token that
236
- * represents them on it, so that each collateral row can pick up its own.
237
- **/
238
- async #accountWithdrawals(ca, blockNumber) {
239
- const compressor = this.sdk.withdrawalCompressor;
240
- const byPhantomToken = new AddressMap(void 0, "accountWithdrawals");
241
- const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
242
- if (!compressor || !holdsPhantomToken) return byPhantomToken;
243
- const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
244
- const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
245
- const add = (w, outputs, claimableAt) => {
246
- const assets = outputs.map((o) => ({
247
- isDelayed: true,
248
- ...priceOracle.toTokenAmount(o.token, o.amount),
249
- redeemer: w.redeemer,
250
- claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
251
- }));
252
- byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
253
- };
254
- for (const w of claimable) add(w, w.outputs);
255
- for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
256
- return byPhantomToken;
257
- }
258
- /**
259
171
  * Credit account compressor contract of the current chain.
260
172
  *
261
173
  * Resolved on every access, because the address provider is only populated
@@ -5,7 +5,8 @@ import { CreditAccountCompressorV310Contract } from "./credit-account-compressor
5
5
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
6
6
  import "./credit-account-compressor/index.js";
7
7
  import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
8
- import { primaryInstantOutput } from "./intents/operations/claim-delayed/index.js";
8
+ import { IntentPreviewError } from "./intents/types.js";
9
+ import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
9
10
  import { CreditAccountOperationsService } from "./intents/index.js";
10
11
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./liquidations/constants.js";
11
12
  import { LiquidationsService } from "./liquidations/LiquidationsService.js";
@@ -24,4 +25,4 @@ import { toWithdrawalStatus } from "./withdrawal-compressor/types.js";
24
25
  import { WithdrawalCompressorV313Contract } from "./withdrawal-compressor/WithdrawalCompressorV313Contract.js";
25
26
  import { createWithdrawalCompressor } from "./withdrawal-compressor/createWithdrawalCompressor.js";
26
27
  import "./withdrawal-compressor/index.js";
27
- export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, getWithdrawalCompressorAddress, iCreditAccountAbi, primaryInstantOutput, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
28
+ export { AbstractWithdrawalCompressorContract, AccountBotsService, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountOperationsService, CreditAccountsServiceV310, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, IntentPreviewError, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, LiquidationsService, MultichainLiquidationsService, PeripheryCompressorV310Contract, RedemptionLoggerV310Contract, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
@@ -0,0 +1,108 @@
1
+ import "../../constants/math.js";
2
+ import "../../constants/index.js";
3
+ import { IntentPreviewError } from "./types.js";
4
+ import { eq } from "./utils/common.js";
5
+ import { isPhantomToken } from "./utils/pick-token.js";
6
+ //#region src/sdk/accounts/intents/guards.ts
7
+ /**
8
+ * What the market itself refuses, checked before anything is quoted.
9
+ *
10
+ * The planners answer for the arithmetic of an intent and the ledger for the
11
+ * balances it moves, but neither can see that the facade is paused or that the
12
+ * pool has run out of what it lends. On-chain those come back as a reverted
13
+ * multicall with a selector no form can explain, so they are read from the
14
+ * loaded market and reported as refusals instead.
15
+ */
16
+ /**
17
+ * The facade takes no multicall while it is paused or past its expiration, so
18
+ * every intent the engine previews would revert on arrival.
19
+ */
20
+ function assertMarketOperable(suite) {
21
+ if (suite.isPaused) throw new IntentPreviewError("marketPaused", `${suite.creditManager.address} is paused`);
22
+ if (suite.isExpired) throw new IntentPreviewError("marketExpired", `${suite.creditManager.address} expired at ${suite.creditFacade.expirationDate}`);
23
+ }
24
+ /**
25
+ * What the pool will hand this manager in one transaction: the tightest of its
26
+ * free liquidity, the manager's remaining debt limit and the per-block cap the
27
+ * facade puts on a single borrow. A zero multiplier switches borrowing off
28
+ * outright, which reads here as nothing being available.
29
+ */
30
+ function borrowable(suite) {
31
+ const { pool } = suite.market.pool;
32
+ const { maxDebtPerBlockMultiplier, maxDebt } = suite.creditFacade;
33
+ if (maxDebtPerBlockMultiplier === 0) return 0n;
34
+ const available = pool.creditManagerDebtParams.get(suite.creditManager.address)?.available;
35
+ return [
36
+ pool.availableLiquidity,
37
+ maxDebt * BigInt(maxDebtPerBlockMultiplier),
38
+ ...available === void 0 ? [] : [available]
39
+ ].reduce((a, b) => a < b ? a : b);
40
+ }
41
+ /** The pool has to be able to lend what the plan means to draw. */
42
+ function assertCanBorrow(suite, amount) {
43
+ const limit = borrowable(suite);
44
+ if (amount > limit) throw new IntentPreviewError("insufficientPoolLiquidity", `borrow: ${amount} exceeds what the pool can lend now (${limit})`);
45
+ }
46
+ /**
47
+ * What the account is allowed to end up holding more of than it started with.
48
+ *
49
+ * A forbidden token may be sold and may leave, but its balance must not grow —
50
+ * the facade checks exactly that at the end of the multicall. A token the
51
+ * market takes no quota for is not forbidden, only worthless as collateral:
52
+ * buying one builds a position the collateral check cannot count, so the plan
53
+ * is refused before it is signed rather than after it reverts.
54
+ *
55
+ * The underlying answers to neither rule, and a phantom token is a redemption
56
+ * in flight rather than a holding.
57
+ */
58
+ function assertGrowthAllowed(args) {
59
+ const { sdk, suite, market, before, after } = args;
60
+ const forbidden = forbiddenTokens(suite);
61
+ const underlying = market.pool.underlying;
62
+ for (const { token, balance } of after) {
63
+ if (balance <= (before.find((a) => eq(a.token, token))?.balance ?? 0n)) continue;
64
+ if (forbidden.some((f) => eq(f, token))) throw new IntentPreviewError("forbiddenToken", `${token} is forbidden in this market and the plan buys more of it`);
65
+ if (eq(token, underlying) || isPhantomToken(sdk, token)) continue;
66
+ if (!market.pool.pqk.hasActiveQuota(token)) throw new IntentPreviewError("quotaLimitReached", `${token} takes no quota in this market, so it counts as no collateral`);
67
+ }
68
+ }
69
+ /** Tokens the facade's mask flags, which is indexed by collateral position. */
70
+ function forbiddenTokens(suite) {
71
+ const mask = suite.creditFacade.forbiddenTokensMask;
72
+ if (mask === 0n) return [];
73
+ return suite.creditManager.collateralTokens.filter((_, i) => (mask & 1n << BigInt(i)) !== 0n);
74
+ }
75
+ /**
76
+ * The facade weighs the account against its debt at the end of every multicall
77
+ * and reverts if the collateral does not cover it, so a plan that lands the
78
+ * account below water is refused here.
79
+ *
80
+ * The bar is the health factor of the state the plan projects: collateral under
81
+ * liquidation thresholds, capped by quota, against the debt. Note that a
82
+ * position already underwater cannot be nursed back one step at a time — the
83
+ * check is on where the transaction ends, not on whether it improved things.
84
+ *
85
+ * @remarks
86
+ * The caller decides the pricing the factor was computed at: main prices, or
87
+ * the safe ones the facade switches to when the call hands funds over. A token
88
+ * whose reserve feed the SDK cannot read keeps its main price, so a plan can
89
+ * still be refused on-chain after passing here.
90
+ */
91
+ function assertCollateralised(healthFactorBps) {
92
+ if (healthFactorBps < Number(10000n)) throw new IntentPreviewError("insufficientCollateral", `the account would end at a health factor of ${healthFactorBps}, below 1.0`);
93
+ }
94
+ /**
95
+ * A quota can only be raised as far as the market still has room for: past the
96
+ * token's limit the keeper takes nothing more, whoever is asking.
97
+ */
98
+ function assertQuotaHeadroom(market, increases) {
99
+ for (const { token, balance } of increases) {
100
+ if (balance <= 0n) continue;
101
+ const quota = market.pool.pqk.quotas.get(token);
102
+ if (!quota) continue;
103
+ const left = quota.limit - quota.totalQuoted;
104
+ if (balance > left) throw new IntentPreviewError("quotaLimitReached", `${token} has ${left} of quota left, the plan needs ${balance}`);
105
+ }
106
+ }
107
+ //#endregion
108
+ export { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaHeadroom, borrowable };