@gearbox-protocol/sdk 4.2.0-next.3 → 5.0.0-next.2

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 (79) hide show
  1. package/dist/cjs/bots/BotsPlugin.js +2 -2
  2. package/dist/cjs/dev/calcLiquidatableLTs.js +5 -1
  3. package/dist/cjs/dev/index.js +1 -3
  4. package/dist/cjs/dev/ltUtils.js +2 -2
  5. package/dist/cjs/sdk/GearboxSDK.js +2 -5
  6. package/dist/cjs/sdk/accounts/CreditAccountsService.js +10 -5
  7. package/dist/cjs/sdk/base/BaseContract.js +0 -1
  8. package/dist/cjs/sdk/constants/index.js +3 -1
  9. package/dist/cjs/sdk/{utils/version.js → constants/versions.js} +18 -7
  10. package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
  11. package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +3 -3
  12. package/dist/cjs/sdk/gauges/GaugeStakingService.js +4 -1
  13. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  14. package/dist/cjs/sdk/market/MarketSuite.js +1 -5
  15. package/dist/cjs/sdk/market/credit/createCreditConfigurator.js +3 -2
  16. package/dist/cjs/sdk/market/credit/createCreditFacade.js +3 -2
  17. package/dist/cjs/sdk/market/credit/createCreditManager.js +3 -2
  18. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +55 -49
  19. package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
  20. package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
  21. package/dist/cjs/sdk/market/oracle/createPriceOracle.js +29 -9
  22. package/dist/cjs/sdk/market/pool/createPool.js +3 -2
  23. package/dist/cjs/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
  24. package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
  25. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
  26. package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -1
  27. package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +5 -5
  28. package/dist/cjs/sdk/router/createRouter.js +3 -2
  29. package/dist/cjs/sdk/utils/index.js +1 -3
  30. package/dist/cjs/zappers/ZappersPlugin.js +2 -2
  31. package/dist/esm/bots/BotsPlugin.js +4 -3
  32. package/dist/esm/dev/calcLiquidatableLTs.js +5 -1
  33. package/dist/esm/dev/index.js +0 -1
  34. package/dist/esm/dev/ltUtils.js +9 -3
  35. package/dist/esm/sdk/GearboxSDK.js +6 -6
  36. package/dist/esm/sdk/accounts/CreditAccountsService.js +12 -6
  37. package/dist/esm/sdk/base/BaseContract.js +0 -1
  38. package/dist/esm/sdk/constants/index.js +1 -0
  39. package/dist/esm/sdk/constants/versions.js +18 -0
  40. package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
  41. package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
  42. package/dist/esm/sdk/gauges/GaugeStakingService.js +5 -2
  43. package/dist/esm/sdk/market/MarketRegister.js +7 -3
  44. package/dist/esm/sdk/market/MarketSuite.js +2 -6
  45. package/dist/esm/sdk/market/credit/createCreditConfigurator.js +3 -2
  46. package/dist/esm/sdk/market/credit/createCreditFacade.js +3 -2
  47. package/dist/esm/sdk/market/credit/createCreditManager.js +3 -2
  48. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +60 -50
  49. package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
  50. package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
  51. package/dist/esm/sdk/market/oracle/createPriceOracle.js +28 -8
  52. package/dist/esm/sdk/market/pool/createPool.js +3 -2
  53. package/dist/esm/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
  54. package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
  55. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -3
  56. package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -2
  57. package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +6 -6
  58. package/dist/esm/sdk/router/createRouter.js +3 -2
  59. package/dist/esm/sdk/utils/index.js +0 -1
  60. package/dist/esm/zappers/ZappersPlugin.js +4 -3
  61. package/dist/types/dev/index.d.ts +0 -1
  62. package/dist/types/sdk/constants/index.d.ts +1 -0
  63. package/dist/types/sdk/constants/versions.d.ts +9 -0
  64. package/dist/types/sdk/core/address-provider/AbstractAddressProviderContract.d.ts +3 -2
  65. package/dist/types/sdk/core/address-provider/types.d.ts +3 -2
  66. package/dist/types/sdk/market/MarketSuite.d.ts +2 -2
  67. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +28 -684
  68. package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +1 -1
  69. package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +2 -2
  70. package/dist/types/sdk/market/oracle/createPriceOracle.d.ts +14 -3
  71. package/dist/types/sdk/market/oracle/types.d.ts +97 -6
  72. package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +3 -2
  73. package/dist/types/sdk/utils/index.d.ts +0 -1
  74. package/package.json +1 -1
  75. package/dist/cjs/dev/PriceFeedStore.js +0 -93
  76. package/dist/esm/dev/PriceFeedStore.js +0 -74
  77. package/dist/esm/sdk/utils/version.js +0 -10
  78. package/dist/types/dev/PriceFeedStore.d.ts +0 -10
  79. package/dist/types/sdk/utils/version.d.ts +0 -2
@@ -3,16 +3,16 @@ import { decodeFunctionData, stringToHex } from "viem";
3
3
  import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
4
4
  import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
5
5
  import { BaseContract } from "../../base/index.js";
6
- import { AP_PRICE_FEED_COMPRESSOR } from "../../constants/index.js";
6
+ import {
7
+ AP_PRICE_FEED_COMPRESSOR,
8
+ isV300,
9
+ VERSION_RANGE_310
10
+ } from "../../constants/index.js";
7
11
  import { AddressMap, formatBN } from "../../utils/index.js";
8
12
  import { PriceFeedRef } from "../pricefeeds/index.js";
9
13
  import PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
10
14
  const ZERO_PRICE_FEED = stringToHex("PRICE_FEED::ZERO", { size: 32 });
11
15
  class PriceOracleBaseContract extends BaseContract {
12
- /**
13
- * Underlying token of market to which this price oracle belongs
14
- */
15
- underlying;
16
16
  /**
17
17
  * Mapping Token => [PriceFeed Address, stalenessPeriod]
18
18
  */
@@ -38,12 +38,14 @@ class PriceOracleBaseContract extends BaseContract {
38
38
  void 0,
39
39
  "reservePrices"
40
40
  );
41
- #priceFeedTree = [];
42
- constructor(sdk, args, data, underlying) {
41
+ #priceFeedTree = new AddressMap(
42
+ void 0,
43
+ "priceFeedTree"
44
+ );
45
+ constructor(sdk, args, data) {
43
46
  super(sdk, args);
44
- this.underlying = underlying;
45
47
  const { priceFeedMap, priceFeedTree } = data;
46
- this.#loadState(priceFeedMap, priceFeedTree);
48
+ this.#loadState(priceFeedMap, priceFeedTree, true);
47
49
  }
48
50
  /**
49
51
  * Returns main and reserve price feeds for given tokens
@@ -65,7 +67,7 @@ class PriceOracleBaseContract extends BaseContract {
65
67
  */
66
68
  async updatePriceFeeds() {
67
69
  const updatables = [];
68
- for (const node of this.#priceFeedTree) {
70
+ for (const node of this.#priceFeedTree.values()) {
69
71
  if (node.updatable) {
70
72
  updatables.push(this.sdk.priceFeeds.mustGet(node.baseParams.addr));
71
73
  }
@@ -131,30 +133,19 @@ class PriceOracleBaseContract extends BaseContract {
131
133
  }
132
134
  /**
133
135
  * Returns true if oracle's price feed tree contains given price feed
136
+ * This feed is not necessary connected to token, but can be a component of composite feed for some token
134
137
  * @param priceFeed
135
138
  * @returns
136
139
  */
137
140
  usesPriceFeed(priceFeed) {
138
- return this.#priceFeedTree.some(
139
- (node) => node.baseParams.addr.toLowerCase() === priceFeed.toLowerCase()
140
- );
141
- }
142
- /**
143
- * Tries to convert amount of token into underlying of current market
144
- * @param token
145
- * @param amount
146
- * @param reserve
147
- * @returns
148
- */
149
- convertToUnderlying(token, amount, reserve = false) {
150
- return this.convert(token, this.underlying, amount, reserve);
141
+ return this.#priceFeedTree.has(priceFeed);
151
142
  }
152
143
  /**
153
144
  * Tries to convert amount of from one token to another, using latest known prices
154
145
  * @param from
155
146
  * @param to
156
147
  * @param amount
157
- * @param reserve
148
+ * @param reserve use reserve price feed instead of main
158
149
  */
159
150
  convert(from, to, amount, reserve = false) {
160
151
  if (from === to) {
@@ -169,9 +160,8 @@ class PriceOracleBaseContract extends BaseContract {
169
160
  /**
170
161
  * Tries to convert amount of token to USD, using latest known prices
171
162
  * @param from
172
- * @param to
173
163
  * @param amount
174
- * @param reserve
164
+ * @param reserve use reserve price feed instead of main
175
165
  */
176
166
  convertToUSD(from, amount, reserve = false) {
177
167
  const price = reserve ? this.reservePrice(from) : this.mainPrice(from);
@@ -182,7 +172,7 @@ class PriceOracleBaseContract extends BaseContract {
182
172
  * Tries to convert amount of USD to token, using latest known prices
183
173
  * @param to
184
174
  * @param amount
185
- * @param reserve
175
+ * @param reserve use reserve price feed instead of main
186
176
  */
187
177
  convertFromUSD(to, amount, reserve = false) {
188
178
  const price = reserve ? this.reservePrice(to) : this.mainPrice(to);
@@ -191,26 +181,30 @@ class PriceOracleBaseContract extends BaseContract {
191
181
  }
192
182
  /**
193
183
  * Loads new prices for this oracle from PriceFeedCompressor
194
- * Does not update price feeds, only updates prices
184
+ * Will (re)create price feeds if needed
195
185
  */
196
186
  async updatePrices() {
197
187
  await this.sdk.marketRegister.updatePrices([this.address]);
198
188
  }
189
+ /**
190
+ * Paired method to updatePrices, helps to update prices on all oracles in one multicall
191
+ */
199
192
  syncStateMulticall() {
200
- const args = [this.address];
201
- if (this.version === 300) {
202
- args.push(
193
+ let args = [this.address];
194
+ if (isV300(this.version)) {
195
+ args = [
196
+ args[0],
203
197
  Array.from(
204
198
  /* @__PURE__ */ new Set([
205
- this.underlying,
206
199
  ...this.mainPriceFeeds.keys(),
207
200
  ...this.reservePriceFeeds.keys()
208
201
  ])
209
202
  )
210
- );
203
+ ];
211
204
  }
212
- const [address] = this.sdk.addressProvider.getLatestVersion(
213
- AP_PRICE_FEED_COMPRESSOR
205
+ const [address] = this.sdk.addressProvider.mustGetLatest(
206
+ AP_PRICE_FEED_COMPRESSOR,
207
+ VERSION_RANGE_310
214
208
  );
215
209
  return {
216
210
  call: {
@@ -221,25 +215,39 @@ class PriceOracleBaseContract extends BaseContract {
221
215
  },
222
216
  onResult: (resp) => {
223
217
  const { priceFeedMap, priceFeedTree } = resp;
224
- this.#loadState(priceFeedMap, priceFeedTree);
218
+ this.#loadState(priceFeedMap, priceFeedTree, true);
225
219
  }
226
220
  };
227
221
  }
228
- #loadState(entries, tree) {
229
- this.#priceFeedTree = tree;
230
- this.mainPriceFeeds.clear();
231
- this.reservePriceFeeds.clear();
232
- this.mainPrices.clear();
233
- this.reservePrices.clear();
222
+ /**
223
+ * Helper function to handle situation when we have multiple different compressor data entries for same oracle
224
+ * This happens in v300
225
+ *
226
+ * @deprecated should be unnecessary after full v310 migration (oracles will be unique)
227
+ * @param data
228
+ * @returns
229
+ */
230
+ merge(data) {
231
+ const { priceFeedMap, priceFeedTree } = data;
232
+ this.#loadState(priceFeedMap, priceFeedTree, false);
233
+ return this;
234
+ }
235
+ #loadState(entries, tree, reset) {
236
+ if (reset) {
237
+ this.#priceFeedTree.clear();
238
+ this.mainPriceFeeds.clear();
239
+ this.reservePriceFeeds.clear();
240
+ this.mainPrices.clear();
241
+ this.reservePrices.clear();
242
+ }
234
243
  for (const node of tree) {
244
+ this.#priceFeedTree.upsert(node.baseParams.addr, node);
235
245
  this.sdk.priceFeeds.getOrCreate(node);
236
246
  }
237
- entries.forEach((entry) => {
247
+ for (const entry of entries) {
238
248
  const { token, priceFeed, reserve, stalenessPeriod } = entry;
239
249
  const ref = new PriceFeedRef(this.sdk, priceFeed, stalenessPeriod);
240
- const node = this.#priceFeedTree.find(
241
- (n) => n.baseParams.addr === priceFeed
242
- );
250
+ const node = this.#priceFeedTree.get(priceFeed);
243
251
  const price = node?.answer?.price;
244
252
  const priceFeedType = node?.baseParams.contractType;
245
253
  if (reserve) {
@@ -256,7 +264,7 @@ class PriceOracleBaseContract extends BaseContract {
256
264
  }
257
265
  }
258
266
  this.#labelPriceFeed(priceFeed, reserve ? "Reserve" : "Main", token);
259
- });
267
+ }
260
268
  this.logger?.debug(
261
269
  `Got ${this.mainPriceFeeds.size} main and ${this.reservePriceFeeds.size} reserve price feeds`
262
270
  );
@@ -277,6 +285,8 @@ class PriceOracleBaseContract extends BaseContract {
277
285
  * Helper method to find "attachment point" of price feed (makes sense for updatable price feeds only) -
278
286
  * returns token (in v3.0 can be ticker) and main/reserve flag
279
287
  *
288
+ * @deprecated Should be gone after v310 migration
289
+ *
280
290
  * @param priceFeed
281
291
  * @returns
282
292
  */
@@ -293,6 +303,9 @@ class PriceOracleBaseContract extends BaseContract {
293
303
  }
294
304
  return [void 0, false];
295
305
  }
306
+ /**
307
+ * Returns list of addresses that should be watched for events to sync state
308
+ */
296
309
  get watchAddresses() {
297
310
  return /* @__PURE__ */ new Set([this.address]);
298
311
  }
@@ -319,9 +332,6 @@ class PriceOracleBaseContract extends BaseContract {
319
332
  )
320
333
  };
321
334
  }
322
- get priceFeedTree() {
323
- return this.#priceFeedTree;
324
- }
325
335
  #noAnswerWarn(priceFeed, node) {
326
336
  let label = this.labelAddress(priceFeed);
327
337
  if (!node) {
@@ -4,7 +4,7 @@ import { tickerInfoTokensByNetwork } from "../../sdk-gov-legacy/index.js";
4
4
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
5
5
  const abi = [...iPriceOracleV300Abi, ...iPausableAbi];
6
6
  class PriceOracleV300Contract extends PriceOracleBaseContract {
7
- constructor(sdk, data, underlying) {
7
+ constructor(sdk, data) {
8
8
  super(
9
9
  sdk,
10
10
  {
@@ -12,8 +12,7 @@ class PriceOracleV300Contract extends PriceOracleBaseContract {
12
12
  name: "PriceOracleV3",
13
13
  abi
14
14
  },
15
- data,
16
- underlying
15
+ data
17
16
  );
18
17
  }
19
18
  processLog(log) {
@@ -2,7 +2,7 @@ import { iPriceOracleV310Abi } from "../../../abi/v310.js";
2
2
  import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
3
3
  const abi = iPriceOracleV310Abi;
4
4
  class PriceOracleV310Contract extends PriceOracleBaseContract {
5
- constructor(sdk, data, underlying) {
5
+ constructor(sdk, data) {
6
6
  super(
7
7
  sdk,
8
8
  {
@@ -10,8 +10,7 @@ class PriceOracleV310Contract extends PriceOracleBaseContract {
10
10
  name: "PriceOracleV3",
11
11
  abi
12
12
  },
13
- data,
14
- underlying
13
+ data
15
14
  );
16
15
  }
17
16
  processLog(log) {
@@ -1,15 +1,35 @@
1
+ import { isV300, isV310 } from "../../constants/index.js";
2
+ import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
1
3
  import { PriceOracleV300Contract } from "./PriceOracleV300Contract.js";
2
4
  import { PriceOracleV310Contract } from "./PriceOracleV310Contract.js";
3
- function createPriceOracle(sdk, data, underlying) {
4
- const v = data.baseParams.version;
5
- if (v >= 300n && v < 310n) {
6
- return new PriceOracleV300Contract(sdk, data, underlying);
5
+ function getOrCreatePriceOracle(sdk, data) {
6
+ const { version, addr } = data.baseParams;
7
+ const existing = sdk.contracts.get(addr);
8
+ if (existing) {
9
+ return tryExtendExistingOracle(existing, data);
7
10
  }
8
- if (v === 310n) {
9
- return new PriceOracleV310Contract(sdk, data, underlying);
11
+ if (isV300(version)) {
12
+ return new PriceOracleV300Contract(sdk, data);
10
13
  }
11
- throw new Error(`Unsupported oracle version ${v}`);
14
+ if (isV310(version)) {
15
+ return new PriceOracleV310Contract(sdk, data);
16
+ }
17
+ throw new Error(`Unsupported oracle version ${version}`);
18
+ }
19
+ function tryExtendExistingOracle(existing, data) {
20
+ const { version, addr } = data.baseParams;
21
+ if (!(existing instanceof PriceOracleBaseContract)) {
22
+ throw new Error(
23
+ `expected oracle contract at ${addr}, found existing ${existing.contractType}`
24
+ );
25
+ }
26
+ if (Number(existing.version) !== Number(version)) {
27
+ throw new Error(
28
+ `expected oracle contract at ${addr} to have version ${version}, found ${existing.version}`
29
+ );
30
+ }
31
+ return existing.merge(data);
12
32
  }
13
33
  export {
14
- createPriceOracle
34
+ getOrCreatePriceOracle
15
35
  };
@@ -1,11 +1,12 @@
1
+ import { isV300, isV310 } from "../../constants/index.js";
1
2
  import { PoolV300Contract } from "./PoolV300Contract.js";
2
3
  import { PoolV310Contract } from "./PoolV310Contract.js";
3
4
  function createPool(sdk, data) {
4
5
  const v = data.baseParams.version;
5
- if (v >= 300n && v < 310n) {
6
+ if (isV300(v)) {
6
7
  return new PoolV300Contract(sdk, data);
7
8
  }
8
- if (v === 310n) {
9
+ if (isV310(v)) {
9
10
  return new PoolV310Contract(sdk, data);
10
11
  }
11
12
  throw new Error(`Unsupported pool version ${v}`);
@@ -1,11 +1,12 @@
1
+ import { isV300, isV310 } from "../../constants/index.js";
1
2
  import { PoolQuotaKeeperV300Contract } from "./PoolQuotaKeeperV300Contract.js";
2
3
  import { PoolQuotaKeeperV310Contract } from "./PoolQuotaKeeperV310Contract.js";
3
4
  function createPoolQuotaKeeper(sdk, pool, pqk) {
4
5
  const v = pqk.baseParams.version;
5
- if (v >= 300n && v < 310n) {
6
+ if (isV300(v)) {
6
7
  return new PoolQuotaKeeperV300Contract(sdk, pool, pqk);
7
8
  }
8
- if (v === 310n) {
9
+ if (isV310(v)) {
9
10
  return new PoolQuotaKeeperV310Contract(sdk, pool, pqk);
10
11
  }
11
12
  throw new Error(`Unsupported pool quota keeper version ${v}`);
@@ -1,4 +1,5 @@
1
1
  import { decodeAbiParameters, hexToBytes } from "viem";
2
+ import { isV310 } from "../../constants/versions.js";
2
3
  import {
3
4
  AbstractPriceFeedContract
4
5
  } from "./AbstractPriceFeed.js";
@@ -15,7 +16,7 @@ class AbstractLPPriceFeedContract extends AbstractPriceFeedContract {
15
16
  constructor(sdk, args) {
16
17
  super(sdk, { ...args, decimals: 8 });
17
18
  this.hasLowerBoundCap = true;
18
- if (args.baseParams.version === 310n) {
19
+ if (isV310(args.baseParams.version)) {
19
20
  const decoder = decodeAbiParameters(
20
21
  [
21
22
  { type: "address", name: "lpToken" },
@@ -2,7 +2,8 @@ import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
2
2
  import { SDKConstruct } from "../../base/index.js";
3
3
  import {
4
4
  ADDRESS_0X0,
5
- AP_PRICE_FEED_COMPRESSOR
5
+ AP_PRICE_FEED_COMPRESSOR,
6
+ VERSION_RANGE_310
6
7
  } from "../../constants/index.js";
7
8
  import { AddressMap, bytes32ToString, childLogger } from "../../utils/index.js";
8
9
  import { Hooks } from "../../utils/internal/index.js";
@@ -109,9 +110,9 @@ class PriceFeedRegister extends SDKConstruct {
109
110
  * This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
110
111
  */
111
112
  async getPartialUpdatablePriceFeeds(marketConfigurators, pools) {
112
- const priceFeedCompressorAddress = this.sdk.addressProvider.getAddress(
113
+ const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
113
114
  AP_PRICE_FEED_COMPRESSOR,
114
- 310
115
+ VERSION_RANGE_310
115
116
  );
116
117
  const configurators = marketConfigurators ?? this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
117
118
  this.logger?.debug(
@@ -1,6 +1,6 @@
1
1
  import { bytesToString, decodeAbiParameters, toBytes } from "viem";
2
2
  import { redstonePriceFeedAbi } from "../../abi/index.js";
3
- import { ADDRESS_0X0 } from "../../constants/index.js";
3
+ import { ADDRESS_0X0, isV310 } from "../../constants/index.js";
4
4
  import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
5
5
  class RedstonePriceFeedContract extends AbstractPriceFeedContract {
6
6
  token;
@@ -16,7 +16,7 @@ class RedstonePriceFeedContract extends AbstractPriceFeedContract {
16
16
  name: `RedstonePriceFeed`,
17
17
  abi: redstonePriceFeedAbi
18
18
  });
19
- if (args.baseParams.version === 310n) {
19
+ if (isV310(args.baseParams.version)) {
20
20
  const decoder = decodeAbiParameters(
21
21
  [
22
22
  { type: "address", name: "token" },
@@ -1,7 +1,7 @@
1
1
  import { getAbiItem, getAddress } from "viem";
2
2
  import { iPriceOracleV300Abi } from "../../abi/v300.js";
3
3
  import { SDKConstruct } from "../base/index.js";
4
- import { ADDRESS_PROVIDER_BLOCK } from "../constants/index.js";
4
+ import { ADDRESS_PROVIDER_BLOCK, isV300 } from "../constants/index.js";
5
5
  import { PriceFeedRef } from "../market/index.js";
6
6
  import { AddressMap, formatDuration, hexEq } from "../utils/index.js";
7
7
  import { getLogsSafe } from "../utils/viem/index.js";
@@ -16,12 +16,12 @@ class V300StalenessPeriodPlugin extends SDKConstruct {
16
16
  this.#logger = sdk.logger?.child?.({ name: "V300StalenessPeriodPlugin" }) ?? sdk.logger;
17
17
  }
18
18
  async attach() {
19
- await this.#syncReservePriceFeeds();
19
+ await this.#syncPriceFeeds();
20
20
  }
21
21
  async syncState() {
22
- await this.#syncReservePriceFeeds();
22
+ await this.#syncPriceFeeds();
23
23
  }
24
- async #syncReservePriceFeeds() {
24
+ async #syncPriceFeeds() {
25
25
  const oracles = this.#getOraclesMap();
26
26
  const [fromBlock, toBlock] = [this.#syncedTo + 1n, this.sdk.currentBlock];
27
27
  if (oracles.size === 0 || fromBlock > toBlock) {
@@ -44,7 +44,7 @@ class V300StalenessPeriodPlugin extends SDKConstruct {
44
44
  strict: true
45
45
  });
46
46
  this.#logger?.info(
47
- `loaded ${events.length} SetReservePriceFeed events in range [${fromBlock}; ${toBlock}]`
47
+ `loaded ${events.length} price feed events in range [${fromBlock}; ${toBlock}]`
48
48
  );
49
49
  for (const e of events) {
50
50
  const oracle = oracles.mustGet(e.address);
@@ -97,7 +97,7 @@ class V300StalenessPeriodPlugin extends SDKConstruct {
97
97
  }
98
98
  #getOraclesMap() {
99
99
  return new AddressMap(
100
- this.sdk.marketRegister.markets.filter((m) => m.priceOracle.version === 300).map((m) => [m.priceOracle.address, m.priceOracle])
100
+ this.sdk.marketRegister.markets.filter((m) => isV300(m.priceOracle.version)).map((m) => [m.priceOracle.address, m.priceOracle])
101
101
  );
102
102
  }
103
103
  }
@@ -1,10 +1,11 @@
1
+ import { isV300, isV310 } from "../constants/index.js";
1
2
  import { RouterV300Contract } from "./RouterV300Contract.js";
2
3
  import { RouterV310Contract } from "./RouterV310Contract.js";
3
4
  function createRouter(sdk, address, version) {
4
- if (version >= 300 && version < 310) {
5
+ if (isV300(version)) {
5
6
  return new RouterV300Contract(sdk, address, version);
6
7
  }
7
- if (version === 310) {
8
+ if (isV310(version)) {
8
9
  return new RouterV310Contract(sdk, address, version);
9
10
  }
10
11
  throw new Error(`Unsupported router version ${version}`);
@@ -10,4 +10,3 @@ export * from "./json.js";
10
10
  export * from "./mappers.js";
11
11
  export * from "./retry.js";
12
12
  export * from "./toAddress.js";
13
- export * from "./version.js";
@@ -2,7 +2,8 @@ import { iPeripheryCompressorAbi } from "../abi/compressors.js";
2
2
  import {
3
3
  AddressMap,
4
4
  AP_PERIPHERY_COMPRESSOR,
5
- SDKConstruct
5
+ SDKConstruct,
6
+ VERSION_RANGE_310
6
7
  } from "../sdk/index.js";
7
8
  class ZappersPlugin extends SDKConstruct {
8
9
  #zappers;
@@ -12,9 +13,9 @@ class ZappersPlugin extends SDKConstruct {
12
13
  }
13
14
  async loadZappers() {
14
15
  this.#zappers = new AddressMap(void 0, "zappers");
15
- const pcAddr = this.sdk.addressProvider.getAddress(
16
+ const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
16
17
  AP_PERIPHERY_COMPRESSOR,
17
- 310
18
+ VERSION_RANGE_310
18
19
  );
19
20
  this.sdk.logger?.debug(
20
21
  `loading zappers with periphery compressor ${pcAddr}`
@@ -6,4 +6,3 @@ export * from "./createTransport.js";
6
6
  export * from "./detectChain.js";
7
7
  export * from "./ltUtils.js";
8
8
  export * from "./migrateFaucet.js";
9
- export * from "./PriceFeedStore.js";
@@ -4,3 +4,4 @@ export * from "./bot-permissions.js";
4
4
  export * from "./math.js";
5
5
  export * from "./networks.js";
6
6
  export * from "./periphery.js";
7
+ export * from "./versions.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Version range, inclusive of both ends
3
+ */
4
+ export type VersionRange = [number, number];
5
+ export declare const VERSION_RANGE_300: VersionRange;
6
+ export declare const VERSION_RANGE_310: VersionRange;
7
+ export declare function isV300(version: number | bigint | string): boolean;
8
+ export declare function isV310(version: number | bigint | string): boolean;
9
+ export declare function isVersionRange(version: number | bigint | string, range: VersionRange): boolean;
@@ -1,6 +1,7 @@
1
1
  import { type Abi, type Address } from "viem";
2
2
  import type { BaseContractOptions } from "../../base/BaseContract.js";
3
3
  import { BaseContract } from "../../base/index.js";
4
+ import type { VersionRange } from "../../constants/index.js";
4
5
  import type { GearboxSDK } from "../../GearboxSDK.js";
5
6
  import type { AddressProviderV3StateHuman } from "../../types/index.js";
6
7
  import type { AddressProviderState } from "./types.js";
@@ -9,8 +10,8 @@ export default abstract class AbstractAddressProviderContract<abi extends Abi |
9
10
  constructor(sdk: GearboxSDK, args: BaseContractOptions<abi>, addresses?: Record<string, Record<number, Address>>);
10
11
  protected setInternalAddress(key: string, address: Address, version: number): void;
11
12
  getAddress(contract: string, version?: number): Address;
12
- getLatestVersion(contract: string): [address: Address, version: number];
13
- getLatestInRange(contract: string, range: [number, number]): [address: Address, version: number] | undefined;
13
+ getLatest(contract: string, range: VersionRange): [address: Address, version: number] | undefined;
14
+ mustGetLatest(contract: string, range: VersionRange): [address: Address, version: number];
14
15
  get state(): AddressProviderState;
15
16
  stateHuman(raw?: boolean): AddressProviderV3StateHuman;
16
17
  }
@@ -1,5 +1,6 @@
1
1
  import type { Address } from "viem";
2
2
  import type { BaseParams, IBaseContract } from "../../base/index.js";
3
+ import type { VersionRange } from "../../constants/versions.js";
3
4
  import type { AddressProviderV3StateHuman } from "../../types/index.js";
4
5
  export interface AddressProviderState {
5
6
  baseParams: BaseParams;
@@ -8,8 +9,8 @@ export interface AddressProviderState {
8
9
  export interface IAddressProviderContract extends IBaseContract {
9
10
  state: AddressProviderState;
10
11
  getAddress: (contract: string, version?: number) => Address;
11
- getLatestVersion: (contract: string) => [address: Address, version: number];
12
- getLatestInRange: (contract: string, range: [number, number]) => [address: Address, version: number] | undefined;
12
+ getLatest: (contract: string, range: VersionRange) => [address: Address, version: number] | undefined;
13
+ mustGetLatest: (contract: string, range: VersionRange) => [address: Address, version: number];
13
14
  syncState: (blockNumber: bigint) => Promise<void>;
14
15
  stateHuman: (raw?: boolean) => AddressProviderV3StateHuman;
15
16
  }
@@ -5,13 +5,13 @@ import type { GearboxSDK } from "../GearboxSDK.js";
5
5
  import type { MarketStateHuman } from "../types/index.js";
6
6
  import { CreditSuite } from "./credit/index.js";
7
7
  import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
8
- import type { PriceOracleContract } from "./oracle/index.js";
8
+ import type { IPriceOracleContract } from "./oracle/index.js";
9
9
  import { PoolSuite } from "./pool/index.js";
10
10
  export declare class MarketSuite extends SDKConstruct {
11
11
  readonly acl: Address;
12
12
  readonly configurator: MarketConfiguratorContract;
13
13
  readonly pool: PoolSuite;
14
- readonly priceOracle: PriceOracleContract;
14
+ readonly priceOracle: IPriceOracleContract;
15
15
  readonly creditManagers: CreditSuite[];
16
16
  /**
17
17
  * Original data received from compressor