@gearbox-protocol/sdk 13.3.3 → 13.3.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.
- package/dist/cjs/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +78 -157
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/cjs/sdk/base/BaseContract.js +26 -6
- package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/cjs/sdk/base/Construct.js +15 -3
- package/dist/cjs/sdk/base/TokensMeta.js +23 -0
- package/dist/cjs/sdk/constants/address-provider.js +0 -22
- package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/cjs/sdk/market/MarketRegister.js +74 -3
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/cjs/sdk/options.js +30 -24
- package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
- package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
- package/dist/cjs/sdk/utils/AddressMap.js +53 -17
- package/dist/cjs/sdk/utils/AddressSet.js +9 -0
- package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +78 -157
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/esm/sdk/base/BaseContract.js +26 -6
- package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/esm/sdk/base/Construct.js +15 -3
- package/dist/esm/sdk/base/TokensMeta.js +23 -0
- package/dist/esm/sdk/constants/address-provider.js +0 -21
- package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/esm/sdk/market/MarketRegister.js +74 -3
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/esm/sdk/options.js +30 -24
- package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
- package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
- package/dist/esm/sdk/utils/AddressMap.js +53 -17
- package/dist/esm/sdk/utils/AddressSet.js +9 -0
- package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +56 -142
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/types.d.ts +230 -18
- package/dist/types/sdk/base/BaseContract.d.ts +67 -6
- package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
- package/dist/types/sdk/base/Construct.d.ts +31 -0
- package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
- package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
- package/dist/types/sdk/base/types.d.ts +185 -25
- package/dist/types/sdk/chain/chains.d.ts +78 -18
- package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
- package/dist/types/sdk/constants/address-provider.d.ts +4 -3
- package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
- package/dist/types/sdk/core/types.d.ts +46 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
- package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
- package/dist/types/sdk/market/oracle/types.d.ts +76 -57
- package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
- package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
- package/dist/types/sdk/options.d.ts +13 -4
- package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
- package/dist/types/sdk/plugins/types.d.ts +73 -43
- package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
- package/dist/types/sdk/pools/types.d.ts +75 -6
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
- package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
- package/dist/types/sdk/router/types.d.ts +51 -69
- package/dist/types/sdk/types/state.d.ts +32 -3
- package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
- package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
- package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
- package/package.json +4 -2
|
@@ -9,30 +9,111 @@ import { MarketConfiguratorContract } from "./MarketConfiguratorContract.js";
|
|
|
9
9
|
import { MarketSuite } from "./MarketSuite.js";
|
|
10
10
|
import type { IPriceOracleContract } from "./oracle/index.js";
|
|
11
11
|
import type { PoolSuite } from "./pool/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Central registry of all Gearbox markets on the current chain.
|
|
14
|
+
*
|
|
15
|
+
* A market groups a lending pool, a price oracle, and one or more credit
|
|
16
|
+
* managers into a single unit. The `MarketRegister` loads this data from the
|
|
17
|
+
* on-chain market compressor and exposes convenience lookup methods
|
|
18
|
+
**/
|
|
12
19
|
export declare class MarketRegister extends SDKConstruct {
|
|
13
20
|
#private;
|
|
21
|
+
/**
|
|
22
|
+
* @param sdk - Top-level SDK instance.
|
|
23
|
+
* @param ignoreMarkets - Pool addresses of markets to exclude from loading.
|
|
24
|
+
**/
|
|
14
25
|
constructor(sdk: GearboxSDK, ignoreMarkets?: Address[]);
|
|
26
|
+
/**
|
|
27
|
+
* Restores market state from a previously serialized snapshot,
|
|
28
|
+
* bypassing on-chain reads.
|
|
29
|
+
* @param state - Array of market data snapshots.
|
|
30
|
+
**/
|
|
15
31
|
hydrate(state: MarketData[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Fetches all markets from the on-chain for the given market configurators.
|
|
34
|
+
*
|
|
35
|
+
* @param marketConfigurators - Addresses of market configurator contracts to query.
|
|
36
|
+
* @param ignoreUpdateablePrices - When `true`, skips generating off-chain
|
|
37
|
+
* price updates before loading
|
|
38
|
+
**/
|
|
16
39
|
loadMarkets(marketConfigurators: Address[], ignoreUpdateablePrices?: boolean): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* The active filter used to scope market compressor queries.
|
|
42
|
+
* @throws If the register has not been hydrated or attached yet.
|
|
43
|
+
**/
|
|
17
44
|
get marketFilter(): MarketFilter;
|
|
45
|
+
/**
|
|
46
|
+
* Re-synchronizes market state with the chain. If during sdk synchronization
|
|
47
|
+
* we detected that some markets or market configurators were changed,
|
|
48
|
+
* we reload everything.
|
|
49
|
+
*
|
|
50
|
+
* Otherwise only prices are refreshed.
|
|
51
|
+
*
|
|
52
|
+
* @param ignoreUpdateablePrices - When `true`, skips off-chain price updates.
|
|
53
|
+
**/
|
|
18
54
|
syncState(ignoreUpdateablePrices?: boolean): Promise<void>;
|
|
19
55
|
/**
|
|
20
56
|
* Loads new prices and price feeds for given oracles from PriceFeedCompressor, defaults to all oracles
|
|
21
57
|
*/
|
|
22
58
|
updatePrices(oracles?: Address[]): Promise<void>;
|
|
23
59
|
get watchAddresses(): Set<Address>;
|
|
60
|
+
/**
|
|
61
|
+
* Serializable snapshot of all loaded markets, suitable for hydration.
|
|
62
|
+
**/
|
|
24
63
|
get state(): MarketData[];
|
|
64
|
+
/**
|
|
65
|
+
* Returns a human-readable snapshot of all markets.
|
|
66
|
+
* @param raw - When `true`, includes raw/unformatted values.
|
|
67
|
+
**/
|
|
25
68
|
stateHuman(raw?: boolean): {
|
|
26
69
|
markets: MarketStateHuman[];
|
|
27
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* All pool suites across loaded markets.
|
|
73
|
+
**/
|
|
28
74
|
get pools(): PoolSuite[];
|
|
75
|
+
/**
|
|
76
|
+
* All price oracles across loaded markets.
|
|
77
|
+
**/
|
|
29
78
|
get priceOracles(): IPriceOracleContract[];
|
|
79
|
+
/**
|
|
80
|
+
* All credit manager suites across loaded markets.
|
|
81
|
+
**/
|
|
30
82
|
get creditManagers(): CreditSuite[];
|
|
83
|
+
/**
|
|
84
|
+
* All known market configurator contracts.
|
|
85
|
+
**/
|
|
31
86
|
get marketConfigurators(): MarketConfiguratorContract[];
|
|
87
|
+
/**
|
|
88
|
+
* Finds a credit manager suite by its on-chain address.
|
|
89
|
+
* @param creditManager - Credit manager contract address.
|
|
90
|
+
* @throws If no loaded market contains the given credit manager.
|
|
91
|
+
**/
|
|
32
92
|
findCreditManager(creditManager: Address): CreditSuite;
|
|
93
|
+
/**
|
|
94
|
+
* Finds the market that contains the given credit manager.
|
|
95
|
+
* @param creditManager - Credit manager contract address.
|
|
96
|
+
* @throws If no loaded market contains the given credit manager.
|
|
97
|
+
**/
|
|
33
98
|
findByCreditManager(creditManager: Address): MarketSuite;
|
|
99
|
+
/**
|
|
100
|
+
* Finds the market that uses the given price oracle.
|
|
101
|
+
* @param address - Price oracle contract address.
|
|
102
|
+
* @throws If no loaded market uses the given oracle.
|
|
103
|
+
**/
|
|
34
104
|
findByPriceOracle(address: Address): MarketSuite;
|
|
105
|
+
/**
|
|
106
|
+
* Finds the market associated with the given pool.
|
|
107
|
+
* @param address - Pool contract address.
|
|
108
|
+
* @throws If no loaded market uses the given pool.
|
|
109
|
+
**/
|
|
35
110
|
findByPool(address: Address): MarketSuite;
|
|
111
|
+
/**
|
|
112
|
+
* Underlying address map of pool address to market suite
|
|
113
|
+
**/
|
|
36
114
|
get marketsMap(): AddressMap<MarketSuite>;
|
|
115
|
+
/**
|
|
116
|
+
* All loaded market suites.
|
|
117
|
+
**/
|
|
37
118
|
get markets(): MarketSuite[];
|
|
38
119
|
}
|
|
@@ -6,6 +6,9 @@ import type { IAdapterContract } from "./types.js";
|
|
|
6
6
|
export interface PlaceholderAdapterContractOptions {
|
|
7
7
|
baseParams: RelaxedBaseParams;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
9
12
|
export declare class PlaceholderAdapterContract extends PlaceholderContract implements IAdapterContract {
|
|
10
13
|
#private;
|
|
11
14
|
constructor(options: ConstructOptions, args: PlaceholderAdapterContractOptions);
|
|
@@ -9,88 +9,78 @@ import type { IPriceFeedContract, UpdatePriceFeedsResult } from "../pricefeeds/i
|
|
|
9
9
|
import { PriceFeedRef } from "../pricefeeds/index.js";
|
|
10
10
|
import PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
|
|
11
11
|
import type { DelegatedOracleMulticall, IPriceOracleContract, OnDemandPriceUpdates, PriceFeedsForTokensOptions } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Base implementation of the Gearbox price oracle.
|
|
14
|
+
*
|
|
15
|
+
* Manages dual main/reserve price feed mappings and price answers for
|
|
16
|
+
* every collateral token in a market. Provides token-to-USD and
|
|
17
|
+
* token-to-token conversion using the latest known prices.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam abi - The concrete oracle contract's ABI type.
|
|
20
|
+
**/
|
|
12
21
|
export declare abstract class PriceOracleBaseContract<abi extends Abi | readonly unknown[]> extends BaseContract<abi> implements IPriceOracleContract {
|
|
13
22
|
#private;
|
|
14
23
|
readonly sdk: GearboxSDK;
|
|
15
24
|
/**
|
|
16
|
-
*
|
|
17
|
-
|
|
25
|
+
* {@inheritDoc IPriceOracleContract.mainPriceFeeds}
|
|
26
|
+
**/
|
|
18
27
|
readonly mainPriceFeeds: AddressMap<PriceFeedRef>;
|
|
19
28
|
/**
|
|
20
|
-
*
|
|
21
|
-
|
|
29
|
+
* {@inheritDoc IPriceOracleContract.reservePriceFeeds}
|
|
30
|
+
**/
|
|
22
31
|
readonly reservePriceFeeds: AddressMap<PriceFeedRef>;
|
|
23
32
|
/**
|
|
24
|
-
*
|
|
25
|
-
|
|
33
|
+
* {@inheritDoc IPriceOracleContract.mainPrices}
|
|
34
|
+
**/
|
|
26
35
|
readonly mainPrices: PriceFeedAnswerMap;
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
29
|
-
|
|
37
|
+
* {@inheritDoc IPriceOracleContract.reservePrices}
|
|
38
|
+
**/
|
|
30
39
|
readonly reservePrices: PriceFeedAnswerMap;
|
|
31
40
|
constructor(sdk: GearboxSDK, args: BaseContractArgs<abi>, data: PriceOracleData);
|
|
32
41
|
/**
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
* @param opts Option to include main/reserve feeds only, defaults to both
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
42
|
+
* {@inheritDoc IPriceOracleContract.priceFeedsForTokens}
|
|
43
|
+
**/
|
|
38
44
|
priceFeedsForTokens(tokens: Address[], opts?: PriceFeedsForTokensOptions): IPriceFeedContract[];
|
|
39
45
|
abstract onDemandPriceUpdates(creditFacade: Address, updates?: UpdatePriceFeedsResult): OnDemandPriceUpdates;
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
* @param token
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
47
|
+
* {@inheritDoc IPriceOracleContract.mainPrice}
|
|
48
|
+
**/
|
|
46
49
|
mainPrice(token: Address): bigint;
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
* @param token
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
51
|
+
* {@inheritDoc IPriceOracleContract.reservePrice}
|
|
52
|
+
**/
|
|
53
53
|
reservePrice(token: Address): bigint;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
* @param priceFeed
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
55
|
+
* {@inheritDoc IPriceOracleContract.usesPriceFeed}
|
|
56
|
+
**/
|
|
60
57
|
usesPriceFeed(priceFeed: Address): boolean;
|
|
61
58
|
/**
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
* @param to
|
|
65
|
-
* @param amount
|
|
66
|
-
* @param reserve use reserve price feed instead of main
|
|
67
|
-
*/
|
|
59
|
+
* {@inheritDoc IPriceOracleContract.convert}
|
|
60
|
+
**/
|
|
68
61
|
convert(from: Address, to: Address, amount: bigint, reserve?: boolean): bigint;
|
|
69
62
|
/**
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
* @param amount
|
|
73
|
-
* @param reserve use reserve price feed instead of main
|
|
74
|
-
*/
|
|
63
|
+
* {@inheritDoc IPriceOracleContract.convertToUSD}
|
|
64
|
+
**/
|
|
75
65
|
convertToUSD(from: Address, amount: bigint, reserve?: boolean): bigint;
|
|
76
66
|
/**
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
* @param amount
|
|
80
|
-
* @param reserve use reserve price feed instead of main
|
|
81
|
-
*/
|
|
67
|
+
* {@inheritDoc IPriceOracleContract.convertFromUSD}
|
|
68
|
+
**/
|
|
82
69
|
convertFromUSD(to: Address, amount: bigint, reserve?: boolean): bigint;
|
|
83
70
|
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
71
|
+
* {@inheritDoc IPriceOracleContract.priceFeeds}
|
|
72
|
+
**/
|
|
86
73
|
get priceFeeds(): IPriceFeedContract[];
|
|
87
74
|
/**
|
|
88
|
-
*
|
|
89
|
-
|
|
75
|
+
* {@inheritDoc IPriceOracleContract.syncStateMulticall}
|
|
76
|
+
**/
|
|
90
77
|
syncStateMulticall(): DelegatedOracleMulticall;
|
|
91
78
|
/**
|
|
92
|
-
*
|
|
93
|
-
|
|
79
|
+
* {@inheritDoc IPriceOracleContract.watchAddresses}
|
|
80
|
+
**/
|
|
94
81
|
get watchAddresses(): Set<Address>;
|
|
82
|
+
/**
|
|
83
|
+
* {@inheritDoc IPriceOracleContract.stateHuman}
|
|
84
|
+
**/
|
|
95
85
|
stateHuman(raw?: boolean): PriceOracleStateHuman;
|
|
96
86
|
}
|
|
@@ -5,8 +5,20 @@ import type { MultiCall, PriceOracleStateHuman } from "../../types/index.js";
|
|
|
5
5
|
import type { AddressMap } from "../../utils/index.js";
|
|
6
6
|
import type { IPriceFeedContract, PriceFeedRef, PriceUpdateV310, UpdatePriceFeedsResult } from "../pricefeeds/index.js";
|
|
7
7
|
import type PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
|
|
8
|
+
/**
|
|
9
|
+
* Filter controlling which feed types to include when querying
|
|
10
|
+
* price feeds for a set of tokens. Both default to `true`.
|
|
11
|
+
**/
|
|
8
12
|
export interface PriceFeedsForTokensOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Include main (primary) price feeds.
|
|
15
|
+
* @default true
|
|
16
|
+
**/
|
|
9
17
|
main?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Include reserve (fallback) price feeds.
|
|
20
|
+
* @default true
|
|
21
|
+
**/
|
|
10
22
|
reserve?: boolean;
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
@@ -17,97 +29,104 @@ export interface OnDemandPriceUpdates {
|
|
|
17
29
|
raw: PriceUpdateV310[];
|
|
18
30
|
multicall: MultiCall[];
|
|
19
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Public interface for a Gearbox price oracle contract.
|
|
34
|
+
*
|
|
35
|
+
* Each Gearbox market has one price oracle that aggregates USD-denominated
|
|
36
|
+
* price feeds for every collateral token.
|
|
37
|
+
**/
|
|
20
38
|
export interface IPriceOracleContract extends IBaseContract {
|
|
21
39
|
/**
|
|
22
|
-
* All price feed
|
|
23
|
-
|
|
40
|
+
* All price feed contract instances known to this oracle
|
|
41
|
+
**/
|
|
24
42
|
priceFeeds: IPriceFeedContract[];
|
|
25
43
|
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
44
|
+
* Main price feed references, keyed by token address.
|
|
45
|
+
**/
|
|
28
46
|
mainPriceFeeds: AddressMap<PriceFeedRef>;
|
|
29
47
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
48
|
+
* Latest main prices in USD (8 decimals), keyed by token address.
|
|
49
|
+
**/
|
|
32
50
|
mainPrices: PriceFeedAnswerMap;
|
|
33
51
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
|
|
38
|
-
*/
|
|
52
|
+
* Returns the main USD price for a token.
|
|
53
|
+
* @param token - Token address.
|
|
54
|
+
* @throws If the token has no main feed or the answer failed.
|
|
55
|
+
**/
|
|
39
56
|
mainPrice: (token: Address) => bigint;
|
|
40
57
|
/**
|
|
41
|
-
*
|
|
42
|
-
|
|
58
|
+
* Reserve price feed references, keyed by token address.
|
|
59
|
+
**/
|
|
43
60
|
reservePriceFeeds: AddressMap<PriceFeedRef>;
|
|
44
61
|
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
62
|
+
* Latest reserve prices in USD (8 decimals), keyed by token address.
|
|
63
|
+
**/
|
|
47
64
|
reservePrices: PriceFeedAnswerMap;
|
|
48
65
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
|
|
53
|
-
*/
|
|
66
|
+
* Returns the reserve USD price for a token.
|
|
67
|
+
* @param token - Token address.
|
|
68
|
+
* @throws If the token has no reserve feed or the answer failed.
|
|
69
|
+
**/
|
|
54
70
|
reservePrice: (token: Address) => bigint;
|
|
55
71
|
/**
|
|
56
|
-
*
|
|
57
|
-
|
|
72
|
+
* @internal
|
|
73
|
+
**/
|
|
58
74
|
syncStateMulticall: () => DelegatedOracleMulticall;
|
|
59
75
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
|
|
76
|
+
* Checks whether the given price feed address appears anywhere in this
|
|
77
|
+
* oracle's feed tree (including as a dependency of a composite feed,
|
|
78
|
+
* not just directly assigned to a token).
|
|
79
|
+
* @param priceFeed - Price feed address to look up.
|
|
80
|
+
**/
|
|
65
81
|
usesPriceFeed: (priceFeed: Address) => boolean;
|
|
66
82
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @param tokens
|
|
69
|
-
* @param opts
|
|
70
|
-
|
|
71
|
-
*/
|
|
83
|
+
* Collects the main and/or reserve price feeds assigned to the given tokens.
|
|
84
|
+
* @param tokens - Token addresses to query.
|
|
85
|
+
* @param opts - Filter to include only main or only reserve feeds.
|
|
86
|
+
**/
|
|
72
87
|
priceFeedsForTokens: (tokens: Address[], opts?: PriceFeedsForTokensOptions) => IPriceFeedContract[];
|
|
73
88
|
/**
|
|
74
|
-
* Converts previously obtained price updates into CreditFacade
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @
|
|
78
|
-
|
|
89
|
+
* Converts previously obtained price updates into CreditFacade
|
|
90
|
+
* multicall entries and raw `PriceUpdateV310` structures.
|
|
91
|
+
* @param creditFacade - Address of the credit facade that will receive the multicall.
|
|
92
|
+
* @param updates - Price update result to convert. When omitted, uses latest cached updates.
|
|
93
|
+
**/
|
|
79
94
|
onDemandPriceUpdates: (creditFacade: Address, updates?: UpdatePriceFeedsResult) => OnDemandPriceUpdates;
|
|
80
95
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @param from
|
|
83
|
-
* @param to
|
|
84
|
-
* @param amount
|
|
85
|
-
* @param reserve
|
|
86
|
-
|
|
96
|
+
* Converts an amount from one token to another using latest known prices.
|
|
97
|
+
* @param from - Source token address.
|
|
98
|
+
* @param to - Destination token address.
|
|
99
|
+
* @param amount - Amount in source-token decimals.
|
|
100
|
+
* @param reserve - Use reserve feeds instead of main.
|
|
101
|
+
**/
|
|
87
102
|
convert: (from: Address, to: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
88
103
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param from
|
|
91
|
-
* @param amount
|
|
92
|
-
* @param reserve
|
|
93
|
-
|
|
104
|
+
* Converts a token amount to its USD value using latest known prices.
|
|
105
|
+
* @param from - Token address.
|
|
106
|
+
* @param amount - Amount in token decimals.
|
|
107
|
+
* @param reserve - Use reserve feeds instead of main.
|
|
108
|
+
**/
|
|
94
109
|
convertToUSD: (from: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
95
110
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @param to
|
|
98
|
-
* @param amount
|
|
99
|
-
* @param reserve
|
|
100
|
-
|
|
111
|
+
* Converts a USD amount to a token amount using latest known prices.
|
|
112
|
+
* @param to - Token address.
|
|
113
|
+
* @param amount - Amount in USD (8 decimals).
|
|
114
|
+
* @param reserve - Use reserve feeds instead of main.
|
|
115
|
+
**/
|
|
101
116
|
convertFromUSD: (to: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
102
117
|
/**
|
|
103
|
-
*
|
|
104
|
-
|
|
118
|
+
* @internal
|
|
119
|
+
**/
|
|
105
120
|
watchAddresses: Set<Address>;
|
|
106
121
|
/**
|
|
107
|
-
* Returns human
|
|
108
|
-
|
|
122
|
+
* Returns a human-readable snapshot of the oracle state.
|
|
123
|
+
* @param raw - When `true`, includes raw/unformatted values.
|
|
124
|
+
**/
|
|
109
125
|
stateHuman: (raw?: boolean) => PriceOracleStateHuman;
|
|
110
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
**/
|
|
111
130
|
export interface DelegatedOracleMulticall {
|
|
112
131
|
call: ContractFunctionParameters<typeof priceFeedCompressorAbi, "view", "getPriceOracleState">;
|
|
113
132
|
onResult: (resp: ContractFunctionReturnType<typeof priceFeedCompressorAbi, "view", "getPriceOracleState">) => void;
|
|
@@ -2,6 +2,9 @@ import type { Abi, Address, UnionOmit } from "viem";
|
|
|
2
2
|
import type { ConstructOptions } from "../../base/Construct.js";
|
|
3
3
|
import type { LPPriceFeedStateHuman } from "../../types/state-human.js";
|
|
4
4
|
import { AbstractPriceFeedContract, type PriceFeedConstructorArgs } from "./AbstractPriceFeed.js";
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
export declare abstract class AbstractLPPriceFeedContract<const abi extends Abi | readonly unknown[]> extends AbstractPriceFeedContract<abi> {
|
|
6
9
|
readonly lpContract: Address;
|
|
7
10
|
readonly lpToken: Address;
|
|
@@ -13,6 +13,9 @@ export declare class PartialPriceFeedInitError extends Error {
|
|
|
13
13
|
readonly priceFeed: PriceFeedConstructorArgs<any>;
|
|
14
14
|
constructor(priceFeed: PriceFeedConstructorArgs<any>);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
16
19
|
export declare abstract class AbstractPriceFeedContract<const abi extends Abi | readonly unknown[]> extends BaseContract<abi> implements IPriceFeedContract {
|
|
17
20
|
#private;
|
|
18
21
|
hasLowerBoundCap: boolean;
|
|
@@ -3,13 +3,33 @@ import { Construct, type ConstructOptions } from "../../base/index.js";
|
|
|
3
3
|
import type { PriceFeedStateHuman } from "../../types/index.js";
|
|
4
4
|
import type { IPriceFeedContract } from "./types.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
|
|
6
|
+
* Connector between a price oracle and a price feed contract.
|
|
7
|
+
*
|
|
8
|
+
* Each token tracked by a {@link IPriceOracleContract} has an associated
|
|
9
|
+
* `PriceFeedRef` that pairs the feed's on-chain address with the
|
|
10
|
+
* staleness period the oracle uses when evaluating the feed's answer.
|
|
11
|
+
**/
|
|
8
12
|
export declare class PriceFeedRef extends Construct {
|
|
9
13
|
#private;
|
|
14
|
+
/**
|
|
15
|
+
* On-chain address of the referenced price feed contract.
|
|
16
|
+
**/
|
|
10
17
|
readonly address: Address;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum allowed age (in seconds) of the feed's answer before the
|
|
20
|
+
* oracle considers it stale.
|
|
21
|
+
**/
|
|
11
22
|
readonly stalenessPeriod: number;
|
|
12
23
|
constructor(options: ConstructOptions, address: Address, stalenessPeriod: number);
|
|
24
|
+
/**
|
|
25
|
+
* Lazily resolved price feed contract instance.
|
|
26
|
+
* @throws If the feed is not registered in the contracts register.
|
|
27
|
+
**/
|
|
13
28
|
get priceFeed(): IPriceFeedContract;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a human-readable snapshot of the feed state, including the
|
|
31
|
+
* staleness period formatted as a duration string.
|
|
32
|
+
* @param raw - When `true`, includes raw/unformatted values.
|
|
33
|
+
**/
|
|
14
34
|
stateHuman(raw?: boolean): PriceFeedStateHuman;
|
|
15
35
|
}
|
|
@@ -6,43 +6,77 @@ import type { RawTx } from "../../types/index.js";
|
|
|
6
6
|
import type { IHooks } from "../../utils/internal/index.js";
|
|
7
7
|
import { type PartialPriceFeedTreeNode } from "./AbstractPriceFeed.js";
|
|
8
8
|
import type { IPriceFeedContract, PriceUpdateV310, UpdatePriceFeedsResult } from "./types.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { IPriceUpdateTask, PythOptions, RedstoneOptions } from "./updates/index.js";
|
|
10
10
|
export type PriceFeedRegisterHooks = {
|
|
11
11
|
/**
|
|
12
12
|
* Emitted when transactions to update price feeds have been generated, but before they're used anywhere
|
|
13
13
|
*/
|
|
14
14
|
updatesGenerated: [UpdatePriceFeedsResult];
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for external price-update providers supported by the register.
|
|
18
|
+
**/
|
|
16
19
|
export interface PriceFeedRegisterOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Redstone price-update provider options.
|
|
22
|
+
**/
|
|
17
23
|
redstone?: RedstoneOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Pyth price-update provider options.
|
|
26
|
+
**/
|
|
18
27
|
pyth?: PythOptions;
|
|
19
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
* Diagnostic snapshot of the most recent price-update round.
|
|
32
|
+
**/
|
|
20
33
|
export interface LatestUpdate {
|
|
34
|
+
/**
|
|
35
|
+
* Unix timestamp (seconds) of the most recent update.
|
|
36
|
+
**/
|
|
21
37
|
timestamp: number;
|
|
38
|
+
/**
|
|
39
|
+
* Individual update tasks that were executed.
|
|
40
|
+
**/
|
|
22
41
|
updates: IPriceUpdateTask[];
|
|
23
42
|
}
|
|
24
43
|
/**
|
|
25
|
-
*
|
|
26
|
-
* It's reused by PriceOracles belonging to different markets
|
|
44
|
+
* Chain-level cache of price feed contract instances.
|
|
27
45
|
*
|
|
46
|
+
* All {@link IPriceOracleContract}s across different markets share a single
|
|
47
|
+
* `PriceFeedRegister`, avoiding duplicate contract wrappers for the same
|
|
48
|
+
* on-chain feed. The register also orchestrates off-chain price updates
|
|
49
|
+
* (Pyth, Redstone, etc.).
|
|
28
50
|
**/
|
|
29
51
|
export declare class PriceFeedRegister extends SDKConstruct implements IHooks<PriceFeedRegisterHooks> {
|
|
30
52
|
#private;
|
|
31
|
-
readonly updaters: IPriceUpdater[];
|
|
32
53
|
constructor(sdk: GearboxSDK, opts?: PriceFeedRegisterOptions);
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* Registers a callback for price-feed register lifecycle events.
|
|
57
|
+
* @param event - Event name.
|
|
58
|
+
* @param handler - Callback to invoke.
|
|
59
|
+
**/
|
|
33
60
|
addHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
* Removes a previously registered hook.
|
|
64
|
+
* @param event - Event name.
|
|
65
|
+
* @param handler - Callback to remove.
|
|
66
|
+
**/
|
|
34
67
|
removeHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: PriceFeedRegisterHooks[K]) => void | Promise<void>) => void;
|
|
35
68
|
/**
|
|
36
69
|
* Returns all price feeds known to sdk
|
|
37
70
|
*/
|
|
38
71
|
get feeds(): readonly IPriceFeedContract[];
|
|
39
72
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
73
|
+
* Generates transactions to push fresh off-chain prices to updatable feeds.
|
|
74
|
+
*
|
|
75
|
+
* @param priceFeeds - Top-level price feeds whose updatable dependencies
|
|
76
|
+
* will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
|
|
77
|
+
* to gather feeds from all oracles. When omitted, all registered feeds
|
|
78
|
+
* are used.
|
|
79
|
+
**/
|
|
46
80
|
generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[] | {
|
|
47
81
|
main: true;
|
|
48
82
|
} | {
|
|
@@ -69,7 +103,7 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
|
|
|
69
103
|
reserve: true;
|
|
70
104
|
}): Promise<RawTx>;
|
|
71
105
|
/**
|
|
72
|
-
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
|
|
106
|
+
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
|
|
73
107
|
* This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
|
|
74
108
|
* @param feeds
|
|
75
109
|
* @param block
|
|
@@ -91,17 +125,47 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
|
|
|
91
125
|
} | {
|
|
92
126
|
blockTag: BlockTag;
|
|
93
127
|
}): Promise<PriceUpdateV310[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Checks whether a price feed is already registered at the given address.
|
|
130
|
+
* @param address - On-chain address to look up.
|
|
131
|
+
**/
|
|
94
132
|
has(address: Address): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the cached price feed contract at the given address.
|
|
135
|
+
* @param address - On-chain address to look up.
|
|
136
|
+
* @throws If no feed is registered at that address.
|
|
137
|
+
**/
|
|
95
138
|
mustGet(address: Address): IPriceFeedContract;
|
|
139
|
+
/**
|
|
140
|
+
* Inserts or updates a price feed from a full tree node.
|
|
141
|
+
*
|
|
142
|
+
* If a fully loaded feed already exists at the same address, only the
|
|
143
|
+
* answer is refreshed. Otherwise a new contract wrapper is created and
|
|
144
|
+
* cached.
|
|
145
|
+
*
|
|
146
|
+
* @param data - Full price feed tree node from the compressor.
|
|
147
|
+
* @returns The cached (or newly created) feed instance.
|
|
148
|
+
* @throws If the created feed is only partially initialized.
|
|
149
|
+
**/
|
|
96
150
|
upsert(data: PriceFeedTreeNode): IPriceFeedContract;
|
|
97
151
|
/**
|
|
98
152
|
* Loads PARTIAL information about all updatable price feeds from MarketCompressor
|
|
99
153
|
* Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
|
|
100
154
|
*/
|
|
101
155
|
getPartialUpdatablePriceFeeds(configurators: Address[], pools?: Address[]): Promise<IPriceFeedContract[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Instantiates the appropriate price feed contract wrapper based on
|
|
158
|
+
* the `contractType` discriminator in the node's base params.
|
|
159
|
+
*
|
|
160
|
+
* @param data - Partial or full price feed tree node.
|
|
161
|
+
* @returns A new (uncached) feed contract instance.
|
|
162
|
+
* @throws If the contract type is unsupported and strict mode is enabled.
|
|
163
|
+
**/
|
|
102
164
|
create(data: PartialPriceFeedTreeNode): IPriceFeedContract;
|
|
103
165
|
/**
|
|
104
|
-
*
|
|
105
|
-
|
|
166
|
+
* @internal
|
|
167
|
+
* Diagnostic snapshot of the most recent price-update round, or
|
|
168
|
+
* `undefined` if no updates have been generated yet.
|
|
169
|
+
**/
|
|
106
170
|
get latestUpdate(): LatestUpdate | undefined;
|
|
107
171
|
}
|