@gearbox-protocol/sdk 13.4.0-beta.1 → 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 +66 -187
- 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/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 +69 -188
- 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/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 +55 -132
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/multicall-utils.d.ts +3 -3
- package/dist/types/sdk/accounts/types.d.ts +215 -28
- 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 +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 +3 -2
|
@@ -3,6 +3,10 @@ class AddressMap {
|
|
|
3
3
|
#map;
|
|
4
4
|
#frozen = false;
|
|
5
5
|
#name;
|
|
6
|
+
/**
|
|
7
|
+
* @param entries - Optional initial key-value pairs. Address strings are checksummed automatically.
|
|
8
|
+
* @param name - Optional label used in error messages when a lookup fails.
|
|
9
|
+
*/
|
|
6
10
|
constructor(entries, name) {
|
|
7
11
|
this.#map = /* @__PURE__ */ new Map();
|
|
8
12
|
if (entries) {
|
|
@@ -14,9 +18,10 @@ class AddressMap {
|
|
|
14
18
|
this.#name = name;
|
|
15
19
|
}
|
|
16
20
|
/**
|
|
17
|
-
* Adds or updates value
|
|
18
|
-
* @param address
|
|
19
|
-
* @param value
|
|
21
|
+
* Adds or updates a value. Passing `undefined` removes the entry.
|
|
22
|
+
* @param address - EVM address (checksummed automatically).
|
|
23
|
+
* @param value - Value to store, or `undefined` to delete the entry.
|
|
24
|
+
* @throws If the map has been {@link freeze | frozen}.
|
|
20
25
|
*/
|
|
21
26
|
upsert(address, value) {
|
|
22
27
|
if (this.#frozen) {
|
|
@@ -30,9 +35,10 @@ class AddressMap {
|
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param address
|
|
35
|
-
* @param value
|
|
38
|
+
* Inserts a value, throwing if the address is already present.
|
|
39
|
+
* @param address - EVM address (checksummed automatically).
|
|
40
|
+
* @param value - Value to store.
|
|
41
|
+
* @throws If the map has been {@link freeze | frozen} or if `address` already exists.
|
|
36
42
|
*/
|
|
37
43
|
insert(address, value) {
|
|
38
44
|
if (this.#frozen) {
|
|
@@ -47,27 +53,26 @@ class AddressMap {
|
|
|
47
53
|
this.#map.set(key, value);
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
|
-
* Checks
|
|
51
|
-
* @param address
|
|
52
|
-
* @returns
|
|
56
|
+
* Checks whether an address is present in the map.
|
|
57
|
+
* @param address - EVM address (case-insensitive).
|
|
53
58
|
*/
|
|
54
59
|
has(address) {
|
|
55
60
|
const key = getAddress(address);
|
|
56
61
|
return this.#map.has(key);
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param address
|
|
61
|
-
* @returns
|
|
64
|
+
* Looks up a value by EVM address (case-insensitive).
|
|
65
|
+
* @param address - EVM address to look up.
|
|
66
|
+
* @returns The stored value, or `undefined` if not present.
|
|
62
67
|
*/
|
|
63
68
|
get(address) {
|
|
64
69
|
const key = getAddress(address);
|
|
65
70
|
return this.#map.get(key);
|
|
66
71
|
}
|
|
67
72
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param address
|
|
70
|
-
* @
|
|
73
|
+
* Looks up a value by EVM address, throwing if the address is absent.
|
|
74
|
+
* @param address - EVM address to look up.
|
|
75
|
+
* @throws If `address` is not in the map.
|
|
71
76
|
*/
|
|
72
77
|
mustGet(address) {
|
|
73
78
|
const key = getAddress(address);
|
|
@@ -77,40 +82,71 @@ class AddressMap {
|
|
|
77
82
|
return this.#map.get(key);
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @param address
|
|
85
|
+
* Removes an entry by address. No-op if the address is absent.
|
|
86
|
+
* @param address - EVM address to remove.
|
|
82
87
|
*/
|
|
83
88
|
delete(address) {
|
|
84
89
|
const key = getAddress(address);
|
|
85
90
|
this.#map.delete(key);
|
|
86
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Removes all entries from the map.
|
|
94
|
+
**/
|
|
87
95
|
clear() {
|
|
88
96
|
this.#map.clear();
|
|
89
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns all entries as an array of `[checksummedAddress, value]` tuples.
|
|
100
|
+
**/
|
|
90
101
|
entries() {
|
|
91
102
|
return Array.from(this.#map.entries());
|
|
92
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns all values in insertion order.
|
|
106
|
+
**/
|
|
93
107
|
values() {
|
|
94
108
|
return Array.from(this.#map.values());
|
|
95
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns all checksummed addresses in insertion order.
|
|
112
|
+
**/
|
|
96
113
|
keys() {
|
|
97
114
|
return Array.from(this.#map.keys());
|
|
98
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Converts the map to a plain `Record<Address, T>` object.
|
|
118
|
+
**/
|
|
99
119
|
asRecord() {
|
|
100
120
|
return Object.fromEntries(this.#map.entries());
|
|
101
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Number of entries in the map.
|
|
124
|
+
**/
|
|
102
125
|
get size() {
|
|
103
126
|
return this.#map.size;
|
|
104
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Prevents further mutations. Any subsequent call to {@link upsert},
|
|
130
|
+
* {@link insert}, or {@link delete} will throw.
|
|
131
|
+
*/
|
|
105
132
|
freeze() {
|
|
106
133
|
this.#frozen = true;
|
|
107
134
|
}
|
|
108
135
|
get name() {
|
|
109
136
|
return this.#name;
|
|
110
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Creates an `AddressMap` from a plain record object.
|
|
140
|
+
* @param record - Object whose keys are EVM addresses.
|
|
141
|
+
*/
|
|
111
142
|
static fromRecord(record) {
|
|
112
143
|
return new AddressMap(Object.entries(record));
|
|
113
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Creates an `AddressMap` by extracting an address from each array element.
|
|
147
|
+
* @param array - Source items.
|
|
148
|
+
* @param mapFn - Function that returns the address key for a given item.
|
|
149
|
+
*/
|
|
114
150
|
static fromMappedArray(array, mapFn) {
|
|
115
151
|
return new AddressMap(array.map((item) => [mapFn(item), item]));
|
|
116
152
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getAddress } from "viem";
|
|
2
2
|
class AddressSet extends Set {
|
|
3
|
+
/**
|
|
4
|
+
* @param entries - Optional initial addresses. Each is checksummed automatically.
|
|
5
|
+
*/
|
|
3
6
|
constructor(entries) {
|
|
4
7
|
super(Array.from(entries ?? []).map((a) => getAddress(a)));
|
|
5
8
|
}
|
|
@@ -12,9 +15,15 @@ class AddressSet extends Set {
|
|
|
12
15
|
has(value) {
|
|
13
16
|
return super.has(getAddress(value));
|
|
14
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns all addresses as an array.
|
|
20
|
+
**/
|
|
15
21
|
asArray() {
|
|
16
22
|
return Array.from(this);
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Maps each address through `fn` and returns the resulting array.
|
|
26
|
+
**/
|
|
18
27
|
map(fn) {
|
|
19
28
|
return this.asArray().map(fn);
|
|
20
29
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type Address, type Chain, type DecodeFunctionDataReturnType, type Hex, type PublicClient, type Transport } from "viem";
|
|
2
|
-
import type { RawTx } from "../../sdk/index.js";
|
|
2
|
+
import type { PriceUpdate, RawTx } from "../../sdk/index.js";
|
|
3
3
|
import { BaseContract, type ParsedCallArgs } from "../../sdk/index.js";
|
|
4
4
|
import type { InputValueParams, PriceFeed } from "../core/index.js";
|
|
5
|
-
import type { PriceUpdate } from "./types.js";
|
|
6
5
|
declare const abi: readonly [{
|
|
7
6
|
readonly type: "function";
|
|
8
7
|
readonly inputs: readonly [{
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type Address, type Chain, type PublicClient, type Transport } from "viem";
|
|
2
|
-
import
|
|
3
|
-
import { type PriceUpdate } from "../../bindings/index.js";
|
|
4
|
-
export declare function getUpdateCalldata(tx: IPriceUpdateTx): PriceUpdate;
|
|
2
|
+
import type { RawTx } from "../../../sdk/index.js";
|
|
5
3
|
export declare function getPriceUpdateTx({ client, priceFeeds, useMulticall3, gasLimit, }: {
|
|
6
4
|
client: PublicClient<Transport, Chain>;
|
|
7
5
|
priceFeeds: Address[];
|
|
@@ -13,100 +13,302 @@ import { type PluginsMap } from "./plugins/index.js";
|
|
|
13
13
|
import { type IRouterContract } from "./router/index.js";
|
|
14
14
|
import type { GearboxState, GearboxStateHuman } from "./types/index.js";
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
|
|
16
|
+
* Serialised state format version, checked during hydration to detect
|
|
17
|
+
* incompatible snapshots.
|
|
18
|
+
**/
|
|
18
19
|
export declare const STATE_VERSION = 1;
|
|
20
|
+
/**
|
|
21
|
+
* Explicit network identity, required when working with forked testnets
|
|
22
|
+
* whose chain IDs differ from the canonical mainnet/testnet values.
|
|
23
|
+
**/
|
|
19
24
|
export interface NetworkOptions {
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
26
|
+
* EVM chain ID.
|
|
27
|
+
* Must be set explicitly for forked testnets whose chain ID differs
|
|
28
|
+
* from the canonical network.
|
|
29
|
+
**/
|
|
23
30
|
chainId: number;
|
|
24
31
|
/**
|
|
25
|
-
*
|
|
26
|
-
|
|
32
|
+
* Gearbox network type (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
33
|
+
* Must be set explicitly for forked testnets whose chain ID differs
|
|
34
|
+
* from the canonical network.
|
|
35
|
+
**/
|
|
27
36
|
networkType: NetworkType;
|
|
28
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Connection options for the underlying JSON-RPC provider.
|
|
40
|
+
*
|
|
41
|
+
* Supply **one** of the three variants:
|
|
42
|
+
* - `rpcURLs` — the SDK creates a viem transport internally (with optional
|
|
43
|
+
* fallback when multiple URLs are given).
|
|
44
|
+
* - `transport` — bring your own viem `Transport`.
|
|
45
|
+
* - `client` — bring your own fully-configured viem `PublicClient`.
|
|
46
|
+
* When using this variant, the client is responsible for carrying the
|
|
47
|
+
* correct `networkType` and `chainId`.
|
|
48
|
+
*
|
|
49
|
+
* ### Network detection
|
|
50
|
+
*
|
|
51
|
+
* For the `rpcURLs` and `transport` variants, `networkType` and `chainId` are
|
|
52
|
+
* resolved as follows (see {@link NetworkOptions}):
|
|
53
|
+
* - If `networkType` is provided, it is used directly; `chainId` defaults to
|
|
54
|
+
* the canonical chain ID for that network when omitted.
|
|
55
|
+
* - If `networkType` is **not** provided, it is detected automatically using {@link detectNetwork}.
|
|
56
|
+
* When `chainId` is also omitted it is fetched via `eth_chainId`.
|
|
57
|
+
*
|
|
58
|
+
**/
|
|
29
59
|
export type ClientOptions = {
|
|
30
60
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
61
|
+
* One or more JSON-RPC endpoint URLs.
|
|
62
|
+
* When more than one URL is provided, a viem `fallback` transport is created.
|
|
63
|
+
**/
|
|
33
64
|
rpcURLs: string[];
|
|
34
65
|
/**
|
|
35
|
-
*
|
|
36
|
-
|
|
66
|
+
* Per-request timeout in milliseconds.
|
|
67
|
+
**/
|
|
37
68
|
timeout?: number;
|
|
38
69
|
/**
|
|
39
|
-
*
|
|
40
|
-
|
|
70
|
+
* Number of automatic retries per RPC call.
|
|
71
|
+
**/
|
|
41
72
|
retryCount?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Low-level options forwarded to the viem HTTP transport.
|
|
75
|
+
**/
|
|
42
76
|
httpTransportOptions?: HttpRpcClientOptions | undefined;
|
|
43
77
|
} | {
|
|
44
78
|
/**
|
|
45
|
-
*
|
|
46
|
-
|
|
79
|
+
* Pre-built viem transport.
|
|
80
|
+
**/
|
|
47
81
|
transport: Transport;
|
|
48
82
|
} | {
|
|
49
83
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
84
|
+
* Pre-built viem public client.
|
|
85
|
+
* Must already carry a {@link GearboxChain} definition with `networkType`
|
|
86
|
+
* and `chainId`.
|
|
87
|
+
**/
|
|
53
88
|
client: PublicClient<Transport, GearboxChain>;
|
|
54
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Options accepted by {@link GearboxSDK.hydrate}.
|
|
92
|
+
*
|
|
93
|
+
* Same as {@link SDKOptions} but without fields that are already captured
|
|
94
|
+
* inside the serialised {@link GearboxState} (`blockNumber`,
|
|
95
|
+
* `addressProvider`, `marketConfigurators`).
|
|
96
|
+
*
|
|
97
|
+
* @typeParam Plugins - Map of plugin names to plugin instances.
|
|
98
|
+
**/
|
|
55
99
|
export type HydrateOptions<Plugins extends PluginsMap> = Omit<SDKOptions<Plugins>, "blockNumber" | "addressProvider" | "marketConfigurators">;
|
|
100
|
+
/**
|
|
101
|
+
* Options for {@link GearboxSDK.syncState}, controlling which block to
|
|
102
|
+
* sync to and whether updatable price feeds should be refreshed.
|
|
103
|
+
**/
|
|
56
104
|
export interface SyncStateOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Target block number to sync to.
|
|
107
|
+
**/
|
|
57
108
|
blockNumber: bigint;
|
|
109
|
+
/**
|
|
110
|
+
* Block timestamp corresponding to `blockNumber`.
|
|
111
|
+
**/
|
|
58
112
|
timestamp: bigint;
|
|
113
|
+
/**
|
|
114
|
+
* When `true`, skip refreshing updatable price feeds during this sync.
|
|
115
|
+
**/
|
|
59
116
|
ignoreUpdateablePrices?: boolean;
|
|
60
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Hook event map for the SDK lifecycle.
|
|
120
|
+
*
|
|
121
|
+
* Register listeners via {@link GearboxSDK.addHook} and remove them
|
|
122
|
+
* with {@link GearboxSDK.removeHook}.
|
|
123
|
+
*
|
|
124
|
+
* - `syncState` — fired after {@link GearboxSDK.syncState} completes.
|
|
125
|
+
* - `rehydrate` — fired after {@link GearboxSDK.rehydrate} completes.
|
|
126
|
+
**/
|
|
61
127
|
export type SDKHooks = {
|
|
62
128
|
syncState: [SyncStateOptions];
|
|
63
129
|
rehydrate: [SyncStateOptions];
|
|
64
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* Main entry point for the Gearbox SDK.
|
|
133
|
+
*
|
|
134
|
+
* `GearboxSDK` aggregates on-chain state for the Gearbox protocol — markets,
|
|
135
|
+
* credit managers, pools, price oracles, and price feeds — into a single
|
|
136
|
+
* queryable object that can be kept up-to-date via {@link syncState} or
|
|
137
|
+
* serialised/restored via {@link state}/{@link hydrate}.
|
|
138
|
+
*
|
|
139
|
+
* It represents on-chain state using instances of js classes that provide convenient methods
|
|
140
|
+
* to read state and prepare transactions to interact with the protocol.
|
|
141
|
+
*
|
|
142
|
+
* Create an instance with the static {@link GearboxSDK.attach | attach}
|
|
143
|
+
* (reads live chain data) or {@link GearboxSDK.hydrate | hydrate}
|
|
144
|
+
* (restores from a saved snapshot) factory methods.
|
|
145
|
+
*
|
|
146
|
+
* @typeParam Plugins - Map of plugin names to plugin instances that extend
|
|
147
|
+
* the SDK with additional domain-specific functionality.
|
|
148
|
+
**/
|
|
65
149
|
export declare class GearboxSDK<const Plugins extends PluginsMap = {}> extends ChainContractsRegister {
|
|
66
150
|
#private;
|
|
151
|
+
/**
|
|
152
|
+
* Registered plugin instances, keyed by plugin name.
|
|
153
|
+
**/
|
|
67
154
|
readonly plugins: Plugins;
|
|
155
|
+
/**
|
|
156
|
+
* Gas limit applied to read-only `eth_call` requests.
|
|
157
|
+
* `undefined` means that gas limit will not be set on read-only calls,
|
|
158
|
+
* leaving it to rpc provider to decide.
|
|
159
|
+
**/
|
|
68
160
|
readonly gasLimit: bigint | undefined;
|
|
69
161
|
/**
|
|
70
|
-
*
|
|
71
|
-
|
|
162
|
+
* When `true`, the SDK throws on unrecognised contract types instead of
|
|
163
|
+
* falling back to a generic contract wrapper.
|
|
164
|
+
**/
|
|
72
165
|
readonly strictContractTypes: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Registers a callback for an SDK lifecycle event.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link SDKHooks} for available event names.
|
|
170
|
+
**/
|
|
73
171
|
addHook: <K extends keyof SDKHooks>(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
172
|
+
/**
|
|
173
|
+
* Removes a previously registered lifecycle callback.
|
|
174
|
+
*
|
|
175
|
+
* @see {@link SDKHooks} for available event names.
|
|
176
|
+
**/
|
|
74
177
|
removeHook: <K extends keyof SDKHooks>(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Creates and initialises a new SDK instance by reading live on-chain state.
|
|
180
|
+
*
|
|
181
|
+
* This is the primary way to bootstrap the SDK. The method connects to the
|
|
182
|
+
* chain, discovers the address provider and all configured markets, and
|
|
183
|
+
* attaches any supplied plugins.
|
|
184
|
+
*
|
|
185
|
+
* @param options - Combined SDK, client, and (optional) network options.
|
|
186
|
+
* @returns A fully initialised SDK instance.
|
|
187
|
+
**/
|
|
75
188
|
static attach<const Plugins extends PluginsMap>(options: SDKOptions<Plugins> & ClientOptions & Partial<NetworkOptions>): Promise<GearboxSDK<Plugins>>;
|
|
189
|
+
/**
|
|
190
|
+
* Creates a new SDK instance from a previously serialised {@link GearboxState}
|
|
191
|
+
* snapshot, without making any on-chain calls.
|
|
192
|
+
*
|
|
193
|
+
* Use this for fast startup when a recent state snapshot is available
|
|
194
|
+
* (e.g. loaded from a file or received from a backend service).
|
|
195
|
+
*
|
|
196
|
+
* @param options - SDK and client options (block number and address provider
|
|
197
|
+
* are taken from the snapshot).
|
|
198
|
+
* @param state - Serialised state obtained from {@link GearboxSDK.state}.
|
|
199
|
+
* @returns A fully initialised SDK instance.
|
|
200
|
+
* @throws If the snapshot's {@link STATE_VERSION} does not match.
|
|
201
|
+
**/
|
|
76
202
|
static hydrate<const Plugins extends PluginsMap>(options: HydrateOptions<Plugins> & ClientOptions, state: GearboxState<Plugins>): GearboxSDK<Plugins>;
|
|
77
203
|
private constructor();
|
|
78
204
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
|
|
205
|
+
* Re-attaches the SDK using the same configuration, discarding all cached
|
|
206
|
+
* state and re-reading everything from the chain.
|
|
207
|
+
*
|
|
208
|
+
* Useful when the SDK needs a full refresh (e.g. after a protocol upgrade).
|
|
209
|
+
* Note that if the original `blockNumber` was pinned, the same block is
|
|
210
|
+
* re-used — call {@link syncState} instead if you want to advance.
|
|
211
|
+
*
|
|
212
|
+
* @throws If the SDK has not been attached yet.
|
|
213
|
+
**/
|
|
82
214
|
reattach(): Promise<void>;
|
|
83
215
|
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
216
|
+
* Replaces the SDK's in-memory state with a new serialised snapshot
|
|
217
|
+
* without re-creating the instance.
|
|
218
|
+
*
|
|
219
|
+
* After hydration the `rehydrate` hook is triggered so that listeners
|
|
220
|
+
* can react to the state change.
|
|
221
|
+
*
|
|
222
|
+
* @param state - Serialised state obtained from {@link GearboxSDK.state}.
|
|
223
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
224
|
+
**/
|
|
86
225
|
rehydrate(state: GearboxState<Plugins>): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Gearbox network type the SDK is connected to (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
228
|
+
**/
|
|
87
229
|
get networkType(): NetworkType;
|
|
230
|
+
/**
|
|
231
|
+
* Returns a human-readable snapshot of the entire SDK state, suitable
|
|
232
|
+
* for logging or diagnostic inspection.
|
|
233
|
+
*
|
|
234
|
+
* @param raw - When `true`, include raw numeric values alongside
|
|
235
|
+
* formatted ones.
|
|
236
|
+
* @default true
|
|
237
|
+
**/
|
|
88
238
|
stateHuman(raw?: boolean): GearboxStateHuman;
|
|
239
|
+
/**
|
|
240
|
+
* Serialisable snapshot of the current SDK state.
|
|
241
|
+
*
|
|
242
|
+
* The returned object can be persisted (e.g. written to a file) and later
|
|
243
|
+
* passed to {@link GearboxSDK.hydrate} for instant restoration without
|
|
244
|
+
* on-chain reads.
|
|
245
|
+
**/
|
|
89
246
|
get state(): GearboxState<Plugins>;
|
|
90
247
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
248
|
+
* Incrementally updates the SDK state by replaying on-chain events from the
|
|
249
|
+
* last processed block up to the target block (defaults to `latest`).
|
|
250
|
+
*
|
|
251
|
+
* Use the to periodically update sdk state on cron, or subscribe to new blocks
|
|
252
|
+
* using viem's `watchBlocks`
|
|
253
|
+
*
|
|
254
|
+
* On failure the SDK reverts to the previous block/timestamp so that
|
|
255
|
+
* subsequent calls can retry.
|
|
256
|
+
*
|
|
257
|
+
* @param opts - Target block and sync behaviour. When omitted the latest
|
|
258
|
+
* block is fetched automatically.
|
|
259
|
+
* @returns `true` if the sync completed successfully, `false` if it was
|
|
260
|
+
* skipped or failed.
|
|
261
|
+
**/
|
|
95
262
|
syncState(opts?: SyncStateOptions): Promise<boolean>;
|
|
263
|
+
/**
|
|
264
|
+
* Block number that the SDK state corresponds to.
|
|
265
|
+
*
|
|
266
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
267
|
+
**/
|
|
96
268
|
get currentBlock(): bigint;
|
|
269
|
+
/**
|
|
270
|
+
* Block timestamp (Unix epoch seconds) corresponding to {@link currentBlock}.
|
|
271
|
+
*
|
|
272
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
273
|
+
**/
|
|
97
274
|
get timestamp(): bigint;
|
|
98
275
|
/**
|
|
99
|
-
*
|
|
100
|
-
|
|
276
|
+
* Global registry of all price feeds known to the SDK (on all markets).
|
|
277
|
+
*
|
|
278
|
+
* Unlike per-oracle price feed references, this register does not carry
|
|
279
|
+
* oracle-specific metadata (staleness period, main/reserve designation, etc.).
|
|
280
|
+
*
|
|
281
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
282
|
+
**/
|
|
101
283
|
get priceFeeds(): PriceFeedRegister;
|
|
284
|
+
/**
|
|
285
|
+
* Address of the GEAR governance token on this chain, or `undefined`
|
|
286
|
+
* if the address provider does not list it.
|
|
287
|
+
**/
|
|
102
288
|
get gear(): Address | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* The chain's address provider contract, the central directory for all
|
|
291
|
+
* protocol-wide Gearbox protocol addresses.
|
|
292
|
+
*
|
|
293
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
294
|
+
**/
|
|
103
295
|
get addressProvider(): IAddressProviderContract;
|
|
296
|
+
/**
|
|
297
|
+
* Registry of all loaded markets (pools, credit managers, oracles, etc.).
|
|
298
|
+
*
|
|
299
|
+
* @throws If the SDK has not been attached or hydrated yet.
|
|
300
|
+
**/
|
|
104
301
|
get marketRegister(): MarketRegister;
|
|
105
302
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
303
|
+
* Resolves the appropriate router contract for a given credit manager,
|
|
304
|
+
* credit facade, or explicit version range.
|
|
305
|
+
*
|
|
306
|
+
* @param params - Identifies the context: a credit manager address/state,
|
|
307
|
+
* a credit facade address/state, or a {@link VersionRange}.
|
|
308
|
+
* @returns The matching router contract instance.
|
|
309
|
+
* @throws If the credit facade version is unsupported or no router is
|
|
310
|
+
* registered for the resolved version range.
|
|
311
|
+
**/
|
|
110
312
|
routerFor(params: {
|
|
111
313
|
creditManager: Address | BaseState | IBaseContract;
|
|
112
314
|
} | {
|