@gearbox-protocol/deploy-tools 5.29.3 → 5.29.5

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 (2) hide show
  1. package/dist/index.mjs +94 -78
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -389704,7 +389704,6 @@ var BaseContract = class extends SDKConstruct {
389704
389704
  this.addressLabels.set(this.#address, name);
389705
389705
  }
389706
389706
  }
389707
- // TODO: unused
389708
389707
  stateHuman(_ = true) {
389709
389708
  return {
389710
389709
  address: this.sdk.provider.addressLabels.get(this.address),
@@ -404993,7 +404992,7 @@ var AbstractLPPriceFeedContract = class _AbstractLPPriceFeedContract extends Abs
404993
404992
  constructor(sdk, args) {
404994
404993
  super(sdk, { ...args, decimals: 8 });
404995
404994
  this.hasLowerBoundCap = true;
404996
- if (args.baseParams.version === 310n) {
404995
+ if (isV310(args.baseParams.version)) {
404997
404996
  const decoder = decodeAbiParameters(
404998
404997
  [
404999
404998
  { type: "address", name: "lpToken" },
@@ -405369,7 +405368,7 @@ var RedstonePriceFeedContract = class extends AbstractPriceFeedContract {
405369
405368
  name: `RedstonePriceFeed`,
405370
405369
  abi: redstonePriceFeedAbi
405371
405370
  });
405372
- if (args.baseParams.version === 310n) {
405371
+ if (isV310(args.baseParams.version)) {
405373
405372
  const decoder = decodeAbiParameters(
405374
405373
  [
405375
405374
  { type: "address", name: "token" },
@@ -405928,10 +405927,6 @@ var PriceFeedAnswerMap = class extends AddressMap {
405928
405927
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js
405929
405928
  var ZERO_PRICE_FEED = stringToHex("PRICE_FEED::ZERO", { size: 32 });
405930
405929
  var PriceOracleBaseContract = class extends BaseContract {
405931
- /**
405932
- * Underlying token of market to which this price oracle belongs
405933
- */
405934
- underlying;
405935
405930
  /**
405936
405931
  * Mapping Token => [PriceFeed Address, stalenessPeriod]
405937
405932
  */
@@ -405957,12 +405952,14 @@ var PriceOracleBaseContract = class extends BaseContract {
405957
405952
  void 0,
405958
405953
  "reservePrices"
405959
405954
  );
405960
- #priceFeedTree = [];
405961
- constructor(sdk, args, data, underlying) {
405955
+ #priceFeedTree = new AddressMap(
405956
+ void 0,
405957
+ "priceFeedTree"
405958
+ );
405959
+ constructor(sdk, args, data) {
405962
405960
  super(sdk, args);
405963
- this.underlying = underlying;
405964
405961
  const { priceFeedMap, priceFeedTree } = data;
405965
- this.#loadState(priceFeedMap, priceFeedTree);
405962
+ this.#loadState(priceFeedMap, priceFeedTree, true);
405966
405963
  }
405967
405964
  /**
405968
405965
  * Returns main and reserve price feeds for given tokens
@@ -405984,7 +405981,7 @@ var PriceOracleBaseContract = class extends BaseContract {
405984
405981
  */
405985
405982
  async updatePriceFeeds() {
405986
405983
  const updatables = [];
405987
- for (const node of this.#priceFeedTree) {
405984
+ for (const node of this.#priceFeedTree.values()) {
405988
405985
  if (node.updatable) {
405989
405986
  updatables.push(this.sdk.priceFeeds.mustGet(node.baseParams.addr));
405990
405987
  }
@@ -406050,30 +406047,19 @@ var PriceOracleBaseContract = class extends BaseContract {
406050
406047
  }
406051
406048
  /**
406052
406049
  * Returns true if oracle's price feed tree contains given price feed
406050
+ * This feed is not necessary connected to token, but can be a component of composite feed for some token
406053
406051
  * @param priceFeed
406054
406052
  * @returns
406055
406053
  */
406056
406054
  usesPriceFeed(priceFeed) {
406057
- return this.#priceFeedTree.some(
406058
- (node) => node.baseParams.addr.toLowerCase() === priceFeed.toLowerCase()
406059
- );
406060
- }
406061
- /**
406062
- * Tries to convert amount of token into underlying of current market
406063
- * @param token
406064
- * @param amount
406065
- * @param reserve
406066
- * @returns
406067
- */
406068
- convertToUnderlying(token, amount, reserve = false) {
406069
- return this.convert(token, this.underlying, amount, reserve);
406055
+ return this.#priceFeedTree.has(priceFeed);
406070
406056
  }
406071
406057
  /**
406072
406058
  * Tries to convert amount of from one token to another, using latest known prices
406073
406059
  * @param from
406074
406060
  * @param to
406075
406061
  * @param amount
406076
- * @param reserve
406062
+ * @param reserve use reserve price feed instead of main
406077
406063
  */
406078
406064
  convert(from5, to, amount, reserve = false) {
406079
406065
  if (from5 === to) {
@@ -406088,9 +406074,8 @@ var PriceOracleBaseContract = class extends BaseContract {
406088
406074
  /**
406089
406075
  * Tries to convert amount of token to USD, using latest known prices
406090
406076
  * @param from
406091
- * @param to
406092
406077
  * @param amount
406093
- * @param reserve
406078
+ * @param reserve use reserve price feed instead of main
406094
406079
  */
406095
406080
  convertToUSD(from5, amount, reserve = false) {
406096
406081
  const price = reserve ? this.reservePrice(from5) : this.mainPrice(from5);
@@ -406101,7 +406086,7 @@ var PriceOracleBaseContract = class extends BaseContract {
406101
406086
  * Tries to convert amount of USD to token, using latest known prices
406102
406087
  * @param to
406103
406088
  * @param amount
406104
- * @param reserve
406089
+ * @param reserve use reserve price feed instead of main
406105
406090
  */
406106
406091
  convertFromUSD(to, amount, reserve = false) {
406107
406092
  const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
@@ -406110,23 +406095,26 @@ var PriceOracleBaseContract = class extends BaseContract {
406110
406095
  }
406111
406096
  /**
406112
406097
  * Loads new prices for this oracle from PriceFeedCompressor
406113
- * Does not update price feeds, only updates prices
406098
+ * Will (re)create price feeds if needed
406114
406099
  */
406115
406100
  async updatePrices() {
406116
406101
  await this.sdk.marketRegister.updatePrices([this.address]);
406117
406102
  }
406103
+ /**
406104
+ * Paired method to updatePrices, helps to update prices on all oracles in one multicall
406105
+ */
406118
406106
  syncStateMulticall() {
406119
- const args = [this.address];
406120
- if (this.version === 300) {
406121
- args.push(
406107
+ let args = [this.address];
406108
+ if (isV300(this.version)) {
406109
+ args = [
406110
+ args[0],
406122
406111
  Array.from(
406123
406112
  /* @__PURE__ */ new Set([
406124
- this.underlying,
406125
406113
  ...this.mainPriceFeeds.keys(),
406126
406114
  ...this.reservePriceFeeds.keys()
406127
406115
  ])
406128
406116
  )
406129
- );
406117
+ ];
406130
406118
  }
406131
406119
  const [address] = this.sdk.addressProvider.mustGetLatest(
406132
406120
  AP_PRICE_FEED_COMPRESSOR,
@@ -406141,25 +406129,39 @@ var PriceOracleBaseContract = class extends BaseContract {
406141
406129
  },
406142
406130
  onResult: (resp) => {
406143
406131
  const { priceFeedMap, priceFeedTree } = resp;
406144
- this.#loadState(priceFeedMap, priceFeedTree);
406132
+ this.#loadState(priceFeedMap, priceFeedTree, true);
406145
406133
  }
406146
406134
  };
406147
406135
  }
406148
- #loadState(entries, tree) {
406149
- this.#priceFeedTree = tree;
406150
- this.mainPriceFeeds.clear();
406151
- this.reservePriceFeeds.clear();
406152
- this.mainPrices.clear();
406153
- this.reservePrices.clear();
406136
+ /**
406137
+ * Helper function to handle situation when we have multiple different compressor data entries for same oracle
406138
+ * This happens in v300
406139
+ *
406140
+ * @deprecated should be unnecessary after full v310 migration (oracles will be unique)
406141
+ * @param data
406142
+ * @returns
406143
+ */
406144
+ merge(data) {
406145
+ const { priceFeedMap, priceFeedTree } = data;
406146
+ this.#loadState(priceFeedMap, priceFeedTree, false);
406147
+ return this;
406148
+ }
406149
+ #loadState(entries, tree, reset2) {
406150
+ if (reset2) {
406151
+ this.#priceFeedTree.clear();
406152
+ this.mainPriceFeeds.clear();
406153
+ this.reservePriceFeeds.clear();
406154
+ this.mainPrices.clear();
406155
+ this.reservePrices.clear();
406156
+ }
406154
406157
  for (const node of tree) {
406158
+ this.#priceFeedTree.upsert(node.baseParams.addr, node);
406155
406159
  this.sdk.priceFeeds.getOrCreate(node);
406156
406160
  }
406157
- entries.forEach((entry) => {
406161
+ for (const entry of entries) {
406158
406162
  const { token, priceFeed, reserve, stalenessPeriod } = entry;
406159
406163
  const ref = new PriceFeedRef(this.sdk, priceFeed, stalenessPeriod);
406160
- const node = this.#priceFeedTree.find(
406161
- (n) => n.baseParams.addr === priceFeed
406162
- );
406164
+ const node = this.#priceFeedTree.get(priceFeed);
406163
406165
  const price = node?.answer?.price;
406164
406166
  const priceFeedType = node?.baseParams.contractType;
406165
406167
  if (reserve) {
@@ -406176,7 +406178,7 @@ var PriceOracleBaseContract = class extends BaseContract {
406176
406178
  }
406177
406179
  }
406178
406180
  this.#labelPriceFeed(priceFeed, reserve ? "Reserve" : "Main", token);
406179
- });
406181
+ }
406180
406182
  this.logger?.debug(
406181
406183
  `Got ${this.mainPriceFeeds.size} main and ${this.reservePriceFeeds.size} reserve price feeds`
406182
406184
  );
@@ -406197,6 +406199,8 @@ var PriceOracleBaseContract = class extends BaseContract {
406197
406199
  * Helper method to find "attachment point" of price feed (makes sense for updatable price feeds only) -
406198
406200
  * returns token (in v3.0 can be ticker) and main/reserve flag
406199
406201
  *
406202
+ * @deprecated Should be gone after v310 migration
406203
+ *
406200
406204
  * @param priceFeed
406201
406205
  * @returns
406202
406206
  */
@@ -406213,6 +406217,9 @@ var PriceOracleBaseContract = class extends BaseContract {
406213
406217
  }
406214
406218
  return [void 0, false];
406215
406219
  }
406220
+ /**
406221
+ * Returns list of addresses that should be watched for events to sync state
406222
+ */
406216
406223
  get watchAddresses() {
406217
406224
  return /* @__PURE__ */ new Set([this.address]);
406218
406225
  }
@@ -406239,9 +406246,6 @@ var PriceOracleBaseContract = class extends BaseContract {
406239
406246
  )
406240
406247
  };
406241
406248
  }
406242
- get priceFeedTree() {
406243
- return this.#priceFeedTree;
406244
- }
406245
406249
  #noAnswerWarn(priceFeed, node) {
406246
406250
  let label = this.labelAddress(priceFeed);
406247
406251
  if (!node) {
@@ -406282,7 +406286,7 @@ function formatAnswer({ price, success, updatedAt }, raw = true) {
406282
406286
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js
406283
406287
  var abi17 = [...iPriceOracleV300Abi, ...iPausableAbi];
406284
406288
  var PriceOracleV300Contract = class extends PriceOracleBaseContract {
406285
- constructor(sdk, data, underlying) {
406289
+ constructor(sdk, data) {
406286
406290
  super(
406287
406291
  sdk,
406288
406292
  {
@@ -406290,8 +406294,7 @@ var PriceOracleV300Contract = class extends PriceOracleBaseContract {
406290
406294
  name: "PriceOracleV3",
406291
406295
  abi: abi17
406292
406296
  },
406293
- data,
406294
- underlying
406297
+ data
406295
406298
  );
406296
406299
  }
406297
406300
  processLog(log2) {
@@ -406330,7 +406333,7 @@ var PriceOracleV300Contract = class extends PriceOracleBaseContract {
406330
406333
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js
406331
406334
  var abi18 = iPriceOracleV310Abi;
406332
406335
  var PriceOracleV310Contract = class extends PriceOracleBaseContract {
406333
- constructor(sdk, data, underlying) {
406336
+ constructor(sdk, data) {
406334
406337
  super(
406335
406338
  sdk,
406336
406339
  {
@@ -406338,8 +406341,7 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
406338
406341
  name: "PriceOracleV3",
406339
406342
  abi: abi18
406340
406343
  },
406341
- data,
406342
- underlying
406344
+ data
406343
406345
  );
406344
406346
  }
406345
406347
  processLog(log2) {
@@ -406353,15 +406355,33 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
406353
406355
  };
406354
406356
 
406355
406357
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/sdk/market/oracle/createPriceOracle.js
406356
- function createPriceOracle(sdk, data, underlying) {
406357
- const v = data.baseParams.version;
406358
- if (isV300(v)) {
406359
- return new PriceOracleV300Contract(sdk, data, underlying);
406358
+ function getOrCreatePriceOracle(sdk, data) {
406359
+ const { version: version4, addr } = data.baseParams;
406360
+ const existing = sdk.contracts.get(addr);
406361
+ if (existing) {
406362
+ return tryExtendExistingOracle(existing, data);
406360
406363
  }
406361
- if (isV310(v)) {
406362
- return new PriceOracleV310Contract(sdk, data, underlying);
406364
+ if (isV300(version4)) {
406365
+ return new PriceOracleV300Contract(sdk, data);
406366
+ }
406367
+ if (isV310(version4)) {
406368
+ return new PriceOracleV310Contract(sdk, data);
406363
406369
  }
406364
- throw new Error(`Unsupported oracle version ${v}`);
406370
+ throw new Error(`Unsupported oracle version ${version4}`);
406371
+ }
406372
+ function tryExtendExistingOracle(existing, data) {
406373
+ const { version: version4, addr } = data.baseParams;
406374
+ if (!(existing instanceof PriceOracleBaseContract)) {
406375
+ throw new Error(
406376
+ `expected oracle contract at ${addr}, found existing ${existing.contractType}`
406377
+ );
406378
+ }
406379
+ if (Number(existing.version) !== Number(version4)) {
406380
+ throw new Error(
406381
+ `expected oracle contract at ${addr} to have version ${version4}, found ${existing.version}`
406382
+ );
406383
+ }
406384
+ return existing.merge(data);
406365
406385
  }
406366
406386
 
406367
406387
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/sdk/market/pool/GaugeContract.js
@@ -407032,11 +407052,7 @@ var MarketSuite = class extends SDKConstruct {
407032
407052
  for (let i = 0; i < marketData.creditManagers.length; i++) {
407033
407053
  this.creditManagers.push(new CreditSuite(sdk, marketData, i));
407034
407054
  }
407035
- this.priceOracle = createPriceOracle(
407036
- sdk,
407037
- marketData.priceOracle,
407038
- marketData.pool.underlying
407039
- );
407055
+ this.priceOracle = getOrCreatePriceOracle(sdk, marketData.priceOracle);
407040
407056
  }
407041
407057
  get dirty() {
407042
407058
  return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
@@ -407297,12 +407313,12 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
407297
407313
  this.#logger = sdk.logger?.child?.({ name: "V300StalenessPeriodPlugin" }) ?? sdk.logger;
407298
407314
  }
407299
407315
  async attach() {
407300
- await this.#syncReservePriceFeeds();
407316
+ await this.#syncPriceFeeds();
407301
407317
  }
407302
407318
  async syncState() {
407303
- await this.#syncReservePriceFeeds();
407319
+ await this.#syncPriceFeeds();
407304
407320
  }
407305
- async #syncReservePriceFeeds() {
407321
+ async #syncPriceFeeds() {
407306
407322
  const oracles = this.#getOraclesMap();
407307
407323
  const [fromBlock, toBlock] = [this.#syncedTo + 1n, this.sdk.currentBlock];
407308
407324
  if (oracles.size === 0 || fromBlock > toBlock) {
@@ -407325,7 +407341,7 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
407325
407341
  strict: true
407326
407342
  });
407327
407343
  this.#logger?.info(
407328
- `loaded ${events.length} SetReservePriceFeed events in range [${fromBlock}; ${toBlock}]`
407344
+ `loaded ${events.length} price feed events in range [${fromBlock}; ${toBlock}]`
407329
407345
  );
407330
407346
  for (const e of events) {
407331
407347
  const oracle = oracles.mustGet(e.address);
@@ -407378,7 +407394,7 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
407378
407394
  }
407379
407395
  #getOraclesMap() {
407380
407396
  return new AddressMap(
407381
- this.sdk.marketRegister.markets.filter((m) => m.priceOracle.version === 300).map((m) => [m.priceOracle.address, m.priceOracle])
407397
+ this.sdk.marketRegister.markets.filter((m) => isV300(m.priceOracle.version)).map((m) => [m.priceOracle.address, m.priceOracle])
407382
407398
  );
407383
407399
  }
407384
407400
  };
@@ -435993,7 +436009,7 @@ function getRenderer(opts) {
435993
436009
  var package_default = {
435994
436010
  name: "@gearbox-protocol/deploy-tools",
435995
436011
  description: "Gearbox deploy tools",
435996
- version: "5.29.3",
436012
+ version: "5.29.5",
435997
436013
  homepage: "https://gearbox.fi",
435998
436014
  keywords: [
435999
436015
  "gearbox"
@@ -436036,7 +436052,7 @@ var package_default = {
436036
436052
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
436037
436053
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
436038
436054
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
436039
- "@gearbox-protocol/sdk": "5.1.0",
436055
+ "@gearbox-protocol/sdk": "6.0.0-next.1",
436040
436056
  "@gearbox-protocol/sdk-gov": "^2.37.0",
436041
436057
  "@types/lodash-es": "^4.17.12",
436042
436058
  "@types/node": "^22.15.12",
@@ -436173,7 +436189,7 @@ function prices() {
436173
436189
  "",
436174
436190
  ""
436175
436191
  ],
436176
- ...printPrices(m.priceOracle)
436192
+ ...printPrices(sdk, m.priceOracle)
436177
436193
  ];
436178
436194
  console.log((0, import_table2.table)(data, tableConfig));
436179
436195
  }
@@ -436198,8 +436214,8 @@ var tableConfig = {
436198
436214
  }
436199
436215
  ]
436200
436216
  };
436201
- function printPrices(oracle) {
436202
- const { mainPriceFeeds, reservePriceFeeds, mainPrices, reservePrices, sdk } = oracle;
436217
+ function printPrices(sdk, oracle) {
436218
+ const { mainPriceFeeds, reservePriceFeeds, mainPrices, reservePrices } = oracle;
436203
436219
  const tokens = /* @__PURE__ */ new Set([
436204
436220
  ...mainPriceFeeds.keys(),
436205
436221
  ...reservePriceFeeds.keys(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/deploy-tools",
3
3
  "description": "Gearbox deploy tools",
4
- "version": "5.29.3",
4
+ "version": "5.29.5",
5
5
  "homepage": "https://gearbox.fi",
6
6
  "keywords": [
7
7
  "gearbox"
@@ -44,7 +44,7 @@
44
44
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
45
45
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
46
46
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
47
- "@gearbox-protocol/sdk": "5.1.0",
47
+ "@gearbox-protocol/sdk": "6.0.0-next.1",
48
48
  "@gearbox-protocol/sdk-gov": "^2.37.0",
49
49
  "@types/lodash-es": "^4.17.12",
50
50
  "@types/node": "^22.15.12",