@gearbox-protocol/sdk 13.3.3 → 13.4.0-beta.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/permissionless/utils/price-update/get-price-update-tx.js +3 -15
- package/dist/cjs/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +196 -340
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +30 -35
- package/dist/cjs/sdk/accounts/multicall-utils.js +91 -0
- 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/credit/CreditFacadeV310Contract.js +6 -0
- 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/esm/permissionless/utils/price-update/get-price-update-tx.js +6 -20
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +204 -342
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +30 -35
- package/dist/esm/sdk/accounts/multicall-utils.js +69 -0
- 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/credit/CreditFacadeV310Contract.js +6 -0
- 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/types/permissionless/bindings/price-feed-store.d.ts +1 -2
- package/dist/types/permissionless/bindings/types.d.ts +0 -4
- package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +1 -3
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +92 -147
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/multicall-utils.d.ts +39 -0
- package/dist/types/sdk/accounts/types.d.ts +237 -40
- 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/credit/CreditFacadeV310Contract.d.ts +1 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
- package/dist/types/sdk/market/oracle/types.d.ts +78 -59
- 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 +80 -16
- package/dist/types/sdk/market/pricefeeds/getRawPriceUpdates.d.ts +2 -2
- package/dist/types/sdk/market/pricefeeds/types.d.ts +75 -11
- 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 +47 -70
- 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/package.json +4 -2
|
@@ -4,13 +4,36 @@ import { BaseContract, type ConstructOptions } from "../base/index.js";
|
|
|
4
4
|
import type { VersionRange } from "../constants/index.js";
|
|
5
5
|
import type { AddressProviderV3StateHuman } from "../types/index.js";
|
|
6
6
|
import type { AddressProviderAddresses, AddressProviderState } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Base implementation of the Gearbox address provider contract.
|
|
9
|
+
*
|
|
10
|
+
* Maintains an in-memory registry of `(contractName, version) → address`
|
|
11
|
+
* mappings for all global (chain-wide) Gearbox contracts.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam abi - The contract's ABI type.
|
|
14
|
+
**/
|
|
7
15
|
export default abstract class AbstractAddressProviderContract<abi extends Abi | readonly unknown[]> extends BaseContract<abi> {
|
|
8
16
|
#private;
|
|
9
17
|
constructor(options: ConstructOptions, args: BaseContractArgs<abi>, addresses?: AddressProviderAddresses);
|
|
10
18
|
protected setInternalAddress(key: string, address: Address, version: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* {@inheritDoc IAddressProviderContract.getAddress}
|
|
21
|
+
**/
|
|
11
22
|
getAddress(contract: string, version?: number): Address;
|
|
23
|
+
/**
|
|
24
|
+
* {@inheritDoc IAddressProviderContract.getLatest}
|
|
25
|
+
**/
|
|
12
26
|
getLatest(contract: string, range: VersionRange): [address: Address, version: number] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* {@inheritDoc IAddressProviderContract.mustGetLatest}
|
|
29
|
+
**/
|
|
13
30
|
mustGetLatest(contract: string, range: VersionRange): [address: Address, version: number];
|
|
31
|
+
/**
|
|
32
|
+
* {@inheritDoc IAddressProviderContract.state}
|
|
33
|
+
**/
|
|
14
34
|
get state(): AddressProviderState;
|
|
35
|
+
/**
|
|
36
|
+
* {@inheritDoc IAddressProviderContract.stateHuman}
|
|
37
|
+
**/
|
|
15
38
|
stateHuman(raw?: boolean): AddressProviderV3StateHuman;
|
|
16
39
|
}
|
|
@@ -17,15 +17,61 @@ export interface AddressProviderAddresses {
|
|
|
17
17
|
*/
|
|
18
18
|
overrides?: Record<string, Record<number, Address>>;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Serializable snapshot of the address provider's current state,
|
|
22
|
+
* including its on-chain identity and all registered contract addresses.
|
|
23
|
+
**/
|
|
20
24
|
export interface AddressProviderState {
|
|
25
|
+
/**
|
|
26
|
+
* On-chain identification parameters for the address provider itself.
|
|
27
|
+
**/
|
|
21
28
|
baseParams: BaseParams;
|
|
29
|
+
/**
|
|
30
|
+
* Registered addresses keyed by contract name, then by version number.
|
|
31
|
+
**/
|
|
22
32
|
addresses: Record<string, Record<number, Address>>;
|
|
23
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Public interface for the Gearbox address provider contract.
|
|
36
|
+
*
|
|
37
|
+
* The address provider is the single entry-point for discovering all other
|
|
38
|
+
* Gearbox contracts on a given chain. It maps `(contractName, version)` pairs
|
|
39
|
+
* to on-chain addresses.
|
|
40
|
+
**/
|
|
24
41
|
export interface IAddressProviderContract extends IBaseContract {
|
|
42
|
+
/**
|
|
43
|
+
* Serializable snapshot of the provider's current state.
|
|
44
|
+
**/
|
|
25
45
|
state: AddressProviderState;
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the address of a registered contract by name and version.
|
|
48
|
+
* @param contract - Registered contract name (e.g. `"MARKET_COMPRESSOR"`).
|
|
49
|
+
* @param version - Version number to look up. Defaults to 0 - contract without versioning
|
|
50
|
+
* @throws If no address is registered for the given name and version.
|
|
51
|
+
**/
|
|
26
52
|
getAddress: (contract: string, version?: number) => Address;
|
|
53
|
+
/**
|
|
54
|
+
* Finds the highest-versioned address within a version range.
|
|
55
|
+
* @param contract - Registered contract name.
|
|
56
|
+
* @param range - Inclusive `[min, max]` version range to search.
|
|
57
|
+
* @returns A `[address, version]` tuple, or `undefined` if none match.
|
|
58
|
+
**/
|
|
27
59
|
getLatest: (contract: string, range: VersionRange) => [address: Address, version: number] | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Like {@link getLatest}, but throws if no address is found in the range.
|
|
62
|
+
* @param contract - Registered contract name.
|
|
63
|
+
* @param range - Inclusive `[min, max]` version range to search.
|
|
64
|
+
* @throws If no address is registered in the given range.
|
|
65
|
+
**/
|
|
28
66
|
mustGetLatest: (contract: string, range: VersionRange) => [address: Address, version: number];
|
|
67
|
+
/**
|
|
68
|
+
* Re-reads all registered addresses from chain at the given block.
|
|
69
|
+
* @param blockNumber - Block number to read state at.
|
|
70
|
+
**/
|
|
29
71
|
syncState: (blockNumber: bigint) => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns a human-readable snapshot of the address provider state.
|
|
74
|
+
* @param raw - When `true`, includes raw/unformatted values alongside display strings.
|
|
75
|
+
**/
|
|
30
76
|
stateHuman: (raw?: boolean) => AddressProviderV3StateHuman;
|
|
31
77
|
}
|
|
@@ -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);
|
|
@@ -14,6 +14,7 @@ export declare class CreditFacadeV310Contract extends CreditFacadeV310BaseContra
|
|
|
14
14
|
liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[], lossPolicyData?: Hex): RawTx;
|
|
15
15
|
closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
|
|
16
16
|
multicall(ca: Address, calls: MultiCall[]): RawTx;
|
|
17
|
+
botMulticall(ca: Address, calls: MultiCall[]): RawTx;
|
|
17
18
|
openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
|
|
18
19
|
}
|
|
19
20
|
export {};
|
|
@@ -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
|
}
|
|
@@ -3,10 +3,22 @@ import type { priceFeedCompressorAbi } from "../../../abi/compressors/priceFeedC
|
|
|
3
3
|
import type { IBaseContract } from "../../base/index.js";
|
|
4
4
|
import type { MultiCall, PriceOracleStateHuman } from "../../types/index.js";
|
|
5
5
|
import type { AddressMap } from "../../utils/index.js";
|
|
6
|
-
import type { IPriceFeedContract, PriceFeedRef,
|
|
6
|
+
import type { IPriceFeedContract, PriceFeedRef, PriceUpdate, 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
|
/**
|
|
@@ -14,100 +26,107 @@ export interface PriceFeedsForTokensOptions {
|
|
|
14
26
|
* as raw PriceUpdate in liquidator calls.
|
|
15
27
|
*/
|
|
16
28
|
export interface OnDemandPriceUpdates {
|
|
17
|
-
raw:
|
|
29
|
+
raw: PriceUpdate[];
|
|
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
|
}
|