@gearbox-protocol/sdk 10.6.0 → 10.7.1

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.
@@ -184,7 +184,15 @@ const retryCodes = /* @__PURE__ */ new Set([
184
184
  const defaultShouldRetry = ({
185
185
  error
186
186
  }) => {
187
- if (error instanceof import_viem.CallExecutionError && error.details === "header not found") {
187
+ const callExError = error instanceof import_viem.BaseError && error.walk(
188
+ (e) => e instanceof import_viem.CallExecutionError && e.details === "header not found"
189
+ );
190
+ if (callExError && [
191
+ "unknown block",
192
+ "header not found",
193
+ "resource unavailable",
194
+ "requested resource not available"
195
+ ].some((s) => callExError.details.toLowerCase().includes(s))) {
188
196
  return true;
189
197
  }
190
198
  if ("code" in error && typeof error.code === "number") {
@@ -265,7 +265,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
265
265
  slippage = 50n,
266
266
  force = false,
267
267
  keepAssets,
268
- ignoreReservePrices
268
+ ignoreReservePrices,
269
+ applyLossPolicy
269
270
  } = props;
270
271
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
271
272
  const routerCloseResult = await this.sdk.routerFor(account).findBestClosePath({
@@ -281,12 +282,28 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
281
282
  ignoreReservePrices
282
283
  });
283
284
  const calls = [...priceUpdates, ...routerCloseResult.calls];
285
+ let lossPolicyData;
286
+ if (applyLossPolicy) {
287
+ const market = this.sdk.marketRegister.findByCreditManager(
288
+ account.creditManager
289
+ );
290
+ lossPolicyData = await market.lossPolicy.getLiquidationData(
291
+ account.creditAccount
292
+ );
293
+ }
284
294
  const tx = cm.creditFacade.liquidateCreditAccount(
285
295
  account.creditAccount,
286
296
  to,
287
- calls
297
+ calls,
298
+ lossPolicyData
288
299
  );
289
- return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
300
+ return {
301
+ tx,
302
+ calls,
303
+ routerCloseResult,
304
+ lossPolicyData,
305
+ creditFacade: cm.creditFacade
306
+ };
290
307
  }
291
308
  /**
292
309
  * Closes credit account or closes credit account and keeps it open with zero debt.
@@ -21,6 +21,7 @@ __export(AliasLossPolicyV310Contract_exports, {
21
21
  AliasLossPolicyV310Contract: () => AliasLossPolicyV310Contract
22
22
  });
23
23
  module.exports = __toCommonJS(AliasLossPolicyV310Contract_exports);
24
+ var import_viem = require("viem");
24
25
  var import_generated = require("../../../abi/310/generated.js");
25
26
  var import_base = require("../../base/index.js");
26
27
  const abi = import_generated.iAliasedLossPolicyV310Abi;
@@ -33,6 +34,31 @@ class AliasLossPolicyV310Contract extends import_base.BaseContract {
33
34
  version: params.version
34
35
  });
35
36
  }
37
+ async getLiquidationData(creditAccount, blockNumber) {
38
+ const pfs = await this.sdk.client.readContract({
39
+ address: this.address,
40
+ abi: this.abi,
41
+ functionName: "getRequiredAliasPriceFeeds",
42
+ args: [creditAccount],
43
+ blockNumber
44
+ });
45
+ const updates = await this.sdk.priceFeeds.generateExternalPriceFeedsUpdates(
46
+ [...pfs],
47
+ blockNumber ? { blockNumber } : void 0
48
+ );
49
+ return (0, import_viem.encodeAbiParameters)(
50
+ [
51
+ {
52
+ type: "tuple[]",
53
+ components: [
54
+ { type: "address", name: "priceFeed" },
55
+ { type: "bytes", name: "data" }
56
+ ]
57
+ }
58
+ ],
59
+ [updates]
60
+ );
61
+ }
36
62
  }
37
63
  // Annotate the CommonJS export names for ESM import in node:
38
64
  0 && (module.exports = {
@@ -33,6 +33,9 @@ class LossPolicyContract extends import_base.BaseContract {
33
33
  version: params.version
34
34
  });
35
35
  }
36
+ async getLiquidationData(_creditAccount, _blockNumber) {
37
+ return void 0;
38
+ }
36
39
  }
37
40
  // Annotate the CommonJS export names for ESM import in node:
38
41
  0 && (module.exports = {
@@ -172,7 +172,15 @@ const retryCodes = /* @__PURE__ */ new Set([
172
172
  const defaultShouldRetry = ({
173
173
  error
174
174
  }) => {
175
- if (error instanceof CallExecutionError && error.details === "header not found") {
175
+ const callExError = error instanceof BaseError && error.walk(
176
+ (e) => e instanceof CallExecutionError && e.details === "header not found"
177
+ );
178
+ if (callExError && [
179
+ "unknown block",
180
+ "header not found",
181
+ "resource unavailable",
182
+ "requested resource not available"
183
+ ].some((s) => callExError.details.toLowerCase().includes(s))) {
176
184
  return true;
177
185
  }
178
186
  if ("code" in error && typeof error.code === "number") {
@@ -255,7 +255,8 @@ class AbstractCreditAccountService extends SDKConstruct {
255
255
  slippage = 50n,
256
256
  force = false,
257
257
  keepAssets,
258
- ignoreReservePrices
258
+ ignoreReservePrices,
259
+ applyLossPolicy
259
260
  } = props;
260
261
  const cm = this.sdk.marketRegister.findCreditManager(account.creditManager);
261
262
  const routerCloseResult = await this.sdk.routerFor(account).findBestClosePath({
@@ -271,12 +272,28 @@ class AbstractCreditAccountService extends SDKConstruct {
271
272
  ignoreReservePrices
272
273
  });
273
274
  const calls = [...priceUpdates, ...routerCloseResult.calls];
275
+ let lossPolicyData;
276
+ if (applyLossPolicy) {
277
+ const market = this.sdk.marketRegister.findByCreditManager(
278
+ account.creditManager
279
+ );
280
+ lossPolicyData = await market.lossPolicy.getLiquidationData(
281
+ account.creditAccount
282
+ );
283
+ }
274
284
  const tx = cm.creditFacade.liquidateCreditAccount(
275
285
  account.creditAccount,
276
286
  to,
277
- calls
287
+ calls,
288
+ lossPolicyData
278
289
  );
279
- return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
290
+ return {
291
+ tx,
292
+ calls,
293
+ routerCloseResult,
294
+ lossPolicyData,
295
+ creditFacade: cm.creditFacade
296
+ };
280
297
  }
281
298
  /**
282
299
  * Closes credit account or closes credit account and keeps it open with zero debt.
@@ -1,3 +1,4 @@
1
+ import { encodeAbiParameters } from "viem";
1
2
  import { iAliasedLossPolicyV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/index.js";
3
4
  const abi = iAliasedLossPolicyV310Abi;
@@ -10,6 +11,31 @@ class AliasLossPolicyV310Contract extends BaseContract {
10
11
  version: params.version
11
12
  });
12
13
  }
14
+ async getLiquidationData(creditAccount, blockNumber) {
15
+ const pfs = await this.sdk.client.readContract({
16
+ address: this.address,
17
+ abi: this.abi,
18
+ functionName: "getRequiredAliasPriceFeeds",
19
+ args: [creditAccount],
20
+ blockNumber
21
+ });
22
+ const updates = await this.sdk.priceFeeds.generateExternalPriceFeedsUpdates(
23
+ [...pfs],
24
+ blockNumber ? { blockNumber } : void 0
25
+ );
26
+ return encodeAbiParameters(
27
+ [
28
+ {
29
+ type: "tuple[]",
30
+ components: [
31
+ { type: "address", name: "priceFeed" },
32
+ { type: "bytes", name: "data" }
33
+ ]
34
+ }
35
+ ],
36
+ [updates]
37
+ );
38
+ }
13
39
  }
14
40
  export {
15
41
  AliasLossPolicyV310Contract
@@ -10,6 +10,9 @@ class LossPolicyContract extends BaseContract {
10
10
  version: params.version
11
11
  });
12
12
  }
13
+ async getLiquidationData(_creditAccount, _blockNumber) {
14
+ return void 0;
15
+ }
13
16
  }
14
17
  export {
15
18
  LossPolicyContract
@@ -5,7 +5,7 @@ import type { GearboxSDK } from "../GearboxSDK.js";
5
5
  import type { OnDemandPriceUpdates, PriceUpdateV300, PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
6
6
  import { type Asset, type RouterCASlice } from "../router/index.js";
7
7
  import type { MultiCall } from "../types/index.js";
8
- import type { AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
8
+ import type { AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, EnableTokensProps, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
9
9
  export interface CreditAccountServiceOptions {
10
10
  batchSize?: number;
11
11
  }
@@ -56,7 +56,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
56
56
  * @param props - {@link FullyLiquidateProps}
57
57
  * @returns
58
58
  */
59
- fullyLiquidate(props: FullyLiquidateProps): Promise<CloseCreditAccountResult>;
59
+ fullyLiquidate(props: FullyLiquidateProps): Promise<FullyLiquidateResult>;
60
60
  /**
61
61
  * Closes credit account or closes credit account and keeps it open with zero debt.
62
62
  - Ca is closed in the following order: price update -> close path to swap all tokens into underlying ->
@@ -1,4 +1,4 @@
1
- import type { Address, ContractFunctionArgs, GetContractReturnType, PublicClient } from "viem";
1
+ import type { Address, ContractFunctionArgs, GetContractReturnType, Hex, PublicClient } from "viem";
2
2
  import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAccountCompressor.js";
3
3
  import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
4
4
  import type { LiquidationBotType as LiquidationBotTypeSDK } from "../../plugins/bots/types.js";
@@ -42,6 +42,9 @@ export interface PriceUpdatesOptions {
42
42
  export interface CloseCreditAccountResult extends CreditAccountOperationResult {
43
43
  routerCloseResult: RouterCloseResult;
44
44
  }
45
+ export interface FullyLiquidateResult extends CloseCreditAccountResult {
46
+ lossPolicyData?: Hex;
47
+ }
45
48
  export interface CreditAccountOperationResult {
46
49
  tx: RawTx;
47
50
  calls: Array<MultiCall>;
@@ -332,6 +335,10 @@ export interface FullyLiquidateProps {
332
335
  * If true, will ignore reserve prices
333
336
  */
334
337
  ignoreReservePrices?: boolean;
338
+ /**
339
+ * If true, will try to apply loss policy
340
+ */
341
+ applyLossPolicy?: boolean;
335
342
  }
336
343
  export interface PermitResult {
337
344
  r: Address;
@@ -1,5 +1,7 @@
1
+ import { type Address, type Hex } from "viem";
1
2
  import { BaseContract, type BaseParams } from "../../base/index.js";
2
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
+ import type { ILossPolicyContract } from "./types.js";
3
5
  declare const abi: readonly [{
4
6
  readonly type: "function";
5
7
  readonly name: "accessMode";
@@ -271,7 +273,8 @@ declare const abi: readonly [{
271
273
  readonly anonymous: false;
272
274
  }];
273
275
  type abi = typeof abi;
274
- export declare class AliasLossPolicyV310Contract extends BaseContract<abi> {
276
+ export declare class AliasLossPolicyV310Contract extends BaseContract<abi> implements ILossPolicyContract {
275
277
  constructor(sdk: GearboxSDK, params: BaseParams);
278
+ getLiquidationData(creditAccount: Address, blockNumber?: bigint): Promise<Hex | undefined>;
276
279
  }
277
280
  export {};
@@ -1,5 +1,7 @@
1
+ import type { Address, Hex } from "viem";
1
2
  import { BaseContract, type BaseParams } from "../../base/index.js";
2
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
+ import type { ILossPolicyContract } from "./types.js";
3
5
  declare const abi: readonly [{
4
6
  readonly type: "function";
5
7
  readonly name: "accessMode";
@@ -127,7 +129,8 @@ declare const abi: readonly [{
127
129
  readonly anonymous: false;
128
130
  }];
129
131
  type abi = typeof abi;
130
- export declare class LossPolicyContract extends BaseContract<abi> {
132
+ export declare class LossPolicyContract extends BaseContract<abi> implements ILossPolicyContract {
131
133
  constructor(sdk: GearboxSDK, params: BaseParams);
134
+ getLiquidationData(_creditAccount: Address, _blockNumber?: bigint): Promise<Hex | undefined>;
132
135
  }
133
136
  export {};
@@ -1,5 +1,13 @@
1
+ import type { Address, Hex } from "viem";
1
2
  import type { IBaseContract } from "../../base/index.js";
2
3
  import type { BaseContractStateHuman } from "../../types/index.js";
3
4
  export interface ILossPolicyContract extends IBaseContract {
4
5
  stateHuman(raw?: boolean): BaseContractStateHuman;
6
+ /**
7
+ * Returns lossPolicyData that is passed to CreditFacade.liquidateCreditAccount
8
+ * Returns undefined if lossPolicyData is not supported
9
+ * @param creditAccount
10
+ * @param blockNumber
11
+ */
12
+ getLiquidationData(creditAccount: Address, blockNumber?: bigint): Promise<Hex | undefined>;
5
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "10.6.0",
3
+ "version": "10.7.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -65,12 +65,12 @@
65
65
  "zod": "^4.1.12"
66
66
  },
67
67
  "devDependencies": {
68
- "@biomejs/biome": "^2.3.3",
68
+ "@biomejs/biome": "^2.3.4",
69
69
  "@commitlint/cli": "^20.1.0",
70
70
  "@commitlint/config-conventional": "^20.0.0",
71
- "@gearbox-protocol/biome-config": "^1.0.9",
71
+ "@gearbox-protocol/biome-config": "^1.0.10",
72
72
  "@types/cross-spawn": "^6.0.6",
73
- "axios": "^1.13.1",
73
+ "axios": "^1.13.2",
74
74
  "cross-spawn": "^7.0.6",
75
75
  "husky": "^9.1.7",
76
76
  "lint-staged": "^16.2.6",
@@ -80,7 +80,7 @@
80
80
  "tsx": "^4.20.6",
81
81
  "typescript": "^5.9.3",
82
82
  "viem-deal": "^2.0.4",
83
- "vitest": "^4.0.6"
83
+ "vitest": "^4.0.7"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "axios": "^1.0.0",