@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,140 @@
1
+ //#region src/model/charts.ts
2
+ /**
3
+ * Historical charts of an opportunity or a position.
4
+ *
5
+ * Charts are backend-only by construction: the chain serves the present, and
6
+ * reconstructing a series from it would mean archive-node reads per point.
7
+ *
8
+ * A chart is read as a {@link ChartBundle}: one shared x-axis plus one
9
+ * {@link ChartSeries} per metric, each holding values only. Alignment is
10
+ * therefore structural — series `i` and series `j` describe the same instant at
11
+ * the same index — rather than a property the backend promises and every
12
+ * consumer re-checks.
13
+ **/
14
+ /**
15
+ * Time window a chart covers, ending at the present.
16
+ *
17
+ * `"max"` is the full history the backend retains for the subject.
18
+ **/
19
+ const CHART_RANGES = [
20
+ "1d",
21
+ "1w",
22
+ "1m",
23
+ "1y",
24
+ "max"
25
+ ];
26
+ /**
27
+ * Every metric a pool opportunity can chart.
28
+ **/
29
+ const POOL_OPPORTUNITY_CHART_METRICS = [
30
+ "depositApy",
31
+ "borrowApy",
32
+ "dieselRate",
33
+ "supplied",
34
+ "borrowed",
35
+ "availableLiquidity"
36
+ ];
37
+ /**
38
+ * Every metric a strategy opportunity can chart.
39
+ *
40
+ * `collateralPrice` is the collateral/underlying series a liquidation-price
41
+ * chart draws; the two USD series are the same prices quoted in dollars.
42
+ **/
43
+ const STRATEGY_OPPORTUNITY_CHART_METRICS = [
44
+ "netApy",
45
+ "borrowApy",
46
+ "collateralApy",
47
+ "tvl",
48
+ "collateralPrice",
49
+ "collateralUsdPrice",
50
+ "underlyingUsdPrice"
51
+ ];
52
+ /**
53
+ * Every metric a pool position can chart.
54
+ *
55
+ * Nothing to do with {@link POOL_OPPORTUNITY_CHART_METRICS}: an opportunity charts what the
56
+ * pool did, a position charts what one wallet's deposit did in it. `mwr` and
57
+ * `twr` are cumulative returns since the position opened — money-weighted, so
58
+ * sensitive to when deposits and withdrawals landed, and time-weighted, which
59
+ * strips that timing out. Both are anchored at inception, so a narrow `range`
60
+ * only zooms the visible slice and its first point is rarely zero.
61
+ **/
62
+ const POOL_POSITION_CHART_METRICS = [
63
+ "value",
64
+ "apy",
65
+ "pnl",
66
+ "mwr",
67
+ "twr",
68
+ "underlyingPrice"
69
+ ];
70
+ /**
71
+ * Every metric a strategy position can chart.
72
+ *
73
+ * `twrApy` annualizes `twr` over the position's whole life; the two trailing
74
+ * APYs annualize it over a fixed window instead, so they track the current pace
75
+ * rather than the lifetime rate and are comparable across positions of
76
+ * different ages.
77
+ **/
78
+ const STRATEGY_POSITION_CHART_METRICS = [
79
+ "totalValueUsd",
80
+ "totalValueUnderlying",
81
+ "debt",
82
+ "healthFactor",
83
+ "leverage",
84
+ "borrowApy",
85
+ "underlyingPrice",
86
+ "pnl",
87
+ "mwr",
88
+ "twr",
89
+ "twrApy",
90
+ "trailingApy7d",
91
+ "trailingApy30d"
92
+ ];
93
+ /**
94
+ * Unit of every metric, the one place either side decides it.
95
+ *
96
+ * A metric added to a union above fails to compile here until its unit is
97
+ * named, and the wire schema rejects a series whose `unit` disagrees with this
98
+ * table, so the backend cannot drift from it silently.
99
+ **/
100
+ const CHART_METRIC_UNITS = {
101
+ depositApy: "bps",
102
+ borrowApy: "bps",
103
+ netApy: "bps",
104
+ collateralApy: "bps",
105
+ supplied: "token",
106
+ borrowed: "token",
107
+ availableLiquidity: "token",
108
+ tvl: "token",
109
+ dieselRate: "ratio",
110
+ collateralPrice: "ratio",
111
+ collateralUsdPrice: "usd",
112
+ underlyingUsdPrice: "usd",
113
+ value: "token",
114
+ apy: "bps",
115
+ pnl: "token",
116
+ mwr: "bps",
117
+ twr: "bps",
118
+ underlyingPrice: "usd",
119
+ totalValueUsd: "usd",
120
+ totalValueUnderlying: "token",
121
+ debt: "token",
122
+ healthFactor: "bps",
123
+ leverage: "scalar",
124
+ twrApy: "bps",
125
+ trailingApy7d: "bps",
126
+ trailingApy30d: "bps"
127
+ };
128
+ /**
129
+ * Reason a series could not be produced at all, which is not the same as a
130
+ * series that has no points in the window.
131
+ **/
132
+ const CHART_UNAVAILABLE_CODES = [
133
+ "unknown_subject",
134
+ "unsupported_metric",
135
+ "no_price_feed",
136
+ "not_indexed",
137
+ "internal"
138
+ ];
139
+ //#endregion
140
+ export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS };
@@ -0,0 +1,226 @@
1
+ import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS } from "./charts.js";
2
+ import { timestampSchema, tokenSchema } from "./primitives.schema.js";
3
+ import { z } from "zod/v4";
4
+ //#region src/model/charts.schema.ts
5
+ /**
6
+ * Runtime schemas for {@link ./charts.js}, see the note in
7
+ * `primitives.schema.ts` on why they are written by hand.
8
+ *
9
+ * Metric schemas are shared with the backend, while
10
+ * {@link chartBundleSchemaFor} builds the response schema for one concrete
11
+ * request. Component schemas remain available for consumers that validate
12
+ * model fragments.
13
+ **/
14
+ /**
15
+ * {@link ChartRange}
16
+ **/
17
+ const chartRangeSchema = z.enum(CHART_RANGES);
18
+ /**
19
+ * {@link PoolOpportunityChartMetric}
20
+ **/
21
+ const poolOpportunityChartMetricSchema = z.enum(POOL_OPPORTUNITY_CHART_METRICS);
22
+ /**
23
+ * {@link StrategyOpportunityChartMetric}
24
+ **/
25
+ const strategyOpportunityChartMetricSchema = z.enum(STRATEGY_OPPORTUNITY_CHART_METRICS);
26
+ /**
27
+ * {@link PoolPositionChartMetric}
28
+ **/
29
+ const poolPositionChartMetricSchema = z.enum(POOL_POSITION_CHART_METRICS);
30
+ /**
31
+ * {@link StrategyPositionChartMetric}
32
+ **/
33
+ const strategyPositionChartMetricSchema = z.enum(STRATEGY_POSITION_CHART_METRICS);
34
+ /**
35
+ * {@link ChartMetric}, every metric either kind of subject can chart.
36
+ **/
37
+ const chartMetricSchema = z.union([
38
+ poolOpportunityChartMetricSchema,
39
+ strategyOpportunityChartMetricSchema,
40
+ poolPositionChartMetricSchema,
41
+ strategyPositionChartMetricSchema
42
+ ]);
43
+ /**
44
+ * {@link ChartQuery}
45
+ **/
46
+ const chartQuerySchema = z.object({
47
+ metrics: z.array(chartMetricSchema).readonly().refine((metrics) => metrics.length > 0, { error: "a chart read needs at least one metric" }).refine((metrics) => new Set(metrics).size === metrics.length, { error: "a chart read needs distinct metrics" }),
48
+ range: chartRangeSchema
49
+ });
50
+ /**
51
+ * {@link ChartQuery} as a URL can carry it: the metrics comma-joined, since
52
+ * repeated `?metrics=` entries would order differently between clients and give
53
+ * one request two cache keys.
54
+ **/
55
+ const chartQueryParamsSchema = z.object({
56
+ metrics: z.string().regex(/^\w+(,\w+)*$/),
57
+ range: chartRangeSchema
58
+ });
59
+ /**
60
+ * Codec for {@link ChartQuery} to encode/decode to/from url query parameters.
61
+ *
62
+ * The one place the wire form of a chart request is decided. The SDK encodes
63
+ * with it, the backend decodes with it, and the checks that a read names at
64
+ * least one metric and names none of them twice ride along in both directions —
65
+ * so a bad request fails before it is issued, not after a round trip.
66
+ **/
67
+ const chartQueryCodec = z.codec(chartQueryParamsSchema, chartQuerySchema, {
68
+ decode: (params) => ({
69
+ metrics: params.metrics.split(","),
70
+ range: params.range
71
+ }),
72
+ encode: (query) => ({
73
+ metrics: query.metrics.join(","),
74
+ range: query.range
75
+ })
76
+ });
77
+ /**
78
+ * {@link ChartDenomination}
79
+ **/
80
+ const chartDenominationSchema = z.discriminatedUnion("unit", [
81
+ z.object({ unit: z.literal("bps") }),
82
+ z.object({ unit: z.literal("usd") }),
83
+ z.object({ unit: z.literal("scalar") }),
84
+ z.object({
85
+ unit: z.literal("token"),
86
+ base: tokenSchema
87
+ }),
88
+ z.object({
89
+ unit: z.literal("ratio"),
90
+ base: tokenSchema,
91
+ quote: tokenSchema
92
+ })
93
+ ]);
94
+ /**
95
+ * {@link ChartValue}. `null` is a gap, never a zero.
96
+ **/
97
+ const chartValueSchema = z.number().nullable();
98
+ /**
99
+ * {@link ChartSeries}
100
+ **/
101
+ const chartSeriesSchema = z.union([z.intersection(z.object({
102
+ status: z.literal("ok"),
103
+ values: z.array(chartValueSchema)
104
+ }), chartDenominationSchema), z.object({
105
+ status: z.literal("unavailable"),
106
+ reason: z.object({
107
+ code: z.enum(CHART_UNAVAILABLE_CODES),
108
+ message: z.string().optional()
109
+ })
110
+ })]);
111
+ /**
112
+ * {@link ChartWindow}
113
+ **/
114
+ const chartWindowSchema = z.object({
115
+ range: chartRangeSchema,
116
+ from: timestampSchema,
117
+ to: timestampSchema
118
+ });
119
+ const gridSamplingSchema = z.object({
120
+ kind: z.literal("grid"),
121
+ intervalSeconds: z.number().int().positive()
122
+ });
123
+ /**
124
+ * A bundle whose series are keyed by `keys`.
125
+ *
126
+ * `z.record` over a literal union is what enforces the metric set: a key that
127
+ * was not asked for is rejected, and one that was but is missing fails as an
128
+ * absent value. Exactly-once therefore needs no counting — an object cannot
129
+ * hold the same key twice.
130
+ **/
131
+ function chartBundleSchemaWith(keys, expectedRange) {
132
+ return z.object({
133
+ window: chartWindowSchema,
134
+ sampling: gridSamplingSchema,
135
+ timestamps: z.array(timestampSchema),
136
+ series: z.record(keys, chartSeriesSchema)
137
+ }).superRefine((bundle, ctx) => checkChartBundle(bundle, ctx, expectedRange));
138
+ }
139
+ /**
140
+ * The invariants a bundle upholds beyond its shape, checked on every read so a
141
+ * backend that breaks one is rejected rather than plotted:
142
+ *
143
+ * - each available series holds exactly one value per timestamp, which is what
144
+ * makes two series of a bundle comparable at an index;
145
+ * - a series' unit is the one {@link CHART_METRIC_UNITS} gives the metric it is
146
+ * keyed by, so a consumer can format from either without them disagreeing;
147
+ * - the window's bounds are the axis' own, so a chart drawn from `window` and a
148
+ * chart drawn from `timestamps` cover the same span;
149
+ * - timestamps lie on the declared grid and are exactly one interval apart;
150
+ * - when validating a read, the response names the range that was requested.
151
+ **/
152
+ function checkChartBundle(bundle, ctx, expectedRange) {
153
+ const { sampling, timestamps, window, series } = bundle;
154
+ const entries = Object.entries(series);
155
+ for (const [metric, chart] of entries) {
156
+ if (chart.status !== "ok") continue;
157
+ if (chart.values.length !== timestamps.length) ctx.addIssue({
158
+ code: "custom",
159
+ path: [
160
+ "series",
161
+ metric,
162
+ "values"
163
+ ],
164
+ message: `series "${metric}" holds ${chart.values.length} values for ${timestamps.length} timestamps`
165
+ });
166
+ if (CHART_METRIC_UNITS[metric] !== chart.unit) ctx.addIssue({
167
+ code: "custom",
168
+ path: [
169
+ "series",
170
+ metric,
171
+ "unit"
172
+ ],
173
+ message: `metric "${metric}" is ${CHART_METRIC_UNITS[metric]}, not ${chart.unit}`
174
+ });
175
+ }
176
+ const first = timestamps.at(0);
177
+ const last = timestamps.at(-1);
178
+ if (first !== void 0 && first !== window.from) ctx.addIssue({
179
+ code: "custom",
180
+ path: ["window", "from"],
181
+ message: `window starts at ${window.from} but the axis starts at ${first}`
182
+ });
183
+ if (last !== void 0 && last !== window.to) ctx.addIssue({
184
+ code: "custom",
185
+ path: ["window", "to"],
186
+ message: `window ends at ${window.to} but the axis ends at ${last}`
187
+ });
188
+ if (expectedRange !== void 0 && window.range !== expectedRange) ctx.addIssue({
189
+ code: "custom",
190
+ path: ["window", "range"],
191
+ message: `requested range ${expectedRange}, received ${window.range}`
192
+ });
193
+ for (let i = 0; i < timestamps.length; i += 1) {
194
+ const timestamp = timestamps[i];
195
+ if (timestamp % sampling.intervalSeconds !== 0) ctx.addIssue({
196
+ code: "custom",
197
+ path: ["timestamps", i],
198
+ message: `timestamp ${timestamp} is not on the ${sampling.intervalSeconds}-second grid`
199
+ });
200
+ const previous = timestamps[i - 1];
201
+ if (previous !== void 0 && timestamp - previous !== sampling.intervalSeconds) ctx.addIssue({
202
+ code: "custom",
203
+ path: ["timestamps", i],
204
+ message: `timestamps are not ${sampling.intervalSeconds} seconds apart`
205
+ });
206
+ }
207
+ }
208
+ /**
209
+ * The schema one chart read is decoded with: a {@link ChartBundle} keyed by the
210
+ * requested distinct metrics, all of them and nothing else, for the requested
211
+ * range.
212
+ *
213
+ * Pinning the metrics is what upholds the `ChartBundle<Metrics>` a caller gets
214
+ * back — a response that answers a different question fails validation rather
215
+ * than being cast into the requested shape. The declared return type is the one
216
+ * the key schema actually enforces, which the compiler cannot see through a
217
+ * schema built from a runtime list.
218
+ **/
219
+ function chartBundleSchemaFor(metrics, range) {
220
+ if (metrics.length === 0) throw new RangeError("a chart read needs at least one metric");
221
+ if (new Set(metrics).size !== metrics.length) throw new RangeError("a chart read needs distinct metrics");
222
+ const literals = metrics.map((metric) => z.literal(metric));
223
+ return chartBundleSchemaWith(z.union(literals), range);
224
+ }
225
+ //#endregion
226
+ export { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema };
@@ -1,17 +1,19 @@
1
+ import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS } from "./charts.js";
2
+ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
3
+ import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema } from "./charts.schema.js";
1
4
  import "./curators.js";
2
5
  import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
3
6
  import { FILTER_ALL, isFilterSet } from "./filters.js";
4
7
  import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
5
- import { POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS } from "./history.js";
6
- import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
7
- import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
8
- import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
9
- import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
10
- import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema } from "./history.schema.js";
11
8
  import { matchesLiquidatableAccountFilter } from "./liquidations.js";
9
+ import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
10
+ import "./notices.js";
11
+ import { noticeKindSchema, noticeSchema } from "./notices.schema.js";
12
12
  import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
13
+ import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
13
14
  import { liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
15
+ import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
14
16
  import "./primitives.js";
15
17
  import "./response.js";
16
18
  import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
17
- export { FILTER_ALL, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
19
+ export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
@@ -1,6 +1,6 @@
1
1
  import { ZodAddress } from "../sdk/utils/zod.js";
2
- import { filterable } from "./filters.schema.js";
3
2
  import { assetTypeSchema, chainIdSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
3
+ import { filterable } from "./filters.schema.js";
4
4
  import { z } from "zod/v4";
5
5
  //#region src/model/liquidations.schema.ts
6
6
  /**
@@ -0,0 +1,23 @@
1
+ import { tokenSchema } from "./primitives.schema.js";
2
+ import { z } from "zod/v4";
3
+ //#region src/model/notices.schema.ts
4
+ /**
5
+ * {@link NoticeKind}
6
+ **/
7
+ const noticeKindSchema = z.union([
8
+ z.literal("expired"),
9
+ z.literal("externalRewards"),
10
+ z.literal("extraApy"),
11
+ z.literal("warning"),
12
+ z.literal("disclaimer")
13
+ ]);
14
+ /**
15
+ * {@link Notice}
16
+ **/
17
+ const noticeSchema = z.object({
18
+ kind: noticeKindSchema,
19
+ message: z.string(),
20
+ token: tokenSchema.optional()
21
+ });
22
+ //#endregion
23
+ export { noticeKindSchema, noticeSchema };
@@ -1,8 +1,8 @@
1
1
  import { ZodAddress } from "../sdk/utils/zod.js";
2
+ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
2
3
  import { curatorSchema } from "./curators.schema.js";
3
4
  import { isFilterSet } from "./filters.js";
4
5
  import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
5
- import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
6
6
  import { z } from "zod/v4";
7
7
  //#region src/model/opportunities.schema.ts
8
8
  /**
@@ -1,9 +1,9 @@
1
- import { ZodAddress } from "../sdk/utils/zod.js";
1
+ import { ZodAddress, ZodBigInt, ZodHex } from "../sdk/utils/zod.js";
2
+ import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
2
3
  import { isFilterSet } from "./filters.js";
3
4
  import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
4
- import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
5
- import { apyBreakdownSchema, pointsProgramSchema } from "./opportunities.schema.js";
6
5
  import { delayedReceivedAssetSchema, liquidationPositionSchema } from "./liquidations.schema.js";
6
+ import { apyBreakdownSchema, pointsProgramSchema } from "./opportunities.schema.js";
7
7
  import { z } from "zod/v4";
8
8
  //#region src/model/positions.schema.ts
9
9
  /**
@@ -72,6 +72,15 @@ const poolPositionSchema = z.object({
72
72
  pnl: pnlBreakdownSchema.optional()
73
73
  });
74
74
  /**
75
+ * {@link BorrowRateBreakdown}
76
+ **/
77
+ const borrowRateBreakdownSchema = z.object({
78
+ total: bpsSchema,
79
+ totalOnDebt: bpsSchema,
80
+ base: bpsSchema,
81
+ quotas: z.record(ZodAddress(), bpsSchema)
82
+ });
83
+ /**
75
84
  * {@link StrategyPosition}
76
85
  **/
77
86
  const strategyPositionSchema = z.object({
@@ -87,6 +96,9 @@ const strategyPositionSchema = z.object({
87
96
  totalDebt: tokenAmountSchema,
88
97
  totalValue: tokenAmountSchema,
89
98
  healthFactor: bpsSchema,
99
+ borrowRate: borrowRateBreakdownSchema.optional(),
100
+ timeToLiquidation: ZodBigInt().nullable().optional(),
101
+ liquidationPrice: ZodBigInt().nullable().optional(),
90
102
  pnl: pnlBreakdownSchema.optional(),
91
103
  collaterals: z.array(positionCollateralSchema)
92
104
  });
@@ -161,5 +173,35 @@ const positionKeySchema = z.discriminatedUnion("kind", [z.object({
161
173
  kind: z.literal("strategy"),
162
174
  ...strategyPositionKeySchema.shape
163
175
  })]);
176
+ /**
177
+ * {@link PositionsTotals}
178
+ **/
179
+ const positionsTotalsSchema = z.object({
180
+ currentYield: apyBreakdownSchema.nullable(),
181
+ pnl: pnlBreakdownSchema.nullable(),
182
+ netValueUsd: z.number().nullable(),
183
+ claimableUsd: z.number().nullable()
184
+ });
185
+ /**
186
+ * {@link PositionTransactionKind}
187
+ **/
188
+ const positionTransactionKindSchema = z.union([
189
+ z.literal("open"),
190
+ z.literal("deposit"),
191
+ z.literal("withdraw"),
192
+ z.literal("adjustLeverage"),
193
+ z.literal("addCollateral"),
194
+ z.literal("withdrawCollateral"),
195
+ z.literal("liquidation")
196
+ ]);
197
+ /**
198
+ * {@link PositionTransaction}
199
+ **/
200
+ const positionTransactionSchema = z.object({
201
+ txHash: ZodHex(),
202
+ timestamp: timestampSchema,
203
+ kind: positionTransactionKindSchema,
204
+ assets: z.array(tokenAmountSchema)
205
+ });
164
206
  //#endregion
165
- export { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
207
+ export { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema };
@@ -17,23 +17,34 @@ var AbstractNamespace = class {
17
17
  **/
18
18
  maxOffchainLagSeconds;
19
19
  logger;
20
+ /**
21
+ * The SDK's loading policy, awaited before every on-chain leg: attached, and
22
+ * the touched chains no older than the SDK allows.
23
+ **/
24
+ ensureFresh;
20
25
  #name;
21
26
  #onchain;
22
27
  #offchain;
28
+ /** {@link onchain}, built once: the source's methods behind the loading policy. */
29
+ #onchainView;
23
30
  constructor(name, onchain, offchain, options) {
24
31
  this.#name = name;
25
32
  this.#onchain = onchain;
26
33
  this.#offchain = offchain;
27
34
  this.maxOffchainLagSeconds = options.maxOffchainLagSeconds;
35
+ this.ensureFresh = options.ensureFresh;
28
36
  this.logger = options.logger?.child?.({ name }) ?? options.logger;
37
+ this.#onchainView = onchain && options.ensureFresh ? behindLoadingPolicy(onchain, options.ensureFresh) : onchain;
29
38
  }
30
39
  /**
31
- * The on-chain source namespace on its own. Throws
40
+ * The on-chain source namespace on its own — every read of it attaches and
41
+ * revalidates like a merged read does, so a consumer showing the two sources
42
+ * separately still gets the SDK's loading policy. Throws
32
43
  * {@link SourceUnavailableError} in `offchain` mode.
33
44
  **/
34
45
  get onchain() {
35
- if (!this.#onchain) throw new SourceUnavailableError(this.#name, "onchain");
36
- return this.#onchain;
46
+ if (!this.#onchainView) throw new SourceUnavailableError(this.#name, "onchain");
47
+ return this.#onchainView;
37
48
  }
38
49
  /**
39
50
  * The backend source namespace on its own. Throws
@@ -50,7 +61,10 @@ var AbstractNamespace = class {
50
61
  async merged(action, query) {
51
62
  const onchain = this.#onchain;
52
63
  const offchain = this.#offchain;
53
- const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain, query.fromChain), this.#ask(action, "offchain", offchain, query.fromBackend)]);
64
+ const [fromChain, fromBackend] = await Promise.all([this.#ask(action, "onchain", onchain, async (source) => {
65
+ await this.ensureFresh?.(query.chainIds);
66
+ return query.fromChain(source);
67
+ }), this.#ask(action, "offchain", offchain, query.fromBackend)]);
54
68
  const merged = query.merge(fromChain.response, fromBackend.response);
55
69
  if (merged && !everyChainFailed(merged.meta)) return merged;
56
70
  const sole = onchain && offchain ? void 0 : fromChain.error ?? fromBackend.error;
@@ -71,5 +85,21 @@ var AbstractNamespace = class {
71
85
  }
72
86
  }
73
87
  };
88
+ /**
89
+ * The source's every method, awaiting the loading policy first. The policy is
90
+ * asked for every chain — an escape hatch does not tell which chains a call
91
+ * touches (the merged reads do, and scope it); the object identity differs
92
+ * from the source's, its type does not.
93
+ **/
94
+ function behindLoadingPolicy(source, ensureFresh) {
95
+ return new Proxy(source, { get(target, property, receiver) {
96
+ const value = Reflect.get(target, property, receiver);
97
+ if (typeof value !== "function") return value;
98
+ return async (...args) => {
99
+ await ensureFresh();
100
+ return Reflect.apply(value, target, args);
101
+ };
102
+ } });
103
+ }
74
104
  //#endregion
75
105
  export { AbstractNamespace };