@megaflow-labs/sdk 0.1.0 → 0.1.1
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 +33 -0
- package/dist/index.d.mts +46 -23
- package/dist/index.d.ts +46 -23
- package/dist/index.js +75 -3
- package/dist/index.mjs +58 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,39 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [0.1.1] – 2026-02-26
|
|
10
|
+
|
|
11
|
+
### Improvements — Developer Experience
|
|
12
|
+
|
|
13
|
+
#### Zero external imports (single SDK import pattern)
|
|
14
|
+
- Added `MegaFlowClient.fromPrivateKey(privateKey)` static factory — no need to import `privateKeyToAccount` from viem
|
|
15
|
+
- Added `MegaFlowClient.fromMnemonic(mnemonic)` static factory — create a client from a BIP-39 phrase in one line
|
|
16
|
+
- Added `client.address` getter — access the connected account's address without reaching into viem internals
|
|
17
|
+
|
|
18
|
+
#### viem re-exports
|
|
19
|
+
The most commonly needed viem utilities are now re-exported from `@megaflow-labs/sdk` directly:
|
|
20
|
+
- **Account factories**: `privateKeyToAccount`, `mnemonicToAccount`, `hdKeyToAccount`
|
|
21
|
+
- **Unit helpers**: `parseUnits`, `parseEther`, `formatUnits`, `formatEther`
|
|
22
|
+
- **Address utilities**: `isAddress`, `getAddress`, `zeroAddress`
|
|
23
|
+
- **Encoding**: `encodeFunctionData`, `decodeFunctionData`, `encodeAbiParameters`, `decodeAbiParameters`
|
|
24
|
+
- **Types**: `Address`, `Hash`, `Hex`, `PublicClient`, `WalletClient`, `Account`, `TransactionReceipt`
|
|
25
|
+
|
|
26
|
+
Before (v0.1.0):
|
|
27
|
+
```typescript
|
|
28
|
+
import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
29
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
30
|
+
import { parseUnits } from 'viem';
|
|
31
|
+
const client = new MegaFlowClient().connectWithAccount(privateKeyToAccount('0x...'));
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
After (v0.1.1):
|
|
35
|
+
```typescript
|
|
36
|
+
import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
37
|
+
const client = MegaFlowClient.fromPrivateKey('0x...');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
9
42
|
## [0.1.0] – 2026-02-26
|
|
10
43
|
|
|
11
44
|
### Initial release
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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';
|
|
3
|
+
export { hdKeyToAccount, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* MegaETH Chain Definitions
|
|
@@ -1472,26 +1474,26 @@ declare class MegaFlowBuilder {
|
|
|
1472
1474
|
* - ERC20 balance/allowance reads
|
|
1473
1475
|
* - Multicall token state fetching
|
|
1474
1476
|
*
|
|
1475
|
-
* @example
|
|
1477
|
+
* @example Zero-config (recommended)
|
|
1476
1478
|
* ```typescript
|
|
1477
|
-
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1478
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1479
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1479
1480
|
*
|
|
1480
|
-
*
|
|
1481
|
+
* // One import, no viem required
|
|
1482
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1481
1483
|
*
|
|
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
1484
|
* const result = await client.batch()
|
|
1491
|
-
* .safeApprove(USDC, DEX_ROUTER,
|
|
1485
|
+
* .safeApprove(USDC, DEX_ROUTER, parseUnits('100', 6), 0n)
|
|
1492
1486
|
* .swapExactTokensForTokens({ ... })
|
|
1493
1487
|
* .executeSync(); // instant receipt on MegaETH
|
|
1494
1488
|
* ```
|
|
1489
|
+
*
|
|
1490
|
+
* @example With existing viem account
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1493
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1494
|
+
*
|
|
1495
|
+
* const client = new MegaFlowClient().connectWithAccount(privateKeyToAccount('0x...'));
|
|
1496
|
+
* ```
|
|
1495
1497
|
*/
|
|
1496
1498
|
|
|
1497
1499
|
declare class MegaFlowClient {
|
|
@@ -1501,6 +1503,30 @@ declare class MegaFlowClient {
|
|
|
1501
1503
|
private wsClient?;
|
|
1502
1504
|
private nonceCache;
|
|
1503
1505
|
constructor(config?: MegaFlowClientConfig);
|
|
1506
|
+
/**
|
|
1507
|
+
* Create a client from a raw private key.
|
|
1508
|
+
* Eliminates the need to import `privateKeyToAccount` from viem/accounts.
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```typescript
|
|
1512
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1513
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
static fromPrivateKey(privateKey: Hex, config?: MegaFlowClientConfig): MegaFlowClient;
|
|
1517
|
+
/**
|
|
1518
|
+
* Create a client from a BIP-39 mnemonic phrase.
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```typescript
|
|
1522
|
+
* const client = MegaFlowClient.fromMnemonic('word1 word2 ... word12');
|
|
1523
|
+
* ```
|
|
1524
|
+
*/
|
|
1525
|
+
static fromMnemonic(mnemonic: string, config?: MegaFlowClientConfig): MegaFlowClient;
|
|
1526
|
+
/**
|
|
1527
|
+
* The connected account's address, or undefined if not yet connected.
|
|
1528
|
+
*/
|
|
1529
|
+
get address(): Address | undefined;
|
|
1504
1530
|
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1505
1531
|
connect(walletClient: WalletClient): this;
|
|
1506
1532
|
/**
|
|
@@ -1588,26 +1614,23 @@ declare class MegaFlowClient {
|
|
|
1588
1614
|
* atomic transaction through the MegaRouter contract. All operations
|
|
1589
1615
|
* either succeed together or revert together.
|
|
1590
1616
|
*
|
|
1591
|
-
* @example Quick start
|
|
1617
|
+
* @example Quick start — single import
|
|
1592
1618
|
* ```typescript
|
|
1593
|
-
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1594
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1595
|
-
*
|
|
1596
|
-
* const account = privateKeyToAccount('0x...');
|
|
1619
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1597
1620
|
*
|
|
1598
|
-
* //
|
|
1599
|
-
* const client =
|
|
1621
|
+
* // No viem import needed — fromPrivateKey handles it internally
|
|
1622
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1600
1623
|
*
|
|
1601
|
-
* const allowance = await client.getAllowance(USDC,
|
|
1624
|
+
* const allowance = await client.getAllowance(USDC, client.address!, DEX_ROUTER);
|
|
1602
1625
|
*
|
|
1603
1626
|
* const result = await client.batch()
|
|
1604
1627
|
* .safeApprove(USDC, DEX_ROUTER, parseUnits('100', 6), allowance)
|
|
1605
1628
|
* .swapExactTokensForTokens({
|
|
1606
1629
|
* router: DEX_ROUTER,
|
|
1607
1630
|
* amountIn: parseUnits('100', 6),
|
|
1608
|
-
* amountOutMin:
|
|
1631
|
+
* amountOutMin: parseUnits('0.03', 18),
|
|
1609
1632
|
* path: [USDC, WETH],
|
|
1610
|
-
* to:
|
|
1633
|
+
* to: client.address!,
|
|
1611
1634
|
* })
|
|
1612
1635
|
* .executeSync(); // instant receipt on MegaETH
|
|
1613
1636
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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';
|
|
3
|
+
export { hdKeyToAccount, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* MegaETH Chain Definitions
|
|
@@ -1472,26 +1474,26 @@ declare class MegaFlowBuilder {
|
|
|
1472
1474
|
* - ERC20 balance/allowance reads
|
|
1473
1475
|
* - Multicall token state fetching
|
|
1474
1476
|
*
|
|
1475
|
-
* @example
|
|
1477
|
+
* @example Zero-config (recommended)
|
|
1476
1478
|
* ```typescript
|
|
1477
|
-
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1478
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1479
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1479
1480
|
*
|
|
1480
|
-
*
|
|
1481
|
+
* // One import, no viem required
|
|
1482
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1481
1483
|
*
|
|
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
1484
|
* const result = await client.batch()
|
|
1491
|
-
* .safeApprove(USDC, DEX_ROUTER,
|
|
1485
|
+
* .safeApprove(USDC, DEX_ROUTER, parseUnits('100', 6), 0n)
|
|
1492
1486
|
* .swapExactTokensForTokens({ ... })
|
|
1493
1487
|
* .executeSync(); // instant receipt on MegaETH
|
|
1494
1488
|
* ```
|
|
1489
|
+
*
|
|
1490
|
+
* @example With existing viem account
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1493
|
+
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1494
|
+
*
|
|
1495
|
+
* const client = new MegaFlowClient().connectWithAccount(privateKeyToAccount('0x...'));
|
|
1496
|
+
* ```
|
|
1495
1497
|
*/
|
|
1496
1498
|
|
|
1497
1499
|
declare class MegaFlowClient {
|
|
@@ -1501,6 +1503,30 @@ declare class MegaFlowClient {
|
|
|
1501
1503
|
private wsClient?;
|
|
1502
1504
|
private nonceCache;
|
|
1503
1505
|
constructor(config?: MegaFlowClientConfig);
|
|
1506
|
+
/**
|
|
1507
|
+
* Create a client from a raw private key.
|
|
1508
|
+
* Eliminates the need to import `privateKeyToAccount` from viem/accounts.
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* ```typescript
|
|
1512
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1513
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
static fromPrivateKey(privateKey: Hex, config?: MegaFlowClientConfig): MegaFlowClient;
|
|
1517
|
+
/**
|
|
1518
|
+
* Create a client from a BIP-39 mnemonic phrase.
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```typescript
|
|
1522
|
+
* const client = MegaFlowClient.fromMnemonic('word1 word2 ... word12');
|
|
1523
|
+
* ```
|
|
1524
|
+
*/
|
|
1525
|
+
static fromMnemonic(mnemonic: string, config?: MegaFlowClientConfig): MegaFlowClient;
|
|
1526
|
+
/**
|
|
1527
|
+
* The connected account's address, or undefined if not yet connected.
|
|
1528
|
+
*/
|
|
1529
|
+
get address(): Address | undefined;
|
|
1504
1530
|
connectWithAccount(account: Account, rpcUrl?: string): this;
|
|
1505
1531
|
connect(walletClient: WalletClient): this;
|
|
1506
1532
|
/**
|
|
@@ -1588,26 +1614,23 @@ declare class MegaFlowClient {
|
|
|
1588
1614
|
* atomic transaction through the MegaRouter contract. All operations
|
|
1589
1615
|
* either succeed together or revert together.
|
|
1590
1616
|
*
|
|
1591
|
-
* @example Quick start
|
|
1617
|
+
* @example Quick start — single import
|
|
1592
1618
|
* ```typescript
|
|
1593
|
-
* import { MegaFlowClient } from '@megaflow-labs/sdk';
|
|
1594
|
-
* import { privateKeyToAccount } from 'viem/accounts';
|
|
1595
|
-
*
|
|
1596
|
-
* const account = privateKeyToAccount('0x...');
|
|
1619
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1597
1620
|
*
|
|
1598
|
-
* //
|
|
1599
|
-
* const client =
|
|
1621
|
+
* // No viem import needed — fromPrivateKey handles it internally
|
|
1622
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1600
1623
|
*
|
|
1601
|
-
* const allowance = await client.getAllowance(USDC,
|
|
1624
|
+
* const allowance = await client.getAllowance(USDC, client.address!, DEX_ROUTER);
|
|
1602
1625
|
*
|
|
1603
1626
|
* const result = await client.batch()
|
|
1604
1627
|
* .safeApprove(USDC, DEX_ROUTER, parseUnits('100', 6), allowance)
|
|
1605
1628
|
* .swapExactTokensForTokens({
|
|
1606
1629
|
* router: DEX_ROUTER,
|
|
1607
1630
|
* amountIn: parseUnits('100', 6),
|
|
1608
|
-
* amountOutMin:
|
|
1631
|
+
* amountOutMin: parseUnits('0.03', 18),
|
|
1609
1632
|
* path: [USDC, WETH],
|
|
1610
|
-
* to:
|
|
1633
|
+
* to: client.address!,
|
|
1611
1634
|
* })
|
|
1612
1635
|
* .executeSync(); // instant receipt on MegaETH
|
|
1613
1636
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -46,16 +46,32 @@ __export(index_exports, {
|
|
|
46
46
|
createMegaFlowMainnet: () => createMegaFlowMainnet,
|
|
47
47
|
createMegaFlowTestnet: () => createMegaFlowTestnet,
|
|
48
48
|
deadlineInMinutes: () => deadlineInMinutes,
|
|
49
|
+
decodeAbiParameters: () => import_viem7.decodeAbiParameters,
|
|
50
|
+
decodeFunctionData: () => import_viem7.decodeFunctionData,
|
|
51
|
+
encodeAbiParameters: () => import_viem7.encodeAbiParameters,
|
|
52
|
+
encodeFunctionData: () => import_viem7.encodeFunctionData,
|
|
53
|
+
formatEther: () => import_viem5.formatEther,
|
|
54
|
+
formatUnits: () => import_viem5.formatUnits,
|
|
55
|
+
getAddress: () => import_viem6.getAddress,
|
|
49
56
|
getKyberQuote: () => getKyberQuote,
|
|
57
|
+
hdKeyToAccount: () => import_accounts2.hdKeyToAccount,
|
|
58
|
+
hexToBigInt: () => import_viem5.hexToBigInt,
|
|
59
|
+
isAddress: () => import_viem6.isAddress,
|
|
50
60
|
isUserRejection: () => isUserRejection,
|
|
51
61
|
isValidAddress: () => isValidAddress,
|
|
52
62
|
isValidHex: () => isValidHex,
|
|
53
63
|
megaethChains: () => megaethChains,
|
|
54
64
|
megaethMainnet: () => megaethMainnet,
|
|
55
65
|
megaethTestnet: () => megaethTestnet,
|
|
66
|
+
mnemonicToAccount: () => import_accounts2.mnemonicToAccount,
|
|
67
|
+
numberToHex: () => import_viem5.numberToHex,
|
|
56
68
|
parseBatchExecutedEvent: () => parseBatchExecutedEvent,
|
|
57
69
|
parseCallExecutedEvents: () => parseCallExecutedEvents,
|
|
58
|
-
parseCallResults: () => parseCallResults
|
|
70
|
+
parseCallResults: () => parseCallResults,
|
|
71
|
+
parseEther: () => import_viem5.parseEther,
|
|
72
|
+
parseUnits: () => import_viem5.parseUnits,
|
|
73
|
+
privateKeyToAccount: () => import_accounts2.privateKeyToAccount,
|
|
74
|
+
zeroAddress: () => import_viem6.zeroAddress
|
|
59
75
|
});
|
|
60
76
|
module.exports = __toCommonJS(index_exports);
|
|
61
77
|
|
|
@@ -1078,7 +1094,8 @@ var MegaFlowBuilder = class {
|
|
|
1078
1094
|
// src/client.ts
|
|
1079
1095
|
var import_viem4 = require("viem");
|
|
1080
1096
|
var import_actions = require("viem/actions");
|
|
1081
|
-
var
|
|
1097
|
+
var import_accounts = require("viem/accounts");
|
|
1098
|
+
var MegaFlowClient = class _MegaFlowClient {
|
|
1082
1099
|
constructor(config = {}) {
|
|
1083
1100
|
// Local nonce cache: address → last used nonce
|
|
1084
1101
|
this.nonceCache = /* @__PURE__ */ new Map();
|
|
@@ -1100,8 +1117,43 @@ var MegaFlowClient = class {
|
|
|
1100
1117
|
}
|
|
1101
1118
|
}
|
|
1102
1119
|
// ==========================================================================
|
|
1120
|
+
// Static factories — zero external imports needed
|
|
1121
|
+
// ==========================================================================
|
|
1122
|
+
/**
|
|
1123
|
+
* Create a client from a raw private key.
|
|
1124
|
+
* Eliminates the need to import `privateKeyToAccount` from viem/accounts.
|
|
1125
|
+
*
|
|
1126
|
+
* @example
|
|
1127
|
+
* ```typescript
|
|
1128
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1129
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1130
|
+
* ```
|
|
1131
|
+
*/
|
|
1132
|
+
static fromPrivateKey(privateKey, config = {}) {
|
|
1133
|
+
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
1134
|
+
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Create a client from a BIP-39 mnemonic phrase.
|
|
1138
|
+
*
|
|
1139
|
+
* @example
|
|
1140
|
+
* ```typescript
|
|
1141
|
+
* const client = MegaFlowClient.fromMnemonic('word1 word2 ... word12');
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
static fromMnemonic(mnemonic, config = {}) {
|
|
1145
|
+
const account = (0, import_accounts.mnemonicToAccount)(mnemonic);
|
|
1146
|
+
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1147
|
+
}
|
|
1148
|
+
// ==========================================================================
|
|
1103
1149
|
// Connection
|
|
1104
1150
|
// ==========================================================================
|
|
1151
|
+
/**
|
|
1152
|
+
* The connected account's address, or undefined if not yet connected.
|
|
1153
|
+
*/
|
|
1154
|
+
get address() {
|
|
1155
|
+
return this.walletClient?.account?.address;
|
|
1156
|
+
}
|
|
1105
1157
|
connectWithAccount(account, rpcUrl) {
|
|
1106
1158
|
const chain = this.config.chain ?? megaethMainnet;
|
|
1107
1159
|
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
@@ -1316,6 +1368,10 @@ var MegaFlowClient = class {
|
|
|
1316
1368
|
};
|
|
1317
1369
|
|
|
1318
1370
|
// src/index.ts
|
|
1371
|
+
var import_accounts2 = require("viem/accounts");
|
|
1372
|
+
var import_viem5 = require("viem");
|
|
1373
|
+
var import_viem6 = require("viem");
|
|
1374
|
+
var import_viem7 = require("viem");
|
|
1319
1375
|
function createMegaFlow(config) {
|
|
1320
1376
|
return new MegaFlowBuilder(config);
|
|
1321
1377
|
}
|
|
@@ -1362,14 +1418,30 @@ function createMegaFlowClientTestnet(routerAddress, rpcUrl) {
|
|
|
1362
1418
|
createMegaFlowMainnet,
|
|
1363
1419
|
createMegaFlowTestnet,
|
|
1364
1420
|
deadlineInMinutes,
|
|
1421
|
+
decodeAbiParameters,
|
|
1422
|
+
decodeFunctionData,
|
|
1423
|
+
encodeAbiParameters,
|
|
1424
|
+
encodeFunctionData,
|
|
1425
|
+
formatEther,
|
|
1426
|
+
formatUnits,
|
|
1427
|
+
getAddress,
|
|
1365
1428
|
getKyberQuote,
|
|
1429
|
+
hdKeyToAccount,
|
|
1430
|
+
hexToBigInt,
|
|
1431
|
+
isAddress,
|
|
1366
1432
|
isUserRejection,
|
|
1367
1433
|
isValidAddress,
|
|
1368
1434
|
isValidHex,
|
|
1369
1435
|
megaethChains,
|
|
1370
1436
|
megaethMainnet,
|
|
1371
1437
|
megaethTestnet,
|
|
1438
|
+
mnemonicToAccount,
|
|
1439
|
+
numberToHex,
|
|
1372
1440
|
parseBatchExecutedEvent,
|
|
1373
1441
|
parseCallExecutedEvents,
|
|
1374
|
-
parseCallResults
|
|
1442
|
+
parseCallResults,
|
|
1443
|
+
parseEther,
|
|
1444
|
+
parseUnits,
|
|
1445
|
+
privateKeyToAccount,
|
|
1446
|
+
zeroAddress
|
|
1375
1447
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1030,7 +1030,8 @@ import {
|
|
|
1030
1030
|
webSocket as webSocket2
|
|
1031
1031
|
} from "viem";
|
|
1032
1032
|
import { multicall } from "viem/actions";
|
|
1033
|
-
|
|
1033
|
+
import { privateKeyToAccount, mnemonicToAccount } from "viem/accounts";
|
|
1034
|
+
var MegaFlowClient = class _MegaFlowClient {
|
|
1034
1035
|
constructor(config = {}) {
|
|
1035
1036
|
// Local nonce cache: address → last used nonce
|
|
1036
1037
|
this.nonceCache = /* @__PURE__ */ new Map();
|
|
@@ -1052,8 +1053,43 @@ var MegaFlowClient = class {
|
|
|
1052
1053
|
}
|
|
1053
1054
|
}
|
|
1054
1055
|
// ==========================================================================
|
|
1056
|
+
// Static factories — zero external imports needed
|
|
1057
|
+
// ==========================================================================
|
|
1058
|
+
/**
|
|
1059
|
+
* Create a client from a raw private key.
|
|
1060
|
+
* Eliminates the need to import `privateKeyToAccount` from viem/accounts.
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```typescript
|
|
1064
|
+
* import { MegaFlowClient, parseUnits } from '@megaflow-labs/sdk';
|
|
1065
|
+
* const client = MegaFlowClient.fromPrivateKey('0xYOUR_PRIVATE_KEY');
|
|
1066
|
+
* ```
|
|
1067
|
+
*/
|
|
1068
|
+
static fromPrivateKey(privateKey, config = {}) {
|
|
1069
|
+
const account = privateKeyToAccount(privateKey);
|
|
1070
|
+
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Create a client from a BIP-39 mnemonic phrase.
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```typescript
|
|
1077
|
+
* const client = MegaFlowClient.fromMnemonic('word1 word2 ... word12');
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
static fromMnemonic(mnemonic, config = {}) {
|
|
1081
|
+
const account = mnemonicToAccount(mnemonic);
|
|
1082
|
+
return new _MegaFlowClient(config).connectWithAccount(account);
|
|
1083
|
+
}
|
|
1084
|
+
// ==========================================================================
|
|
1055
1085
|
// Connection
|
|
1056
1086
|
// ==========================================================================
|
|
1087
|
+
/**
|
|
1088
|
+
* The connected account's address, or undefined if not yet connected.
|
|
1089
|
+
*/
|
|
1090
|
+
get address() {
|
|
1091
|
+
return this.walletClient?.account?.address;
|
|
1092
|
+
}
|
|
1057
1093
|
connectWithAccount(account, rpcUrl) {
|
|
1058
1094
|
const chain = this.config.chain ?? megaethMainnet;
|
|
1059
1095
|
this.walletClient = createWalletClient2({
|
|
@@ -1268,6 +1304,10 @@ var MegaFlowClient = class {
|
|
|
1268
1304
|
};
|
|
1269
1305
|
|
|
1270
1306
|
// src/index.ts
|
|
1307
|
+
import { privateKeyToAccount as privateKeyToAccount2, mnemonicToAccount as mnemonicToAccount2, hdKeyToAccount } from "viem/accounts";
|
|
1308
|
+
import { parseUnits, parseEther as parseEther2, formatUnits, formatEther, hexToBigInt, numberToHex } from "viem";
|
|
1309
|
+
import { isAddress, getAddress, zeroAddress } from "viem";
|
|
1310
|
+
import { encodeFunctionData as encodeFunctionData2, decodeFunctionData, encodeAbiParameters, decodeAbiParameters as decodeAbiParameters2 } from "viem";
|
|
1271
1311
|
function createMegaFlow(config) {
|
|
1272
1312
|
return new MegaFlowBuilder(config);
|
|
1273
1313
|
}
|
|
@@ -1313,14 +1353,30 @@ export {
|
|
|
1313
1353
|
createMegaFlowMainnet,
|
|
1314
1354
|
createMegaFlowTestnet,
|
|
1315
1355
|
deadlineInMinutes,
|
|
1356
|
+
decodeAbiParameters2 as decodeAbiParameters,
|
|
1357
|
+
decodeFunctionData,
|
|
1358
|
+
encodeAbiParameters,
|
|
1359
|
+
encodeFunctionData2 as encodeFunctionData,
|
|
1360
|
+
formatEther,
|
|
1361
|
+
formatUnits,
|
|
1362
|
+
getAddress,
|
|
1316
1363
|
getKyberQuote,
|
|
1364
|
+
hdKeyToAccount,
|
|
1365
|
+
hexToBigInt,
|
|
1366
|
+
isAddress,
|
|
1317
1367
|
isUserRejection,
|
|
1318
1368
|
isValidAddress,
|
|
1319
1369
|
isValidHex,
|
|
1320
1370
|
megaethChains,
|
|
1321
1371
|
megaethMainnet,
|
|
1322
1372
|
megaethTestnet,
|
|
1373
|
+
mnemonicToAccount2 as mnemonicToAccount,
|
|
1374
|
+
numberToHex,
|
|
1323
1375
|
parseBatchExecutedEvent,
|
|
1324
1376
|
parseCallExecutedEvents,
|
|
1325
|
-
parseCallResults
|
|
1377
|
+
parseCallResults,
|
|
1378
|
+
parseEther2 as parseEther,
|
|
1379
|
+
parseUnits,
|
|
1380
|
+
privateKeyToAccount2 as privateKeyToAccount,
|
|
1381
|
+
zeroAddress
|
|
1326
1382
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megaflow-labs/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
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",
|