@gearbox-protocol/sdk 5.1.0 → 6.0.0-next.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.
- package/dist/cjs/dev/calcLiquidatableLTs.js +5 -1
- package/dist/cjs/sdk/base/BaseContract.js +0 -1
- package/dist/cjs/sdk/market/MarketSuite.js +1 -5
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +52 -47
- 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 +28 -9
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -1
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +5 -5
- package/dist/esm/dev/calcLiquidatableLTs.js +5 -1
- package/dist/esm/sdk/base/BaseContract.js +0 -1
- package/dist/esm/sdk/market/MarketSuite.js +2 -6
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +53 -47
- 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 +27 -8
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +2 -1
- package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -2
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +6 -6
- 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/package.json +1 -1
|
@@ -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,16 +1,35 @@
|
|
|
1
1
|
import { isV300, isV310 } from "../../constants/index.js";
|
|
2
|
+
import { PriceOracleBaseContract } from "./PriceOracleBaseContract.js";
|
|
2
3
|
import { PriceOracleV300Contract } from "./PriceOracleV300Contract.js";
|
|
3
4
|
import { PriceOracleV310Contract } from "./PriceOracleV310Contract.js";
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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);
|
|
8
10
|
}
|
|
9
|
-
if (
|
|
10
|
-
return new
|
|
11
|
+
if (isV300(version)) {
|
|
12
|
+
return new PriceOracleV300Contract(sdk, data);
|
|
11
13
|
}
|
|
12
|
-
|
|
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);
|
|
13
32
|
}
|
|
14
33
|
export {
|
|
15
|
-
|
|
34
|
+
getOrCreatePriceOracle
|
|
16
35
|
};
|
|
@@ -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" },
|
|
@@ -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
|
}
|
|
@@ -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
|