@gearbox-protocol/sdk 15.1.0-next.23 → 15.1.0-next.25

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 (76) hide show
  1. package/dist/cjs/model/charts.js +20 -34
  2. package/dist/cjs/model/opportunities.schema.js +17 -17
  3. package/dist/cjs/sdk/OnchainSDK.js +16 -0
  4. package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +2 -2
  5. package/dist/cjs/sdk/base/TokensMeta.js +33 -1
  6. package/dist/cjs/sdk/base/index.js +1 -0
  7. package/dist/cjs/sdk/base/token-types.js +13 -0
  8. package/dist/cjs/sdk/chain/chains.js +9 -12
  9. package/dist/cjs/sdk/chain/index.js +0 -1
  10. package/dist/cjs/sdk/index.js +5 -3
  11. package/dist/cjs/sdk/market/MarketSuite.js +11 -5
  12. package/dist/cjs/sdk/market/credit/CreditSuite.js +11 -9
  13. package/dist/cjs/sdk/market/credit/collateralUtils.js +2 -14
  14. package/dist/cjs/sdk/market/credit/index.js +0 -1
  15. package/dist/cjs/sdk/market/index.js +4 -2
  16. package/dist/cjs/sdk/market/math.js +71 -17
  17. package/dist/cjs/sdk/market/strategyName.js +4 -6
  18. package/dist/cjs/sdk/positions/PositionsService.js +1 -1
  19. package/dist/esm/dev/AccountOpener.js +1 -1
  20. package/dist/esm/dev/withdrawalUtils.js +1 -1
  21. package/dist/esm/model/charts.js +20 -34
  22. package/dist/esm/model/opportunities.schema.js +17 -17
  23. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  24. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  25. package/dist/esm/sdk/OnchainSDK.js +16 -0
  26. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  27. package/dist/esm/sdk/accounts/intents/utils/pick-token.js +1 -1
  28. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  29. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  30. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  31. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  32. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  33. package/dist/esm/sdk/base/TokensMeta.js +36 -4
  34. package/dist/esm/sdk/base/index.js +2 -2
  35. package/dist/esm/sdk/base/token-types.js +13 -1
  36. package/dist/esm/sdk/chain/chains.js +10 -12
  37. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  38. package/dist/esm/sdk/chain/index.js +2 -2
  39. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  40. package/dist/esm/sdk/index.js +5 -5
  41. package/dist/esm/sdk/market/MarketSuite.js +11 -5
  42. package/dist/esm/sdk/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  43. package/dist/esm/sdk/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  44. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  45. package/dist/esm/sdk/market/credit/CreditSuite.js +12 -10
  46. package/dist/esm/sdk/market/credit/collateralUtils.js +2 -13
  47. package/dist/esm/sdk/market/credit/index.js +2 -2
  48. package/dist/esm/sdk/market/index.js +3 -3
  49. package/dist/esm/sdk/market/math.js +68 -17
  50. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  51. package/dist/esm/sdk/market/strategyName.js +4 -6
  52. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  53. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  54. package/dist/esm/sdk/pools/PoolService.js +1 -1
  55. package/dist/esm/sdk/positions/PositionsService.js +1 -1
  56. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  57. package/dist/types/model/charts.d.ts +16 -23
  58. package/dist/types/model/charts.schema.d.ts +24 -52
  59. package/dist/types/model/opportunities.d.ts +27 -29
  60. package/dist/types/model/opportunities.schema.d.ts +113 -242
  61. package/dist/types/model/primitives.d.ts +4 -0
  62. package/dist/types/new-sdk/opportunities/types.d.ts +1 -1
  63. package/dist/types/new-sdk/positions/types.d.ts +1 -1
  64. package/dist/types/sdk/base/TokensMeta.d.ts +31 -2
  65. package/dist/types/sdk/base/index.d.ts +3 -3
  66. package/dist/types/sdk/base/token-types.d.ts +14 -1
  67. package/dist/types/sdk/chain/chains.d.ts +3 -11
  68. package/dist/types/sdk/chain/index.d.ts +2 -2
  69. package/dist/types/sdk/index.d.ts +6 -6
  70. package/dist/types/sdk/market/credit/CreditSuite.d.ts +1 -5
  71. package/dist/types/sdk/market/credit/collateralUtils.d.ts +1 -7
  72. package/dist/types/sdk/market/credit/index.d.ts +2 -2
  73. package/dist/types/sdk/market/index.d.ts +3 -3
  74. package/dist/types/sdk/market/math.d.ts +64 -13
  75. package/dist/types/sdk/market/strategyName.d.ts +3 -5
  76. package/package.json +1 -1
@@ -75,6 +75,70 @@ function calcBorrowApy(baseInterestRate, feeInterest) {
75
75
  return rayToBps(baseInterestRate * (require_sdk_constants_math.PERCENTAGE_FACTOR + BigInt(feeInterest)) / require_sdk_constants_math.PERCENTAGE_FACTOR);
76
76
  }
77
77
  /**
78
+ * Annual quota cost of a collateral, in basis points:
79
+ * `quotaRate × (1 + feeInterest)` — the quoted rate plus the protocol's cut of
80
+ * the accrued quota interest, matching {@link calcBorrowApy}.
81
+ *
82
+ * @param quotaRate - Pool quota keeper rate in basis points, without the fee.
83
+ * @param feeInterest - Credit manager interest fee in basis points.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%
88
+ * calcQuotaRate(200, 2500) // 2% × 1.25 = 250 bps = 2.5%
89
+ * ```
90
+ **/
91
+ function calcQuotaRate(quotaRate, feeInterest) {
92
+ return Math.round(quotaRate * (FULL + feeInterest) / FULL);
93
+ }
94
+ /**
95
+ * Extra quota, as a fraction of equity, that an aggressive position quotes
96
+ * above the debt it actually owes. Matches {@link MAX_LEVERAGE_BUFFER_BPS}.
97
+ **/
98
+ const DEFAULT_QUOTA_BUFFER_BPS = 500;
99
+ /**
100
+ * Quoted amount per unit of equity at the given leverage and quota mode.
101
+ * Dimensionless: `1` means the quota equals the user's equity.
102
+ **/
103
+ function calcQuotaMultiplier(leverage, lt, quotaMode = "safe") {
104
+ switch (quotaMode) {
105
+ case "min": return leverage - 1;
106
+ case "safe": return leverage * lt / FULL;
107
+ case "aggressive": return (1 + 500 / FULL) * (leverage - 1);
108
+ }
109
+ }
110
+ /**
111
+ * Annual cost of credit on the user's equity, in basis points, at a given
112
+ * leverage and quota mode: base interest on the borrowed part plus quota
113
+ * interest on the quoted amount. Both rates already include the protocol's
114
+ * interest fee.
115
+ *
116
+ * @param opportunity - Borrow APY, quota rate, and liquidation threshold.
117
+ * @param leverage - Total-value leverage, same scale as {@link Leverage}.
118
+ * @param mode - How much quota the position quotes, see {@link QuotaMode}.
119
+ **/
120
+ function calcEffectiveBorrowApy(opportunity, leverage, mode = "safe") {
121
+ const { borrowApy, quotaRate, liquidationThreshold } = opportunity;
122
+ return Math.round(borrowApy * (leverage - 1) + quotaRate * calcQuotaMultiplier(leverage, liquidationThreshold, mode));
123
+ }
124
+ /**
125
+ * Net yield of a strategy on the user's equity, in basis points, at a given
126
+ * leverage and quota mode:
127
+ * `leverage × totalCollateralApy − effectiveBorrowApy`. Collateral yield is
128
+ * on the whole position; borrow and quota interest are those of
129
+ * {@link calcEffectiveBorrowApy}.
130
+ *
131
+ * @param opportunity - Borrow APY, quota rate, and liquidation threshold.
132
+ * @param totalCollateralApy - Collateral yield the caller chose, typically
133
+ * `totalApy` of {@link StrategyOpportunity.collateralApy} or
134
+ * {@link StrategyOpportunity.collateralApyAvg7D}.
135
+ * @param leverage - Total-value leverage, same scale as {@link Leverage}.
136
+ * @param mode - How much quota the position quotes, see {@link QuotaMode}.
137
+ **/
138
+ function calcNetStrategyApy(opportunity, totalCollateralApy, leverage, mode = "safe") {
139
+ return Math.round(leverage * totalCollateralApy - calcEffectiveBorrowApy(opportunity, leverage, mode));
140
+ }
141
+ /**
78
142
  * 5% safety margin subtracted from 100% in {@link calcMaxLeverage}, so a
79
143
  * maxed position opens with HF slightly above 1.
80
144
  **/
@@ -91,9 +155,11 @@ const MAX_LEVERAGE_BUFFER_BPS = 500;
91
155
  * // liquidationThreshold: 9000 bps = 90%
92
156
  * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
93
157
  * ```
158
+ * @throws If `liquidationThreshold` is 100% or more, which would make
159
+ * leverage unbounded.
94
160
  **/
95
161
  function calcMaxLeverage(liquidationThreshold) {
96
- if (liquidationThreshold >= FULL) return 0;
162
+ if (liquidationThreshold >= FULL) throw new Error("cannot compute max leverage: liquidation threshold is 100% or more");
97
163
  const leverage = (FULL - 500) / (FULL - liquidationThreshold);
98
164
  return Math.max(leverage, 1);
99
165
  }
@@ -135,21 +201,6 @@ function calcPositionLeverage(totalValue, totalDebt) {
135
201
  return Number(totalValue) / Number(equity);
136
202
  }
137
203
  /**
138
- * Annual quota cost on equity, in basis points:
139
- * `quotaRate × (1 + feeInterest) × leverage`. Quota accrues on the whole
140
- * quoted position, and the DAO takes `feeInterest` of it as with base interest.
141
- *
142
- * @example
143
- * ```ts
144
- * // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%, leverage: 9.5x
145
- * calcAdditionalBorrowApy(200, 2500, 9.5) // 2% × 1.25 × 9.5 = 2375 bps = 23.75%
146
- * ```
147
- **/
148
- function calcAdditionalBorrowApy(quotaRate, feeInterest, leverage) {
149
- if (!Number.isFinite(leverage) || leverage <= 0) return 0;
150
- return Math.round(quotaRate * (1 + feeInterest / FULL) * leverage);
151
- }
152
- /**
153
204
  * {@link PERCENTAGE_FACTOR} less a 0.1% safety buffer.
154
205
  *
155
206
  * Partial liquidation amounts are computed off prices that can drift between
@@ -205,12 +256,15 @@ function optimalHFForPartialLiquidation(borrowRate) {
205
256
  return require_sdk_constants_math.PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
206
257
  }
207
258
  //#endregion
259
+ exports.DEFAULT_QUOTA_BUFFER_BPS = DEFAULT_QUOTA_BUFFER_BPS;
208
260
  exports.MAX_LEVERAGE_BUFFER_BPS = MAX_LEVERAGE_BUFFER_BPS;
209
261
  exports.PARTIAL_LIQUIDATION_BUFFER_BPS = PARTIAL_LIQUIDATION_BUFFER_BPS;
210
- exports.calcAdditionalBorrowApy = calcAdditionalBorrowApy;
211
262
  exports.calcBorrowApy = calcBorrowApy;
263
+ exports.calcEffectiveBorrowApy = calcEffectiveBorrowApy;
212
264
  exports.calcMaxLeverage = calcMaxLeverage;
265
+ exports.calcNetStrategyApy = calcNetStrategyApy;
213
266
  exports.calcPositionLeverage = calcPositionLeverage;
267
+ exports.calcQuotaRate = calcQuotaRate;
214
268
  exports.calcUtilization = calcUtilization;
215
269
  exports.healthFactorBps = healthFactorBps;
216
270
  exports.minSeizedAmount = minSeizedAmount;
@@ -1,19 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk_chain_chains = require("../chain/chains.js");
3
2
  //#region src/sdk/market/strategyName.ts
4
3
  /**
5
4
  * Display name of a leveraged strategy: the target collateral over the
6
5
  * borrowed underlying, e.g. `"wstETH / WETH"`.
7
6
  *
8
- * A curated pretty name from {@link getTokenPrettyName} wins over the target's
9
- * ticker when one is configured.
7
+ * Uses each token's display {@link Token.symbol}, which may already be a
8
+ * curated pretty name or a `"source -> target"` redemption rewrite.
10
9
  *
11
10
  * @param target - Collateral the position is built around.
12
11
  * @param underlying - Token the position borrows.
13
- * @param network - Chain id or network type label of the market.
14
12
  **/
15
- function strategyName(target, underlying, network) {
16
- return `${require_sdk_chain_chains.getTokenPrettyName(target.address, network) ?? target.symbol} / ${underlying.symbol}`;
13
+ function strategyName(target, underlying) {
14
+ return `${target.symbol} / ${underlying.symbol}`;
17
15
  }
18
16
  //#endregion
19
17
  exports.strategyName = strategyName;
@@ -177,7 +177,7 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
177
177
  chainId: this.sdk.chainId,
178
178
  creditManager: ca.creditManager,
179
179
  creditAccount: ca.creditAccount,
180
- name: target ? require_sdk_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
180
+ name: target ? require_sdk_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token) : token.symbol,
181
181
  targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
182
182
  leverage: require_sdk_market_math.calcPositionLeverage(totalValue, totalDebtValue),
183
183
  borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
@@ -1,9 +1,9 @@
1
- import { ierc20Abi } from "../abi/iERC20.js";
2
1
  import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
3
2
  import { AddressMap } from "../sdk/utils/AddressMap.js";
4
3
  import { AddressSet } from "../sdk/utils/AddressSet.js";
5
4
  import { AssetsMap } from "../sdk/utils/AssetsMap.js";
6
5
  import { childLogger } from "../sdk/utils/childLogger.js";
6
+ import { ierc20Abi } from "../abi/iERC20.js";
7
7
  import "../sdk/constants/addresses.js";
8
8
  import { MAX_UINT256, PERCENTAGE_FACTOR } from "../sdk/constants/math.js";
9
9
  import { SDKConstruct } from "../sdk/base/SDKConstruct.js";
@@ -1,6 +1,6 @@
1
- import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
2
1
  import { getNetworkType } from "../sdk/chain/chains.js";
3
2
  import { getWithdrawalCompressorAddress } from "../sdk/accounts/withdrawal-compressor/addresses.js";
3
+ import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
4
4
  import "../sdk/index.js";
5
5
  import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
6
6
  import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
@@ -28,11 +28,10 @@ const CHART_RANGES = [
28
28
  **/
29
29
  const POOL_OPPORTUNITY_CHART_METRICS = [
30
30
  "depositApy",
31
- "borrowApy",
31
+ "depositApyAvg7d",
32
32
  "dieselRate",
33
33
  "supplied",
34
- "borrowed",
35
- "availableLiquidity"
34
+ "borrowed"
36
35
  ];
37
36
  /**
38
37
  * Every metric a strategy opportunity can chart.
@@ -41,8 +40,10 @@ const POOL_OPPORTUNITY_CHART_METRICS = [
41
40
  * chart draws; the two USD series are the same prices quoted in dollars.
42
41
  **/
43
42
  const STRATEGY_OPPORTUNITY_CHART_METRICS = [
44
- "netApy",
45
43
  "borrowApy",
44
+ "borrowApyAvg7d",
45
+ "quotaRate",
46
+ "liquidationThreshold",
46
47
  "collateralApy",
47
48
  "tvl",
48
49
  "collateralPrice",
@@ -53,42 +54,32 @@ const STRATEGY_OPPORTUNITY_CHART_METRICS = [
53
54
  * Every metric a pool position can chart.
54
55
  *
55
56
  * 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.
57
+ * pool did, a position charts what one wallet's deposit did in it. `mwr` is the
58
+ * money-weighted return since the position opened, so it is sensitive to when
59
+ * deposits and withdrawals landed. It is anchored at inception, so a narrow
60
+ * `range` only zooms the visible slice and its first point is rarely zero.
61
61
  **/
62
62
  const POOL_POSITION_CHART_METRICS = [
63
- "value",
64
63
  "apy",
65
64
  "pnl",
66
- "mwr",
67
- "twr",
68
- "underlyingPrice"
65
+ "mwr"
69
66
  ];
70
67
  /**
71
68
  * Every metric a strategy position can chart.
72
69
  *
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.
70
+ * `netApy7d` is the trailing seven-day net yield, so it tracks the position's
71
+ * recent pace rather than its lifetime return and is comparable across
72
+ * positions of different ages.
77
73
  **/
78
74
  const STRATEGY_POSITION_CHART_METRICS = [
79
- "totalValueUsd",
80
75
  "totalValueUnderlying",
81
76
  "debt",
82
77
  "healthFactor",
83
- "leverage",
84
78
  "borrowApy",
85
- "underlyingPrice",
79
+ "borrowApyAvg7d",
86
80
  "pnl",
87
81
  "mwr",
88
- "twr",
89
- "twrApy",
90
- "trailingApy7d",
91
- "trailingApy30d"
82
+ "netApy7d"
92
83
  ];
93
84
  /**
94
85
  * Unit of every metric, the one place either side decides it.
@@ -99,31 +90,26 @@ const STRATEGY_POSITION_CHART_METRICS = [
99
90
  **/
100
91
  const CHART_METRIC_UNITS = {
101
92
  depositApy: "bps",
93
+ depositApyAvg7d: "bps",
102
94
  borrowApy: "bps",
103
- netApy: "bps",
95
+ borrowApyAvg7d: "bps",
96
+ quotaRate: "bps",
97
+ liquidationThreshold: "bps",
104
98
  collateralApy: "bps",
105
99
  supplied: "token",
106
100
  borrowed: "token",
107
- availableLiquidity: "token",
108
101
  tvl: "token",
109
102
  dieselRate: "ratio",
110
103
  collateralPrice: "ratio",
111
104
  collateralUsdPrice: "usd",
112
105
  underlyingUsdPrice: "usd",
113
- value: "token",
114
106
  apy: "bps",
115
107
  pnl: "token",
116
108
  mwr: "bps",
117
- twr: "bps",
118
- underlyingPrice: "usd",
119
- totalValueUsd: "usd",
120
109
  totalValueUnderlying: "token",
121
110
  debt: "token",
122
111
  healthFactor: "bps",
123
- leverage: "scalar",
124
- twrApy: "bps",
125
- trailingApy7d: "bps",
126
- trailingApy30d: "bps"
112
+ netApy7d: "bps"
127
113
  };
128
114
  /**
129
115
  * Reason a series could not be produced at all, which is not the same as a
@@ -65,6 +65,17 @@ const opportunityBaseSchema = z.object({
65
65
  sunset: z.boolean()
66
66
  });
67
67
  /**
68
+ * {@link QuotaAsset}
69
+ **/
70
+ const quotaAssetSchema = z.object({
71
+ token: tokenSchema,
72
+ quotaRate: tolerance(bpsSchema, "bps"),
73
+ limit: amountSchema,
74
+ used: tolerance(amountSchema, "amount"),
75
+ allocationShare: tolerance(bpsSchema, "bps"),
76
+ allocatedDebt: tolerance(amountSchema, "amount")
77
+ });
78
+ /**
68
79
  * {@link PoolOpportunity}
69
80
  **/
70
81
  const poolOpportunitySchema = z.object({
@@ -75,7 +86,8 @@ const poolOpportunitySchema = z.object({
75
86
  availableLiquidity: tolerance(amountSchema, "amount"),
76
87
  utilization: tolerance(bpsSchema, "bps"),
77
88
  supplyApy: apyBreakdownSchema,
78
- supplyApyAvg7D: offchainOnly(apyBreakdownSchema).optional()
89
+ supplyApyAvg7D: offchainOnly(apyBreakdownSchema).optional(),
90
+ quotaAssets: z.array(quotaAssetSchema)
79
91
  });
80
92
  /**
81
93
  * {@link StrategyOpportunity}
@@ -91,12 +103,10 @@ const strategyOpportunitySchema = z.object({
91
103
  expirationDate: timestampSchema.nullable(),
92
104
  collateralApy: offchainOnly(apyBreakdownSchema).optional(),
93
105
  collateralApyAvg7D: offchainOnly(apyBreakdownSchema).optional(),
94
- maxLeverageApy: offchainOnly(apyBreakdownSchema).optional(),
95
- maxLeverageApyAvg7D: offchainOnly(apyBreakdownSchema).optional(),
96
- borrowApy: tolerance(bpsSchema, "bps").optional(),
106
+ borrowApy: tolerance(bpsSchema, "bps"),
97
107
  borrowApyAvg7D: offchainOnly(bpsSchema).optional(),
98
- additionalBorrowApy: tolerance(bpsSchema, "bps").optional(),
99
- additionalBorrowApyAvg7D: offchainOnly(bpsSchema).optional(),
108
+ quotaRate: tolerance(bpsSchema, "bps"),
109
+ quotaRateAvg7D: offchainOnly(bpsSchema).optional(),
100
110
  totalValue: offchainOnly(amountSchema).optional(),
101
111
  utilization: offchainOnly(bpsSchema).optional(),
102
112
  availableLiquidity: tolerance(amountSchema, "amount"),
@@ -171,15 +181,6 @@ const rateCurveSchema = z.object({
171
181
  borrowingLimitUtilization: bpsSchema.nullable()
172
182
  });
173
183
  /**
174
- * {@link QuotaAsset}
175
- **/
176
- const quotaAssetSchema = z.object({
177
- token: tokenSchema,
178
- quotaRate: bpsSchema,
179
- limit: amountSchema,
180
- used: amountSchema
181
- });
182
- /**
183
184
  * {@link PriceFeedData}. Recursive: a composite feed lists the feeds it reads.
184
185
  **/
185
186
  const priceFeedDataSchema = z.object({
@@ -205,8 +206,7 @@ const priceFeedSummarySchema = z.object({
205
206
  **/
206
207
  const poolOpportunityDetailSchema = z.object({
207
208
  ...poolOpportunitySchema.shape,
208
- rateCurve: rateCurveSchema,
209
- quotaAssets: z.array(quotaAssetSchema)
209
+ rateCurve: rateCurveSchema
210
210
  });
211
211
  /**
212
212
  * {@link StrategyOpportunityDetail}
@@ -1,5 +1,5 @@
1
- import { iZapperAbi } from "../../abi/iZapper.js";
2
1
  import { iPoolV310Abi } from "../../abi/310/generated.js";
2
+ import { iZapperAbi } from "../../abi/iZapper.js";
3
3
  import { asPreviewSimulationError } from "./errors.js";
4
4
  //#region src/preview/simulate/simulatePoolOperation.ts
5
5
  function previewRead(operation) {
@@ -1,6 +1,6 @@
1
- import { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
3
2
  import { AddressMap } from "../../sdk/utils/AddressMap.js";
3
+ import { ierc20Abi } from "../../abi/iERC20.js";
4
4
  import "../../sdk/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
6
6
  import { getAddress, isAddressEqual, parseEventLogs } from "viem";
@@ -228,6 +228,21 @@ var OnchainSDK = class extends ChainContractsRegister {
228
228
  ...this.#withdrawalCompressor ? [this.#withdrawalCompressor.getLoadWithdrawableAssetsMulticall(force)] : [],
229
229
  this.tokensMeta.getLoadTokenDataMulticall()
230
230
  ], { blockNumber: this.currentBlock });
231
+ this.#renameRedemptionPhantoms();
232
+ }
233
+ /**
234
+ * Rewrites redemption phantom display symbols from the withdrawal
235
+ * compressor's source/target mapping. No-op when the compressor is missing
236
+ * or its assets cache has not been loaded.
237
+ **/
238
+ #renameRedemptionPhantoms() {
239
+ const compressor = this.#withdrawalCompressor;
240
+ if (!compressor?.state) return;
241
+ this.tokensMeta.renameRedemptionPhantoms(compressor.getWithdrawableAssets().map((a) => ({
242
+ phantom: a.withdrawalPhantomToken,
243
+ source: a.token,
244
+ target: a.underlying
245
+ })));
231
246
  }
232
247
  /**
233
248
  * Restores SDK state from a previously serialised {@link GearboxState}
@@ -256,6 +271,7 @@ var OnchainSDK = class extends ChainContractsRegister {
256
271
  this.#rwa.setState(state.rwa);
257
272
  if (state.withdrawals) this.#withdrawalCompressor?.hydrate(state.withdrawals);
258
273
  if (state.tokens) this.tokensMeta.hydrate(state.tokens);
274
+ this.#renameRedemptionPhantoms();
259
275
  for (const [name, plugin] of TypedObjectUtils.entries(this.plugins)) {
260
276
  const pluginState = state.plugins[name];
261
277
  if (plugin.hydrate && pluginState) {
@@ -1,5 +1,3 @@
1
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
3
1
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
4
2
  import { ADDRESS_0X0 } from "../constants/addresses.js";
5
3
  import { MAX_UINT256 } from "../constants/math.js";
@@ -10,6 +8,8 @@ import "../base/index.js";
10
8
  import { AccountBotsService } from "./bots/AccountBotsService.js";
11
9
  import "./bots/index.js";
12
10
  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";
@@ -1,4 +1,4 @@
1
- import { NON_STRATEGY_PHANTOM_TOKEN_TYPES } from "../../../market/credit/collateralUtils.js";
1
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES } from "../../../base/token-types.js";
2
2
  import { eq } from "./common.js";
3
3
  import { convertAmount } from "./convert-amount.js";
4
4
  //#region src/sdk/accounts/intents/utils/pick-token.ts
@@ -1,4 +1,3 @@
1
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
2
1
  import { AddressSet } from "../../utils/AddressSet.js";
3
2
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
4
3
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
20
19
  import "../../market/rwa/securitize/index.js";
21
20
  import "../../market/index.js";
22
21
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  //#region src/sdk/accounts/liquidations/LiquidationsService.ts
24
24
  /**
25
25
  * Service for discovering liquidatable credit accounts and previewing manual
@@ -1,7 +1,7 @@
1
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
2
1
  import { BaseContract } from "../../base/BaseContract.js";
3
2
  import "../../base/index.js";
4
3
  import { decodeDelayedIntent } from "./intent-codec.js";
4
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
5
5
  import { InvalidDelayedIntentError } from "./errors.js";
6
6
  //#region src/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
7
7
  const abi = iRedemptionLoggerV310Abi;
@@ -1,5 +1,5 @@
1
- import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
2
1
  import { encodeDelayedIntent } from "./intent-codec.js";
3
2
  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/sdk/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";
4
1
  import { AddressMap } from "../utils/AddressMap.js";
5
2
  import { AddressSet } from "../utils/AddressSet.js";
6
3
  import { bytes32ToString } from "../utils/bytes32ToString.js";
7
4
  import { getAssetType } from "../chain/chains.js";
8
5
  import { formatBN } from "../utils/formatter.js";
9
6
  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 { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
11
11
  //#region src/sdk/base/TokensMeta.ts
12
12
  /**
@@ -40,10 +40,21 @@ var TokensMeta = class extends AddressMap {
40
40
  ...existing,
41
41
  ...v
42
42
  };
43
+ if (v) {
44
+ const pretty = this.#prettyName(address);
45
+ if (pretty) v = {
46
+ ...v,
47
+ symbol: pretty
48
+ };
49
+ }
43
50
  super.upsert(address, v);
44
51
  }
45
52
  /**
46
- * Returns the symbol string for a token.
53
+ * Returns the display symbol for a token.
54
+ *
55
+ * This is not always the on-chain ERC-20 `symbol()`: curated pretty names
56
+ * and redemption phantom tokens (`"source -> target"`) replace it.
57
+ *
47
58
  * @param token - Token address.
48
59
  * @throws If the token is not in the registry.
49
60
  */
@@ -138,11 +149,32 @@ var TokensMeta = class extends AddressMap {
138
149
  }
139
150
  return meta.asset;
140
151
  }
152
+ /**
153
+ * Rewrites display symbols of redemption phantom tokens to
154
+ * `"${source} -> ${target}"`.
155
+ *
156
+ * @param renames - Phantom / source / target address triples.
157
+ **/
158
+ renameRedemptionPhantoms(renames) {
159
+ for (const { phantom, source, target } of renames) {
160
+ const meta = this.get(phantom);
161
+ if (!meta || !this.has(source) || !this.has(target)) continue;
162
+ this.upsert(phantom, {
163
+ ...meta,
164
+ symbol: `${this.symbol(source)} -> ${this.symbol(target)}`
165
+ });
166
+ }
167
+ }
141
168
  get #networkType() {
142
169
  const { chain } = this.#client;
143
170
  if ("network" in chain) return chain.network;
144
171
  throw new Error(`chain ${chain.id} is not a Gearbox SDK chain`);
145
172
  }
173
+ #prettyName(token) {
174
+ const { chain } = this.#client;
175
+ if (!("network" in chain)) return;
176
+ return chain.tokenPrettyNames?.get(token);
177
+ }
146
178
  formatBN(arg0, arg1, arg2) {
147
179
  const token = typeof arg0 === "object" ? arg0.token : arg0;
148
180
  const amount = typeof arg0 === "object" ? arg0.balance : arg1;
@@ -5,6 +5,6 @@ import { BaseContract, ContractParseError } from "./BaseContract.js";
5
5
  import { MissingSerializedParamsError } from "./errors.js";
6
6
  import { MultichainConstruct } from "./MultichainConstruct.js";
7
7
  import { SDKConstruct } from "./SDKConstruct.js";
8
- import { PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND } from "./token-types.js";
8
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND } from "./token-types.js";
9
9
  import { VotingContractStatus } from "./types.js";
10
- export { BaseContract, ChainContractsRegister, Construct, ContractParseError, MissingSerializedParamsError, MultichainConstruct, PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, SDKConstruct, TokensMeta, VotingContractStatus };
10
+ export { BaseContract, ChainContractsRegister, Construct, ContractParseError, MissingSerializedParamsError, MultichainConstruct, NON_STRATEGY_PHANTOM_TOKEN_TYPES, PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND, SDKConstruct, TokensMeta, VotingContractStatus };
@@ -12,5 +12,17 @@ const PHANTOM_TOKEN_CONTRACT_TYPES = [
12
12
  const RWA_UNDERLYING_DEFAULT = "RWA_UNDERLYING::DEFAULT";
13
13
  const RWA_UNDERLYING_ON_DEMAND = "RWA_UNDERLYING::ON_DEMAND";
14
14
  const RWA_ON_DEMAND_LP_MONOPOLIZED = "ON_DEMAND_LP::MONOPOLIZED";
15
+ /**
16
+ * Withdrawal and redemption phantom tokens that can never be acquired as a
17
+ * strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
18
+ * rewards) can.
19
+ */
20
+ const NON_STRATEGY_PHANTOM_TOKEN_TYPES = [
21
+ "PHANTOM_TOKEN::INFINIFI_UNWIND",
22
+ "PHANTOM_TOKEN::MELLOW_WITHDRAWAL",
23
+ "PHANTOM_TOKEN::MIDAS_REDEMPTION",
24
+ "PHANTOM_TOKEN::SECURITIZE_RD",
25
+ "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
26
+ ];
15
27
  //#endregion
16
- export { PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND };
28
+ export { NON_STRATEGY_PHANTOM_TOKEN_TYPES, PHANTOM_TOKEN_CONTRACT_TYPES, RWA_ON_DEMAND_LP_MONOPOLIZED, RWA_UNDERLYING_DEFAULT, RWA_UNDERLYING_ON_DEMAND };
@@ -106,7 +106,15 @@ const chains = {
106
106
  "0xb46edf298989F0F106EDD80E4ae8f59a13531dB4",
107
107
  "0xd98e31C67c7C21f233C37c9AC9Ae656dcb0d5d25"
108
108
  ]),
109
- sunsetStrategies: new AddressSet(["0x9fF97B167Dd442bd5f277098bf1154C5807D3566", "0x187C5022002d45107dB72B0b59E72111f69Bd513"]),
109
+ sunsetStrategies: new AddressSet([
110
+ "0x1840056a2bdbe949e017a3716e3fdd4a0d327bf0",
111
+ "0x187C5022002d45107dB72B0b59E72111f69Bd513",
112
+ "0x9fF97B167Dd442bd5f277098bf1154C5807D3566",
113
+ "0xa4c644f3180d10cd3b2121d455a2a88e1bda2928",
114
+ "0xb79d6544839d169869476589d2e54014a074317b",
115
+ "0xc307a074bd5aec2d6ad1d9b74465c24a59b490fd",
116
+ "0xf5edc34204e67e592bdcb84114571c9e4bd0bdf7"
117
+ ]),
110
118
  isPublic: true,
111
119
  wellKnownToken: {
112
120
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
@@ -542,15 +550,5 @@ function getLegacyStrategyTarget(creditManager, network) {
542
550
  function getAccountTargetCollateral(creditAccount, network) {
543
551
  return getChain(network).accountTargetCollaterals?.get(creditAccount);
544
552
  }
545
- /**
546
- * Curated display name of a token, or `undefined` when the token has none and
547
- * its ticker symbol should be used instead.
548
- *
549
- * @param token - Token address.
550
- * @param network - Chain id or {@link NetworkType} label.
551
- **/
552
- function getTokenPrettyName(token, network) {
553
- return getChain(network).tokenPrettyNames?.get(token);
554
- }
555
553
  //#endregion
556
- export { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, getTokenPrettyName, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds };
554
+ export { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds };
@@ -1,5 +1,5 @@
1
- import { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { chains } from "./chains.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.js";
3
3
  //#region src/sdk/chain/detectNetwork.ts
4
4
  /**
5
5
  * Detects the network type from the given client.
@@ -1,3 +1,3 @@
1
- import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, getTokenPrettyName, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds } from "./chains.js";
1
+ import { NetworkType, SUPPORTED_NETWORKS, chains, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds } from "./chains.js";
2
2
  import { detectNetwork } from "./detectNetwork.js";
3
- export { NetworkType, SUPPORTED_NETWORKS, chains, detectNetwork, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, getTokenPrettyName, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds };
3
+ export { NetworkType, SUPPORTED_NETWORKS, chains, detectNetwork, findCuratorMarketConfigurator, getAccountTargetCollateral, getAssetType, getChain, getCuratorName, getLegacyStrategyTarget, getNetworkType, isPublicNetwork, isRWAToken, isSunsetPool, isSunsetStrategy, isSupportedNetwork, toChainIds };
@@ -1,8 +1,8 @@
1
- import { iVersionAbi } from "../../abi/iVersion.js";
2
1
  import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
3
2
  import { isV310 } from "../constants/versions.js";
4
3
  import "../constants/index.js";
5
4
  import { hexEq } from "../utils/hex.js";
5
+ import { iVersionAbi } from "../../abi/iVersion.js";
6
6
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
7
7
  //#region src/sdk/core/createAddressProvider.ts
8
8
  const OVERRIDE_ADDRESSES = { Mainnet: {