@gearbox-protocol/sdk 8.30.3 → 8.31.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.
@@ -74,9 +74,11 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
74
74
  if (raw.success) {
75
75
  return raw;
76
76
  }
77
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(void 0, {
78
- account
79
- });
77
+ const { txs: priceUpdateTxs } = await this.getUpdateForAccount(
78
+ raw.creditManager,
79
+ raw,
80
+ void 0
81
+ );
80
82
  const [cad] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
81
83
  priceUpdates: priceUpdateTxs,
82
84
  contracts: [
@@ -106,7 +108,8 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
106
108
  includeZeroDebt = false,
107
109
  maxHealthFactor = import_constants.MAX_UINT256,
108
110
  minHealthFactor = 0n,
109
- owner = import_constants.ADDRESS_0X0
111
+ owner = import_constants.ADDRESS_0X0,
112
+ ignoreReservePrices = false
110
113
  } = options ?? {};
111
114
  const arg0 = creditManager ?? {
112
115
  configurators: this.marketConfigurators,
@@ -121,7 +124,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
121
124
  maxHealthFactor,
122
125
  reverting: false
123
126
  };
124
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
127
+ const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
128
+ ignoreReservePrices ? { main: true } : void 0
129
+ );
125
130
  const allCAs = [];
126
131
  for (const reverting of [false, true]) {
127
132
  let offset = 0n;
@@ -221,6 +221,9 @@ class MarketRegister extends import_base.SDKConstruct {
221
221
  get pools() {
222
222
  return this.markets.map((market) => market.pool);
223
223
  }
224
+ get priceOracles() {
225
+ return this.markets.map((market) => market.priceOracle);
226
+ }
224
227
  get creditManagers() {
225
228
  return this.markets.flatMap((market) => market.creditManagers);
226
229
  }
@@ -274,6 +277,14 @@ class MarketRegister extends import_base.SDKConstruct {
274
277
  get markets() {
275
278
  return this.#markets.values();
276
279
  }
280
+ /**
281
+ * Helper to get human-friendly label for address
282
+ * @param address
283
+ * @returns
284
+ */
285
+ labelAddress(address) {
286
+ return this.provider.addressLabels.get(address);
287
+ }
277
288
  }
278
289
  // Annotate the CommonJS export names for ESM import in node:
279
290
  0 && (module.exports = {
@@ -64,12 +64,26 @@ class PriceFeedRegister extends import_base.SDKConstruct {
64
64
  removeHook = this.#hooks.removeHook.bind(this.#hooks);
65
65
  /**
66
66
  * Returns RawTxs to update price feeds
67
- * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
67
+ * @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
68
+ * Or filter criteria, that will gather all main or reserve price feeds from all oracles
69
+ * If not provided will use all price feeds that are attached
68
70
  * @param logContext extra information for logging
69
71
  * @returns
70
72
  */
71
73
  async generatePriceFeedsUpdateTxs(priceFeeds, logContext = {}) {
72
- const updateables = priceFeeds ? priceFeeds.flatMap((pf) => pf.updatableDependencies()) : this.#feeds.values();
74
+ let updateables = this.#feeds.values();
75
+ let filterRemark = "";
76
+ if (priceFeeds) {
77
+ if (Array.isArray(priceFeeds)) {
78
+ updateables = priceFeeds.flatMap((pf) => pf.updatableDependencies());
79
+ } else if ("main" in priceFeeds && priceFeeds.main) {
80
+ filterRemark = " main";
81
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.mainPriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
82
+ } else if ("reserve" in priceFeeds && priceFeeds.reserve) {
83
+ filterRemark = " reserve";
84
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.reservePriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
85
+ }
86
+ }
73
87
  const txs = [];
74
88
  const latestUpdate = {
75
89
  updates: [],
@@ -92,7 +106,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
92
106
  const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
93
107
  this.logger?.debug(
94
108
  logContext,
95
- `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
109
+ `generated ${txs.length}${filterRemark} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
96
110
  );
97
111
  if (txs.length) {
98
112
  await this.#hooks.triggerHooks("updatesGenerated", result);
@@ -171,7 +185,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
171
185
  }
172
186
  /**
173
187
  * Loads PARTIAL information about all updatable price feeds from MarketCompressor
174
- * This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
188
+ * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
175
189
  */
176
190
  async getPartialUpdatablePriceFeeds(configurators, pools) {
177
191
  const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
@@ -71,9 +71,11 @@ class AbstractCreditAccountService extends SDKConstruct {
71
71
  if (raw.success) {
72
72
  return raw;
73
73
  }
74
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(void 0, {
75
- account
76
- });
74
+ const { txs: priceUpdateTxs } = await this.getUpdateForAccount(
75
+ raw.creditManager,
76
+ raw,
77
+ void 0
78
+ );
77
79
  const [cad] = await simulateWithPriceUpdates(this.client, {
78
80
  priceUpdates: priceUpdateTxs,
79
81
  contracts: [
@@ -103,7 +105,8 @@ class AbstractCreditAccountService extends SDKConstruct {
103
105
  includeZeroDebt = false,
104
106
  maxHealthFactor = MAX_UINT256,
105
107
  minHealthFactor = 0n,
106
- owner = ADDRESS_0X0
108
+ owner = ADDRESS_0X0,
109
+ ignoreReservePrices = false
107
110
  } = options ?? {};
108
111
  const arg0 = creditManager ?? {
109
112
  configurators: this.marketConfigurators,
@@ -118,7 +121,9 @@ class AbstractCreditAccountService extends SDKConstruct {
118
121
  maxHealthFactor,
119
122
  reverting: false
120
123
  };
121
- const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
124
+ const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
125
+ ignoreReservePrices ? { main: true } : void 0
126
+ );
122
127
  const allCAs = [];
123
128
  for (const reverting of [false, true]) {
124
129
  let offset = 0n;
@@ -202,6 +202,9 @@ class MarketRegister extends SDKConstruct {
202
202
  get pools() {
203
203
  return this.markets.map((market) => market.pool);
204
204
  }
205
+ get priceOracles() {
206
+ return this.markets.map((market) => market.priceOracle);
207
+ }
205
208
  get creditManagers() {
206
209
  return this.markets.flatMap((market) => market.creditManagers);
207
210
  }
@@ -255,6 +258,14 @@ class MarketRegister extends SDKConstruct {
255
258
  get markets() {
256
259
  return this.#markets.values();
257
260
  }
261
+ /**
262
+ * Helper to get human-friendly label for address
263
+ * @param address
264
+ * @returns
265
+ */
266
+ labelAddress(address) {
267
+ return this.provider.addressLabels.get(address);
268
+ }
258
269
  }
259
270
  export {
260
271
  MarketRegister
@@ -47,12 +47,26 @@ class PriceFeedRegister extends SDKConstruct {
47
47
  removeHook = this.#hooks.removeHook.bind(this.#hooks);
48
48
  /**
49
49
  * Returns RawTxs to update price feeds
50
- * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
50
+ * @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
51
+ * Or filter criteria, that will gather all main or reserve price feeds from all oracles
52
+ * If not provided will use all price feeds that are attached
51
53
  * @param logContext extra information for logging
52
54
  * @returns
53
55
  */
54
56
  async generatePriceFeedsUpdateTxs(priceFeeds, logContext = {}) {
55
- const updateables = priceFeeds ? priceFeeds.flatMap((pf) => pf.updatableDependencies()) : this.#feeds.values();
57
+ let updateables = this.#feeds.values();
58
+ let filterRemark = "";
59
+ if (priceFeeds) {
60
+ if (Array.isArray(priceFeeds)) {
61
+ updateables = priceFeeds.flatMap((pf) => pf.updatableDependencies());
62
+ } else if ("main" in priceFeeds && priceFeeds.main) {
63
+ filterRemark = " main";
64
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.mainPriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
65
+ } else if ("reserve" in priceFeeds && priceFeeds.reserve) {
66
+ filterRemark = " reserve";
67
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.reservePriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
68
+ }
69
+ }
56
70
  const txs = [];
57
71
  const latestUpdate = {
58
72
  updates: [],
@@ -75,7 +89,7 @@ class PriceFeedRegister extends SDKConstruct {
75
89
  const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
76
90
  this.logger?.debug(
77
91
  logContext,
78
- `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
92
+ `generated ${txs.length}${filterRemark} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
79
93
  );
80
94
  if (txs.length) {
81
95
  await this.#hooks.triggerHooks("updatesGenerated", result);
@@ -154,7 +168,7 @@ class PriceFeedRegister extends SDKConstruct {
154
168
  }
155
169
  /**
156
170
  * Loads PARTIAL information about all updatable price feeds from MarketCompressor
157
- * This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
171
+ * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
158
172
  */
159
173
  async getPartialUpdatablePriceFeeds(configurators, pools) {
160
174
  const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
@@ -27,6 +27,10 @@ export interface GetCreditAccountsOptions {
27
27
  includeZeroDebt?: boolean;
28
28
  minHealthFactor?: bigint;
29
29
  maxHealthFactor?: bigint;
30
+ /**
31
+ * If true, will filter out reserve price updates
32
+ */
33
+ ignoreReservePrices?: boolean;
30
34
  }
31
35
  export interface CloseCreditAccountResult extends CreditAccountOperationResult {
32
36
  routerCloseResult: RouterCloseResult;
@@ -7,6 +7,7 @@ import { AddressMap } from "../utils/index.js";
7
7
  import type { CreditSuite } from "./credit/index.js";
8
8
  import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
9
9
  import { MarketSuite } from "./MarketSuite.js";
10
+ import type { IPriceOracleContract } from "./oracle/index.js";
10
11
  import type { PoolSuite } from "./pool/index.js";
11
12
  export declare class MarketRegister extends SDKConstruct {
12
13
  #private;
@@ -26,6 +27,7 @@ export declare class MarketRegister extends SDKConstruct {
26
27
  markets: MarketStateHuman[];
27
28
  };
28
29
  get pools(): PoolSuite[];
30
+ get priceOracles(): IPriceOracleContract[];
29
31
  get creditManagers(): CreditSuite[];
30
32
  get marketConfigurators(): MarketConfiguratorContract[];
31
33
  findCreditManager(creditManager: Address): CreditSuite;
@@ -34,4 +36,10 @@ export declare class MarketRegister extends SDKConstruct {
34
36
  findByPool(address: Address): MarketSuite;
35
37
  get marketsMap(): AddressMap<MarketSuite>;
36
38
  get markets(): MarketSuite[];
39
+ /**
40
+ * Helper to get human-friendly label for address
41
+ * @param address
42
+ * @returns
43
+ */
44
+ labelAddress(address: Address): string;
37
45
  }
@@ -35,18 +35,28 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
35
35
  removeHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
36
36
  /**
37
37
  * Returns RawTxs to update price feeds
38
- * @param priceFeeds top-level price feeds, actual updatable price feeds will be derived. If not provided will use all price feeds that are attached
38
+ * @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
39
+ * Or filter criteria, that will gather all main or reserve price feeds from all oracles
40
+ * If not provided will use all price feeds that are attached
39
41
  * @param logContext extra information for logging
40
42
  * @returns
41
43
  */
42
- generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[], logContext?: Record<string, any>): Promise<UpdatePriceFeedsResult>;
44
+ generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[] | {
45
+ main: true;
46
+ } | {
47
+ reserve: true;
48
+ }, logContext?: Record<string, any>): Promise<UpdatePriceFeedsResult>;
43
49
  /**
44
50
  * Similar to {@link generatePriceFeedsUpdateTxs}, but returns raw structures instead of transactions
45
51
  * @param priceFeeds
46
52
  * @param logContext
47
53
  * @returns
48
54
  */
49
- generatePriceFeedsUpdates(priceFeeds?: IPriceFeedContract[], logContext?: Record<string, any>): Promise<PriceUpdateV310[]>;
55
+ generatePriceFeedsUpdates(priceFeeds?: IPriceFeedContract[] | {
56
+ main: true;
57
+ } | {
58
+ reserve: true;
59
+ }, logContext?: Record<string, any>): Promise<PriceUpdateV310[]>;
50
60
  /**
51
61
  * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
52
62
  * This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
@@ -75,7 +85,7 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
75
85
  getOrCreate(data: PriceFeedTreeNode): IPriceFeedContract;
76
86
  /**
77
87
  * Loads PARTIAL information about all updatable price feeds from MarketCompressor
78
- * This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
88
+ * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
79
89
  */
80
90
  getPartialUpdatablePriceFeeds(configurators: Address[], pools?: Address[]): Promise<IPriceFeedContract[]>;
81
91
  create(data: PartialPriceFeedTreeNode): IPriceFeedContract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.30.3",
3
+ "version": "8.31.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -60,7 +60,7 @@
60
60
  "date-fns": "^4.1.0",
61
61
  "decimal.js-light": "^2.5.1",
62
62
  "viem": ">=2.23.15 <3.0.0",
63
- "zod": "^4.1.7"
63
+ "zod": "^4.1.8"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@biomejs/biome": "^2.2.4",
@@ -68,7 +68,7 @@
68
68
  "@commitlint/config-conventional": "^19.8.1",
69
69
  "@gearbox-protocol/biome-config": "^1.0.2",
70
70
  "@types/cross-spawn": "^6.0.6",
71
- "axios": "^1.11.0",
71
+ "axios": "^1.12.1",
72
72
  "cross-spawn": "^7.0.6",
73
73
  "husky": "^9.1.7",
74
74
  "lint-staged": "^16.1.6",