@gearbox-protocol/sdk 11.0.0 → 11.1.0

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.
@@ -24,8 +24,14 @@ module.exports = __toCommonJS(AliasLossPolicyV310Contract_exports);
24
24
  var import_viem = require("viem");
25
25
  var import_generated = require("../../../abi/310/generated.js");
26
26
  var import_base = require("../../base/index.js");
27
+ var import_utils = require("../../utils/index.js");
28
+ var import_constants = require("./constants.js");
27
29
  const abi = import_generated.iAliasedLossPolicyV310Abi;
28
30
  class AliasLossPolicyV310Contract extends import_base.BaseContract {
31
+ accessMode;
32
+ checksEnabled;
33
+ tokens;
34
+ priceFeedParams;
29
35
  constructor(sdk, params) {
30
36
  super(sdk, {
31
37
  abi,
@@ -33,6 +39,24 @@ class AliasLossPolicyV310Contract extends import_base.BaseContract {
33
39
  contractType: params.contractType,
34
40
  version: params.version
35
41
  });
42
+ [this.accessMode, this.checksEnabled, this.tokens, this.priceFeedParams] = (0, import_viem.decodeAbiParameters)(
43
+ [
44
+ { name: "accessMode", type: "uint8" },
45
+ { name: "checksEnabled", type: "bool" },
46
+ { name: "tokens", type: "address[]" },
47
+ {
48
+ name: "priceFeedParams",
49
+ type: "tuple[]",
50
+ components: [
51
+ { name: "priceFeed", type: "address" },
52
+ { name: "stalenessPeriod", type: "uint32" },
53
+ { name: "skipCheck", type: "bool" },
54
+ { name: "tokenDecimals", type: "uint8" }
55
+ ]
56
+ }
57
+ ],
58
+ params.serializedParams
59
+ );
36
60
  }
37
61
  async getLiquidationData(creditAccount, blockNumber) {
38
62
  const pfs = await this.sdk.client.readContract({
@@ -63,6 +87,21 @@ class AliasLossPolicyV310Contract extends import_base.BaseContract {
63
87
  [updates]
64
88
  );
65
89
  }
90
+ stateHuman(raw) {
91
+ return {
92
+ ...super.stateHuman(raw),
93
+ contractType: import_constants.LOSS_POLICY_ALIASED,
94
+ checksEnabled: this.checksEnabled,
95
+ accessMode: import_constants.LOSS_POLICY_ACCESS_MODES[this.accessMode] ?? this.accessMode.toString(),
96
+ tokens: this.tokens.map((t) => this.labelAddress(t)),
97
+ priceFeedParams: this.priceFeedParams.map((p) => ({
98
+ priceFeed: this.labelAddress(p.priceFeed),
99
+ stalenessPeriod: (0, import_utils.formatDuration)(p.stalenessPeriod, raw),
100
+ skipCheck: p.skipCheck,
101
+ tokenDecimals: p.tokenDecimals
102
+ }))
103
+ };
104
+ }
66
105
  }
67
106
  // Annotate the CommonJS export names for ESM import in node:
68
107
  0 && (module.exports = {
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ LOSS_POLICY_ACCESS_MODES: () => LOSS_POLICY_ACCESS_MODES,
22
+ LOSS_POLICY_ALIASED: () => LOSS_POLICY_ALIASED,
23
+ LOSS_POLICY_DEFAULT: () => LOSS_POLICY_DEFAULT
24
+ });
25
+ module.exports = __toCommonJS(constants_exports);
26
+ const LOSS_POLICY_ALIASED = "LOSS_POLICY::ALIASED";
27
+ const LOSS_POLICY_DEFAULT = "LOSS_POLICY::DEFAULT";
28
+ const LOSS_POLICY_ACCESS_MODES = [
29
+ "Permissionless",
30
+ "Permissioned",
31
+ "Forbidden"
32
+ ];
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ LOSS_POLICY_ACCESS_MODES,
36
+ LOSS_POLICY_ALIASED,
37
+ LOSS_POLICY_DEFAULT
38
+ });
@@ -23,6 +23,7 @@ __export(createLossPolicy_exports, {
23
23
  module.exports = __toCommonJS(createLossPolicy_exports);
24
24
  var import__ = require("../../index.js");
25
25
  var import_AliasLossPolicyV310Contract = require("./AliasLossPolicyV310Contract.js");
26
+ var import_constants = require("./constants.js");
26
27
  var import_LossPolicyContract = require("./LossPolicyContract.js");
27
28
  function createLossPolicy(sdk, { baseParams }) {
28
29
  const existing = sdk.contracts.get(baseParams.addr);
@@ -31,9 +32,9 @@ function createLossPolicy(sdk, { baseParams }) {
31
32
  }
32
33
  const contractType = (0, import__.bytes32ToString)(baseParams.contractType);
33
34
  switch (contractType) {
34
- case "LOSS_POLICY::ALIASED":
35
+ case import_constants.LOSS_POLICY_ALIASED:
35
36
  return new import_AliasLossPolicyV310Contract.AliasLossPolicyV310Contract(sdk, baseParams);
36
- case "LOSS_POLICY::DEFAULT":
37
+ case import_constants.LOSS_POLICY_DEFAULT:
37
38
  return new import_LossPolicyContract.LossPolicyContract(sdk, baseParams);
38
39
  default:
39
40
  if (sdk.strictContractTypes) {
@@ -1,8 +1,17 @@
1
- import { encodeAbiParameters } from "viem";
1
+ import {
2
+ decodeAbiParameters,
3
+ encodeAbiParameters
4
+ } from "viem";
2
5
  import { iAliasedLossPolicyV310Abi } from "../../../abi/310/generated.js";
3
6
  import { BaseContract } from "../../base/index.js";
7
+ import { formatDuration } from "../../utils/index.js";
8
+ import { LOSS_POLICY_ACCESS_MODES, LOSS_POLICY_ALIASED } from "./constants.js";
4
9
  const abi = iAliasedLossPolicyV310Abi;
5
10
  class AliasLossPolicyV310Contract extends BaseContract {
11
+ accessMode;
12
+ checksEnabled;
13
+ tokens;
14
+ priceFeedParams;
6
15
  constructor(sdk, params) {
7
16
  super(sdk, {
8
17
  abi,
@@ -10,6 +19,24 @@ class AliasLossPolicyV310Contract extends BaseContract {
10
19
  contractType: params.contractType,
11
20
  version: params.version
12
21
  });
22
+ [this.accessMode, this.checksEnabled, this.tokens, this.priceFeedParams] = decodeAbiParameters(
23
+ [
24
+ { name: "accessMode", type: "uint8" },
25
+ { name: "checksEnabled", type: "bool" },
26
+ { name: "tokens", type: "address[]" },
27
+ {
28
+ name: "priceFeedParams",
29
+ type: "tuple[]",
30
+ components: [
31
+ { name: "priceFeed", type: "address" },
32
+ { name: "stalenessPeriod", type: "uint32" },
33
+ { name: "skipCheck", type: "bool" },
34
+ { name: "tokenDecimals", type: "uint8" }
35
+ ]
36
+ }
37
+ ],
38
+ params.serializedParams
39
+ );
13
40
  }
14
41
  async getLiquidationData(creditAccount, blockNumber) {
15
42
  const pfs = await this.sdk.client.readContract({
@@ -40,6 +67,21 @@ class AliasLossPolicyV310Contract extends BaseContract {
40
67
  [updates]
41
68
  );
42
69
  }
70
+ stateHuman(raw) {
71
+ return {
72
+ ...super.stateHuman(raw),
73
+ contractType: LOSS_POLICY_ALIASED,
74
+ checksEnabled: this.checksEnabled,
75
+ accessMode: LOSS_POLICY_ACCESS_MODES[this.accessMode] ?? this.accessMode.toString(),
76
+ tokens: this.tokens.map((t) => this.labelAddress(t)),
77
+ priceFeedParams: this.priceFeedParams.map((p) => ({
78
+ priceFeed: this.labelAddress(p.priceFeed),
79
+ stalenessPeriod: formatDuration(p.stalenessPeriod, raw),
80
+ skipCheck: p.skipCheck,
81
+ tokenDecimals: p.tokenDecimals
82
+ }))
83
+ };
84
+ }
43
85
  }
44
86
  export {
45
87
  AliasLossPolicyV310Contract
@@ -0,0 +1,12 @@
1
+ const LOSS_POLICY_ALIASED = "LOSS_POLICY::ALIASED";
2
+ const LOSS_POLICY_DEFAULT = "LOSS_POLICY::DEFAULT";
3
+ const LOSS_POLICY_ACCESS_MODES = [
4
+ "Permissionless",
5
+ "Permissioned",
6
+ "Forbidden"
7
+ ];
8
+ export {
9
+ LOSS_POLICY_ACCESS_MODES,
10
+ LOSS_POLICY_ALIASED,
11
+ LOSS_POLICY_DEFAULT
12
+ };
@@ -1,5 +1,6 @@
1
1
  import { bytes32ToString } from "../../index.js";
2
2
  import { AliasLossPolicyV310Contract } from "./AliasLossPolicyV310Contract.js";
3
+ import { LOSS_POLICY_ALIASED, LOSS_POLICY_DEFAULT } from "./constants.js";
3
4
  import { LossPolicyContract } from "./LossPolicyContract.js";
4
5
  function createLossPolicy(sdk, { baseParams }) {
5
6
  const existing = sdk.contracts.get(baseParams.addr);
@@ -8,9 +9,9 @@ function createLossPolicy(sdk, { baseParams }) {
8
9
  }
9
10
  const contractType = bytes32ToString(baseParams.contractType);
10
11
  switch (contractType) {
11
- case "LOSS_POLICY::ALIASED":
12
+ case LOSS_POLICY_ALIASED:
12
13
  return new AliasLossPolicyV310Contract(sdk, baseParams);
13
- case "LOSS_POLICY::DEFAULT":
14
+ case LOSS_POLICY_DEFAULT:
14
15
  return new LossPolicyContract(sdk, baseParams);
15
16
  default:
16
17
  if (sdk.strictContractTypes) {
@@ -1,6 +1,7 @@
1
1
  import { type Address, type Hex } from "viem";
2
2
  import { BaseContract, type BaseParams } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
+ import type { AliasLossPolicyStateHuman } from "../../types/state-human.js";
4
5
  import type { ILossPolicyContract } from "./types.js";
5
6
  declare const abi: readonly [{
6
7
  readonly type: "function";
@@ -273,8 +274,19 @@ declare const abi: readonly [{
273
274
  readonly anonymous: false;
274
275
  }];
275
276
  type abi = typeof abi;
277
+ export interface AliasedPriceFeedParams {
278
+ priceFeed: Address;
279
+ stalenessPeriod: number;
280
+ skipCheck: boolean;
281
+ tokenDecimals: number;
282
+ }
276
283
  export declare class AliasLossPolicyV310Contract extends BaseContract<abi> implements ILossPolicyContract {
284
+ readonly accessMode: number;
285
+ readonly checksEnabled: boolean;
286
+ readonly tokens: readonly Address[];
287
+ readonly priceFeedParams: readonly AliasedPriceFeedParams[];
277
288
  constructor(sdk: GearboxSDK, params: BaseParams);
278
289
  getLiquidationData(creditAccount: Address, blockNumber?: bigint): Promise<Hex | undefined>;
290
+ stateHuman(raw?: boolean): AliasLossPolicyStateHuman;
279
291
  }
280
292
  export {};
@@ -0,0 +1,4 @@
1
+ export declare const LOSS_POLICY_ALIASED: "LOSS_POLICY::ALIASED";
2
+ export declare const LOSS_POLICY_DEFAULT: "LOSS_POLICY::DEFAULT";
3
+ export declare const LOSS_POLICY_ACCESS_MODES: readonly ["Permissionless", "Permissioned", "Forbidden"];
4
+ export type LossPolicyAccessMode = (typeof LOSS_POLICY_ACCESS_MODES)[number];
@@ -171,12 +171,25 @@ export interface PoolSuiteStateHuman {
171
171
  interestRateModel?: InterestRateModelStateHuman;
172
172
  rateKeeper: RateKeeperStateHuman;
173
173
  }
174
+ export interface AliasLossPolicyStateHuman extends BaseContractStateHuman {
175
+ contractType: "LOSS_POLICY::ALIASED";
176
+ accessMode: string;
177
+ checksEnabled: boolean;
178
+ tokens: string[];
179
+ priceFeedParams: {
180
+ priceFeed: string;
181
+ stalenessPeriod: string;
182
+ skipCheck: boolean;
183
+ tokenDecimals: number;
184
+ }[];
185
+ }
186
+ export type LossPolicyStateHuman = AliasLossPolicyStateHuman | BaseContractStateHuman;
174
187
  export interface MarketStateHuman {
175
188
  configurator: string;
176
189
  pool: PoolSuiteStateHuman;
177
190
  creditManagers: CreditSuiteStateHuman[];
178
191
  priceOracle: PriceOracleStateHuman;
179
- lossPolicy: BaseContractStateHuman;
192
+ lossPolicy: LossPolicyStateHuman;
180
193
  pausableAdmins: string[];
181
194
  unpausableAdmins: string[];
182
195
  emergencyLiquidators: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",