@continuumdao/ctm-mpc-defi 0.1.3

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.
Files changed (65) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +111 -0
  3. package/dist/agent/catalog.cjs +484 -0
  4. package/dist/agent/catalog.cjs.map +1 -0
  5. package/dist/agent/catalog.d.cts +117 -0
  6. package/dist/agent/catalog.d.ts +117 -0
  7. package/dist/agent/catalog.js +474 -0
  8. package/dist/agent/catalog.js.map +1 -0
  9. package/dist/chains/evm/index.cjs +474 -0
  10. package/dist/chains/evm/index.cjs.map +1 -0
  11. package/dist/chains/evm/index.d.cts +62 -0
  12. package/dist/chains/evm/index.d.ts +62 -0
  13. package/dist/chains/evm/index.js +459 -0
  14. package/dist/chains/evm/index.js.map +1 -0
  15. package/dist/chains/near/index.cjs +25 -0
  16. package/dist/chains/near/index.cjs.map +1 -0
  17. package/dist/chains/near/index.d.cts +37 -0
  18. package/dist/chains/near/index.d.ts +37 -0
  19. package/dist/chains/near/index.js +20 -0
  20. package/dist/chains/near/index.js.map +1 -0
  21. package/dist/chains/solana/index.cjs +25 -0
  22. package/dist/chains/solana/index.cjs.map +1 -0
  23. package/dist/chains/solana/index.d.cts +40 -0
  24. package/dist/chains/solana/index.d.ts +40 -0
  25. package/dist/chains/solana/index.js +20 -0
  26. package/dist/chains/solana/index.js.map +1 -0
  27. package/dist/core/index.cjs +128 -0
  28. package/dist/core/index.cjs.map +1 -0
  29. package/dist/core/index.d.cts +10 -0
  30. package/dist/core/index.d.ts +10 -0
  31. package/dist/core/index.js +116 -0
  32. package/dist/core/index.js.map +1 -0
  33. package/dist/envelope-CcE5Cz_q.d.ts +35 -0
  34. package/dist/envelope-DYDPnrHZ.d.cts +35 -0
  35. package/dist/index.cjs +2481 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +15 -0
  38. package/dist/index.d.ts +15 -0
  39. package/dist/index.js +2446 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/keygen-CfNp8yKJ.d.cts +9 -0
  42. package/dist/keygen-DsINazx8.d.ts +9 -0
  43. package/dist/nodeRead-BnmSaMGO.d.cts +8 -0
  44. package/dist/nodeRead-BnmSaMGO.d.ts +8 -0
  45. package/dist/protocols/evm/curve-dao/index.cjs +869 -0
  46. package/dist/protocols/evm/curve-dao/index.cjs.map +1 -0
  47. package/dist/protocols/evm/curve-dao/index.d.cts +147 -0
  48. package/dist/protocols/evm/curve-dao/index.d.ts +147 -0
  49. package/dist/protocols/evm/curve-dao/index.js +846 -0
  50. package/dist/protocols/evm/curve-dao/index.js.map +1 -0
  51. package/dist/protocols/evm/uniswap-v4/index.cjs +1700 -0
  52. package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -0
  53. package/dist/protocols/evm/uniswap-v4/index.d.cts +323 -0
  54. package/dist/protocols/evm/uniswap-v4/index.d.ts +323 -0
  55. package/dist/protocols/evm/uniswap-v4/index.js +1659 -0
  56. package/dist/protocols/evm/uniswap-v4/index.js.map +1 -0
  57. package/dist/registry-BwZoE668.d.cts +8 -0
  58. package/dist/registry-oMKlO_5z.d.ts +8 -0
  59. package/dist/txParams-BC7ogvdR.d.cts +19 -0
  60. package/dist/txParams-BC7ogvdR.d.ts +19 -0
  61. package/dist/types-5u863Fd9.d.ts +34 -0
  62. package/dist/types-B8idm_gu.d.cts +34 -0
  63. package/dist/types-Ce2qNHai.d.cts +57 -0
  64. package/dist/types-Ce2qNHai.d.ts +57 -0
  65. package/package.json +94 -0
@@ -0,0 +1,323 @@
1
+ import { d as ProtocolModule } from '../../../types-Ce2qNHai.cjs';
2
+ import { Address } from 'viem';
3
+ import { N as NodeReadAuth } from '../../../nodeRead-BnmSaMGO.cjs';
4
+ import { K as KeyGenSubsetForPermit } from '../../../keygen-CfNp8yKJ.cjs';
5
+ import { E as EvmChainDetail } from '../../../types-B8idm_gu.cjs';
6
+
7
+ /** Canonical Uniswap token-allowance contract on most EVM chains. */
8
+ declare const PERMIT2_ADDRESS: Address;
9
+ declare function isUniswapV4ChainSupported(chainId: string | number | bigint | null | undefined): boolean;
10
+ declare function getUniswapUniversalRouterSpenderOrThrow(chainId: number): Address;
11
+ declare const MAX_UINT160: bigint;
12
+ declare const MAX_UINT48: bigint;
13
+ declare const UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS = 1500000n;
14
+ declare const UNISWAP_TRADE_BASE_DEFAULT = "https://trade-api.gateway.uniswap.org/v1";
15
+ declare const UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT = "2.0";
16
+ declare const UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES = 30;
17
+ declare const UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET: number;
18
+
19
+ /** POST /v1/quote `type` (same as `uniswap_trade_quote.py` `--type`). */
20
+ type UniswapQuoteTradeType = 'EXACT_INPUT' | 'EXACT_OUTPUT';
21
+ /** Parse chain id like Python: decimal or 0x hex. */
22
+ declare function parseUniswapChainId(value: string | number): number;
23
+ /** `tokenIn` is the EVM address `0x0` used by the Trade API for the chain’s native (gas) token. */
24
+ declare function isUniswapTokenInAddressNative(tokenIn: string | undefined | null): boolean;
25
+ /** `fullQuote` / stored quote response: top-level or nested has `quote.input` with a native or ERC-20 address. */
26
+ declare function isUniswapFullQuoteResponseNativeIn(stored: Record<string, unknown> | null | undefined): boolean;
27
+ /**
28
+ * GET /getKeyGenResultById and return `ethereumaddress` (swapper), same as
29
+ * `uniswap_mpc_helpers.resolve_owner_from_keygen` in mpc-config.
30
+ */
31
+ declare function fetchEthereumAddressForKeyGen(managementNodeUrl: string, keyGenId: string, readAuth?: NodeReadAuth, init?: RequestInit): Promise<string>;
32
+ interface UniswapTradeQuoteParams {
33
+ amount: string;
34
+ tokenIn: string;
35
+ tokenOut: string;
36
+ uniswapApiKey: string;
37
+ /**
38
+ * KeyGen id — used to resolve `swapper` from GET /getKeyGenResultById unless `swapper` is set.
39
+ * Required unless `swapper` is set.
40
+ */
41
+ keyGen?: string;
42
+ type: UniswapQuoteTradeType;
43
+ /**
44
+ * Slippage as percent, e.g. `0.5` for 0.5%. If omitted, the body uses
45
+ * `autoSlippage: "DEFAULT"` (same as the Python script when `--slippage` is not set).
46
+ */
47
+ slippage?: number | string;
48
+ /**
49
+ * Chain id for the input side (`tokenInChainId` in the HTTP body; Python `--chain-id`).
50
+ * You may set **`chainId` or `tokenInChainId`** (same meaning); if both are set, `chainId` wins.
51
+ * Same-chain quote: set one chain here and omit `tokenOutChainId` (or set both to the same id).
52
+ */
53
+ chainId?: string | number;
54
+ /**
55
+ * Same as `chainId` (input chain). If `chainId` is omitted, this must be set.
56
+ */
57
+ tokenInChainId?: string | number;
58
+ /**
59
+ * Output chain id; defaults to the input chain when omitted (Python: empty `--token-out-chain-id`).
60
+ */
61
+ tokenOutChainId?: string | number;
62
+ /**
63
+ * When `true`, sends `x-permit2-disabled: true` (Uniswap’s header for classic ERC-20 allowance; no permitData in the response).
64
+ * Omit or set `false` for the default Trade API routing (default).
65
+ */
66
+ permit2Disabled?: boolean;
67
+ /**
68
+ * MPC wallet (swapper) address. If omitted, `managementNodeUrl` is used with `keyGen`
69
+ * to call GET /getKeyGenResultById.
70
+ */
71
+ swapper?: `0x${string}` | string;
72
+ /**
73
+ * Management node base URL (MPC), required when `swapper` is not provided.
74
+ */
75
+ managementNodeUrl?: string;
76
+ /** For Browser HTTPS: Bearer on GET to /getKeyGenResultById. */
77
+ nodeReadAuth?: NodeReadAuth;
78
+ /** Trade API base without `/quote` (default: Uniswap gateway v1). */
79
+ baseUrl?: string;
80
+ /** `x-universal-router-version` (default `2.0`, aligned with Python / v4). */
81
+ universalRouterVersion?: string;
82
+ signal?: AbortSignal;
83
+ /** Override for tests. */
84
+ fetchImpl?: typeof fetch;
85
+ }
86
+ declare function buildUniswapQuoteRequestBody(args: Pick<UniswapTradeQuoteParams, 'type' | 'amount' | 'tokenIn' | 'tokenOut' | 'slippage' | 'chainId' | 'tokenInChainId' | 'tokenOutChainId'> & {
87
+ swapper: string;
88
+ }): Record<string, unknown>;
89
+ /**
90
+ * Pull a user-facing string from Uniswap / generic JSON error bodies.
91
+ */
92
+ declare function errorMessageFromUniswapJsonBody(value: unknown): string | null;
93
+ /**
94
+ * User-facing string from an HTTP body: JSON `message` / `error` / `detail` first,
95
+ * else a short plain-text / HTML page title, not the raw document (avoids huge HTML in UI).
96
+ */
97
+ declare function messageFromUniswapHttpResponseBody(text: string, status: number, statusText?: string): string;
98
+ /**
99
+ * `POST` Uniswap Trade API `/v1/quote` — TypeScript version of
100
+ * `mpc-config/recipes/uniswapV4/uniswap_trade_quote.py` (core HTTP call + KeyGen → swapper).
101
+ *
102
+ * CORS: calling the Trade API from a browser may be blocked. Prefer a server / route
103
+ * handler, or use this in Node. KeyGen resolution uses a GET to your management node
104
+ * and follows the same read-auth pattern as the app.
105
+ */
106
+ declare function uniswapTradeQuote(args: UniswapTradeQuoteParams): Promise<Record<string, unknown>>;
107
+ /**
108
+ * Single-line JSON for mpc-config `uniswap_trade_swap.py --quote-json` (compact quote body).
109
+ */
110
+ declare function uniswapQuoteToJsonQuoteOneLine(quote: Record<string, unknown>): string;
111
+ /**
112
+ * `quote.input.amount` / `quote.output.amount` as bigints, if present (classic response).
113
+ */
114
+ declare function parseUniswapQuoteClassicInOut(res: Record<string, unknown>): {
115
+ inputWei: bigint;
116
+ outputWei: bigint;
117
+ } | null;
118
+ /**
119
+ * Fields from Uniswap Trade API `200` `quote` (e.g. {@link https://api-docs.uniswap.org/api-reference/swapping/quote} `ClassicQuote`):
120
+ * - `slippage` — slippage tolerance (percent) used for the quote
121
+ * - `priceImpact` — “impact the trade has on the market price of the pool, between 0-100 percent”
122
+ */
123
+ declare function parseUniswapQuoteSlippageInfo(res: Record<string, unknown>): {
124
+ slippageTolerancePercent: number | null;
125
+ priceImpactPercent: number | null;
126
+ };
127
+ /** Compact percent for UI (e.g. 0.5, 1.2345). */
128
+ declare function formatUniswapPercentForUi(n: number): string;
129
+ /** Human string for a modal amount field, trimmed of trailing fraction zeros. */
130
+ declare function formatUniswapAmountFieldFromWei(wei: bigint, decimals: number): string;
131
+ /**
132
+ * One-line prefill for multi-sign "purpose" (user may append context below in the same field).
133
+ */
134
+ declare function buildUniswapV4PurposePrefill(args: {
135
+ tradeType: UniswapQuoteTradeType;
136
+ tokenInSymbol: string;
137
+ tokenOutSymbol: string;
138
+ tokenInDecimals: number;
139
+ tokenOutDecimals: number;
140
+ amountInput: string;
141
+ quote: Record<string, unknown> | null;
142
+ slippageInput: string;
143
+ chainName: string;
144
+ chainId: number;
145
+ }): string;
146
+ /**
147
+ * Human-readable lines from a Trade API `/quote` 200 JSON body.
148
+ * Classic quotes expose `quote.input` / `quote.output` with `amount` (base units as string).
149
+ */
150
+ declare function formatUniswapQuoteForDisplay(res: Record<string, unknown>, args: {
151
+ tradeType: UniswapQuoteTradeType;
152
+ tokenInDecimals: number;
153
+ tokenOutDecimals: number;
154
+ tokenInSymbol: string;
155
+ tokenOutSymbol: string;
156
+ }): {
157
+ title: string;
158
+ lines: string[];
159
+ rawJson: string;
160
+ };
161
+
162
+ /**
163
+ * When `batchIndex` is set, allow per-item `batchMeta[i].evm` when present; else top-level `evm` in ExtraJSON.
164
+ */
165
+ declare function isUniswapV4SwapEvmSignRequest(detail: Record<string, unknown> | null | undefined, batchIndex?: number): boolean;
166
+ /**
167
+ * Gas units for Get Sig without `eth_estimateGas` (same calldata often reverts on estimate).
168
+ * Order: proposal row[i] (or [0] / single `txParams`) / ExtraJSON uniswapV4 (audit, quote).
169
+ * Pass `batchIndex` when the sign request is a multi-tx batch.
170
+ */
171
+ declare function resolveRouterSwapGasUnitsFromSignRequest(detail: Record<string, unknown> | null | undefined, batchIndex?: number): bigint | null;
172
+
173
+ /** `deadline` = `now` + `expiryMinutes * 60` (seconds). */
174
+ declare function swapTransactionDeadlineUnixFromExpiryMinutes(expiryMinutes: number, nowSec?: number): number;
175
+ /** The stored `uniswapTradeQuote` is the full `POST /quote` JSON; `/swap` wants the **inner** classic quote. */
176
+ declare function getClassicQuoteFromStoredUniswapResponse(stored: Record<string, unknown> | null | undefined): unknown;
177
+ type TransactionRequest = {
178
+ to: string;
179
+ from?: string;
180
+ data: string;
181
+ value: string;
182
+ /** Trade API or eth-style field name */
183
+ gasLimit?: string;
184
+ gas?: string;
185
+ chainId?: number;
186
+ };
187
+ type CreateSwapResponse = {
188
+ requestId?: string;
189
+ swap: TransactionRequest;
190
+ gasFee?: string;
191
+ };
192
+ /**
193
+ * `POST /v1/swap` — builds swap calldata (Universal Router) from a quote fetched with classic-allowance header `x-permit2-disabled: true`.
194
+ * @see https://api-docs.uniswap.org/api-reference/swapping/swap
195
+ */
196
+ declare function uniswapCreateSwap(args: {
197
+ uniswapApiKey: string;
198
+ baseUrl?: string;
199
+ /** Full `POST /quote` JSON (must include classic `quote`). */
200
+ fullQuoteFromPermit: Record<string, unknown>;
201
+ universalRouterVersion?: string;
202
+ fetchImpl?: typeof fetch;
203
+ /**
204
+ * In the browser, direct `POST` to `trade-api.gateway.uniswap.org` is blocked by CORS.
205
+ * When true (default in browser), the request goes to same-origin `POST /api/uniswap/swap` which proxies server-side. Set `false` to force a direct call (e.g. tests, Node scripts).
206
+ */
207
+ useServerProxy?: boolean;
208
+ /**
209
+ * Universal Router swap deadline (unix seconds). Defaults to now + {@link UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET}.
210
+ * Omitting this caused short API defaults and `TransactionDeadlinePassed` after MPC delay.
211
+ */
212
+ swapTransactionDeadlineUnix?: number;
213
+ }): Promise<CreateSwapResponse>;
214
+ type ChainRow = {
215
+ legacy?: boolean;
216
+ gasLimit?: number;
217
+ gasMultiplier?: number;
218
+ gasPrice?: number;
219
+ baseFee?: number;
220
+ priorityFee?: number;
221
+ baseFeeMultiplier?: number;
222
+ };
223
+ /**
224
+ * Apply UI slippage % on top of the base approve amount (EXACT_OUTPUT only at call sites; basis points, ceil wei).
225
+ * Example: 0.5% → multiply by 1.005 (10050/10000). `undefined` / non‑positive leaves `baseWei` unchanged.
226
+ */
227
+ declare function applySlippagePercentToApproveWei(baseWei: bigint, slippagePercent: number | undefined): bigint;
228
+ type UniswapV4SkipPermit2BatchArg = {
229
+ keyGen: KeyGenSubsetForPermit;
230
+ chainId: number;
231
+ rpcUrl: string;
232
+ chainDetail: ChainRow;
233
+ useCustomGas: boolean;
234
+ customGasChainDetails?: Record<string, unknown> | null;
235
+ /** `0x0` = native (ETH) in; otherwise ERC-20. */
236
+ tokenIn: Address;
237
+ executorAddress: Address;
238
+ swap: TransactionRequest;
239
+ createSwapResponse: {
240
+ requestId?: string;
241
+ gasFee?: string;
242
+ swap: TransactionRequest;
243
+ };
244
+ fullQuoteSnapshot: Record<string, unknown>;
245
+ purposeText: string;
246
+ swapDeadlineUnix: number;
247
+ slippagePercent?: number;
248
+ };
249
+ /**
250
+ * **Classic ERC-20 allowance** batch (on-chain approvals only), two shapes:
251
+ *
252
+ * - **`swap.to` == inner `router` (calldata arg)** — Universal Router is the tx target; tokens move via the **allowance hub**:
253
+ * `ERC20→hub`, hub `approve(router)`, swap (3 txs).
254
+ *
255
+ * - **`swap.to` ≠ inner `router`** — Trade uses a **dispatcher** that calls `ERC20.transferFrom` with **`msg.sender` = `swap.to`**.
256
+ * Approving only the hub is insufficient (`cast run` shows `transfer amount exceeds allowance`). Path:
257
+ * `ERC20.approve(swap.to)`, swap (2 txs).
258
+ *
259
+ * Approved amount: `max(quote.input, calldata amount)`; with **EXACT_OUTPUT** trades, multiply by `(1 + slippage%)` from the quote modal (input can grow vs the quoted figure).
260
+ */
261
+ declare function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args: UniswapV4SkipPermit2BatchArg): Promise<{
262
+ bodyForSign: Record<string, unknown>;
263
+ messageToSign: string;
264
+ }>;
265
+
266
+ type UniswapV4SessionPayload = {
267
+ chainId: number;
268
+ rpcUrl: string;
269
+ chainSupported: boolean;
270
+ universalRouter?: string;
271
+ };
272
+ declare function computeUniswapV4Session(args: {
273
+ assetsChainId: string | number;
274
+ rpcUrl: string | undefined;
275
+ protocolEnabled: boolean;
276
+ }): UniswapV4SessionPayload;
277
+
278
+ type SwapExactInputArgs = {
279
+ keyGen: KeyGenSubsetForPermit;
280
+ purposeText: string;
281
+ chainId: number;
282
+ rpcUrl: string;
283
+ executorAddress: Address;
284
+ chainDetail: EvmChainDetail;
285
+ useCustomGas: boolean;
286
+ customGasChainDetails?: Record<string, unknown> | null;
287
+ tokenIn: Address;
288
+ uniswapApiKey: string;
289
+ fullQuote: Record<string, unknown>;
290
+ slippagePercent?: number;
291
+ swapTransactionDeadlineUnix?: number;
292
+ baseUrl?: string;
293
+ };
294
+ /** Quote then build swap multisign body for EXACT_INPUT (caller must have fetched quote first for EXACT_OUTPUT). */
295
+ declare function swapFromQuote(args: SwapExactInputArgs & {
296
+ swap: Awaited<ReturnType<typeof uniswapCreateSwap>>;
297
+ }): Promise<{
298
+ bodyForSign: Record<string, unknown>;
299
+ messageToSign: string;
300
+ }>;
301
+ declare function quoteSwap(args: Parameters<typeof uniswapTradeQuote>[0]): Promise<Record<string, unknown>>;
302
+ declare function createSwap(args: Parameters<typeof uniswapCreateSwap>[0]): Promise<Awaited<ReturnType<typeof uniswapCreateSwap>>>;
303
+ declare function swapExactInput(args: SwapExactInputArgs & {
304
+ tradeType?: UniswapQuoteTradeType;
305
+ }): Promise<{
306
+ bodyForSign: Record<string, unknown>;
307
+ messageToSign: string;
308
+ }>;
309
+
310
+ declare const UNISWAP_V4_PROTOCOL_ID = "uniswap-v4";
311
+ declare const uniswapV4ProtocolModule: ProtocolModule;
312
+
313
+ declare const uniswapV4: {
314
+ quoteSwap: typeof quoteSwap;
315
+ createSwap: typeof createSwap;
316
+ swapExactInput: typeof swapExactInput;
317
+ swapFromQuote: typeof swapFromQuote;
318
+ buildSwapMultisignBody: typeof buildEvmMultisignBodyUniswapV4SkipPermit2Batch;
319
+ quote: typeof uniswapTradeQuote;
320
+ isChainSupported: typeof isUniswapV4ChainSupported;
321
+ };
322
+
323
+ export { MAX_UINT160, MAX_UINT48, PERMIT2_ADDRESS, type SwapExactInputArgs, UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES, UNISWAP_TRADE_BASE_DEFAULT, UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS, UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT, UNISWAP_V4_PROTOCOL_ID, type UniswapQuoteTradeType, type UniswapTradeQuoteParams, type UniswapV4SessionPayload, applySlippagePercentToApproveWei, buildEvmMultisignBodyUniswapV4SkipPermit2Batch, buildUniswapQuoteRequestBody, buildUniswapV4PurposePrefill, computeUniswapV4Session, createSwap, errorMessageFromUniswapJsonBody, fetchEthereumAddressForKeyGen, formatUniswapAmountFieldFromWei, formatUniswapPercentForUi, formatUniswapQuoteForDisplay, getClassicQuoteFromStoredUniswapResponse, getUniswapUniversalRouterSpenderOrThrow, isUniswapFullQuoteResponseNativeIn, isUniswapTokenInAddressNative, isUniswapV4ChainSupported, isUniswapV4SwapEvmSignRequest, messageFromUniswapHttpResponseBody, parseUniswapChainId, parseUniswapQuoteClassicInOut, parseUniswapQuoteSlippageInfo, quoteSwap, resolveRouterSwapGasUnitsFromSignRequest, swapExactInput, swapFromQuote, swapTransactionDeadlineUnixFromExpiryMinutes, uniswapCreateSwap, uniswapQuoteToJsonQuoteOneLine, uniswapTradeQuote, uniswapV4, uniswapV4ProtocolModule };
@@ -0,0 +1,323 @@
1
+ import { d as ProtocolModule } from '../../../types-Ce2qNHai.js';
2
+ import { Address } from 'viem';
3
+ import { N as NodeReadAuth } from '../../../nodeRead-BnmSaMGO.js';
4
+ import { K as KeyGenSubsetForPermit } from '../../../keygen-DsINazx8.js';
5
+ import { E as EvmChainDetail } from '../../../types-5u863Fd9.js';
6
+
7
+ /** Canonical Uniswap token-allowance contract on most EVM chains. */
8
+ declare const PERMIT2_ADDRESS: Address;
9
+ declare function isUniswapV4ChainSupported(chainId: string | number | bigint | null | undefined): boolean;
10
+ declare function getUniswapUniversalRouterSpenderOrThrow(chainId: number): Address;
11
+ declare const MAX_UINT160: bigint;
12
+ declare const MAX_UINT48: bigint;
13
+ declare const UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS = 1500000n;
14
+ declare const UNISWAP_TRADE_BASE_DEFAULT = "https://trade-api.gateway.uniswap.org/v1";
15
+ declare const UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT = "2.0";
16
+ declare const UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES = 30;
17
+ declare const UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET: number;
18
+
19
+ /** POST /v1/quote `type` (same as `uniswap_trade_quote.py` `--type`). */
20
+ type UniswapQuoteTradeType = 'EXACT_INPUT' | 'EXACT_OUTPUT';
21
+ /** Parse chain id like Python: decimal or 0x hex. */
22
+ declare function parseUniswapChainId(value: string | number): number;
23
+ /** `tokenIn` is the EVM address `0x0` used by the Trade API for the chain’s native (gas) token. */
24
+ declare function isUniswapTokenInAddressNative(tokenIn: string | undefined | null): boolean;
25
+ /** `fullQuote` / stored quote response: top-level or nested has `quote.input` with a native or ERC-20 address. */
26
+ declare function isUniswapFullQuoteResponseNativeIn(stored: Record<string, unknown> | null | undefined): boolean;
27
+ /**
28
+ * GET /getKeyGenResultById and return `ethereumaddress` (swapper), same as
29
+ * `uniswap_mpc_helpers.resolve_owner_from_keygen` in mpc-config.
30
+ */
31
+ declare function fetchEthereumAddressForKeyGen(managementNodeUrl: string, keyGenId: string, readAuth?: NodeReadAuth, init?: RequestInit): Promise<string>;
32
+ interface UniswapTradeQuoteParams {
33
+ amount: string;
34
+ tokenIn: string;
35
+ tokenOut: string;
36
+ uniswapApiKey: string;
37
+ /**
38
+ * KeyGen id — used to resolve `swapper` from GET /getKeyGenResultById unless `swapper` is set.
39
+ * Required unless `swapper` is set.
40
+ */
41
+ keyGen?: string;
42
+ type: UniswapQuoteTradeType;
43
+ /**
44
+ * Slippage as percent, e.g. `0.5` for 0.5%. If omitted, the body uses
45
+ * `autoSlippage: "DEFAULT"` (same as the Python script when `--slippage` is not set).
46
+ */
47
+ slippage?: number | string;
48
+ /**
49
+ * Chain id for the input side (`tokenInChainId` in the HTTP body; Python `--chain-id`).
50
+ * You may set **`chainId` or `tokenInChainId`** (same meaning); if both are set, `chainId` wins.
51
+ * Same-chain quote: set one chain here and omit `tokenOutChainId` (or set both to the same id).
52
+ */
53
+ chainId?: string | number;
54
+ /**
55
+ * Same as `chainId` (input chain). If `chainId` is omitted, this must be set.
56
+ */
57
+ tokenInChainId?: string | number;
58
+ /**
59
+ * Output chain id; defaults to the input chain when omitted (Python: empty `--token-out-chain-id`).
60
+ */
61
+ tokenOutChainId?: string | number;
62
+ /**
63
+ * When `true`, sends `x-permit2-disabled: true` (Uniswap’s header for classic ERC-20 allowance; no permitData in the response).
64
+ * Omit or set `false` for the default Trade API routing (default).
65
+ */
66
+ permit2Disabled?: boolean;
67
+ /**
68
+ * MPC wallet (swapper) address. If omitted, `managementNodeUrl` is used with `keyGen`
69
+ * to call GET /getKeyGenResultById.
70
+ */
71
+ swapper?: `0x${string}` | string;
72
+ /**
73
+ * Management node base URL (MPC), required when `swapper` is not provided.
74
+ */
75
+ managementNodeUrl?: string;
76
+ /** For Browser HTTPS: Bearer on GET to /getKeyGenResultById. */
77
+ nodeReadAuth?: NodeReadAuth;
78
+ /** Trade API base without `/quote` (default: Uniswap gateway v1). */
79
+ baseUrl?: string;
80
+ /** `x-universal-router-version` (default `2.0`, aligned with Python / v4). */
81
+ universalRouterVersion?: string;
82
+ signal?: AbortSignal;
83
+ /** Override for tests. */
84
+ fetchImpl?: typeof fetch;
85
+ }
86
+ declare function buildUniswapQuoteRequestBody(args: Pick<UniswapTradeQuoteParams, 'type' | 'amount' | 'tokenIn' | 'tokenOut' | 'slippage' | 'chainId' | 'tokenInChainId' | 'tokenOutChainId'> & {
87
+ swapper: string;
88
+ }): Record<string, unknown>;
89
+ /**
90
+ * Pull a user-facing string from Uniswap / generic JSON error bodies.
91
+ */
92
+ declare function errorMessageFromUniswapJsonBody(value: unknown): string | null;
93
+ /**
94
+ * User-facing string from an HTTP body: JSON `message` / `error` / `detail` first,
95
+ * else a short plain-text / HTML page title, not the raw document (avoids huge HTML in UI).
96
+ */
97
+ declare function messageFromUniswapHttpResponseBody(text: string, status: number, statusText?: string): string;
98
+ /**
99
+ * `POST` Uniswap Trade API `/v1/quote` — TypeScript version of
100
+ * `mpc-config/recipes/uniswapV4/uniswap_trade_quote.py` (core HTTP call + KeyGen → swapper).
101
+ *
102
+ * CORS: calling the Trade API from a browser may be blocked. Prefer a server / route
103
+ * handler, or use this in Node. KeyGen resolution uses a GET to your management node
104
+ * and follows the same read-auth pattern as the app.
105
+ */
106
+ declare function uniswapTradeQuote(args: UniswapTradeQuoteParams): Promise<Record<string, unknown>>;
107
+ /**
108
+ * Single-line JSON for mpc-config `uniswap_trade_swap.py --quote-json` (compact quote body).
109
+ */
110
+ declare function uniswapQuoteToJsonQuoteOneLine(quote: Record<string, unknown>): string;
111
+ /**
112
+ * `quote.input.amount` / `quote.output.amount` as bigints, if present (classic response).
113
+ */
114
+ declare function parseUniswapQuoteClassicInOut(res: Record<string, unknown>): {
115
+ inputWei: bigint;
116
+ outputWei: bigint;
117
+ } | null;
118
+ /**
119
+ * Fields from Uniswap Trade API `200` `quote` (e.g. {@link https://api-docs.uniswap.org/api-reference/swapping/quote} `ClassicQuote`):
120
+ * - `slippage` — slippage tolerance (percent) used for the quote
121
+ * - `priceImpact` — “impact the trade has on the market price of the pool, between 0-100 percent”
122
+ */
123
+ declare function parseUniswapQuoteSlippageInfo(res: Record<string, unknown>): {
124
+ slippageTolerancePercent: number | null;
125
+ priceImpactPercent: number | null;
126
+ };
127
+ /** Compact percent for UI (e.g. 0.5, 1.2345). */
128
+ declare function formatUniswapPercentForUi(n: number): string;
129
+ /** Human string for a modal amount field, trimmed of trailing fraction zeros. */
130
+ declare function formatUniswapAmountFieldFromWei(wei: bigint, decimals: number): string;
131
+ /**
132
+ * One-line prefill for multi-sign "purpose" (user may append context below in the same field).
133
+ */
134
+ declare function buildUniswapV4PurposePrefill(args: {
135
+ tradeType: UniswapQuoteTradeType;
136
+ tokenInSymbol: string;
137
+ tokenOutSymbol: string;
138
+ tokenInDecimals: number;
139
+ tokenOutDecimals: number;
140
+ amountInput: string;
141
+ quote: Record<string, unknown> | null;
142
+ slippageInput: string;
143
+ chainName: string;
144
+ chainId: number;
145
+ }): string;
146
+ /**
147
+ * Human-readable lines from a Trade API `/quote` 200 JSON body.
148
+ * Classic quotes expose `quote.input` / `quote.output` with `amount` (base units as string).
149
+ */
150
+ declare function formatUniswapQuoteForDisplay(res: Record<string, unknown>, args: {
151
+ tradeType: UniswapQuoteTradeType;
152
+ tokenInDecimals: number;
153
+ tokenOutDecimals: number;
154
+ tokenInSymbol: string;
155
+ tokenOutSymbol: string;
156
+ }): {
157
+ title: string;
158
+ lines: string[];
159
+ rawJson: string;
160
+ };
161
+
162
+ /**
163
+ * When `batchIndex` is set, allow per-item `batchMeta[i].evm` when present; else top-level `evm` in ExtraJSON.
164
+ */
165
+ declare function isUniswapV4SwapEvmSignRequest(detail: Record<string, unknown> | null | undefined, batchIndex?: number): boolean;
166
+ /**
167
+ * Gas units for Get Sig without `eth_estimateGas` (same calldata often reverts on estimate).
168
+ * Order: proposal row[i] (or [0] / single `txParams`) / ExtraJSON uniswapV4 (audit, quote).
169
+ * Pass `batchIndex` when the sign request is a multi-tx batch.
170
+ */
171
+ declare function resolveRouterSwapGasUnitsFromSignRequest(detail: Record<string, unknown> | null | undefined, batchIndex?: number): bigint | null;
172
+
173
+ /** `deadline` = `now` + `expiryMinutes * 60` (seconds). */
174
+ declare function swapTransactionDeadlineUnixFromExpiryMinutes(expiryMinutes: number, nowSec?: number): number;
175
+ /** The stored `uniswapTradeQuote` is the full `POST /quote` JSON; `/swap` wants the **inner** classic quote. */
176
+ declare function getClassicQuoteFromStoredUniswapResponse(stored: Record<string, unknown> | null | undefined): unknown;
177
+ type TransactionRequest = {
178
+ to: string;
179
+ from?: string;
180
+ data: string;
181
+ value: string;
182
+ /** Trade API or eth-style field name */
183
+ gasLimit?: string;
184
+ gas?: string;
185
+ chainId?: number;
186
+ };
187
+ type CreateSwapResponse = {
188
+ requestId?: string;
189
+ swap: TransactionRequest;
190
+ gasFee?: string;
191
+ };
192
+ /**
193
+ * `POST /v1/swap` — builds swap calldata (Universal Router) from a quote fetched with classic-allowance header `x-permit2-disabled: true`.
194
+ * @see https://api-docs.uniswap.org/api-reference/swapping/swap
195
+ */
196
+ declare function uniswapCreateSwap(args: {
197
+ uniswapApiKey: string;
198
+ baseUrl?: string;
199
+ /** Full `POST /quote` JSON (must include classic `quote`). */
200
+ fullQuoteFromPermit: Record<string, unknown>;
201
+ universalRouterVersion?: string;
202
+ fetchImpl?: typeof fetch;
203
+ /**
204
+ * In the browser, direct `POST` to `trade-api.gateway.uniswap.org` is blocked by CORS.
205
+ * When true (default in browser), the request goes to same-origin `POST /api/uniswap/swap` which proxies server-side. Set `false` to force a direct call (e.g. tests, Node scripts).
206
+ */
207
+ useServerProxy?: boolean;
208
+ /**
209
+ * Universal Router swap deadline (unix seconds). Defaults to now + {@link UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET}.
210
+ * Omitting this caused short API defaults and `TransactionDeadlinePassed` after MPC delay.
211
+ */
212
+ swapTransactionDeadlineUnix?: number;
213
+ }): Promise<CreateSwapResponse>;
214
+ type ChainRow = {
215
+ legacy?: boolean;
216
+ gasLimit?: number;
217
+ gasMultiplier?: number;
218
+ gasPrice?: number;
219
+ baseFee?: number;
220
+ priorityFee?: number;
221
+ baseFeeMultiplier?: number;
222
+ };
223
+ /**
224
+ * Apply UI slippage % on top of the base approve amount (EXACT_OUTPUT only at call sites; basis points, ceil wei).
225
+ * Example: 0.5% → multiply by 1.005 (10050/10000). `undefined` / non‑positive leaves `baseWei` unchanged.
226
+ */
227
+ declare function applySlippagePercentToApproveWei(baseWei: bigint, slippagePercent: number | undefined): bigint;
228
+ type UniswapV4SkipPermit2BatchArg = {
229
+ keyGen: KeyGenSubsetForPermit;
230
+ chainId: number;
231
+ rpcUrl: string;
232
+ chainDetail: ChainRow;
233
+ useCustomGas: boolean;
234
+ customGasChainDetails?: Record<string, unknown> | null;
235
+ /** `0x0` = native (ETH) in; otherwise ERC-20. */
236
+ tokenIn: Address;
237
+ executorAddress: Address;
238
+ swap: TransactionRequest;
239
+ createSwapResponse: {
240
+ requestId?: string;
241
+ gasFee?: string;
242
+ swap: TransactionRequest;
243
+ };
244
+ fullQuoteSnapshot: Record<string, unknown>;
245
+ purposeText: string;
246
+ swapDeadlineUnix: number;
247
+ slippagePercent?: number;
248
+ };
249
+ /**
250
+ * **Classic ERC-20 allowance** batch (on-chain approvals only), two shapes:
251
+ *
252
+ * - **`swap.to` == inner `router` (calldata arg)** — Universal Router is the tx target; tokens move via the **allowance hub**:
253
+ * `ERC20→hub`, hub `approve(router)`, swap (3 txs).
254
+ *
255
+ * - **`swap.to` ≠ inner `router`** — Trade uses a **dispatcher** that calls `ERC20.transferFrom` with **`msg.sender` = `swap.to`**.
256
+ * Approving only the hub is insufficient (`cast run` shows `transfer amount exceeds allowance`). Path:
257
+ * `ERC20.approve(swap.to)`, swap (2 txs).
258
+ *
259
+ * Approved amount: `max(quote.input, calldata amount)`; with **EXACT_OUTPUT** trades, multiply by `(1 + slippage%)` from the quote modal (input can grow vs the quoted figure).
260
+ */
261
+ declare function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args: UniswapV4SkipPermit2BatchArg): Promise<{
262
+ bodyForSign: Record<string, unknown>;
263
+ messageToSign: string;
264
+ }>;
265
+
266
+ type UniswapV4SessionPayload = {
267
+ chainId: number;
268
+ rpcUrl: string;
269
+ chainSupported: boolean;
270
+ universalRouter?: string;
271
+ };
272
+ declare function computeUniswapV4Session(args: {
273
+ assetsChainId: string | number;
274
+ rpcUrl: string | undefined;
275
+ protocolEnabled: boolean;
276
+ }): UniswapV4SessionPayload;
277
+
278
+ type SwapExactInputArgs = {
279
+ keyGen: KeyGenSubsetForPermit;
280
+ purposeText: string;
281
+ chainId: number;
282
+ rpcUrl: string;
283
+ executorAddress: Address;
284
+ chainDetail: EvmChainDetail;
285
+ useCustomGas: boolean;
286
+ customGasChainDetails?: Record<string, unknown> | null;
287
+ tokenIn: Address;
288
+ uniswapApiKey: string;
289
+ fullQuote: Record<string, unknown>;
290
+ slippagePercent?: number;
291
+ swapTransactionDeadlineUnix?: number;
292
+ baseUrl?: string;
293
+ };
294
+ /** Quote then build swap multisign body for EXACT_INPUT (caller must have fetched quote first for EXACT_OUTPUT). */
295
+ declare function swapFromQuote(args: SwapExactInputArgs & {
296
+ swap: Awaited<ReturnType<typeof uniswapCreateSwap>>;
297
+ }): Promise<{
298
+ bodyForSign: Record<string, unknown>;
299
+ messageToSign: string;
300
+ }>;
301
+ declare function quoteSwap(args: Parameters<typeof uniswapTradeQuote>[0]): Promise<Record<string, unknown>>;
302
+ declare function createSwap(args: Parameters<typeof uniswapCreateSwap>[0]): Promise<Awaited<ReturnType<typeof uniswapCreateSwap>>>;
303
+ declare function swapExactInput(args: SwapExactInputArgs & {
304
+ tradeType?: UniswapQuoteTradeType;
305
+ }): Promise<{
306
+ bodyForSign: Record<string, unknown>;
307
+ messageToSign: string;
308
+ }>;
309
+
310
+ declare const UNISWAP_V4_PROTOCOL_ID = "uniswap-v4";
311
+ declare const uniswapV4ProtocolModule: ProtocolModule;
312
+
313
+ declare const uniswapV4: {
314
+ quoteSwap: typeof quoteSwap;
315
+ createSwap: typeof createSwap;
316
+ swapExactInput: typeof swapExactInput;
317
+ swapFromQuote: typeof swapFromQuote;
318
+ buildSwapMultisignBody: typeof buildEvmMultisignBodyUniswapV4SkipPermit2Batch;
319
+ quote: typeof uniswapTradeQuote;
320
+ isChainSupported: typeof isUniswapV4ChainSupported;
321
+ };
322
+
323
+ export { MAX_UINT160, MAX_UINT48, PERMIT2_ADDRESS, type SwapExactInputArgs, UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES, UNISWAP_TRADE_BASE_DEFAULT, UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS, UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT, UNISWAP_V4_PROTOCOL_ID, type UniswapQuoteTradeType, type UniswapTradeQuoteParams, type UniswapV4SessionPayload, applySlippagePercentToApproveWei, buildEvmMultisignBodyUniswapV4SkipPermit2Batch, buildUniswapQuoteRequestBody, buildUniswapV4PurposePrefill, computeUniswapV4Session, createSwap, errorMessageFromUniswapJsonBody, fetchEthereumAddressForKeyGen, formatUniswapAmountFieldFromWei, formatUniswapPercentForUi, formatUniswapQuoteForDisplay, getClassicQuoteFromStoredUniswapResponse, getUniswapUniversalRouterSpenderOrThrow, isUniswapFullQuoteResponseNativeIn, isUniswapTokenInAddressNative, isUniswapV4ChainSupported, isUniswapV4SwapEvmSignRequest, messageFromUniswapHttpResponseBody, parseUniswapChainId, parseUniswapQuoteClassicInOut, parseUniswapQuoteSlippageInfo, quoteSwap, resolveRouterSwapGasUnitsFromSignRequest, swapExactInput, swapFromQuote, swapTransactionDeadlineUnixFromExpiryMinutes, uniswapCreateSwap, uniswapQuoteToJsonQuoteOneLine, uniswapTradeQuote, uniswapV4, uniswapV4ProtocolModule };