@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.
- package/dist/cjs/bots/BotsPlugin.js +2 -2
- package/dist/cjs/dev/calcLiquidatableLTs.js +5 -1
- package/dist/cjs/dev/index.js +1 -3
- package/dist/cjs/dev/ltUtils.js +2 -2
- package/dist/cjs/sdk/GearboxSDK.js +2 -5
- package/dist/cjs/sdk/accounts/CreditAccountsService.js +10 -5
- package/dist/cjs/sdk/base/BaseContract.js +0 -1
- package/dist/cjs/sdk/constants/index.js +3 -1
- package/dist/cjs/sdk/{utils/version.js → constants/versions.js} +18 -7
- package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
- package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +3 -3
- package/dist/cjs/sdk/gauges/GaugeStakingService.js +4 -1
- package/dist/cjs/sdk/market/MarketRegister.js +2 -2
- package/dist/cjs/sdk/market/MarketSuite.js +1 -5
- package/dist/cjs/sdk/market/credit/createCreditConfigurator.js +3 -2
- package/dist/cjs/sdk/market/credit/createCreditFacade.js +3 -2
- package/dist/cjs/sdk/market/credit/createCreditManager.js +3 -2
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +55 -49
- package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
- package/dist/cjs/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
- package/dist/cjs/sdk/market/oracle/createPriceOracle.js +29 -9
- package/dist/cjs/sdk/market/pool/createPool.js +3 -2
- package/dist/cjs/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -1
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +5 -5
- package/dist/cjs/sdk/router/createRouter.js +3 -2
- package/dist/cjs/sdk/utils/index.js +1 -3
- package/dist/cjs/zappers/ZappersPlugin.js +2 -2
- package/dist/esm/bots/BotsPlugin.js +4 -3
- package/dist/esm/dev/calcLiquidatableLTs.js +5 -1
- package/dist/esm/dev/index.js +0 -1
- package/dist/esm/dev/ltUtils.js +9 -3
- package/dist/esm/sdk/GearboxSDK.js +6 -6
- package/dist/esm/sdk/accounts/CreditAccountsService.js +12 -6
- package/dist/esm/sdk/base/BaseContract.js +0 -1
- package/dist/esm/sdk/constants/index.js +1 -0
- package/dist/esm/sdk/constants/versions.js +18 -0
- package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +8 -12
- package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/esm/sdk/gauges/GaugeStakingService.js +5 -2
- package/dist/esm/sdk/market/MarketRegister.js +7 -3
- package/dist/esm/sdk/market/MarketSuite.js +2 -6
- package/dist/esm/sdk/market/credit/createCreditConfigurator.js +3 -2
- package/dist/esm/sdk/market/credit/createCreditFacade.js +3 -2
- package/dist/esm/sdk/market/credit/createCreditManager.js +3 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +60 -50
- package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +2 -3
- package/dist/esm/sdk/market/oracle/PriceOracleV310Contract.js +2 -3
- package/dist/esm/sdk/market/oracle/createPriceOracle.js +28 -8
- package/dist/esm/sdk/market/pool/createPool.js +3 -2
- package/dist/esm/sdk/market/pool/createPoolQuotaKeeper.js +3 -2
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -3
- package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -2
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +6 -6
- package/dist/esm/sdk/router/createRouter.js +3 -2
- package/dist/esm/sdk/utils/index.js +0 -1
- package/dist/esm/zappers/ZappersPlugin.js +4 -3
- package/dist/types/dev/index.d.ts +0 -1
- package/dist/types/sdk/constants/index.d.ts +1 -0
- package/dist/types/sdk/constants/versions.d.ts +9 -0
- package/dist/types/sdk/core/address-provider/AbstractAddressProviderContract.d.ts +3 -2
- package/dist/types/sdk/core/address-provider/types.d.ts +3 -2
- package/dist/types/sdk/market/MarketSuite.d.ts +2 -2
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +28 -684
- package/dist/types/sdk/market/oracle/PriceOracleV300Contract.d.ts +1 -1
- package/dist/types/sdk/market/oracle/PriceOracleV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/oracle/createPriceOracle.d.ts +14 -3
- package/dist/types/sdk/market/oracle/types.d.ts +97 -6
- package/dist/types/sdk/plugins/V300StalenessPeriodPlugin.d.ts +3 -2
- package/dist/types/sdk/utils/index.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/dev/PriceFeedStore.js +0 -93
- package/dist/esm/dev/PriceFeedStore.js +0 -74
- package/dist/esm/sdk/utils/version.js +0 -10
- package/dist/types/dev/PriceFeedStore.d.ts +0 -10
- 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 {
|
|
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
|
-
|
|
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.
|
|
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
|
-
*
|
|
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
|
-
|
|
201
|
-
if (this.version
|
|
202
|
-
args
|
|
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.
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
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 (
|
|
9
|
-
return new
|
|
11
|
+
if (isV300(version)) {
|
|
12
|
+
return new PriceOracleV300Contract(sdk, data);
|
|
10
13
|
}
|
|
11
|
-
|
|
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
|
-
|
|
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
|
|
6
|
+
if (isV300(v)) {
|
|
6
7
|
return new PoolV300Contract(sdk, data);
|
|
7
8
|
}
|
|
8
|
-
if (v
|
|
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
|
|
6
|
+
if (isV300(v)) {
|
|
6
7
|
return new PoolQuotaKeeperV300Contract(sdk, pool, pqk);
|
|
7
8
|
}
|
|
8
|
-
if (v
|
|
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
|
|
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.
|
|
113
|
+
const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
|
|
113
114
|
AP_PRICE_FEED_COMPRESSOR,
|
|
114
|
-
|
|
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
|
|
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.#
|
|
19
|
+
await this.#syncPriceFeeds();
|
|
20
20
|
}
|
|
21
21
|
async syncState() {
|
|
22
|
-
await this.#
|
|
22
|
+
await this.#syncPriceFeeds();
|
|
23
23
|
}
|
|
24
|
-
async #
|
|
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}
|
|
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
|
|
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
|
|
5
|
+
if (isV300(version)) {
|
|
5
6
|
return new RouterV300Contract(sdk, address, version);
|
|
6
7
|
}
|
|
7
|
-
if (version
|
|
8
|
+
if (isV310(version)) {
|
|
8
9
|
return new RouterV310Contract(sdk, address, version);
|
|
9
10
|
}
|
|
10
11
|
throw new Error(`Unsupported router version ${version}`);
|
|
@@ -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.
|
|
16
|
+
const [pcAddr] = this.sdk.addressProvider.mustGetLatest(
|
|
16
17
|
AP_PERIPHERY_COMPRESSOR,
|
|
17
|
-
|
|
18
|
+
VERSION_RANGE_310
|
|
18
19
|
);
|
|
19
20
|
this.sdk.logger?.debug(
|
|
20
21
|
`loading zappers with periphery compressor ${pcAddr}`
|
|
@@ -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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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 {
|
|
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:
|
|
14
|
+
readonly priceOracle: IPriceOracleContract;
|
|
15
15
|
readonly creditManagers: CreditSuite[];
|
|
16
16
|
/**
|
|
17
17
|
* Original data received from compressor
|