@gearbox-protocol/sdk 13.3.2 → 13.3.4
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/rewards/rewards/api.js +4 -124
- package/dist/cjs/rewards/rewards/extra-apy.js +5 -7
- package/dist/cjs/rewards/rewards/index.js +1 -5
- package/dist/cjs/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +40 -141
- 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/rewards/rewards/api.js +4 -124
- package/dist/esm/rewards/rewards/extra-apy.js +4 -6
- package/dist/esm/rewards/rewards/index.js +0 -2
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +40 -141
- 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/rewards/rewards/api.d.ts +5 -28
- package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
- package/dist/types/rewards/rewards/index.d.ts +0 -2
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +55 -141
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/types.d.ts +219 -17
- 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
- package/dist/cjs/rewards/rewards/apy.js +0 -177
- package/dist/esm/rewards/rewards/apy.js +0 -160
- package/dist/types/rewards/rewards/apy.d.ts +0 -44
|
@@ -3,21 +3,54 @@ import type { PhantomTokenContractType } from "../constants/index.js";
|
|
|
3
3
|
import type { Asset } from "../router/index.js";
|
|
4
4
|
import { AddressMap } from "../utils/index.js";
|
|
5
5
|
import type { TokenMetaData } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for {@link TokensMeta.formatBN}.
|
|
8
|
+
**/
|
|
6
9
|
export interface FormatBNOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Number of decimal places in the formatted output.
|
|
12
|
+
**/
|
|
7
13
|
precision?: number;
|
|
14
|
+
/**
|
|
15
|
+
* When `true`, appends the token symbol to the formatted string.
|
|
16
|
+
**/
|
|
8
17
|
symbol?: boolean;
|
|
9
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Token metadata enriched with some attributes specific to certain classes of tokens
|
|
21
|
+
**/
|
|
10
22
|
export interface TokenMetaDataExtended extends TokenMetaData {
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
24
|
+
* Classification of the phantom token, or `undefined` for normal tokens.
|
|
25
|
+
**/
|
|
14
26
|
phantomTokenType?: PhantomTokenContractType;
|
|
15
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Registry of token metadata (symbol, decimals, phantom type) keyed by address.
|
|
30
|
+
*
|
|
31
|
+
* Extends {@link AddressMap} with convenience accessors for formatting token
|
|
32
|
+
* amounts and looking up tokens by symbol.
|
|
33
|
+
*
|
|
34
|
+
* Provides methods to lazy-load information about certain classes of tokens (e.g. phantom tokens)
|
|
35
|
+
*/
|
|
16
36
|
export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
|
|
17
37
|
#private;
|
|
18
38
|
constructor(client: PublicClient<Transport, Chain>);
|
|
39
|
+
/**
|
|
40
|
+
* Clears all token metadata
|
|
41
|
+
**/
|
|
19
42
|
reset(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the symbol string for a token.
|
|
45
|
+
* @param token - Token address.
|
|
46
|
+
* @throws If the token is not in the registry.
|
|
47
|
+
*/
|
|
20
48
|
symbol(token: Address): string;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the decimal count for a token.
|
|
51
|
+
* @param token - Token address.
|
|
52
|
+
* @throws If the token is not in the registry.
|
|
53
|
+
*/
|
|
21
54
|
decimals(token: Address): number;
|
|
22
55
|
/**
|
|
23
56
|
* Returns the phantom token type for a given token, or undefined for normal tokens
|
|
@@ -29,9 +62,33 @@ export declare class TokensMeta extends AddressMap<TokenMetaDataExtended> {
|
|
|
29
62
|
* Throws if the phantom token data is not loaded
|
|
30
63
|
*/
|
|
31
64
|
get phantomTokens(): AddressMap<TokenMetaDataExtended>;
|
|
65
|
+
/**
|
|
66
|
+
* Formats a raw token amount into a human-readable decimal string,
|
|
67
|
+
* dividing by `10^decimals` for the token.
|
|
68
|
+
*
|
|
69
|
+
* Accepts either an {@link Asset} object or a separate `(token, amount)` pair.
|
|
70
|
+
*
|
|
71
|
+
* @param asset - Asset object containing `token` address and `balance`.
|
|
72
|
+
* @param options - Formatting options.
|
|
73
|
+
*/
|
|
32
74
|
formatBN(asset: Asset, options?: FormatBNOptions): string;
|
|
75
|
+
/**
|
|
76
|
+
* @param token - Token address.
|
|
77
|
+
* @param amount - Raw amount (in smallest unit).
|
|
78
|
+
* @param options - Formatting options.
|
|
79
|
+
*/
|
|
33
80
|
formatBN(token: Address, amount: number | bigint | string | undefined, options?: FormatBNOptions): string;
|
|
81
|
+
/**
|
|
82
|
+
* Finds a token by its symbol (e.g. `"USDC"`).
|
|
83
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
84
|
+
* @returns The matching metadata, or `undefined` if no token has this symbol.
|
|
85
|
+
*/
|
|
34
86
|
findBySymbol(symbol: string): TokenMetaData | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Finds a token by its symbol, throwing if not found.
|
|
89
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
90
|
+
* @throws If no token matches the symbol.
|
|
91
|
+
*/
|
|
35
92
|
mustFindBySymbol(symbol: string): TokenMetaData;
|
|
36
93
|
/**
|
|
37
94
|
* Loads phantom token data for all known tokens from chain
|
|
@@ -5,65 +5,208 @@ import type { gaugeCompressorAbi } from "../../abi/compressors/gaugeCompressor.j
|
|
|
5
5
|
import type { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
|
|
6
6
|
import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
|
|
7
7
|
import type { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
8
|
+
/**
|
|
9
|
+
* Recursively unwraps array types to their element type.
|
|
10
|
+
**/
|
|
8
11
|
export type Unarray<A> = A extends readonly unknown[] ? Unarray<A[number]> : A;
|
|
12
|
+
/**
|
|
13
|
+
* On-chain identification parameters shared by all Gearbox contracts.
|
|
14
|
+
**/
|
|
9
15
|
export interface BaseParams {
|
|
16
|
+
/**
|
|
17
|
+
* Contract address.
|
|
18
|
+
**/
|
|
10
19
|
addr: Address;
|
|
20
|
+
/**
|
|
21
|
+
* Contract version as a raw `uint256`.
|
|
22
|
+
**/
|
|
11
23
|
version: bigint;
|
|
24
|
+
/**
|
|
25
|
+
* ABI-encoded contract type identifier (bytes32).
|
|
26
|
+
**/
|
|
12
27
|
contractType: Hex;
|
|
28
|
+
/**
|
|
29
|
+
* Opaque ABI-encoded configuration specific to the contract type.
|
|
30
|
+
**/
|
|
13
31
|
serializedParams: Hex;
|
|
14
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Same as {@link BaseParams} but accepts JS-friendly value types, useful when
|
|
35
|
+
* constructing parameters manually rather than reading them from chain.
|
|
36
|
+
*/
|
|
15
37
|
export interface RelaxedBaseParams {
|
|
38
|
+
/**
|
|
39
|
+
* Contract address.
|
|
40
|
+
**/
|
|
16
41
|
addr: Address;
|
|
42
|
+
/**
|
|
43
|
+
* Contract version as a JS `number` or raw `bigint`.
|
|
44
|
+
**/
|
|
17
45
|
version: number | bigint;
|
|
18
46
|
/**
|
|
19
|
-
* Hex or parsed
|
|
20
|
-
|
|
47
|
+
* Hex bytes32 or its human-readable parsed string.
|
|
48
|
+
**/
|
|
21
49
|
contractType: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional ABI-encoded configuration.
|
|
52
|
+
**/
|
|
22
53
|
serializedParams?: Hex;
|
|
23
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Wrapper that pairs any contract state payload with its {@link BaseParams}.
|
|
57
|
+
**/
|
|
24
58
|
export interface BaseState {
|
|
25
59
|
baseParams: BaseParams;
|
|
26
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Filter criteria for querying markets.
|
|
63
|
+
**/
|
|
27
64
|
export type MarketFilter = AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof marketCompressorAbi, "getMarkets">["inputs"]>[0];
|
|
65
|
+
/**
|
|
66
|
+
* Full on-chain snapshot of a single credit account.
|
|
67
|
+
**/
|
|
28
68
|
export type CreditAccountData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof creditAccountCompressorAbi, "getCreditAccountData">["outputs"]>>;
|
|
69
|
+
/**
|
|
70
|
+
* Reward distribution details for a single reward token.
|
|
71
|
+
**/
|
|
29
72
|
export type RewardInfo = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof rewardsCompressorAbi, "getRewards">["outputs"]>>;
|
|
73
|
+
/**
|
|
74
|
+
* Full on-chain snapshot of a single Gearbox market (pool + credit managers + oracle).
|
|
75
|
+
**/
|
|
30
76
|
export type MarketData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof marketCompressorAbi, "getMarkets">["outputs"]>>;
|
|
77
|
+
/**
|
|
78
|
+
* Gauge voting state for a pool.
|
|
79
|
+
**/
|
|
31
80
|
export type GaugeData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof gaugeCompressorAbi, "getGaugeInfo">["outputs"]>>;
|
|
81
|
+
/**
|
|
82
|
+
* Bot connection data for a credit account.
|
|
83
|
+
**/
|
|
32
84
|
export type ConnectedBotData = Unarray<AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof peripheryCompressorAbi, "getConnectedBots">["outputs"]>>;
|
|
85
|
+
/**
|
|
86
|
+
* On-chain state of a single credit suite (credit manager + facade + configurator + adapters).
|
|
87
|
+
**/
|
|
33
88
|
export type CreditSuiteState = Unarray<MarketData["creditManagers"]>;
|
|
89
|
+
/**
|
|
90
|
+
* On-chain state of a credit manager contract.
|
|
91
|
+
**/
|
|
34
92
|
export type CreditManagerState = CreditSuiteState["creditManager"];
|
|
93
|
+
/**
|
|
94
|
+
* On-chain state of a credit facade contract.
|
|
95
|
+
**/
|
|
35
96
|
export type CreditFacadeState = CreditSuiteState["creditFacade"];
|
|
97
|
+
/**
|
|
98
|
+
* On-chain state of a credit configurator contract.
|
|
99
|
+
**/
|
|
36
100
|
export type CreditConfiguratorState = CreditSuiteState["creditConfigurator"];
|
|
101
|
+
/**
|
|
102
|
+
* Adapter contract data for a credit suite.
|
|
103
|
+
**/
|
|
37
104
|
export type AdapterData = Unarray<CreditSuiteState["adapters"]>;
|
|
105
|
+
/**
|
|
106
|
+
* On-chain metadata for a single token (symbol, decimals, address).
|
|
107
|
+
**/
|
|
38
108
|
export type TokenMetaData = Unarray<MarketData["tokens"]>;
|
|
109
|
+
/**
|
|
110
|
+
* On-chain state of a lending pool.
|
|
111
|
+
**/
|
|
39
112
|
export type PoolState = MarketData["pool"];
|
|
113
|
+
/**
|
|
114
|
+
* On-chain state of a quota keeper.
|
|
115
|
+
**/
|
|
40
116
|
export type QuotaKeeperState = MarketData["quotaKeeper"];
|
|
117
|
+
/**
|
|
118
|
+
* Quota parameters for a single token in a market.
|
|
119
|
+
**/
|
|
41
120
|
export type QuotaState = Unarray<QuotaKeeperState["quotas"]>;
|
|
121
|
+
/**
|
|
122
|
+
* On-chain state of a rate keeper.
|
|
123
|
+
**/
|
|
42
124
|
export type RateKeeperState = MarketData["rateKeeper"];
|
|
125
|
+
/**
|
|
126
|
+
* On-chain state of a price oracle (feed map + feed tree).
|
|
127
|
+
**/
|
|
43
128
|
export type PriceOracleData = MarketData["priceOracle"];
|
|
129
|
+
/**
|
|
130
|
+
* Single token-to-price-feed mapping entry in the oracle.
|
|
131
|
+
**/
|
|
44
132
|
export type PriceFeedMapEntry = Unarray<PriceOracleData["priceFeedMap"]>;
|
|
133
|
+
/**
|
|
134
|
+
* Node in the hierarchical price feed tree.
|
|
135
|
+
**/
|
|
45
136
|
export type PriceFeedTreeNode = Unarray<PriceOracleData["priceFeedTree"]>;
|
|
137
|
+
/**
|
|
138
|
+
* Latest price answer from a price feed.
|
|
139
|
+
**/
|
|
46
140
|
export type PriceFeedAnswer = PriceFeedTreeNode["answer"];
|
|
141
|
+
/**
|
|
142
|
+
* Debt parameters for a credit manager within a pool.
|
|
143
|
+
**/
|
|
47
144
|
export type CreditManagerDebtParams = Unarray<PoolState["creditManagerDebtParams"]>;
|
|
145
|
+
/**
|
|
146
|
+
* Whether a contract is permitted to participate in gauge voting.
|
|
147
|
+
**/
|
|
48
148
|
export declare enum VotingContractStatus {
|
|
49
149
|
NOT_ALLOWED = 0,
|
|
50
150
|
ALLOWED = 1,
|
|
51
151
|
UNVOTE_ONLY = 2
|
|
52
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* String-valued record of named function arguments produced by calldata parsing.
|
|
155
|
+
**/
|
|
53
156
|
export type ParsedCallArgs = Record<string, string>;
|
|
157
|
+
/**
|
|
158
|
+
* Human-readable representation of a decoded contract call (v1 format, string-coerced args).
|
|
159
|
+
**/
|
|
54
160
|
export interface ParsedCall {
|
|
161
|
+
/**
|
|
162
|
+
* Chain the call targets.
|
|
163
|
+
**/
|
|
55
164
|
chainId: number;
|
|
165
|
+
/**
|
|
166
|
+
* Address of the called contract.
|
|
167
|
+
**/
|
|
56
168
|
target: Address;
|
|
169
|
+
/**
|
|
170
|
+
* Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`).
|
|
171
|
+
**/
|
|
57
172
|
contractType: string;
|
|
173
|
+
/**
|
|
174
|
+
* Human-readable label for the target address.
|
|
175
|
+
**/
|
|
58
176
|
label: string;
|
|
177
|
+
/**
|
|
178
|
+
* Decoded function name, or a placeholder for unknown selectors.
|
|
179
|
+
**/
|
|
59
180
|
functionName: string;
|
|
181
|
+
/**
|
|
182
|
+
* Named arguments as string key-value pairs.
|
|
183
|
+
**/
|
|
60
184
|
args: ParsedCallArgs;
|
|
61
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Structured representation of a decoded contract call (v2 format) that
|
|
188
|
+
* preserves original argument types instead of coercing to strings.
|
|
189
|
+
*/
|
|
62
190
|
export interface ParsedCallV2 {
|
|
191
|
+
/**
|
|
192
|
+
* Chain the call targets.
|
|
193
|
+
**/
|
|
63
194
|
chainId: number;
|
|
195
|
+
/**
|
|
196
|
+
* Address of the called contract.
|
|
197
|
+
**/
|
|
64
198
|
target: Address;
|
|
199
|
+
/**
|
|
200
|
+
* Gearbox contract type identifier.
|
|
201
|
+
**/
|
|
65
202
|
contractType: string;
|
|
203
|
+
/**
|
|
204
|
+
* Human-readable label for the target address.
|
|
205
|
+
**/
|
|
66
206
|
label?: string;
|
|
207
|
+
/**
|
|
208
|
+
* Contract version number.
|
|
209
|
+
**/
|
|
67
210
|
version: number;
|
|
68
211
|
/**
|
|
69
212
|
* Function signature produced by viem's `toFunctionSignature`, e.g.:
|
|
@@ -74,56 +217,73 @@ export interface ParsedCallV2 {
|
|
|
74
217
|
* For unknown selectors: `"unknown function 0x1a2b3c4d"`
|
|
75
218
|
*/
|
|
76
219
|
functionName: string;
|
|
220
|
+
/**
|
|
221
|
+
* Named arguments with their original types (bigint, Address, etc.).
|
|
222
|
+
**/
|
|
77
223
|
rawArgs: Record<string, unknown>;
|
|
78
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Shared interface for all SDK contract wrappers, providing identity fields
|
|
227
|
+
* and calldata decoding/stringifying capabilities.
|
|
228
|
+
*/
|
|
79
229
|
export interface IBaseContract {
|
|
80
230
|
/**
|
|
81
|
-
*
|
|
231
|
+
* On-chain address of the contract.
|
|
82
232
|
**/
|
|
83
233
|
readonly address: Address;
|
|
84
234
|
/**
|
|
85
|
-
*
|
|
235
|
+
* Human-readable contract type (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
|
|
86
236
|
**/
|
|
87
237
|
readonly contractType: string;
|
|
88
238
|
/**
|
|
89
|
-
* Contract version
|
|
239
|
+
* Contract version number.
|
|
240
|
+
* @default 0
|
|
90
241
|
**/
|
|
91
242
|
readonly version: number;
|
|
92
243
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
|
|
244
|
+
* Display name used for labeling in logs and parsed calls.
|
|
245
|
+
*
|
|
246
|
+
* @remarks Other contracts may register additional labels via
|
|
247
|
+
* {@link ChainContractsRegister.setAddressLabel}, so prefer the register's
|
|
248
|
+
* labeling methods for user-facing output.
|
|
249
|
+
*/
|
|
96
250
|
readonly name: string;
|
|
97
251
|
/**
|
|
98
|
-
*
|
|
99
|
-
|
|
252
|
+
* @internal
|
|
253
|
+
* `true` when the local state has diverged from on-chain and needs a sync.
|
|
254
|
+
**/
|
|
100
255
|
dirty: boolean;
|
|
101
256
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @param raw
|
|
257
|
+
* Returns a human-readable snapshot of the contract's current state.
|
|
258
|
+
* @param raw - When `true`, includes raw/unformatted values.
|
|
104
259
|
*/
|
|
105
260
|
stateHuman(raw?: boolean): unknown;
|
|
106
261
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
262
|
+
* Decodes calldata into a {@link ParsedCall} with string-coerced arguments.
|
|
263
|
+
*
|
|
264
|
+
* @remarks This is a safe method: unknown selectors produce a fallback
|
|
265
|
+
* result instead of throwing. For strict parsing, use {@link mustParseFunctionData}.
|
|
266
|
+
*/
|
|
110
267
|
parseFunctionData: (calldata: Hex) => ParsedCall;
|
|
111
268
|
/**
|
|
112
|
-
* Same as {@link parseFunctionData}, but throws
|
|
113
|
-
|
|
269
|
+
* Same as {@link parseFunctionData}, but throws {@link ContractParseError}
|
|
270
|
+
* on unknown selectors.
|
|
271
|
+
*/
|
|
114
272
|
mustParseFunctionData: (calldata: Hex) => ParsedCall;
|
|
115
273
|
/**
|
|
116
|
-
* Converts
|
|
117
|
-
*
|
|
118
|
-
|
|
274
|
+
* Converts calldata to a single human-friendly string (e.g. for logging).
|
|
275
|
+
*
|
|
276
|
+
* @remarks This is a safe method that never throws.
|
|
277
|
+
*/
|
|
119
278
|
stringifyFunctionData: (calldata: Hex) => string;
|
|
120
279
|
/**
|
|
121
|
-
* Same as {@link stringifyFunctionData}, but throws
|
|
122
|
-
|
|
280
|
+
* Same as {@link stringifyFunctionData}, but throws on decode failure.
|
|
281
|
+
*/
|
|
123
282
|
mustStringifyFunctionData: (calldata: Hex) => string;
|
|
124
283
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
|
|
284
|
+
* Decodes calldata into a {@link ParsedCallV2} preserving original argument types.
|
|
285
|
+
* @param calldata - Raw ABI-encoded calldata.
|
|
286
|
+
* @param strict - When `true`, throws on unknown selectors; otherwise returns a fallback.
|
|
287
|
+
*/
|
|
128
288
|
parseFunctionDataV2: (calldata: Hex, strict?: boolean) => ParsedCallV2;
|
|
129
289
|
}
|
|
@@ -1,29 +1,55 @@
|
|
|
1
1
|
import type { Address, Chain } from "viem";
|
|
2
2
|
import { z } from "zod/v4";
|
|
3
|
+
/**
|
|
4
|
+
* Known curator names that manage Gearbox markets.
|
|
5
|
+
*
|
|
6
|
+
**/
|
|
3
7
|
export type Curator = "Chaos Labs" | "K3" | "cp0x" | "Re7" | "Invariant Group" | "Tulipa" | "M11 Credit" | "kpk" | "Hyperithm" | "UltraYield" | "TelosC" | "Gami Labs";
|
|
8
|
+
/**
|
|
9
|
+
* Extended viem {@link Chain} with Gearbox-specific metadata.
|
|
10
|
+
*
|
|
11
|
+
* Every supported network is represented by a `GearboxChain` instance in
|
|
12
|
+
* the {@link chains} record.
|
|
13
|
+
**/
|
|
4
14
|
export interface GearboxChain extends Chain {
|
|
15
|
+
/**
|
|
16
|
+
* Gearbox network type label (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
17
|
+
**/
|
|
5
18
|
network: NetworkType;
|
|
19
|
+
/**
|
|
20
|
+
* Market configurator addresses operated by known curators on this chain.
|
|
21
|
+
**/
|
|
6
22
|
defaultMarketConfigurators: Record<Address, Curator>;
|
|
23
|
+
/**
|
|
24
|
+
* Market configurators used in test/staging environments.
|
|
25
|
+
**/
|
|
7
26
|
testMarketConfigurators?: Record<Address, Curator>;
|
|
27
|
+
/**
|
|
28
|
+
* Whether this chain is production-ready
|
|
29
|
+
**/
|
|
8
30
|
isPublic: boolean;
|
|
9
31
|
/**
|
|
10
|
-
*
|
|
11
|
-
* This can be used to uniquely identify the chain from arbitrary RPC endpoint
|
|
32
|
+
* A well-known ERC-20 token that uniquely identifies this chain.
|
|
12
33
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
*/
|
|
34
|
+
* Used by {@link detectNetwork} to determine which chain an arbitrary
|
|
35
|
+
* RPC endpoint is connected to.
|
|
36
|
+
**/
|
|
17
37
|
wellKnownToken: {
|
|
18
38
|
address: Address;
|
|
19
39
|
symbol: string;
|
|
20
40
|
};
|
|
21
41
|
/**
|
|
22
|
-
* Block number when Gearbox address provider was deployed
|
|
23
|
-
|
|
42
|
+
* Block number when the Gearbox address provider was deployed.
|
|
43
|
+
**/
|
|
24
44
|
firstBlock?: bigint;
|
|
25
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Tuple of all network labels the SDK can work with.
|
|
48
|
+
**/
|
|
26
49
|
export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain", "Etherlink", "Hemi", "Lisk", "Plasma", "Somnia"];
|
|
50
|
+
/**
|
|
51
|
+
* Zod schema for validating/parsing network type strings.
|
|
52
|
+
**/
|
|
27
53
|
export declare const NetworkType: z.ZodEnum<{
|
|
28
54
|
Mainnet: "Mainnet";
|
|
29
55
|
Arbitrum: "Arbitrum";
|
|
@@ -42,23 +68,57 @@ export declare const NetworkType: z.ZodEnum<{
|
|
|
42
68
|
Plasma: "Plasma";
|
|
43
69
|
Somnia: "Somnia";
|
|
44
70
|
}>;
|
|
71
|
+
/**
|
|
72
|
+
* All supported Gearbox network labels
|
|
73
|
+
**/
|
|
45
74
|
export type NetworkType = z.infer<typeof NetworkType>;
|
|
75
|
+
/**
|
|
76
|
+
* Pre-configured {@link GearboxChain} instances for every supported network.
|
|
77
|
+
**/
|
|
46
78
|
export declare const chains: Record<NetworkType, GearboxChain>;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the {@link GearboxChain} for a given chain ID or network type label.
|
|
81
|
+
*
|
|
82
|
+
* @param chainIdOrNetworkType - Numeric chain ID, bigint chain ID, or a {@link NetworkType} string.
|
|
83
|
+
* @throws If the chain ID / network type is not supported.
|
|
84
|
+
**/
|
|
47
85
|
export declare function getChain(chainIdOrNetworkType: number | bigint | NetworkType): GearboxChain;
|
|
86
|
+
/**
|
|
87
|
+
* Resolves a numeric chain ID to its {@link NetworkType} label.
|
|
88
|
+
*
|
|
89
|
+
* @param chainId - Numeric or bigint chain ID.
|
|
90
|
+
* @throws If the chain ID does not correspond to a supported network.
|
|
91
|
+
**/
|
|
48
92
|
export declare function getNetworkType(chainId: number | bigint): NetworkType;
|
|
93
|
+
/**
|
|
94
|
+
* Type guard that checks whether a chain ID belongs to a supported Gearbox network.
|
|
95
|
+
*
|
|
96
|
+
* @param chainId - Numeric chain ID, or `undefined`.
|
|
97
|
+
**/
|
|
49
98
|
export declare function isSupportedNetwork(chainId: number | undefined): chainId is number;
|
|
99
|
+
/**
|
|
100
|
+
* Returns `true` if the given network or chain ID has a publicly deployed Gearbox instance.
|
|
101
|
+
*
|
|
102
|
+
* @param networkOrChainId - {@link NetworkType} string or numeric chain ID.
|
|
103
|
+
**/
|
|
50
104
|
export declare function isPublicNetwork(networkOrChainId: NetworkType | number | bigint): boolean;
|
|
51
105
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
|
|
106
|
+
* Looks up the {@link Curator} name for a market configurator address.
|
|
107
|
+
*
|
|
108
|
+
* Searches default and test market configurators across all chains, or
|
|
109
|
+
* a single network if provided.
|
|
110
|
+
*
|
|
111
|
+
* @param marketConfigurator - On-chain market configurator address.
|
|
112
|
+
* @param network - Optional network to restrict the search to.
|
|
113
|
+
* @returns The curator name, or `undefined` if not found.
|
|
114
|
+
**/
|
|
57
115
|
export declare function getCuratorName(marketConfigurator: Address, network?: NetworkType): Curator | undefined;
|
|
58
116
|
/**
|
|
59
|
-
* Finds market configurator address
|
|
60
|
-
*
|
|
61
|
-
* @param
|
|
62
|
-
* @
|
|
63
|
-
|
|
117
|
+
* Finds the market configurator address for a given curator on a network.
|
|
118
|
+
*
|
|
119
|
+
* @param curator - Curator name to search for.
|
|
120
|
+
* @param network - Network to search in.
|
|
121
|
+
* @returns The market configurator address, or `undefined` if the curator
|
|
122
|
+
* has no configurator on this network.
|
|
123
|
+
**/
|
|
64
124
|
export declare function findCuratorMarketConfigurator(curator: Curator, network: NetworkType): Address | undefined;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { PublicClient } from "viem";
|
|
2
2
|
import type { NetworkType } from "./chains.js";
|
|
3
|
+
/**
|
|
4
|
+
* Detects the network type from the given client.
|
|
5
|
+
* See {@link GearboxChain.wellKnownToken} for more details.
|
|
6
|
+
* @param client - viem public client
|
|
7
|
+
* @returns Network type
|
|
8
|
+
* @throws {Error} If the network type is not supported
|
|
9
|
+
*/
|
|
3
10
|
export declare function detectNetwork(client: PublicClient): Promise<NetworkType>;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { NetworkType } from "../chain/index.js";
|
|
3
1
|
export declare const NO_VERSION = 0;
|
|
4
2
|
export declare const AP_ACCOUNT_FACTORY = "ACCOUNT_FACTORY";
|
|
5
3
|
export declare const AP_ACL = "ACL";
|
|
@@ -33,5 +31,8 @@ export declare const AP_WETH_GATEWAY = "WETH_GATEWAY";
|
|
|
33
31
|
export declare const AP_WETH_TOKEN = "WETH_TOKEN";
|
|
34
32
|
export declare const AP_ZAPPER_REGISTER = "ZAPPER_REGISTER";
|
|
35
33
|
export declare const AP_ZERO_PRICE_FEED = "ZERO_PRICE_FEED";
|
|
36
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Default address provider address for v3.1.0
|
|
36
|
+
* Is determenistic and does not depend on the network type
|
|
37
|
+
*/
|
|
37
38
|
export declare const ADDRESS_PROVIDER_V310 = "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38";
|
|
@@ -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
|
}
|