keyring-agent-core 0.3.4 → 0.3.6
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/index.d.ts +1034 -278
- package/dist/index.js +248 -107
- package/dist/index.native.js +372 -231
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,20 @@ declare function clampTick(tick: number): number;
|
|
|
35
35
|
* Shared types for swap/bridge service providers.
|
|
36
36
|
*/
|
|
37
37
|
type ProviderName = 'debridge' | 'relay';
|
|
38
|
+
/**
|
|
39
|
+
* Why a swap is happening — this, not the chain alone, decides which config
|
|
40
|
+
* API picks the provider. See {@link file://./routing.ts}.
|
|
41
|
+
*
|
|
42
|
+
* 'pool' — internal native→token legs for add-liquidity (coinpool config).
|
|
43
|
+
* 'userSwap' — user-facing swap / buy (keyringV2 setting, like the app).
|
|
44
|
+
*/
|
|
45
|
+
type SwapRoute = 'pool' | 'userSwap';
|
|
46
|
+
/** Input to provider resolution. `dstChainId` defaults to `srcChainId`. */
|
|
47
|
+
interface SwapRouteRequest {
|
|
48
|
+
route: SwapRoute;
|
|
49
|
+
srcChainId?: number | string | null;
|
|
50
|
+
dstChainId?: number | string | null;
|
|
51
|
+
}
|
|
38
52
|
interface SwapQuoteParams {
|
|
39
53
|
srcChainId: number | string;
|
|
40
54
|
srcTokenAddress: string;
|
|
@@ -50,7 +64,12 @@ interface SwapQuoteParams {
|
|
|
50
64
|
*/
|
|
51
65
|
slippage?: number | 'auto';
|
|
52
66
|
isCrossChain?: boolean;
|
|
53
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Which route this quote serves. Decides WHICH affiliate config the adapter
|
|
69
|
+
* reads — the two are not interchangeable, see
|
|
70
|
+
* {@link file://./KeyringSettingApi.ts}. Defaults to `'userSwap'`.
|
|
71
|
+
*/
|
|
72
|
+
route?: SwapRoute;
|
|
54
73
|
}
|
|
55
74
|
interface SwapTxData {
|
|
56
75
|
from?: string;
|
|
@@ -61,6 +80,17 @@ interface SwapTxData {
|
|
|
61
80
|
};
|
|
62
81
|
value?: string;
|
|
63
82
|
chainId?: number | string;
|
|
83
|
+
/**
|
|
84
|
+
* Gas the provider estimated for THIS transaction, when it reports one.
|
|
85
|
+
*
|
|
86
|
+
* Carried because the fee that sizes a spend is `gasPrice × gasLimit`, and the
|
|
87
|
+
* app prefers the quote's own gas over a fixed default (its `gasLimitRawTx`) —
|
|
88
|
+
* a multi-hop route costs more than the 1M fallback, and reserving the
|
|
89
|
+
* fallback for it leaves a "Max" the swap cannot pay for. Dropping it here is
|
|
90
|
+
* why the agent could only ever price the default; the app's own adapter has
|
|
91
|
+
* always kept it (`RelayAdapter.js`).
|
|
92
|
+
*/
|
|
93
|
+
gas?: string | number;
|
|
64
94
|
maxFeePerGas?: string;
|
|
65
95
|
maxPriorityFeePerGas?: string;
|
|
66
96
|
}
|
|
@@ -85,25 +115,49 @@ interface CheckApprovalParams {
|
|
|
85
115
|
tokenDecimals: number;
|
|
86
116
|
quoteData: SwapQuoteResult;
|
|
87
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* One unsigned ERC-20 approval transaction, ready to sign and broadcast as-is.
|
|
120
|
+
*
|
|
121
|
+
* A swap can need MORE THAN ONE of these, in order. The case that forces it is
|
|
122
|
+
* a token whose `approve` refuses to overwrite a non-zero allowance — USDT on
|
|
123
|
+
* Ethereum being the canonical one, which reverts on
|
|
124
|
+
* `require(!((_value != 0) && (allowed[owner][spender] != 0)))`. Raising such an
|
|
125
|
+
* allowance takes two transactions: `approve(spender, 0)`, then
|
|
126
|
+
* `approve(spender, amount)`. Relay already returns both as two separate
|
|
127
|
+
* `approve` steps in a single quote; the deBridge path builds the same pair
|
|
128
|
+
* itself. See `CheckApprovalResult.approvals`.
|
|
129
|
+
*/
|
|
130
|
+
interface ApprovalTx {
|
|
131
|
+
to?: string;
|
|
132
|
+
from?: string;
|
|
133
|
+
data?: string;
|
|
134
|
+
value?: string;
|
|
135
|
+
chainId?: number | string;
|
|
136
|
+
gas?: string | number;
|
|
137
|
+
maxFeePerGas?: string;
|
|
138
|
+
maxPriorityFeePerGas?: string;
|
|
139
|
+
}
|
|
88
140
|
interface CheckApprovalResult {
|
|
89
141
|
isNeeded: boolean;
|
|
90
142
|
integrated?: boolean;
|
|
91
143
|
contractAddress?: string;
|
|
144
|
+
/**
|
|
145
|
+
* EVERY approval transaction this swap needs, in the order they must be sent.
|
|
146
|
+
* Usually one; two when a standing allowance has to be zeroed first (see
|
|
147
|
+
* `ApprovalTx`). Empty/absent when `isNeeded` is false.
|
|
148
|
+
*
|
|
149
|
+
* Callers MUST run all of them — taking only the first sends the zeroing
|
|
150
|
+
* approve and then a swap with no allowance, which reverts.
|
|
151
|
+
*/
|
|
152
|
+
approvals?: ApprovalTx[];
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated The FIRST entry of `approvals`, kept so existing callers keep
|
|
155
|
+
* compiling. It is NOT sufficient on its own — read `approvals` instead.
|
|
156
|
+
*/
|
|
92
157
|
approvalData?: unknown;
|
|
93
158
|
message?: string;
|
|
94
159
|
error?: string;
|
|
95
160
|
}
|
|
96
|
-
interface ExecuteSwapParams {
|
|
97
|
-
quoteData: SwapQuoteResult;
|
|
98
|
-
}
|
|
99
|
-
interface ExecuteSwapResult {
|
|
100
|
-
success: boolean;
|
|
101
|
-
provider?: ProviderName;
|
|
102
|
-
txData?: SwapTxData;
|
|
103
|
-
steps?: unknown[];
|
|
104
|
-
estimation?: Record<string, unknown>;
|
|
105
|
-
error?: string;
|
|
106
|
-
}
|
|
107
161
|
interface TrackTransactionParams {
|
|
108
162
|
requestIdOrTxHash: string;
|
|
109
163
|
}
|
|
@@ -113,26 +167,37 @@ interface TrackTransactionResult {
|
|
|
113
167
|
status: TrackStatus;
|
|
114
168
|
error?: string;
|
|
115
169
|
}
|
|
116
|
-
interface
|
|
170
|
+
interface SwapProviderConfig {
|
|
117
171
|
apiBaseUrl?: string;
|
|
118
172
|
apiKey?: string;
|
|
119
173
|
accessToken?: string;
|
|
120
174
|
}
|
|
121
|
-
type
|
|
175
|
+
type SwapProviderConfigMap = Record<ProviderName, SwapProviderConfig>;
|
|
122
176
|
|
|
123
177
|
/**
|
|
124
178
|
* Abstract base for swap/bridge providers. Each adapter must implement the five
|
|
125
179
|
* methods below; the factory wires the active provider based on chain config.
|
|
126
180
|
*/
|
|
127
|
-
declare abstract class
|
|
128
|
-
protected readonly config:
|
|
129
|
-
protected constructor(config:
|
|
181
|
+
declare abstract class BaseSwapProvider {
|
|
182
|
+
protected readonly config: SwapProviderConfig;
|
|
183
|
+
protected constructor(config: SwapProviderConfig);
|
|
130
184
|
abstract getProviderName(): ProviderName;
|
|
185
|
+
/**
|
|
186
|
+
* A view of this adapter that serves `route` — every quote it produces
|
|
187
|
+
* defaults to that route, so callers need not repeat it on each `getQuote`.
|
|
188
|
+
*
|
|
189
|
+
* Returns a lightweight delegating wrapper rather than mutating `this`:
|
|
190
|
+
* adapters are cached and shared per provider by the factory, so the SAME
|
|
191
|
+
* instance serves both routes concurrently. Storing the route as state would
|
|
192
|
+
* let one route's quote read the other route's affiliate config.
|
|
193
|
+
*
|
|
194
|
+
* An explicit `route` on the quote params still wins.
|
|
195
|
+
*/
|
|
196
|
+
withRoute(route: SwapRoute): BaseSwapProvider;
|
|
131
197
|
/** True when approval is delivered as part of the quote (e.g. Relay). */
|
|
132
|
-
hasIntegratedApproval(): boolean;
|
|
198
|
+
abstract hasIntegratedApproval(): boolean;
|
|
133
199
|
abstract getQuote(params: SwapQuoteParams): Promise<SwapQuoteResult>;
|
|
134
200
|
abstract checkApproval(params: CheckApprovalParams): Promise<CheckApprovalResult>;
|
|
135
|
-
abstract executeSwap(params: ExecuteSwapParams): Promise<ExecuteSwapResult>;
|
|
136
201
|
abstract trackTransaction(params: TrackTransactionParams): Promise<TrackTransactionResult>;
|
|
137
202
|
}
|
|
138
203
|
|
|
@@ -141,10 +206,10 @@ declare abstract class BaseSwapService {
|
|
|
141
206
|
* uses /dln/order/create-tx. Approval is NOT integrated — caller must check
|
|
142
207
|
* on-chain allowance against `tx.to` separately.
|
|
143
208
|
*/
|
|
144
|
-
declare class
|
|
209
|
+
declare class DebridgeProvider extends BaseSwapProvider {
|
|
145
210
|
private readonly apiBaseUrl;
|
|
146
211
|
private readonly accessToken;
|
|
147
|
-
constructor(config?:
|
|
212
|
+
constructor(config?: SwapProviderConfig);
|
|
148
213
|
getProviderName(): ProviderName;
|
|
149
214
|
hasIntegratedApproval(): boolean;
|
|
150
215
|
getQuote(params: SwapQuoteParams): Promise<SwapQuoteResult>;
|
|
@@ -155,6 +220,11 @@ declare class DebridgeAdapter extends BaseSwapService {
|
|
|
155
220
|
* on-chain `allowance(userAddress, spender)` and only flag `isNeeded` when the
|
|
156
221
|
* current allowance is below `amount` (no redundant approve when already set).
|
|
157
222
|
*
|
|
223
|
+
* `approvals` carries the transactions to send, in order. It is usually one
|
|
224
|
+
* `approve(spender, amount)`, but a token that refuses to overwrite a non-zero
|
|
225
|
+
* allowance (USDT on Ethereum) needs its allowance zeroed first, so it is two.
|
|
226
|
+
* See `buildApprovals` for how that is detected without a token list.
|
|
227
|
+
*
|
|
158
228
|
* `amount` is the spend in the token's smallest units (wei-equivalent), the
|
|
159
229
|
* same value passed as `srcTokenAmount` to the quote.
|
|
160
230
|
*/
|
|
@@ -166,79 +236,467 @@ declare class DebridgeAdapter extends BaseSwapService {
|
|
|
166
236
|
* (`0xdd62ed3e`) + two 32-byte-padded addresses.
|
|
167
237
|
*/
|
|
168
238
|
private readAllowance;
|
|
169
|
-
executeSwap(params: ExecuteSwapParams): Promise<ExecuteSwapResult>;
|
|
170
239
|
trackTransaction(params: TrackTransactionParams): Promise<TrackTransactionResult>;
|
|
171
240
|
private get;
|
|
172
241
|
}
|
|
173
242
|
|
|
174
243
|
/**
|
|
175
|
-
* Relay.link adapter. Relay bundles approval + swap into a single quote
|
|
176
|
-
*
|
|
244
|
+
* Relay.link adapter. Relay bundles approval + swap into a single quote, so
|
|
245
|
+
* `hasIntegratedApproval` is true.
|
|
246
|
+
*
|
|
247
|
+
* The approval part is a LIST, not a single step: `steps` carries one `approve`
|
|
248
|
+
* entry per approval transaction the swap needs, followed by the
|
|
249
|
+
* `swap`/`deposit` step. Most tokens produce one; a token that refuses to
|
|
250
|
+
* overwrite a non-zero allowance (USDT on Ethereum) produces two — an
|
|
251
|
+
* `approve(spender, 0)` and then the real `approve(spender, amount)` — and both
|
|
252
|
+
* must be sent, in order. Picking only the first sends the zeroing approve and
|
|
253
|
+
* then swaps against an allowance of 0, which reverts.
|
|
177
254
|
*/
|
|
178
|
-
declare class
|
|
255
|
+
declare class RelayProvider extends BaseSwapProvider {
|
|
179
256
|
private readonly apiBaseUrl;
|
|
180
257
|
private readonly apiKey?;
|
|
181
|
-
constructor(config?:
|
|
258
|
+
constructor(config?: SwapProviderConfig);
|
|
182
259
|
getProviderName(): ProviderName;
|
|
183
260
|
hasIntegratedApproval(): boolean;
|
|
184
261
|
getQuote(params: SwapQuoteParams): Promise<SwapQuoteResult>;
|
|
262
|
+
/**
|
|
263
|
+
* Relay decides the approvals itself and ships them in the quote, so this
|
|
264
|
+
* reads them back rather than probing the chain. Every `approve` step becomes
|
|
265
|
+
* one entry of `approvals`, in quote order — two of them when the pay token
|
|
266
|
+
* needs its allowance zeroed first.
|
|
267
|
+
*/
|
|
185
268
|
checkApproval(params: CheckApprovalParams): Promise<CheckApprovalResult>;
|
|
186
|
-
executeSwap(params: ExecuteSwapParams): Promise<ExecuteSwapResult>;
|
|
187
269
|
trackTransaction(params: TrackTransactionParams): Promise<TrackTransactionResult>;
|
|
188
270
|
private request;
|
|
189
271
|
}
|
|
190
272
|
|
|
191
273
|
/**
|
|
192
|
-
*
|
|
274
|
+
* The coinpool platform config: deployed contract addresses, and the
|
|
275
|
+
* chain→provider map that routes add-liquidity swap legs.
|
|
276
|
+
*
|
|
277
|
+
* This is coinpool's OWN source of truth, separate from the keyringV2
|
|
278
|
+
* setting ({@link file://./KeyringV2SettingService.ts}) that user-facing swaps
|
|
279
|
+
* read. The two must not be merged — see {@link file://./SwapRouter.ts}.
|
|
280
|
+
*
|
|
281
|
+
* Both payloads are effectively static (contract deployments and their routing),
|
|
282
|
+
* so they are cached for the lifetime of the process.
|
|
283
|
+
*/
|
|
284
|
+
declare class CoinpoolConfigApi {
|
|
285
|
+
private readonly addresses;
|
|
286
|
+
private readonly providerMap;
|
|
287
|
+
constructor(addressesUrl?: string, providerMapUrl?: string);
|
|
288
|
+
/**
|
|
289
|
+
* The provider coinpool assigns to `chainId`, or null when the API is
|
|
290
|
+
* unreachable or the chain has no mapping (caller falls back to a default).
|
|
291
|
+
*/
|
|
292
|
+
getProviderByChain(chainId: number | string): Promise<ProviderName | null>;
|
|
293
|
+
/** The add-liquidity gateway (`createPoolProxyV3`) for `chainId`. */
|
|
294
|
+
getGatewayAddress(chainId: string): Promise<string | undefined>;
|
|
295
|
+
/** The Uniswap NFT position manager for `chainId`. */
|
|
296
|
+
getPositionManagerAddress(chainId: string): Promise<string | undefined>;
|
|
297
|
+
/**
|
|
298
|
+
* Decimal chain ids that have an add-liquidity gateway configured. Empty when
|
|
299
|
+
* the config isn't loaded yet — callers treat that as "nothing supported".
|
|
300
|
+
*/
|
|
301
|
+
getGatewayChains(): Promise<string[]>;
|
|
302
|
+
private getAddress;
|
|
303
|
+
private listChainsWithAddress;
|
|
304
|
+
/** Entries are either a bare address or a list; the first is canonical. */
|
|
305
|
+
private firstAddress;
|
|
306
|
+
/** Accepts a hex ("0x2105") or decimal chain id; returns its decimal key. */
|
|
307
|
+
private toDecimalChainKey;
|
|
308
|
+
private isProviderName;
|
|
309
|
+
}
|
|
310
|
+
/** Shared instance — the config is global and immutable. */
|
|
311
|
+
declare const coinpoolConfigApi: CoinpoolConfigApi;
|
|
312
|
+
|
|
313
|
+
interface AffiliateFee {
|
|
314
|
+
affiliateFeeRecipient: string;
|
|
315
|
+
affiliateFeePercent: number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The Keyring exchange admin setting — the source of truth the APP uses for
|
|
319
|
+
* user-facing swaps.
|
|
320
|
+
*
|
|
321
|
+
* It answers two independent questions, both served from one cached fetch:
|
|
322
|
+
*
|
|
323
|
+
* 1. Routing — {@link getBridgeProvider}, a port of the app's
|
|
324
|
+
* `useGetSettingExchange` + the `bridgeProvider` memo in
|
|
325
|
+
* `useGetRawTxExchange`.
|
|
326
|
+
* 2. Affiliate fees — {@link getAffiliateFee}, applied by adapters on EVERY
|
|
327
|
+
* route, including coinpool-routed pool legs.
|
|
328
|
+
*
|
|
329
|
+
* Distinct from {@link file://./CoinpoolConfigApi.ts}, which is coinpool's
|
|
330
|
+
* own config. Keeping them apart is deliberate.
|
|
331
|
+
*/
|
|
332
|
+
declare class KeyringSettingApi {
|
|
333
|
+
private readonly setting;
|
|
334
|
+
private readonly chainSupport;
|
|
335
|
+
constructor(settingUrl?: string);
|
|
336
|
+
/**
|
|
337
|
+
* The provider for a swap, exactly like the app resolves it:
|
|
338
|
+
*
|
|
339
|
+
* 1. `keyringV2.bridgeProvider` is the default route for every pair.
|
|
340
|
+
* 2. A pair overrides to deBridge when either side is in deBridge's
|
|
341
|
+
* `requireChain` AND both sides are supported by deBridge.
|
|
342
|
+
* 3. Anything unreachable falls back to {@link DEFAULT_PROVIDER}.
|
|
343
|
+
*
|
|
344
|
+
* `dstChainId` defaults to `srcChainId` (same-chain swap). Chain ids may be
|
|
345
|
+
* hex (`0x2105`) or decimal.
|
|
346
|
+
*/
|
|
347
|
+
getBridgeProvider(srcChainId: number | string | null | undefined, dstChainId?: number | string | null): Promise<ProviderName>;
|
|
348
|
+
/**
|
|
349
|
+
* The affiliate fee to attach to a quote, or null when none should be (missing
|
|
350
|
+
* recipient or a non-positive percent).
|
|
351
|
+
*
|
|
352
|
+
* The two routes read DIFFERENT parts of this payload, and must keep doing so:
|
|
353
|
+
*
|
|
354
|
+
* `'userSwap'` — the `keyringV2` block, exactly like the app's
|
|
355
|
+
* `getMoreDataSwap` ({@link resolveKeyringV2Fee}).
|
|
356
|
+
* `'pool'` — the legacy top-level keys, which is what the pool gateway
|
|
357
|
+
* has always been paid through ({@link resolveLegacyFee}).
|
|
358
|
+
*
|
|
359
|
+
* Defaults to `'userSwap'`, matching {@link SwapQuoteParams.route}.
|
|
360
|
+
*/
|
|
361
|
+
getAffiliateFee(provider: ProviderName, chainId: number | string, route?: SwapRoute): Promise<AffiliateFee | null>;
|
|
362
|
+
/**
|
|
363
|
+
* Route `'pool'` — the legacy top-level keys.
|
|
364
|
+
*
|
|
365
|
+
* deBridge keys its recipient per chain inside the `affiliateRecipient` JSON
|
|
366
|
+
* string; Relay uses one flat recipient + percent pair.
|
|
367
|
+
*/
|
|
368
|
+
private resolveLegacyFee;
|
|
369
|
+
/**
|
|
370
|
+
* Route `'userSwap'` — the `keyringV2` block, a direct port of the app's
|
|
371
|
+
* `getSettingAffiliate` (`SwapServices/{Debridge,Relay}Adapter.js`).
|
|
372
|
+
*
|
|
373
|
+
* Both fields are keyed on the provider ACTUALLY serving the quote, matching
|
|
374
|
+
* the app's adapters — each reads its own `PLATFORM_EXCHANGE` key rather than
|
|
375
|
+
* the setting's default `bridgeProvider`. That distinction is load-bearing:
|
|
376
|
+
* `requireChain` can route a pair to deBridge while `bridgeProvider` still
|
|
377
|
+
* says relay, and the fee must follow the provider that gets paid.
|
|
378
|
+
*
|
|
379
|
+
* percent = provider.affiliateFeePercentCustom[chainId]
|
|
380
|
+
* || provider.affiliateFeePercent
|
|
381
|
+
* || 0
|
|
382
|
+
*
|
|
383
|
+
* recipient = provider.affiliateRecipientCustom[chainId]
|
|
384
|
+
* || keyringV2.affiliateRecipientDefault
|
|
385
|
+
*
|
|
386
|
+
* The app treats 0 / '' as "not set" at every level (`||`), so this does too.
|
|
387
|
+
* Note the app has a final `|| AFFILIATE_FEE_RECIPIENT` env fallback that the
|
|
388
|
+
* core has no equivalent for; with no recipient configured we attach no fee.
|
|
389
|
+
*/
|
|
390
|
+
private resolveKeyringV2Fee;
|
|
391
|
+
/** Legacy `affiliateRecipient` is a JSON *string* keyed by chain id. */
|
|
392
|
+
private parseRecipientMap;
|
|
393
|
+
/** Fetches both providers' supported chains; one failing must not sink the other. */
|
|
394
|
+
private fetchChainSupport;
|
|
395
|
+
private requireChainKeys;
|
|
396
|
+
private normalizeProvider;
|
|
397
|
+
/** Accepts a hex (`0x2105`) or decimal chain id and returns its decimal string. */
|
|
398
|
+
private toChainKey;
|
|
399
|
+
private toPercent;
|
|
400
|
+
}
|
|
401
|
+
/** Shared instance — the setting is global. */
|
|
402
|
+
declare const keyringSettingApi: KeyringSettingApi;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Abstract base for swap routers.
|
|
406
|
+
*
|
|
407
|
+
* A router answers ONE question: which provider (deBridge / Relay) should serve
|
|
408
|
+
* this swap? Each concrete router owns a different source of truth, and they are
|
|
409
|
+
* deliberately kept apart — see {@link PoolSwapRouter} and
|
|
410
|
+
* {@link UserSwapRouter}.
|
|
411
|
+
*
|
|
412
|
+
* Subclasses implement {@link resolveProvider}; the base wraps it in
|
|
413
|
+
* {@link resolve}, which guarantees a usable provider even when the underlying
|
|
414
|
+
* config API fails. Routing sits on the critical path of a swap the user is
|
|
415
|
+
* waiting on, so a config outage must degrade to {@link DEFAULT_PROVIDER}
|
|
416
|
+
* rather than surface as an error.
|
|
417
|
+
*
|
|
418
|
+
* Affiliate fees are NOT a routing concern: they come from the Keyring setting
|
|
419
|
+
* on EVERY route, including coinpool-routed pool legs. Adapters read them
|
|
420
|
+
* directly ({@link file://./KeyringSettingApi.ts}).
|
|
421
|
+
*/
|
|
422
|
+
declare abstract class SwapRouter {
|
|
423
|
+
/** The route this router serves. Used as its key in the registry. */
|
|
424
|
+
abstract readonly route: SwapRoute;
|
|
425
|
+
/**
|
|
426
|
+
* Resolves the provider for `request`. May throw or return null — the caller
|
|
427
|
+
* is {@link resolve}, which supplies the fallback.
|
|
428
|
+
*/
|
|
429
|
+
protected abstract resolveProvider(request: SwapRouteRequest): Promise<ProviderName | null>;
|
|
430
|
+
/**
|
|
431
|
+
* The provider for `request`. Never throws: any failure inside
|
|
432
|
+
* {@link resolveProvider} degrades to {@link DEFAULT_PROVIDER}.
|
|
433
|
+
*/
|
|
434
|
+
resolve(request: SwapRouteRequest): Promise<ProviderName>;
|
|
435
|
+
/**
|
|
436
|
+
* Normalizes a chain id to a finite number, or null when absent/unparseable.
|
|
437
|
+
* Shared by subclasses so every router treats chain ids alike.
|
|
438
|
+
*/
|
|
439
|
+
protected toNumericChainId(chainId: number | string | null | undefined): number | null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Route `'pool'` — the native→token legs add-liquidity mixes before minting.
|
|
443
|
+
*
|
|
444
|
+
* Reads the coinpool config (`bridgeProviderByChain`), keyed on the source chain
|
|
445
|
+
* ALONE: these legs are always same-chain, so there is no pair to consider. This
|
|
446
|
+
* is the historical behaviour and the pool gateway is deployed against it, so it
|
|
447
|
+
* stays as-is.
|
|
448
|
+
*/
|
|
449
|
+
declare class PoolSwapRouter extends SwapRouter {
|
|
450
|
+
private readonly config;
|
|
451
|
+
readonly route: "pool";
|
|
452
|
+
constructor(config?: CoinpoolConfigApi);
|
|
453
|
+
protected resolveProvider({ srcChainId }: SwapRouteRequest): Promise<ProviderName | null>;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Route `'userSwap'` — a user-facing swap or buy.
|
|
193
457
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
458
|
+
* Routed exactly like the Keyring app: the `keyringV2` admin setting's
|
|
459
|
+
* `bridgeProvider` is the default, overridden to deBridge when either side of
|
|
460
|
+
* the pair is in deBridge's `requireChain` and both sides support it. Uses BOTH
|
|
461
|
+
* chain ids because it is cross-chain aware.
|
|
197
462
|
*/
|
|
198
|
-
declare class
|
|
199
|
-
private readonly
|
|
200
|
-
|
|
463
|
+
declare class UserSwapRouter extends SwapRouter {
|
|
464
|
+
private readonly setting;
|
|
465
|
+
readonly route: "userSwap";
|
|
466
|
+
constructor(setting?: KeyringSettingApi);
|
|
467
|
+
protected resolveProvider({ srcChainId, dstChainId }: SwapRouteRequest): Promise<ProviderName | null>;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Holds one {@link SwapRouter} per route and dispatches a request to the right
|
|
472
|
+
* one.
|
|
473
|
+
*
|
|
474
|
+
* Routers self-declare the route they serve, so adding a route never touches
|
|
475
|
+
* the dispatch logic below.
|
|
476
|
+
*/
|
|
477
|
+
declare class SwapRouterRegistry {
|
|
478
|
+
private readonly routers;
|
|
479
|
+
constructor(routers?: readonly SwapRouter[]);
|
|
480
|
+
/**
|
|
481
|
+
* Resolves the provider for `request` via its route's router.
|
|
482
|
+
*
|
|
483
|
+
* Never throws. Routers already degrade to {@link DEFAULT_PROVIDER} on config
|
|
484
|
+
* failure; the guard here covers an unknown `route` arriving from untyped JS,
|
|
485
|
+
* so a bad route picks the default provider instead of crashing a swap the
|
|
486
|
+
* user is waiting on.
|
|
487
|
+
*/
|
|
488
|
+
resolveProvider(request: SwapRouteRequest): Promise<ProviderName>;
|
|
489
|
+
}
|
|
490
|
+
/** Shared registry backing the default {@link file://./SwapProviderFactory.ts} singleton. */
|
|
491
|
+
declare const swapRouterRegistry: SwapRouterRegistry;
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Builds (and caches) the adapter for a swap.
|
|
495
|
+
*
|
|
496
|
+
* Callers state WHY they are swapping — the `route` — and the factory delegates
|
|
497
|
+
* to the matching {@link file://./SwapRouter.ts}. Two routes exist and they read
|
|
498
|
+
* different config sources on purpose:
|
|
499
|
+
*
|
|
500
|
+
* `{ route: 'pool' }` → coinpool `bridgeProviderByChain` (add-liquidity legs)
|
|
501
|
+
* `{ route: 'userSwap' }` → keyringV2 `bridgeProvider` (user swap / buy, like the app)
|
|
502
|
+
*
|
|
503
|
+
* Adapters are stateless, so one instance per provider is shared process-wide.
|
|
504
|
+
*/
|
|
505
|
+
declare class SwapProviderFactory {
|
|
506
|
+
/**
|
|
507
|
+
* An EXPLICIT config override, or undefined to read the module default.
|
|
508
|
+
*
|
|
509
|
+
* Deliberately not defaulted in the constructor: `config.ts` imports this
|
|
510
|
+
* module for `swapProviderFactory` while this module imports
|
|
511
|
+
* `SWAP_PROVIDER_CONFIG` from it, and in the bundled build the singleton below
|
|
512
|
+
* is constructed BEFORE that const is assigned. A default parameter would
|
|
513
|
+
* therefore capture `undefined` for the life of the process, and every
|
|
514
|
+
* `createService` would fault on it. Reading the binding lazily in
|
|
515
|
+
* {@link providers} sidesteps the cycle: by the time a quote is taken, the
|
|
516
|
+
* module has finished evaluating.
|
|
517
|
+
*/
|
|
518
|
+
private readonly configOverride?;
|
|
519
|
+
private readonly routersOverride?;
|
|
201
520
|
private readonly cache;
|
|
202
|
-
constructor(providerConfig?:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
521
|
+
constructor(providerConfig?: SwapProviderConfigMap, routers?: SwapRouterRegistry);
|
|
522
|
+
/** Connection config in force — an injected map, else the module default. */
|
|
523
|
+
private get providers();
|
|
524
|
+
/** Router registry in force — same lazy read, same cycle. */
|
|
525
|
+
private get routers();
|
|
526
|
+
/**
|
|
527
|
+
* The adapter for a swap, chosen by its route, with that route already bound
|
|
528
|
+
* to it. Never throws on config failure — routing degrades to the default
|
|
529
|
+
* provider.
|
|
530
|
+
*
|
|
531
|
+
* The returned service applies `request.route` to every quote, so callers
|
|
532
|
+
* state the route ONCE here rather than repeating it on each `getQuote`.
|
|
533
|
+
*/
|
|
534
|
+
getService(request: SwapRouteRequest): Promise<BaseSwapProvider>;
|
|
535
|
+
/**
|
|
536
|
+
* The adapter for an ALREADY-resolved provider. Use this to stay on the
|
|
537
|
+
* provider that produced a quote (approval and execution must not re-route
|
|
538
|
+
* mid-flight); use {@link getService} to start a new swap.
|
|
539
|
+
*/
|
|
540
|
+
getServiceByProvider(provider: ProviderName): BaseSwapProvider;
|
|
541
|
+
/**
|
|
542
|
+
* Discards the cached adapters so the next call rebuilds them from the
|
|
543
|
+
* CURRENT provider config. Needed when connection config (an API key) is
|
|
544
|
+
* installed after an adapter has already been handed out.
|
|
545
|
+
*/
|
|
546
|
+
resetCache(): void;
|
|
547
|
+
/** The provider a route resolves to, without building the adapter. */
|
|
548
|
+
resolveProvider(request: SwapRouteRequest): Promise<ProviderName>;
|
|
209
549
|
private createService;
|
|
210
550
|
}
|
|
211
|
-
/** Default singleton. */
|
|
212
|
-
declare const
|
|
551
|
+
/** Default singleton (production endpoints). */
|
|
552
|
+
declare const swapProviderFactory: SwapProviderFactory;
|
|
213
553
|
|
|
214
554
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
555
|
+
* Connection-level config (base URLs, tokens) for each swap provider.
|
|
556
|
+
*
|
|
557
|
+
* WHICH provider serves a given swap is decided at runtime by the routers
|
|
558
|
+
* ({@link file://./SwapRouter.ts}); this map only says how to reach each one.
|
|
218
559
|
*/
|
|
219
|
-
declare const SWAP_PROVIDER_CONFIG:
|
|
560
|
+
declare const SWAP_PROVIDER_CONFIG: SwapProviderConfigMap;
|
|
220
561
|
declare const DEFAULT_PROVIDER: ProviderName;
|
|
562
|
+
/**
|
|
563
|
+
* Installs connection-level overrides for a provider — the host app's API key
|
|
564
|
+
* for Relay, say — before the first quote is taken.
|
|
565
|
+
*
|
|
566
|
+
* Adapters are built once and cached per provider, so this ALSO drops the
|
|
567
|
+
* factory's cache: an adapter constructed before the key arrived would keep
|
|
568
|
+
* sending unauthenticated requests for the life of the process.
|
|
569
|
+
*/
|
|
570
|
+
declare function configureSwapProvider(name: ProviderName, cfg: Partial<SwapProviderConfig>): void;
|
|
221
571
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
572
|
+
/**
|
|
573
|
+
* A single remote value, fetched at most once per TTL and shared by every
|
|
574
|
+
* concurrent caller.
|
|
575
|
+
*
|
|
576
|
+
* Three config sources in this module needed the same thing — a lazy load, a
|
|
577
|
+
* single-flight guard so parallel tool calls don't stampede the API, and a
|
|
578
|
+
* failure mode that never rejects. Each had grown its own copy of that logic;
|
|
579
|
+
* this is the one implementation they all use.
|
|
580
|
+
*
|
|
581
|
+
* On failure {@link get} resolves to the last known value, or null if it never
|
|
582
|
+
* loaded. Callers therefore always receive a value or null and never an
|
|
583
|
+
* exception — routing and address lookups sit on the critical path of a user's
|
|
584
|
+
* swap, so a config outage must degrade rather than throw.
|
|
585
|
+
*/
|
|
586
|
+
declare class CachedResource<T> {
|
|
587
|
+
private readonly loader;
|
|
588
|
+
private readonly ttlMs;
|
|
589
|
+
private value;
|
|
590
|
+
private loadedAt;
|
|
591
|
+
private inFlight;
|
|
592
|
+
/**
|
|
593
|
+
* @param loader Fetches a fresh value. May throw; failures are absorbed.
|
|
594
|
+
* @param ttlMs How long a loaded value stays fresh. Omit (or `Infinity`) to
|
|
595
|
+
* cache for the lifetime of the process — right for values that are
|
|
596
|
+
* effectively static, like deployed contract addresses.
|
|
597
|
+
*/
|
|
598
|
+
constructor(loader: () => Promise<T | null>, ttlMs?: number);
|
|
599
|
+
/** The cached value, loading it first if missing or stale. Never throws. */
|
|
600
|
+
get(): Promise<T | null>;
|
|
225
601
|
}
|
|
602
|
+
|
|
226
603
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
604
|
+
* Reading a quote's provider-specific shape.
|
|
605
|
+
*
|
|
606
|
+
* Every adapter answers with its own JSON under `raw`, so the two facts callers
|
|
607
|
+
* actually want — how much comes out, and why it failed — sit at a different
|
|
608
|
+
* path per provider. These helpers own that mapping.
|
|
609
|
+
*
|
|
610
|
+
* They live in the swap module rather than in a tool because BOTH the agent's
|
|
611
|
+
* tools and the app's in-chat amount form quote through `swapProviderFactory`
|
|
612
|
+
* and must read the result identically: an estimate the form derived one way and
|
|
613
|
+
* the confirm card derived another would show the user two different numbers for
|
|
614
|
+
* one trade.
|
|
615
|
+
*/
|
|
616
|
+
/**
|
|
617
|
+
* Estimated receive amount in the destination token's smallest units, or
|
|
618
|
+
* `undefined` when the quote reports none.
|
|
619
|
+
*
|
|
620
|
+
* Shape differs per provider — deBridge same-chain: `raw.tokenOut.minAmount`;
|
|
621
|
+
* deBridge cross-chain: `raw.estimation.dstChainTokenOut.amount`; Relay:
|
|
622
|
+
* `raw.details.currencyOut.{amount|minimumAmount}`. Anything that isn't a run of
|
|
623
|
+
* digits is rejected rather than passed on: these are smallest-unit integers, and
|
|
624
|
+
* a decimal or an e-notation string here would be scaled by the token's decimals
|
|
625
|
+
* a second time downstream.
|
|
230
626
|
*/
|
|
231
|
-
declare function
|
|
627
|
+
declare function extractOutRaw(quote: SwapQuoteResult): string | undefined;
|
|
232
628
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
629
|
+
* A human-readable failure reason from a failed quote. Adapters set
|
|
630
|
+
* `errorMessage` (string) and `error` (string or a provider object); deBridge
|
|
631
|
+
* also nests a reason in `raw.errorMessage` / `raw.error`. Always returns
|
|
632
|
+
* something, so the caller has a line to show.
|
|
633
|
+
*/
|
|
634
|
+
declare function extractQuoteError(quote: SwapQuoteResult): string;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* The fixed native protocol fee (in WEI) a swap on `srcChainId` will be charged,
|
|
638
|
+
* or `0n` when none applies.
|
|
639
|
+
*
|
|
640
|
+
* Mirrors `useProtocolFee` exactly, including its failure mode: the hook wraps
|
|
641
|
+
* the whole read in a try/catch returning '0', so an unreachable RPC or a chain
|
|
642
|
+
* without the contract degrades to "no fee" rather than blocking the user. Never
|
|
643
|
+
* throws.
|
|
644
|
+
*
|
|
645
|
+
* `dstChainId` defaults to `srcChainId`, i.e. a same-chain swap, which is the
|
|
646
|
+
* case that returns `0n`.
|
|
235
647
|
*/
|
|
236
|
-
declare function
|
|
648
|
+
declare function readProtocolFeeWei(input: {
|
|
649
|
+
provider: ProviderName;
|
|
650
|
+
srcChainId: number | string | null | undefined;
|
|
651
|
+
dstChainId?: number | string | null | undefined;
|
|
652
|
+
}): Promise<bigint>;
|
|
237
653
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
654
|
+
/**
|
|
655
|
+
* Building the ERC-20 approval leg of a swap, for providers that do NOT bundle
|
|
656
|
+
* it themselves (deBridge). Relay ships its own approve steps in the quote and
|
|
657
|
+
* does not come through here — see `RelayProvider.checkApproval`.
|
|
658
|
+
*
|
|
659
|
+
* The reason this is more than one `encodeFunctionData` call: some ERC-20s
|
|
660
|
+
* refuse to overwrite a NON-ZERO allowance. USDT on Ethereum is the canonical
|
|
661
|
+
* one — its `approve` carries
|
|
662
|
+
*
|
|
663
|
+
* require(!((_value != 0) && (allowed[msg.sender][_spender] != 0)));
|
|
664
|
+
*
|
|
665
|
+
* so raising a standing allowance reverts, and the allowance has to be zeroed
|
|
666
|
+
* first. Others of the same 2017-2018 vintage (KNC, OMG, the old ERC-20 BNB)
|
|
667
|
+
* do the same. Which is why this is decided by BEHAVIOUR, not by a hard-coded
|
|
668
|
+
* token list: the chain is asked whether `approve(spender, amount)` would
|
|
669
|
+
* succeed as things stand, and only when it would not is the zeroing approve
|
|
670
|
+
* prepended. A list would miss every token nobody has reported yet.
|
|
671
|
+
*/
|
|
672
|
+
/** `approve(spender, value)` calldata for an ERC-20. */
|
|
673
|
+
declare function encodeApprove(spender: string, value: bigint): string;
|
|
674
|
+
interface BuildApprovalsParams {
|
|
675
|
+
/** Undefined when the caller has no chain to probe on — see below. */
|
|
676
|
+
chain?: string;
|
|
677
|
+
token: string;
|
|
678
|
+
owner: string;
|
|
679
|
+
spender: string;
|
|
680
|
+
/** The spend, in the token's smallest units. */
|
|
681
|
+
amount: bigint;
|
|
682
|
+
/** Current allowance, when the caller has already read it. */
|
|
683
|
+
allowance?: bigint | null;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Every approval transaction needed to let `spender` pull `amount`, in order.
|
|
687
|
+
*
|
|
688
|
+
* - `[]` when the standing allowance already covers the spend.
|
|
689
|
+
* - `[approve(amount)]` in the ordinary case.
|
|
690
|
+
* - `[approve(0), approve(amount)]` when a non-zero allowance is in the way and
|
|
691
|
+
* the token will not let it be overwritten.
|
|
692
|
+
*
|
|
693
|
+
* The zeroing leg is only added when there IS something to zero, so a first-time
|
|
694
|
+
* approval is never charged for two transactions. When the probe cannot reach a
|
|
695
|
+
* verdict the single approve is returned unchanged: that is what every earlier
|
|
696
|
+
* build did, and guessing "reset" on an unreadable RPC would spend the user's
|
|
697
|
+
* gas on a transaction that is very probably unnecessary.
|
|
698
|
+
*/
|
|
699
|
+
declare function buildApprovals({ chain, token, owner, spender, amount, allowance, }: BuildApprovalsParams): Promise<ApprovalTx[]>;
|
|
242
700
|
|
|
243
701
|
declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
244
702
|
interface NativeTokenInfo {
|
|
@@ -260,18 +718,10 @@ interface ChainMeta {
|
|
|
260
718
|
declare function getChainMeta(chainId: string): ChainMeta | undefined;
|
|
261
719
|
declare function getNativeTokenInfo(chainId: string): NativeTokenInfo | undefined;
|
|
262
720
|
interface PoolServiceConfig {
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
* `isProduction` flag (defaults to the prod singleton when true).
|
|
266
|
-
*/
|
|
267
|
-
swapFactory?: SwapServiceFactory;
|
|
721
|
+
/** Optional swap factory override. Defaults to the shared singleton. */
|
|
722
|
+
swapFactory?: SwapProviderFactory;
|
|
268
723
|
/** Pantograph URL for native price lookups. Default: https://pantograph.keyring.app */
|
|
269
724
|
pantographUrl?: string;
|
|
270
|
-
/**
|
|
271
|
-
* Whether to hit production endpoints for addresses + bridge-provider config.
|
|
272
|
-
* Default true.
|
|
273
|
-
*/
|
|
274
|
-
isProduction?: boolean;
|
|
275
725
|
}
|
|
276
726
|
interface TransactionReceiptLog {
|
|
277
727
|
address?: string;
|
|
@@ -333,7 +783,6 @@ interface PoolOnchainInfo {
|
|
|
333
783
|
}
|
|
334
784
|
declare class PoolService {
|
|
335
785
|
private swapFactory;
|
|
336
|
-
private isProduction;
|
|
337
786
|
constructor(config?: PoolServiceConfig);
|
|
338
787
|
/**
|
|
339
788
|
* True when this service has on-chain pool support (RPC + gateway config) for
|
|
@@ -462,9 +911,10 @@ declare class PoolService {
|
|
|
462
911
|
* Fetches a single-leg same-chain swap quote (native → token) used to mix
|
|
463
912
|
* the user's native input into pool token0 / token1 before minting.
|
|
464
913
|
*
|
|
465
|
-
* Provider is picked by `
|
|
466
|
-
*
|
|
467
|
-
* normalised: `{ to, data, value, minAmountOut }`, regardless of
|
|
914
|
+
* Provider is picked by `SwapProviderFactory` on the `'pool'` route: the
|
|
915
|
+
* coinpool `bridgeProviderByChain` config, keyed on the chain id. The return
|
|
916
|
+
* shape is normalised: `{ to, data, value, minAmountOut }`, regardless of
|
|
917
|
+
* provider.
|
|
468
918
|
*
|
|
469
919
|
* Throws on failure; caller decides whether to surface or skip.
|
|
470
920
|
*/
|
|
@@ -1091,71 +1541,64 @@ interface BuyTokenSide {
|
|
|
1091
1541
|
amount?: string;
|
|
1092
1542
|
/** Amount in the token's smallest unit (wei-equivalent), as a decimal string. */
|
|
1093
1543
|
rawAmount?: string;
|
|
1544
|
+
/**
|
|
1545
|
+
* Token logo URL, when the balance/metadata source reported one. Display only
|
|
1546
|
+
* — the FE falls back to a generic token icon when it is absent, so nothing
|
|
1547
|
+
* depends on it being set.
|
|
1548
|
+
*/
|
|
1549
|
+
logo?: string;
|
|
1094
1550
|
}
|
|
1095
1551
|
/**
|
|
1096
|
-
* Props for the FE `
|
|
1097
|
-
* BuyTokenTool
|
|
1098
|
-
* spend amount.
|
|
1552
|
+
* Props for the FE `SwapTokenForm` component — the ONE payload SwapTokenTool and
|
|
1553
|
+
* BuyTokenTool ship, and the only UI either of them emits.
|
|
1099
1554
|
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
* a
|
|
1555
|
+
* Sent as soon as both sides of the trade are resolved, whether or not the user
|
|
1556
|
+
* named an amount: named, it arrives as `initialAmount` and the form opens
|
|
1557
|
+
* pre-filled; unnamed, the form opens empty. Either way the amount stays
|
|
1558
|
+
* editable and the FE quotes it.
|
|
1559
|
+
*
|
|
1560
|
+
* This replaced two things at once: percentage action-buttons that spent a full
|
|
1561
|
+
* agent turn per tap, and a separately-quoted confirm card. Both were the same
|
|
1562
|
+
* trade at different stages, and neither let the user change the amount without
|
|
1563
|
+
* another round-trip through the model.
|
|
1564
|
+
*
|
|
1565
|
+
* The FE quotes by calling `swapProviderFactory` directly: the core is imported
|
|
1566
|
+
* IN-PROCESS by the app, so the adapters the tools once used are already
|
|
1567
|
+
* reachable. It must quote with `route: 'userSwap'` and `isCrossChain: false` —
|
|
1568
|
+
* the route decides which affiliate config applies, so another route would price
|
|
1569
|
+
* a different trade.
|
|
1570
|
+
*
|
|
1571
|
+
* `fromToken.rawAmount` carries the SPENDABLE balance in smallest units — for a
|
|
1572
|
+
* native source that is already NET of the gas reserve, so "100%" can never
|
|
1573
|
+
* leave the user unable to pay for the swap. The FE derives every percentage
|
|
1574
|
+
* from it with `mulDivFloor` (exported from the core alongside these types):
|
|
1575
|
+
* float math on a balance rounds UP and trips a false "insufficient balance".
|
|
1107
1576
|
*/
|
|
1108
|
-
interface
|
|
1577
|
+
interface SwapTokenFormProps {
|
|
1109
1578
|
chain: ChainRef;
|
|
1110
|
-
/**
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
estimatedOut?: string;
|
|
1116
|
-
/** Estimated receive amount of buyToken in smallest units, when available. */
|
|
1117
|
-
estimatedOutRaw?: string;
|
|
1118
|
-
/** Swap provider that produced the quote (e.g. "debridge", "relay"). */
|
|
1119
|
-
provider?: string;
|
|
1120
|
-
/** Raw swap transaction the FE signs + broadcasts. */
|
|
1121
|
-
swapTx: UnsignedTx;
|
|
1122
|
-
/**
|
|
1123
|
-
* Raw ERC-20 approve transaction to run BEFORE the swap. Present only when an
|
|
1124
|
-
* allowance is required (native pay token or sufficient allowance ⇒ omitted).
|
|
1125
|
-
*/
|
|
1126
|
-
approveTx?: UnsignedTx;
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Props for the FE `SwapTokenConfirmTx` component — the single data cube the
|
|
1130
|
-
* SwapTokenTool ships once the user has supplied a SOURCE token they hold,
|
|
1131
|
-
* a destination token, and a source amount.
|
|
1132
|
-
*
|
|
1133
|
-
* Mechanically identical to {@link BuyTokenConfirmTxProps} (deBridge EXACT_INPUT
|
|
1134
|
-
* quote → raw swap tx → optional approve), but the framing is "swap FROM a token
|
|
1135
|
-
* I already hold TO another token": `fromToken` is the user's held source token
|
|
1136
|
-
* (always balance-checked) and `toToken` is what they receive. Like buy, this is
|
|
1137
|
-
* NOT a wallet-action form payload — SwapTokenTool emits its own UI component, so
|
|
1138
|
-
* `swap_token` is intentionally NOT a member of WalletActionType.
|
|
1139
|
-
*/
|
|
1140
|
-
interface SwapTokenConfirmTxProps {
|
|
1141
|
-
chain: ChainRef;
|
|
1142
|
-
/** Token the user spends (the source they already hold). */
|
|
1579
|
+
/**
|
|
1580
|
+
* The token being spent. `rawAmount` is the spendable balance (smallest
|
|
1581
|
+
* units, gas reserve already deducted for native); `amount` is the same
|
|
1582
|
+
* figure human-readable. Carries no chosen amount — that is what the form asks for.
|
|
1583
|
+
*/
|
|
1143
1584
|
fromToken: BuyTokenSide;
|
|
1144
|
-
/**
|
|
1585
|
+
/** The token being received. Has no amount until the form quotes one. */
|
|
1145
1586
|
toToken: BuyTokenSide;
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
|
|
1150
|
-
/** Swap provider that produced the quote (e.g. "debridge", "relay"). */
|
|
1151
|
-
provider?: string;
|
|
1152
|
-
/** Raw swap transaction the FE signs + broadcasts. */
|
|
1153
|
-
swapTx: UnsignedTx;
|
|
1587
|
+
/** Wallet the swap is quoted and signed for (sender and recipient). */
|
|
1588
|
+
walletAddress: string;
|
|
1589
|
+
/** 'swap' when the user started from a token they hold, 'buy' when from the destination. */
|
|
1590
|
+
intent: 'swap' | 'buy';
|
|
1154
1591
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1592
|
+
* Amount the user already named ("swap 10 USDC to USDT"), pre-filled into the
|
|
1593
|
+
* field and quoted on sight. Absent when they named no amount, leaving the
|
|
1594
|
+
* field empty for them to size.
|
|
1595
|
+
*
|
|
1596
|
+
* This is what lets ONE form serve both cases. The amount is still fully
|
|
1597
|
+
* editable — a named amount is a starting point, not a commitment — and it is
|
|
1598
|
+
* already validated against the spendable balance by the tool, so the form
|
|
1599
|
+
* never opens pre-filled with more than the user can spend.
|
|
1157
1600
|
*/
|
|
1158
|
-
|
|
1601
|
+
initialAmount?: string;
|
|
1159
1602
|
}
|
|
1160
1603
|
/** Human-readable summary of an add-liquidity tx, shown above the Confirm button. */
|
|
1161
1604
|
interface AddLiquiditySummary {
|
|
@@ -1458,6 +1901,19 @@ interface AgentConfig {
|
|
|
1458
1901
|
* is not listed simply uses those built-in and catalogue endpoints.
|
|
1459
1902
|
*/
|
|
1460
1903
|
rpcUrls?: Record<string, string>;
|
|
1904
|
+
/**
|
|
1905
|
+
* Connection-level config for the swap providers, keyed by provider name —
|
|
1906
|
+
* currently the host app's Relay API key. Installed before any swap tool
|
|
1907
|
+
* runs, so quotes taken through the agent carry the same key (rate limits,
|
|
1908
|
+
* attribution) as the ones the app takes directly.
|
|
1909
|
+
*
|
|
1910
|
+
* Omit it and the providers fall back to their built-in public endpoints.
|
|
1911
|
+
*/
|
|
1912
|
+
swapProviders?: Partial<Record<'debridge' | 'relay', {
|
|
1913
|
+
apiKey?: string;
|
|
1914
|
+
apiBaseUrl?: string;
|
|
1915
|
+
accessToken?: string;
|
|
1916
|
+
}>>;
|
|
1461
1917
|
/**
|
|
1462
1918
|
* Restrict which of the built-in supported chains are active by REMOVING the
|
|
1463
1919
|
* listed ones. Each entry is a {@link ChainSelector} — the chain's canonical
|
|
@@ -1620,11 +2076,6 @@ interface AgentConfig {
|
|
|
1620
2076
|
searchBaseUrl?: string;
|
|
1621
2077
|
/** Minimum USD value the user must supply to add liquidity. Default 10. */
|
|
1622
2078
|
minProvideUsd?: number;
|
|
1623
|
-
/**
|
|
1624
|
-
* Hit production endpoints (coinpool.app) for addresses + bridge-provider
|
|
1625
|
-
* mapping. Set false for staging. Default true.
|
|
1626
|
-
*/
|
|
1627
|
-
isProduction?: boolean;
|
|
1628
2079
|
} | false;
|
|
1629
2080
|
/**
|
|
1630
2081
|
* Tools that must NOT open a form in this deployment, mapped to the message
|
|
@@ -1845,6 +2296,22 @@ declare class Subagent {
|
|
|
1845
2296
|
interface RewriteResult {
|
|
1846
2297
|
/** True if the user message depends on prior turns (pronoun, ellipsis, confirmation, continuation). */
|
|
1847
2298
|
isFollowUp: boolean;
|
|
2299
|
+
/**
|
|
2300
|
+
* The model's SEMANTIC judgement of the latest message read in isolation:
|
|
2301
|
+
* does it state both an action and what that action applies to, so a reader
|
|
2302
|
+
* with zero access to prior turns understands it?
|
|
2303
|
+
*
|
|
2304
|
+
* This is the primitive `isFollowUp` and `topicChanged` are derived from.
|
|
2305
|
+
* Asking for it separately is what makes the pair reliable: the model used to
|
|
2306
|
+
* answer "is this a follow-up?" by pattern-matching topical similarity to the
|
|
2307
|
+
* previous turn, so a self-contained new intent that reused a token from the
|
|
2308
|
+
* previous turn ("buy usdc" during an add-liquidity flow) came back as a
|
|
2309
|
+
* follow-up and inherited context it never asked for. "Does this sentence
|
|
2310
|
+
* stand alone?" is a question about the sentence only, which the model
|
|
2311
|
+
* answers far more consistently — and it cannot be approximated with a word
|
|
2312
|
+
* list, since the same short reply is elliptical or not depending on meaning.
|
|
2313
|
+
*/
|
|
2314
|
+
selfContained: boolean;
|
|
1848
2315
|
/**
|
|
1849
2316
|
* The fully-resolved, self-contained version of the user query in the user's
|
|
1850
2317
|
* language. Equal to the original message when `isFollowUp` is false.
|
|
@@ -7457,10 +7924,7 @@ interface CoinPoolPairSummary {
|
|
|
7457
7924
|
}
|
|
7458
7925
|
type SubgraphSort = 'tvl' | 'volume' | 'apr' | 'fee' | 'liquidity';
|
|
7459
7926
|
|
|
7460
|
-
type TopPoolsToolConfig = UniswapServiceConfig
|
|
7461
|
-
/** Hit production addresses endpoints (for add-liquidity gateway lookup). Default true. */
|
|
7462
|
-
isProduction?: boolean;
|
|
7463
|
-
};
|
|
7927
|
+
type TopPoolsToolConfig = UniswapServiceConfig;
|
|
7464
7928
|
/**
|
|
7465
7929
|
* Tool: get-top-pools
|
|
7466
7930
|
*
|
|
@@ -7528,10 +7992,7 @@ interface CoinPoolServiceConfig {
|
|
|
7528
7992
|
coinPoolBaseUrl?: string;
|
|
7529
7993
|
}
|
|
7530
7994
|
|
|
7531
|
-
type PoolDetailToolConfig = UniswapServiceConfig
|
|
7532
|
-
/** Hit production addresses endpoints (for add-liquidity gateway lookup). Default true. */
|
|
7533
|
-
isProduction?: boolean;
|
|
7534
|
-
};
|
|
7995
|
+
type PoolDetailToolConfig = UniswapServiceConfig;
|
|
7535
7996
|
/**
|
|
7536
7997
|
* Tool: get-pool-detail
|
|
7537
7998
|
*
|
|
@@ -7588,10 +8049,7 @@ declare class PoolDetailTool extends BaseTool {
|
|
|
7588
8049
|
private fetchPriceRanges;
|
|
7589
8050
|
}
|
|
7590
8051
|
|
|
7591
|
-
type PoolSearchToolConfig = UniswapServiceConfig
|
|
7592
|
-
/** Hit production addresses endpoints (for add-liquidity gateway lookup). Default true. */
|
|
7593
|
-
isProduction?: boolean;
|
|
7594
|
-
};
|
|
8052
|
+
type PoolSearchToolConfig = UniswapServiceConfig;
|
|
7595
8053
|
/**
|
|
7596
8054
|
* Tool: search-pools
|
|
7597
8055
|
*
|
|
@@ -7620,10 +8078,7 @@ interface PoolHistoricalVolumePoint {
|
|
|
7620
8078
|
volumeUsd?: number;
|
|
7621
8079
|
}
|
|
7622
8080
|
|
|
7623
|
-
type PoolByAddressToolConfig = UniswapServiceConfig
|
|
7624
|
-
/** Hit production addresses endpoints (for add-liquidity gateway lookup). Default true. */
|
|
7625
|
-
isProduction?: boolean;
|
|
7626
|
-
};
|
|
8081
|
+
type PoolByAddressToolConfig = UniswapServiceConfig;
|
|
7627
8082
|
/**
|
|
7628
8083
|
* Tool: lookup-pool-by-address
|
|
7629
8084
|
*
|
|
@@ -8534,22 +8989,39 @@ declare class SubgraphAddPoolTool extends BaseTool {
|
|
|
8534
8989
|
}
|
|
8535
8990
|
|
|
8536
8991
|
/**
|
|
8537
|
-
*
|
|
8992
|
+
* The transaction-fee model for wallet-action tools — the exchange screen's
|
|
8993
|
+
* `feeGas`, ported so the agent sizes a spend exactly like the app does.
|
|
8994
|
+
*
|
|
8995
|
+
* The app computes one figure and uses it for three decisions
|
|
8996
|
+
* (`Exchange/index.js`):
|
|
8997
|
+
*
|
|
8998
|
+
* feeGas = gasPrice × gasLimit + protocolFee
|
|
8538
8999
|
*
|
|
8539
|
-
*
|
|
8540
|
-
*
|
|
8541
|
-
* is
|
|
9000
|
+
* 1. "Max" on a NATIVE spend is `balance − feeGas`.
|
|
9001
|
+
* 2. A spend is rejected when `amountIn > balance − feeGas`.
|
|
9002
|
+
* 3. Any spend is rejected when the wallet's NATIVE balance is `≤ feeGas` —
|
|
9003
|
+
* including an ERC-20 spend, which still needs native to pay its own gas.
|
|
8542
9004
|
*
|
|
8543
|
-
*
|
|
8544
|
-
* - buy / swap: gasLimit 1_000_000 (a router call + possible approval).
|
|
9005
|
+
* Each term matches the app:
|
|
8545
9006
|
*
|
|
8546
|
-
*
|
|
8547
|
-
*
|
|
8548
|
-
*
|
|
8549
|
-
*
|
|
8550
|
-
*
|
|
8551
|
-
*
|
|
9007
|
+
* - `gasPrice` is read live via `eth_gasPrice` against the chain's RPC (a
|
|
9008
|
+
* caller-supplied override when configured, else the chain's default).
|
|
9009
|
+
* - `gasLimit` prefers the QUOTE's own gas (`tx.gas`, or deBridge's
|
|
9010
|
+
* `estimatedTransactionFee.details.gasLimit`) and floors it at the default —
|
|
9011
|
+
* the app's `gasLimitRawTx` memo. Without a quote the default stands:
|
|
9012
|
+
* - send native: 30_000 (a plain value transfer)
|
|
9013
|
+
* - buy / swap: 1_000_000 (a router call + possible approval), the same
|
|
9014
|
+
* number as the app's `DEFAULT_GAS_LIMIT`.
|
|
9015
|
+
* - `protocolFee` is deBridge's fixed native order fee, non-zero only on a
|
|
9016
|
+
* CROSS-CHAIN deBridge route — see {@link readProtocolFeeWei}.
|
|
9017
|
+
*
|
|
9018
|
+
* Best-effort and SILENT throughout: when a term can't be read (RPC error,
|
|
9019
|
+
* unknown chain) it contributes `0n`, so the user degrades to a larger spendable
|
|
9020
|
+
* rather than being blocked by an outage. The one thing never guessed upward is
|
|
9021
|
+
* the reserve itself — an overstated reserve would falsely reject a legitimate
|
|
9022
|
+
* "100%".
|
|
8552
9023
|
*/
|
|
9024
|
+
|
|
8553
9025
|
/** Gas limits per native action kind (matches the FE's tx builders). */
|
|
8554
9026
|
declare const NATIVE_GAS_LIMIT: {
|
|
8555
9027
|
readonly send: 30000n;
|
|
@@ -8557,6 +9029,137 @@ declare const NATIVE_GAS_LIMIT: {
|
|
|
8557
9029
|
readonly swap: 1000000n;
|
|
8558
9030
|
};
|
|
8559
9031
|
type NativeActionKind = keyof typeof NATIVE_GAS_LIMIT;
|
|
9032
|
+
/**
|
|
9033
|
+
* The gas limit to price the reserve at: the QUOTE's own gas when it reports
|
|
9034
|
+
* one, floored at the kind's default — the app's `gasLimitRawTx`.
|
|
9035
|
+
*
|
|
9036
|
+
* The floor is what makes this safe in both directions. A quote reporting MORE
|
|
9037
|
+
* than the default (a multi-hop route) raises the reserve, which the fixed
|
|
9038
|
+
* default used to understate; a quote reporting less — or none — cannot lower it
|
|
9039
|
+
* below the default and shrink the reserve on a route that may still need an
|
|
9040
|
+
* approval on top.
|
|
9041
|
+
*/
|
|
9042
|
+
declare function resolveGasLimit(kind: NativeActionKind, quoteGas?: QuoteGas): bigint;
|
|
9043
|
+
/**
|
|
9044
|
+
* The gas figures a provider quote may carry. Structural rather than tied to
|
|
9045
|
+
* `SwapQuoteResult`, so a caller can pass the raw quote, its `raw` payload, or
|
|
9046
|
+
* a hand-built object without a cast.
|
|
9047
|
+
*/
|
|
9048
|
+
interface QuoteGas {
|
|
9049
|
+
tx?: {
|
|
9050
|
+
gas?: string | number | bigint | null;
|
|
9051
|
+
} | null;
|
|
9052
|
+
estimatedTransactionFee?: {
|
|
9053
|
+
details?: {
|
|
9054
|
+
gasLimit?: string | number | bigint | null;
|
|
9055
|
+
} | null;
|
|
9056
|
+
} | null;
|
|
9057
|
+
}
|
|
9058
|
+
/** Everything the fee model needs beyond the chain and the action kind. */
|
|
9059
|
+
interface FeeContext {
|
|
9060
|
+
/** The quote being sized, when one has been taken — supplies the real gas limit. */
|
|
9061
|
+
quoteGas?: QuoteGas;
|
|
9062
|
+
/** Provider serving the swap; only deBridge charges a fixed protocol fee. */
|
|
9063
|
+
provider?: ProviderName;
|
|
9064
|
+
/** Destination chain. Defaults to the source chain (same-chain swap → no protocol fee). */
|
|
9065
|
+
dstChainId?: number | string | null;
|
|
9066
|
+
}
|
|
9067
|
+
/**
|
|
9068
|
+
* The full transaction fee (in wei) for an action of `kind` on `chainId` —
|
|
9069
|
+
* `gasPrice × gasLimit + protocolFee`, the app's `feeGas`.
|
|
9070
|
+
*
|
|
9071
|
+
* This is the ONE figure to reserve, to compare a spend against, and to check
|
|
9072
|
+
* the native balance against. Returns `0n` only when the gas price is unreadable
|
|
9073
|
+
* AND no protocol fee applies. Never throws.
|
|
9074
|
+
*/
|
|
9075
|
+
declare function estimateTransactionFeeWei(chainId: string, kind: NativeActionKind, context?: FeeContext): Promise<bigint>;
|
|
9076
|
+
/**
|
|
9077
|
+
* Estimate the native gas reserve (in wei) to set aside for a transaction of
|
|
9078
|
+
* the given kind on `chainId`. Returns `0n` when the gas price can't be read
|
|
9079
|
+
* from any endpoint — the caller then treats the full balance as spendable.
|
|
9080
|
+
* Never throws.
|
|
9081
|
+
*
|
|
9082
|
+
* Thin alias for {@link estimateTransactionFeeWei}, kept because "the reserve
|
|
9083
|
+
* withheld from a native balance" and "the fee the transaction costs" are the
|
|
9084
|
+
* same number and must never drift apart.
|
|
9085
|
+
*/
|
|
9086
|
+
declare function estimateNativeGasReserveWei(chainId: string, kind: NativeActionKind, context?: FeeContext): Promise<bigint>;
|
|
9087
|
+
/**
|
|
9088
|
+
* Given a native balance (human token units) and a gas reserve (wei), return the
|
|
9089
|
+
* spendable balance in the SAME human units: `balance − gasReserve`, floored at
|
|
9090
|
+
* 0. Uses the chain's native decimals to convert the wei reserve. When decimals
|
|
9091
|
+
* are unknown the reserve is ignored (returns the full balance).
|
|
9092
|
+
*/
|
|
9093
|
+
declare function spendableNative(balanceNum: number, gasReserveWei: bigint, chainId: string): number;
|
|
9094
|
+
/**
|
|
9095
|
+
* Convert a wei fee to the chain's native units, or `null` when the chain's
|
|
9096
|
+
* decimals are unknown (the caller then has no figure to compare and skips the
|
|
9097
|
+
* check rather than inventing one).
|
|
9098
|
+
*/
|
|
9099
|
+
declare function feeWeiToNative(feeWei: bigint, chainId: string): number | null;
|
|
9100
|
+
/**
|
|
9101
|
+
* How much MORE native coin the wallet needs before the transaction can pay its
|
|
9102
|
+
* own fee, or `null` when it already has enough.
|
|
9103
|
+
*
|
|
9104
|
+
* This is the app's `minBalanceAddToSwap` — `feeGas − balanceNative`, floored at
|
|
9105
|
+
* 0 — and it exists for the case a native-only reserve cannot express: spending
|
|
9106
|
+
* an ERC-20 still burns NATIVE gas, so a wallet holding plenty of USDC and no ETH
|
|
9107
|
+
* passes every balance check on the token being spent and then fails on chain.
|
|
9108
|
+
* The exchange screen blocks that case up front ("You need {amount} {item} to
|
|
9109
|
+
* swap"); before this, the agent opened the form and let the user find out at
|
|
9110
|
+
* signing time.
|
|
9111
|
+
*
|
|
9112
|
+
* Mirrors the app's `>=` comparison, so a balance exactly equal to the fee counts
|
|
9113
|
+
* as insufficient: spending it all would leave nothing for the next block's price
|
|
9114
|
+
* movement. Returns `null` when the fee is 0 or unresolvable, which keeps an RPC
|
|
9115
|
+
* outage from blocking a user who may well have enough.
|
|
9116
|
+
*/
|
|
9117
|
+
declare function nativeGasShortfall(input: {
|
|
9118
|
+
/** The wallet's NATIVE balance, in native units. */
|
|
9119
|
+
nativeBalance: number;
|
|
9120
|
+
/** The fee the transaction will cost, from {@link estimateTransactionFeeWei}. */
|
|
9121
|
+
feeWei: bigint;
|
|
9122
|
+
chainId: string;
|
|
9123
|
+
}): number | null;
|
|
9124
|
+
/** What a failed affordability check reports, all in native units. */
|
|
9125
|
+
interface NativeGasGap {
|
|
9126
|
+
/** How much more native coin the wallet needs. */
|
|
9127
|
+
shortfall: number;
|
|
9128
|
+
/** Native coin symbol, for the message ("you need 0.0012 ETH"). */
|
|
9129
|
+
nativeSymbol: string;
|
|
9130
|
+
/** The fee the transaction is expected to cost. */
|
|
9131
|
+
fee: number;
|
|
9132
|
+
}
|
|
9133
|
+
/**
|
|
9134
|
+
* Whether the wallet can pay this action's transaction fee at all, and if not,
|
|
9135
|
+
* how much native coin it is short.
|
|
9136
|
+
*
|
|
9137
|
+
* The gas reserve alone does not cover this. It is subtracted from a NATIVE
|
|
9138
|
+
* spend, so it protects "swap all my ETH" — but an ERC-20 spend burns native gas
|
|
9139
|
+
* the reserve never touches, and a wallet holding USDC with an empty ETH balance
|
|
9140
|
+
* passes every check on the token being spent and only fails at signing. The
|
|
9141
|
+
* exchange screen checks the native balance against `feeGas` on BOTH paths and
|
|
9142
|
+
* blocks with "You need {amount} {item} to swap"; this is that check.
|
|
9143
|
+
*
|
|
9144
|
+
* Returns `null` — "let it through" — whenever the answer isn't clearly no: the
|
|
9145
|
+
* wallet has enough, or the fee/balance can't be read. An RPC outage must never
|
|
9146
|
+
* block a user who can perfectly well pay.
|
|
9147
|
+
*
|
|
9148
|
+
* `readNativeBalance` is injected rather than imported so this stays independent
|
|
9149
|
+
* of any one tool's balance source; a wallet with no native entry reads as 0,
|
|
9150
|
+
* which IS the shortfall this exists to catch.
|
|
9151
|
+
*/
|
|
9152
|
+
declare function checkNativeGasAffordable(input: {
|
|
9153
|
+
chainId: string | undefined;
|
|
9154
|
+
gasKind: NativeActionKind;
|
|
9155
|
+
/** Resolves the wallet's native balance + symbol, or undefined when unreadable. */
|
|
9156
|
+
readNativeBalance: () => Promise<{
|
|
9157
|
+
balance?: number;
|
|
9158
|
+
symbol?: string;
|
|
9159
|
+
} | undefined>;
|
|
9160
|
+
/** Quote/provider context, so the fee matches the one the tx will actually pay. */
|
|
9161
|
+
feeContext?: FeeContext;
|
|
9162
|
+
}): Promise<NativeGasGap | null>;
|
|
8560
9163
|
|
|
8561
9164
|
/** Resolved token identity used to pre-fill a wallet-action form. */
|
|
8562
9165
|
interface ResolvedToken {
|
|
@@ -8928,9 +9531,19 @@ declare class ApproveTokenTool extends BaseWalletActionTool {
|
|
|
8928
9531
|
* Tool: open-buy-token-form
|
|
8929
9532
|
*
|
|
8930
9533
|
* A STANDALONE wallet-action tool (NOT a `BaseWalletActionTool`): instead of
|
|
8931
|
-
* emitting the shared form payload, it
|
|
8932
|
-
*
|
|
8933
|
-
*
|
|
9534
|
+
* emitting the shared form payload, it resolves the two tokens and ships a custom
|
|
9535
|
+
* `SwapTokenForm` payload the FE sizes, quotes and executes itself. That's why
|
|
9536
|
+
* `buy_token` is intentionally NOT a member of `WalletActionType`.
|
|
9537
|
+
*
|
|
9538
|
+
* The tool deliberately does NOT quote. It once did — building a priced confirm
|
|
9539
|
+
* card whenever the user named an amount — but a quote built here goes stale
|
|
9540
|
+
* while the message sits in the chat, and the amount it was built for could not
|
|
9541
|
+
* be changed without another agent turn. The form quotes on the FE for the amount
|
|
9542
|
+
* currently on screen, so what executes is always what was just priced.
|
|
9543
|
+
*
|
|
9544
|
+
* It emits the SAME `SwapTokenForm` payload as {@link SwapTokenTool}: a buy and a
|
|
9545
|
+
* swap are one transaction under two framings, so they are one form. Only
|
|
9546
|
+
* `intent` differs, and it decides wording and which x402 route is charged.
|
|
8934
9547
|
*
|
|
8935
9548
|
* Branches, picked deterministically from the args:
|
|
8936
9549
|
*
|
|
@@ -8951,19 +9564,16 @@ declare class ApproveTokenTool extends BaseWalletActionTool {
|
|
|
8951
9564
|
* 25/50/75/100% buttons sized off the real balance. Skipped for the native
|
|
8952
9565
|
* pay token and when balances can't be read.
|
|
8953
9566
|
*
|
|
8954
|
-
* 1.5 **Amount
|
|
8955
|
-
*
|
|
8956
|
-
*
|
|
8957
|
-
*
|
|
8958
|
-
*
|
|
8959
|
-
*
|
|
8960
|
-
* tx), checks allowance, and emits a `BuyTokenConfirmTx` payload bundling
|
|
8961
|
-
* the estimate, the raw swap transaction, and the approve transaction (when
|
|
8962
|
-
* one is needed). The FE executes approve (if any) then swap itself.
|
|
9567
|
+
* 1.5 **Amount form** — dest + pay token are known. The tool reads the pay-token
|
|
9568
|
+
* balance (for the percentage shortcuts) and emits ONE `SwapTokenForm`
|
|
9569
|
+
* payload, whether or not the user named an amount: named, it arrives as
|
|
9570
|
+
* `initialAmount` and the form opens pre-filled; unnamed, the form opens
|
|
9571
|
+
* empty. Either way the amount stays editable and the FE quotes it. This is
|
|
9572
|
+
* the tool's only UI outcome.
|
|
8963
9573
|
*
|
|
8964
9574
|
* When none of the above produces a result (couldn't resolve the dest token,
|
|
8965
|
-
*
|
|
8966
|
-
*
|
|
9575
|
+
* amount given only on the buy side, …) the tool returns an error/_instructions
|
|
9576
|
+
* object — it never opens a generic form.
|
|
8967
9577
|
*
|
|
8968
9578
|
* Amount disambiguation mirrors the chatbot SDK:
|
|
8969
9579
|
* - "buy PEPE with 10 USDC" → pay_with_amount = "10"
|
|
@@ -9071,13 +9681,6 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9071
9681
|
* just comes back with `address: null`.
|
|
9072
9682
|
*/
|
|
9073
9683
|
private resolveSide;
|
|
9074
|
-
/**
|
|
9075
|
-
* Pay token + dest token + a pay-token amount are known. Fetch a swap quote
|
|
9076
|
-
* (estimated receive amount + raw swap tx), check approval, and return a
|
|
9077
|
-
* `BuyTokenConfirmTx` UI payload the FE executes itself. Returns `null` when
|
|
9078
|
-
* anything we need can't be produced (bad chain, quote failed, non-EVM tx).
|
|
9079
|
-
*/
|
|
9080
|
-
private buildConfirmTx;
|
|
9081
9684
|
/**
|
|
9082
9685
|
* deBridge only quotes EXACT_INPUT, so a "buy X of the dest token" request has
|
|
9083
9686
|
* no input amount to seed the quote. Convert the desired output into a pay-token
|
|
@@ -9117,29 +9720,6 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9117
9720
|
* string or `null`.
|
|
9118
9721
|
*/
|
|
9119
9722
|
private resolveBuyAmountSpec;
|
|
9120
|
-
/**
|
|
9121
|
-
* Check whether the pay token needs an allowance for this swap and, if so,
|
|
9122
|
-
* return a ready-to-sign ERC-20 approve tx. Relay bundles the approve step in
|
|
9123
|
-
* the quote (`approvalData` is the tx); deBridge only reports the spender
|
|
9124
|
-
* (`tx.to`), so we encode the approve calldata ourselves.
|
|
9125
|
-
*/
|
|
9126
|
-
private buildApproveTx;
|
|
9127
|
-
/** Human amount → smallest-unit decimal string (no float drift via BigInt). */
|
|
9128
|
-
private toRawAmount;
|
|
9129
|
-
/**
|
|
9130
|
-
* Pull a human-readable failure reason out of a failed quote. Adapters set
|
|
9131
|
-
* `errorMessage` (string) and `error` (string or a provider object). deBridge
|
|
9132
|
-
* also nests a reason in `raw.errorMessage` / `raw.error`. Falls back to a
|
|
9133
|
-
* generic line so the caller always has something to show.
|
|
9134
|
-
*/
|
|
9135
|
-
private extractQuoteError;
|
|
9136
|
-
/**
|
|
9137
|
-
* Estimated receive amount in the dest token's smallest units. Shape differs
|
|
9138
|
-
* per provider — deBridge same-chain: `raw.tokenOut.minAmount`; deBridge
|
|
9139
|
-
* cross-chain: `raw.estimation.dstChainTokenOut.amount`; Relay:
|
|
9140
|
-
* `raw.details.currencyOut.{amount|minimumAmount}`.
|
|
9141
|
-
*/
|
|
9142
|
-
private extractOutRaw;
|
|
9143
9723
|
private buildPayWithPicker;
|
|
9144
9724
|
/**
|
|
9145
9725
|
* Guard the buy flow against a pay token the user can't fund. Returns:
|
|
@@ -9150,19 +9730,27 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9150
9730
|
*/
|
|
9151
9731
|
private checkPayBalance;
|
|
9152
9732
|
/**
|
|
9153
|
-
*
|
|
9154
|
-
*
|
|
9155
|
-
*
|
|
9156
|
-
*
|
|
9157
|
-
*
|
|
9158
|
-
* held balance minus a silently-estimated swap gas reserve (gasLimit
|
|
9159
|
-
* 1_000_000 × gasPrice) — so the percent buttons, amount picker, and balance
|
|
9160
|
-
* check stay within what the user can actually spend while still covering gas.
|
|
9161
|
-
* The reserve is never surfaced; callers only ever expose the spendable
|
|
9162
|
-
* number. ERC-20 pay tokens are returned at their raw held balance (gas is
|
|
9163
|
-
* paid in the native coin, not the pay token).
|
|
9733
|
+
* The connected wallet's SPENDABLE balance of the PAY token — the shared
|
|
9734
|
+
* {@link readSpendableBalance}, which is also what the in-chat form calls when
|
|
9735
|
+
* the user refreshes. A native pay coin comes back net of the swap gas reserve
|
|
9736
|
+
* so a sized buy always leaves gas to execute it; an ERC-20 comes back at its
|
|
9737
|
+
* held balance. `null` when the balance can't be read or the token isn't held.
|
|
9164
9738
|
*/
|
|
9165
9739
|
private readPayBalance;
|
|
9740
|
+
/**
|
|
9741
|
+
* The wallet's RAW held native balance — no gas reserve deducted.
|
|
9742
|
+
*
|
|
9743
|
+
* Distinct from {@link readPayBalance} on purpose. That one answers "how much of
|
|
9744
|
+
* this can be spent", which for the native coin is already `held − fee`. The
|
|
9745
|
+
* fee affordability check needs the other question — "does the wallet hold
|
|
9746
|
+
* enough to pay the fee at all" — and must compare against the raw balance, or
|
|
9747
|
+
* it subtracts the fee twice and rejects wallets that can pay. The exchange
|
|
9748
|
+
* screen reads a raw `balanceNative` for the same comparison.
|
|
9749
|
+
*
|
|
9750
|
+
* Returns `{ balance: 0 }` when the native coin can't be read or isn't held:
|
|
9751
|
+
* both mean the fee cannot be paid, which is the finding, not a reason to skip.
|
|
9752
|
+
*/
|
|
9753
|
+
private readNativeHeldBalance;
|
|
9166
9754
|
/**
|
|
9167
9755
|
* 25/50/75/100% quick-spend buttons sized off a held balance. Every amount is
|
|
9168
9756
|
* an EXACT fraction of the exact balance STRING, floored — so a clicked button
|
|
@@ -9171,7 +9759,25 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9171
9759
|
* percent.
|
|
9172
9760
|
*/
|
|
9173
9761
|
private percentSpendButtons;
|
|
9174
|
-
|
|
9762
|
+
/**
|
|
9763
|
+
* Both sides are resolved but no amount was given. Ship the INTERACTIVE amount
|
|
9764
|
+
* form: the user sizes the spend on a slider, the FE quotes it live, and one
|
|
9765
|
+
* tap executes it — no further agent turn.
|
|
9766
|
+
*
|
|
9767
|
+
* This used to emit four percent BUTTONS, each of which re-submitted a prompt
|
|
9768
|
+
* and re-ran this whole tool just to change one number. The form collapses that
|
|
9769
|
+
* to a single payload, so changing your mind costs nothing.
|
|
9770
|
+
*
|
|
9771
|
+
* The spendable balance rides down as `rawAmount` (smallest units) so the FE
|
|
9772
|
+
* can take exact BigInt fractions of it; for a native pay token it is already
|
|
9773
|
+
* net of the gas reserve (see {@link readPayBalance}). Returns `null` when the
|
|
9774
|
+
* balance can't be read — the caller then falls through to asking for an
|
|
9775
|
+
* amount in words, exactly as before.
|
|
9776
|
+
*
|
|
9777
|
+
* The mirror of SwapTokenTool's own `buildAmountForm`: same payload shape, same
|
|
9778
|
+
* FE component, distinguished only by `intent`.
|
|
9779
|
+
*/
|
|
9780
|
+
private buildAmountForm;
|
|
9175
9781
|
/**
|
|
9176
9782
|
* Trim IEEE-754 noise from a computed amount (≤8 significant digits) and
|
|
9177
9783
|
* ALWAYS return plain decimal notation — never exponential ("1.5e-7"). Use
|
|
@@ -9221,10 +9827,16 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9221
9827
|
* Tool: open-swap-token-form
|
|
9222
9828
|
*
|
|
9223
9829
|
* A STANDALONE wallet-action tool (NOT a `BaseWalletActionTool`), built as the
|
|
9224
|
-
* mirror of {@link BuyTokenTool}: it
|
|
9225
|
-
*
|
|
9830
|
+
* mirror of {@link BuyTokenTool}: it resolves the two tokens and ships a custom
|
|
9831
|
+
* `SwapTokenAmountForm` payload the FE sizes, quotes and executes itself. That's
|
|
9226
9832
|
* why `swap_token` is intentionally NOT a member of `WalletActionType`.
|
|
9227
9833
|
*
|
|
9834
|
+
* The tool deliberately does NOT quote. It once did — building a priced confirm
|
|
9835
|
+
* card whenever the user named an amount — but a quote built here goes stale
|
|
9836
|
+
* while the message sits in the chat, and any amount it was built for could not
|
|
9837
|
+
* then be changed without another agent turn. The form quotes on the FE for the
|
|
9838
|
+
* amount currently on screen, so what executes is always what was just priced.
|
|
9839
|
+
*
|
|
9228
9840
|
* The defining difference from BUY: the SOURCE is a token the user ALREADY HOLDS.
|
|
9229
9841
|
* Buy starts from a destination ("buy PEPE") and asks which wallet token to pay
|
|
9230
9842
|
* with; swap starts from the user's own token ("swap USDC") and asks what to
|
|
@@ -9242,7 +9854,10 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9242
9854
|
* 0. **Source picker** — the user named NO source (`from_symbol`/`from_address`
|
|
9243
9855
|
* empty). The tool fetches the wallet's native + ERC-20 holdings and emits
|
|
9244
9856
|
* `actionButtons` so the user picks which token to swap FROM. A click
|
|
9245
|
-
* re-submits a prompt like `"swap USDC"` which routes back here.
|
|
9857
|
+
* re-submits a prompt like `"swap USDC"` which routes back here. When a
|
|
9858
|
+
* destination WAS named ("swap to PEPE"), it rides along in every click-
|
|
9859
|
+
* prompt — `"swap USDC to PEPE"` — so choosing a source doesn't discard the
|
|
9860
|
+
* half of the request the user already made.
|
|
9246
9861
|
*
|
|
9247
9862
|
* 1. **Destination picker (trending)** — the user named the source only. The
|
|
9248
9863
|
* tool fetches the chain's live trending list (minus the source token) and
|
|
@@ -9256,19 +9871,15 @@ declare class BuyTokenTool extends BaseTool {
|
|
|
9256
9871
|
* amount, it reports the shortfall and emits 25/50/75/100% buttons sized off
|
|
9257
9872
|
* the real balance. Skipped for the native source token.
|
|
9258
9873
|
*
|
|
9259
|
-
* 1.5 **Amount
|
|
9260
|
-
*
|
|
9261
|
-
* the
|
|
9262
|
-
*
|
|
9263
|
-
*
|
|
9264
|
-
*
|
|
9265
|
-
* allowance, and emits a `SwapTokenConfirmTx` payload bundling the estimate,
|
|
9266
|
-
* the raw swap transaction, and the approve transaction (when one is needed).
|
|
9267
|
-
* The FE executes approve (if any) then swap itself.
|
|
9874
|
+
* 1.5 **Amount form** — source + dest known. The tool reads the source balance
|
|
9875
|
+
* (for the percentage shortcuts) and emits ONE `SwapTokenAmountForm` payload,
|
|
9876
|
+
* whether or not the user named an amount: named, it arrives as
|
|
9877
|
+
* `initialAmount` and the form opens pre-filled; unnamed, the form opens
|
|
9878
|
+
* empty. Either way the amount stays editable and the FE quotes it. This is
|
|
9879
|
+
* the tool's only UI outcome.
|
|
9268
9880
|
*
|
|
9269
|
-
* When none of the above produces a result (couldn't resolve a token,
|
|
9270
|
-
*
|
|
9271
|
-
* generic form.
|
|
9881
|
+
* When none of the above produces a result (couldn't resolve a token, …) the
|
|
9882
|
+
* tool returns an error/_instructions object — it never opens a generic form.
|
|
9272
9883
|
*
|
|
9273
9884
|
* Amount disambiguation mirrors BuyTokenTool. The swap is EXACT_INPUT (deBridge),
|
|
9274
9885
|
* so the amount that seeds the quote is the SOURCE amount:
|
|
@@ -9325,13 +9936,6 @@ declare class SwapTokenTool extends BaseTool {
|
|
|
9325
9936
|
* just comes back with `address: null`.
|
|
9326
9937
|
*/
|
|
9327
9938
|
private resolveSide;
|
|
9328
|
-
/**
|
|
9329
|
-
* Source token + dest token + a source-token amount are known. Fetch a swap
|
|
9330
|
-
* quote (estimated receive amount + raw swap tx), check approval, and return a
|
|
9331
|
-
* `SwapTokenConfirmTx` UI payload the FE executes itself. Returns `null` when
|
|
9332
|
-
* anything we need can't be produced (bad chain, quote failed, non-EVM tx).
|
|
9333
|
-
*/
|
|
9334
|
-
private buildConfirmTx;
|
|
9335
9939
|
/**
|
|
9336
9940
|
* deBridge only quotes EXACT_INPUT, so a "swap to X of the dest token" request
|
|
9337
9941
|
* has no input amount to seed the quote. Convert the desired output into a
|
|
@@ -9368,29 +9972,6 @@ declare class SwapTokenTool extends BaseTool {
|
|
|
9368
9972
|
* null). Returns a plain token amount string or `null`.
|
|
9369
9973
|
*/
|
|
9370
9974
|
private resolveToAmountSpec;
|
|
9371
|
-
/**
|
|
9372
|
-
* Check whether the source token needs an allowance for this swap and, if so,
|
|
9373
|
-
* return a ready-to-sign ERC-20 approve tx. deBridge only reports the spender
|
|
9374
|
-
* (`tx.to`), so we encode the approve calldata ourselves; integrated providers
|
|
9375
|
-
* (Relay) hand back the approve tx directly.
|
|
9376
|
-
*/
|
|
9377
|
-
private buildApproveTx;
|
|
9378
|
-
/** Human amount → smallest-unit decimal string (no float drift via BigInt). */
|
|
9379
|
-
private toRawAmount;
|
|
9380
|
-
/**
|
|
9381
|
-
* Pull a human-readable failure reason out of a failed quote. Adapters set
|
|
9382
|
-
* `errorMessage` (string) and `error` (string or a provider object). deBridge
|
|
9383
|
-
* also nests a reason in `raw.errorMessage` / `raw.error`. Falls back to a
|
|
9384
|
-
* generic line so the caller always has something to show.
|
|
9385
|
-
*/
|
|
9386
|
-
private extractQuoteError;
|
|
9387
|
-
/**
|
|
9388
|
-
* Estimated receive amount in the dest token's smallest units. Shape differs
|
|
9389
|
-
* per provider — deBridge same-chain: `raw.tokenOut.minAmount`; deBridge
|
|
9390
|
-
* cross-chain: `raw.estimation.dstChainTokenOut.amount`; Relay:
|
|
9391
|
-
* `raw.details.currencyOut.{amount|minimumAmount}`.
|
|
9392
|
-
*/
|
|
9393
|
-
private extractOutRaw;
|
|
9394
9975
|
private buildSourcePicker;
|
|
9395
9976
|
private buildToTrendingPicker;
|
|
9396
9977
|
/**
|
|
@@ -9402,19 +9983,28 @@ declare class SwapTokenTool extends BaseTool {
|
|
|
9402
9983
|
*/
|
|
9403
9984
|
private checkFromBalance;
|
|
9404
9985
|
/**
|
|
9405
|
-
*
|
|
9406
|
-
*
|
|
9407
|
-
*
|
|
9408
|
-
*
|
|
9409
|
-
*
|
|
9410
|
-
*
|
|
9411
|
-
* 1_000_000 × gasPrice) — so the percent buttons, amount picker, and balance
|
|
9412
|
-
* check all stay within what the user can actually swap while still covering
|
|
9413
|
-
* gas. The reserve is never surfaced; callers only ever expose the spendable
|
|
9414
|
-
* number. ERC-20 sources are returned at their raw held balance (gas is paid
|
|
9415
|
-
* in the native coin, not the source token).
|
|
9986
|
+
* The connected wallet's SPENDABLE balance of the source token — the shared
|
|
9987
|
+
* {@link readSpendableBalance}, which is also what the in-chat form calls when
|
|
9988
|
+
* the user refreshes. Native sources come back net of the swap gas reserve, so
|
|
9989
|
+
* the percent buttons and the balance check stay within what can actually be
|
|
9990
|
+
* swapped; ERC-20 sources come back at their held balance. `null` when the
|
|
9991
|
+
* balance can't be read or the token isn't held.
|
|
9416
9992
|
*/
|
|
9417
9993
|
private readFromBalance;
|
|
9994
|
+
/**
|
|
9995
|
+
* The wallet's RAW held native balance — no gas reserve deducted.
|
|
9996
|
+
*
|
|
9997
|
+
* Distinct from {@link readFromBalance} on purpose. That one answers "how much of
|
|
9998
|
+
* this can be spent", which for the native coin is already `held − fee`. The
|
|
9999
|
+
* fee affordability check needs the other question — "does the wallet hold
|
|
10000
|
+
* enough to pay the fee at all" — and must compare against the raw balance, or
|
|
10001
|
+
* it subtracts the fee twice and rejects wallets that can pay. The exchange
|
|
10002
|
+
* screen reads a raw `balanceNative` for the same comparison.
|
|
10003
|
+
*
|
|
10004
|
+
* Returns `{ balance: 0 }` when the native coin can't be read or isn't held:
|
|
10005
|
+
* both mean the fee cannot be paid, which is the finding, not a reason to skip.
|
|
10006
|
+
*/
|
|
10007
|
+
private readNativeHeldBalance;
|
|
9418
10008
|
/**
|
|
9419
10009
|
* 25/50/75/100% quick-spend buttons sized off a held balance. Every amount is
|
|
9420
10010
|
* an EXACT fraction of the exact balance STRING, floored — so a clicked button
|
|
@@ -9423,7 +10013,27 @@ declare class SwapTokenTool extends BaseTool {
|
|
|
9423
10013
|
* percent.
|
|
9424
10014
|
*/
|
|
9425
10015
|
private percentSpendButtons;
|
|
9426
|
-
|
|
10016
|
+
/**
|
|
10017
|
+
* Both sides are resolved: ship the interactive form. The user sizes the spend
|
|
10018
|
+
* (pre-filled when they already named an amount), the FE quotes it live, and
|
|
10019
|
+
* one tap executes it — no further agent turn, and no quote that can go stale
|
|
10020
|
+
* sitting on screen.
|
|
10021
|
+
*
|
|
10022
|
+
* This is the tool's ONLY UI outcome. It used to emit four percent BUTTONS
|
|
10023
|
+
* when no amount was given and a separately-quoted confirm card when one was;
|
|
10024
|
+
* both are now this single form, which is why the tool no longer quotes at all.
|
|
10025
|
+
*
|
|
10026
|
+
* The spendable balance rides down as `rawAmount` (smallest units) so the FE
|
|
10027
|
+
* can take exact BigInt fractions of it; for a native source it is already net
|
|
10028
|
+
* of the gas reserve (see {@link readFromBalance}).
|
|
10029
|
+
*
|
|
10030
|
+
* A balance that can't be read is NOT fatal — the FE quotes for itself, so it
|
|
10031
|
+
* only needs the two tokens. The form simply opens without percentage
|
|
10032
|
+
* shortcuts and without a "spendable" line, rather than the user losing the
|
|
10033
|
+
* form entirely over a balance lookup. Returns `null` only when something the
|
|
10034
|
+
* form genuinely cannot work without is missing (chain, symbol, decimals).
|
|
10035
|
+
*/
|
|
10036
|
+
private buildAmountForm;
|
|
9427
10037
|
/**
|
|
9428
10038
|
* Trim IEEE-754 noise from a computed amount (≤8 significant digits) and
|
|
9429
10039
|
* ALWAYS return plain decimal notation — never exponential ("1.5e-7").
|
|
@@ -9565,6 +10175,152 @@ declare class SendNftTool extends BaseWalletActionTool {
|
|
|
9565
10175
|
private paramsFromNft;
|
|
9566
10176
|
}
|
|
9567
10177
|
|
|
10178
|
+
/**
|
|
10179
|
+
* Exact decimal-string math for wallet balances, quantised to a token's own
|
|
10180
|
+
* decimals.
|
|
10181
|
+
*
|
|
10182
|
+
* Amounts compared against — or derived from — a wallet balance MUST stay exact
|
|
10183
|
+
* AND must never carry more fractional digits than the token supports (USDT on
|
|
10184
|
+
* Optimism is 6 dp; ETH is 18). Float math / significant-figure rounding can
|
|
10185
|
+
* round UP (false "insufficient balance"), and a fraction like 25% of a 6-dp
|
|
10186
|
+
* balance can spill to 8 dp — an amount the token can't represent, which
|
|
10187
|
+
* `toRawAmount` then silently truncates (possibly to 0).
|
|
10188
|
+
*
|
|
10189
|
+
* Everything here works on decimal STRINGS / BigInt (arbitrary precision, so
|
|
10190
|
+
* very large and very small balances are exact), tolerates scientific notation
|
|
10191
|
+
* on input, and FLOORS — a fraction of a balance can never exceed it.
|
|
10192
|
+
*
|
|
10193
|
+
* Use these for any balance-sourced amount. Plain float rounding (`trimAmount`)
|
|
10194
|
+
* stays fine for price-derived ESTIMATES (usd→token, buy/swap→pay).
|
|
10195
|
+
*/
|
|
10196
|
+
/** Expand any exponential notation ("1.5e-7") in a JS number to plain decimal. */
|
|
10197
|
+
declare function toPlainDecimal(n: number): string;
|
|
10198
|
+
/**
|
|
10199
|
+
* Normalise a numeric string to a plain decimal — expands scientific notation
|
|
10200
|
+
* ("1.5e-7" → "0.00000015", "1.2e21" → "1200000000000000000000") with arbitrary
|
|
10201
|
+
* precision (pure string math, never via the lossy `Number`). Returns null when
|
|
10202
|
+
* the string isn't a number.
|
|
10203
|
+
*/
|
|
10204
|
+
declare function normalizeDecimal(input: string): string | null;
|
|
10205
|
+
/** Render a non-negative integer scaled by 10^decimals back to a decimal string. */
|
|
10206
|
+
declare function weiToHuman(wei: bigint, decimals: number): string;
|
|
10207
|
+
/**
|
|
10208
|
+
* Convert a human decimal string to the token's smallest unit (wei), truncating
|
|
10209
|
+
* any fractional digits beyond `decimals`. Tolerates scientific notation.
|
|
10210
|
+
* Returns null when not a positive number.
|
|
10211
|
+
*/
|
|
10212
|
+
declare function humanToWei(value: string, decimals: number): bigint | null;
|
|
10213
|
+
/**
|
|
10214
|
+
* Exact numeric string from a raw amount input, with NO rounding — so a
|
|
10215
|
+
* high-decimal amount a user typed/clicked is preserved verbatim. Strips a
|
|
10216
|
+
* trailing token symbol ("0.0000011 WBTC" → "0.0000011"), tolerates scientific
|
|
10217
|
+
* notation, normalises a leading ".". Returns null when no positive number.
|
|
10218
|
+
*/
|
|
10219
|
+
declare function exactAmountString(raw: unknown): string | null;
|
|
10220
|
+
/**
|
|
10221
|
+
* Floor a decimal string to at most `decimals` fractional digits — drops digits
|
|
10222
|
+
* the token can't represent (USDT-OP keeps 6). Exact, never rounds up.
|
|
10223
|
+
*/
|
|
10224
|
+
declare function floorToDecimals(value: string, decimals: number): string;
|
|
10225
|
+
/**
|
|
10226
|
+
* Exact `value × num / den`, FLOORED and quantised to `decimals` fractional
|
|
10227
|
+
* digits — never rounds up, so a fraction of a balance ("50% / 25% / all") can
|
|
10228
|
+
* never exceed the real balance nor carry more precision than the token has.
|
|
10229
|
+
*/
|
|
10230
|
+
declare function mulDivFloor(value: string, num: bigint, den: bigint, decimals: number): string;
|
|
10231
|
+
/** Exact decimal-string comparison (no float, e-notation aware). -1 / 0 / 1. */
|
|
10232
|
+
declare function compareDecimal(a: string, b: string): number;
|
|
10233
|
+
|
|
10234
|
+
/**
|
|
10235
|
+
* The SPENDABLE balance of a wallet-action's source token — one implementation.
|
|
10236
|
+
*
|
|
10237
|
+
* "Spendable" is not "held". For an ERC-20 the two are the same, but for the
|
|
10238
|
+
* chain's NATIVE coin some of the balance has to be left behind to pay the
|
|
10239
|
+
* transaction's own gas, so spendable is `balance − gasReserve` (see
|
|
10240
|
+
* {@link estimateNativeGasReserveWei}). Sizing a swap off the raw native balance
|
|
10241
|
+
* produces a "Max" the user cannot actually execute: the router call reverts for
|
|
10242
|
+
* want of gas.
|
|
10243
|
+
*
|
|
10244
|
+
* This lived twice — `SwapTokenTool.readFromBalance` and
|
|
10245
|
+
* `BuyTokenTool.readPayBalance` were the same function under two variable names
|
|
10246
|
+
* — and now lives once, for the same reason `decimalAmount` is shared: the tool
|
|
10247
|
+
* that SEEDS a form and the form that later RE-READS the balance must agree to
|
|
10248
|
+
* the last digit, and two copies of a gas reserve are two chances to drift.
|
|
10249
|
+
*
|
|
10250
|
+
* Exported from the package because the in-chat swap/buy form re-reads the
|
|
10251
|
+
* balance itself when the user taps Refresh. The alternative — the form doing
|
|
10252
|
+
* its own `getBalance` — is precisely the copy this module exists to prevent: it
|
|
10253
|
+
* would read the RAW native balance and quietly lose the gas reserve.
|
|
10254
|
+
*/
|
|
10255
|
+
|
|
10256
|
+
/**
|
|
10257
|
+
* A token's logo, whichever name the source used for it.
|
|
10258
|
+
*
|
|
10259
|
+
* The wallet-balance API says `logo`, while the Pantograph token search spreads
|
|
10260
|
+
* the same URL across `logo` / `icon_image` / `logoURI` / `thumbnail` depending
|
|
10261
|
+
* on the list a token came from — so reading only one of them leaves tokens that
|
|
10262
|
+
* do have an icon rendering as the blank placeholder.
|
|
10263
|
+
*/
|
|
10264
|
+
declare const pickLogo: (t: {
|
|
10265
|
+
logo?: string;
|
|
10266
|
+
icon_image?: string;
|
|
10267
|
+
logoURI?: string;
|
|
10268
|
+
thumbnail?: string;
|
|
10269
|
+
}) => string | undefined;
|
|
10270
|
+
/** What a spendable read yields. `null` from the reader means "no usable balance". */
|
|
10271
|
+
interface SpendableBalance {
|
|
10272
|
+
/**
|
|
10273
|
+
* Human-readable spendable amount — already net of the gas reserve for a
|
|
10274
|
+
* native source. This is the exact string every fraction is taken FROM; never
|
|
10275
|
+
* re-round it, since rounding up produces an amount the user does not have.
|
|
10276
|
+
*/
|
|
10277
|
+
balanceFormatted: string;
|
|
10278
|
+
/** The same figure as a number, for comparisons. */
|
|
10279
|
+
balanceNum: number;
|
|
10280
|
+
/**
|
|
10281
|
+
* The same figure in the token's SMALLEST units. What the form's percentage
|
|
10282
|
+
* pills divide, so the number shown and the number divided are provably one.
|
|
10283
|
+
* `undefined` when decimals aren't known and the conversion can't be made.
|
|
10284
|
+
*/
|
|
10285
|
+
rawAmount?: string;
|
|
10286
|
+
symbol?: string;
|
|
10287
|
+
decimals?: number;
|
|
10288
|
+
logo?: string;
|
|
10289
|
+
}
|
|
10290
|
+
/**
|
|
10291
|
+
* Read the spendable balance of `tokenAddress` for `walletAddress` on `chain`.
|
|
10292
|
+
*
|
|
10293
|
+
* Returns `null` — never a zero — when the token isn't held, the balance is
|
|
10294
|
+
* unreadable, or a native balance is entirely consumed by its own gas reserve.
|
|
10295
|
+
* "Holds nothing" and "we couldn't ask" both mean the caller has no percentages
|
|
10296
|
+
* to offer, and both must leave whatever figure is already on screen alone
|
|
10297
|
+
* rather than overwrite it with a zero the wallet does not report.
|
|
10298
|
+
*
|
|
10299
|
+
* @param moralis The balance source. Callers that have no Moralis
|
|
10300
|
+
* configured get `null`, as before.
|
|
10301
|
+
* @param walletAddress The holder.
|
|
10302
|
+
* @param tokenAddress `'native'` for the chain's coin, else the contract.
|
|
10303
|
+
* @param chain Hex chain id. Required for the native gas reserve; a
|
|
10304
|
+
* native read without one returns the full balance.
|
|
10305
|
+
* @param kind Which gas limit the reserve is sized against —
|
|
10306
|
+
* `'swap'` (a router call, the default) or `'send'`.
|
|
10307
|
+
* @param feeContext Quote/provider context for the reserve: the quote's own
|
|
10308
|
+
* gas limit and, on a cross-chain deBridge route, its fixed
|
|
10309
|
+
* protocol fee. Omitted, the reserve falls back to the
|
|
10310
|
+
* default gas limit and no protocol fee — which is what
|
|
10311
|
+
* every pre-quote caller wants.
|
|
10312
|
+
* @param dbg Optional trace sink, so the tools keep the logging they had.
|
|
10313
|
+
*/
|
|
10314
|
+
declare function readSpendableBalance(input: {
|
|
10315
|
+
moralis?: MoralisService;
|
|
10316
|
+
walletAddress: string;
|
|
10317
|
+
tokenAddress: string;
|
|
10318
|
+
chain?: string;
|
|
10319
|
+
kind?: NativeActionKind;
|
|
10320
|
+
feeContext?: FeeContext;
|
|
10321
|
+
dbg?: (msg: string, data?: unknown) => void;
|
|
10322
|
+
}): Promise<SpendableBalance | null>;
|
|
10323
|
+
|
|
9568
10324
|
/**
|
|
9569
10325
|
* JSON-RPC wire types + the EIP-1193 request function every transport exposes.
|
|
9570
10326
|
*/
|
|
@@ -12001,4 +12757,4 @@ declare class AbortError extends Error {
|
|
|
12001
12757
|
*/
|
|
12002
12758
|
declare function isAbortError(err: unknown): boolean;
|
|
12003
12759
|
|
|
12004
|
-
export { AI_AGENT_TOOL_NAMES, type Abi, type AbiItem, type AbiParameter, AbortError, type AddLiquidityFormProps, type AddLiquiditySummary, type Address, type AffiliateFee, type AgentConfig, AgentCore, type AgentResponse, ApproveTokenTool, type ApyPoint, BaseNftAiTool, BaseSwapService, BaseTool, BaseWalletActionTool, type BlockParameters, type BlockTag, type BuyTokenConfirmTxProps, type BuyTokenSide, BuyTokenTool, type CallParameters, type Chain, type ChainMeta, type ChainRef, type ChainSelector, ChatHistory, type ChatMessage, type ChatOptions, type ChatRole, type CheckApprovalParams, type CheckApprovalResult, type Client, type ClientBatchConfig, type ConfirmAddLiquidityTxProps, type ContractFunctionParameters, type CortexResponse, DEFAULT_CHAIN, DEFAULT_PROVIDER, DEFAULT_RPC_BY_CHAIN, DebridgeAdapter, type DecodedCall, type DecodedEvent, type DecodedParam, type DefaultSubagentName, type DefiPosition, type DefiPositionDetails, type DefiPositionToken, type DefiProtocolSummary, type EIP1193RequestFn, EstimatePoolYieldTool, type EstimatePoolYieldToolConfig, type ExchangeProviderConfig, type ExecuteSwapParams, type ExecuteSwapResult, GeminiProvider, GeminiSearchAiTool, type GeminiSearchAiToolConfig, HEX_TO_PANTOGRAPH, type Hex, type HolderChangePeriod, type HolderSupplyTier, type HttpMethod, type IngestKnowledgeBaseInput, type IngestKnowledgeBaseResult, type InputTokenInfo, type KBSearchResult, KnowledgeBase, type KnowledgeBaseEntry, type KnowledgeBaseProvider, type LLMProvider, type LLMProviderConfig, type LLMResponse, type LLMToolCall, type LendingMarket, type LendingMarketCardProps, LendingMarketDetailTool, type LendingMarketDetailToolConfig, type LendingMarketListProps, type LendingMarketOverview, LendingMarketsTool, type LendingMarketsToolConfig, type LendingProtocolType, LendingReadService, LendingService, type LendingServiceConfig, type LendingSupplyPosition, LendingSupplyService, MULTICALL3_ADDRESS, ManageLiquidityRedirectTool, type MarketplaceLink, type MoralisApiResponse, MoralisService, type MoralisServiceConfig, type MulticallParameters, type MulticallRawParameters, type MulticallResult, NFC_AGENT_TOOL_NAMES, NFC_AMAZON_DEFAULT_DOMAIN, NFC_AMAZON_DOMAINS, type NFTCollectionItem, NFTContractInfoTool, type NFTContractMetadata, type NFTItem, type NFTLastSale, type NFTMetadata, NFTMetadataTool, NFT_AGENT_TOOL_NAMES, type NativeTokenInfo, NfcBuyTool, NfcInfoTool, type NftTransferLastSale, NoFormTool, type NoFormToolMessages, OpenAddLiquidityFormTool, type OpenAddLiquidityFormToolConfig, OpenSupplyFormTool, type OpenSupplyFormToolConfig, POOL_AGENT_TOOL_NAMES, PantographService, type PantographServiceConfig, type PantographYieldIdentity, type PaymentToken, PoolByAddressTool, type PoolByAddressToolConfig, PoolDetailTool, type PoolDetailToolConfig, type PoolDisplayInfo, PoolFallbackAiTool, type PoolFallbackAiToolConfig, type PoolOnchainInfo, PoolPriceRangesTool, type PoolPriceRangesToolConfig, PoolSearchTool, type PoolSearchToolConfig, PoolService, type PoolServiceConfig, type PresetInputs, PreviewAddLiquidityTool, type PreviewAddLiquidityToolConfig, type PriceBounds, type PriceRangePrefill, type ProviderName, PublicClient, type PublicClientConfig, type QuickRate, type RangePreset, type ReActPhase, type ReActStep, type ReActTrace, type ReadContractParameters, RelayAdapter, type ResolvedRange, Router, type RouterAssignment, type RouterDecision, SUPPLIABLE_TYPES, SUPPORTED_CHAINS, SUPPORTED_CHAINS_LABEL, SWAP_PROVIDER_CONFIG, SendNativeTool, SendNftTool, SendTokenTool, type StateOverride, type StorageProvider, Subagent, type SubagentCard, type SubagentOptions, type SubagentParams, type SubagentResult, type SubagentTask, type SubagentToggles, SubgraphAddPoolTool, type SubgraphAddPoolToolConfig, SubgraphCoinPoolPairsTool, type SubgraphCoinPoolPairsToolConfig, SubgraphPoolByAddressTool, type SubgraphPoolByAddressToolConfig, SubgraphPoolByPositionIdTool, type SubgraphPoolByPositionIdToolConfig, SubgraphPoolSearchTool, type SubgraphPoolSearchToolConfig, SubgraphPositionDetailTool, type SubgraphPositionDetailToolConfig, SubgraphTrendingPoolsTool, type SubgraphTrendingPoolsToolConfig, type SuggestedAction, Summarizer, type SuppliableMarket, type SupplyProtocolType, type SupplyUsdcProps, type SupportedChainId, type SupportedChainName, type SwapQuoteParams, type SwapQuoteResult, type SwapServiceConfig, SwapServiceFactory, type SwapTokenConfirmTxProps, SwapTokenTool, type SwapTxData, Synthesizer, TOKEN_AGENT_TOOL_NAMES, TRANSFER_TOPIC, TRENDING_DEFAULT_BY_HEX_CHAIN, type TokenAnalyticsResponse, type TokenAnalyticsTimeframeBuckets, TokenAnalyticsTool, type TokenAnalyticsToolConfig, type TokenApproval, type TokenApprovalSpender, type TokenApprovalToken, type TokenBalance, type TokenDisplay, type TokenHoldersResponse, TokenHoldersTool, type TokenHoldersToolConfig, TokenInfoTool, type TokenInfoToolConfig, type TokenMetadata, type TokenScoreMetrics, type TokenScoreResponse, type TokenScoreSupply, type TokenScoreTimeframeBuckets, TokenScoreTool, type TokenScoreToolConfig, type Tool, type ToolDefinition, type ToolKind, type ToolParameter, ToolRegistry, type ToolResult, type TopGainerTimeFrames, type TopGainerToken, type TopGainersTimeFrame, TopGainersTool, type TopGainersToolConfig, TopPoolsTool, type TopPoolsToolConfig, type TrackStatus, type TrackTransactionParams, type TrackTransactionResult, type TransactionByHashResponse, TransactionByHashTool, type TransactionByHashToolConfig, type TransactionLog, type TransactionReceipt, type TransactionReceiptLog, type Transport, type TransportConfig, type TrendingToken, type TrendingTokenTimeframeBuckets, TrendingTokensTool, type TrendingTokensToolConfig, type UIPayload, UNISWAP_CHAIN_SLUG, UNRESOLVED_ASSET, type UnsignedTx, type UpstashEmbedStrategy, type UpstashFusionAlgorithm, type UpstashKBUpsertEntry, UpstashKnowledgeBase, type UpstashKnowledgeBaseConfig, type UserContext, type VectorKBConfig, WALLET_ACTION_AGENT_TOOL_NAMES, WALLET_AGENT_TOOL_NAMES, type WalletActionProps, type WalletActionType, type WalletApprovalsResponse, WalletApprovalsTool, type WalletApprovalsToolConfig, type WalletDefiPositionSummary, WalletDefiPositionsTool, type WalletDefiPositionsToolConfig, type WalletDefiPositionsV1Response, type WalletDefiProtocolPositionsResponse, WalletDefiProtocolPositionsTool, type WalletDefiProtocolPositionsToolConfig, type WalletDefiProtocolPositionsV1Response, type WalletDefiSummaryResponse, type WalletDefiSummaryV1Response, type WalletHistoryCategory, type WalletHistoryContractInteraction, type WalletHistoryErc20Transfer, type WalletHistoryItem, type WalletHistoryNativeTransfer, type WalletHistoryNftTransfer, type WalletHistoryResponse, WalletHistoryTool, type WalletHistoryToolConfig, WalletLendingPositionsTool, type WalletLendingPositionsToolConfig, WalletNFTsTool, type WalletNFTsToolConfig, type WalletNftCardProps, type WalletNftListProps, type WalletNftTransferItem, type WalletNftTransfersResponse, WalletNftTransfersTool, type WalletNftTransfersToolConfig, type WalletPnlDaysWindow, type WalletPnlResponse, type WalletPnlSummaryResponse, WalletPnlSummaryTool, type WalletPnlSummaryToolConfig, type WalletPnlTokenItem, WalletPnlTool, type WalletPnlToolConfig, WalletTokenBalancesTool, type WalletTokenBalancesToolConfig, type WalletTokenTransferItem, type WalletTokenTransfersResponse, WalletTokenTransfersTool, type WalletTokenTransfersToolConfig, type WebsiteTrustExtraData, type WebsiteTrustInput, WebsiteTrustKeyringAgent, type WebsiteTrustKeyringAgentConfig, type WebsiteTrustResult, type X402Authorization, type X402Challenge, type X402Display, type X402Outcome, type X402PaymentRequiredProps, type X402Receipt, type X402RequestSpec, type X402Requirements, type X402SignRequest, type X402Signer, type X402TypedData, type X402Version, type YieldConversionCall, type YieldConversionPlan, type YieldPricingOptions, type YieldPricingToken, type YieldTokenInput, type YieldTokenValue, ZERO_ADDRESS, amazonDomainForLanguage, apiClient, applyYieldConversions, buildChallenge, buildRangePresets, buildUniswapPoolUrl, call, chains, checksumAddress, clampTick, clearPublicClientCache, completeX402, configureSupportedChains, convertSusdsShares, createAiAgent, createDefaultSubagents, createNfcAgent, createNftAgent, createPoolAgent, createPublicClient, createTokenAgent, createTransport, createWalletActionAgent, createWalletAgent, createX402SignatureProvider, decodeAbiParameters, decodeErrorResult, decodeFunctionData, decodeFunctionResult, displayFromChallenge, effectivePriceUSD, encodeAbiParameters, encodeErrorResult, encodeFunctionData, encodeSignedHeader, erc1155Abi, erc20Abi, erc20Abi_bytes32, erc721Abi, estimateGas, ethCallAt, ethCallByChain, fallback, fetchTopMarketplaces, getAbiItem, getAddress, getAffiliateFee, getBalance, getBlock, getBlockNumber, getChain, getChainContractAddress, getChainId, getChainMeta, getCode, getDefaultRpcUrl, getGasPrice, getGatewayAddress, getGatewayChains, getNativeTokenInfo, getPositionManagerAddress, getProviderByChain, getPublicClient, getRevertReason, getRpcOverrides, getStorageAt, getTokenPriceUSD, getTransactionCount, http, ingestKnowledgeBase, isAbortError, isAddress, isAddressEqual, isPaymentRequired, isShareBasedProtocol, isShareBasedYieldToken, isSupplyChain, listCandidateChains, listSupplyChains, multicall, multicall3Abi, multicallRaw, nfcAmazonSearchUrl, normaliseCountry, normalizePriceRangeToPool, parseAbi, parseAbiItem, parseAbiParameters, planYieldTokenConversions, priceToTick, protocolLabelFor, psm3For, readContract, readPaymentError, readPaymentRequired, readReceipt, registerMaybeNoForm, requestWithX402, resolveNfcShopLinks, resolveRpcUrl, resolveRpcUrls, resolveTokenPriceUSD, roundTickToSpacing, rpcCall, setRpcOverrides, swapServiceFactory, tickToPrice, toEventSelector, toFunctionSelector, toPantographChain, valueYieldTokens };
|
|
12760
|
+
export { AI_AGENT_TOOL_NAMES, type Abi, type AbiItem, type AbiParameter, AbortError, type AddLiquidityFormProps, type AddLiquiditySummary, type Address, type AffiliateFee, type AgentConfig, AgentCore, type AgentResponse, type ApprovalTx, ApproveTokenTool, type ApyPoint, BaseNftAiTool, BaseSwapProvider, BaseTool, BaseWalletActionTool, type BlockParameters, type BlockTag, type BuildApprovalsParams, type BuyTokenSide, BuyTokenTool, CachedResource, type CallParameters, type Chain, type ChainMeta, type ChainRef, type ChainSelector, ChatHistory, type ChatMessage, type ChatOptions, type ChatRole, type CheckApprovalParams, type CheckApprovalResult, type Client, type ClientBatchConfig, CoinpoolConfigApi, type ConfirmAddLiquidityTxProps, type ContractFunctionParameters, type CortexResponse, DEFAULT_CHAIN, DEFAULT_PROVIDER, DEFAULT_RPC_BY_CHAIN, DebridgeProvider, type DecodedCall, type DecodedEvent, type DecodedParam, type DefaultSubagentName, type DefiPosition, type DefiPositionDetails, type DefiPositionToken, type DefiProtocolSummary, type EIP1193RequestFn, EstimatePoolYieldTool, type EstimatePoolYieldToolConfig, type FeeContext, GeminiProvider, GeminiSearchAiTool, type GeminiSearchAiToolConfig, HEX_TO_PANTOGRAPH, type Hex, type HolderChangePeriod, type HolderSupplyTier, type HttpMethod, type IngestKnowledgeBaseInput, type IngestKnowledgeBaseResult, type InputTokenInfo, type KBSearchResult, KeyringSettingApi, KnowledgeBase, type KnowledgeBaseEntry, type KnowledgeBaseProvider, type LLMProvider, type LLMProviderConfig, type LLMResponse, type LLMToolCall, type LendingMarket, type LendingMarketCardProps, LendingMarketDetailTool, type LendingMarketDetailToolConfig, type LendingMarketListProps, type LendingMarketOverview, LendingMarketsTool, type LendingMarketsToolConfig, type LendingProtocolType, LendingReadService, LendingService, type LendingServiceConfig, type LendingSupplyPosition, LendingSupplyService, MULTICALL3_ADDRESS, ManageLiquidityRedirectTool, type MarketplaceLink, type MoralisApiResponse, MoralisService, type MoralisServiceConfig, type MulticallParameters, type MulticallRawParameters, type MulticallResult, NATIVE_GAS_LIMIT, NFC_AGENT_TOOL_NAMES, NFC_AMAZON_DEFAULT_DOMAIN, NFC_AMAZON_DOMAINS, type NFTCollectionItem, NFTContractInfoTool, type NFTContractMetadata, type NFTItem, type NFTLastSale, type NFTMetadata, NFTMetadataTool, NFT_AGENT_TOOL_NAMES, type NativeActionKind, type NativeGasGap, type NativeTokenInfo, NfcBuyTool, NfcInfoTool, type NftTransferLastSale, NoFormTool, type NoFormToolMessages, OpenAddLiquidityFormTool, type OpenAddLiquidityFormToolConfig, OpenSupplyFormTool, type OpenSupplyFormToolConfig, POOL_AGENT_TOOL_NAMES, PantographService, type PantographServiceConfig, type PantographYieldIdentity, type PaymentToken, PoolByAddressTool, type PoolByAddressToolConfig, PoolDetailTool, type PoolDetailToolConfig, type PoolDisplayInfo, PoolFallbackAiTool, type PoolFallbackAiToolConfig, type PoolOnchainInfo, PoolPriceRangesTool, type PoolPriceRangesToolConfig, PoolSearchTool, type PoolSearchToolConfig, PoolService, type PoolServiceConfig, PoolSwapRouter, type PresetInputs, PreviewAddLiquidityTool, type PreviewAddLiquidityToolConfig, type PriceBounds, type PriceRangePrefill, type ProviderName, PublicClient, type PublicClientConfig, type QuickRate, type QuoteGas, type RangePreset, type ReActPhase, type ReActStep, type ReActTrace, type ReadContractParameters, RelayProvider, type ResolvedRange, Router, type RouterAssignment, type RouterDecision, SUPPLIABLE_TYPES, SUPPORTED_CHAINS, SUPPORTED_CHAINS_LABEL, SWAP_PROVIDER_CONFIG, SendNativeTool, SendNftTool, SendTokenTool, type SpendableBalance, type StateOverride, type StorageProvider, Subagent, type SubagentCard, type SubagentOptions, type SubagentParams, type SubagentResult, type SubagentTask, type SubagentToggles, SubgraphAddPoolTool, type SubgraphAddPoolToolConfig, SubgraphCoinPoolPairsTool, type SubgraphCoinPoolPairsToolConfig, SubgraphPoolByAddressTool, type SubgraphPoolByAddressToolConfig, SubgraphPoolByPositionIdTool, type SubgraphPoolByPositionIdToolConfig, SubgraphPoolSearchTool, type SubgraphPoolSearchToolConfig, SubgraphPositionDetailTool, type SubgraphPositionDetailToolConfig, SubgraphTrendingPoolsTool, type SubgraphTrendingPoolsToolConfig, type SuggestedAction, Summarizer, type SuppliableMarket, type SupplyProtocolType, type SupplyUsdcProps, type SupportedChainId, type SupportedChainName, type SwapProviderConfig, type SwapProviderConfigMap, SwapProviderFactory, type SwapQuoteParams, type SwapQuoteResult, type SwapRoute, type SwapRouteRequest, SwapRouter, SwapRouterRegistry, type SwapTokenFormProps, SwapTokenTool, type SwapTxData, Synthesizer, TOKEN_AGENT_TOOL_NAMES, TRANSFER_TOPIC, TRENDING_DEFAULT_BY_HEX_CHAIN, type TokenAnalyticsResponse, type TokenAnalyticsTimeframeBuckets, TokenAnalyticsTool, type TokenAnalyticsToolConfig, type TokenApproval, type TokenApprovalSpender, type TokenApprovalToken, type TokenBalance, type TokenDisplay, type TokenHoldersResponse, TokenHoldersTool, type TokenHoldersToolConfig, TokenInfoTool, type TokenInfoToolConfig, type TokenMetadata, type TokenScoreMetrics, type TokenScoreResponse, type TokenScoreSupply, type TokenScoreTimeframeBuckets, TokenScoreTool, type TokenScoreToolConfig, type Tool, type ToolDefinition, type ToolKind, type ToolParameter, ToolRegistry, type ToolResult, type TopGainerTimeFrames, type TopGainerToken, type TopGainersTimeFrame, TopGainersTool, type TopGainersToolConfig, TopPoolsTool, type TopPoolsToolConfig, type TrackStatus, type TrackTransactionParams, type TrackTransactionResult, type TransactionByHashResponse, TransactionByHashTool, type TransactionByHashToolConfig, type TransactionLog, type TransactionReceipt, type TransactionReceiptLog, type Transport, type TransportConfig, type TrendingToken, type TrendingTokenTimeframeBuckets, TrendingTokensTool, type TrendingTokensToolConfig, type UIPayload, UNISWAP_CHAIN_SLUG, UNRESOLVED_ASSET, type UnsignedTx, type UpstashEmbedStrategy, type UpstashFusionAlgorithm, type UpstashKBUpsertEntry, UpstashKnowledgeBase, type UpstashKnowledgeBaseConfig, type UserContext, UserSwapRouter, type VectorKBConfig, WALLET_ACTION_AGENT_TOOL_NAMES, WALLET_AGENT_TOOL_NAMES, type WalletActionProps, type WalletActionType, type WalletApprovalsResponse, WalletApprovalsTool, type WalletApprovalsToolConfig, type WalletDefiPositionSummary, WalletDefiPositionsTool, type WalletDefiPositionsToolConfig, type WalletDefiPositionsV1Response, type WalletDefiProtocolPositionsResponse, WalletDefiProtocolPositionsTool, type WalletDefiProtocolPositionsToolConfig, type WalletDefiProtocolPositionsV1Response, type WalletDefiSummaryResponse, type WalletDefiSummaryV1Response, type WalletHistoryCategory, type WalletHistoryContractInteraction, type WalletHistoryErc20Transfer, type WalletHistoryItem, type WalletHistoryNativeTransfer, type WalletHistoryNftTransfer, type WalletHistoryResponse, WalletHistoryTool, type WalletHistoryToolConfig, WalletLendingPositionsTool, type WalletLendingPositionsToolConfig, WalletNFTsTool, type WalletNFTsToolConfig, type WalletNftCardProps, type WalletNftListProps, type WalletNftTransferItem, type WalletNftTransfersResponse, WalletNftTransfersTool, type WalletNftTransfersToolConfig, type WalletPnlDaysWindow, type WalletPnlResponse, type WalletPnlSummaryResponse, WalletPnlSummaryTool, type WalletPnlSummaryToolConfig, type WalletPnlTokenItem, WalletPnlTool, type WalletPnlToolConfig, WalletTokenBalancesTool, type WalletTokenBalancesToolConfig, type WalletTokenTransferItem, type WalletTokenTransfersResponse, WalletTokenTransfersTool, type WalletTokenTransfersToolConfig, type WebsiteTrustExtraData, type WebsiteTrustInput, WebsiteTrustKeyringAgent, type WebsiteTrustKeyringAgentConfig, type WebsiteTrustResult, type X402Authorization, type X402Challenge, type X402Display, type X402Outcome, type X402PaymentRequiredProps, type X402Receipt, type X402RequestSpec, type X402Requirements, type X402SignRequest, type X402Signer, type X402TypedData, type X402Version, type YieldConversionCall, type YieldConversionPlan, type YieldPricingOptions, type YieldPricingToken, type YieldTokenInput, type YieldTokenValue, ZERO_ADDRESS, amazonDomainForLanguage, apiClient, applyYieldConversions, buildApprovals, buildChallenge, buildRangePresets, buildUniswapPoolUrl, call, chains, checkNativeGasAffordable, checksumAddress, clampTick, clearPublicClientCache, coinpoolConfigApi, compareDecimal, completeX402, configureSupportedChains, configureSwapProvider, convertSusdsShares, createAiAgent, createDefaultSubagents, createNfcAgent, createNftAgent, createPoolAgent, createPublicClient, createTokenAgent, createTransport, createWalletActionAgent, createWalletAgent, createX402SignatureProvider, decodeAbiParameters, decodeErrorResult, decodeFunctionData, decodeFunctionResult, displayFromChallenge, effectivePriceUSD, encodeAbiParameters, encodeApprove, encodeErrorResult, encodeFunctionData, encodeSignedHeader, erc1155Abi, erc20Abi, erc20Abi_bytes32, erc721Abi, estimateGas, estimateNativeGasReserveWei, estimateTransactionFeeWei, ethCallAt, ethCallByChain, exactAmountString, extractOutRaw, extractQuoteError, fallback, feeWeiToNative, fetchTopMarketplaces, floorToDecimals, getAbiItem, getAddress, getBalance, getBlock, getBlockNumber, getChain, getChainContractAddress, getChainId, getChainMeta, getCode, getDefaultRpcUrl, getGasPrice, getNativeTokenInfo, getPublicClient, getRevertReason, getRpcOverrides, getStorageAt, getTokenPriceUSD, getTransactionCount, http, humanToWei, ingestKnowledgeBase, isAbortError, isAddress, isAddressEqual, isPaymentRequired, isShareBasedProtocol, isShareBasedYieldToken, isSupplyChain, keyringSettingApi, listCandidateChains, listSupplyChains, mulDivFloor, multicall, multicall3Abi, multicallRaw, nativeGasShortfall, nfcAmazonSearchUrl, normaliseCountry, normalizeDecimal, normalizePriceRangeToPool, parseAbi, parseAbiItem, parseAbiParameters, pickLogo, planYieldTokenConversions, priceToTick, protocolLabelFor, psm3For, readContract, readPaymentError, readPaymentRequired, readProtocolFeeWei, readReceipt, readSpendableBalance, registerMaybeNoForm, requestWithX402, resolveGasLimit, resolveNfcShopLinks, resolveRpcUrl, resolveRpcUrls, resolveTokenPriceUSD, roundTickToSpacing, rpcCall, setRpcOverrides, spendableNative, swapProviderFactory, swapRouterRegistry, tickToPrice, toEventSelector, toFunctionSelector, toPantographChain, toPlainDecimal, valueYieldTokens, weiToHuman };
|