@gearbox-protocol/sdk 9.5.1 → 9.6.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/sdk/GearboxSDK.js +4 -3
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +8 -0
- package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +8 -17
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +6 -0
- package/dist/esm/sdk/GearboxSDK.js +4 -3
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +8 -0
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +8 -17
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +6 -0
- package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -1
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +2 -5
- package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +4 -0
- package/dist/types/sdk/market/pricefeeds/types.d.ts +5 -4
- package/package.json +1 -1
|
@@ -89,9 +89,8 @@ class GearboxSDK {
|
|
|
89
89
|
gasLimit
|
|
90
90
|
} = options;
|
|
91
91
|
let { networkType, addressProvider, chainId } = options;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
});
|
|
92
|
+
const transport = (0, import_chain.createTransport)(options);
|
|
93
|
+
const attachClient = (0, import_viem.createPublicClient)({ transport });
|
|
95
94
|
if (!networkType) {
|
|
96
95
|
networkType = await (0, import_chain.detectNetwork)(attachClient);
|
|
97
96
|
}
|
|
@@ -104,6 +103,8 @@ class GearboxSDK {
|
|
|
104
103
|
const marketConfigurators = mcs ?? import_utils.TypedObjectUtils.keys(import_chain.chains[networkType].defaultMarketConfigurators);
|
|
105
104
|
const provider = new import_chain.Provider({
|
|
106
105
|
...options,
|
|
106
|
+
transport,
|
|
107
|
+
// pass transport to avoid creating a new transport in provider
|
|
107
108
|
chainId,
|
|
108
109
|
networkType
|
|
109
110
|
});
|
|
@@ -22,6 +22,7 @@ __export(AbstractLPPriceFeed_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(AbstractLPPriceFeed_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
+
var import_abi = require("../../abi/index.js");
|
|
25
26
|
var import_versions = require("../../constants/versions.js");
|
|
26
27
|
var import_AbstractPriceFeed = require("./AbstractPriceFeed.js");
|
|
27
28
|
const LOWER_BOUND_FACTOR = 99n;
|
|
@@ -89,6 +90,13 @@ class AbstractLPPriceFeedContract extends import_AbstractPriceFeed.AbstractPrice
|
|
|
89
90
|
);
|
|
90
91
|
return lowerBound;
|
|
91
92
|
}
|
|
93
|
+
async currentLowerBound() {
|
|
94
|
+
return await this.sdk.provider.publicClient.readContract({
|
|
95
|
+
abi: import_abi.ilpPriceFeedAbi,
|
|
96
|
+
address: this.address,
|
|
97
|
+
functionName: "lowerBound"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
92
100
|
static toLowerBound(value) {
|
|
93
101
|
return value * LOWER_BOUND_FACTOR / 100n;
|
|
94
102
|
}
|
|
@@ -22,7 +22,6 @@ __export(AbstractPriceFeed_exports, {
|
|
|
22
22
|
PartialPriceFeedInitError: () => PartialPriceFeedInitError
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(AbstractPriceFeed_exports);
|
|
25
|
-
var import_abi = require("../../abi/index.js");
|
|
26
25
|
var import_base = require("../../base/index.js");
|
|
27
26
|
var import_isUpdatablePriceFeed = require("./isUpdatablePriceFeed.js");
|
|
28
27
|
var import_PriceFeedRef = require("./PriceFeedRef.js");
|
|
@@ -44,6 +43,7 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
|
|
|
44
43
|
#decimals;
|
|
45
44
|
#underlyingPriceFeeds;
|
|
46
45
|
#skipCheck;
|
|
46
|
+
#answer;
|
|
47
47
|
#args;
|
|
48
48
|
hasLowerBoundCap = false;
|
|
49
49
|
description;
|
|
@@ -60,6 +60,7 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
|
|
|
60
60
|
this.#decimals = args.decimals;
|
|
61
61
|
this.#updatable = args.updatable;
|
|
62
62
|
this.#skipCheck = args.skipCheck;
|
|
63
|
+
this.#answer = args.answer;
|
|
63
64
|
if (args.underlyingFeeds && args.underlyingStalenessPeriods) {
|
|
64
65
|
const underlyingStalenessPeriods = args.underlyingStalenessPeriods;
|
|
65
66
|
this.#underlyingPriceFeeds = args.underlyingFeeds.map(
|
|
@@ -94,6 +95,12 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
|
|
|
94
95
|
}
|
|
95
96
|
return this.#underlyingPriceFeeds;
|
|
96
97
|
}
|
|
98
|
+
get answer() {
|
|
99
|
+
if (this.#answer === void 0) {
|
|
100
|
+
throw new PartialPriceFeedInitError(this.#args);
|
|
101
|
+
}
|
|
102
|
+
return this.#answer;
|
|
103
|
+
}
|
|
97
104
|
get priceFeedType() {
|
|
98
105
|
return this.contractType;
|
|
99
106
|
}
|
|
@@ -106,22 +113,6 @@ class AbstractPriceFeedContract extends import_base.BaseContract {
|
|
|
106
113
|
pricefeeds: this.underlyingPriceFeeds.map((f) => f.stateHuman(raw))
|
|
107
114
|
};
|
|
108
115
|
}
|
|
109
|
-
async currentLowerBound() {
|
|
110
|
-
return await this.sdk.provider.publicClient.readContract({
|
|
111
|
-
abi: import_abi.ilpPriceFeedAbi,
|
|
112
|
-
address: this.address,
|
|
113
|
-
functionName: "lowerBound"
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
async answer(overrides) {
|
|
117
|
-
const lastRoundData = await this.sdk.provider.publicClient.readContract({
|
|
118
|
-
abi: import_abi.ilpPriceFeedAbi,
|
|
119
|
-
address: this.address,
|
|
120
|
-
functionName: "latestRoundData",
|
|
121
|
-
...overrides
|
|
122
|
-
});
|
|
123
|
-
return lastRoundData[1];
|
|
124
|
-
}
|
|
125
116
|
updatableDependencies() {
|
|
126
117
|
const underlying = this.underlyingPriceFeeds.flatMap(
|
|
127
118
|
(f) => f.priceFeed.updatableDependencies()
|
|
@@ -63,6 +63,12 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
63
63
|
}
|
|
64
64
|
addHook = this.#hooks.addHook.bind(this.#hooks);
|
|
65
65
|
removeHook = this.#hooks.removeHook.bind(this.#hooks);
|
|
66
|
+
/**
|
|
67
|
+
* Returns all price feeds known to sdk
|
|
68
|
+
*/
|
|
69
|
+
get feeds() {
|
|
70
|
+
return this.#feeds.values();
|
|
71
|
+
}
|
|
66
72
|
/**
|
|
67
73
|
* Returns RawTxs to update price feeds
|
|
68
74
|
* @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
|
|
@@ -87,9 +87,8 @@ class GearboxSDK {
|
|
|
87
87
|
gasLimit
|
|
88
88
|
} = options;
|
|
89
89
|
let { networkType, addressProvider, chainId } = options;
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
});
|
|
90
|
+
const transport = createTransport(options);
|
|
91
|
+
const attachClient = createPublicClient({ transport });
|
|
93
92
|
if (!networkType) {
|
|
94
93
|
networkType = await detectNetwork(attachClient);
|
|
95
94
|
}
|
|
@@ -102,6 +101,8 @@ class GearboxSDK {
|
|
|
102
101
|
const marketConfigurators = mcs ?? TypedObjectUtils.keys(chains[networkType].defaultMarketConfigurators);
|
|
103
102
|
const provider = new Provider({
|
|
104
103
|
...options,
|
|
104
|
+
transport,
|
|
105
|
+
// pass transport to avoid creating a new transport in provider
|
|
105
106
|
chainId,
|
|
106
107
|
networkType
|
|
107
108
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decodeAbiParameters, hexToBytes } from "viem";
|
|
2
|
+
import { ilpPriceFeedAbi } from "../../abi/index.js";
|
|
2
3
|
import { isV310 } from "../../constants/versions.js";
|
|
3
4
|
import {
|
|
4
5
|
AbstractPriceFeedContract
|
|
@@ -68,6 +69,13 @@ class AbstractLPPriceFeedContract extends AbstractPriceFeedContract {
|
|
|
68
69
|
);
|
|
69
70
|
return lowerBound;
|
|
70
71
|
}
|
|
72
|
+
async currentLowerBound() {
|
|
73
|
+
return await this.sdk.provider.publicClient.readContract({
|
|
74
|
+
abi: ilpPriceFeedAbi,
|
|
75
|
+
address: this.address,
|
|
76
|
+
functionName: "lowerBound"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
71
79
|
static toLowerBound(value) {
|
|
72
80
|
return value * LOWER_BOUND_FACTOR / 100n;
|
|
73
81
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ilpPriceFeedAbi } from "../../abi/index.js";
|
|
2
1
|
import { BaseContract } from "../../base/index.js";
|
|
3
2
|
import { isUpdatablePriceFeed } from "./isUpdatablePriceFeed.js";
|
|
4
3
|
import { PriceFeedRef } from "./PriceFeedRef.js";
|
|
@@ -20,6 +19,7 @@ class AbstractPriceFeedContract extends BaseContract {
|
|
|
20
19
|
#decimals;
|
|
21
20
|
#underlyingPriceFeeds;
|
|
22
21
|
#skipCheck;
|
|
22
|
+
#answer;
|
|
23
23
|
#args;
|
|
24
24
|
hasLowerBoundCap = false;
|
|
25
25
|
description;
|
|
@@ -36,6 +36,7 @@ class AbstractPriceFeedContract extends BaseContract {
|
|
|
36
36
|
this.#decimals = args.decimals;
|
|
37
37
|
this.#updatable = args.updatable;
|
|
38
38
|
this.#skipCheck = args.skipCheck;
|
|
39
|
+
this.#answer = args.answer;
|
|
39
40
|
if (args.underlyingFeeds && args.underlyingStalenessPeriods) {
|
|
40
41
|
const underlyingStalenessPeriods = args.underlyingStalenessPeriods;
|
|
41
42
|
this.#underlyingPriceFeeds = args.underlyingFeeds.map(
|
|
@@ -70,6 +71,12 @@ class AbstractPriceFeedContract extends BaseContract {
|
|
|
70
71
|
}
|
|
71
72
|
return this.#underlyingPriceFeeds;
|
|
72
73
|
}
|
|
74
|
+
get answer() {
|
|
75
|
+
if (this.#answer === void 0) {
|
|
76
|
+
throw new PartialPriceFeedInitError(this.#args);
|
|
77
|
+
}
|
|
78
|
+
return this.#answer;
|
|
79
|
+
}
|
|
73
80
|
get priceFeedType() {
|
|
74
81
|
return this.contractType;
|
|
75
82
|
}
|
|
@@ -82,22 +89,6 @@ class AbstractPriceFeedContract extends BaseContract {
|
|
|
82
89
|
pricefeeds: this.underlyingPriceFeeds.map((f) => f.stateHuman(raw))
|
|
83
90
|
};
|
|
84
91
|
}
|
|
85
|
-
async currentLowerBound() {
|
|
86
|
-
return await this.sdk.provider.publicClient.readContract({
|
|
87
|
-
abi: ilpPriceFeedAbi,
|
|
88
|
-
address: this.address,
|
|
89
|
-
functionName: "lowerBound"
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
async answer(overrides) {
|
|
93
|
-
const lastRoundData = await this.sdk.provider.publicClient.readContract({
|
|
94
|
-
abi: ilpPriceFeedAbi,
|
|
95
|
-
address: this.address,
|
|
96
|
-
functionName: "latestRoundData",
|
|
97
|
-
...overrides
|
|
98
|
-
});
|
|
99
|
-
return lastRoundData[1];
|
|
100
|
-
}
|
|
101
92
|
updatableDependencies() {
|
|
102
93
|
const underlying = this.underlyingPriceFeeds.flatMap(
|
|
103
94
|
(f) => f.priceFeed.updatableDependencies()
|
|
@@ -52,6 +52,12 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
52
52
|
}
|
|
53
53
|
addHook = this.#hooks.addHook.bind(this.#hooks);
|
|
54
54
|
removeHook = this.#hooks.removeHook.bind(this.#hooks);
|
|
55
|
+
/**
|
|
56
|
+
* Returns all price feeds known to sdk
|
|
57
|
+
*/
|
|
58
|
+
get feeds() {
|
|
59
|
+
return this.#feeds.values();
|
|
60
|
+
}
|
|
55
61
|
/**
|
|
56
62
|
* Returns RawTxs to update price feeds
|
|
57
63
|
* @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
|
|
@@ -2,7 +2,8 @@ import type { Abi, Address, UnionOmit } from "viem";
|
|
|
2
2
|
import type { GearboxSDK } from "../../GearboxSDK.js";
|
|
3
3
|
import type { LPPriceFeedStateHuman } from "../../types/state-human.js";
|
|
4
4
|
import { AbstractPriceFeedContract, type PriceFeedConstructorArgs } from "./AbstractPriceFeed.js";
|
|
5
|
-
|
|
5
|
+
import type { ILPPriceFeedContract } from "./types.js";
|
|
6
|
+
export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi | readonly unknown[]> extends AbstractPriceFeedContract<abi> implements ILPPriceFeedContract {
|
|
6
7
|
readonly lpContract: Address;
|
|
7
8
|
readonly lpToken: Address;
|
|
8
9
|
readonly lowerBound: bigint;
|
|
@@ -13,6 +14,7 @@ export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi
|
|
|
13
14
|
constructor(sdk: GearboxSDK, args: PriceFeedConstructorArgs<abi>);
|
|
14
15
|
abstract getValue(): Promise<bigint>;
|
|
15
16
|
getLowerBound(): Promise<bigint>;
|
|
17
|
+
currentLowerBound(): Promise<bigint>;
|
|
16
18
|
static toLowerBound(value: bigint): bigint;
|
|
17
19
|
stateHuman(raw?: boolean): UnionOmit<LPPriceFeedStateHuman, "stalenessPeriod">;
|
|
18
20
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Abi, RequiredBy, UnionOmit } from "viem";
|
|
2
|
-
import type { PriceFeedTreeNode } from "../../base/index.js";
|
|
2
|
+
import type { PriceFeedAnswer, PriceFeedTreeNode } from "../../base/index.js";
|
|
3
3
|
import { BaseContract } from "../../base/index.js";
|
|
4
4
|
import type { GearboxSDK } from "../../GearboxSDK.js";
|
|
5
5
|
import type { PriceFeedStateHuman } from "../../types/index.js";
|
|
@@ -24,11 +24,8 @@ export declare abstract class AbstractPriceFeedContract<const abi extends Abi |
|
|
|
24
24
|
get updatable(): boolean;
|
|
25
25
|
get skipCheck(): boolean;
|
|
26
26
|
get underlyingPriceFeeds(): readonly PriceFeedRef[];
|
|
27
|
+
get answer(): PriceFeedAnswer;
|
|
27
28
|
get priceFeedType(): PriceFeedContractType;
|
|
28
29
|
stateHuman(raw?: boolean): UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
|
|
29
|
-
currentLowerBound(): Promise<bigint>;
|
|
30
|
-
answer(overrides?: {
|
|
31
|
-
blockNumber?: bigint;
|
|
32
|
-
}): Promise<bigint>;
|
|
33
30
|
updatableDependencies(): IUpdatablePriceFeedContract[];
|
|
34
31
|
}
|
|
@@ -3,6 +3,9 @@ import { SDKConstruct } from "../../base/index.js";
|
|
|
3
3
|
import type { GearboxSDK } from "../../GearboxSDK.js";
|
|
4
4
|
import type { PriceFeedStateHuman } from "../../types/index.js";
|
|
5
5
|
import type { IPriceFeedContract } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* PriceFeedRef is a connector between price feed and oracle, e.g. oracle's entry for price feed + staleness period
|
|
8
|
+
*/
|
|
6
9
|
export declare class PriceFeedRef extends SDKConstruct {
|
|
7
10
|
#private;
|
|
8
11
|
readonly address: Address;
|
|
@@ -33,6 +33,10 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
|
|
|
33
33
|
constructor(sdk: GearboxSDK, opts?: PriceFeedRegisterOptions);
|
|
34
34
|
addHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
|
|
35
35
|
removeHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Returns all price feeds known to sdk
|
|
38
|
+
*/
|
|
39
|
+
get feeds(): readonly IPriceFeedContract[];
|
|
36
40
|
/**
|
|
37
41
|
* Returns RawTxs to update price feeds
|
|
38
42
|
* @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address, Hex, UnionOmit } from "viem";
|
|
2
|
-
import type { IBaseContract } from "../../base/index.js";
|
|
2
|
+
import type { IBaseContract, PriceFeedAnswer } from "../../base/index.js";
|
|
3
3
|
import type { IPriceUpdateTx, PriceFeedStateHuman, RawTx } from "../../types/index.js";
|
|
4
4
|
import type { PriceFeedRef } from "./PriceFeedRef.js";
|
|
5
5
|
export type PriceFeedUsageType = "Main" | "Reserve";
|
|
@@ -18,10 +18,11 @@ export interface IPriceFeedContract extends IBaseContract {
|
|
|
18
18
|
* This flag idicates that all the price feed data (decimals, skip check, dependencies...) has been loaded from compressor
|
|
19
19
|
*/
|
|
20
20
|
readonly loaded: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Latest answer for this price feed
|
|
23
|
+
*/
|
|
24
|
+
readonly answer: PriceFeedAnswer;
|
|
21
25
|
readonly underlyingPriceFeeds: readonly PriceFeedRef[];
|
|
22
|
-
answer: (overrides?: {
|
|
23
|
-
blockNumber?: bigint;
|
|
24
|
-
}) => Promise<bigint>;
|
|
25
26
|
stateHuman: (raw?: boolean) => UnionOmit<PriceFeedStateHuman, "stalenessPeriod">;
|
|
26
27
|
/**
|
|
27
28
|
* Returns all updatable depenedencies (uderlying price feeds) of this price feed, including price feed itself, if it's updatable
|