@gearbox-protocol/sdk 16.0.0-next.23 → 16.0.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.
@@ -81,8 +81,8 @@ async function previewOpenStrategy(props) {
81
81
  require_onchain_accounts_intents_guards.assertQuotaHeadroom(sdk, market, averageQuota);
82
82
  const snapshot = {
83
83
  creditManager,
84
- assets: averageAssets,
85
- quotas: averageQuota,
84
+ assets: minAssets,
85
+ quotas: minQuota,
86
86
  totalDebt: debt,
87
87
  totalValue: margin + debt
88
88
  };
@@ -101,6 +101,8 @@ async function previewOpenStrategy(props) {
101
101
  toUnderlying: (from, amount) => convert(from, underlying, amount)
102
102
  });
103
103
  return {
104
+ creditManager,
105
+ name: suite.name,
104
106
  totalDebt: market.toUnderlyingAmount(debt),
105
107
  netValue: market.toUnderlyingAmount(margin),
106
108
  totalValue: market.toUnderlyingAmount(margin + debt),
@@ -288,8 +288,11 @@ async function realize(steps, props) {
288
288
  });
289
289
  const oracle = market.priceOracle;
290
290
  const state = {
291
+ creditManager: creditAccount.creditManager,
292
+ name: suite.name,
291
293
  totalValue: market.toUnderlyingAmount(totalValue),
292
294
  totalDebt: market.toUnderlyingAmount(debt),
295
+ netValue: market.toUnderlyingAmount(totalValue - debt),
293
296
  leverage: require_onchain_market_math.calcPositionLeverage(totalValue, debt),
294
297
  assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
295
298
  quotas: Object.values(quotasAfter).map((q) => ({
@@ -203,6 +203,7 @@ function buildMockSdk(args) {
203
203
  const facadePaused = args.facadePaused ?? false;
204
204
  const expirationDate = args.expirationDate ?? 0;
205
205
  const creditManagerSuite = {
206
+ name: "TestCreditManager",
206
207
  creditManager: {
207
208
  address: args.creditManager,
208
209
  liquidationThresholds,
@@ -190,6 +190,7 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
190
190
  collateralWithdrawn: collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
191
191
  totalValue: market.toUnderlyingAmount(totalValue),
192
192
  totalDebt: market.toUnderlyingAmount(post.totalDebt),
193
+ netValue: market.toUnderlyingAmount(totalValue - post.totalDebt),
193
194
  totalDebtChange: market.toUnderlyingAmount(post.totalDebt - before.totalDebt),
194
195
  quotas: quotas.map((q) => ({
195
196
  token: sdk.tokensMeta.mustGetToken(q.token),
@@ -48,6 +48,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
48
48
  collateralWithdrawn: after.collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
49
49
  totalValue: market.toUnderlyingAmount(totalValue),
50
50
  totalDebt: market.toUnderlyingAmount(account.totalDebt),
51
+ netValue: market.toUnderlyingAmount(totalValue - account.totalDebt),
51
52
  totalDebtChange: market.toUnderlyingAmount(account.totalDebt - before.totalDebt),
52
53
  quotas: quotas.map((q) => ({
53
54
  token: sdk.tokensMeta.mustGetToken(q.token),
@@ -25,8 +25,8 @@ const require_preview_validate_checkOperation = require("./checkOperation.js");
25
25
  * came back `ok` has already passed them.
26
26
  */
27
27
  function checkSimulation(input, options = {}) {
28
- const { sdk, state, creditManager } = input;
29
- const suite = sdk.marketRegister.findCreditManager(creditManager);
28
+ const { sdk, state } = input;
29
+ const suite = sdk.marketRegister.findCreditManager(state.creditManager);
30
30
  return require_preview_validate_checkOperation.marketIssues(suite) || require_onchain_validation_checks.checkDebtInBand({
31
31
  debt: state.totalDebt.value,
32
32
  minDebt: suite.creditFacade.minDebt,
@@ -80,8 +80,8 @@ async function previewOpenStrategy(props) {
80
80
  assertQuotaHeadroom(sdk, market, averageQuota);
81
81
  const snapshot = {
82
82
  creditManager,
83
- assets: averageAssets,
84
- quotas: averageQuota,
83
+ assets: minAssets,
84
+ quotas: minQuota,
85
85
  totalDebt: debt,
86
86
  totalValue: margin + debt
87
87
  };
@@ -100,6 +100,8 @@ async function previewOpenStrategy(props) {
100
100
  toUnderlying: (from, amount) => convert(from, underlying, amount)
101
101
  });
102
102
  return {
103
+ creditManager,
104
+ name: suite.name,
103
105
  totalDebt: market.toUnderlyingAmount(debt),
104
106
  netValue: market.toUnderlyingAmount(margin),
105
107
  totalValue: market.toUnderlyingAmount(margin + debt),
@@ -287,8 +287,11 @@ async function realize(steps, props) {
287
287
  });
288
288
  const oracle = market.priceOracle;
289
289
  const state = {
290
+ creditManager: creditAccount.creditManager,
291
+ name: suite.name,
290
292
  totalValue: market.toUnderlyingAmount(totalValue),
291
293
  totalDebt: market.toUnderlyingAmount(debt),
294
+ netValue: market.toUnderlyingAmount(totalValue - debt),
292
295
  leverage: calcPositionLeverage(totalValue, debt),
293
296
  assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
294
297
  quotas: Object.values(quotasAfter).map((q) => ({
@@ -203,6 +203,7 @@ function buildMockSdk(args) {
203
203
  const facadePaused = args.facadePaused ?? false;
204
204
  const expirationDate = args.expirationDate ?? 0;
205
205
  const creditManagerSuite = {
206
+ name: "TestCreditManager",
206
207
  creditManager: {
207
208
  address: args.creditManager,
208
209
  liquidationThresholds,
@@ -189,6 +189,7 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
189
189
  collateralWithdrawn: collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
190
190
  totalValue: market.toUnderlyingAmount(totalValue),
191
191
  totalDebt: market.toUnderlyingAmount(post.totalDebt),
192
+ netValue: market.toUnderlyingAmount(totalValue - post.totalDebt),
192
193
  totalDebtChange: market.toUnderlyingAmount(post.totalDebt - before.totalDebt),
193
194
  quotas: quotas.map((q) => ({
194
195
  token: sdk.tokensMeta.mustGetToken(q.token),
@@ -47,6 +47,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
47
47
  collateralWithdrawn: after.collateralWithdrawn.toAssets().map((a) => oracle.toTokenAmount(a.token, a.balance)),
48
48
  totalValue: market.toUnderlyingAmount(totalValue),
49
49
  totalDebt: market.toUnderlyingAmount(account.totalDebt),
50
+ netValue: market.toUnderlyingAmount(totalValue - account.totalDebt),
50
51
  totalDebtChange: market.toUnderlyingAmount(account.totalDebt - before.totalDebt),
51
52
  quotas: quotas.map((q) => ({
52
53
  token: sdk.tokensMeta.mustGetToken(q.token),
@@ -24,8 +24,8 @@ import { collateralIssue, marketIssues, quotaCountIssue } from "./checkOperation
24
24
  * came back `ok` has already passed them.
25
25
  */
26
26
  function checkSimulation(input, options = {}) {
27
- const { sdk, state, creditManager } = input;
28
- const suite = sdk.marketRegister.findCreditManager(creditManager);
27
+ const { sdk, state } = input;
28
+ const suite = sdk.marketRegister.findCreditManager(state.creditManager);
29
29
  return marketIssues(suite) || checkDebtInBand({
30
30
  debt: state.totalDebt.value,
31
31
  minDebt: suite.creditFacade.minDebt,
@@ -147,6 +147,16 @@ interface PoolOperationPreview {
147
147
  * names — an RWA market reports USDC, not the dcUSDC wrapper the pool holds.
148
148
  **/
149
149
  interface AccountProjection {
150
+ /**
151
+ * Credit manager the account belongs to. Carried on the projection itself so
152
+ * a caller weighing one — `checkSimulation` among them — needs nothing beside
153
+ * it to find the market.
154
+ */
155
+ creditManager: Address;
156
+ /**
157
+ * Human-readable credit manager name.
158
+ */
159
+ name: string;
150
160
  /**
151
161
  * Health factor in basis points: below `10000` the account is liquidatable.
152
162
  *
@@ -196,6 +206,13 @@ interface AccountProjection {
196
206
  * fees, in the market's underlying.
197
207
  **/
198
208
  totalDebt: TokenAmount;
209
+ /**
210
+ * Own funds in the position: `totalValue` less `totalDebt`, in the market's
211
+ * underlying. The read model leaves a strategy caller to subtract these two
212
+ * itself; a projection reports the figure so an "own funds" row reads the
213
+ * same on every screen that shows one.
214
+ **/
215
+ netValue: TokenAmount;
199
216
  /**
200
217
  * What the account holds, token by token.
201
218
  **/
@@ -210,14 +227,6 @@ interface AccountProjection {
210
227
  }
211
228
  interface OpenCreditAccountPreview extends AccountProjection {
212
229
  operation: "OpenCreditAccount" | "RWAOpenCreditAccount";
213
- /**
214
- * Credit manager the account is opened in
215
- */
216
- creditManager: Address;
217
- /**
218
- * Human-readable credit manager name
219
- */
220
- name: string;
221
230
  /**
222
231
  * Collateral token this position is a strategy in: the first quoted token,
223
232
  * with its balance taken from `assets`. Undefined when nothing is quoted.
@@ -231,11 +240,6 @@ interface OpenCreditAccountPreview extends AccountProjection {
231
240
  * accordingly (omitted entirely when it reaches zero).
232
241
  */
233
242
  collateralAdded: TokenAmount[];
234
- /**
235
- * Own funds in the position: what the wallet put in, valued in underlying.
236
- * `totalValue` is this plus the borrowed amount.
237
- */
238
- netValue: TokenAmount;
239
243
  /**
240
244
  * Set when preview encountered non-fatal errors, all fields are
241
245
  * still computed best-effort, but derived fields (`assets`,
@@ -245,14 +249,6 @@ interface OpenCreditAccountPreview extends AccountProjection {
245
249
  }
246
250
  interface AdjustCreditAccountPreview extends AccountProjection {
247
251
  operation: "AdjustCreditAccount";
248
- /**
249
- * Credit manager the account is opened in
250
- */
251
- creditManager: Address;
252
- /**
253
- * Human-readable credit manager name
254
- */
255
- name: string;
256
252
  /**
257
253
  * Credit account that is being adjusted
258
254
  */
@@ -39,8 +39,6 @@ interface OpenStrategyPreview extends Omit<AccountProjection, "assets" | "quotas
39
39
  * opening always hands the pool's funds over.
40
40
  **/
41
41
  safeHealthFactor: Bps;
42
- /** Own funds put in, valued in underlying. */
43
- netValue: TokenAmount;
44
42
  /** What the routed leg lost to market depth; `undefined` if not measured. */
45
43
  priceImpact: PathLossRate | undefined;
46
44
  /** Expected post-open balances. */
@@ -3,7 +3,6 @@ import { PreviewIssue } from "../../onchain/validation/refusal.js";
3
3
  import { OperationState } from "../../onchain/accounts/intents/types.js";
4
4
  import "../../onchain/index.js";
5
5
  import { CheckOperationOptions } from "./checkOperation.js";
6
- import { Address } from "viem";
7
6
  //#region src/preview/validate/checkSimulation.d.ts
8
7
  /**
9
8
  * Whether a simulated operation clears the caller's own bars.
@@ -28,7 +27,6 @@ import { Address } from "viem";
28
27
  declare function checkSimulation(input: {
29
28
  sdk: OnchainSDK;
30
29
  state: OperationState;
31
- creditManager: Address;
32
30
  }, options?: CheckOperationOptions): PreviewIssue | null;
33
31
  //#endregion
34
32
  export { checkSimulation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.23",
3
+ "version": "16.0.0-next.25",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {