@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
|
@@ -49,17 +49,29 @@ var import_YearnPriceFeed = require("./YearnPriceFeed.js");
|
|
|
49
49
|
var import_ZeroPriceFeed = require("./ZeroPriceFeed.js");
|
|
50
50
|
class PriceFeedRegister extends import_base.SDKConstruct {
|
|
51
51
|
#hooks = new import_internal.Hooks();
|
|
52
|
+
#updaters;
|
|
52
53
|
#feeds = new import_utils.AddressMap(void 0, "priceFeeds");
|
|
53
54
|
#latestUpdate;
|
|
54
|
-
updaters;
|
|
55
55
|
constructor(sdk, opts = {}) {
|
|
56
56
|
super(sdk);
|
|
57
|
-
this
|
|
57
|
+
this.#updaters = [
|
|
58
58
|
new import_updates.PythUpdater(sdk, opts?.pyth),
|
|
59
59
|
new import_updates.RedstoneUpdater(sdk, opts?.redstone)
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
* Registers a callback for price-feed register lifecycle events.
|
|
65
|
+
* @param event - Event name.
|
|
66
|
+
* @param handler - Callback to invoke.
|
|
67
|
+
**/
|
|
62
68
|
addHook = this.#hooks.addHook.bind(this.#hooks);
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
* Removes a previously registered hook.
|
|
72
|
+
* @param event - Event name.
|
|
73
|
+
* @param handler - Callback to remove.
|
|
74
|
+
**/
|
|
63
75
|
removeHook = this.#hooks.removeHook.bind(this.#hooks);
|
|
64
76
|
/**
|
|
65
77
|
* Returns all price feeds known to sdk
|
|
@@ -68,12 +80,13 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
68
80
|
return this.#feeds.values();
|
|
69
81
|
}
|
|
70
82
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
83
|
+
* Generates transactions to push fresh off-chain prices to updatable feeds.
|
|
84
|
+
*
|
|
85
|
+
* @param priceFeeds - Top-level price feeds whose updatable dependencies
|
|
86
|
+
* will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
|
|
87
|
+
* to gather feeds from all oracles. When omitted, all registered feeds
|
|
88
|
+
* are used.
|
|
89
|
+
**/
|
|
77
90
|
async generatePriceFeedsUpdateTxs(priceFeeds) {
|
|
78
91
|
let updateables = this.#feeds.values();
|
|
79
92
|
let filterRemark = "";
|
|
@@ -94,7 +107,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
94
107
|
timestamp: Math.floor(Date.now() / 1e3)
|
|
95
108
|
};
|
|
96
109
|
const updates = (await Promise.all(
|
|
97
|
-
this
|
|
110
|
+
this.#updaters.map((u) => u.getUpdateTxs(updateables).catch(() => []))
|
|
98
111
|
)).flat();
|
|
99
112
|
let maxTimestamp = 0;
|
|
100
113
|
for (const tx of updates) {
|
|
@@ -144,7 +157,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
144
157
|
});
|
|
145
158
|
}
|
|
146
159
|
/**
|
|
147
|
-
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
|
|
160
|
+
* Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
|
|
148
161
|
* This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
|
|
149
162
|
* @param feeds
|
|
150
163
|
* @param block
|
|
@@ -181,12 +194,32 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
181
194
|
);
|
|
182
195
|
return (0, import_getRawPriceUpdates.getRawPriceUpdates)(updates);
|
|
183
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Checks whether a price feed is already registered at the given address.
|
|
199
|
+
* @param address - On-chain address to look up.
|
|
200
|
+
**/
|
|
184
201
|
has(address) {
|
|
185
202
|
return this.#feeds.has(address);
|
|
186
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns the cached price feed contract at the given address.
|
|
206
|
+
* @param address - On-chain address to look up.
|
|
207
|
+
* @throws If no feed is registered at that address.
|
|
208
|
+
**/
|
|
187
209
|
mustGet(address) {
|
|
188
210
|
return this.#feeds.mustGet(address);
|
|
189
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Inserts or updates a price feed from a full tree node.
|
|
214
|
+
*
|
|
215
|
+
* If a fully loaded feed already exists at the same address, only the
|
|
216
|
+
* answer is refreshed. Otherwise a new contract wrapper is created and
|
|
217
|
+
* cached.
|
|
218
|
+
*
|
|
219
|
+
* @param data - Full price feed tree node from the compressor.
|
|
220
|
+
* @returns The cached (or newly created) feed instance.
|
|
221
|
+
* @throws If the created feed is only partially initialized.
|
|
222
|
+
**/
|
|
190
223
|
upsert(data) {
|
|
191
224
|
const existing = this.#feeds.get(data.baseParams.addr);
|
|
192
225
|
if (existing?.loaded) {
|
|
@@ -233,6 +266,14 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
233
266
|
);
|
|
234
267
|
return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
|
|
235
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Instantiates the appropriate price feed contract wrapper based on
|
|
271
|
+
* the `contractType` discriminator in the node's base params.
|
|
272
|
+
*
|
|
273
|
+
* @param data - Partial or full price feed tree node.
|
|
274
|
+
* @returns A new (uncached) feed contract instance.
|
|
275
|
+
* @throws If the contract type is unsupported and strict mode is enabled.
|
|
276
|
+
**/
|
|
236
277
|
create(data) {
|
|
237
278
|
const contractType = (0, import_utils.bytes32ToString)(
|
|
238
279
|
data.baseParams.contractType
|
|
@@ -296,8 +337,10 @@ class PriceFeedRegister extends import_base.SDKConstruct {
|
|
|
296
337
|
});
|
|
297
338
|
}
|
|
298
339
|
/**
|
|
299
|
-
*
|
|
300
|
-
|
|
340
|
+
* @internal
|
|
341
|
+
* Diagnostic snapshot of the most recent price-update round, or
|
|
342
|
+
* `undefined` if no updates have been generated yet.
|
|
343
|
+
**/
|
|
301
344
|
get latestUpdate() {
|
|
302
345
|
return this.#latestUpdate;
|
|
303
346
|
}
|
package/dist/cjs/sdk/options.js
CHANGED
|
@@ -26,50 +26,56 @@ var import_updates = require("./market/pricefeeds/updates/index.js");
|
|
|
26
26
|
var import_utils = require("./utils/index.js");
|
|
27
27
|
const SDKOptions = import_v4.z.object({
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
|
|
29
|
+
* Override address of the Gearbox AddressProvider contract.
|
|
30
|
+
* If not set, uses default universal address provider address {@link ADDRESS_PROVIDER_V310}
|
|
31
|
+
**/
|
|
31
32
|
addressProvider: (0, import_utils.ZodAddress)().optional(),
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
|
|
34
|
+
* Addresses of market configurator contracts to load.
|
|
35
|
+
* If not set, all default market configurators for the chain are loaded
|
|
36
|
+
* (from {@link GearboxChain.defaultMarketConfigurators})
|
|
37
|
+
**/
|
|
35
38
|
marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
38
|
-
|
|
40
|
+
* Pin SDK to a specific block number during attach.
|
|
41
|
+
* When set, all on-chain reads use this block instead of `latest`.
|
|
42
|
+
**/
|
|
39
43
|
blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
45
|
+
* Skip fetching updatable price feeds on attach and sync.
|
|
46
|
+
* Speeds up initialisation when prices are not needed.
|
|
47
|
+
**/
|
|
44
48
|
ignoreUpdateablePrices: import_v4.z.boolean().optional(),
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
47
|
-
|
|
50
|
+
* Pool addresses whose markets should be skipped during attach/hydrate/sync.
|
|
51
|
+
**/
|
|
48
52
|
ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
49
53
|
/**
|
|
50
|
-
*
|
|
51
|
-
|
|
54
|
+
* When `true`, throw on unrecognised contract types instead of falling
|
|
55
|
+
* back to a generic contract wrapper.
|
|
56
|
+
**/
|
|
52
57
|
strictContractTypes: import_v4.z.boolean().optional(),
|
|
53
58
|
/**
|
|
54
|
-
* Plugins
|
|
55
|
-
|
|
59
|
+
* Plugins that extend SDK functionality.
|
|
60
|
+
**/
|
|
56
61
|
plugins: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
57
62
|
/**
|
|
58
|
-
*
|
|
59
|
-
|
|
63
|
+
* Custom logger implementation.
|
|
64
|
+
**/
|
|
60
65
|
logger: import_v4.z.any(),
|
|
61
66
|
/**
|
|
62
|
-
* Options
|
|
63
|
-
|
|
67
|
+
* Options for Redstone price-feed updates.
|
|
68
|
+
**/
|
|
64
69
|
redstone: import_updates.RedstoneOptions.optional(),
|
|
65
70
|
/**
|
|
66
|
-
* Options
|
|
67
|
-
|
|
71
|
+
* Options for Pyth price-feed updates.
|
|
72
|
+
**/
|
|
68
73
|
pyth: import_updates.PythOptions.optional(),
|
|
69
74
|
/**
|
|
70
|
-
* Explicit gas limit for read
|
|
71
|
-
*
|
|
72
|
-
|
|
75
|
+
* Explicit gas limit for read-only `eth_call` requests.
|
|
76
|
+
* `null` disables the gas limit entirely; `undefined` uses the SDK default.
|
|
77
|
+
* Default gas limit is 550_000_000 (550M).
|
|
78
|
+
**/
|
|
73
79
|
gasLimit: import_v4.z.bigint().nonnegative().nullable().optional()
|
|
74
80
|
});
|
|
75
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -24,11 +24,23 @@ module.exports = __toCommonJS(BasePlugin_exports);
|
|
|
24
24
|
class BasePlugin {
|
|
25
25
|
#sdk;
|
|
26
26
|
logger;
|
|
27
|
+
/**
|
|
28
|
+
* Plugin state version for hydration compatibility checks.
|
|
29
|
+
* @default 1
|
|
30
|
+
**/
|
|
27
31
|
version = 1;
|
|
32
|
+
/**
|
|
33
|
+
* When `true`, state is fetched eagerly during the `attach` phase
|
|
34
|
+
* rather than waiting for an explicit `load` call.
|
|
35
|
+
**/
|
|
28
36
|
loadOnAttach;
|
|
29
37
|
constructor(loadOnAttach = false) {
|
|
30
38
|
this.loadOnAttach = loadOnAttach;
|
|
31
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Reference to the parent SDK instance.
|
|
42
|
+
* @throws Error if the SDK has not been attached yet.
|
|
43
|
+
**/
|
|
32
44
|
get sdk() {
|
|
33
45
|
if (!this.#sdk) {
|
|
34
46
|
throw new Error("SDK is not attached");
|
|
@@ -42,17 +54,29 @@ class BasePlugin {
|
|
|
42
54
|
this.#sdk = sdk;
|
|
43
55
|
this.logger = sdk.logger?.child?.({ name: this.constructor.name }) ?? sdk.logger;
|
|
44
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* {@inheritDoc IGearboxSDKPlugin.attach}
|
|
59
|
+
**/
|
|
45
60
|
async attach() {
|
|
46
61
|
if (this.loadOnAttach) {
|
|
47
62
|
await this.load(true);
|
|
48
63
|
}
|
|
49
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* {@inheritDoc IGearboxSDKPlugin.syncState}
|
|
67
|
+
**/
|
|
50
68
|
async syncState() {
|
|
51
69
|
await this.load(false);
|
|
52
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Network type of the connected chain (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
73
|
+
**/
|
|
53
74
|
get network() {
|
|
54
75
|
return this.sdk.networkType;
|
|
55
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Viem public client for read-only chain interactions.
|
|
79
|
+
**/
|
|
56
80
|
get client() {
|
|
57
81
|
return this.sdk.client;
|
|
58
82
|
}
|
|
@@ -33,6 +33,9 @@ class AbstractPoolService extends import_base.SDKConstruct {
|
|
|
33
33
|
this.#version = version;
|
|
34
34
|
this.logger?.debug(`Created PoolService with version: ${this.#version}`);
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc IPoolsService.addLiquidity}
|
|
38
|
+
**/
|
|
36
39
|
addLiquidity({
|
|
37
40
|
collateral,
|
|
38
41
|
pool,
|
|
@@ -89,6 +92,9 @@ class AbstractPoolService extends import_base.SDKConstruct {
|
|
|
89
92
|
];
|
|
90
93
|
}
|
|
91
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* {@inheritDoc IPoolsService.removeLiquidity}
|
|
97
|
+
**/
|
|
92
98
|
removeLiquidity({
|
|
93
99
|
pool,
|
|
94
100
|
amount,
|
|
@@ -26,6 +26,9 @@ var import_math = require("../constants/math.js");
|
|
|
26
26
|
var import_utils = require("../utils/index.js");
|
|
27
27
|
var import_helpers = require("./helpers.js");
|
|
28
28
|
class AbstractRouterContract extends import_base.BaseContract {
|
|
29
|
+
/**
|
|
30
|
+
* Reference to the parent SDK instance.
|
|
31
|
+
**/
|
|
29
32
|
sdk;
|
|
30
33
|
constructor(sdk, args) {
|
|
31
34
|
super(sdk, args);
|
|
@@ -88,7 +91,7 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
|
-
* Tries to sell just
|
|
94
|
+
* Tries to sell just enough of the most valuable token to cover debt.
|
|
92
95
|
* @param ca
|
|
93
96
|
* @param keepAssets
|
|
94
97
|
* @returns
|
|
@@ -41,8 +41,8 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
44
|
+
* {@inheritDoc IRouterContract.findOneTokenPath}
|
|
45
|
+
**/
|
|
46
46
|
async findOneTokenPath(props) {
|
|
47
47
|
const {
|
|
48
48
|
creditAccount,
|
|
@@ -83,8 +83,8 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
|
|
86
|
+
* {@inheritDoc IRouterContract.findOpenStrategyPath}
|
|
87
|
+
**/
|
|
88
88
|
async findOpenStrategyPath(props) {
|
|
89
89
|
const {
|
|
90
90
|
creditManager: cm,
|
|
@@ -141,8 +141,8 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
145
|
-
|
|
144
|
+
* {@inheritDoc IRouterContract.findClaimAllRewards}
|
|
145
|
+
**/
|
|
146
146
|
async findClaimAllRewards(props) {
|
|
147
147
|
const record = props.tokensToClaim.reduce(
|
|
148
148
|
(acc, a) => {
|
|
@@ -167,8 +167,8 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
|
-
*
|
|
171
|
-
|
|
170
|
+
* {@inheritDoc IRouterContract.findBestClosePath}
|
|
171
|
+
**/
|
|
172
172
|
async findBestClosePath(props) {
|
|
173
173
|
const {
|
|
174
174
|
creditAccount: ca,
|
|
@@ -233,17 +233,22 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* @param
|
|
239
|
-
|
|
236
|
+
* Override the number of route splits used when swapping a specific token.
|
|
237
|
+
*
|
|
238
|
+
* @param token - Token address to configure.
|
|
239
|
+
* @param numSplits - Number of parallel route splits.
|
|
240
|
+
* @internal
|
|
241
|
+
**/
|
|
240
242
|
setNumSplits(token, numSplits) {
|
|
241
243
|
this.#numSplits.upsert(token, numSplits);
|
|
242
244
|
}
|
|
243
245
|
/**
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
|
|
246
|
+
* Set the default number of route splits applied to the highest-value
|
|
247
|
+
* token in each swap.
|
|
248
|
+
*
|
|
249
|
+
* @param numSplits - Default number of parallel route splits.
|
|
250
|
+
* @internal
|
|
251
|
+
**/
|
|
247
252
|
setDefaultNumSplits(numSplits) {
|
|
248
253
|
this.#defaultNumSplits = numSplits;
|
|
249
254
|
}
|
|
@@ -26,6 +26,10 @@ class AddressMap {
|
|
|
26
26
|
#map;
|
|
27
27
|
#frozen = false;
|
|
28
28
|
#name;
|
|
29
|
+
/**
|
|
30
|
+
* @param entries - Optional initial key-value pairs. Address strings are checksummed automatically.
|
|
31
|
+
* @param name - Optional label used in error messages when a lookup fails.
|
|
32
|
+
*/
|
|
29
33
|
constructor(entries, name) {
|
|
30
34
|
this.#map = /* @__PURE__ */ new Map();
|
|
31
35
|
if (entries) {
|
|
@@ -37,9 +41,10 @@ class AddressMap {
|
|
|
37
41
|
this.#name = name;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
|
-
* Adds or updates value
|
|
41
|
-
* @param address
|
|
42
|
-
* @param value
|
|
44
|
+
* Adds or updates a value. Passing `undefined` removes the entry.
|
|
45
|
+
* @param address - EVM address (checksummed automatically).
|
|
46
|
+
* @param value - Value to store, or `undefined` to delete the entry.
|
|
47
|
+
* @throws If the map has been {@link freeze | frozen}.
|
|
43
48
|
*/
|
|
44
49
|
upsert(address, value) {
|
|
45
50
|
if (this.#frozen) {
|
|
@@ -53,9 +58,10 @@ class AddressMap {
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @param address
|
|
58
|
-
* @param value
|
|
61
|
+
* Inserts a value, throwing if the address is already present.
|
|
62
|
+
* @param address - EVM address (checksummed automatically).
|
|
63
|
+
* @param value - Value to store.
|
|
64
|
+
* @throws If the map has been {@link freeze | frozen} or if `address` already exists.
|
|
59
65
|
*/
|
|
60
66
|
insert(address, value) {
|
|
61
67
|
if (this.#frozen) {
|
|
@@ -70,27 +76,26 @@ class AddressMap {
|
|
|
70
76
|
this.#map.set(key, value);
|
|
71
77
|
}
|
|
72
78
|
/**
|
|
73
|
-
* Checks
|
|
74
|
-
* @param address
|
|
75
|
-
* @returns
|
|
79
|
+
* Checks whether an address is present in the map.
|
|
80
|
+
* @param address - EVM address (case-insensitive).
|
|
76
81
|
*/
|
|
77
82
|
has(address) {
|
|
78
83
|
const key = (0, import_viem.getAddress)(address);
|
|
79
84
|
return this.#map.has(key);
|
|
80
85
|
}
|
|
81
86
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param address
|
|
84
|
-
* @returns
|
|
87
|
+
* Looks up a value by EVM address (case-insensitive).
|
|
88
|
+
* @param address - EVM address to look up.
|
|
89
|
+
* @returns The stored value, or `undefined` if not present.
|
|
85
90
|
*/
|
|
86
91
|
get(address) {
|
|
87
92
|
const key = (0, import_viem.getAddress)(address);
|
|
88
93
|
return this.#map.get(key);
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @param address
|
|
93
|
-
* @
|
|
96
|
+
* Looks up a value by EVM address, throwing if the address is absent.
|
|
97
|
+
* @param address - EVM address to look up.
|
|
98
|
+
* @throws If `address` is not in the map.
|
|
94
99
|
*/
|
|
95
100
|
mustGet(address) {
|
|
96
101
|
const key = (0, import_viem.getAddress)(address);
|
|
@@ -100,40 +105,71 @@ class AddressMap {
|
|
|
100
105
|
return this.#map.get(key);
|
|
101
106
|
}
|
|
102
107
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param address
|
|
108
|
+
* Removes an entry by address. No-op if the address is absent.
|
|
109
|
+
* @param address - EVM address to remove.
|
|
105
110
|
*/
|
|
106
111
|
delete(address) {
|
|
107
112
|
const key = (0, import_viem.getAddress)(address);
|
|
108
113
|
this.#map.delete(key);
|
|
109
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Removes all entries from the map.
|
|
117
|
+
**/
|
|
110
118
|
clear() {
|
|
111
119
|
this.#map.clear();
|
|
112
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns all entries as an array of `[checksummedAddress, value]` tuples.
|
|
123
|
+
**/
|
|
113
124
|
entries() {
|
|
114
125
|
return Array.from(this.#map.entries());
|
|
115
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns all values in insertion order.
|
|
129
|
+
**/
|
|
116
130
|
values() {
|
|
117
131
|
return Array.from(this.#map.values());
|
|
118
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Returns all checksummed addresses in insertion order.
|
|
135
|
+
**/
|
|
119
136
|
keys() {
|
|
120
137
|
return Array.from(this.#map.keys());
|
|
121
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Converts the map to a plain `Record<Address, T>` object.
|
|
141
|
+
**/
|
|
122
142
|
asRecord() {
|
|
123
143
|
return Object.fromEntries(this.#map.entries());
|
|
124
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Number of entries in the map.
|
|
147
|
+
**/
|
|
125
148
|
get size() {
|
|
126
149
|
return this.#map.size;
|
|
127
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Prevents further mutations. Any subsequent call to {@link upsert},
|
|
153
|
+
* {@link insert}, or {@link delete} will throw.
|
|
154
|
+
*/
|
|
128
155
|
freeze() {
|
|
129
156
|
this.#frozen = true;
|
|
130
157
|
}
|
|
131
158
|
get name() {
|
|
132
159
|
return this.#name;
|
|
133
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates an `AddressMap` from a plain record object.
|
|
163
|
+
* @param record - Object whose keys are EVM addresses.
|
|
164
|
+
*/
|
|
134
165
|
static fromRecord(record) {
|
|
135
166
|
return new AddressMap(Object.entries(record));
|
|
136
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates an `AddressMap` by extracting an address from each array element.
|
|
170
|
+
* @param array - Source items.
|
|
171
|
+
* @param mapFn - Function that returns the address key for a given item.
|
|
172
|
+
*/
|
|
137
173
|
static fromMappedArray(array, mapFn) {
|
|
138
174
|
return new AddressMap(array.map((item) => [mapFn(item), item]));
|
|
139
175
|
}
|
|
@@ -23,6 +23,9 @@ __export(AddressSet_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(AddressSet_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
class AddressSet extends Set {
|
|
26
|
+
/**
|
|
27
|
+
* @param entries - Optional initial addresses. Each is checksummed automatically.
|
|
28
|
+
*/
|
|
26
29
|
constructor(entries) {
|
|
27
30
|
super(Array.from(entries ?? []).map((a) => (0, import_viem.getAddress)(a)));
|
|
28
31
|
}
|
|
@@ -35,9 +38,15 @@ class AddressSet extends Set {
|
|
|
35
38
|
has(value) {
|
|
36
39
|
return super.has((0, import_viem.getAddress)(value));
|
|
37
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns all addresses as an array.
|
|
43
|
+
**/
|
|
38
44
|
asArray() {
|
|
39
45
|
return Array.from(this);
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Maps each address through `fn` and returns the resulting array.
|
|
49
|
+
**/
|
|
41
50
|
map(fn) {
|
|
42
51
|
return this.asArray().map(fn);
|
|
43
52
|
}
|
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var sendRawTx_exports = {};
|
|
20
20
|
__export(sendRawTx_exports, {
|
|
21
|
+
estimateRawTxGas: () => estimateRawTxGas,
|
|
21
22
|
sendRawTx: () => sendRawTx
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(sendRawTx_exports);
|
|
@@ -36,7 +37,22 @@ async function sendRawTx(client, params) {
|
|
|
36
37
|
value: BigInt(tx.value)
|
|
37
38
|
});
|
|
38
39
|
}
|
|
40
|
+
async function estimateRawTxGas(client, params) {
|
|
41
|
+
const { tx, ...rest } = params;
|
|
42
|
+
return (0, import_utils.getAction)(
|
|
43
|
+
client,
|
|
44
|
+
import_actions.estimateGas,
|
|
45
|
+
"estimateGas"
|
|
46
|
+
)({
|
|
47
|
+
...rest,
|
|
48
|
+
account: params.account,
|
|
49
|
+
data: tx.callData,
|
|
50
|
+
to: tx.to,
|
|
51
|
+
value: BigInt(tx.value)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
39
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
55
|
0 && (module.exports = {
|
|
56
|
+
estimateRawTxGas,
|
|
41
57
|
sendRawTx
|
|
42
58
|
});
|