@megaflow-labs/sdk 0.1.1 → 0.1.2
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 +15 -0
- package/README.md +67 -17
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +40 -15
- package/dist/index.mjs +23 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,21 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [0.1.2] – 2026-02-28
|
|
10
|
+
|
|
11
|
+
### Improvements — Developer Experience
|
|
12
|
+
|
|
13
|
+
#### Added `connectWithPrivateKey` convenience method
|
|
14
|
+
- You can now connect the `MegaFlowBuilder` and `MegaFlowClient` directly with a private key hex string, without needing to manually import `privateKeyToAccount` or create account objects.
|
|
15
|
+
|
|
16
|
+
#### Expanded viem re-exports
|
|
17
|
+
- Re-exported `parseAbi`, `parseAbiItem`, `parseAbiParameters` (ABI helpers)
|
|
18
|
+
- Re-exported `createPublicClient`, `createWalletClient`, `http`, `webSocket` (Client factories)
|
|
19
|
+
- Re-exported `Chain`, `decodeAbiParameters` (Types and Encoding)
|
|
20
|
+
- This allows developers to rely **entirely** on the SDK imports for script and dapp building, eliminating duplicate `viem` dependencies.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
9
24
|
## [0.1.1] – 2026-02-26
|
|
10
25
|
|
|
11
26
|
### Improvements — Developer Experience
|
package/README.md
CHANGED
|
@@ -26,25 +26,21 @@ On standard EVM chains, sending multiple transactions requires multiple wallet c
|
|
|
26
26
|
npm install @megaflow-labs/sdk
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
>
|
|
29
|
+
> **Node.js ≥ 18** required. `viem` is a peer dependency — but all commonly used viem utilities are **re-exported from the SDK** so you rarely need to install it separately.
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
33
|
## Quick Start
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
|
-
import { MegaFlowClient, MEGAETH_TOKENS } from '@megaflow-labs/sdk';
|
|
37
|
-
import { privateKeyToAccount } from 'viem/accounts';
|
|
38
|
-
import { parseUnits, parseEther } from 'viem';
|
|
36
|
+
import { MegaFlowClient, MEGAETH_TOKENS, parseUnits, parseEther } from '@megaflow-labs/sdk';
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Zero-config: connects to MegaETH Mainnet automatically
|
|
43
|
-
const client = new MegaFlowClient().connectWithAccount(account);
|
|
38
|
+
// fromPrivateKey() creates a fully connected client in one line
|
|
39
|
+
const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
44
40
|
|
|
45
41
|
// Read on-chain state
|
|
46
|
-
const balance = await client.getTokenBalance(MEGAETH_TOKENS.WETH,
|
|
47
|
-
const allowance = await client.getAllowance(USDC,
|
|
42
|
+
const balance = await client.getTokenBalance(MEGAETH_TOKENS.WETH, client.address!);
|
|
43
|
+
const allowance = await client.getAllowance(USDC, client.address!, DEX_ROUTER);
|
|
48
44
|
|
|
49
45
|
// Build, simulate, and execute — all in one chain
|
|
50
46
|
const result = await client
|
|
@@ -55,7 +51,7 @@ const result = await client
|
|
|
55
51
|
amountIn: parseUnits('100', 6),
|
|
56
52
|
amountOutMin: parseEther('0.03'),
|
|
57
53
|
path: [USDC, MEGAETH_TOKENS.WETH],
|
|
58
|
-
to:
|
|
54
|
+
to: client.address!,
|
|
59
55
|
})
|
|
60
56
|
.executeSync(); // instant receipt on MegaETH (~10ms)
|
|
61
57
|
|
|
@@ -63,6 +59,13 @@ console.log(`Tx hash: ${result.receipt.transactionHash}`);
|
|
|
63
59
|
console.log(`Gas used: ${result.gasUsed}`);
|
|
64
60
|
```
|
|
65
61
|
|
|
62
|
+
> **Using an existing viem account or WalletClient?** Both still work:
|
|
63
|
+
> ```typescript
|
|
64
|
+
> import { MegaFlowClient, privateKeyToAccount } from '@megaflow-labs/sdk';
|
|
65
|
+
> const client = new MegaFlowClient().connectWithAccount(privateKeyToAccount('0x...'));
|
|
66
|
+
> // or: .connect(myExistingWalletClient)
|
|
67
|
+
> ```
|
|
68
|
+
|
|
66
69
|
---
|
|
67
70
|
|
|
68
71
|
## Core Concepts
|
|
@@ -94,15 +97,16 @@ const result = await builder.execute();
|
|
|
94
97
|
|
|
95
98
|
Stateful high-level client. Extends MegaFlowBuilder with token reads, nonce management, and WebSocket support.
|
|
96
99
|
|
|
100
|
+
**Factory methods (v0.1.1+):**
|
|
101
|
+
|
|
97
102
|
```typescript
|
|
98
|
-
import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
103
|
+
import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
client.
|
|
105
|
+
// From private key
|
|
106
|
+
const client = MegaFlowClient.fromPrivateKey('0xYOUR_KEY');
|
|
102
107
|
|
|
103
|
-
//
|
|
104
|
-
const
|
|
105
|
-
const allowance = await client.getAllowance(token, address, spender);
|
|
108
|
+
// From mnemonic
|
|
109
|
+
const client2 = MegaFlowClient.fromMnemonic('word1 word2 ... word12');
|
|
106
110
|
|
|
107
111
|
// Batch transfers to multiple recipients in one tx
|
|
108
112
|
const result = await client
|
|
@@ -116,6 +120,22 @@ const result = await client
|
|
|
116
120
|
|
|
117
121
|
---
|
|
118
122
|
|
|
123
|
+
## What's re-exported from viem
|
|
124
|
+
|
|
125
|
+
You can import all of these directly from `@megaflow-labs/sdk` — **no separate `viem` install needed**:
|
|
126
|
+
|
|
127
|
+
| Category | Exports |
|
|
128
|
+
|---|---|
|
|
129
|
+
| **Account factories** | `privateKeyToAccount`, `mnemonicToAccount`, `hdKeyToAccount` |
|
|
130
|
+
| **Unit helpers** | `parseUnits`, `parseEther`, `formatUnits`, `formatEther` |
|
|
131
|
+
| **ABI helpers** | `parseAbi`, `parseAbiItem`, `parseAbiParameters` |
|
|
132
|
+
| **Client factories** | `createPublicClient`, `createWalletClient`, `http`, `webSocket` |
|
|
133
|
+
| **Address utilities** | `isAddress`, `getAddress`, `zeroAddress` |
|
|
134
|
+
| **Encoding** | `encodeFunctionData`, `decodeFunctionData`, `encodeAbiParameters`, `decodeAbiParameters` |
|
|
135
|
+
| **Types** | `Address`, `Hash`, `Hex`, `Chain`, `PublicClient`, `WalletClient`, `Account`, `TransactionReceipt` |
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
119
139
|
## API Reference
|
|
120
140
|
|
|
121
141
|
### Execution Methods
|
|
@@ -246,11 +266,41 @@ const client = new MegaFlowClient({ rpcUrl: 'https://your-rpc.example.com' });
|
|
|
246
266
|
|
|
247
267
|
---
|
|
248
268
|
|
|
269
|
+
## Examples
|
|
270
|
+
|
|
271
|
+
See the **[megaflow-labs/examples](https://github.com/megaflow-labs/examples)** repository for 14 working TypeScript scripts covering real DeFi patterns:
|
|
272
|
+
|
|
273
|
+
| Script | Pattern |
|
|
274
|
+
|---|---|
|
|
275
|
+
| `04-yield-optimizer` | Wrap + Approve + Supply to Aave in one tx |
|
|
276
|
+
| `05-leverage-loop` | Flashloan-style leverage loop without smart contracts |
|
|
277
|
+
| `06-nft-sweep-and-stake` | Buy NFT + stake atomically |
|
|
278
|
+
| `07-token-snipe-and-protect` | Snipe + stop-loss authorization |
|
|
279
|
+
| `08-bridge-intent` | Swap + bridge to L1 in one signature |
|
|
280
|
+
| `09-flash-arbitrage` | Zero-risk EOA arbitrage across two DEXes |
|
|
281
|
+
| `10-debt-repayment` | Liquidation rescue (swap illiquid → repay) |
|
|
282
|
+
| `11-airdrop-claim-and-sell` | Claim + sell before price collapses |
|
|
283
|
+
| `12-payroll-batch` | Treasury swap + pay 50 contributors |
|
|
284
|
+
| `13-portfolio-rebalance` | Multi-sell → single target buy |
|
|
285
|
+
| `14-options-payoff` | Conditional options exercise |
|
|
286
|
+
|
|
287
|
+
**Clone and run:**
|
|
288
|
+
```bash
|
|
289
|
+
git clone https://github.com/megaflow-labs/examples
|
|
290
|
+
cd examples && npm install
|
|
291
|
+
cp .env.example .env # add your PRIVATE_KEY
|
|
292
|
+
npm run 04-yield
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
249
297
|
## Links
|
|
250
298
|
|
|
251
299
|
- **Website:** [megaflow.space](https://megaflow.space)
|
|
300
|
+
- **Examples:** [github.com/megaflow-labs/examples](https://github.com/megaflow-labs/examples)
|
|
252
301
|
- **GitHub:** [github.com/megaflow-labs](https://github.com/megaflow-labs)
|
|
253
302
|
- **NPM:** [@megaflow-labs/sdk](https://www.npmjs.com/package/@megaflow-labs/sdk)
|
|
303
|
+
- **AI Context:** [llms.txt](https://github.com/megaflow-labs/sdk/blob/main/llms.txt)
|
|
254
304
|
|
|
255
305
|
---
|
|
256
306
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chain, Address, Hex, Hash, TransactionReceipt, PublicClient, WalletClient, Account } from 'viem';
|
|
2
|
-
export { Account, Address, Hash, Hex, PublicClient, TransactionReceipt, WalletClient, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, formatEther, formatUnits, getAddress, hexToBigInt, isAddress, numberToHex, parseEther, parseUnits, zeroAddress } from 'viem';
|
|
2
|
+
export { Account, Address, Chain, Hash, Hex, PublicClient, TransactionReceipt, WalletClient, createPublicClient, createWalletClient, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, formatEther, formatUnits, getAddress, hexToBigInt, http, isAddress, numberToHex, parseAbi, parseAbiItem, parseAbiParameters, parseEther, parseUnits, webSocket, zeroAddress } from 'viem';
|
|
3
3
|
export { hdKeyToAccount, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1290,8 +1290,13 @@ declare class MegaFlowBuilder {
|
|
|
1290
1290
|
*/
|
|
1291
1291
|
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1292
1292
|
/**
|
|
1293
|
-
*
|
|
1293
|
+
* Connect using a raw private key hex string.
|
|
1294
|
+
* The most convenient way to connect in scripts — no viem import needed.
|
|
1295
|
+
*
|
|
1296
|
+
* @example
|
|
1297
|
+
* builder.connectWithPrivateKey(process.env.PRIVATE_KEY!)
|
|
1294
1298
|
*/
|
|
1299
|
+
connectWithPrivateKey(privateKey: `0x${string}`, rpcUrl?: string): this;
|
|
1295
1300
|
disconnect(): this;
|
|
1296
1301
|
/**
|
|
1297
1302
|
* Add a raw call (pre-encoded calldata).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chain, Address, Hex, Hash, TransactionReceipt, PublicClient, WalletClient, Account } from 'viem';
|
|
2
|
-
export { Account, Address, Hash, Hex, PublicClient, TransactionReceipt, WalletClient, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, formatEther, formatUnits, getAddress, hexToBigInt, isAddress, numberToHex, parseEther, parseUnits, zeroAddress } from 'viem';
|
|
2
|
+
export { Account, Address, Chain, Hash, Hex, PublicClient, TransactionReceipt, WalletClient, createPublicClient, createWalletClient, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, formatEther, formatUnits, getAddress, hexToBigInt, http, isAddress, numberToHex, parseAbi, parseAbiItem, parseAbiParameters, parseEther, parseUnits, webSocket, zeroAddress } from 'viem';
|
|
3
3
|
export { hdKeyToAccount, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1290,8 +1290,13 @@ declare class MegaFlowBuilder {
|
|
|
1290
1290
|
*/
|
|
1291
1291
|
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1292
1292
|
/**
|
|
1293
|
-
*
|
|
1293
|
+
* Connect using a raw private key hex string.
|
|
1294
|
+
* The most convenient way to connect in scripts — no viem import needed.
|
|
1295
|
+
*
|
|
1296
|
+
* @example
|
|
1297
|
+
* builder.connectWithPrivateKey(process.env.PRIVATE_KEY!)
|
|
1294
1298
|
*/
|
|
1299
|
+
connectWithPrivateKey(privateKey: `0x${string}`, rpcUrl?: string): this;
|
|
1295
1300
|
disconnect(): this;
|
|
1296
1301
|
/**
|
|
1297
1302
|
* Add a raw call (pre-encoded calldata).
|
package/dist/index.js
CHANGED
|
@@ -45,33 +45,40 @@ __export(index_exports, {
|
|
|
45
45
|
createMegaFlowClientTestnet: () => createMegaFlowClientTestnet,
|
|
46
46
|
createMegaFlowMainnet: () => createMegaFlowMainnet,
|
|
47
47
|
createMegaFlowTestnet: () => createMegaFlowTestnet,
|
|
48
|
+
createPublicClient: () => import_viem8.createPublicClient,
|
|
49
|
+
createWalletClient: () => import_viem8.createWalletClient,
|
|
48
50
|
deadlineInMinutes: () => deadlineInMinutes,
|
|
49
|
-
decodeAbiParameters: () =>
|
|
50
|
-
decodeFunctionData: () =>
|
|
51
|
-
encodeAbiParameters: () =>
|
|
52
|
-
encodeFunctionData: () =>
|
|
51
|
+
decodeAbiParameters: () => import_viem9.decodeAbiParameters,
|
|
52
|
+
decodeFunctionData: () => import_viem9.decodeFunctionData,
|
|
53
|
+
encodeAbiParameters: () => import_viem9.encodeAbiParameters,
|
|
54
|
+
encodeFunctionData: () => import_viem9.encodeFunctionData,
|
|
53
55
|
formatEther: () => import_viem5.formatEther,
|
|
54
56
|
formatUnits: () => import_viem5.formatUnits,
|
|
55
|
-
getAddress: () =>
|
|
57
|
+
getAddress: () => import_viem7.getAddress,
|
|
56
58
|
getKyberQuote: () => getKyberQuote,
|
|
57
|
-
hdKeyToAccount: () =>
|
|
59
|
+
hdKeyToAccount: () => import_accounts3.hdKeyToAccount,
|
|
58
60
|
hexToBigInt: () => import_viem5.hexToBigInt,
|
|
59
|
-
|
|
61
|
+
http: () => import_viem8.http,
|
|
62
|
+
isAddress: () => import_viem7.isAddress,
|
|
60
63
|
isUserRejection: () => isUserRejection,
|
|
61
64
|
isValidAddress: () => isValidAddress,
|
|
62
65
|
isValidHex: () => isValidHex,
|
|
63
66
|
megaethChains: () => megaethChains,
|
|
64
67
|
megaethMainnet: () => megaethMainnet,
|
|
65
68
|
megaethTestnet: () => megaethTestnet,
|
|
66
|
-
mnemonicToAccount: () =>
|
|
69
|
+
mnemonicToAccount: () => import_accounts3.mnemonicToAccount,
|
|
67
70
|
numberToHex: () => import_viem5.numberToHex,
|
|
71
|
+
parseAbi: () => import_viem6.parseAbi,
|
|
72
|
+
parseAbiItem: () => import_viem6.parseAbiItem,
|
|
73
|
+
parseAbiParameters: () => import_viem6.parseAbiParameters,
|
|
68
74
|
parseBatchExecutedEvent: () => parseBatchExecutedEvent,
|
|
69
75
|
parseCallExecutedEvents: () => parseCallExecutedEvents,
|
|
70
76
|
parseCallResults: () => parseCallResults,
|
|
71
77
|
parseEther: () => import_viem5.parseEther,
|
|
72
78
|
parseUnits: () => import_viem5.parseUnits,
|
|
73
|
-
privateKeyToAccount: () =>
|
|
74
|
-
|
|
79
|
+
privateKeyToAccount: () => import_accounts3.privateKeyToAccount,
|
|
80
|
+
webSocket: () => import_viem8.webSocket,
|
|
81
|
+
zeroAddress: () => import_viem7.zeroAddress
|
|
75
82
|
});
|
|
76
83
|
module.exports = __toCommonJS(index_exports);
|
|
77
84
|
|
|
@@ -510,6 +517,7 @@ var MegaFlowError = class extends Error {
|
|
|
510
517
|
|
|
511
518
|
// src/builder.ts
|
|
512
519
|
var import_viem3 = require("viem");
|
|
520
|
+
var import_accounts = require("viem/accounts");
|
|
513
521
|
var MegaFlowBuilder = class {
|
|
514
522
|
constructor(config = {}) {
|
|
515
523
|
this.calls = [];
|
|
@@ -549,8 +557,16 @@ var MegaFlowBuilder = class {
|
|
|
549
557
|
return this;
|
|
550
558
|
}
|
|
551
559
|
/**
|
|
552
|
-
*
|
|
560
|
+
* Connect using a raw private key hex string.
|
|
561
|
+
* The most convenient way to connect in scripts — no viem import needed.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* builder.connectWithPrivateKey(process.env.PRIVATE_KEY!)
|
|
553
565
|
*/
|
|
566
|
+
connectWithPrivateKey(privateKey, rpcUrl) {
|
|
567
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
568
|
+
return this.connectWithAccount(account, rpcUrl);
|
|
569
|
+
}
|
|
554
570
|
disconnect() {
|
|
555
571
|
this.walletClient = void 0;
|
|
556
572
|
return this;
|
|
@@ -1094,7 +1110,7 @@ var MegaFlowBuilder = class {
|
|
|
1094
1110
|
// src/client.ts
|
|
1095
1111
|
var import_viem4 = require("viem");
|
|
1096
1112
|
var import_actions = require("viem/actions");
|
|
1097
|
-
var
|
|
1113
|
+
var import_accounts2 = require("viem/accounts");
|
|
1098
1114
|
var MegaFlowClient = class _MegaFlowClient {
|
|
1099
1115
|
constructor(config = {}) {
|
|
1100
1116
|
// Local nonce cache: address → last used nonce
|
|
@@ -1130,7 +1146,7 @@ var MegaFlowClient = class _MegaFlowClient {
|
|
|
1130
1146
|
* ```
|
|
1131
1147
|
*/
|
|
1132
1148
|
static fromPrivateKey(privateKey, config = {}) {
|
|
1133
|
-
const account = (0,
|
|
1149
|
+
const account = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
1134
1150
|
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1135
1151
|
}
|
|
1136
1152
|
/**
|
|
@@ -1142,7 +1158,7 @@ var MegaFlowClient = class _MegaFlowClient {
|
|
|
1142
1158
|
* ```
|
|
1143
1159
|
*/
|
|
1144
1160
|
static fromMnemonic(mnemonic, config = {}) {
|
|
1145
|
-
const account = (0,
|
|
1161
|
+
const account = (0, import_accounts2.mnemonicToAccount)(mnemonic);
|
|
1146
1162
|
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1147
1163
|
}
|
|
1148
1164
|
// ==========================================================================
|
|
@@ -1368,10 +1384,12 @@ var MegaFlowClient = class _MegaFlowClient {
|
|
|
1368
1384
|
};
|
|
1369
1385
|
|
|
1370
1386
|
// src/index.ts
|
|
1371
|
-
var
|
|
1387
|
+
var import_accounts3 = require("viem/accounts");
|
|
1372
1388
|
var import_viem5 = require("viem");
|
|
1373
1389
|
var import_viem6 = require("viem");
|
|
1374
1390
|
var import_viem7 = require("viem");
|
|
1391
|
+
var import_viem8 = require("viem");
|
|
1392
|
+
var import_viem9 = require("viem");
|
|
1375
1393
|
function createMegaFlow(config) {
|
|
1376
1394
|
return new MegaFlowBuilder(config);
|
|
1377
1395
|
}
|
|
@@ -1417,6 +1435,8 @@ function createMegaFlowClientTestnet(routerAddress, rpcUrl) {
|
|
|
1417
1435
|
createMegaFlowClientTestnet,
|
|
1418
1436
|
createMegaFlowMainnet,
|
|
1419
1437
|
createMegaFlowTestnet,
|
|
1438
|
+
createPublicClient,
|
|
1439
|
+
createWalletClient,
|
|
1420
1440
|
deadlineInMinutes,
|
|
1421
1441
|
decodeAbiParameters,
|
|
1422
1442
|
decodeFunctionData,
|
|
@@ -1428,6 +1448,7 @@ function createMegaFlowClientTestnet(routerAddress, rpcUrl) {
|
|
|
1428
1448
|
getKyberQuote,
|
|
1429
1449
|
hdKeyToAccount,
|
|
1430
1450
|
hexToBigInt,
|
|
1451
|
+
http,
|
|
1431
1452
|
isAddress,
|
|
1432
1453
|
isUserRejection,
|
|
1433
1454
|
isValidAddress,
|
|
@@ -1437,11 +1458,15 @@ function createMegaFlowClientTestnet(routerAddress, rpcUrl) {
|
|
|
1437
1458
|
megaethTestnet,
|
|
1438
1459
|
mnemonicToAccount,
|
|
1439
1460
|
numberToHex,
|
|
1461
|
+
parseAbi,
|
|
1462
|
+
parseAbiItem,
|
|
1463
|
+
parseAbiParameters,
|
|
1440
1464
|
parseBatchExecutedEvent,
|
|
1441
1465
|
parseCallExecutedEvents,
|
|
1442
1466
|
parseCallResults,
|
|
1443
1467
|
parseEther,
|
|
1444
1468
|
parseUnits,
|
|
1445
1469
|
privateKeyToAccount,
|
|
1470
|
+
webSocket,
|
|
1446
1471
|
zeroAddress
|
|
1447
1472
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -441,6 +441,7 @@ import {
|
|
|
441
441
|
encodeFunctionData,
|
|
442
442
|
http
|
|
443
443
|
} from "viem";
|
|
444
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
444
445
|
var MegaFlowBuilder = class {
|
|
445
446
|
constructor(config = {}) {
|
|
446
447
|
this.calls = [];
|
|
@@ -480,8 +481,16 @@ var MegaFlowBuilder = class {
|
|
|
480
481
|
return this;
|
|
481
482
|
}
|
|
482
483
|
/**
|
|
483
|
-
*
|
|
484
|
+
* Connect using a raw private key hex string.
|
|
485
|
+
* The most convenient way to connect in scripts — no viem import needed.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* builder.connectWithPrivateKey(process.env.PRIVATE_KEY!)
|
|
484
489
|
*/
|
|
490
|
+
connectWithPrivateKey(privateKey, rpcUrl) {
|
|
491
|
+
const account = privateKeyToAccount(privateKey);
|
|
492
|
+
return this.connectWithAccount(account, rpcUrl);
|
|
493
|
+
}
|
|
485
494
|
disconnect() {
|
|
486
495
|
this.walletClient = void 0;
|
|
487
496
|
return this;
|
|
@@ -1030,7 +1039,7 @@ import {
|
|
|
1030
1039
|
webSocket as webSocket2
|
|
1031
1040
|
} from "viem";
|
|
1032
1041
|
import { multicall } from "viem/actions";
|
|
1033
|
-
import { privateKeyToAccount, mnemonicToAccount } from "viem/accounts";
|
|
1042
|
+
import { privateKeyToAccount as privateKeyToAccount2, mnemonicToAccount } from "viem/accounts";
|
|
1034
1043
|
var MegaFlowClient = class _MegaFlowClient {
|
|
1035
1044
|
constructor(config = {}) {
|
|
1036
1045
|
// Local nonce cache: address → last used nonce
|
|
@@ -1066,7 +1075,7 @@ var MegaFlowClient = class _MegaFlowClient {
|
|
|
1066
1075
|
* ```
|
|
1067
1076
|
*/
|
|
1068
1077
|
static fromPrivateKey(privateKey, config = {}) {
|
|
1069
|
-
const account =
|
|
1078
|
+
const account = privateKeyToAccount2(privateKey);
|
|
1070
1079
|
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1071
1080
|
}
|
|
1072
1081
|
/**
|
|
@@ -1304,9 +1313,11 @@ var MegaFlowClient = class _MegaFlowClient {
|
|
|
1304
1313
|
};
|
|
1305
1314
|
|
|
1306
1315
|
// src/index.ts
|
|
1307
|
-
import { privateKeyToAccount as
|
|
1316
|
+
import { privateKeyToAccount as privateKeyToAccount3, mnemonicToAccount as mnemonicToAccount2, hdKeyToAccount } from "viem/accounts";
|
|
1308
1317
|
import { parseUnits, parseEther as parseEther2, formatUnits, formatEther, hexToBigInt, numberToHex } from "viem";
|
|
1318
|
+
import { parseAbi as parseAbi2, parseAbiItem, parseAbiParameters } from "viem";
|
|
1309
1319
|
import { isAddress, getAddress, zeroAddress } from "viem";
|
|
1320
|
+
import { createPublicClient as createPublicClient3, createWalletClient as createWalletClient3, http as http3, webSocket as webSocket3 } from "viem";
|
|
1310
1321
|
import { encodeFunctionData as encodeFunctionData2, decodeFunctionData, encodeAbiParameters, decodeAbiParameters as decodeAbiParameters2 } from "viem";
|
|
1311
1322
|
function createMegaFlow(config) {
|
|
1312
1323
|
return new MegaFlowBuilder(config);
|
|
@@ -1352,6 +1363,8 @@ export {
|
|
|
1352
1363
|
createMegaFlowClientTestnet,
|
|
1353
1364
|
createMegaFlowMainnet,
|
|
1354
1365
|
createMegaFlowTestnet,
|
|
1366
|
+
createPublicClient3 as createPublicClient,
|
|
1367
|
+
createWalletClient3 as createWalletClient,
|
|
1355
1368
|
deadlineInMinutes,
|
|
1356
1369
|
decodeAbiParameters2 as decodeAbiParameters,
|
|
1357
1370
|
decodeFunctionData,
|
|
@@ -1363,6 +1376,7 @@ export {
|
|
|
1363
1376
|
getKyberQuote,
|
|
1364
1377
|
hdKeyToAccount,
|
|
1365
1378
|
hexToBigInt,
|
|
1379
|
+
http3 as http,
|
|
1366
1380
|
isAddress,
|
|
1367
1381
|
isUserRejection,
|
|
1368
1382
|
isValidAddress,
|
|
@@ -1372,11 +1386,15 @@ export {
|
|
|
1372
1386
|
megaethTestnet,
|
|
1373
1387
|
mnemonicToAccount2 as mnemonicToAccount,
|
|
1374
1388
|
numberToHex,
|
|
1389
|
+
parseAbi2 as parseAbi,
|
|
1390
|
+
parseAbiItem,
|
|
1391
|
+
parseAbiParameters,
|
|
1375
1392
|
parseBatchExecutedEvent,
|
|
1376
1393
|
parseCallExecutedEvents,
|
|
1377
1394
|
parseCallResults,
|
|
1378
1395
|
parseEther2 as parseEther,
|
|
1379
1396
|
parseUnits,
|
|
1380
|
-
|
|
1397
|
+
privateKeyToAccount3 as privateKeyToAccount,
|
|
1398
|
+
webSocket3 as webSocket,
|
|
1381
1399
|
zeroAddress
|
|
1382
1400
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megaflow-labs/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Batch transaction SDK for MegaETH — compose, simulate and execute multiple on-chain operations in a single atomic transaction.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|