@gearbox-protocol/sdk 16.0.0-next.6 → 16.0.0-next.8

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 (36) hide show
  1. package/dist/cjs/model/index.js +1 -0
  2. package/dist/cjs/model/opportunities.schema.js +1 -1
  3. package/dist/cjs/model/positions.js +2 -2
  4. package/dist/cjs/model/positions.schema.js +2 -0
  5. package/dist/cjs/model/primitives.schema.js +8 -0
  6. package/dist/cjs/onchain/accounts/intents/math.js +2 -2
  7. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +2 -5
  8. package/dist/cjs/onchain/market/MarketSuite.js +7 -4
  9. package/dist/cjs/onchain/market/pool/PoolSuite.js +2 -2
  10. package/dist/cjs/onchain/pools/PoolService.js +1 -0
  11. package/dist/cjs/onchain/positions/PositionsService.js +2 -1
  12. package/dist/cjs/onchain/utils/bigint-math.js +9 -0
  13. package/dist/esm/model/index.js +2 -2
  14. package/dist/esm/model/opportunities.schema.js +2 -2
  15. package/dist/esm/model/positions.js +2 -2
  16. package/dist/esm/model/positions.schema.js +3 -1
  17. package/dist/esm/model/primitives.schema.js +8 -1
  18. package/dist/esm/onchain/accounts/intents/math.js +2 -2
  19. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +2 -5
  20. package/dist/esm/onchain/market/MarketSuite.js +7 -4
  21. package/dist/esm/onchain/market/pool/PoolSuite.js +2 -2
  22. package/dist/esm/onchain/pools/PoolService.js +1 -0
  23. package/dist/esm/onchain/positions/PositionsService.js +2 -1
  24. package/dist/esm/onchain/utils/bigint-math.js +9 -0
  25. package/dist/types/model/index.d.ts +3 -3
  26. package/dist/types/model/opportunities.d.ts +4 -4
  27. package/dist/types/model/opportunities.schema.d.ts +9 -0
  28. package/dist/types/model/positions.d.ts +15 -1
  29. package/dist/types/model/positions.schema.d.ts +36 -0
  30. package/dist/types/model/primitives.d.ts +17 -1
  31. package/dist/types/model/primitives.schema.d.ts +13 -1
  32. package/dist/types/onchain/market/MarketSuite.d.ts +5 -5
  33. package/dist/types/onchain/market/pool/PoolSuite.d.ts +2 -2
  34. package/dist/types/onchain/market/pool/types.d.ts +1 -0
  35. package/dist/types/onchain/utils/bigint-math.d.ts +9 -0
  36. package/package.json +1 -1
@@ -140,3 +140,4 @@ exports.tokenRewardsSchema = require_model_opportunities_schema.tokenRewardsSche
140
140
  exports.tokenSchema = require_model_primitives_schema.tokenSchema;
141
141
  exports.tolerance = require_model_compare_schema.tolerance;
142
142
  exports.txCallSchema = require_model_primitives_schema.txCallSchema;
143
+ exports.underlyingTokenSchema = require_model_primitives_schema.underlyingTokenSchema;
@@ -58,7 +58,7 @@ const opportunityBaseSchema = zod_v4.z.object({
58
58
  chainId: require_model_primitives_schema.chainIdSchema,
59
59
  name: zod_v4.z.string(),
60
60
  curator: require_model_curators_schema.curatorSchema,
61
- underlyingToken: require_model_primitives_schema.tokenSchema,
61
+ underlyingToken: require_model_primitives_schema.underlyingTokenSchema,
62
62
  allowedDepositTokens: zod_v4.z.array(require_model_primitives_schema.tokenSchema),
63
63
  paused: zod_v4.z.boolean(),
64
64
  rwa: zod_v4.z.boolean(),
@@ -79,8 +79,8 @@ function matchesPositionFilter(position, filter) {
79
79
  **/
80
80
  function positionUnderlying(position) {
81
81
  switch (position.kind) {
82
- case "pool": return position.netValue.token;
83
- case "strategy": return position.totalValue.token;
82
+ case "pool":
83
+ case "strategy": return position.underlyingToken;
84
84
  case "liquidation": return;
85
85
  }
86
86
  }
@@ -69,6 +69,7 @@ const poolPositionSchema = zod_v4.z.object({
69
69
  name: zod_v4.z.string(),
70
70
  chainId: require_model_primitives_schema.chainIdSchema,
71
71
  pool: require_onchain_utils_zod.ZodAddress(),
72
+ underlyingToken: require_model_primitives_schema.underlyingTokenSchema,
72
73
  netValue: require_model_compare_schema.tolerance(require_model_primitives_schema.tokenAmountSchema, "amount"),
73
74
  apy: require_model_opportunities_schema.apyBreakdownSchema,
74
75
  apyAvg7D: require_model_compare_schema.offchainOnly(require_model_opportunities_schema.apyBreakdownSchema).optional(),
@@ -99,6 +100,7 @@ const strategyPositionSchema = zod_v4.z.object({
99
100
  chainId: require_model_primitives_schema.chainIdSchema,
100
101
  creditManager: require_onchain_utils_zod.ZodAddress(),
101
102
  creditAccount: require_onchain_utils_zod.ZodAddress(),
103
+ underlyingToken: require_model_primitives_schema.underlyingTokenSchema,
102
104
  targetCollateral: require_model_primitives_schema.tokenSchema.nullable(),
103
105
  leverage: require_model_compare_schema.tolerance(require_model_primitives_schema.leverageSchema, "float"),
104
106
  borrowApy: require_model_compare_schema.tolerance(require_model_primitives_schema.bpsSchema, "bps"),
@@ -55,6 +55,13 @@ const tokenSchema = zod_v4.z.object({
55
55
  assetType: assetTypeSchema.optional()
56
56
  });
57
57
  /**
58
+ * {@link UnderlyingToken}
59
+ **/
60
+ const underlyingTokenSchema = zod_v4.z.object({
61
+ ...tokenSchema.shape,
62
+ wrappedAddress: require_onchain_utils_zod.ZodAddress().nullable()
63
+ });
64
+ /**
58
65
  * {@link TokenAmount}
59
66
  **/
60
67
  const tokenAmountSchema = amountSchema.extend({ token: tokenSchema });
@@ -76,3 +83,4 @@ exports.timestampSchema = timestampSchema;
76
83
  exports.tokenAmountSchema = tokenAmountSchema;
77
84
  exports.tokenSchema = tokenSchema;
78
85
  exports.txCallSchema = txCallSchema;
86
+ exports.underlyingTokenSchema = underlyingTokenSchema;
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
2
3
  const require_onchain_constants_math = require("../../constants/math.js");
3
4
  const require_onchain_accounts_intents_types = require("./types.js");
4
5
  //#region src/onchain/accounts/intents/math.ts
@@ -32,10 +33,9 @@ function maxProportionalWithdrawal(position, band) {
32
33
  if (debt === 0n) return allButLast;
33
34
  const repayable = debt - band.minDebt;
34
35
  if (repayable < 0n) return 0n;
35
- const bound = ceilDiv(collateral * (repayable + 1n), debt) - 1n;
36
+ const bound = require_onchain_utils_bigint_math.BigIntMath.ceilDiv(collateral * (repayable + 1n), debt) - 1n;
36
37
  return bound < allButLast ? bound : allButLast;
37
38
  }
38
- const ceilDiv = (a, b) => (a + b - 1n) / b;
39
39
  /** Total leverage cannot drop below 1x — that would be negative debt. */
40
40
  function assertLeverageAtLeastOne(leverage) {
41
41
  if (leverage < 100n) throw new require_onchain_accounts_intents_types.IntentPreviewError("leverageOutOfRange", `target leverage ${leverage} is below 1x`);
@@ -57,8 +57,8 @@ function maxWithdrawCollateral(props) {
57
57
  const targetLt = BigInt(creditManager.liquidationThresholds.get(target.token) ?? 0);
58
58
  const targetUsd = safeUsd(priceOracle, target.token, target.balance);
59
59
  if (targetLt === 0n || !targetUsd) return 0n;
60
- const keptUsd = ceilDiv(shortfall, targetLt);
61
- const kept = ceilDiv(target.balance * keptUsd, targetUsd);
60
+ const keptUsd = require_onchain_utils_bigint_math.BigIntMath.ceilDiv(shortfall, targetLt);
61
+ const kept = require_onchain_utils_bigint_math.BigIntMath.ceilDiv(target.balance * keptUsd, targetUsd);
62
62
  return kept >= target.balance ? 0n : target.balance - kept;
63
63
  }
64
64
  /** USD value at the main feed, or `undefined` when the token has no price. */
@@ -82,8 +82,5 @@ function safeUsd(oracle, token, amount) {
82
82
  return main;
83
83
  }
84
84
  }
85
- function ceilDiv(a, b) {
86
- return (a + b - 1n) / b;
87
- }
88
85
  //#endregion
89
86
  exports.maxWithdrawCollateral = maxWithdrawCollateral;
@@ -96,7 +96,8 @@ var MarketSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
96
96
  this.lossPolicy = require_onchain_market_loss_policy_createLossPolicy.createLossPolicy(sdk, marketData.lossPolicy);
97
97
  }
98
98
  /**
99
- * Underlying token of the market pool.
99
+ * Underlying token of the market pool, as returned by contract.
100
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
100
101
  */
101
102
  get underlying() {
102
103
  return this.pool.underlying;
@@ -118,11 +119,13 @@ var MarketSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
118
119
  * The market's underlying as the shared read model describes it.
119
120
  *
120
121
  * For an RWA market this is the token the underlying wraps rather than the
121
- * wrapper itself, because only that token means anything to a reader. The
122
- * wrapper converts one-for-one, so amounts denominated in it stay exact.
122
+ * wrapper itself, e.g. USDC rather than dcUSDC (which will be "wrappedAddress" in this case)
123
123
  */
124
124
  get underlyingToken() {
125
- return this.tokensMeta.mustGetToken(this.unwrappedUnderlying);
125
+ return {
126
+ ...this.tokensMeta.mustGetToken(this.unwrappedUnderlying),
127
+ wrappedAddress: (0, viem.isAddressEqual)(this.underlying, this.unwrappedUnderlying) ? null : this.underlying
128
+ };
126
129
  }
127
130
  /**
128
131
  * Display name of this market's pool, e.g. `"USDC Pool"`.
@@ -93,8 +93,8 @@ var PoolSuite = class extends require_onchain_base_SDKConstruct.SDKConstruct {
93
93
  return this.register.mustGetContract(this.#marketConfigurator);
94
94
  }
95
95
  /**
96
- * Underlying asset deposited into the pool and borrowed by connected credit
97
- * suites.
96
+ * Underlying token of the market pool, as returned by contract.
97
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
98
98
  */
99
99
  get underlying() {
100
100
  return this.pool.underlying;
@@ -418,6 +418,7 @@ var PoolService = class extends require_onchain_base_SDKConstruct.SDKConstruct {
418
418
  name: this.sdk.tokensMeta.mustGetToken(pool.address).name,
419
419
  chainId: this.chainId,
420
420
  pool: pool.address,
421
+ underlyingToken: market.underlyingToken,
421
422
  netValue: {
422
423
  token: this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying),
423
424
  ...market.priceOracle.toAmount(market.underlying, shares * pool.dieselRate / require_onchain_constants_math.RAY)
@@ -177,7 +177,7 @@ var PositionsService = class extends require_onchain_base_SDKConstruct.SDKConstr
177
177
  const { market } = suite;
178
178
  const { priceOracle } = market;
179
179
  const { pool } = market.pool;
180
- const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
180
+ const token = market.underlyingToken;
181
181
  const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
182
182
  const target = require_onchain_chain_chains.getAccountTargetCollateral(ca.creditAccount, this.sdk.chainId) ?? suite.strategyTargetCollateral;
183
183
  const snapshot = require_onchain_positions_types.accountSnapshotFromCreditAccountData(ca);
@@ -207,6 +207,7 @@ var PositionsService = class extends require_onchain_base_SDKConstruct.SDKConstr
207
207
  chainId: this.sdk.chainId,
208
208
  creditManager: ca.creditManager,
209
209
  creditAccount: ca.creditAccount,
210
+ underlyingToken: token,
210
211
  name: target ? require_onchain_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token) : token.symbol,
211
212
  targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
212
213
  leverage: require_onchain_market_math.calcPositionLeverage(totalValue, totalDebtValue),
@@ -42,6 +42,15 @@ var BigIntMath = class {
42
42
  * @returns A non-positive bigint representation of `a`.
43
43
  */
44
44
  static neg = (a) => a > 0 ? a * -1n : a;
45
+ /**
46
+ * Divides rounding toward positive infinity.
47
+ *
48
+ * @param a - Dividend; must not be negative.
49
+ * @param b - Divisor; must be positive — zero throws, negative returns
50
+ * nonsense rather than the ceiling.
51
+ * @returns The smallest integer that is at least `a / b`.
52
+ **/
53
+ static ceilDiv = (a, b) => (a + b - 1n) / b;
45
54
  };
46
55
  //#endregion
47
56
  exports.BigIntMath = BigIntMath;
@@ -1,6 +1,6 @@
1
1
  import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS } from "./charts.js";
2
2
  import { compareTagOf, offchainOnly, onchainOnly, tolerance } from "./compare.schema.js";
3
- import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
3
+ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema, underlyingTokenSchema } from "./primitives.schema.js";
4
4
  import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema } from "./charts.schema.js";
5
5
  import "./curators.js";
6
6
  import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
@@ -19,4 +19,4 @@ import { ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ER
19
19
  import "./primitives.js";
20
20
  import "./response.js";
21
21
  import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
22
- export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema };
22
+ export { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, FILTER_ALL, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
@@ -1,6 +1,6 @@
1
1
  import { ZodAddress } from "../onchain/utils/zod.js";
2
2
  import { offchainOnly, tolerance } from "./compare.schema.js";
3
- import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema } from "./primitives.schema.js";
3
+ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenSchema, underlyingTokenSchema } from "./primitives.schema.js";
4
4
  import { curatorSchema } from "./curators.schema.js";
5
5
  import { isFilterSet } from "./filters.js";
6
6
  import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
@@ -57,7 +57,7 @@ const opportunityBaseSchema = z.object({
57
57
  chainId: chainIdSchema,
58
58
  name: z.string(),
59
59
  curator: curatorSchema,
60
- underlyingToken: tokenSchema,
60
+ underlyingToken: underlyingTokenSchema,
61
61
  allowedDepositTokens: z.array(tokenSchema),
62
62
  paused: z.boolean(),
63
63
  rwa: z.boolean(),
@@ -78,8 +78,8 @@ function matchesPositionFilter(position, filter) {
78
78
  **/
79
79
  function positionUnderlying(position) {
80
80
  switch (position.kind) {
81
- case "pool": return position.netValue.token;
82
- case "strategy": return position.totalValue.token;
81
+ case "pool":
82
+ case "strategy": return position.underlyingToken;
83
83
  case "liquidation": return;
84
84
  }
85
85
  }
@@ -1,6 +1,6 @@
1
1
  import { ZodAddress, ZodBigInt, ZodHex } from "../onchain/utils/zod.js";
2
2
  import { offchainOnly, onchainOnly, tolerance } from "./compare.schema.js";
3
- import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema } from "./primitives.schema.js";
3
+ import { assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, underlyingTokenSchema } from "./primitives.schema.js";
4
4
  import { isFilterSet } from "./filters.js";
5
5
  import { booleanParamSchema, encodeFlag, filterable } from "./filters.schema.js";
6
6
  import { delayedReceivedAssetSchema, liquidationPositionSchema } from "./liquidations.schema.js";
@@ -68,6 +68,7 @@ const poolPositionSchema = z.object({
68
68
  name: z.string(),
69
69
  chainId: chainIdSchema,
70
70
  pool: ZodAddress(),
71
+ underlyingToken: underlyingTokenSchema,
71
72
  netValue: tolerance(tokenAmountSchema, "amount"),
72
73
  apy: apyBreakdownSchema,
73
74
  apyAvg7D: offchainOnly(apyBreakdownSchema).optional(),
@@ -98,6 +99,7 @@ const strategyPositionSchema = z.object({
98
99
  chainId: chainIdSchema,
99
100
  creditManager: ZodAddress(),
100
101
  creditAccount: ZodAddress(),
102
+ underlyingToken: underlyingTokenSchema,
101
103
  targetCollateral: tokenSchema.nullable(),
102
104
  leverage: tolerance(leverageSchema, "float"),
103
105
  borrowApy: tolerance(bpsSchema, "bps"),
@@ -54,6 +54,13 @@ const tokenSchema = z.object({
54
54
  assetType: assetTypeSchema.optional()
55
55
  });
56
56
  /**
57
+ * {@link UnderlyingToken}
58
+ **/
59
+ const underlyingTokenSchema = z.object({
60
+ ...tokenSchema.shape,
61
+ wrappedAddress: ZodAddress().nullable()
62
+ });
63
+ /**
57
64
  * {@link TokenAmount}
58
65
  **/
59
66
  const tokenAmountSchema = amountSchema.extend({ token: tokenSchema });
@@ -66,4 +73,4 @@ const txCallSchema = z.object({
66
73
  value: ZodBigInt().optional()
67
74
  });
68
75
  //#endregion
69
- export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
76
+ export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema, underlyingTokenSchema };
@@ -1,3 +1,4 @@
1
+ import { BigIntMath } from "../../utils/bigint-math.js";
1
2
  import { LEVERAGE_DECIMALS } from "../../constants/math.js";
2
3
  import { IntentPreviewError } from "./types.js";
3
4
  //#region src/onchain/accounts/intents/math.ts
@@ -31,10 +32,9 @@ function maxProportionalWithdrawal(position, band) {
31
32
  if (debt === 0n) return allButLast;
32
33
  const repayable = debt - band.minDebt;
33
34
  if (repayable < 0n) return 0n;
34
- const bound = ceilDiv(collateral * (repayable + 1n), debt) - 1n;
35
+ const bound = BigIntMath.ceilDiv(collateral * (repayable + 1n), debt) - 1n;
35
36
  return bound < allButLast ? bound : allButLast;
36
37
  }
37
- const ceilDiv = (a, b) => (a + b - 1n) / b;
38
38
  /** Total leverage cannot drop below 1x — that would be negative debt. */
39
39
  function assertLeverageAtLeastOne(leverage) {
40
40
  if (leverage < 100n) throw new IntentPreviewError("leverageOutOfRange", `target leverage ${leverage} is below 1x`);
@@ -56,8 +56,8 @@ function maxWithdrawCollateral(props) {
56
56
  const targetLt = BigInt(creditManager.liquidationThresholds.get(target.token) ?? 0);
57
57
  const targetUsd = safeUsd(priceOracle, target.token, target.balance);
58
58
  if (targetLt === 0n || !targetUsd) return 0n;
59
- const keptUsd = ceilDiv(shortfall, targetLt);
60
- const kept = ceilDiv(target.balance * keptUsd, targetUsd);
59
+ const keptUsd = BigIntMath.ceilDiv(shortfall, targetLt);
60
+ const kept = BigIntMath.ceilDiv(target.balance * keptUsd, targetUsd);
61
61
  return kept >= target.balance ? 0n : target.balance - kept;
62
62
  }
63
63
  /** USD value at the main feed, or `undefined` when the token has no price. */
@@ -81,8 +81,5 @@ function safeUsd(oracle, token, amount) {
81
81
  return main;
82
82
  }
83
83
  }
84
- function ceilDiv(a, b) {
85
- return (a + b - 1n) / b;
86
- }
87
84
  //#endregion
88
85
  export { maxWithdrawCollateral };
@@ -95,7 +95,8 @@ var MarketSuite = class extends SDKConstruct {
95
95
  this.lossPolicy = createLossPolicy(sdk, marketData.lossPolicy);
96
96
  }
97
97
  /**
98
- * Underlying token of the market pool.
98
+ * Underlying token of the market pool, as returned by contract.
99
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
99
100
  */
100
101
  get underlying() {
101
102
  return this.pool.underlying;
@@ -117,11 +118,13 @@ var MarketSuite = class extends SDKConstruct {
117
118
  * The market's underlying as the shared read model describes it.
118
119
  *
119
120
  * For an RWA market this is the token the underlying wraps rather than the
120
- * wrapper itself, because only that token means anything to a reader. The
121
- * wrapper converts one-for-one, so amounts denominated in it stay exact.
121
+ * wrapper itself, e.g. USDC rather than dcUSDC (which will be "wrappedAddress" in this case)
122
122
  */
123
123
  get underlyingToken() {
124
- return this.tokensMeta.mustGetToken(this.unwrappedUnderlying);
124
+ return {
125
+ ...this.tokensMeta.mustGetToken(this.unwrappedUnderlying),
126
+ wrappedAddress: isAddressEqual(this.underlying, this.unwrappedUnderlying) ? null : this.underlying
127
+ };
125
128
  }
126
129
  /**
127
130
  * Display name of this market's pool, e.g. `"USDC Pool"`.
@@ -92,8 +92,8 @@ var PoolSuite = class extends SDKConstruct {
92
92
  return this.register.mustGetContract(this.#marketConfigurator);
93
93
  }
94
94
  /**
95
- * Underlying asset deposited into the pool and borrowed by connected credit
96
- * suites.
95
+ * Underlying token of the market pool, as returned by contract.
96
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
97
97
  */
98
98
  get underlying() {
99
99
  return this.pool.underlying;
@@ -417,6 +417,7 @@ var PoolService = class extends SDKConstruct {
417
417
  name: this.sdk.tokensMeta.mustGetToken(pool.address).name,
418
418
  chainId: this.chainId,
419
419
  pool: pool.address,
420
+ underlyingToken: market.underlyingToken,
420
421
  netValue: {
421
422
  token: this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying),
422
423
  ...market.priceOracle.toAmount(market.underlying, shares * pool.dieselRate / RAY)
@@ -176,7 +176,7 @@ var PositionsService = class extends SDKConstruct {
176
176
  const { market } = suite;
177
177
  const { priceOracle } = market;
178
178
  const { pool } = market.pool;
179
- const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
179
+ const token = market.underlyingToken;
180
180
  const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
181
181
  const target = getAccountTargetCollateral(ca.creditAccount, this.sdk.chainId) ?? suite.strategyTargetCollateral;
182
182
  const snapshot = accountSnapshotFromCreditAccountData(ca);
@@ -206,6 +206,7 @@ var PositionsService = class extends SDKConstruct {
206
206
  chainId: this.sdk.chainId,
207
207
  creditManager: ca.creditManager,
208
208
  creditAccount: ca.creditAccount,
209
+ underlyingToken: token,
209
210
  name: target ? strategyName(this.sdk.tokensMeta.mustGetToken(target), token) : token.symbol,
210
211
  targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
211
212
  leverage: calcPositionLeverage(totalValue, totalDebtValue),
@@ -41,6 +41,15 @@ var BigIntMath = class {
41
41
  * @returns A non-positive bigint representation of `a`.
42
42
  */
43
43
  static neg = (a) => a > 0 ? a * -1n : a;
44
+ /**
45
+ * Divides rounding toward positive infinity.
46
+ *
47
+ * @param a - Dividend; must not be negative.
48
+ * @param b - Divisor; must be positive — zero throws, negative returns
49
+ * nonsense rather than the ceiling.
50
+ * @returns The smallest integer that is at least `a / b`.
51
+ **/
52
+ static ceilDiv = (a, b) => (a + b - 1n) / b;
44
53
  };
45
54
  //#endregion
46
55
  export { BigIntMath };
@@ -1,4 +1,4 @@
1
- import { Amount, Asset, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall } from "./primitives.js";
1
+ import { Amount, Asset, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall, UnderlyingToken } from "./primitives.js";
2
2
  import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, GridSampling, OpportunityChartMetric, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PoolOpportunityChartMetric, PoolPositionChartMetric, PositionChartMetric, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, StrategyOpportunityChartMetric, StrategyPositionChartMetric } from "./charts.js";
3
3
  import { chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, poolOpportunityChartMetricSchema, poolPositionChartMetricSchema, strategyOpportunityChartMetricSchema, strategyPositionChartMetricSchema } from "./charts.schema.js";
4
4
  import { CompareTag, CompareTolerance, ToleranceCompareTag, compareTagOf, offchainOnly, onchainOnly, tolerance } from "./compare.schema.js";
@@ -16,7 +16,7 @@ import { noticeKindSchema, noticeSchema } from "./notices.schema.js";
16
16
  import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
17
17
  import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
18
18
  import { AdjustCreditAccountPreview, CloseCreditAccountPreview, DelayedCreditAccountOperationPreview, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, InstantOperationPreview, OpenCreditAccountPreview, OperationPreview, OperationPreviewError, PoolOperationPreview, PoolOperationType, PreviewOperationInput, PreviewOperationOptions, RepayCreditAccountPreview } from "./previews.js";
19
- import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
19
+ import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema, underlyingTokenSchema } from "./primitives.schema.js";
20
20
  import { ChainFailed, ChainMetadata, ChainScoped, ChainSucceeded, DataResponse, DataSource, ResponseMetadata } from "./response.js";
21
21
  import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
22
- export { AdjustCreditAccountPreview, Amount, ApyBreakdown, Asset, AssetType, BorrowRateBreakdown, Bps, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, CloseCreditAccountPreview, CompareTag, CompareTolerance, Curator, CuratorName, DataResponse, DataSource, DelayedAddCollateralIntent, DelayedCloseAccountIntent, DelayedCreditAccountOperationPreview, DelayedDecreaseLeverageIntent, DelayedDepositAndIncreaseLeverageIntent, DelayedDepositIntent, DelayedIncreaseLeverageIntent, DelayedIntent, DelayedReceivedAsset, DelayedWithdrawCollateralIntent, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, FILTER_ALL, FilterAll, Filterable, GridSampling, InstantOperationPreview, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Notice, NoticeKind, NoticeSubject, OpenCreditAccountPreview, OperationPreview, OperationPreviewError, Opportunity, OpportunityBase, OpportunityChartMetric, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolOperationPreview, PoolOperationType, PoolOpportunity, PoolOpportunityChartMetric, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionChartMetric, PoolPositionKey, PoolPositionRef, Position, PositionChartMetric, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, PositionTransaction, PositionTransactionKind, PositionsTotals, PreviewOperationInput, PreviewOperationOptions, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, RepayCreditAccountPreview, ResponseMetadata, Rewards, RewardsPnL, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, StrategyOpportunity, StrategyOpportunityChartMetric, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionChartMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenQuotaRate, TokenRewards, TokenRewardsPnL, ToleranceCompareTag, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema };
22
+ export { AdjustCreditAccountPreview, Amount, ApyBreakdown, Asset, AssetType, BorrowRateBreakdown, Bps, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, ChartBundle, ChartDenomination, ChartMetric, ChartQuery, ChartRange, ChartSeries, ChartSeriesOk, ChartSeriesUnavailable, ChartUnavailableCode, ChartUnit, ChartValue, ChartWindow, CloseCreditAccountPreview, CompareTag, CompareTolerance, Curator, CuratorName, DataResponse, DataSource, DelayedAddCollateralIntent, DelayedCloseAccountIntent, DelayedCreditAccountOperationPreview, DelayedDecreaseLeverageIntent, DelayedDepositAndIncreaseLeverageIntent, DelayedDepositIntent, DelayedIncreaseLeverageIntent, DelayedIntent, DelayedReceivedAsset, DelayedWithdrawCollateralIntent, ERROR_ADAPTER_CALL_OUTSIDE_BRACKET, ERROR_INVALID_TRANSACTION_VALUE, ERROR_MALFORMED_BRACKET, ERROR_NON_ADAPTER_CALL_IN_BRACKET, ERROR_UNPREVIEWABLE_ADAPTER_CALL, ERROR_UNPREVIEWABLE_RWA_WRAP_UNWRAP, ERROR_UNPRICEABLE_TOKEN, FILTER_ALL, FilterAll, Filterable, GridSampling, InstantOperationPreview, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Notice, NoticeKind, NoticeSubject, OpenCreditAccountPreview, OperationPreview, OperationPreviewError, Opportunity, OpportunityBase, OpportunityChartMetric, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolOperationPreview, PoolOperationType, PoolOpportunity, PoolOpportunityChartMetric, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionChartMetric, PoolPositionKey, PoolPositionRef, Position, PositionChartMetric, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, PositionTransaction, PositionTransactionKind, PositionsTotals, PreviewOperationInput, PreviewOperationOptions, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, RepayCreditAccountPreview, ResponseMetadata, Rewards, RewardsPnL, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, StrategyOpportunity, StrategyOpportunityChartMetric, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionChartMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenQuotaRate, TokenRewards, TokenRewardsPnL, ToleranceCompareTag, TxCall, UnderlyingToken, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema };
@@ -1,4 +1,4 @@
1
- import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token } from "./primitives.js";
1
+ import { Amount, AssetType, Bps, ChainId, Leverage, Timestamp, Token, UnderlyingToken } from "./primitives.js";
2
2
  import { Curator } from "./curators.js";
3
3
  import { ChainScopedFilter, Filterable } from "./filters.js";
4
4
  import { Address } from "viem";
@@ -127,10 +127,10 @@ interface OpportunityBase {
127
127
  * Token that is supplied to the pool and borrowed by credit accounts. All
128
128
  * amounts of the opportunity are denominated in it.
129
129
  *
130
- * For RWA markets it's an unwrapped, e.g. — `USDC`, not `dcUSDC` (pool underlying according to contract).
131
- * The wrapper converts one-for-one, so every amount stays exact.
130
+ * For RWA markets this is the unwrapped asset, e.g. USDC rather than
131
+ * dcUSDC (the pool's on-chain underlying).
132
132
  **/
133
- underlyingToken: Token;
133
+ underlyingToken: UnderlyingToken;
134
134
  /**
135
135
  * Tokens a user can transfer from their wallet to deposit into a pool
136
136
  * position or to use when opening a credit account. They are not necessarily
@@ -126,6 +126,7 @@ declare const opportunityBaseSchema: z.ZodObject<{
126
126
  name: z.ZodString;
127
127
  decimals: z.ZodNumber;
128
128
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
129
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
129
130
  }, z.core.$strip>;
130
131
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
131
132
  chainId: z.ZodNumber;
@@ -199,6 +200,7 @@ declare const poolOpportunitySchema: z.ZodObject<{
199
200
  name: z.ZodString;
200
201
  decimals: z.ZodNumber;
201
202
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
203
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
202
204
  }, z.core.$strip>;
203
205
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
204
206
  chainId: z.ZodNumber;
@@ -331,6 +333,7 @@ declare const strategyOpportunitySchema: z.ZodObject<{
331
333
  name: z.ZodString;
332
334
  decimals: z.ZodNumber;
333
335
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
336
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
334
337
  }, z.core.$strip>;
335
338
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
336
339
  chainId: z.ZodNumber;
@@ -469,6 +472,7 @@ declare const opportunitySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
469
472
  name: z.ZodString;
470
473
  decimals: z.ZodNumber;
471
474
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
475
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
472
476
  }, z.core.$strip>;
473
477
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
474
478
  chainId: z.ZodNumber;
@@ -597,6 +601,7 @@ declare const opportunitySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
597
601
  name: z.ZodString;
598
602
  decimals: z.ZodNumber;
599
603
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
604
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
600
605
  }, z.core.$strip>;
601
606
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
602
607
  chainId: z.ZodNumber;
@@ -842,6 +847,7 @@ declare const poolOpportunityDetailSchema: z.ZodObject<{
842
847
  name: z.ZodString;
843
848
  decimals: z.ZodNumber;
844
849
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
850
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
845
851
  }, z.core.$strip>;
846
852
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
847
853
  chainId: z.ZodNumber;
@@ -982,6 +988,7 @@ declare const strategyOpportunityDetailSchema: z.ZodObject<{
982
988
  name: z.ZodString;
983
989
  decimals: z.ZodNumber;
984
990
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
991
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
985
992
  }, z.core.$strip>;
986
993
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
987
994
  chainId: z.ZodNumber;
@@ -1145,6 +1152,7 @@ declare const opportunityDetailSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1145
1152
  name: z.ZodString;
1146
1153
  decimals: z.ZodNumber;
1147
1154
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
1155
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
1148
1156
  }, z.core.$strip>;
1149
1157
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
1150
1158
  chainId: z.ZodNumber;
@@ -1281,6 +1289,7 @@ declare const opportunityDetailSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1281
1289
  name: z.ZodString;
1282
1290
  decimals: z.ZodNumber;
1283
1291
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
1292
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
1284
1293
  }, z.core.$strip>;
1285
1294
  allowedDepositTokens: z.ZodArray<z.ZodObject<{
1286
1295
  chainId: z.ZodNumber;
@@ -1,4 +1,4 @@
1
- import { AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount } from "./primitives.js";
1
+ import { AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, UnderlyingToken } from "./primitives.js";
2
2
  import { ChainScopedFilter, Filterable } from "./filters.js";
3
3
  import { DelayedReceivedAsset, LiquidationPosition } from "./liquidations.js";
4
4
  import { ApyBreakdown, PointsProgram } from "./opportunities.js";
@@ -113,6 +113,13 @@ interface PoolPosition {
113
113
  * Address of the ERC-4626 pool contract.
114
114
  **/
115
115
  pool: Address;
116
+ /**
117
+ * Pool underlying token.
118
+ *
119
+ * For RWA markets this is the unwrapped asset, e.g. USDC rather than
120
+ * dcUSDC (the pool's on-chain underlying).
121
+ **/
122
+ underlyingToken: UnderlyingToken;
116
123
  /**
117
124
  * Underlying the held shares are worth at the current share rate, i.e.
118
125
  * `pool.convertToAssets(pool.balanceOf(wallet))`.
@@ -199,6 +206,13 @@ interface StrategyPosition {
199
206
  * Credit account address.
200
207
  **/
201
208
  creditAccount: Address;
209
+ /**
210
+ * Pool underlying token.
211
+ *
212
+ * For RWA markets this is the unwrapped asset, e.g. USDC rather than
213
+ * dcUSDC (the pool's on-chain underlying).
214
+ **/
215
+ underlyingToken: UnderlyingToken;
202
216
  /**
203
217
  * Collateral token this position is a strategy in.
204
218
  **/
@@ -171,6 +171,15 @@ declare const poolPositionSchema: z.ZodObject<{
171
171
  name: z.ZodString;
172
172
  chainId: z.ZodNumber;
173
173
  pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
174
+ underlyingToken: z.ZodObject<{
175
+ chainId: z.ZodNumber;
176
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
177
+ symbol: z.ZodString;
178
+ name: z.ZodString;
179
+ decimals: z.ZodNumber;
180
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
181
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
182
+ }, z.core.$strip>;
174
183
  netValue: z.ZodObject<{
175
184
  value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
176
185
  valueUsd: z.ZodNullable<z.ZodNumber>;
@@ -321,6 +330,15 @@ declare const strategyPositionSchema: z.ZodObject<{
321
330
  chainId: z.ZodNumber;
322
331
  creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
323
332
  creditAccount: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
333
+ underlyingToken: z.ZodObject<{
334
+ chainId: z.ZodNumber;
335
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
336
+ symbol: z.ZodString;
337
+ name: z.ZodString;
338
+ decimals: z.ZodNumber;
339
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
340
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
341
+ }, z.core.$strip>;
324
342
  targetCollateral: z.ZodNullable<z.ZodObject<{
325
343
  chainId: z.ZodNumber;
326
344
  address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
@@ -536,6 +554,15 @@ declare const positionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
536
554
  name: z.ZodString;
537
555
  chainId: z.ZodNumber;
538
556
  pool: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
557
+ underlyingToken: z.ZodObject<{
558
+ chainId: z.ZodNumber;
559
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
560
+ symbol: z.ZodString;
561
+ name: z.ZodString;
562
+ decimals: z.ZodNumber;
563
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
564
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
565
+ }, z.core.$strip>;
539
566
  netValue: z.ZodObject<{
540
567
  value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
541
568
  valueUsd: z.ZodNullable<z.ZodNumber>;
@@ -649,6 +676,15 @@ declare const positionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
649
676
  chainId: z.ZodNumber;
650
677
  creditManager: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
651
678
  creditAccount: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
679
+ underlyingToken: z.ZodObject<{
680
+ chainId: z.ZodNumber;
681
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
682
+ symbol: z.ZodString;
683
+ name: z.ZodString;
684
+ decimals: z.ZodNumber;
685
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
686
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
687
+ }, z.core.$strip>;
652
688
  targetCollateral: z.ZodNullable<z.ZodObject<{
653
689
  chainId: z.ZodNumber;
654
690
  address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
@@ -156,6 +156,22 @@ interface Token {
156
156
  **/
157
157
  assetType?: AssetType;
158
158
  }
159
+ /**
160
+ * A market's underlying as the shared read model describes it.
161
+ *
162
+ * For an RWA market this is the token the wrapper holds (e.g. USDC) rather
163
+ * than the wrapper itself (e.g. dcUSDC). The wrapper converts one-for-one, so
164
+ * amounts denominated in it stay exact; {@link wrappedAddress} names the
165
+ * wrapper when there is one.
166
+ **/
167
+ interface UnderlyingToken extends Token {
168
+ /**
169
+ * Address of the compliance wrapper the pool actually holds (e.g. dcUSDC)
170
+ * when the market underlying is an RWA wrapper, or `null` when the
171
+ * underlying is the token itself.
172
+ **/
173
+ wrappedAddress: Address | null;
174
+ }
159
175
  /**
160
176
  * An {@link Amount} that names its own token.
161
177
  **/
@@ -186,4 +202,4 @@ interface TxCall {
186
202
  value?: bigint;
187
203
  }
188
204
  //#endregion
189
- export { Amount, Asset, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall };
205
+ export { Amount, Asset, AssetType, Bps, ChainId, Leverage, Timestamp, Token, TokenAmount, TxCall, UnderlyingToken };
@@ -47,6 +47,18 @@ declare const tokenSchema: z.ZodObject<{
47
47
  decimals: z.ZodNumber;
48
48
  assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
49
49
  }, z.core.$strip>;
50
+ /**
51
+ * {@link UnderlyingToken}
52
+ **/
53
+ declare const underlyingTokenSchema: z.ZodObject<{
54
+ chainId: z.ZodNumber;
55
+ address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
56
+ symbol: z.ZodString;
57
+ name: z.ZodString;
58
+ decimals: z.ZodNumber;
59
+ assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
60
+ wrappedAddress: z.ZodNullable<z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>>;
61
+ }, z.core.$strip>;
50
62
  /**
51
63
  * {@link TokenAmount}
52
64
  **/
@@ -71,4 +83,4 @@ declare const txCallSchema: z.ZodObject<{
71
83
  value: z.ZodOptional<z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>>;
72
84
  }, z.core.$strip>;
73
85
  //#endregion
74
- export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema };
86
+ export { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema, underlyingTokenSchema };
@@ -1,4 +1,4 @@
1
- import { Token } from "../../model/primitives.js";
1
+ import { Token, UnderlyingToken } from "../../model/primitives.js";
2
2
  import { Curator } from "../../model/curators.js";
3
3
  import { Opportunity, OpportunityFilter, PoolOpportunity, PoolOpportunityDetail, PriceFeedSummary, QuotaAsset } from "../../model/opportunities.js";
4
4
  import "../../model/index.js";
@@ -81,7 +81,8 @@ declare class MarketSuite extends SDKConstruct {
81
81
  */
82
82
  constructor(sdk: OnchainSDK, marketData: MarketData);
83
83
  /**
84
- * Underlying token of the market pool.
84
+ * Underlying token of the market pool, as returned by contract.
85
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
85
86
  */
86
87
  get underlying(): Address;
87
88
  /**
@@ -97,10 +98,9 @@ declare class MarketSuite extends SDKConstruct {
97
98
  * The market's underlying as the shared read model describes it.
98
99
  *
99
100
  * For an RWA market this is the token the underlying wraps rather than the
100
- * wrapper itself, because only that token means anything to a reader. The
101
- * wrapper converts one-for-one, so amounts denominated in it stay exact.
101
+ * wrapper itself, e.g. USDC rather than dcUSDC (which will be "wrappedAddress" in this case)
102
102
  */
103
- get underlyingToken(): Token;
103
+ get underlyingToken(): UnderlyingToken;
104
104
  /**
105
105
  * Display name of this market's pool, e.g. `"USDC Pool"`.
106
106
  */
@@ -80,8 +80,8 @@ declare class PoolSuite extends SDKConstruct {
80
80
  */
81
81
  get marketConfigurator(): MarketConfiguratorContract;
82
82
  /**
83
- * Underlying asset deposited into the pool and borrowed by connected credit
84
- * suites.
83
+ * Underlying token of the market pool, as returned by contract.
84
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
85
85
  */
86
86
  get underlying(): Address;
87
87
  /**
@@ -45,6 +45,7 @@ interface IPoolContract extends IBaseContract {
45
45
  interestRateModel: Address;
46
46
  /**
47
47
  * Pool's underlying token, same as `asset()`.
48
+ * For RWA markets this is a wrapped token (e.g. dcUSDC, rather than USDC)
48
49
  */
49
50
  underlying: Address;
50
51
  /**
@@ -37,6 +37,15 @@ declare class BigIntMath {
37
37
  * @returns A non-positive bigint representation of `a`.
38
38
  */
39
39
  static neg: (a: bigint) => bigint;
40
+ /**
41
+ * Divides rounding toward positive infinity.
42
+ *
43
+ * @param a - Dividend; must not be negative.
44
+ * @param b - Divisor; must be positive — zero throws, negative returns
45
+ * nonsense rather than the ceiling.
46
+ * @returns The smallest integer that is at least `a / b`.
47
+ **/
48
+ static ceilDiv: (a: bigint, b: bigint) => bigint;
40
49
  }
41
50
  //#endregion
42
51
  export { BigIntMath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.6",
3
+ "version": "16.0.0-next.8",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {