@gearbox-protocol/sdk 14.12.0-next.65 → 14.12.0-next.67

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 (249) hide show
  1. package/dist/cjs/common-utils/index.js +2 -2
  2. package/dist/cjs/common-utils/utils/apy/calculate-safe-borrow-rate.js +3 -3
  3. package/dist/cjs/common-utils/utils/assets-math.js +7 -7
  4. package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +2 -2
  5. package/dist/cjs/common-utils/utils/creditAccount/debt.js +2 -2
  6. package/dist/cjs/common-utils/utils/creditAccount/quota-utils.js +5 -5
  7. package/dist/cjs/common-utils/utils/index.js +2 -2
  8. package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +2 -2
  9. package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +5 -5
  10. package/dist/cjs/common-utils/utils/strategies/strategy-info/calculate-total-points.js +2 -2
  11. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +2 -2
  12. package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +4 -4
  13. package/dist/cjs/dev/index.js +2 -1
  14. package/dist/cjs/dev/kycUtils.js +1 -1
  15. package/dist/cjs/dev/midasUtils.js +104 -0
  16. package/dist/cjs/model/history.js +28 -0
  17. package/dist/cjs/model/history.schema.js +84 -0
  18. package/dist/cjs/model/index.js +64 -0
  19. package/dist/cjs/model/liquidations.js +23 -0
  20. package/dist/cjs/model/liquidations.schema.js +91 -0
  21. package/dist/cjs/model/opportunities.js +55 -0
  22. package/dist/cjs/model/opportunities.schema.js +220 -0
  23. package/dist/cjs/model/package.json +1 -0
  24. package/dist/cjs/model/positions.js +1 -0
  25. package/dist/cjs/model/primitives.js +1 -0
  26. package/dist/cjs/model/primitives.schema.js +85 -0
  27. package/dist/cjs/new-sdk/AbstractNamespace.js +158 -0
  28. package/dist/cjs/new-sdk/GearboxSDK.js +122 -0
  29. package/dist/cjs/new-sdk/index.js +11 -0
  30. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +122 -0
  31. package/dist/cjs/new-sdk/opportunities/index.js +4 -0
  32. package/dist/cjs/new-sdk/opportunities/types.js +1 -0
  33. package/dist/cjs/new-sdk/package.json +1 -0
  34. package/dist/cjs/new-sdk/types.js +22 -0
  35. package/dist/cjs/new-sdk/utils/history.js +1 -0
  36. package/dist/cjs/new-sdk/utils/index.js +2 -0
  37. package/dist/cjs/offchain/GearboxAPI.js +33 -0
  38. package/dist/cjs/offchain/index.js +8 -0
  39. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +97 -0
  40. package/dist/cjs/offchain/opportunities/index.js +4 -0
  41. package/dist/cjs/offchain/package.json +1 -0
  42. package/dist/cjs/offchain/types.js +1 -0
  43. package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -5
  44. package/dist/cjs/rewards/rewards/api.js +2 -2
  45. package/dist/cjs/rewards/rewards/extra-apy.js +2 -2
  46. package/dist/cjs/sdk/MultichainSDK.js +18 -2
  47. package/dist/cjs/sdk/OnchainSDK.js +8 -1
  48. package/dist/cjs/sdk/accounts/index.js +2 -0
  49. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +150 -106
  50. package/dist/cjs/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  51. package/dist/cjs/sdk/accounts/liquidations/constants.js +13 -0
  52. package/dist/cjs/sdk/accounts/liquidations/index.js +2 -0
  53. package/dist/cjs/sdk/base/MultichainConstruct.js +80 -0
  54. package/dist/cjs/sdk/base/TokensMeta.js +51 -0
  55. package/dist/cjs/sdk/base/index.js +2 -0
  56. package/dist/cjs/sdk/chain/chains.js +76 -0
  57. package/dist/cjs/sdk/chain/index.js +4 -0
  58. package/dist/cjs/sdk/core/errors.js +13 -0
  59. package/dist/cjs/sdk/core/index.js +2 -1
  60. package/dist/cjs/sdk/index.js +25 -1
  61. package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
  62. package/dist/cjs/sdk/market/MarketSuite.js +163 -0
  63. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  64. package/dist/cjs/sdk/market/credit/CreditSuite.js +102 -0
  65. package/dist/cjs/sdk/market/math.js +104 -0
  66. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  67. package/dist/cjs/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  68. package/dist/cjs/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  69. package/dist/cjs/sdk/market/pool/PoolSuite.js +28 -0
  70. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +27 -0
  71. package/dist/cjs/sdk/market/pool/math.js +44 -0
  72. package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  73. package/dist/cjs/sdk/opportunities/MultichainOpportunitiesService.js +60 -0
  74. package/dist/cjs/sdk/opportunities/OpportunitiesService.js +103 -0
  75. package/dist/cjs/sdk/opportunities/index.js +12 -0
  76. package/dist/cjs/sdk/types/multichain.js +1 -0
  77. package/dist/cjs/{common-utils → sdk}/utils/bigint-math.js +11 -11
  78. package/dist/cjs/sdk/utils/index.js +3 -0
  79. package/dist/cjs/sdk/utils/zod.js +12 -0
  80. package/dist/esm/common-utils/index.js +1 -1
  81. package/dist/esm/common-utils/utils/apy/calculate-safe-borrow-rate.js +1 -1
  82. package/dist/esm/common-utils/utils/assets-math.js +1 -1
  83. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +1 -1
  84. package/dist/esm/common-utils/utils/creditAccount/debt.js +1 -1
  85. package/dist/esm/common-utils/utils/creditAccount/quota-utils.js +1 -1
  86. package/dist/esm/common-utils/utils/index.js +1 -1
  87. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +1 -1
  88. package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-strategy-debt.js +1 -1
  89. package/dist/esm/common-utils/utils/strategies/strategy-info/calculate-total-points.js +1 -1
  90. package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +1 -1
  91. package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +1 -1
  92. package/dist/esm/dev/AccountOpener.js +1 -1
  93. package/dist/esm/dev/index.js +3 -3
  94. package/dist/esm/dev/kycUtils.js +1 -1
  95. package/dist/esm/dev/midasUtils.js +105 -2
  96. package/dist/esm/dev/withdrawalUtils.js +1 -1
  97. package/dist/esm/model/history.js +26 -0
  98. package/dist/esm/model/history.schema.js +76 -0
  99. package/dist/esm/model/index.js +9 -0
  100. package/dist/esm/model/liquidations.js +22 -0
  101. package/dist/esm/model/liquidations.schema.js +83 -0
  102. package/dist/esm/model/opportunities.js +51 -0
  103. package/dist/esm/model/opportunities.schema.js +198 -0
  104. package/dist/esm/model/package.json +1 -0
  105. package/dist/esm/model/positions.js +1 -0
  106. package/dist/esm/model/primitives.js +1 -0
  107. package/dist/esm/model/primitives.schema.js +75 -0
  108. package/dist/esm/new-sdk/AbstractNamespace.js +157 -0
  109. package/dist/esm/new-sdk/GearboxSDK.js +121 -0
  110. package/dist/esm/new-sdk/index.js +7 -0
  111. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +121 -0
  112. package/dist/esm/new-sdk/opportunities/index.js +3 -0
  113. package/dist/esm/new-sdk/opportunities/types.js +1 -0
  114. package/dist/esm/new-sdk/package.json +1 -0
  115. package/dist/esm/new-sdk/types.js +21 -0
  116. package/dist/esm/new-sdk/utils/history.js +1 -0
  117. package/dist/esm/new-sdk/utils/index.js +2 -0
  118. package/dist/esm/offchain/GearboxAPI.js +32 -0
  119. package/dist/esm/offchain/index.js +5 -0
  120. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +95 -0
  121. package/dist/esm/offchain/opportunities/index.js +2 -0
  122. package/dist/esm/offchain/package.json +1 -0
  123. package/dist/esm/offchain/types.js +1 -0
  124. package/dist/esm/preview/preview/buildDelayedPreview.js +1 -1
  125. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  126. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  127. package/dist/esm/rewards/rewards/api.js +1 -1
  128. package/dist/esm/rewards/rewards/extra-apy.js +1 -1
  129. package/dist/esm/sdk/MultichainSDK.js +18 -2
  130. package/dist/esm/sdk/OnchainSDK.js +8 -1
  131. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  132. package/dist/esm/sdk/accounts/index.js +2 -2
  133. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +153 -109
  134. package/dist/esm/sdk/accounts/liquidations/MultichainLiquidationsService.js +32 -38
  135. package/dist/esm/sdk/accounts/liquidations/constants.js +12 -1
  136. package/dist/esm/sdk/accounts/liquidations/index.js +2 -2
  137. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  138. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  139. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  140. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  141. package/dist/esm/sdk/base/MultichainConstruct.js +79 -0
  142. package/dist/esm/sdk/base/TokensMeta.js +53 -2
  143. package/dist/esm/sdk/base/index.js +2 -1
  144. package/dist/esm/sdk/chain/chains.js +74 -2
  145. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  146. package/dist/esm/sdk/chain/index.js +2 -2
  147. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  148. package/dist/esm/sdk/core/errors.js +13 -1
  149. package/dist/esm/sdk/core/index.js +2 -2
  150. package/dist/esm/sdk/index.js +11 -5
  151. package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
  152. package/dist/esm/sdk/market/MarketSuite.js +163 -0
  153. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  154. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +26 -0
  155. package/dist/esm/sdk/market/credit/CreditSuite.js +102 -0
  156. package/dist/esm/sdk/market/math.js +98 -0
  157. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +52 -0
  158. package/dist/esm/sdk/market/pool/LinearInterestRateModelContract.js +30 -0
  159. package/dist/esm/sdk/market/pool/PoolQuotaKeeperV310Contract.js +26 -0
  160. package/dist/esm/sdk/market/pool/PoolSuite.js +28 -0
  161. package/dist/esm/sdk/market/pool/PoolV310Contract.js +28 -1
  162. package/dist/esm/sdk/market/pool/math.js +41 -0
  163. package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +17 -0
  164. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  165. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  166. package/dist/esm/sdk/opportunities/MultichainOpportunitiesService.js +59 -0
  167. package/dist/esm/sdk/opportunities/OpportunitiesService.js +102 -0
  168. package/dist/esm/sdk/opportunities/index.js +4 -0
  169. package/dist/esm/sdk/pools/PoolService.js +1 -1
  170. package/dist/esm/sdk/types/multichain.js +1 -0
  171. package/dist/esm/{common-utils → sdk}/utils/bigint-math.js +11 -11
  172. package/dist/esm/sdk/utils/index.js +3 -2
  173. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  174. package/dist/esm/sdk/utils/zod.js +13 -2
  175. package/dist/types/common-utils/index.d.ts +1 -1
  176. package/dist/types/common-utils/utils/index.d.ts +1 -1
  177. package/dist/types/dev/index.d.ts +2 -2
  178. package/dist/types/dev/midasUtils.d.ts +31 -2
  179. package/dist/types/model/history.d.ts +105 -0
  180. package/dist/types/model/history.schema.d.ts +66 -0
  181. package/dist/types/model/index.d.ts +9 -0
  182. package/dist/types/model/liquidations.d.ts +230 -0
  183. package/dist/types/model/liquidations.schema.d.ts +292 -0
  184. package/dist/types/model/opportunities.d.ts +543 -0
  185. package/dist/types/model/opportunities.schema.d.ts +1066 -0
  186. package/dist/types/model/positions.d.ts +11 -0
  187. package/dist/types/model/primitives.d.ts +193 -0
  188. package/dist/types/model/primitives.schema.d.ts +81 -0
  189. package/dist/types/new-sdk/AbstractNamespace.d.ts +119 -0
  190. package/dist/types/new-sdk/GearboxSDK.d.ts +78 -0
  191. package/dist/types/new-sdk/index.d.ts +9 -0
  192. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +69 -0
  193. package/dist/types/new-sdk/opportunities/index.d.ts +3 -0
  194. package/dist/types/new-sdk/opportunities/types.d.ts +66 -0
  195. package/dist/types/new-sdk/types.d.ts +149 -0
  196. package/dist/types/new-sdk/utils/history.d.ts +44 -0
  197. package/dist/types/new-sdk/utils/index.d.ts +2 -0
  198. package/dist/types/offchain/GearboxAPI.d.ts +31 -0
  199. package/dist/types/offchain/index.d.ts +5 -0
  200. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +69 -0
  201. package/dist/types/offchain/opportunities/index.d.ts +2 -0
  202. package/dist/types/offchain/types.d.ts +50 -0
  203. package/dist/types/sdk/MultichainSDK.d.ts +15 -2
  204. package/dist/types/sdk/OnchainSDK.d.ts +9 -3
  205. package/dist/types/sdk/accounts/index.d.ts +3 -3
  206. package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +24 -16
  207. package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +26 -20
  208. package/dist/types/sdk/accounts/liquidations/constants.d.ts +12 -1
  209. package/dist/types/sdk/accounts/liquidations/index.d.ts +3 -3
  210. package/dist/types/sdk/accounts/liquidations/types.d.ts +34 -309
  211. package/dist/types/sdk/base/MultichainConstruct.d.ts +57 -0
  212. package/dist/types/sdk/base/TokensMeta.d.ts +26 -0
  213. package/dist/types/sdk/base/index.d.ts +2 -1
  214. package/dist/types/sdk/chain/chains.d.ts +68 -1
  215. package/dist/types/sdk/chain/index.d.ts +2 -2
  216. package/dist/types/sdk/core/errors.d.ts +10 -1
  217. package/dist/types/sdk/core/index.d.ts +2 -2
  218. package/dist/types/sdk/index.d.ts +15 -8
  219. package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
  220. package/dist/types/sdk/market/MarketSuite.d.ts +109 -1
  221. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +14 -0
  222. package/dist/types/sdk/market/credit/CreditSuite.d.ts +47 -0
  223. package/dist/types/sdk/market/credit/types.d.ts +22 -0
  224. package/dist/types/sdk/market/index.d.ts +2 -2
  225. package/dist/types/sdk/market/math.d.ts +74 -0
  226. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +23 -0
  227. package/dist/types/sdk/market/oracle/types.d.ts +46 -0
  228. package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +12 -0
  229. package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +22 -1
  230. package/dist/types/sdk/market/pool/PoolSuite.d.ts +23 -0
  231. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +18 -0
  232. package/dist/types/sdk/market/pool/math.d.ts +57 -0
  233. package/dist/types/sdk/market/pool/types.d.ts +23 -0
  234. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +6 -0
  235. package/dist/types/sdk/market/pricefeeds/types.d.ts +10 -0
  236. package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +40 -0
  237. package/dist/types/sdk/opportunities/OpportunitiesService.d.ts +47 -0
  238. package/dist/types/sdk/opportunities/index.d.ts +4 -0
  239. package/dist/types/sdk/types/index.d.ts +2 -1
  240. package/dist/types/sdk/types/multichain.d.ts +65 -0
  241. package/dist/types/sdk/types/state.d.ts +1 -1
  242. package/dist/types/sdk/types/transactions.d.ts +3 -0
  243. package/dist/types/{common-utils → sdk}/utils/bigint-math.d.ts +7 -11
  244. package/dist/types/sdk/utils/index.d.ts +3 -2
  245. package/dist/types/sdk/utils/zod.d.ts +6 -2
  246. package/package.json +16 -1
  247. package/dist/cjs/sdk/accounts/liquidations/helpers.js +0 -201
  248. package/dist/esm/sdk/accounts/liquidations/helpers.js +0 -192
  249. package/dist/types/sdk/accounts/liquidations/helpers.d.ts +0 -140
@@ -0,0 +1,158 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_chain_chains = require("../sdk/chain/chains.js");
3
+ const require_new_sdk_types = require("./types.js");
4
+ //#region src/new-sdk/AbstractNamespace.ts
5
+ /**
6
+ * Shared machinery of every {@link GearboxSDK} namespace.
7
+ *
8
+ * A namespace is a stateless router: it asks the sources its mode allows, in
9
+ * parallel, merges what came back and reports what did not. This class owns
10
+ * that routing — per-chain failure capture, backend degradation, the response
11
+ * envelope and the all-sources-failed rule — so a namespace holds nothing but
12
+ * its reads and its merge policy.
13
+ *
14
+ * The sources are whatever it was handed, and their readiness is their owner's
15
+ * business: a source that is not ready to answer fails the read it was given,
16
+ * and that failure is reported like any other.
17
+ *
18
+ * All protocol knowledge lives in the sources: `MultichainSDK` for the chain,
19
+ * `GearboxAPI` for the backend. None of it is repeated here or in a subclass.
20
+ *
21
+ * @typeParam ListRow - Row type of the namespace's list read.
22
+ **/
23
+ var AbstractNamespace = class {
24
+ logger;
25
+ #onchain;
26
+ #offchain;
27
+ constructor(name, onchain, offchain, logger) {
28
+ this.#onchain = onchain;
29
+ this.#offchain = offchain;
30
+ this.logger = logger?.child?.({ name }) ?? logger;
31
+ }
32
+ /**
33
+ * Asks both sources in parallel and combines whatever answered.
34
+ *
35
+ * The action name is only used in diagnostics and in the error raised when
36
+ * every source the read had failed.
37
+ **/
38
+ async read(action, fromChain, fromBackend, combine) {
39
+ const [onchain, offchain] = await Promise.all([this.fromChain(fromChain), this.fromBackend(fromBackend)]);
40
+ const meta = toMeta(onchain, offchain);
41
+ this.assertAnySourceSucceeded(action, meta);
42
+ return {
43
+ result: combine(onchain.value, offchain.value),
44
+ meta
45
+ };
46
+ }
47
+ /**
48
+ * Reads the namespace's list from both sources, unioned by
49
+ * {@link AbstractNamespace.mergeList}.
50
+ **/
51
+ async readList(action, fromChain, fromBackend) {
52
+ return this.read(action, fromChain, fromBackend, (onchain, offchain) => this.mergeList(onchain ?? [], offchain ?? []));
53
+ }
54
+ /**
55
+ * Reads one row from both sources and merges them under
56
+ * {@link AbstractNamespace.mergeOne}. The key names the chain, so the
57
+ * on-chain leg queries exactly one.
58
+ **/
59
+ async readOne(action, chainId, fromChain, fromBackend) {
60
+ return this.read(action, async (sdk) => {
61
+ const network = this.networkOf(chainId);
62
+ if (!network) return { chains: [] };
63
+ return this.onOneChain(action, network, () => fromChain(sdk));
64
+ }, fromBackend, (onchain, offchain) => {
65
+ if (onchain && offchain) return this.mergeOne(onchain, offchain);
66
+ return onchain ?? offchain;
67
+ });
68
+ }
69
+ /**
70
+ * Reads something only the backend can answer.
71
+ *
72
+ * The fallback stands in for a backend that answered with nothing, which is
73
+ * a different thing from a backend that failed and was dropped.
74
+ **/
75
+ async readOffchain(action, fromBackend, fallback) {
76
+ const offchain = await this.fromBackend(fromBackend);
77
+ const meta = toMeta({ chains: [] }, offchain);
78
+ this.assertAnySourceSucceeded(action, meta);
79
+ return {
80
+ result: offchain.value ?? fallback,
81
+ meta
82
+ };
83
+ }
84
+ /**
85
+ * Runs a read against the chain, or reports the chain as absent when the
86
+ * namespace has no on-chain source at all.
87
+ **/
88
+ async fromChain(run) {
89
+ return this.#onchain ? run(this.#onchain) : { chains: [] };
90
+ }
91
+ /**
92
+ * Runs a read against the backend, turning any rejection into metadata so
93
+ * that a dead backend degrades a `both`-mode read instead of failing it.
94
+ **/
95
+ async fromBackend(run) {
96
+ if (!this.#offchain) return {};
97
+ try {
98
+ const { result, meta } = await run(this.#offchain);
99
+ return {
100
+ value: meta.status === "success" ? result : void 0,
101
+ status: meta
102
+ };
103
+ } catch (error) {
104
+ this.logger?.warn(error, "offchain read failed");
105
+ return { status: {
106
+ status: "error",
107
+ error
108
+ } };
109
+ }
110
+ }
111
+ /**
112
+ * Runs a read against one chain, turning a rejection into that chain's
113
+ * metadata entry.
114
+ **/
115
+ async onOneChain(action, network, run) {
116
+ try {
117
+ return {
118
+ value: await run(),
119
+ chains: [{
120
+ network,
121
+ status: "success"
122
+ }]
123
+ };
124
+ } catch (error) {
125
+ this.logger?.warn(error, `failed to ${action} on ${network}`);
126
+ return { chains: [{
127
+ network,
128
+ status: "error",
129
+ error
130
+ }] };
131
+ }
132
+ }
133
+ /**
134
+ * A read that reached at least one source returns what it has; a read where
135
+ * every source it had failed throws, because an empty result would otherwise
136
+ * be indistinguishable from "there is nothing here".
137
+ **/
138
+ assertAnySourceSucceeded(action, meta) {
139
+ const asked = meta.chains.length > 0 || meta.offchain !== void 0;
140
+ const answered = meta.chains.some((c) => c.status === "success") || meta.offchain?.status === "success";
141
+ if (asked && !answered) throw new require_new_sdk_types.AllSourcesFailedError(action, meta);
142
+ }
143
+ networkOf(chainId) {
144
+ try {
145
+ return require_sdk_chain_chains.getNetworkType(chainId);
146
+ } catch {
147
+ this.logger?.debug(`chain ${chainId} is not a Gearbox network, skipping the onchain source`);
148
+ return;
149
+ }
150
+ }
151
+ };
152
+ function toMeta(onchain, offchain) {
153
+ const meta = { chains: onchain.chains };
154
+ if (offchain.status) meta.offchain = offchain.status;
155
+ return meta;
156
+ }
157
+ //#endregion
158
+ exports.AbstractNamespace = AbstractNamespace;
@@ -0,0 +1,122 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_MultichainSDK = require("../sdk/MultichainSDK.js");
3
+ require("../sdk/index.js");
4
+ const require_offchain_GearboxAPI = require("../offchain/GearboxAPI.js");
5
+ require("../offchain/index.js");
6
+ const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
7
+ require("./opportunities/index.js");
8
+ //#region src/new-sdk/GearboxSDK.ts
9
+ /**
10
+ * Combined entry point over both sources of Gearbox data: the chain and the
11
+ * Gearbox backend.
12
+ *
13
+ * The {@link Mode} is fixed at construction and decides which methods exist,
14
+ * not what they return, so a screen written against `both` cannot silently
15
+ * degrade to a subset when someone reconfigures the SDK:
16
+ *
17
+ * ```ts
18
+ * const sdk = new GearboxSDK({
19
+ * mode: "both",
20
+ * networks: ["Mainnet"],
21
+ * onchain: { chains: { Mainnet: { rpcURLs } } },
22
+ * offchain: { baseUrl: "https://api.gearbox.fi" },
23
+ * });
24
+ * await sdk.attach();
25
+ *
26
+ * const { result, meta } = await sdk.opportunities.list({ kind: "strategy" });
27
+ * ```
28
+ *
29
+ * Every read answers with `{ result, meta }`: `meta` says which chains and
30
+ * which backend answered, because a partial answer is the normal case for a
31
+ * multi-chain read.
32
+ *
33
+ * @typeParam M - Mode the instance was built in.
34
+ **/
35
+ var GearboxSDK = class {
36
+ /**
37
+ * Sources this instance reads from.
38
+ **/
39
+ mode;
40
+ /**
41
+ * Chains this instance covers. Authoritative even when an injected on-chain
42
+ * SDK covers a different set.
43
+ **/
44
+ networks;
45
+ /**
46
+ * Namespace for pool and strategy opportunities.
47
+ **/
48
+ opportunities;
49
+ #attachOptions;
50
+ #onchain;
51
+ #offchain;
52
+ /**
53
+ * Whether this instance built the on-chain SDK, and therefore attaches it.
54
+ **/
55
+ #ownsOnchain = false;
56
+ #attached;
57
+ constructor(options) {
58
+ const { mode, networks, onchain, offchain, attach, logger } = options;
59
+ this.mode = mode;
60
+ this.networks = [...networks];
61
+ this.#attachOptions = attach;
62
+ const needsOnchain = mode === "onchain" || mode === "both";
63
+ const needsOffchain = mode === "offchain" || mode === "both";
64
+ if (needsOnchain && !onchain) throw new Error(`GearboxSDK in ${mode} mode needs an onchain source`);
65
+ if (needsOffchain && !offchain) throw new Error(`GearboxSDK in ${mode} mode needs an offchain source`);
66
+ if (!needsOnchain && onchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the onchain source it was given`);
67
+ if (!needsOffchain && offchain) logger?.warn(`GearboxSDK in ${mode} mode ignores the offchain source it was given`);
68
+ if (needsOnchain && onchain) if (onchain instanceof require_sdk_MultichainSDK.MultichainSDK) this.#onchain = onchain;
69
+ else {
70
+ this.#onchain = new require_sdk_MultichainSDK.MultichainSDK({
71
+ logger,
72
+ ...onchain
73
+ });
74
+ this.#ownsOnchain = true;
75
+ }
76
+ if (needsOffchain && offchain) this.#offchain = offchain instanceof require_offchain_GearboxAPI.GearboxAPI ? offchain : new require_offchain_GearboxAPI.GearboxAPI({
77
+ logger,
78
+ ...offchain
79
+ });
80
+ this.#attached = !this.#ownsOnchain;
81
+ this.opportunities = new require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace(this.#onchain, this.#offchain, logger);
82
+ }
83
+ /**
84
+ * Attaches the on-chain SDK when this instance owns one.
85
+ *
86
+ * Reads issued before this resolves still reach the chain and fail there, so
87
+ * in `both` mode they are served from the backend alone and report the chain
88
+ * as failed in their meta, rather than blocking.
89
+ *
90
+ * A no-op in `offchain` mode and when an already-attached SDK was injected.
91
+ **/
92
+ async attach() {
93
+ if (this.#attached || !this.#ownsOnchain || !this.#onchain) return;
94
+ await this.#onchain.attach(this.#attachOptions);
95
+ this.#attached = true;
96
+ }
97
+ /**
98
+ * Whether the on-chain source is ready to be read from. Always `true` in
99
+ * `offchain` mode, where there is nothing to wait for.
100
+ **/
101
+ get attached() {
102
+ return this.mode === "offchain" ? true : this.#attached;
103
+ }
104
+ /**
105
+ * The underlying on-chain SDK, for everything this facade does not expose
106
+ * yet: markets, credit accounts, transaction building.
107
+ *
108
+ * `undefined` in `offchain` mode. Otherwise it exists from construction on,
109
+ * but only answers reads once {@link attach} has resolved.
110
+ **/
111
+ get onchain() {
112
+ return this.#onchain;
113
+ }
114
+ /**
115
+ * The underlying backend client. `undefined` in `onchain` mode.
116
+ **/
117
+ get offchain() {
118
+ return this.#offchain;
119
+ }
120
+ };
121
+ //#endregion
122
+ exports.GearboxSDK = GearboxSDK;
@@ -0,0 +1,11 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_new_sdk_types = require("./types.js");
3
+ const require_new_sdk_AbstractNamespace = require("./AbstractNamespace.js");
4
+ const require_new_sdk_opportunities_OpportunitiesNamespace = require("./opportunities/OpportunitiesNamespace.js");
5
+ require("./opportunities/index.js");
6
+ const require_new_sdk_GearboxSDK = require("./GearboxSDK.js");
7
+ require("./utils/index.js");
8
+ exports.AbstractNamespace = require_new_sdk_AbstractNamespace.AbstractNamespace;
9
+ exports.AllSourcesFailedError = require_new_sdk_types.AllSourcesFailedError;
10
+ exports.GearboxSDK = require_new_sdk_GearboxSDK.GearboxSDK;
11
+ exports.OpportunitiesNamespace = require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace;
@@ -0,0 +1,122 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_opportunities = require("../../model/opportunities.js");
3
+ require("../../model/index.js");
4
+ const require_new_sdk_AbstractNamespace = require("../AbstractNamespace.js");
5
+ //#region src/new-sdk/opportunities/OpportunitiesNamespace.ts
6
+ /**
7
+ * Fields the backend owns even when the chain also fills them.
8
+ *
9
+ * Empty of on-chain conflicts today — every yield group here is off-chain only,
10
+ * so onchain-first would already yield the backend's value. It is written out
11
+ * anyway so that adding an on-chain estimate of one of them is a deliberate
12
+ * change to this list rather than a silent regression.
13
+ **/
14
+ const OFFCHAIN_OWNED_FIELDS = /* @__PURE__ */ new Set(["supplyApy", "collateralApy"]);
15
+ /**
16
+ * The `opportunities` namespace of the combined SDK.
17
+ *
18
+ * A stateless router over the two sources, see {@link AbstractNamespace} for
19
+ * the routing itself. What is specific to opportunities is the reads below and
20
+ * the merge policy at the bottom of the class.
21
+ *
22
+ * The class implements the methods of every mode; {@link GearboxSDK} exposes it
23
+ * as its mode's slice of {@link OpportunitiesByMode}, so calling a method the
24
+ * mode does not have is a compile error rather than a runtime one.
25
+ **/
26
+ var OpportunitiesNamespace = class extends require_new_sdk_AbstractNamespace.AbstractNamespace {
27
+ constructor(onchain, offchain, logger) {
28
+ super("Opportunities", onchain, offchain, logger);
29
+ }
30
+ /**
31
+ * {@inheritDoc OpportunitiesBase.list}
32
+ **/
33
+ async list(filter) {
34
+ return this.readList("list opportunities", async (sdk) => {
35
+ const { result, meta } = await sdk.opportunities.list(filter);
36
+ return {
37
+ value: result,
38
+ chains: meta
39
+ };
40
+ }, (api) => api.opportunities.list(filter));
41
+ }
42
+ /**
43
+ * {@inheritDoc OpportunitiesBase.getPool}
44
+ **/
45
+ async getPool(key) {
46
+ return this.readOne("get pool opportunity", key.chainId, (sdk) => sdk.opportunities.getPool(key), (api) => api.opportunities.getPool(key));
47
+ }
48
+ /**
49
+ * {@inheritDoc OpportunitiesBase.getStrategy}
50
+ **/
51
+ async getStrategy(key) {
52
+ return this.readOne("get strategy opportunity", key.chainId, (sdk) => sdk.opportunities.getStrategy(key), (api) => api.opportunities.getStrategy(key));
53
+ }
54
+ history(key) {
55
+ return { chart: (metric, range) => this.#chart(key, metric, range) };
56
+ }
57
+ /**
58
+ * Reads one chart of one opportunity from the backend.
59
+ *
60
+ * The metric a caller may name is gated by the reader's type, so the kind of
61
+ * the key is not re-checked here.
62
+ **/
63
+ async #chart(key, metric, range) {
64
+ const { result, meta } = await this.readOffchain(`get ${metric} history`, (api) => api.opportunities.getHistory({
65
+ opportunity: key,
66
+ range,
67
+ metric
68
+ }), {
69
+ metric,
70
+ points: [],
71
+ metadata: {}
72
+ });
73
+ return {
74
+ data: result.points,
75
+ metadata: {
76
+ ...result.metadata,
77
+ source: meta
78
+ }
79
+ };
80
+ }
81
+ /**
82
+ * Merges the two versions of one opportunity.
83
+ *
84
+ * The chain wins every field it fills; the backend fills the rest and owns
85
+ * {@link OFFCHAIN_OWNED_FIELDS}.
86
+ *
87
+ * The rule is onchain-first, field-wise, and never deeper than one level: a
88
+ * group like `totalSupply` or `supplyApy` is taken whole from one source, so
89
+ * a row never mixes an on-chain token amount with a backend dollar value
90
+ * derived from a different block.
91
+ **/
92
+ mergeOne(onchain, offchain) {
93
+ const merged = { ...onchain };
94
+ for (const [field, value] of Object.entries(offchain)) {
95
+ if (value === void 0) continue;
96
+ if (OFFCHAIN_OWNED_FIELDS.has(field) || merged[field] === void 0) merged[field] = value;
97
+ }
98
+ return merged;
99
+ }
100
+ /**
101
+ * Unions the two lists by canonical opportunity id.
102
+ *
103
+ * Rows present in both are merged by {@link OpportunitiesNamespace.mergeOne}.
104
+ * Rows only the backend knows are appended: a chain the SDK does not cover,
105
+ * or a market it has not loaded, is a reason to show more rather than fewer
106
+ * opportunities.
107
+ **/
108
+ mergeList(onchain, offchain) {
109
+ const byId = /* @__PURE__ */ new Map();
110
+ for (const row of onchain) byId.set(require_model_opportunities.opportunityId(row), row);
111
+ const extra = [];
112
+ for (const row of offchain) {
113
+ const id = require_model_opportunities.opportunityId(row);
114
+ const existing = byId.get(id);
115
+ if (existing) byId.set(id, this.mergeOne(existing, row));
116
+ else extra.push(row);
117
+ }
118
+ return [...byId.values(), ...extra];
119
+ }
120
+ };
121
+ //#endregion
122
+ exports.OpportunitiesNamespace = OpportunitiesNamespace;
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_new_sdk_opportunities_OpportunitiesNamespace = require("./OpportunitiesNamespace.js");
3
+ require("./types.js");
4
+ exports.OpportunitiesNamespace = require_new_sdk_opportunities_OpportunitiesNamespace.OpportunitiesNamespace;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
@@ -0,0 +1,22 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/new-sdk/types.ts
3
+ /**
4
+ * Thrown when a read had sources to ask and none of them answered.
5
+ *
6
+ * A read that partially succeeded never throws: it returns what it has and
7
+ * reports the rest in {@link SourceMeta}.
8
+ **/
9
+ var AllSourcesFailedError = class extends Error {
10
+ /**
11
+ * Outcome of every source the failed read asked.
12
+ **/
13
+ meta;
14
+ constructor(action, meta) {
15
+ const reasons = [...meta.chains.filter((c) => c.status === "error").map((c) => `${c.network}: ${c.error}`), ...meta.offchain?.status === "error" ? [`offchain: ${meta.offchain.error}`] : []];
16
+ super(`cannot ${action}, every source failed (${reasons.join("; ")})`);
17
+ this.name = "AllSourcesFailedError";
18
+ this.meta = meta;
19
+ }
20
+ };
21
+ //#endregion
22
+ exports.AllSourcesFailedError = AllSourcesFailedError;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./history.js");
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
3
+ require("./opportunities/index.js");
4
+ //#region src/offchain/GearboxAPI.ts
5
+ /**
6
+ * Client for the Gearbox backend, the off-chain source of the read model.
7
+ *
8
+ * It mirrors the namespace layout of the combined `GearboxSDK`, so the same
9
+ * call reads the same way against either source:
10
+ *
11
+ * ```ts
12
+ * const api = new GearboxAPI({ baseUrl: "https://api.gearbox.fi" });
13
+ * const { result } = await api.opportunities.list({ kind: "strategy" });
14
+ * ```
15
+ *
16
+ * The backend imports the read model from this package and its endpoints
17
+ * return those types directly, so there is no wire DTO layer here — only
18
+ * transport and schema validation.
19
+ *
20
+ * The transport is not implemented yet; see {@link OffchainOpportunities} for
21
+ * what each stubbed endpoint currently answers.
22
+ **/
23
+ var GearboxAPI = class {
24
+ /**
25
+ * Namespace for pool and strategy opportunities.
26
+ **/
27
+ opportunities;
28
+ constructor(options) {
29
+ this.opportunities = new require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities(options);
30
+ }
31
+ };
32
+ //#endregion
33
+ exports.GearboxAPI = GearboxAPI;
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
3
+ require("./opportunities/index.js");
4
+ const require_offchain_GearboxAPI = require("./GearboxAPI.js");
5
+ require("./types.js");
6
+ exports.GearboxAPI = require_offchain_GearboxAPI.GearboxAPI;
7
+ exports.OffchainNotImplementedError = require_offchain_opportunities_OffchainOpportunities.OffchainNotImplementedError;
8
+ exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
@@ -0,0 +1,97 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/offchain/opportunities/OffchainOpportunities.ts
3
+ /**
4
+ * Thrown by the endpoints that have no stub answer, so that a caller in
5
+ * `offchain` mode fails loudly instead of reading an empty detail page as a
6
+ * missing opportunity.
7
+ **/
8
+ var OffchainNotImplementedError = class extends Error {
9
+ constructor(endpoint) {
10
+ super(`GearboxAPI: ${endpoint} is not implemented yet`);
11
+ this.name = "OffchainNotImplementedError";
12
+ }
13
+ };
14
+ /**
15
+ * Backend counterpart of the `opportunities` namespace.
16
+ *
17
+ * This is a stub: the HTTP client is not written yet, so list reads answer with
18
+ * an empty list and detail reads throw. Every signature is already the final
19
+ * one, because the backend returns the read model types directly — there is no
20
+ * wire DTO and no mapper between the two.
21
+ *
22
+ * When the transport lands, each method will validate the response against the
23
+ * matching schema from `src/model` before returning it. A validation failure is
24
+ * a version-skew error and is handled exactly like a transport error: the
25
+ * combined SDK drops the backend's contribution in `both` mode and rethrows in
26
+ * `offchain` mode.
27
+ **/
28
+ var OffchainOpportunities = class {
29
+ #baseUrl;
30
+ #logger;
31
+ constructor(options) {
32
+ this.#baseUrl = options?.baseUrl;
33
+ this.#logger = options?.logger?.child?.({ name: "OffchainOpportunities" });
34
+ }
35
+ /**
36
+ * Base URL the client will call once the transport is implemented.
37
+ **/
38
+ get baseUrl() {
39
+ return this.#baseUrl;
40
+ }
41
+ /**
42
+ * All opportunities the backend knows about, optionally narrowed by
43
+ * {@link OpportunityFilter}.
44
+ *
45
+ * @returns An empty list until the backend client is implemented.
46
+ **/
47
+ async list(filter) {
48
+ this.#logger?.debug({ filter }, "offchain opportunities list is not implemented, serving empty list");
49
+ return {
50
+ result: [],
51
+ meta: { status: "success" }
52
+ };
53
+ }
54
+ /**
55
+ * Detailed view of one pool opportunity.
56
+ *
57
+ * @throws {@link OffchainNotImplementedError} until the backend client is
58
+ * implemented.
59
+ **/
60
+ async getPool(key) {
61
+ throw new OffchainNotImplementedError("opportunities.getPool");
62
+ }
63
+ /**
64
+ * Detailed view of one strategy opportunity.
65
+ *
66
+ * @throws {@link OffchainNotImplementedError} until the backend client is
67
+ * implemented.
68
+ **/
69
+ async getStrategy(key) {
70
+ throw new OffchainNotImplementedError("opportunities.getStrategy");
71
+ }
72
+ /**
73
+ * One historical series of one opportunity. History exists only here:
74
+ * rebuilding it from the chain would mean an archive read per point.
75
+ *
76
+ * The requested metric types the response, so a caller asking for one metric
77
+ * does not have to narrow the union back down. When the transport lands,
78
+ * validation is what upholds it: a response carrying a different metric than
79
+ * the one asked for is a version-skew error like any other.
80
+ *
81
+ * @returns An empty series until the backend client is implemented.
82
+ **/
83
+ async getHistory(query) {
84
+ this.#logger?.debug({ query }, "offchain opportunities history is not implemented, serving empty series");
85
+ return {
86
+ result: {
87
+ metric: query.metric,
88
+ points: [],
89
+ metadata: {}
90
+ },
91
+ meta: { status: "success" }
92
+ };
93
+ }
94
+ };
95
+ //#endregion
96
+ exports.OffchainNotImplementedError = OffchainNotImplementedError;
97
+ exports.OffchainOpportunities = OffchainOpportunities;
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_offchain_opportunities_OffchainOpportunities = require("./OffchainOpportunities.js");
3
+ exports.OffchainNotImplementedError = require_offchain_opportunities_OffchainOpportunities.OffchainNotImplementedError;
4
+ exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_AssetsMap = require("../../sdk/utils/AssetsMap.js");
3
+ const require_sdk_utils_bigint_math = require("../../sdk/utils/bigint-math.js");
3
4
  require("../../sdk/index.js");
4
- const require_common_utils_utils_bigint_math = require("../../common-utils/utils/bigint-math.js");
5
5
  require("../../common-utils/index.js");
6
6
  const require_preview_preview_types = require("./types.js");
7
7
  let viem = require("viem");
@@ -108,7 +108,7 @@ function applyWithdrawCollateral(post, request, intent, converter, collateralWit
108
108
  const { withdrawToken, withdrawAmount, debtRepaid } = intent;
109
109
  const { claimToken } = request;
110
110
  const sameToken = (0, viem.isAddressEqual)(withdrawToken, claimToken);
111
- const fromBalance = require_common_utils_utils_bigint_math.BigIntMath.min(withdrawAmount, post.balances.getOrZero(withdrawToken));
111
+ const fromBalance = require_sdk_utils_bigint_math.BigIntMath.min(withdrawAmount, post.balances.getOrZero(withdrawToken));
112
112
  post.balances.dec(withdrawToken, fromBalance);
113
113
  let withdrawn = fromBalance;
114
114
  const missing = withdrawAmount - fromBalance;
@@ -129,7 +129,7 @@ function applyWithdrawCollateral(post, request, intent, converter, collateralWit
129
129
  const proceeds = converter.convert(claimToken, post.underlying, remaining);
130
130
  post.balances.dec(claimToken, remaining);
131
131
  post.balances.inc(post.underlying, proceeds);
132
- post.repay(require_common_utils_utils_bigint_math.BigIntMath.min(proceeds, debtRepaid));
132
+ post.repay(require_sdk_utils_bigint_math.BigIntMath.min(proceeds, debtRepaid));
133
133
  }
134
134
  }
135
135
  /**
@@ -138,7 +138,7 @@ function applyWithdrawCollateral(post, request, intent, converter, collateralWit
138
138
  * with it.
139
139
  */
140
140
  function repayFromClaim(post, claimToken, convert, amount) {
141
- const spent = require_common_utils_utils_bigint_math.BigIntMath.min(amount, post.balances.getOrZero(claimToken));
141
+ const spent = require_sdk_utils_bigint_math.BigIntMath.min(amount, post.balances.getOrZero(claimToken));
142
142
  if (spent <= 0n) return;
143
143
  const received = convert(claimToken, post.underlying, spent);
144
144
  post.balances.dec(claimToken, spent);
@@ -166,7 +166,7 @@ function buildClosePreview(post, converter, receivedToken) {
166
166
  creditAccount: post.creditAccount,
167
167
  receivedAmount: {
168
168
  token: receivedToken,
169
- balance: require_common_utils_utils_bigint_math.BigIntMath.max(totalValue - post.totalDebt, 0n)
169
+ balance: require_sdk_utils_bigint_math.BigIntMath.max(totalValue - post.totalDebt, 0n)
170
170
  },
171
171
  error: converter.error
172
172
  };
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_bigint_math = require("../../sdk/utils/bigint-math.js");
2
3
  const require_sdk_chain_chains = require("../../sdk/chain/chains.js");
3
4
  const require_sdk_utils_formatter = require("../../sdk/utils/formatter.js");
4
5
  require("../../sdk/index.js");
5
- const require_common_utils_utils_bigint_math = require("../../common-utils/utils/bigint-math.js");
6
6
  require("../../common-utils/index.js");
7
7
  const require_rewards_rewards_merkl_api = require("./merkl-api.js");
8
8
  let viem = require("viem");
@@ -33,7 +33,7 @@ var RewardAmountAPI = class RewardAmountAPI {
33
33
  const pool = poolByItsToken[poolToken];
34
34
  const total = require_sdk_utils_formatter.toBigInt(reason.amount || 0);
35
35
  const claimed = require_sdk_utils_formatter.toBigInt(reason.claimed || 0);
36
- const claimable = require_common_utils_utils_bigint_math.BigIntMath.max(total - claimed, 0n);
36
+ const claimable = require_sdk_utils_bigint_math.BigIntMath.max(total - claimed, 0n);
37
37
  const key = [
38
38
  pool,
39
39
  poolToken,