@gearbox-protocol/sdk 13.3.3 → 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/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/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/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
|
@@ -33,17 +33,29 @@ import { YearnPriceFeedContract } from "./YearnPriceFeed.js";
|
|
|
33
33
|
import { ZeroPriceFeedContract } from "./ZeroPriceFeed.js";
|
|
34
34
|
class PriceFeedRegister extends SDKConstruct {
|
|
35
35
|
#hooks = new Hooks();
|
|
36
|
+
#updaters;
|
|
36
37
|
#feeds = new AddressMap(void 0, "priceFeeds");
|
|
37
38
|
#latestUpdate;
|
|
38
|
-
updaters;
|
|
39
39
|
constructor(sdk, opts = {}) {
|
|
40
40
|
super(sdk);
|
|
41
|
-
this
|
|
41
|
+
this.#updaters = [
|
|
42
42
|
new PythUpdater(sdk, opts?.pyth),
|
|
43
43
|
new RedstoneUpdater(sdk, opts?.redstone)
|
|
44
44
|
];
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
* Registers a callback for price-feed register lifecycle events.
|
|
49
|
+
* @param event - Event name.
|
|
50
|
+
* @param handler - Callback to invoke.
|
|
51
|
+
**/
|
|
46
52
|
addHook = this.#hooks.addHook.bind(this.#hooks);
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
* Removes a previously registered hook.
|
|
56
|
+
* @param event - Event name.
|
|
57
|
+
* @param handler - Callback to remove.
|
|
58
|
+
**/
|
|
47
59
|
removeHook = this.#hooks.removeHook.bind(this.#hooks);
|
|
48
60
|
/**
|
|
49
61
|
* Returns all price feeds known to sdk
|
|
@@ -52,12 +64,13 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
52
64
|
return this.#feeds.values();
|
|
53
65
|
}
|
|
54
66
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
67
|
+
* Generates transactions to push fresh off-chain prices to updatable feeds.
|
|
68
|
+
*
|
|
69
|
+
* @param priceFeeds - Top-level price feeds whose updatable dependencies
|
|
70
|
+
* will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
|
|
71
|
+
* to gather feeds from all oracles. When omitted, all registered feeds
|
|
72
|
+
* are used.
|
|
73
|
+
**/
|
|
61
74
|
async generatePriceFeedsUpdateTxs(priceFeeds) {
|
|
62
75
|
let updateables = this.#feeds.values();
|
|
63
76
|
let filterRemark = "";
|
|
@@ -78,7 +91,7 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
78
91
|
timestamp: Math.floor(Date.now() / 1e3)
|
|
79
92
|
};
|
|
80
93
|
const updates = (await Promise.all(
|
|
81
|
-
this
|
|
94
|
+
this.#updaters.map((u) => u.getUpdateTxs(updateables).catch(() => []))
|
|
82
95
|
)).flat();
|
|
83
96
|
let maxTimestamp = 0;
|
|
84
97
|
for (const tx of updates) {
|
|
@@ -128,7 +141,7 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
128
141
|
});
|
|
129
142
|
}
|
|
130
143
|
/**
|
|
131
|
-
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
|
|
144
|
+
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
|
|
132
145
|
* This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
|
|
133
146
|
* @param feeds
|
|
134
147
|
* @param block
|
|
@@ -165,12 +178,32 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
165
178
|
);
|
|
166
179
|
return getRawPriceUpdates(updates);
|
|
167
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Checks whether a price feed is already registered at the given address.
|
|
183
|
+
* @param address - On-chain address to look up.
|
|
184
|
+
**/
|
|
168
185
|
has(address) {
|
|
169
186
|
return this.#feeds.has(address);
|
|
170
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns the cached price feed contract at the given address.
|
|
190
|
+
* @param address - On-chain address to look up.
|
|
191
|
+
* @throws If no feed is registered at that address.
|
|
192
|
+
**/
|
|
171
193
|
mustGet(address) {
|
|
172
194
|
return this.#feeds.mustGet(address);
|
|
173
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Inserts or updates a price feed from a full tree node.
|
|
198
|
+
*
|
|
199
|
+
* If a fully loaded feed already exists at the same address, only the
|
|
200
|
+
* answer is refreshed. Otherwise a new contract wrapper is created and
|
|
201
|
+
* cached.
|
|
202
|
+
*
|
|
203
|
+
* @param data - Full price feed tree node from the compressor.
|
|
204
|
+
* @returns The cached (or newly created) feed instance.
|
|
205
|
+
* @throws If the created feed is only partially initialized.
|
|
206
|
+
**/
|
|
174
207
|
upsert(data) {
|
|
175
208
|
const existing = this.#feeds.get(data.baseParams.addr);
|
|
176
209
|
if (existing?.loaded) {
|
|
@@ -217,6 +250,14 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
217
250
|
);
|
|
218
251
|
return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
|
|
219
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Instantiates the appropriate price feed contract wrapper based on
|
|
255
|
+
* the `contractType` discriminator in the node's base params.
|
|
256
|
+
*
|
|
257
|
+
* @param data - Partial or full price feed tree node.
|
|
258
|
+
* @returns A new (uncached) feed contract instance.
|
|
259
|
+
* @throws If the contract type is unsupported and strict mode is enabled.
|
|
260
|
+
**/
|
|
220
261
|
create(data) {
|
|
221
262
|
const contractType = bytes32ToString(
|
|
222
263
|
data.baseParams.contractType
|
|
@@ -280,8 +321,10 @@ class PriceFeedRegister extends SDKConstruct {
|
|
|
280
321
|
});
|
|
281
322
|
}
|
|
282
323
|
/**
|
|
283
|
-
*
|
|
284
|
-
|
|
324
|
+
* @internal
|
|
325
|
+
* Diagnostic snapshot of the most recent price-update round, or
|
|
326
|
+
* `undefined` if no updates have been generated yet.
|
|
327
|
+
**/
|
|
285
328
|
get latestUpdate() {
|
|
286
329
|
return this.#latestUpdate;
|
|
287
330
|
}
|
package/dist/esm/sdk/options.js
CHANGED
|
@@ -6,50 +6,56 @@ import {
|
|
|
6
6
|
import { ZodAddress } from "./utils/index.js";
|
|
7
7
|
const SDKOptions = z.object({
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
9
|
+
* Override address of the Gearbox AddressProvider contract.
|
|
10
|
+
* If not set, uses default universal address provider address {@link ADDRESS_PROVIDER_V310}
|
|
11
|
+
**/
|
|
11
12
|
addressProvider: ZodAddress().optional(),
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
|
|
14
|
+
* Addresses of market configurator contracts to load.
|
|
15
|
+
* If not set, all default market configurators for the chain are loaded
|
|
16
|
+
* (from {@link GearboxChain.defaultMarketConfigurators})
|
|
17
|
+
**/
|
|
15
18
|
marketConfigurators: z.array(ZodAddress()).optional(),
|
|
16
19
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
20
|
+
* Pin SDK to a specific block number during attach.
|
|
21
|
+
* When set, all on-chain reads use this block instead of `latest`.
|
|
22
|
+
**/
|
|
19
23
|
blockNumber: z.union([z.bigint().nonnegative(), z.number().int().nonnegative()]).optional(),
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
25
|
+
* Skip fetching updatable price feeds on attach and sync.
|
|
26
|
+
* Speeds up initialisation when prices are not needed.
|
|
27
|
+
**/
|
|
24
28
|
ignoreUpdateablePrices: z.boolean().optional(),
|
|
25
29
|
/**
|
|
26
|
-
*
|
|
27
|
-
|
|
30
|
+
* Pool addresses whose markets should be skipped during attach/hydrate/sync.
|
|
31
|
+
**/
|
|
28
32
|
ignoreMarkets: z.array(ZodAddress()).optional(),
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
34
|
+
* When `true`, throw on unrecognised contract types instead of falling
|
|
35
|
+
* back to a generic contract wrapper.
|
|
36
|
+
**/
|
|
32
37
|
strictContractTypes: z.boolean().optional(),
|
|
33
38
|
/**
|
|
34
|
-
* Plugins
|
|
35
|
-
|
|
39
|
+
* Plugins that extend SDK functionality.
|
|
40
|
+
**/
|
|
36
41
|
plugins: z.record(z.string(), z.any()).optional(),
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
39
|
-
|
|
43
|
+
* Custom logger implementation.
|
|
44
|
+
**/
|
|
40
45
|
logger: z.any(),
|
|
41
46
|
/**
|
|
42
|
-
* Options
|
|
43
|
-
|
|
47
|
+
* Options for Redstone price-feed updates.
|
|
48
|
+
**/
|
|
44
49
|
redstone: RedstoneOptions.optional(),
|
|
45
50
|
/**
|
|
46
|
-
* Options
|
|
47
|
-
|
|
51
|
+
* Options for Pyth price-feed updates.
|
|
52
|
+
**/
|
|
48
53
|
pyth: PythOptions.optional(),
|
|
49
54
|
/**
|
|
50
|
-
* Explicit gas limit for read
|
|
51
|
-
*
|
|
52
|
-
|
|
55
|
+
* Explicit gas limit for read-only `eth_call` requests.
|
|
56
|
+
* `null` disables the gas limit entirely; `undefined` uses the SDK default.
|
|
57
|
+
* Default gas limit is 550_000_000 (550M).
|
|
58
|
+
**/
|
|
53
59
|
gasLimit: z.bigint().nonnegative().nullable().optional()
|
|
54
60
|
});
|
|
55
61
|
export {
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
class BasePlugin {
|
|
2
2
|
#sdk;
|
|
3
3
|
logger;
|
|
4
|
+
/**
|
|
5
|
+
* Plugin state version for hydration compatibility checks.
|
|
6
|
+
* @default 1
|
|
7
|
+
**/
|
|
4
8
|
version = 1;
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, state is fetched eagerly during the `attach` phase
|
|
11
|
+
* rather than waiting for an explicit `load` call.
|
|
12
|
+
**/
|
|
5
13
|
loadOnAttach;
|
|
6
14
|
constructor(loadOnAttach = false) {
|
|
7
15
|
this.loadOnAttach = loadOnAttach;
|
|
8
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Reference to the parent SDK instance.
|
|
19
|
+
* @throws Error if the SDK has not been attached yet.
|
|
20
|
+
**/
|
|
9
21
|
get sdk() {
|
|
10
22
|
if (!this.#sdk) {
|
|
11
23
|
throw new Error("SDK is not attached");
|
|
@@ -19,17 +31,29 @@ class BasePlugin {
|
|
|
19
31
|
this.#sdk = sdk;
|
|
20
32
|
this.logger = sdk.logger?.child?.({ name: this.constructor.name }) ?? sdk.logger;
|
|
21
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* {@inheritDoc IGearboxSDKPlugin.attach}
|
|
36
|
+
**/
|
|
22
37
|
async attach() {
|
|
23
38
|
if (this.loadOnAttach) {
|
|
24
39
|
await this.load(true);
|
|
25
40
|
}
|
|
26
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* {@inheritDoc IGearboxSDKPlugin.syncState}
|
|
44
|
+
**/
|
|
27
45
|
async syncState() {
|
|
28
46
|
await this.load(false);
|
|
29
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Network type of the connected chain (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
50
|
+
**/
|
|
30
51
|
get network() {
|
|
31
52
|
return this.sdk.networkType;
|
|
32
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Viem public client for read-only chain interactions.
|
|
56
|
+
**/
|
|
33
57
|
get client() {
|
|
34
58
|
return this.sdk.client;
|
|
35
59
|
}
|
|
@@ -10,6 +10,9 @@ class AbstractPoolService extends SDKConstruct {
|
|
|
10
10
|
this.#version = version;
|
|
11
11
|
this.logger?.debug(`Created PoolService with version: ${this.#version}`);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* {@inheritDoc IPoolsService.addLiquidity}
|
|
15
|
+
**/
|
|
13
16
|
addLiquidity({
|
|
14
17
|
collateral,
|
|
15
18
|
pool,
|
|
@@ -66,6 +69,9 @@ class AbstractPoolService extends SDKConstruct {
|
|
|
66
69
|
];
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc IPoolsService.removeLiquidity}
|
|
74
|
+
**/
|
|
69
75
|
removeLiquidity({
|
|
70
76
|
pool,
|
|
71
77
|
amount,
|
|
@@ -3,6 +3,9 @@ import { PERCENTAGE_FACTOR } from "../constants/math.js";
|
|
|
3
3
|
import { AddressMap, AddressSet, formatBN, isDust } from "../utils/index.js";
|
|
4
4
|
import { limitLeftover } from "./helpers.js";
|
|
5
5
|
class AbstractRouterContract extends BaseContract {
|
|
6
|
+
/**
|
|
7
|
+
* Reference to the parent SDK instance.
|
|
8
|
+
**/
|
|
6
9
|
sdk;
|
|
7
10
|
constructor(sdk, args) {
|
|
8
11
|
super(sdk, args);
|
|
@@ -65,7 +68,7 @@ class AbstractRouterContract extends BaseContract {
|
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
|
-
* Tries to sell just
|
|
71
|
+
* Tries to sell just enough of the most valuable token to cover debt.
|
|
69
72
|
* @param ca
|
|
70
73
|
* @param keepAssets
|
|
71
74
|
* @returns
|
|
@@ -18,8 +18,8 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
21
|
+
* {@inheritDoc IRouterContract.findOneTokenPath}
|
|
22
|
+
**/
|
|
23
23
|
async findOneTokenPath(props) {
|
|
24
24
|
const {
|
|
25
25
|
creditAccount,
|
|
@@ -60,8 +60,8 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
|
|
63
|
+
* {@inheritDoc IRouterContract.findOpenStrategyPath}
|
|
64
|
+
**/
|
|
65
65
|
async findOpenStrategyPath(props) {
|
|
66
66
|
const {
|
|
67
67
|
creditManager: cm,
|
|
@@ -118,8 +118,8 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
|
|
121
|
+
* {@inheritDoc IRouterContract.findClaimAllRewards}
|
|
122
|
+
**/
|
|
123
123
|
async findClaimAllRewards(props) {
|
|
124
124
|
const record = props.tokensToClaim.reduce(
|
|
125
125
|
(acc, a) => {
|
|
@@ -144,8 +144,8 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
148
|
-
|
|
147
|
+
* {@inheritDoc IRouterContract.findBestClosePath}
|
|
148
|
+
**/
|
|
149
149
|
async findBestClosePath(props) {
|
|
150
150
|
const {
|
|
151
151
|
creditAccount: ca,
|
|
@@ -210,17 +210,22 @@ class RouterV310Contract extends AbstractRouterContract {
|
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* @param
|
|
216
|
-
|
|
213
|
+
* Override the number of route splits used when swapping a specific token.
|
|
214
|
+
*
|
|
215
|
+
* @param token - Token address to configure.
|
|
216
|
+
* @param numSplits - Number of parallel route splits.
|
|
217
|
+
* @internal
|
|
218
|
+
**/
|
|
217
219
|
setNumSplits(token, numSplits) {
|
|
218
220
|
this.#numSplits.upsert(token, numSplits);
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
|
|
223
|
+
* Set the default number of route splits applied to the highest-value
|
|
224
|
+
* token in each swap.
|
|
225
|
+
*
|
|
226
|
+
* @param numSplits - Default number of parallel route splits.
|
|
227
|
+
* @internal
|
|
228
|
+
**/
|
|
224
229
|
setDefaultNumSplits(numSplits) {
|
|
225
230
|
this.#defaultNumSplits = numSplits;
|
|
226
231
|
}
|
|
@@ -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,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
estimateGas,
|
|
3
|
+
sendTransaction
|
|
4
|
+
} from "viem/actions";
|
|
2
5
|
import { getAction } from "viem/utils";
|
|
3
6
|
async function sendRawTx(client, params) {
|
|
4
7
|
const { tx, ...rest } = params;
|
|
@@ -13,6 +16,21 @@ async function sendRawTx(client, params) {
|
|
|
13
16
|
value: BigInt(tx.value)
|
|
14
17
|
});
|
|
15
18
|
}
|
|
19
|
+
async function estimateRawTxGas(client, params) {
|
|
20
|
+
const { tx, ...rest } = params;
|
|
21
|
+
return getAction(
|
|
22
|
+
client,
|
|
23
|
+
estimateGas,
|
|
24
|
+
"estimateGas"
|
|
25
|
+
)({
|
|
26
|
+
...rest,
|
|
27
|
+
account: params.account,
|
|
28
|
+
data: tx.callData,
|
|
29
|
+
to: tx.to,
|
|
30
|
+
value: BigInt(tx.value)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
16
33
|
export {
|
|
34
|
+
estimateRawTxGas,
|
|
17
35
|
sendRawTx
|
|
18
36
|
};
|