@megaflow-labs/sdk 0.1.0
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/CHANGELOG.md +47 -0
- package/README.md +259 -0
- package/dist/index.d.mts +1641 -0
- package/dist/index.d.ts +1641 -0
- package/dist/index.js +1375 -0
- package/dist/index.mjs +1326 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1641 @@
|
|
|
1
|
+
import { Chain, Address, Hex, Hash, TransactionReceipt, PublicClient, WalletClient, Account } from 'viem';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MegaETH Chain Definitions
|
|
5
|
+
*
|
|
6
|
+
* Source: https://docs.megaeth.com / megaeth-ai-developer-skills
|
|
7
|
+
* Chain IDs verified from official wallet-operations.md docs.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* MegaETH Mainnet
|
|
12
|
+
* Chain ID: 4326
|
|
13
|
+
* RPC: https://mainnet.megaeth.com/rpc
|
|
14
|
+
*/
|
|
15
|
+
declare const megaethMainnet: {
|
|
16
|
+
readonly id: 4326;
|
|
17
|
+
readonly name: "MegaETH Mainnet";
|
|
18
|
+
readonly nativeCurrency: {
|
|
19
|
+
readonly decimals: 18;
|
|
20
|
+
readonly name: "Ether";
|
|
21
|
+
readonly symbol: "ETH";
|
|
22
|
+
};
|
|
23
|
+
readonly rpcUrls: {
|
|
24
|
+
readonly default: {
|
|
25
|
+
readonly http: readonly ["https://mainnet.megaeth.com/rpc"];
|
|
26
|
+
readonly webSocket: readonly ["wss://mainnet.megaeth.com/ws"];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly blockExplorers: {
|
|
30
|
+
readonly default: {
|
|
31
|
+
readonly name: "MegaETH Explorer";
|
|
32
|
+
readonly url: "https://mega.etherscan.io";
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* MegaETH Testnet (Carrot)
|
|
38
|
+
* Chain ID: 6343
|
|
39
|
+
* RPC: https://carrot.megaeth.com/rpc
|
|
40
|
+
*/
|
|
41
|
+
declare const megaethTestnet: {
|
|
42
|
+
readonly id: 6343;
|
|
43
|
+
readonly name: "MegaETH Testnet";
|
|
44
|
+
readonly nativeCurrency: {
|
|
45
|
+
readonly decimals: 18;
|
|
46
|
+
readonly name: "Ether";
|
|
47
|
+
readonly symbol: "ETH";
|
|
48
|
+
};
|
|
49
|
+
readonly rpcUrls: {
|
|
50
|
+
readonly default: {
|
|
51
|
+
readonly http: readonly ["https://carrot.megaeth.com/rpc"];
|
|
52
|
+
readonly webSocket: readonly ["wss://carrot.megaeth.com/ws"];
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
readonly blockExplorers: {
|
|
56
|
+
readonly default: {
|
|
57
|
+
readonly name: "MegaETH Testnet Explorer";
|
|
58
|
+
readonly url: "https://megaeth-testnet-v2.blockscout.com";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
readonly testnet: true;
|
|
62
|
+
};
|
|
63
|
+
/** All supported MegaETH chains */
|
|
64
|
+
declare const megaethChains: readonly [{
|
|
65
|
+
readonly id: 4326;
|
|
66
|
+
readonly name: "MegaETH Mainnet";
|
|
67
|
+
readonly nativeCurrency: {
|
|
68
|
+
readonly decimals: 18;
|
|
69
|
+
readonly name: "Ether";
|
|
70
|
+
readonly symbol: "ETH";
|
|
71
|
+
};
|
|
72
|
+
readonly rpcUrls: {
|
|
73
|
+
readonly default: {
|
|
74
|
+
readonly http: readonly ["https://mainnet.megaeth.com/rpc"];
|
|
75
|
+
readonly webSocket: readonly ["wss://mainnet.megaeth.com/ws"];
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
readonly blockExplorers: {
|
|
79
|
+
readonly default: {
|
|
80
|
+
readonly name: "MegaETH Explorer";
|
|
81
|
+
readonly url: "https://mega.etherscan.io";
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}, {
|
|
85
|
+
readonly id: 6343;
|
|
86
|
+
readonly name: "MegaETH Testnet";
|
|
87
|
+
readonly nativeCurrency: {
|
|
88
|
+
readonly decimals: 18;
|
|
89
|
+
readonly name: "Ether";
|
|
90
|
+
readonly symbol: "ETH";
|
|
91
|
+
};
|
|
92
|
+
readonly rpcUrls: {
|
|
93
|
+
readonly default: {
|
|
94
|
+
readonly http: readonly ["https://carrot.megaeth.com/rpc"];
|
|
95
|
+
readonly webSocket: readonly ["wss://carrot.megaeth.com/ws"];
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
readonly blockExplorers: {
|
|
99
|
+
readonly default: {
|
|
100
|
+
readonly name: "MegaETH Testnet Explorer";
|
|
101
|
+
readonly url: "https://megaeth-testnet-v2.blockscout.com";
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
readonly testnet: true;
|
|
105
|
+
}];
|
|
106
|
+
/** Chain ID → Chain lookup */
|
|
107
|
+
declare const chainById: Record<number, Chain>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* MegaFlow SDK Types
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A single call operation in a batch.
|
|
115
|
+
* Mirrors the `Call` struct in MegaRouter.sol.
|
|
116
|
+
*/
|
|
117
|
+
interface MegaCall {
|
|
118
|
+
/** Target contract address */
|
|
119
|
+
target: Address;
|
|
120
|
+
/** ETH value to send with the call (wei) */
|
|
121
|
+
value: bigint;
|
|
122
|
+
/** ABI-encoded function call */
|
|
123
|
+
callData: Hex;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Result from a single call in the batch.
|
|
127
|
+
* Mirrors the `Result` struct in MegaRouter.sol.
|
|
128
|
+
*/
|
|
129
|
+
interface MegaCallResult {
|
|
130
|
+
/** Whether the call succeeded */
|
|
131
|
+
success: boolean;
|
|
132
|
+
/** Raw bytes returned from the call */
|
|
133
|
+
returnData: Hex;
|
|
134
|
+
}
|
|
135
|
+
/** Full result after executing a batch (standard async flow) */
|
|
136
|
+
interface MegaFlowExecutionResult {
|
|
137
|
+
/** Transaction hash */
|
|
138
|
+
hash: Hash;
|
|
139
|
+
/** Full transaction receipt */
|
|
140
|
+
receipt: TransactionReceipt;
|
|
141
|
+
/** Per-call results decoded from receipt logs */
|
|
142
|
+
results: MegaCallResult[];
|
|
143
|
+
/** Gas used for the whole batch */
|
|
144
|
+
gasUsed: bigint;
|
|
145
|
+
/** Effective gas price */
|
|
146
|
+
effectiveGasPrice: bigint;
|
|
147
|
+
/** Total cost in wei (gasUsed * effectiveGasPrice) */
|
|
148
|
+
totalCost: bigint;
|
|
149
|
+
}
|
|
150
|
+
/** Result from executeSync (eth_sendRawTransactionSync) */
|
|
151
|
+
interface MegaFlowSyncResult {
|
|
152
|
+
/** Full transaction receipt (no hash separate — already included) */
|
|
153
|
+
receipt: TransactionReceipt;
|
|
154
|
+
/** Per-call results */
|
|
155
|
+
results: MegaCallResult[];
|
|
156
|
+
/** Gas used */
|
|
157
|
+
gasUsed: bigint;
|
|
158
|
+
/** Execution time in milliseconds (client-side measured) */
|
|
159
|
+
executionTimeMs: number;
|
|
160
|
+
}
|
|
161
|
+
/** Simulation / dry-run result */
|
|
162
|
+
interface MegaFlowSimulationResult {
|
|
163
|
+
/** Whether simulation succeeded */
|
|
164
|
+
success: boolean;
|
|
165
|
+
/** Per-call simulated results (only if success) */
|
|
166
|
+
results?: MegaCallResult[];
|
|
167
|
+
/** Gas estimate for the batch */
|
|
168
|
+
gasEstimate?: bigint;
|
|
169
|
+
/** Error message (only if failed) */
|
|
170
|
+
error?: string;
|
|
171
|
+
/** Decoded revert reason (if available) */
|
|
172
|
+
revertReason?: string;
|
|
173
|
+
/** Index of the failed call (if determinable) */
|
|
174
|
+
failedCallIndex?: number;
|
|
175
|
+
}
|
|
176
|
+
/** Options for execute() and executeSync() */
|
|
177
|
+
interface ExecuteOptions {
|
|
178
|
+
/** Gas limit override */
|
|
179
|
+
gasLimit?: bigint;
|
|
180
|
+
/** Max fee per gas override */
|
|
181
|
+
maxFeePerGas?: bigint;
|
|
182
|
+
/** Max priority fee override */
|
|
183
|
+
maxPriorityFeePerGas?: bigint;
|
|
184
|
+
/** Nonce override */
|
|
185
|
+
nonce?: number;
|
|
186
|
+
}
|
|
187
|
+
/** Configuration for creating a MegaFlowBuilder */
|
|
188
|
+
interface MegaFlowConfig {
|
|
189
|
+
/** Deployed MegaRouter contract address. Defaults to MAINNET_ROUTER_ADDRESS. */
|
|
190
|
+
routerAddress?: Address;
|
|
191
|
+
/** Override RPC URL. Defaults to chain's public endpoint. */
|
|
192
|
+
rpcUrl?: string;
|
|
193
|
+
/** Chain to operate on. Defaults to megaethMainnet. */
|
|
194
|
+
chain?: Chain;
|
|
195
|
+
/** Enable debug logging */
|
|
196
|
+
debug?: boolean;
|
|
197
|
+
}
|
|
198
|
+
/** Configuration for MegaFlowClient */
|
|
199
|
+
interface MegaFlowClientConfig extends MegaFlowConfig {
|
|
200
|
+
/** Pre-configured viem PublicClient (optional) */
|
|
201
|
+
publicClient?: PublicClient;
|
|
202
|
+
/** Pre-configured viem WalletClient (optional) */
|
|
203
|
+
walletClient?: WalletClient;
|
|
204
|
+
}
|
|
205
|
+
interface SwapParams {
|
|
206
|
+
router: Address;
|
|
207
|
+
amountIn: bigint;
|
|
208
|
+
amountOutMin: bigint;
|
|
209
|
+
path: Address[];
|
|
210
|
+
to: Address;
|
|
211
|
+
deadline?: bigint;
|
|
212
|
+
}
|
|
213
|
+
interface ApproveAndSwapParams extends SwapParams {
|
|
214
|
+
token: Address;
|
|
215
|
+
/** Current on-chain allowance (for safe approve pattern) */
|
|
216
|
+
currentAllowance?: bigint;
|
|
217
|
+
}
|
|
218
|
+
interface TransferParams {
|
|
219
|
+
token: Address;
|
|
220
|
+
to: Address;
|
|
221
|
+
amount: bigint;
|
|
222
|
+
}
|
|
223
|
+
interface KyberQuoteParams {
|
|
224
|
+
tokenIn: Address | 'ETH';
|
|
225
|
+
tokenOut: Address | 'ETH';
|
|
226
|
+
amountIn: bigint;
|
|
227
|
+
/** Slippage in basis points (e.g. 50 = 0.5%) */
|
|
228
|
+
slippageBps?: number;
|
|
229
|
+
}
|
|
230
|
+
interface KyberRouteSummary {
|
|
231
|
+
tokenIn: string;
|
|
232
|
+
tokenOut: string;
|
|
233
|
+
amountIn: string;
|
|
234
|
+
amountOut: string;
|
|
235
|
+
gas: string;
|
|
236
|
+
route: unknown[];
|
|
237
|
+
[key: string]: unknown;
|
|
238
|
+
}
|
|
239
|
+
interface KyberBuildResult {
|
|
240
|
+
routerAddress: Address;
|
|
241
|
+
data: Hex;
|
|
242
|
+
value: string;
|
|
243
|
+
gas: string;
|
|
244
|
+
}
|
|
245
|
+
interface BatchExecutedEvent {
|
|
246
|
+
sender: Address;
|
|
247
|
+
callCount: bigint;
|
|
248
|
+
totalValue: bigint;
|
|
249
|
+
blockNumber: bigint;
|
|
250
|
+
transactionHash: Hex;
|
|
251
|
+
}
|
|
252
|
+
interface CallExecutedEvent {
|
|
253
|
+
callIndex: bigint;
|
|
254
|
+
target: Address;
|
|
255
|
+
value: bigint;
|
|
256
|
+
success: boolean;
|
|
257
|
+
blockNumber: bigint;
|
|
258
|
+
transactionHash: Hex;
|
|
259
|
+
}
|
|
260
|
+
type OperationType = 'transfer' | 'approve' | 'safeApprove' | 'swap' | 'wrap' | 'unwrap' | 'kyberSwap' | 'nftTransfer' | 'custom';
|
|
261
|
+
interface RecordedOperation {
|
|
262
|
+
readonly type: OperationType;
|
|
263
|
+
readonly call: MegaCall;
|
|
264
|
+
readonly metadata?: Record<string, unknown>;
|
|
265
|
+
readonly timestamp: number;
|
|
266
|
+
}
|
|
267
|
+
interface BuilderState {
|
|
268
|
+
readonly calls: readonly MegaCall[];
|
|
269
|
+
readonly operations: readonly RecordedOperation[];
|
|
270
|
+
readonly totalValue: bigint;
|
|
271
|
+
readonly chainId: number;
|
|
272
|
+
}
|
|
273
|
+
interface BalanceCheck {
|
|
274
|
+
token: Address | 'ETH';
|
|
275
|
+
required: bigint;
|
|
276
|
+
available: bigint;
|
|
277
|
+
sufficient: boolean;
|
|
278
|
+
}
|
|
279
|
+
interface PreflightResult {
|
|
280
|
+
valid: boolean;
|
|
281
|
+
simulation: MegaFlowSimulationResult;
|
|
282
|
+
balanceChecks: BalanceCheck[];
|
|
283
|
+
estimatedGas: bigint;
|
|
284
|
+
estimatedCost: bigint;
|
|
285
|
+
warnings: string[];
|
|
286
|
+
errors: string[];
|
|
287
|
+
}
|
|
288
|
+
type MegaFlowErrorCode = 'EMPTY_BATCH' | 'WALLET_NOT_CONNECTED' | 'NO_ACCOUNT' | 'SIMULATION_FAILED' | 'EXECUTION_FAILED' | 'INSUFFICIENT_BALANCE' | 'INSUFFICIENT_ALLOWANCE' | 'KYBER_API_ERROR' | 'NETWORK_ERROR' | 'USER_REJECTED' | 'TIMEOUT';
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* MegaFlow SDK Constants & ABIs
|
|
292
|
+
*/
|
|
293
|
+
/**
|
|
294
|
+
* Full ABI for the MegaRouter.sol contract.
|
|
295
|
+
* Keep in sync with contracts/src/MegaRouter.sol
|
|
296
|
+
*/
|
|
297
|
+
declare const MEGA_ROUTER_ABI: readonly [{
|
|
298
|
+
readonly name: "executeBatch";
|
|
299
|
+
readonly type: "function";
|
|
300
|
+
readonly stateMutability: "payable";
|
|
301
|
+
readonly inputs: readonly [{
|
|
302
|
+
readonly type: "tuple[]";
|
|
303
|
+
readonly components: readonly [{
|
|
304
|
+
readonly type: "address";
|
|
305
|
+
readonly name: "target";
|
|
306
|
+
}, {
|
|
307
|
+
readonly type: "uint256";
|
|
308
|
+
readonly name: "value";
|
|
309
|
+
}, {
|
|
310
|
+
readonly type: "bytes";
|
|
311
|
+
readonly name: "callData";
|
|
312
|
+
}];
|
|
313
|
+
readonly name: "calls";
|
|
314
|
+
}];
|
|
315
|
+
readonly outputs: readonly [{
|
|
316
|
+
readonly type: "tuple[]";
|
|
317
|
+
readonly components: readonly [{
|
|
318
|
+
readonly type: "bool";
|
|
319
|
+
readonly name: "success";
|
|
320
|
+
}, {
|
|
321
|
+
readonly type: "bytes";
|
|
322
|
+
readonly name: "returnData";
|
|
323
|
+
}];
|
|
324
|
+
readonly name: "results";
|
|
325
|
+
}];
|
|
326
|
+
}, {
|
|
327
|
+
readonly name: "executeBatchWithOutput";
|
|
328
|
+
readonly type: "function";
|
|
329
|
+
readonly stateMutability: "payable";
|
|
330
|
+
readonly inputs: readonly [{
|
|
331
|
+
readonly type: "tuple[]";
|
|
332
|
+
readonly components: readonly [{
|
|
333
|
+
readonly type: "address";
|
|
334
|
+
readonly name: "target";
|
|
335
|
+
}, {
|
|
336
|
+
readonly type: "uint256";
|
|
337
|
+
readonly name: "value";
|
|
338
|
+
}, {
|
|
339
|
+
readonly type: "bytes";
|
|
340
|
+
readonly name: "callData";
|
|
341
|
+
}];
|
|
342
|
+
readonly name: "calls";
|
|
343
|
+
}, {
|
|
344
|
+
readonly type: "uint256";
|
|
345
|
+
readonly name: "outputCallIndex";
|
|
346
|
+
}, {
|
|
347
|
+
readonly type: "uint256";
|
|
348
|
+
readonly name: "outputOffset";
|
|
349
|
+
}, {
|
|
350
|
+
readonly type: "uint256";
|
|
351
|
+
readonly name: "outputLength";
|
|
352
|
+
}];
|
|
353
|
+
readonly outputs: readonly [{
|
|
354
|
+
readonly type: "tuple[]";
|
|
355
|
+
readonly components: readonly [{
|
|
356
|
+
readonly type: "bool";
|
|
357
|
+
readonly name: "success";
|
|
358
|
+
}, {
|
|
359
|
+
readonly type: "bytes";
|
|
360
|
+
readonly name: "returnData";
|
|
361
|
+
}];
|
|
362
|
+
readonly name: "results";
|
|
363
|
+
}, {
|
|
364
|
+
readonly type: "bytes";
|
|
365
|
+
readonly name: "extractedOutput";
|
|
366
|
+
}];
|
|
367
|
+
}, {
|
|
368
|
+
readonly name: "calculateRequiredETH";
|
|
369
|
+
readonly type: "function";
|
|
370
|
+
readonly stateMutability: "view";
|
|
371
|
+
readonly inputs: readonly [{
|
|
372
|
+
readonly type: "tuple[]";
|
|
373
|
+
readonly components: readonly [{
|
|
374
|
+
readonly type: "address";
|
|
375
|
+
readonly name: "target";
|
|
376
|
+
}, {
|
|
377
|
+
readonly type: "uint256";
|
|
378
|
+
readonly name: "value";
|
|
379
|
+
}, {
|
|
380
|
+
readonly type: "bytes";
|
|
381
|
+
readonly name: "callData";
|
|
382
|
+
}];
|
|
383
|
+
readonly name: "calls";
|
|
384
|
+
}];
|
|
385
|
+
readonly outputs: readonly [{
|
|
386
|
+
readonly type: "uint256";
|
|
387
|
+
}];
|
|
388
|
+
}, {
|
|
389
|
+
readonly name: "flatFee";
|
|
390
|
+
readonly type: "function";
|
|
391
|
+
readonly stateMutability: "view";
|
|
392
|
+
readonly inputs: readonly [];
|
|
393
|
+
readonly outputs: readonly [{
|
|
394
|
+
readonly type: "uint256";
|
|
395
|
+
}];
|
|
396
|
+
}, {
|
|
397
|
+
readonly name: "feeCollector";
|
|
398
|
+
readonly type: "function";
|
|
399
|
+
readonly stateMutability: "view";
|
|
400
|
+
readonly inputs: readonly [];
|
|
401
|
+
readonly outputs: readonly [{
|
|
402
|
+
readonly type: "address";
|
|
403
|
+
}];
|
|
404
|
+
}, {
|
|
405
|
+
readonly name: "BatchExecuted";
|
|
406
|
+
readonly type: "event";
|
|
407
|
+
readonly inputs: readonly [{
|
|
408
|
+
readonly type: "address";
|
|
409
|
+
readonly name: "sender";
|
|
410
|
+
readonly indexed: true;
|
|
411
|
+
}, {
|
|
412
|
+
readonly type: "uint256";
|
|
413
|
+
readonly name: "callCount";
|
|
414
|
+
}, {
|
|
415
|
+
readonly type: "uint256";
|
|
416
|
+
readonly name: "totalValue";
|
|
417
|
+
}];
|
|
418
|
+
}, {
|
|
419
|
+
readonly name: "CallExecuted";
|
|
420
|
+
readonly type: "event";
|
|
421
|
+
readonly inputs: readonly [{
|
|
422
|
+
readonly type: "uint256";
|
|
423
|
+
readonly name: "callIndex";
|
|
424
|
+
readonly indexed: true;
|
|
425
|
+
}, {
|
|
426
|
+
readonly type: "address";
|
|
427
|
+
readonly name: "target";
|
|
428
|
+
readonly indexed: true;
|
|
429
|
+
}, {
|
|
430
|
+
readonly type: "uint256";
|
|
431
|
+
readonly name: "value";
|
|
432
|
+
}, {
|
|
433
|
+
readonly type: "bool";
|
|
434
|
+
readonly name: "success";
|
|
435
|
+
}];
|
|
436
|
+
}, {
|
|
437
|
+
readonly name: "ReentrancyGuard";
|
|
438
|
+
readonly type: "error";
|
|
439
|
+
readonly inputs: readonly [];
|
|
440
|
+
}, {
|
|
441
|
+
readonly name: "InsufficientETH";
|
|
442
|
+
readonly type: "error";
|
|
443
|
+
readonly inputs: readonly [{
|
|
444
|
+
readonly type: "uint256";
|
|
445
|
+
readonly name: "required";
|
|
446
|
+
}, {
|
|
447
|
+
readonly type: "uint256";
|
|
448
|
+
readonly name: "provided";
|
|
449
|
+
}];
|
|
450
|
+
}, {
|
|
451
|
+
readonly name: "InvalidTarget";
|
|
452
|
+
readonly type: "error";
|
|
453
|
+
readonly inputs: readonly [{
|
|
454
|
+
readonly type: "uint256";
|
|
455
|
+
readonly name: "callIndex";
|
|
456
|
+
}];
|
|
457
|
+
}, {
|
|
458
|
+
readonly name: "EmptyCalldata";
|
|
459
|
+
readonly type: "error";
|
|
460
|
+
readonly inputs: readonly [{
|
|
461
|
+
readonly type: "uint256";
|
|
462
|
+
readonly name: "callIndex";
|
|
463
|
+
}];
|
|
464
|
+
}, {
|
|
465
|
+
readonly name: "CallFailed";
|
|
466
|
+
readonly type: "error";
|
|
467
|
+
readonly inputs: readonly [{
|
|
468
|
+
readonly type: "uint256";
|
|
469
|
+
readonly name: "callIndex";
|
|
470
|
+
}, {
|
|
471
|
+
readonly type: "bytes";
|
|
472
|
+
readonly name: "returnData";
|
|
473
|
+
}];
|
|
474
|
+
}, {
|
|
475
|
+
readonly name: "FeeTransferFailed";
|
|
476
|
+
readonly type: "error";
|
|
477
|
+
readonly inputs: readonly [];
|
|
478
|
+
}, {
|
|
479
|
+
readonly name: "SweepFailed";
|
|
480
|
+
readonly type: "error";
|
|
481
|
+
readonly inputs: readonly [];
|
|
482
|
+
}];
|
|
483
|
+
declare const ERC20_ABI: readonly [{
|
|
484
|
+
readonly name: "name";
|
|
485
|
+
readonly type: "function";
|
|
486
|
+
readonly stateMutability: "view";
|
|
487
|
+
readonly inputs: readonly [];
|
|
488
|
+
readonly outputs: readonly [{
|
|
489
|
+
readonly type: "string";
|
|
490
|
+
}];
|
|
491
|
+
}, {
|
|
492
|
+
readonly name: "symbol";
|
|
493
|
+
readonly type: "function";
|
|
494
|
+
readonly stateMutability: "view";
|
|
495
|
+
readonly inputs: readonly [];
|
|
496
|
+
readonly outputs: readonly [{
|
|
497
|
+
readonly type: "string";
|
|
498
|
+
}];
|
|
499
|
+
}, {
|
|
500
|
+
readonly name: "decimals";
|
|
501
|
+
readonly type: "function";
|
|
502
|
+
readonly stateMutability: "view";
|
|
503
|
+
readonly inputs: readonly [];
|
|
504
|
+
readonly outputs: readonly [{
|
|
505
|
+
readonly type: "uint8";
|
|
506
|
+
}];
|
|
507
|
+
}, {
|
|
508
|
+
readonly name: "totalSupply";
|
|
509
|
+
readonly type: "function";
|
|
510
|
+
readonly stateMutability: "view";
|
|
511
|
+
readonly inputs: readonly [];
|
|
512
|
+
readonly outputs: readonly [{
|
|
513
|
+
readonly type: "uint256";
|
|
514
|
+
}];
|
|
515
|
+
}, {
|
|
516
|
+
readonly name: "balanceOf";
|
|
517
|
+
readonly type: "function";
|
|
518
|
+
readonly stateMutability: "view";
|
|
519
|
+
readonly inputs: readonly [{
|
|
520
|
+
readonly type: "address";
|
|
521
|
+
readonly name: "account";
|
|
522
|
+
}];
|
|
523
|
+
readonly outputs: readonly [{
|
|
524
|
+
readonly type: "uint256";
|
|
525
|
+
}];
|
|
526
|
+
}, {
|
|
527
|
+
readonly name: "allowance";
|
|
528
|
+
readonly type: "function";
|
|
529
|
+
readonly stateMutability: "view";
|
|
530
|
+
readonly inputs: readonly [{
|
|
531
|
+
readonly type: "address";
|
|
532
|
+
readonly name: "owner";
|
|
533
|
+
}, {
|
|
534
|
+
readonly type: "address";
|
|
535
|
+
readonly name: "spender";
|
|
536
|
+
}];
|
|
537
|
+
readonly outputs: readonly [{
|
|
538
|
+
readonly type: "uint256";
|
|
539
|
+
}];
|
|
540
|
+
}, {
|
|
541
|
+
readonly name: "transfer";
|
|
542
|
+
readonly type: "function";
|
|
543
|
+
readonly stateMutability: "nonpayable";
|
|
544
|
+
readonly inputs: readonly [{
|
|
545
|
+
readonly type: "address";
|
|
546
|
+
readonly name: "to";
|
|
547
|
+
}, {
|
|
548
|
+
readonly type: "uint256";
|
|
549
|
+
readonly name: "amount";
|
|
550
|
+
}];
|
|
551
|
+
readonly outputs: readonly [{
|
|
552
|
+
readonly type: "bool";
|
|
553
|
+
}];
|
|
554
|
+
}, {
|
|
555
|
+
readonly name: "transferFrom";
|
|
556
|
+
readonly type: "function";
|
|
557
|
+
readonly stateMutability: "nonpayable";
|
|
558
|
+
readonly inputs: readonly [{
|
|
559
|
+
readonly type: "address";
|
|
560
|
+
readonly name: "from";
|
|
561
|
+
}, {
|
|
562
|
+
readonly type: "address";
|
|
563
|
+
readonly name: "to";
|
|
564
|
+
}, {
|
|
565
|
+
readonly type: "uint256";
|
|
566
|
+
readonly name: "amount";
|
|
567
|
+
}];
|
|
568
|
+
readonly outputs: readonly [{
|
|
569
|
+
readonly type: "bool";
|
|
570
|
+
}];
|
|
571
|
+
}, {
|
|
572
|
+
readonly name: "approve";
|
|
573
|
+
readonly type: "function";
|
|
574
|
+
readonly stateMutability: "nonpayable";
|
|
575
|
+
readonly inputs: readonly [{
|
|
576
|
+
readonly type: "address";
|
|
577
|
+
readonly name: "spender";
|
|
578
|
+
}, {
|
|
579
|
+
readonly type: "uint256";
|
|
580
|
+
readonly name: "amount";
|
|
581
|
+
}];
|
|
582
|
+
readonly outputs: readonly [{
|
|
583
|
+
readonly type: "bool";
|
|
584
|
+
}];
|
|
585
|
+
}, {
|
|
586
|
+
readonly name: "Transfer";
|
|
587
|
+
readonly type: "event";
|
|
588
|
+
readonly inputs: readonly [{
|
|
589
|
+
readonly type: "address";
|
|
590
|
+
readonly name: "from";
|
|
591
|
+
readonly indexed: true;
|
|
592
|
+
}, {
|
|
593
|
+
readonly type: "address";
|
|
594
|
+
readonly name: "to";
|
|
595
|
+
readonly indexed: true;
|
|
596
|
+
}, {
|
|
597
|
+
readonly type: "uint256";
|
|
598
|
+
readonly name: "value";
|
|
599
|
+
}];
|
|
600
|
+
}, {
|
|
601
|
+
readonly name: "Approval";
|
|
602
|
+
readonly type: "event";
|
|
603
|
+
readonly inputs: readonly [{
|
|
604
|
+
readonly type: "address";
|
|
605
|
+
readonly name: "owner";
|
|
606
|
+
readonly indexed: true;
|
|
607
|
+
}, {
|
|
608
|
+
readonly type: "address";
|
|
609
|
+
readonly name: "spender";
|
|
610
|
+
readonly indexed: true;
|
|
611
|
+
}, {
|
|
612
|
+
readonly type: "uint256";
|
|
613
|
+
readonly name: "value";
|
|
614
|
+
}];
|
|
615
|
+
}];
|
|
616
|
+
declare const ERC721_ABI: readonly [{
|
|
617
|
+
readonly name: "name";
|
|
618
|
+
readonly type: "function";
|
|
619
|
+
readonly stateMutability: "view";
|
|
620
|
+
readonly inputs: readonly [];
|
|
621
|
+
readonly outputs: readonly [{
|
|
622
|
+
readonly type: "string";
|
|
623
|
+
}];
|
|
624
|
+
}, {
|
|
625
|
+
readonly name: "symbol";
|
|
626
|
+
readonly type: "function";
|
|
627
|
+
readonly stateMutability: "view";
|
|
628
|
+
readonly inputs: readonly [];
|
|
629
|
+
readonly outputs: readonly [{
|
|
630
|
+
readonly type: "string";
|
|
631
|
+
}];
|
|
632
|
+
}, {
|
|
633
|
+
readonly name: "tokenURI";
|
|
634
|
+
readonly type: "function";
|
|
635
|
+
readonly stateMutability: "view";
|
|
636
|
+
readonly inputs: readonly [{
|
|
637
|
+
readonly type: "uint256";
|
|
638
|
+
readonly name: "tokenId";
|
|
639
|
+
}];
|
|
640
|
+
readonly outputs: readonly [{
|
|
641
|
+
readonly type: "string";
|
|
642
|
+
}];
|
|
643
|
+
}, {
|
|
644
|
+
readonly name: "ownerOf";
|
|
645
|
+
readonly type: "function";
|
|
646
|
+
readonly stateMutability: "view";
|
|
647
|
+
readonly inputs: readonly [{
|
|
648
|
+
readonly type: "uint256";
|
|
649
|
+
readonly name: "tokenId";
|
|
650
|
+
}];
|
|
651
|
+
readonly outputs: readonly [{
|
|
652
|
+
readonly type: "address";
|
|
653
|
+
}];
|
|
654
|
+
}, {
|
|
655
|
+
readonly name: "balanceOf";
|
|
656
|
+
readonly type: "function";
|
|
657
|
+
readonly stateMutability: "view";
|
|
658
|
+
readonly inputs: readonly [{
|
|
659
|
+
readonly type: "address";
|
|
660
|
+
readonly name: "owner";
|
|
661
|
+
}];
|
|
662
|
+
readonly outputs: readonly [{
|
|
663
|
+
readonly type: "uint256";
|
|
664
|
+
}];
|
|
665
|
+
}, {
|
|
666
|
+
readonly name: "isApprovedForAll";
|
|
667
|
+
readonly type: "function";
|
|
668
|
+
readonly stateMutability: "view";
|
|
669
|
+
readonly inputs: readonly [{
|
|
670
|
+
readonly type: "address";
|
|
671
|
+
readonly name: "owner";
|
|
672
|
+
}, {
|
|
673
|
+
readonly type: "address";
|
|
674
|
+
readonly name: "operator";
|
|
675
|
+
}];
|
|
676
|
+
readonly outputs: readonly [{
|
|
677
|
+
readonly type: "bool";
|
|
678
|
+
}];
|
|
679
|
+
}, {
|
|
680
|
+
readonly name: "getApproved";
|
|
681
|
+
readonly type: "function";
|
|
682
|
+
readonly stateMutability: "view";
|
|
683
|
+
readonly inputs: readonly [{
|
|
684
|
+
readonly type: "uint256";
|
|
685
|
+
readonly name: "tokenId";
|
|
686
|
+
}];
|
|
687
|
+
readonly outputs: readonly [{
|
|
688
|
+
readonly type: "address";
|
|
689
|
+
}];
|
|
690
|
+
}, {
|
|
691
|
+
readonly name: "transferFrom";
|
|
692
|
+
readonly type: "function";
|
|
693
|
+
readonly stateMutability: "nonpayable";
|
|
694
|
+
readonly inputs: readonly [{
|
|
695
|
+
readonly type: "address";
|
|
696
|
+
readonly name: "from";
|
|
697
|
+
}, {
|
|
698
|
+
readonly type: "address";
|
|
699
|
+
readonly name: "to";
|
|
700
|
+
}, {
|
|
701
|
+
readonly type: "uint256";
|
|
702
|
+
readonly name: "tokenId";
|
|
703
|
+
}];
|
|
704
|
+
readonly outputs: readonly [];
|
|
705
|
+
}, {
|
|
706
|
+
readonly name: "safeTransferFrom";
|
|
707
|
+
readonly type: "function";
|
|
708
|
+
readonly stateMutability: "nonpayable";
|
|
709
|
+
readonly inputs: readonly [{
|
|
710
|
+
readonly type: "address";
|
|
711
|
+
readonly name: "from";
|
|
712
|
+
}, {
|
|
713
|
+
readonly type: "address";
|
|
714
|
+
readonly name: "to";
|
|
715
|
+
}, {
|
|
716
|
+
readonly type: "uint256";
|
|
717
|
+
readonly name: "tokenId";
|
|
718
|
+
}];
|
|
719
|
+
readonly outputs: readonly [];
|
|
720
|
+
}, {
|
|
721
|
+
readonly name: "approve";
|
|
722
|
+
readonly type: "function";
|
|
723
|
+
readonly stateMutability: "nonpayable";
|
|
724
|
+
readonly inputs: readonly [{
|
|
725
|
+
readonly type: "address";
|
|
726
|
+
readonly name: "to";
|
|
727
|
+
}, {
|
|
728
|
+
readonly type: "uint256";
|
|
729
|
+
readonly name: "tokenId";
|
|
730
|
+
}];
|
|
731
|
+
readonly outputs: readonly [];
|
|
732
|
+
}, {
|
|
733
|
+
readonly name: "setApprovalForAll";
|
|
734
|
+
readonly type: "function";
|
|
735
|
+
readonly stateMutability: "nonpayable";
|
|
736
|
+
readonly inputs: readonly [{
|
|
737
|
+
readonly type: "address";
|
|
738
|
+
readonly name: "operator";
|
|
739
|
+
}, {
|
|
740
|
+
readonly type: "bool";
|
|
741
|
+
readonly name: "approved";
|
|
742
|
+
}];
|
|
743
|
+
readonly outputs: readonly [];
|
|
744
|
+
}];
|
|
745
|
+
declare const UNISWAP_V2_ROUTER_ABI: readonly [{
|
|
746
|
+
readonly name: "factory";
|
|
747
|
+
readonly type: "function";
|
|
748
|
+
readonly stateMutability: "pure";
|
|
749
|
+
readonly inputs: readonly [];
|
|
750
|
+
readonly outputs: readonly [{
|
|
751
|
+
readonly type: "address";
|
|
752
|
+
}];
|
|
753
|
+
}, {
|
|
754
|
+
readonly name: "WETH";
|
|
755
|
+
readonly type: "function";
|
|
756
|
+
readonly stateMutability: "pure";
|
|
757
|
+
readonly inputs: readonly [];
|
|
758
|
+
readonly outputs: readonly [{
|
|
759
|
+
readonly type: "address";
|
|
760
|
+
}];
|
|
761
|
+
}, {
|
|
762
|
+
readonly name: "swapExactTokensForTokens";
|
|
763
|
+
readonly type: "function";
|
|
764
|
+
readonly stateMutability: "nonpayable";
|
|
765
|
+
readonly inputs: readonly [{
|
|
766
|
+
readonly name: "amountIn";
|
|
767
|
+
readonly type: "uint256";
|
|
768
|
+
}, {
|
|
769
|
+
readonly name: "amountOutMin";
|
|
770
|
+
readonly type: "uint256";
|
|
771
|
+
}, {
|
|
772
|
+
readonly type: "address[]";
|
|
773
|
+
readonly name: "path";
|
|
774
|
+
}, {
|
|
775
|
+
readonly type: "address";
|
|
776
|
+
readonly name: "to";
|
|
777
|
+
}, {
|
|
778
|
+
readonly name: "deadline";
|
|
779
|
+
readonly type: "uint256";
|
|
780
|
+
}];
|
|
781
|
+
readonly outputs: readonly [{
|
|
782
|
+
readonly name: "amounts";
|
|
783
|
+
readonly type: "uint256[]";
|
|
784
|
+
}];
|
|
785
|
+
}, {
|
|
786
|
+
readonly name: "swapTokensForExactTokens";
|
|
787
|
+
readonly type: "function";
|
|
788
|
+
readonly stateMutability: "nonpayable";
|
|
789
|
+
readonly inputs: readonly [{
|
|
790
|
+
readonly name: "amountOut";
|
|
791
|
+
readonly type: "uint256";
|
|
792
|
+
}, {
|
|
793
|
+
readonly name: "amountInMax";
|
|
794
|
+
readonly type: "uint256";
|
|
795
|
+
}, {
|
|
796
|
+
readonly type: "address[]";
|
|
797
|
+
readonly name: "path";
|
|
798
|
+
}, {
|
|
799
|
+
readonly type: "address";
|
|
800
|
+
readonly name: "to";
|
|
801
|
+
}, {
|
|
802
|
+
readonly name: "deadline";
|
|
803
|
+
readonly type: "uint256";
|
|
804
|
+
}];
|
|
805
|
+
readonly outputs: readonly [{
|
|
806
|
+
readonly name: "amounts";
|
|
807
|
+
readonly type: "uint256[]";
|
|
808
|
+
}];
|
|
809
|
+
}, {
|
|
810
|
+
readonly name: "swapExactETHForTokens";
|
|
811
|
+
readonly type: "function";
|
|
812
|
+
readonly stateMutability: "payable";
|
|
813
|
+
readonly inputs: readonly [{
|
|
814
|
+
readonly name: "amountOutMin";
|
|
815
|
+
readonly type: "uint256";
|
|
816
|
+
}, {
|
|
817
|
+
readonly type: "address[]";
|
|
818
|
+
readonly name: "path";
|
|
819
|
+
}, {
|
|
820
|
+
readonly type: "address";
|
|
821
|
+
readonly name: "to";
|
|
822
|
+
}, {
|
|
823
|
+
readonly name: "deadline";
|
|
824
|
+
readonly type: "uint256";
|
|
825
|
+
}];
|
|
826
|
+
readonly outputs: readonly [{
|
|
827
|
+
readonly name: "amounts";
|
|
828
|
+
readonly type: "uint256[]";
|
|
829
|
+
}];
|
|
830
|
+
}, {
|
|
831
|
+
readonly name: "swapExactTokensForETH";
|
|
832
|
+
readonly type: "function";
|
|
833
|
+
readonly stateMutability: "nonpayable";
|
|
834
|
+
readonly inputs: readonly [{
|
|
835
|
+
readonly name: "amountIn";
|
|
836
|
+
readonly type: "uint256";
|
|
837
|
+
}, {
|
|
838
|
+
readonly name: "amountOutMin";
|
|
839
|
+
readonly type: "uint256";
|
|
840
|
+
}, {
|
|
841
|
+
readonly type: "address[]";
|
|
842
|
+
readonly name: "path";
|
|
843
|
+
}, {
|
|
844
|
+
readonly type: "address";
|
|
845
|
+
readonly name: "to";
|
|
846
|
+
}, {
|
|
847
|
+
readonly name: "deadline";
|
|
848
|
+
readonly type: "uint256";
|
|
849
|
+
}];
|
|
850
|
+
readonly outputs: readonly [{
|
|
851
|
+
readonly name: "amounts";
|
|
852
|
+
readonly type: "uint256[]";
|
|
853
|
+
}];
|
|
854
|
+
}, {
|
|
855
|
+
readonly name: "swapETHForExactTokens";
|
|
856
|
+
readonly type: "function";
|
|
857
|
+
readonly stateMutability: "payable";
|
|
858
|
+
readonly inputs: readonly [{
|
|
859
|
+
readonly name: "amountOut";
|
|
860
|
+
readonly type: "uint256";
|
|
861
|
+
}, {
|
|
862
|
+
readonly type: "address[]";
|
|
863
|
+
readonly name: "path";
|
|
864
|
+
}, {
|
|
865
|
+
readonly type: "address";
|
|
866
|
+
readonly name: "to";
|
|
867
|
+
}, {
|
|
868
|
+
readonly name: "deadline";
|
|
869
|
+
readonly type: "uint256";
|
|
870
|
+
}];
|
|
871
|
+
readonly outputs: readonly [{
|
|
872
|
+
readonly name: "amounts";
|
|
873
|
+
readonly type: "uint256[]";
|
|
874
|
+
}];
|
|
875
|
+
}, {
|
|
876
|
+
readonly name: "getAmountsOut";
|
|
877
|
+
readonly type: "function";
|
|
878
|
+
readonly stateMutability: "view";
|
|
879
|
+
readonly inputs: readonly [{
|
|
880
|
+
readonly name: "amountIn";
|
|
881
|
+
readonly type: "uint256";
|
|
882
|
+
}, {
|
|
883
|
+
readonly type: "address[]";
|
|
884
|
+
readonly name: "path";
|
|
885
|
+
}];
|
|
886
|
+
readonly outputs: readonly [{
|
|
887
|
+
readonly name: "amounts";
|
|
888
|
+
readonly type: "uint256[]";
|
|
889
|
+
}];
|
|
890
|
+
}, {
|
|
891
|
+
readonly name: "getAmountsIn";
|
|
892
|
+
readonly type: "function";
|
|
893
|
+
readonly stateMutability: "view";
|
|
894
|
+
readonly inputs: readonly [{
|
|
895
|
+
readonly name: "amountOut";
|
|
896
|
+
readonly type: "uint256";
|
|
897
|
+
}, {
|
|
898
|
+
readonly type: "address[]";
|
|
899
|
+
readonly name: "path";
|
|
900
|
+
}];
|
|
901
|
+
readonly outputs: readonly [{
|
|
902
|
+
readonly name: "amounts";
|
|
903
|
+
readonly type: "uint256[]";
|
|
904
|
+
}];
|
|
905
|
+
}, {
|
|
906
|
+
readonly name: "addLiquidity";
|
|
907
|
+
readonly type: "function";
|
|
908
|
+
readonly stateMutability: "nonpayable";
|
|
909
|
+
readonly inputs: readonly [{
|
|
910
|
+
readonly type: "address";
|
|
911
|
+
readonly name: "tokenA";
|
|
912
|
+
}, {
|
|
913
|
+
readonly type: "address";
|
|
914
|
+
readonly name: "tokenB";
|
|
915
|
+
}, {
|
|
916
|
+
readonly name: "amountADesired";
|
|
917
|
+
readonly type: "uint256";
|
|
918
|
+
}, {
|
|
919
|
+
readonly name: "amountBDesired";
|
|
920
|
+
readonly type: "uint256";
|
|
921
|
+
}, {
|
|
922
|
+
readonly name: "amountAMin";
|
|
923
|
+
readonly type: "uint256";
|
|
924
|
+
}, {
|
|
925
|
+
readonly name: "amountBMin";
|
|
926
|
+
readonly type: "uint256";
|
|
927
|
+
}, {
|
|
928
|
+
readonly type: "address";
|
|
929
|
+
readonly name: "to";
|
|
930
|
+
}, {
|
|
931
|
+
readonly name: "deadline";
|
|
932
|
+
readonly type: "uint256";
|
|
933
|
+
}];
|
|
934
|
+
readonly outputs: readonly [{
|
|
935
|
+
readonly name: "amountA";
|
|
936
|
+
readonly type: "uint256";
|
|
937
|
+
}, {
|
|
938
|
+
readonly name: "amountB";
|
|
939
|
+
readonly type: "uint256";
|
|
940
|
+
}, {
|
|
941
|
+
readonly name: "liquidity";
|
|
942
|
+
readonly type: "uint256";
|
|
943
|
+
}];
|
|
944
|
+
}, {
|
|
945
|
+
readonly name: "removeLiquidity";
|
|
946
|
+
readonly type: "function";
|
|
947
|
+
readonly stateMutability: "nonpayable";
|
|
948
|
+
readonly inputs: readonly [{
|
|
949
|
+
readonly type: "address";
|
|
950
|
+
readonly name: "tokenA";
|
|
951
|
+
}, {
|
|
952
|
+
readonly type: "address";
|
|
953
|
+
readonly name: "tokenB";
|
|
954
|
+
}, {
|
|
955
|
+
readonly name: "liquidity";
|
|
956
|
+
readonly type: "uint256";
|
|
957
|
+
}, {
|
|
958
|
+
readonly name: "amountAMin";
|
|
959
|
+
readonly type: "uint256";
|
|
960
|
+
}, {
|
|
961
|
+
readonly name: "amountBMin";
|
|
962
|
+
readonly type: "uint256";
|
|
963
|
+
}, {
|
|
964
|
+
readonly type: "address";
|
|
965
|
+
readonly name: "to";
|
|
966
|
+
}, {
|
|
967
|
+
readonly name: "deadline";
|
|
968
|
+
readonly type: "uint256";
|
|
969
|
+
}];
|
|
970
|
+
readonly outputs: readonly [{
|
|
971
|
+
readonly name: "amountA";
|
|
972
|
+
readonly type: "uint256";
|
|
973
|
+
}, {
|
|
974
|
+
readonly name: "amountB";
|
|
975
|
+
readonly type: "uint256";
|
|
976
|
+
}];
|
|
977
|
+
}];
|
|
978
|
+
declare const WETH_ABI: readonly [{
|
|
979
|
+
readonly name: "name";
|
|
980
|
+
readonly type: "function";
|
|
981
|
+
readonly stateMutability: "view";
|
|
982
|
+
readonly inputs: readonly [];
|
|
983
|
+
readonly outputs: readonly [{
|
|
984
|
+
readonly type: "string";
|
|
985
|
+
}];
|
|
986
|
+
}, {
|
|
987
|
+
readonly name: "symbol";
|
|
988
|
+
readonly type: "function";
|
|
989
|
+
readonly stateMutability: "view";
|
|
990
|
+
readonly inputs: readonly [];
|
|
991
|
+
readonly outputs: readonly [{
|
|
992
|
+
readonly type: "string";
|
|
993
|
+
}];
|
|
994
|
+
}, {
|
|
995
|
+
readonly name: "decimals";
|
|
996
|
+
readonly type: "function";
|
|
997
|
+
readonly stateMutability: "view";
|
|
998
|
+
readonly inputs: readonly [];
|
|
999
|
+
readonly outputs: readonly [{
|
|
1000
|
+
readonly type: "uint8";
|
|
1001
|
+
}];
|
|
1002
|
+
}, {
|
|
1003
|
+
readonly name: "totalSupply";
|
|
1004
|
+
readonly type: "function";
|
|
1005
|
+
readonly stateMutability: "view";
|
|
1006
|
+
readonly inputs: readonly [];
|
|
1007
|
+
readonly outputs: readonly [{
|
|
1008
|
+
readonly type: "uint256";
|
|
1009
|
+
}];
|
|
1010
|
+
}, {
|
|
1011
|
+
readonly name: "balanceOf";
|
|
1012
|
+
readonly type: "function";
|
|
1013
|
+
readonly stateMutability: "view";
|
|
1014
|
+
readonly inputs: readonly [{
|
|
1015
|
+
readonly type: "address";
|
|
1016
|
+
readonly name: "account";
|
|
1017
|
+
}];
|
|
1018
|
+
readonly outputs: readonly [{
|
|
1019
|
+
readonly type: "uint256";
|
|
1020
|
+
}];
|
|
1021
|
+
}, {
|
|
1022
|
+
readonly name: "allowance";
|
|
1023
|
+
readonly type: "function";
|
|
1024
|
+
readonly stateMutability: "view";
|
|
1025
|
+
readonly inputs: readonly [{
|
|
1026
|
+
readonly type: "address";
|
|
1027
|
+
readonly name: "owner";
|
|
1028
|
+
}, {
|
|
1029
|
+
readonly type: "address";
|
|
1030
|
+
readonly name: "spender";
|
|
1031
|
+
}];
|
|
1032
|
+
readonly outputs: readonly [{
|
|
1033
|
+
readonly type: "uint256";
|
|
1034
|
+
}];
|
|
1035
|
+
}, {
|
|
1036
|
+
readonly name: "transfer";
|
|
1037
|
+
readonly type: "function";
|
|
1038
|
+
readonly stateMutability: "nonpayable";
|
|
1039
|
+
readonly inputs: readonly [{
|
|
1040
|
+
readonly type: "address";
|
|
1041
|
+
readonly name: "to";
|
|
1042
|
+
}, {
|
|
1043
|
+
readonly type: "uint256";
|
|
1044
|
+
readonly name: "amount";
|
|
1045
|
+
}];
|
|
1046
|
+
readonly outputs: readonly [{
|
|
1047
|
+
readonly type: "bool";
|
|
1048
|
+
}];
|
|
1049
|
+
}, {
|
|
1050
|
+
readonly name: "transferFrom";
|
|
1051
|
+
readonly type: "function";
|
|
1052
|
+
readonly stateMutability: "nonpayable";
|
|
1053
|
+
readonly inputs: readonly [{
|
|
1054
|
+
readonly type: "address";
|
|
1055
|
+
readonly name: "from";
|
|
1056
|
+
}, {
|
|
1057
|
+
readonly type: "address";
|
|
1058
|
+
readonly name: "to";
|
|
1059
|
+
}, {
|
|
1060
|
+
readonly type: "uint256";
|
|
1061
|
+
readonly name: "amount";
|
|
1062
|
+
}];
|
|
1063
|
+
readonly outputs: readonly [{
|
|
1064
|
+
readonly type: "bool";
|
|
1065
|
+
}];
|
|
1066
|
+
}, {
|
|
1067
|
+
readonly name: "approve";
|
|
1068
|
+
readonly type: "function";
|
|
1069
|
+
readonly stateMutability: "nonpayable";
|
|
1070
|
+
readonly inputs: readonly [{
|
|
1071
|
+
readonly type: "address";
|
|
1072
|
+
readonly name: "spender";
|
|
1073
|
+
}, {
|
|
1074
|
+
readonly type: "uint256";
|
|
1075
|
+
readonly name: "amount";
|
|
1076
|
+
}];
|
|
1077
|
+
readonly outputs: readonly [{
|
|
1078
|
+
readonly type: "bool";
|
|
1079
|
+
}];
|
|
1080
|
+
}, {
|
|
1081
|
+
readonly name: "deposit";
|
|
1082
|
+
readonly type: "function";
|
|
1083
|
+
readonly stateMutability: "payable";
|
|
1084
|
+
readonly inputs: readonly [];
|
|
1085
|
+
readonly outputs: readonly [];
|
|
1086
|
+
}, {
|
|
1087
|
+
readonly name: "withdraw";
|
|
1088
|
+
readonly type: "function";
|
|
1089
|
+
readonly stateMutability: "nonpayable";
|
|
1090
|
+
readonly inputs: readonly [{
|
|
1091
|
+
readonly type: "uint256";
|
|
1092
|
+
readonly name: "wad";
|
|
1093
|
+
}];
|
|
1094
|
+
readonly outputs: readonly [];
|
|
1095
|
+
}, {
|
|
1096
|
+
readonly name: "Transfer";
|
|
1097
|
+
readonly type: "event";
|
|
1098
|
+
readonly inputs: readonly [{
|
|
1099
|
+
readonly type: "address";
|
|
1100
|
+
readonly name: "from";
|
|
1101
|
+
readonly indexed: true;
|
|
1102
|
+
}, {
|
|
1103
|
+
readonly type: "address";
|
|
1104
|
+
readonly name: "to";
|
|
1105
|
+
readonly indexed: true;
|
|
1106
|
+
}, {
|
|
1107
|
+
readonly type: "uint256";
|
|
1108
|
+
readonly name: "value";
|
|
1109
|
+
}];
|
|
1110
|
+
}, {
|
|
1111
|
+
readonly name: "Approval";
|
|
1112
|
+
readonly type: "event";
|
|
1113
|
+
readonly inputs: readonly [{
|
|
1114
|
+
readonly type: "address";
|
|
1115
|
+
readonly name: "owner";
|
|
1116
|
+
readonly indexed: true;
|
|
1117
|
+
}, {
|
|
1118
|
+
readonly type: "address";
|
|
1119
|
+
readonly name: "spender";
|
|
1120
|
+
readonly indexed: true;
|
|
1121
|
+
}, {
|
|
1122
|
+
readonly type: "uint256";
|
|
1123
|
+
readonly name: "value";
|
|
1124
|
+
}];
|
|
1125
|
+
}];
|
|
1126
|
+
/**
|
|
1127
|
+
* Known MegaETH gas limits for common operations.
|
|
1128
|
+
* MegaETH intrinsic gas is 60,000 (not 21,000 like Ethereum!).
|
|
1129
|
+
* Source: gas-model.md
|
|
1130
|
+
*/
|
|
1131
|
+
declare const MEGAETH_GAS_LIMITS: {
|
|
1132
|
+
/** Simple ETH transfer — 60k on MegaETH, not 21k */
|
|
1133
|
+
readonly TRANSFER: 60000n;
|
|
1134
|
+
/** ERC20 transfer */
|
|
1135
|
+
readonly ERC20_TRANSFER: 100000n;
|
|
1136
|
+
/** ERC20 approve */
|
|
1137
|
+
readonly ERC20_APPROVE: 80000n;
|
|
1138
|
+
/** DEX swap */
|
|
1139
|
+
readonly SWAP: 350000n;
|
|
1140
|
+
};
|
|
1141
|
+
/** MegaETH stable base fee in wei (0.001 gwei) */
|
|
1142
|
+
declare const MEGAETH_BASE_FEE = 1000000n;
|
|
1143
|
+
declare const MEGAETH_TOKENS: {
|
|
1144
|
+
/** Wrapped ETH */
|
|
1145
|
+
WETH: "0x4200000000000000000000000000000000000006";
|
|
1146
|
+
/** MEGA governance token */
|
|
1147
|
+
MEGA: "0x28B7E77f82B25B95953825F1E3eA0E36c1c29861";
|
|
1148
|
+
/** USDM stablecoin */
|
|
1149
|
+
USDM: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7";
|
|
1150
|
+
};
|
|
1151
|
+
/**
|
|
1152
|
+
* MegaETH L1 bridge contract (on Ethereum mainnet).
|
|
1153
|
+
* Send ETH here to bridge to MegaETH.
|
|
1154
|
+
*/
|
|
1155
|
+
declare const MEGAETH_L1_BRIDGE: "0x0CA3A2FBC3D770b578223FBB6b062fa875a2eE75";
|
|
1156
|
+
/**
|
|
1157
|
+
* KyberSwap Aggregator API base URL for MegaETH.
|
|
1158
|
+
* Source: wallet-operations.md
|
|
1159
|
+
*/
|
|
1160
|
+
declare const KYBERSWAP_API_BASE: "https://aggregator-api.kyberswap.com/megaeth/api/v1";
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* MegaFlow Utility Functions
|
|
1164
|
+
*/
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Parse per-call results from a transaction receipt AND simulateContract result.
|
|
1168
|
+
*
|
|
1169
|
+
* Priority:
|
|
1170
|
+
* 1. Actual `returnData` from `executeBatch()` return value (best — has all returnData)
|
|
1171
|
+
* 2. `CallExecuted` events from the receipt logs (has success flag, no returnData)
|
|
1172
|
+
* 3. Fallback: assume success for all calls
|
|
1173
|
+
*
|
|
1174
|
+
* @param receipt - The transaction receipt
|
|
1175
|
+
* @param callCount - Number of calls in the original batch
|
|
1176
|
+
* @param rawReturnData - Optional: the raw return bytes of `executeBatch` (ABI-encoded Result[])
|
|
1177
|
+
*/
|
|
1178
|
+
declare function parseCallResults(receipt: TransactionReceipt, callCount: number, rawReturnData?: Hex): MegaCallResult[];
|
|
1179
|
+
/**
|
|
1180
|
+
* Parse the `BatchExecuted` event from a transaction receipt.
|
|
1181
|
+
*/
|
|
1182
|
+
declare function parseBatchExecutedEvent(receipt: TransactionReceipt): BatchExecutedEvent | null;
|
|
1183
|
+
/**
|
|
1184
|
+
* Parse all `CallExecuted` events from a receipt.
|
|
1185
|
+
*/
|
|
1186
|
+
declare function parseCallExecutedEvents(receipt: TransactionReceipt): CallExecutedEvent[];
|
|
1187
|
+
/**
|
|
1188
|
+
* Apply MegaETH gas buffer.
|
|
1189
|
+
* MegaETH opcode costs differ from standard EVM.
|
|
1190
|
+
* Uses 10% buffer by default (viem's default 20% is too aggressive for MegaETH).
|
|
1191
|
+
*/
|
|
1192
|
+
declare function applyMegaethGasBuffer(estimate: bigint, bufferPct?: number): bigint;
|
|
1193
|
+
/**
|
|
1194
|
+
* Encode deadline as a unix timestamp (seconds) n minutes from now.
|
|
1195
|
+
*/
|
|
1196
|
+
declare function deadlineInMinutes(minutes: number): bigint;
|
|
1197
|
+
/**
|
|
1198
|
+
* Build the MegaCall(s) for a safe ERC20 approve.
|
|
1199
|
+
* Uses the "approve(0) → approve(amount)" pattern to avoid race conditions
|
|
1200
|
+
* required by tokens like USDT that revert on non-zero → non-zero approve.
|
|
1201
|
+
*/
|
|
1202
|
+
declare function buildSafeApproveCalls(params: {
|
|
1203
|
+
token: Address;
|
|
1204
|
+
spender: Address;
|
|
1205
|
+
amount: bigint;
|
|
1206
|
+
currentAllowance: bigint;
|
|
1207
|
+
}): MegaCall[];
|
|
1208
|
+
/**
|
|
1209
|
+
* Fetch a swap quote from KyberSwap Aggregator for MegaETH.
|
|
1210
|
+
*/
|
|
1211
|
+
declare function getKyberQuote(params: KyberQuoteParams): Promise<KyberRouteSummary>;
|
|
1212
|
+
/**
|
|
1213
|
+
* Build a KyberSwap transaction for on-chain submission.
|
|
1214
|
+
*/
|
|
1215
|
+
declare function buildKyberSwap(params: {
|
|
1216
|
+
routeSummary: KyberRouteSummary;
|
|
1217
|
+
sender: Address;
|
|
1218
|
+
recipient: Address;
|
|
1219
|
+
slippageBps?: number;
|
|
1220
|
+
}): Promise<KyberBuildResult>;
|
|
1221
|
+
/**
|
|
1222
|
+
* Check if error is a user rejection (MetaMask etc.)
|
|
1223
|
+
*/
|
|
1224
|
+
declare function isUserRejection(error: unknown): boolean;
|
|
1225
|
+
/**
|
|
1226
|
+
* Validate Ethereum address format
|
|
1227
|
+
*/
|
|
1228
|
+
declare function isValidAddress(address: string): address is Address;
|
|
1229
|
+
/**
|
|
1230
|
+
* Validate hex string format
|
|
1231
|
+
*/
|
|
1232
|
+
declare function isValidHex(hex: string): hex is Hex;
|
|
1233
|
+
/**
|
|
1234
|
+
* Split calls into chunks (for very large batches that may exceed gas limits)
|
|
1235
|
+
*/
|
|
1236
|
+
declare function chunkCalls<T>(calls: T[], maxPerBatch?: number): T[][];
|
|
1237
|
+
/**
|
|
1238
|
+
* Calculate total ETH value across a set of calls
|
|
1239
|
+
*/
|
|
1240
|
+
declare function calculateTotalValue(calls: Array<{
|
|
1241
|
+
value: bigint;
|
|
1242
|
+
}>): bigint;
|
|
1243
|
+
/**
|
|
1244
|
+
* Typed SDK error with an error code for programmatic handling.
|
|
1245
|
+
*/
|
|
1246
|
+
declare class MegaFlowError extends Error {
|
|
1247
|
+
readonly code: MegaFlowErrorCode;
|
|
1248
|
+
readonly cause?: unknown | undefined;
|
|
1249
|
+
constructor(message: string, code: MegaFlowErrorCode, cause?: unknown | undefined);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* MegaFlowBuilder — Chainable batch transaction builder for MegaETH
|
|
1254
|
+
*
|
|
1255
|
+
* Build and execute multiple on-chain operations atomically through
|
|
1256
|
+
* the MegaRouter contract. All operations either succeed together or
|
|
1257
|
+
* revert together — no partial failures.
|
|
1258
|
+
*
|
|
1259
|
+
* @example
|
|
1260
|
+
* ```typescript
|
|
1261
|
+
* const builder = new MegaFlowBuilder();
|
|
1262
|
+
*
|
|
1263
|
+
* const result = await builder
|
|
1264
|
+
* .connect(walletClient)
|
|
1265
|
+
* .approve(USDC, DEX_ROUTER, amountIn)
|
|
1266
|
+
* .swapExactTokensForTokens({ router: DEX_ROUTER, ... })
|
|
1267
|
+
* .transfer(WETH, recipient, amount)
|
|
1268
|
+
* .execute();
|
|
1269
|
+
* ```
|
|
1270
|
+
*/
|
|
1271
|
+
|
|
1272
|
+
declare class MegaFlowBuilder {
|
|
1273
|
+
protected calls: MegaCall[];
|
|
1274
|
+
protected operations: RecordedOperation[];
|
|
1275
|
+
protected publicClient: PublicClient;
|
|
1276
|
+
protected walletClient?: WalletClient;
|
|
1277
|
+
protected routerAddress: Address;
|
|
1278
|
+
protected chain: Chain;
|
|
1279
|
+
protected readonly debug: boolean;
|
|
1280
|
+
constructor(config?: MegaFlowConfig);
|
|
1281
|
+
/**
|
|
1282
|
+
* Connect a pre-built viem WalletClient.
|
|
1283
|
+
*/
|
|
1284
|
+
connect(walletClient: WalletClient): this;
|
|
1285
|
+
/**
|
|
1286
|
+
* Connect using a viem Account object.
|
|
1287
|
+
* Creates an internal WalletClient bound to MegaETH's chain/RPC.
|
|
1288
|
+
*/
|
|
1289
|
+
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1290
|
+
/**
|
|
1291
|
+
* Disconnect the wallet (for cleanup).
|
|
1292
|
+
*/
|
|
1293
|
+
disconnect(): this;
|
|
1294
|
+
/**
|
|
1295
|
+
* Add a raw call (pre-encoded calldata).
|
|
1296
|
+
*/
|
|
1297
|
+
add(target: Address, callData: Hex, value?: bigint): this;
|
|
1298
|
+
/**
|
|
1299
|
+
* Add a type-safe ABI-encoded call.
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* builder.addCall({
|
|
1303
|
+
* target: '0x...',
|
|
1304
|
+
* abi: myAbi,
|
|
1305
|
+
* functionName: 'mint',
|
|
1306
|
+
* args: [recipient, amount],
|
|
1307
|
+
* })
|
|
1308
|
+
*/
|
|
1309
|
+
addCall<TAbi extends readonly unknown[]>(params: {
|
|
1310
|
+
target: Address;
|
|
1311
|
+
abi: TAbi;
|
|
1312
|
+
functionName: string;
|
|
1313
|
+
args?: readonly unknown[];
|
|
1314
|
+
value?: bigint;
|
|
1315
|
+
}): this;
|
|
1316
|
+
/**
|
|
1317
|
+
* Send native ETH to an address.
|
|
1318
|
+
* Uses a minimal `receive()` call (empty calldata is not allowed by MegaRouter,
|
|
1319
|
+
* so we send a 1-byte noop that any contract with a `receive()` will handle).
|
|
1320
|
+
*/
|
|
1321
|
+
sendETH(to: Address, value: bigint): this;
|
|
1322
|
+
/**
|
|
1323
|
+
* ERC20 approve.
|
|
1324
|
+
* Uses the simple single-approve pattern.
|
|
1325
|
+
* For safe two-step approve, use `safeApprove()`.
|
|
1326
|
+
*/
|
|
1327
|
+
approve(token: Address, spender: Address, amount: bigint): this;
|
|
1328
|
+
/**
|
|
1329
|
+
* Safe ERC20 approve — resets allowance to 0 first if non-zero,
|
|
1330
|
+
* then sets the new amount. Prevents ERC20 approval race conditions
|
|
1331
|
+
* (required by some tokens like USDT).
|
|
1332
|
+
*
|
|
1333
|
+
* @param currentAllowance Current on-chain allowance. Pass 0n if unknown and you want a single approve.
|
|
1334
|
+
*/
|
|
1335
|
+
safeApprove(token: Address, spender: Address, amount: bigint, currentAllowance: bigint): this;
|
|
1336
|
+
/**
|
|
1337
|
+
* ERC20 transfer.
|
|
1338
|
+
*/
|
|
1339
|
+
transfer(token: Address, to: Address, amount: bigint): this;
|
|
1340
|
+
/**
|
|
1341
|
+
* ERC20 transferFrom.
|
|
1342
|
+
*/
|
|
1343
|
+
transferFrom(token: Address, from: Address, to: Address, amount: bigint): this;
|
|
1344
|
+
/**
|
|
1345
|
+
* Batch transfer same token to multiple recipients in one batch.
|
|
1346
|
+
* @example .multiTransfer(USDC, [{ to: addr1, amount: 100n }, { to: addr2, amount: 200n }])
|
|
1347
|
+
*/
|
|
1348
|
+
multiTransfer(token: Address, transfers: Array<{
|
|
1349
|
+
to: Address;
|
|
1350
|
+
amount: bigint;
|
|
1351
|
+
}>): this;
|
|
1352
|
+
/**
|
|
1353
|
+
* ERC721 safeTransferFrom.
|
|
1354
|
+
*/
|
|
1355
|
+
transferNFT(nft: Address, from: Address, to: Address, tokenId: bigint): this;
|
|
1356
|
+
/**
|
|
1357
|
+
* ERC721 approve (single token).
|
|
1358
|
+
*/
|
|
1359
|
+
approveNFT(nft: Address, to: Address, tokenId: bigint): this;
|
|
1360
|
+
/**
|
|
1361
|
+
* ERC721 setApprovalForAll.
|
|
1362
|
+
*/
|
|
1363
|
+
setApprovalForAll(nft: Address, operator: Address, approved: boolean): this;
|
|
1364
|
+
/**
|
|
1365
|
+
* Wrap ETH → WETH.
|
|
1366
|
+
* The value is sent as ETH and WETH is received in return.
|
|
1367
|
+
*/
|
|
1368
|
+
wrapETH(wethAddress: Address | undefined, amount: bigint): this;
|
|
1369
|
+
/**
|
|
1370
|
+
* Unwrap WETH → ETH.
|
|
1371
|
+
*/
|
|
1372
|
+
unwrapWETH(wethAddress: Address | undefined, amount: bigint): this;
|
|
1373
|
+
/**
|
|
1374
|
+
* Token→Token swap via Uniswap V2 router interface.
|
|
1375
|
+
*/
|
|
1376
|
+
swapExactTokensForTokens(params: SwapParams): this;
|
|
1377
|
+
/**
|
|
1378
|
+
* ETH→Token swap via Uniswap V2 router interface.
|
|
1379
|
+
*/
|
|
1380
|
+
swapExactETHForTokens(params: Omit<SwapParams, 'amountIn'> & {
|
|
1381
|
+
amountIn: bigint;
|
|
1382
|
+
}): this;
|
|
1383
|
+
/**
|
|
1384
|
+
* Token→ETH swap via Uniswap V2 router interface.
|
|
1385
|
+
*/
|
|
1386
|
+
swapExactTokensForETH(params: SwapParams): this;
|
|
1387
|
+
/**
|
|
1388
|
+
* Approve a token and then swap in the same batch (2 calls, 1 tx).
|
|
1389
|
+
* This is the core "Sui-style composability" pattern.
|
|
1390
|
+
*/
|
|
1391
|
+
approveAndSwap(params: ApproveAndSwapParams): this;
|
|
1392
|
+
/**
|
|
1393
|
+
* Add a KyberSwap aggregator swap call.
|
|
1394
|
+
* Fetches route and encodes the on-chain call automatically.
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* await builder.kyberSwap({
|
|
1398
|
+
* tokenIn: USDC,
|
|
1399
|
+
* tokenOut: WETH,
|
|
1400
|
+
* amountIn: parseUnits('100', 6),
|
|
1401
|
+
* slippageBps: 30, // 0.3%
|
|
1402
|
+
* }, senderAddress);
|
|
1403
|
+
*/
|
|
1404
|
+
kyberSwap(params: KyberQuoteParams, sender: Address): Promise<this>;
|
|
1405
|
+
/** Get a copy of queued calls */
|
|
1406
|
+
getCalls(): readonly MegaCall[];
|
|
1407
|
+
/** Get recorded operations (for debugging/tracking) */
|
|
1408
|
+
getOperations(): readonly RecordedOperation[];
|
|
1409
|
+
/** Get full builder state (for serialization/debugging) */
|
|
1410
|
+
getState(): BuilderState;
|
|
1411
|
+
/** Clear all queued calls and operation history */
|
|
1412
|
+
clear(): this;
|
|
1413
|
+
/** Remove and return the last call */
|
|
1414
|
+
pop(): MegaCall | undefined;
|
|
1415
|
+
/** Total ETH value across all calls */
|
|
1416
|
+
getTotalValue(): bigint;
|
|
1417
|
+
/** Number of calls in the current batch */
|
|
1418
|
+
get length(): number;
|
|
1419
|
+
/** Whether batch is empty */
|
|
1420
|
+
get isEmpty(): boolean;
|
|
1421
|
+
/** Whether a wallet is connected */
|
|
1422
|
+
get isConnected(): boolean;
|
|
1423
|
+
/** The connected account address (or undefined) */
|
|
1424
|
+
get account(): Address | undefined;
|
|
1425
|
+
/**
|
|
1426
|
+
* Get a human-readable summary of the queued batch.
|
|
1427
|
+
* Great for logging/debugging before execution.
|
|
1428
|
+
*/
|
|
1429
|
+
summary(): string;
|
|
1430
|
+
/** Read the protocol flat fee from the MegaRouter contract */
|
|
1431
|
+
getFlatFee(): Promise<bigint>;
|
|
1432
|
+
/** Calculate total ETH required (sum of call values + flat fee) */
|
|
1433
|
+
calculateRequiredETH(): Promise<bigint>;
|
|
1434
|
+
/**
|
|
1435
|
+
* Simulate the batch via eth_call — no state changes, no gas spent.
|
|
1436
|
+
* Very useful for pre-flight checks before submitting the real transaction.
|
|
1437
|
+
*/
|
|
1438
|
+
simulate(): Promise<MegaFlowSimulationResult>;
|
|
1439
|
+
/**
|
|
1440
|
+
* Execute the batch using the standard async flow:
|
|
1441
|
+
* 1. Simulate to get request params
|
|
1442
|
+
* 2. walletClient.writeContract → txHash
|
|
1443
|
+
* 3. waitForTransactionReceipt
|
|
1444
|
+
*
|
|
1445
|
+
* On MegaETH this is still very fast (~100-200ms) due to 10ms blocks.
|
|
1446
|
+
* For true synchronous receipts use `executeSync()`.
|
|
1447
|
+
*/
|
|
1448
|
+
execute(options?: ExecuteOptions): Promise<MegaFlowExecutionResult>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Execute using MegaETH's `eth_sendRawTransactionSync` (EIP-7966).
|
|
1451
|
+
* Returns the full receipt in one RPC round-trip (~10ms).
|
|
1452
|
+
*
|
|
1453
|
+
* This is the preferred method on MegaETH — no polling required.
|
|
1454
|
+
*/
|
|
1455
|
+
executeSync(options?: ExecuteOptions): Promise<MegaFlowSyncResult>;
|
|
1456
|
+
/**
|
|
1457
|
+
* Same as executeSync but uses `realtime_sendRawTransaction` (MegaETH original).
|
|
1458
|
+
* Both are functionally identical; use `executeSync` for cross-chain compatibility.
|
|
1459
|
+
*/
|
|
1460
|
+
executeRealtime(options?: ExecuteOptions): Promise<MegaFlowSyncResult>;
|
|
1461
|
+
private recordOperation;
|
|
1462
|
+
private extractFailedCallIndex;
|
|
1463
|
+
private log;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
/**
|
|
1467
|
+
* MegaFlowClient — High-level stateful client for MegaETH
|
|
1468
|
+
*
|
|
1469
|
+
* Wraps MegaFlowBuilder with:
|
|
1470
|
+
* - Automatic nonce management for rapid sequential transactions
|
|
1471
|
+
* - WebSocket support for lower latency
|
|
1472
|
+
* - ERC20 balance/allowance reads
|
|
1473
|
+
* - Multicall token state fetching
|
|
1474
|
+
*
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```typescript
|
|
1477
|
+
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1478
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1479
|
+
*
|
|
1480
|
+
* const account = privateKeyToAccount('0x...');
|
|
1481
|
+
*
|
|
1482
|
+
* // Zero-config: uses MegaETH Mainnet by default
|
|
1483
|
+
* const client = new MegaFlowClient().connectWithAccount(account);
|
|
1484
|
+
*
|
|
1485
|
+
* // Read state
|
|
1486
|
+
* const balance = await client.getTokenBalance(USDC, account.address);
|
|
1487
|
+
* const allowance = await client.getAllowance(USDC, account.address, DEX_ROUTER);
|
|
1488
|
+
*
|
|
1489
|
+
* // Build + execute in one call
|
|
1490
|
+
* const result = await client.batch()
|
|
1491
|
+
* .safeApprove(USDC, DEX_ROUTER, amountIn, allowance)
|
|
1492
|
+
* .swapExactTokensForTokens({ ... })
|
|
1493
|
+
* .executeSync(); // instant receipt on MegaETH
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
|
|
1497
|
+
declare class MegaFlowClient {
|
|
1498
|
+
private config;
|
|
1499
|
+
protected publicClient: PublicClient;
|
|
1500
|
+
protected walletClient?: WalletClient;
|
|
1501
|
+
private wsClient?;
|
|
1502
|
+
private nonceCache;
|
|
1503
|
+
constructor(config?: MegaFlowClientConfig);
|
|
1504
|
+
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1505
|
+
connect(walletClient: WalletClient): this;
|
|
1506
|
+
/**
|
|
1507
|
+
* Enable a WebSocket client for lower latency.
|
|
1508
|
+
* WebSocket is 5-6x faster than HTTP on MegaETH.
|
|
1509
|
+
*
|
|
1510
|
+
* Requires the chain to have a webSocket URL configured.
|
|
1511
|
+
*/
|
|
1512
|
+
enableWebSocket(wsUrl?: string): this;
|
|
1513
|
+
/** Active public client (prefers WebSocket when enabled) */
|
|
1514
|
+
get activeClient(): PublicClient;
|
|
1515
|
+
/**
|
|
1516
|
+
* Create a new MegaFlowBuilder linked to this client's configuration.
|
|
1517
|
+
* Start building calls, then call `.execute()` or `.executeSync()`.
|
|
1518
|
+
*/
|
|
1519
|
+
batch(): MegaFlowBuilder;
|
|
1520
|
+
/**
|
|
1521
|
+
* Get the native ETH balance of an address.
|
|
1522
|
+
*/
|
|
1523
|
+
getETHBalance(address: Address): Promise<bigint>;
|
|
1524
|
+
/**
|
|
1525
|
+
* Get the ERC20 token balance of an address.
|
|
1526
|
+
*/
|
|
1527
|
+
getTokenBalance(token: Address, owner: Address): Promise<bigint>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Get the current ERC20 allowance.
|
|
1530
|
+
*/
|
|
1531
|
+
getAllowance(token: Address, owner: Address, spender: Address): Promise<bigint>;
|
|
1532
|
+
/**
|
|
1533
|
+
* Get multiple token balances in a single multicall.
|
|
1534
|
+
* Much faster than sequential calls on MegaETH (v2.0.14+).
|
|
1535
|
+
*/
|
|
1536
|
+
getMultipleBalances(tokens: Address[], owner: Address): Promise<{
|
|
1537
|
+
token: Address;
|
|
1538
|
+
balance: bigint;
|
|
1539
|
+
}[]>;
|
|
1540
|
+
/**
|
|
1541
|
+
* Get token metadata (name, symbol, decimals) in a single multicall round-trip.
|
|
1542
|
+
*/
|
|
1543
|
+
getTokenInfo(token: Address): Promise<{
|
|
1544
|
+
name: string;
|
|
1545
|
+
symbol: string;
|
|
1546
|
+
decimals: number;
|
|
1547
|
+
totalSupply: bigint;
|
|
1548
|
+
}>;
|
|
1549
|
+
/** Get protocol flat fee from the deployed router */
|
|
1550
|
+
getFlatFee(): Promise<bigint>;
|
|
1551
|
+
/** Get fee collector address from the deployed router */
|
|
1552
|
+
getFeeCollector(): Promise<Address>;
|
|
1553
|
+
/**
|
|
1554
|
+
* Get the next usable nonce for an address, respecting locally tracked nonces.
|
|
1555
|
+
*
|
|
1556
|
+
* Critical for MegaETH: 10ms blocks mean sequential txs can race.
|
|
1557
|
+
* Local nonce tracking prevents "already known" / "nonce too low" errors.
|
|
1558
|
+
*/
|
|
1559
|
+
getNextNonce(address: Address): Promise<number>;
|
|
1560
|
+
/** Reset locally cached nonce for an address (call after a tx confirms or fails). */
|
|
1561
|
+
resetNonce(address: Address): void;
|
|
1562
|
+
/**
|
|
1563
|
+
* Get the current gas price from MegaETH RPC.
|
|
1564
|
+
* Returns the raw value (avoids viem's 20% buffer).
|
|
1565
|
+
*/
|
|
1566
|
+
getGasPrice(): Promise<bigint>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Bridge ETH from Ethereum mainnet to MegaETH.
|
|
1569
|
+
*
|
|
1570
|
+
* NOTE: This must be called from an Ethereum mainnet wallet client,
|
|
1571
|
+
* not the MegaETH wallet client.
|
|
1572
|
+
*
|
|
1573
|
+
* @param l1WalletClient - Ethereum mainnet wallet client
|
|
1574
|
+
* @param amount - Amount in wei to bridge
|
|
1575
|
+
*/
|
|
1576
|
+
bridgeETHToMegaETH(l1WalletClient: WalletClient, amount: bigint): Promise<Hex>;
|
|
1577
|
+
get isConnected(): boolean;
|
|
1578
|
+
get account(): Address | undefined;
|
|
1579
|
+
get routerAddress(): Address;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* @megaflow/sdk
|
|
1584
|
+
*
|
|
1585
|
+
* MegaFlow SDK — Batch Transaction Builder for MegaETH
|
|
1586
|
+
*
|
|
1587
|
+
* Build, simulate and execute multiple on-chain operations as a single
|
|
1588
|
+
* atomic transaction through the MegaRouter contract. All operations
|
|
1589
|
+
* either succeed together or revert together.
|
|
1590
|
+
*
|
|
1591
|
+
* @example Quick start
|
|
1592
|
+
* ```typescript
|
|
1593
|
+
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1594
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1595
|
+
*
|
|
1596
|
+
* const account = privateKeyToAccount('0x...');
|
|
1597
|
+
*
|
|
1598
|
+
* // Zero-config: uses MegaETH Mainnet by default
|
|
1599
|
+
* const client = new MegaFlowClient().connectWithAccount(account);
|
|
1600
|
+
*
|
|
1601
|
+
* const allowance = await client.getAllowance(USDC, account.address, DEX_ROUTER);
|
|
1602
|
+
*
|
|
1603
|
+
* const result = await client.batch()
|
|
1604
|
+
* .safeApprove(USDC, DEX_ROUTER, parseUnits('100', 6), allowance)
|
|
1605
|
+
* .swapExactTokensForTokens({
|
|
1606
|
+
* router: DEX_ROUTER,
|
|
1607
|
+
* amountIn: parseUnits('100', 6),
|
|
1608
|
+
* amountOutMin: parseEther('0.03'),
|
|
1609
|
+
* path: [USDC, WETH],
|
|
1610
|
+
* to: account.address,
|
|
1611
|
+
* })
|
|
1612
|
+
* .executeSync(); // instant receipt on MegaETH
|
|
1613
|
+
* ```
|
|
1614
|
+
*/
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* Create a MegaFlowBuilder with the given config.
|
|
1618
|
+
*/
|
|
1619
|
+
declare function createMegaFlow(config: MegaFlowConfig): MegaFlowBuilder;
|
|
1620
|
+
/**
|
|
1621
|
+
* Create a MegaFlowClient with the given config.
|
|
1622
|
+
*/
|
|
1623
|
+
declare function createMegaFlowClient(config: MegaFlowClientConfig): MegaFlowClient;
|
|
1624
|
+
/**
|
|
1625
|
+
* Quick builder for MegaETH Mainnet.
|
|
1626
|
+
*/
|
|
1627
|
+
declare function createMegaFlowMainnet(routerAddress: Address): MegaFlowBuilder;
|
|
1628
|
+
/**
|
|
1629
|
+
* Quick builder for MegaETH Testnet (Carrot).
|
|
1630
|
+
*/
|
|
1631
|
+
declare function createMegaFlowTestnet(routerAddress: Address): MegaFlowBuilder;
|
|
1632
|
+
/**
|
|
1633
|
+
* Quick full client for MegaETH Mainnet.
|
|
1634
|
+
*/
|
|
1635
|
+
declare function createMegaFlowClientMainnet(routerAddress: Address, rpcUrl?: string): MegaFlowClient;
|
|
1636
|
+
/**
|
|
1637
|
+
* Quick full client for MegaETH Testnet (Carrot).
|
|
1638
|
+
*/
|
|
1639
|
+
declare function createMegaFlowClientTestnet(routerAddress: Address, rpcUrl?: string): MegaFlowClient;
|
|
1640
|
+
|
|
1641
|
+
export { type ApproveAndSwapParams, type BalanceCheck, type BatchExecutedEvent, type BuilderState, type CallExecutedEvent, ERC20_ABI, ERC721_ABI, type ExecuteOptions, KYBERSWAP_API_BASE, type KyberBuildResult, type KyberQuoteParams, type KyberRouteSummary, MEGAETH_BASE_FEE, MEGAETH_GAS_LIMITS, MEGAETH_L1_BRIDGE, MEGAETH_TOKENS, MEGA_ROUTER_ABI, type MegaCall, type MegaCallResult, MegaFlowBuilder, MegaFlowClient, type MegaFlowClientConfig, type MegaFlowConfig, MegaFlowError, type MegaFlowErrorCode, type MegaFlowExecutionResult, type MegaFlowSimulationResult, type MegaFlowSyncResult, type OperationType, type PreflightResult, type RecordedOperation, type SwapParams, type TransferParams, UNISWAP_V2_ROUTER_ABI, WETH_ABI, applyMegaethGasBuffer, buildKyberSwap, buildSafeApproveCalls, calculateTotalValue, chainById, chunkCalls, createMegaFlow, createMegaFlowClient, createMegaFlowClientMainnet, createMegaFlowClientTestnet, createMegaFlowMainnet, createMegaFlowTestnet, deadlineInMinutes, getKyberQuote, isUserRejection, isValidAddress, isValidHex, megaethChains, megaethMainnet, megaethTestnet, parseBatchExecutedEvent, parseCallExecutedEvents, parseCallResults };
|