@gearbox-protocol/sdk 16.0.0-next.50 → 16.0.0-next.52

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 (93) hide show
  1. package/dist/cjs/model/index.js +1 -0
  2. package/dist/cjs/model/result.js +10 -0
  3. package/dist/cjs/onchain/accounts/intents/leverage-band.js +1 -1
  4. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +8 -19
  5. package/dist/cjs/onchain/accounts/intents/open-strategy.js +1 -1
  6. package/dist/cjs/onchain/accounts/intents/realize.js +1 -1
  7. package/dist/cjs/onchain/accounts/intents/testing/market.js +6 -5
  8. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +21 -74
  9. package/dist/cjs/onchain/accounts/intents/utils/pick-token.js +1 -1
  10. package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +2 -2
  11. package/dist/cjs/onchain/accounts/intents/utils/router-path.js +1 -1
  12. package/dist/cjs/onchain/accounts/intents/view.js +1 -1
  13. package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +3 -3
  14. package/dist/cjs/onchain/chain/chains.js +9 -3
  15. package/dist/cjs/onchain/index.js +1 -1
  16. package/dist/cjs/onchain/market/MarketSuite.js +0 -28
  17. package/dist/cjs/onchain/market/credit/collateralUtils.js +2 -2
  18. package/dist/cjs/onchain/market/index.js +1 -1
  19. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +66 -13
  20. package/dist/cjs/onchain/market/oracle/TestPriceOracle.mock.js +215 -0
  21. package/dist/cjs/onchain/market/oracle/index.js +1 -1
  22. package/dist/cjs/onchain/positions/PositionsService.js +5 -7
  23. package/dist/cjs/onchain/positions/calcHealthFactor.js +4 -3
  24. package/dist/cjs/onchain/router/AbstractRouterContract.js +2 -24
  25. package/dist/cjs/onchain/router/RouterV310Contract.js +1 -12
  26. package/dist/cjs/preview/preview/buildDelayedStrategyPositionOperationPreview.js +26 -38
  27. package/dist/cjs/preview/preview/previewAdjustStrategyPosition.js +2 -3
  28. package/dist/cjs/preview/preview/previewExitOrRepayStrategyPosition.js +4 -5
  29. package/dist/cjs/preview/preview/previewOpenStrategyPosition.js +3 -7
  30. package/dist/cjs/preview/preview/previewOperation.js +1 -2
  31. package/dist/esm/dev/AccountOpener.js +1 -1
  32. package/dist/esm/dev/withdrawalUtils.js +1 -1
  33. package/dist/esm/model/index.js +2 -2
  34. package/dist/esm/model/result.js +10 -1
  35. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  36. package/dist/esm/onchain/accounts/intents/leverage-band.js +1 -1
  37. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +8 -19
  38. package/dist/esm/onchain/accounts/intents/open-strategy.js +1 -1
  39. package/dist/esm/onchain/accounts/intents/realize.js +1 -1
  40. package/dist/esm/onchain/accounts/intents/testing/market.js +6 -5
  41. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +22 -75
  42. package/dist/esm/onchain/accounts/intents/utils/pick-token.js +1 -1
  43. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +2 -2
  44. package/dist/esm/onchain/accounts/intents/utils/router-path.js +1 -1
  45. package/dist/esm/onchain/accounts/intents/view.js +1 -1
  46. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +4 -4
  47. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  48. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  49. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  50. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  51. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  52. package/dist/esm/onchain/chain/chains.js +9 -3
  53. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  54. package/dist/esm/onchain/index.js +1 -1
  55. package/dist/esm/onchain/market/MarketSuite.js +0 -28
  56. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  57. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  58. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  59. package/dist/esm/onchain/market/credit/collateralUtils.js +2 -2
  60. package/dist/esm/onchain/market/index.js +1 -1
  61. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +66 -13
  62. package/dist/esm/onchain/market/oracle/TestPriceOracle.mock.js +213 -0
  63. package/dist/esm/onchain/market/oracle/index.js +1 -1
  64. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  65. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  66. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  67. package/dist/esm/onchain/positions/PositionsService.js +5 -7
  68. package/dist/esm/onchain/positions/calcHealthFactor.js +4 -3
  69. package/dist/esm/onchain/router/AbstractRouterContract.js +2 -24
  70. package/dist/esm/onchain/router/RouterV310Contract.js +1 -12
  71. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  72. package/dist/esm/preview/preview/buildDelayedStrategyPositionOperationPreview.js +26 -38
  73. package/dist/esm/preview/preview/previewAdjustStrategyPosition.js +2 -3
  74. package/dist/esm/preview/preview/previewExitOrRepayStrategyPosition.js +4 -5
  75. package/dist/esm/preview/preview/previewOpenStrategyPosition.js +3 -7
  76. package/dist/esm/preview/preview/previewOperation.js +1 -2
  77. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  78. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  79. package/dist/types/model/index.d.ts +2 -2
  80. package/dist/types/model/previews.d.ts +4 -3
  81. package/dist/types/model/result.d.ts +16 -1
  82. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +5 -3
  83. package/dist/types/onchain/accounts/intents/testing/market.d.ts +5 -1
  84. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +1 -2
  85. package/dist/types/onchain/index.d.ts +2 -2
  86. package/dist/types/onchain/market/MarketSuite.d.ts +2 -29
  87. package/dist/types/onchain/market/index.d.ts +2 -2
  88. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +15 -5
  89. package/dist/types/onchain/market/oracle/types.d.ts +40 -28
  90. package/dist/types/onchain/positions/calcHealthFactor.d.ts +7 -3
  91. package/dist/types/onchain/router/AbstractRouterContract.d.ts +0 -4
  92. package/dist/types/preview/preview/buildDelayedStrategyPositionOperationPreview.d.ts +4 -6
  93. package/package.json +2 -10
@@ -1,3 +1,5 @@
1
+ import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
+ import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
1
3
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
2
4
  import { ADDRESS_0X0 } from "../constants/addresses.js";
3
5
  import { MAX_UINT256 } from "../constants/math.js";
@@ -8,8 +10,6 @@ import "../base/index.js";
8
10
  import { AccountBotsService } from "./bots/AccountBotsService.js";
9
11
  import "./bots/index.js";
10
12
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
11
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
13
13
  import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
14
  import "../market/index.js";
15
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
@@ -36,7 +36,7 @@ function calcLeverageBand({ sdk, creditManager, collateral, targetHF }) {
36
36
  if (!target) return;
37
37
  const ceiling = suite.creditManager.maxLeverage(target, targetHF);
38
38
  const underlying = market.pool.underlying;
39
- const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount) ?? 0n;
39
+ const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
40
40
  const netValue = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
41
41
  if (netValue <= 0n) return {
42
42
  min: 1,
@@ -11,9 +11,11 @@ import { eq } from "./utils/common.js";
11
11
  * check counts: a holding backed by a quota contributes the lesser of the
12
12
  * quota and its threshold-weighted value, an unquoted one — the underlying —
13
13
  * its weighted value alone, and dust or a disabled balance nothing at all.
14
- * Collateral is valued at the lower of its two feeds, the way the facade
15
- * values a call that hands funds over; the debt is valued at the main feed,
16
- * as the check does. Zero debt frees the whole balance.
14
+ * Collateral is valued at the protocol safe price (`min` of the two feeds,
15
+ * 0 when there is no reserve), the way the facade values a call that hands
16
+ * funds over; the underlying is exempt and is valued at the main feed, as
17
+ * `CreditManagerV3._safeConvertToUSD` does. The debt is valued at the main
18
+ * feed, as the check does. Zero debt frees the whole balance.
17
19
  *
18
20
  * Rounding always favours the account, so the answer clears the check rather
19
21
  * than landing a wei short of it.
@@ -36,7 +38,7 @@ function maxWithdrawCollateral(props) {
36
38
  /** What a holding backs, in the check's units: USD × PERCENTAGE_FACTOR. */
37
39
  const weigh = (t) => {
38
40
  const lt = BigInt(creditManager.liquidationThresholds.get(t.token) ?? 0);
39
- const weighted = (safeUsd(priceOracle, t.token, t.balance) ?? 0n) * lt;
41
+ const weighted = (eq(t.token, underlying) ? usd(priceOracle, t.token, t.balance) ?? 0n : priceOracle.safeConvertMinUSD(t.token, t.balance).value) * lt;
40
42
  if (t.quota === 0n) return weighted;
41
43
  return BigIntMath.min(quotaUsd(t) * PERCENTAGE_FACTOR, weighted);
42
44
  };
@@ -54,8 +56,8 @@ function maxWithdrawCollateral(props) {
54
56
  const shortfall = required - otherMoney;
55
57
  if (target.quota > 0n && quotaUsd(target) * 10000n < shortfall) return 0n;
56
58
  const targetLt = BigInt(creditManager.liquidationThresholds.get(target.token) ?? 0);
57
- const targetUsd = safeUsd(priceOracle, target.token, target.balance);
58
- if (targetLt === 0n || !targetUsd) return 0n;
59
+ const targetUsd = eq(target.token, underlying) ? usd(priceOracle, target.token, target.balance) ?? 0n : priceOracle.safeConvertMinUSD(target.token, target.balance).value;
60
+ if (targetLt === 0n || targetUsd === 0n) return 0n;
59
61
  const keptUsd = BigIntMath.ceilDiv(shortfall, targetLt);
60
62
  const kept = BigIntMath.ceilDiv(target.balance * keptUsd, targetUsd);
61
63
  return kept >= target.balance ? 0n : target.balance - kept;
@@ -68,18 +70,5 @@ function usd(oracle, token, amount) {
68
70
  return;
69
71
  }
70
72
  }
71
- /**
72
- * USD value at the lower of the token's two feeds — what a call handing funds
73
- * over is judged at. Falls back to the main feed where there is no second one.
74
- **/
75
- function safeUsd(oracle, token, amount) {
76
- const main = usd(oracle, token, amount);
77
- if (main === void 0) return;
78
- try {
79
- return BigIntMath.min(main, oracle.convertToUSD(token, amount, true));
80
- } catch {
81
- return main;
82
- }
83
- }
84
73
  //#endregion
85
74
  export { maxWithdrawCollateral };
@@ -27,7 +27,7 @@ async function buildOpenStrategyState(props) {
27
27
  const market = sdk.marketRegister.findByCreditManager(creditManager);
28
28
  assertMarketOperable(suite);
29
29
  const underlying = market.pool.underlying.toLowerCase();
30
- const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount) ?? 0n;
30
+ const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
31
31
  const margin = collateral.reduce((acc, a) => acc + convert(a.token, underlying, a.balance), 0n);
32
32
  if (margin <= 0n) throw new IntentPreviewError("insufficientSourceBalance", void 0, "openStrategy: collateral is worth nothing in underlying");
33
33
  const debt = debtForLeverage(margin, leverage);
@@ -29,7 +29,7 @@ async function realize(steps, props) {
29
29
  slippage
30
30
  });
31
31
  const market = sdk.marketRegister.findByCreditManager(creditAccount.creditManager);
32
- const price = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount) ?? 0n;
32
+ const price = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
33
33
  const suite = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
34
34
  const start = {
35
35
  initialAssets: creditAccount.tokens,
@@ -78,12 +78,13 @@ const LIQUIDATION_THRESHOLDS = {
78
78
  const MAX_DEBT = toBN("200000", 8);
79
79
  /** Mock SDK on the shared fixture market. */
80
80
  function buildMarketSdk(extras) {
81
+ const prices = {
82
+ ...PRICES,
83
+ ...extras?.extraPrices
84
+ };
81
85
  return buildMockSdk({
82
- prices: {
83
- ...PRICES,
84
- ...extras?.extraPrices
85
- },
86
- reservePrices: extras?.reservePrices,
86
+ prices,
87
+ reservePrices: extras?.reservePrices ?? prices,
87
88
  decimals: {
88
89
  ...DECIMALS,
89
90
  ...extras?.extraDecimals
@@ -1,9 +1,9 @@
1
1
  import "../../../constants/math.js";
2
2
  import "../../../constants/index.js";
3
- import { calcMaxLeverage, usdToNumber } from "../../../market/math.js";
3
+ import { calcMaxLeverage } from "../../../market/math.js";
4
4
  import { CreditSuite } from "../../../market/credit/CreditSuite.js";
5
- import { MarketSuite } from "../../../market/MarketSuite.js";
6
5
  import { PositionsService } from "../../../positions/PositionsService.js";
6
+ import { TestPriceOracle } from "../../../market/oracle/TestPriceOracle.mock.js";
7
7
  import { vi } from "vitest";
8
8
  //#region src/onchain/accounts/intents/testing/sdk-mock.ts
9
9
  /**
@@ -94,27 +94,25 @@ function echoEncodableOpCalls(op) {
94
94
  /**
95
95
  * Mock `OnchainSDK` covering exactly what the intent-service touches:
96
96
  * price conversion, quota params, CM/facade lookup and call assembly.
97
- * Conversion mirrors the legacy price-based math:
98
- * `amount * price[from] * 10^dec(to) / (price[to] * 10^dec(from))`.
97
+ * Conversion is a real {@link TestPriceOracle} seeded from the fixture records.
99
98
  */
100
99
  function buildMockSdk(args) {
101
100
  const decimalsOf = (token) => args.decimals[token.toLowerCase()] ?? 18;
102
- const convert = (token, to, amount) => {
103
- const from = token.toLowerCase();
104
- const target = to.toLowerCase();
105
- if (from === target) return amount;
106
- const fromPrice = args.prices[from];
107
- const toPrice = args.prices[target];
108
- if (fromPrice === void 0 || toPrice === void 0) throw new Error(`mock priceOracle: missing price for ${from} or ${target}`);
109
- return amount * fromPrice * 10n ** BigInt(decimalsOf(target)) / (toPrice * 10n ** BigInt(decimalsOf(from)));
110
- };
111
- const safeConvert = (token, to, amount) => {
112
- try {
113
- return convert(token, to, amount);
114
- } catch {
115
- return null;
116
- }
101
+ const lookup = (record, token) => record?.[token.toLowerCase()] ?? record?.[token];
102
+ const tokenCfgs = {};
103
+ for (const token of /* @__PURE__ */ new Set([
104
+ ...Object.keys(args.decimals),
105
+ ...Object.keys(args.prices),
106
+ ...Object.keys(args.reservePrices ?? {})
107
+ ])) tokenCfgs[token] = {
108
+ decimals: lookup(args.decimals, token) ?? 18,
109
+ symbol: "TOKEN",
110
+ name: "TOKEN",
111
+ price: lookup(args.prices, token),
112
+ reservePrice: lookup(args.reservePrices, token)
117
113
  };
114
+ const priceOracle = new TestPriceOracle(tokenCfgs);
115
+ const convert = (from, to, amount) => priceOracle.convert(from, to, amount);
118
116
  const fullQuota = (q) => ({
119
117
  cumulativeIndexLU: 0n,
120
118
  totalQuoted: 0n,
@@ -133,18 +131,6 @@ function buildMockSdk(args) {
133
131
  entries: () => Object.entries(args.liquidationThresholds),
134
132
  get: (token) => args.liquidationThresholds[token.toLowerCase()] ?? args.liquidationThresholds[token]
135
133
  };
136
- const _convertToUSD = (token, amount, reserve = false) => {
137
- const key = token.toLowerCase();
138
- const price = reserve ? args.reservePrices?.[key] : args.prices[key];
139
- if (price === void 0) throw new Error(`mock priceOracle: missing ${reserve ? "reserve" : "main"} price for ${token}`);
140
- return amount * price / 10n ** BigInt(decimalsOf(token));
141
- };
142
- const safeUsd = (token, amount) => {
143
- const from = token.toLowerCase();
144
- const price = args.prices[from] ?? args.prices[token];
145
- if (price === void 0) return null;
146
- return amount * price / 10n ** BigInt(decimalsOf(from));
147
- };
148
134
  const tokenOf = (token) => ({
149
135
  chainId: 1,
150
136
  address: token,
@@ -152,57 +138,19 @@ function buildMockSdk(args) {
152
138
  name: "TOKEN",
153
139
  decimals: decimalsOf(token)
154
140
  });
155
- const mainPriceOf = (token) => {
156
- const key = token.toLowerCase();
157
- const price = args.prices[key] ?? args.prices[token];
158
- if (price === void 0) throw new Error(`mock priceOracle: missing main price for ${token}`);
159
- return price;
160
- };
161
- const reservePriceOf = (token) => {
162
- const key = token.toLowerCase();
163
- const price = args.reservePrices?.[key] ?? args.reservePrices?.[token];
164
- if (price === void 0) throw new Error(`mock priceOracle: missing reserve price for ${token}`);
165
- return price;
166
- };
167
141
  const poolPaused = args.poolPaused ?? false;
168
142
  /** {@inheritDoc MarketSuite.toUnderlyingAmount} */
169
- const toUnderlyingAmount = (value) => {
170
- const usd = safeUsd(args.underlying, value);
171
- return {
172
- token: tokenOf(args.rwaAssets?.[args.underlying.toLowerCase()] ?? args.underlying),
173
- value,
174
- valueUsd: usd === null ? null : usdToNumber(usd)
175
- };
176
- };
143
+ const toUnderlyingAmount = (value) => ({
144
+ token: tokenOf(args.rwaAssets?.[args.underlying.toLowerCase()] ?? args.underlying),
145
+ ...priceOracle.toAmount(args.underlying, value)
146
+ });
177
147
  const market = {
178
148
  toUnderlyingAmount,
179
149
  /** {@inheritDoc MarketSuite.curator} */
180
150
  curator: MOCK_CURATOR,
181
151
  /** {@inheritDoc MarketSuite.underlying} */
182
152
  underlying: args.underlying,
183
- priceOracle: {
184
- convert,
185
- safeConvert,
186
- mainPrice: mainPriceOf,
187
- reservePrice: reservePriceOf,
188
- convertToUSD: _convertToUSD,
189
- toAmount: (token, value) => {
190
- const usd = safeUsd(token, value);
191
- return {
192
- value,
193
- valueUsd: usd === null ? null : usdToNumber(usd)
194
- };
195
- },
196
- toTokenAmount: (token, value) => {
197
- const usd = safeUsd(token, value);
198
- return {
199
- token: tokenOf(token),
200
- value,
201
- valueUsd: usd === null ? null : usdToNumber(usd)
202
- };
203
- },
204
- safeConvertToUSD: safeUsd
205
- },
153
+ priceOracle,
206
154
  pool: {
207
155
  pqk: {
208
156
  quotas,
@@ -222,7 +170,6 @@ function buildMockSdk(args) {
222
170
  underlying: args.underlying
223
171
  }
224
172
  };
225
- Object.assign(market, { valueInUnderlying: MarketSuite.prototype.valueInUnderlying });
226
173
  const collateralTokens = [args.underlying.toLowerCase(), ...Object.keys(args.liquidationThresholds).map((t) => t.toLowerCase()).filter((t) => t !== args.underlying.toLowerCase())];
227
174
  const forbidden = new Set((args.forbiddenTokens ?? []).map((t) => t.toLowerCase()));
228
175
  const forbiddenTokensMask = collateralTokens.reduce((mask, token, i) => forbidden.has(token) ? mask | 1n << BigInt(i) : mask, 0n);
@@ -36,7 +36,7 @@ function isRedemptionPhantomToken(sdk, token) {
36
36
  function rankAccountTokens(args) {
37
37
  const { creditAccount, sdk, exclude = [] } = args;
38
38
  const oracle = sdk.marketRegister.findByCreditManager(creditAccount.creditManager).priceOracle;
39
- const convert = (from, to, amount) => oracle.safeConvert(from, to, amount) ?? 0n;
39
+ const convert = (from, to, amount) => oracle.safeConvert(from, to, amount).value;
40
40
  const candidates = [];
41
41
  for (const t of creditAccount.tokens) {
42
42
  if (t.balance <= 0n) continue;
@@ -14,8 +14,8 @@ function probeBasket(balances, oracle) {
14
14
  let basketWad = 0n;
15
15
  for (const asset of balances) {
16
16
  if (asset.balance <= 0n) continue;
17
- const usd = oracle.safeConvertToUSD(asset.token, asset.balance);
18
- if (usd !== null && usd > 0n) basketWad += usd * WAD / PRICE_DECIMALS;
17
+ const usd = oracle.safeConvertToUSD(asset.token, asset.balance).value;
18
+ if (usd > 0n) basketWad += usd * WAD / PRICE_DECIMALS;
19
19
  }
20
20
  if (basketWad <= 0n) return;
21
21
  const probeWad = PROBE_UNIT_USD_WAD;
@@ -151,7 +151,7 @@ function createRouterPaths(args) {
151
151
  function createOraclePaths(args) {
152
152
  const { sdk, creditAccount } = args;
153
153
  const oracle = sdk.marketRegister.findByCreditManager(creditAccount.creditManager).priceOracle;
154
- const price = (from, to, amount) => oracle.safeConvert(from, to, amount) ?? 0n;
154
+ const price = (from, to, amount) => oracle.safeConvert(from, to, amount).value;
155
155
  const estimate = (amount) => ({
156
156
  amount,
157
157
  minAmount: amount,
@@ -11,7 +11,7 @@ import { pickFattestNonPhantomToken } from "./utils/pick-token.js";
11
11
  function accountView(creditAccount, sdk) {
12
12
  const { underlying, creditManager } = creditAccount;
13
13
  const oracle = sdk.marketRegister.findByCreditManager(creditManager).priceOracle;
14
- const price = (from, to, amount) => oracle.safeConvert(from, to, amount) ?? 0n;
14
+ const price = (from, to, amount) => oracle.safeConvert(from, to, amount).value;
15
15
  const { creditFacade } = sdk.marketRegister.findCreditManager(creditManager);
16
16
  let totalValue = 0n;
17
17
  for (const t of creditAccount.tokens) totalValue += price(t.token, underlying, t.balance);
@@ -1,3 +1,4 @@
1
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
1
2
  import { AddressSet } from "../../utils/AddressSet.js";
2
3
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
3
4
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
19
20
  import "../../market/rwa/securitize/index.js";
20
21
  import "../../market/index.js";
21
22
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
24
24
  //#region src/onchain/accounts/liquidations/LiquidationsService.ts
25
25
  /**
@@ -148,11 +148,11 @@ var LiquidationsService = class extends SDKConstruct {
148
148
  #anyMarketTokenAmount(token, value) {
149
149
  const meta = this.sdk.tokensMeta.mustGetToken(token);
150
150
  for (const market of this.sdk.marketRegister.markets) {
151
- const valueUsd = market.priceOracle.safeUsdValue(token, value);
152
- if (valueUsd !== null) return {
151
+ const priced = market.priceOracle.safeConvertToUSD(token, value);
152
+ if (!priced.error) return {
153
153
  token: meta,
154
154
  value,
155
- valueUsd
155
+ valueUsd: usdToNumber(priced.value)
156
156
  };
157
157
  }
158
158
  return {
@@ -1,9 +1,9 @@
1
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { sdkErr, sdkOk } from "../../../model/result.js";
4
5
  import "../../../model/index.js";
5
6
  import { decodeDelayedIntent } from "./intent-codec.js";
6
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
7
7
  //#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
8
8
  const abi = iRedemptionLoggerV310Abi;
9
9
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
1
2
  import { encodeDelayedIntent } from "./intent-codec.js";
2
3
  import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
3
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
4
4
  import { toWithdrawalStatus } from "./types.js";
5
5
  //#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
6
6
  const abi = iWithdrawalCompressorV313Abi;
@@ -1,12 +1,12 @@
1
+ import { iExpirableAbi } from "../../abi/iExpirable.js";
2
+ import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
3
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
4
  import { AddressMap } from "../utils/AddressMap.js";
2
5
  import { AddressSet } from "../utils/AddressSet.js";
3
6
  import { bytes32ToString } from "../utils/bytes32ToString.js";
4
7
  import { getAssetType } from "../chain/chains.js";
5
8
  import { formatBN } from "../utils/formatter.js";
6
9
  import "../utils/index.js";
7
- import { iExpirableAbi } from "../../abi/iExpirable.js";
8
- import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
9
- import { iVersionAbi } from "../../abi/iVersion.js";
10
10
  import { SdkRWADataNotLoadedError } from "../core/errors.js";
11
11
  import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
12
12
  //#region src/onchain/base/TokensMeta.ts
@@ -113,7 +113,11 @@ const chains = {
113
113
  "0xa4c644f3180d10cd3b2121d455a2a88e1bda2928",
114
114
  "0xb79d6544839d169869476589d2e54014a074317b",
115
115
  "0xc307a074bd5aec2d6ad1d9b74465c24a59b490fd",
116
- "0xf5edc34204e67e592bdcb84114571c9e4bd0bdf7"
116
+ "0xf5edc34204e67e592bdcb84114571c9e4bd0bdf7",
117
+ "0x29350A3C2627FB78C7E915cd59AF754edf8998c5",
118
+ "0x5A93bc6983F80f5c55675eA4e77bb46DdC9665e8",
119
+ "0x5415092F06403F30486EF846dBAE0532c6Bd8759",
120
+ "0x9D866298f6B8E168a06e313D47059f2C097A92F1"
117
121
  ]),
118
122
  isPublic: true,
119
123
  wellKnownToken: {
@@ -225,7 +229,8 @@ const chains = {
225
229
  sunsetPools: new AddressSet([
226
230
  "0x09cA6b76276eC0682adb896418b99CB7E44a58A0",
227
231
  "0x34752948B0dc28969485Df2066fFE86D5dc36689",
228
- "0x164A35F31e4E0F6c45D500962a6978D2cbD5a16b"
232
+ "0x164A35F31e4E0F6c45D500962a6978D2cbD5a16b",
233
+ "0xc4173359087CE643235420b7bC610d9B0CF2B82D"
229
234
  ]),
230
235
  sunsetStrategies: new AddressSet([
231
236
  "0xA1F05494Dab74Eb9C352C3A042836579fE168aa7",
@@ -235,7 +240,8 @@ const chains = {
235
240
  "0xb21f766c193541305C18cE146DCD3Fdf642b40eF",
236
241
  "0x04620081bb818B8CD3996943D0A4a37Dbf296cF4",
237
242
  "0x5452971Fc17d025a1AFFDd5F7a44CCDD1BF0524C",
238
- "0x7ea06087C63568f1071c6BEA3AeB51e070ec68B9"
243
+ "0x7ea06087C63568f1071c6BEA3AeB51e070ec68B9",
244
+ "0x06F5b5062477DCf6723c30a76232A5C0B6FCb01A"
239
245
  ]),
240
246
  rwaFactories: [],
241
247
  isPublic: true,
@@ -1,8 +1,8 @@
1
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
2
  import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
2
3
  import { isV310 } from "../constants/versions.js";
3
4
  import "../constants/index.js";
4
5
  import { hexEq } from "../utils/hex.js";
5
- import { iVersionAbi } from "../../abi/iVersion.js";
6
6
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
7
7
  //#region src/onchain/core/createAddressProvider.ts
8
8
  const OVERRIDE_ADDRESSES = { Mainnet: {
@@ -169,9 +169,9 @@ import { WstETHPriceFeedContract } from "./market/pricefeeds/WstETHPriceFeed.js"
169
169
  import { YearnPriceFeedContract } from "./market/pricefeeds/YearnPriceFeed.js";
170
170
  import { ZeroPriceFeedContract } from "./market/pricefeeds/ZeroPriceFeed.js";
171
171
  import { PriceFeedRegister } from "./market/pricefeeds/PriceFeedsRegister.js";
172
+ import { unpriceableTokenError } from "./market/oracle/errors.js";
172
173
  import { PriceOracleV310Contract } from "./market/oracle/PriceOracleV310Contract.js";
173
174
  import { createPriceOracle } from "./market/oracle/createPriceOracle.js";
174
- import { unpriceableTokenError } from "./market/oracle/errors.js";
175
175
  import { GaugeContract } from "./market/pool/GaugeContract.js";
176
176
  import { LinearInterestRateModelContract } from "./market/pool/LinearInterestRateModelContract.js";
177
177
  import { PoolV310Contract } from "./market/pool/PoolV310Contract.js";
@@ -1,7 +1,5 @@
1
1
  import { AddressMap } from "../utils/AddressMap.js";
2
2
  import { isRWAToken, isSunsetPool } from "../chain/chains.js";
3
- import { DUST_THRESHOLD } from "../constants/math.js";
4
- import "../constants/index.js";
5
3
  import "../utils/index.js";
6
4
  import { SDKConstruct } from "../base/SDKConstruct.js";
7
5
  import "../base/index.js";
@@ -152,32 +150,6 @@ var MarketSuite = class extends SDKConstruct {
152
150
  ...this.priceOracle.toAmount(this.underlying, value)
153
151
  });
154
152
  /**
155
- * Sums `assets` in this market's underlying at latest oracle prices.
156
- *
157
- * Balances at or below `minBalance` are ignored. A token the oracle cannot
158
- * price contributes nothing; the first such token is {@link ValueInUnderlying.unpriceable}.
159
- *
160
- * The counterpart of {@link toUnderlyingAmount}: that method labels a figure
161
- * already in underlying, this one produces the figure from mixed holdings.
162
- **/
163
- valueInUnderlying(assets, minBalance = DUST_THRESHOLD) {
164
- let unpriceable;
165
- let value = 0n;
166
- for (const { token, balance } of assets) {
167
- if (balance <= minBalance) continue;
168
- const converted = this.priceOracle.safeConvert(token, this.underlying, balance);
169
- if (converted === null) {
170
- unpriceable ??= token;
171
- continue;
172
- }
173
- value += converted;
174
- }
175
- return unpriceable === void 0 ? { value } : {
176
- value,
177
- unpriceable
178
- };
179
- }
180
- /**
181
153
  * Display name of this market's pool, e.g. `"USDC Pool"`.
182
154
  */
183
155
  get poolName() {
@@ -1,5 +1,5 @@
1
- import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
1
  import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
+ import { AbstractAdapterContract } from "./AbstractAdapter.js";
3
3
  //#region src/onchain/market/adapters/contracts/AccountMigratorAdapterContract.ts
4
4
  const abi = accountMigratorAbi;
5
5
  const protocolAbi = accountMigratorAbi;
@@ -1,6 +1,6 @@
1
+ import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
1
2
  import { MissingSerializedParamsError } from "../../../base/errors.js";
2
3
  import "../../../base/index.js";
3
- import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
4
4
  import { iERC4626Abi } from "../abi/targetContractAbi.js";
5
5
  import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
6
6
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -1,7 +1,7 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/BaseContract.js";
3
4
  import "../../base/index.js";
4
- import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/onchain/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -66,11 +66,11 @@ function pickStrategyTargetCollateral(tokens) {
66
66
  * nothing but its underlying, or nothing the oracle can price.
67
67
  **/
68
68
  function dominantCollateral(account, market) {
69
- let bestValue = 0;
69
+ let bestValue = 0n;
70
70
  let dominant;
71
71
  for (const t of account.tokens) {
72
72
  if (isAddressEqual(t.token, account.underlying) || (t.mask & account.enabledTokensMask) === 0n || t.balance <= 10n) continue;
73
- const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
73
+ const value = market.priceOracle.safeConvertToUSD(t.token, t.balance).value;
74
74
  if (value > bestValue) {
75
75
  bestValue = value;
76
76
  dominant = t.token;
@@ -119,9 +119,9 @@ import { YearnPriceFeedContract } from "./pricefeeds/YearnPriceFeed.js";
119
119
  import { ZeroPriceFeedContract } from "./pricefeeds/ZeroPriceFeed.js";
120
120
  import { PriceFeedRegister } from "./pricefeeds/PriceFeedsRegister.js";
121
121
  import "./pricefeeds/index.js";
122
+ import { unpriceableTokenError } from "./oracle/errors.js";
122
123
  import { PriceOracleV310Contract } from "./oracle/PriceOracleV310Contract.js";
123
124
  import { createPriceOracle } from "./oracle/createPriceOracle.js";
124
- import { unpriceableTokenError } from "./oracle/errors.js";
125
125
  import "./oracle/index.js";
126
126
  import { GaugeContract } from "./pool/GaugeContract.js";
127
127
  import { LinearInterestRateModelContract } from "./pool/LinearInterestRateModelContract.js";