four-flap-meme-sdk 1.4.17 → 1.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/utils/private-sale.d.ts +87 -0
- package/dist/utils/private-sale.js +166 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export { generateWallets, type GeneratedWallet } from './utils/wallet.js';
|
|
|
34
34
|
export { getTokenBalancesWithMulticall, type MulticallResult, type MultiTokenBalancesResult } from './utils/wallet.js';
|
|
35
35
|
export { validatePrivateKeys, type PrivateKeyValidation } from './utils/wallet.js';
|
|
36
36
|
export { stealthTransfer, type StealthTransferResult, type StealthTransferSimpleParams } from './utils/stealth-transfer.js';
|
|
37
|
+
export { privateSaleMerkle, batchPrivateSaleMerkle, type PrivateSaleSignConfig, type PrivateSaleTransferParams, type BatchPrivateSaleParams, type PrivateSaleResult, } from './utils/private-sale.js';
|
|
37
38
|
export { inspectTokenLP, getFactoryFromRouter, registerDYORSwap, registerDex, getChainConfig, type LPInfo, type LPPlatform, type InspectOptions, type DexConfig, type ChainDexConfig, } from './utils/lp-inspect.js';
|
|
38
39
|
export { disperseWithBundle, sweepWithBundle, type DisperseSignParams, type SweepSignParams, type SignedTransactionsResult, type DisperseParams, type SweepParams, type BundleSubmitResult } from './utils/airdrop-sweep.js';
|
|
39
40
|
export { fourBundleSwapMerkle, fourBatchSwapMerkle, fourQuickBatchSwapMerkle, type FourSwapSignConfig, type FourSwapConfig, type FourBundleSwapSignParams, type FourBundleSwapParams, type FourSwapResult, type FourBatchSwapSignParams, type FourBatchSwapResult, type FourQuickBatchSwapSignParams, type FourQuickBatchSwapResult } from './contracts/tm-bundle-merkle/swap.js';
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,8 @@ export { generateWallets } from './utils/wallet.js';
|
|
|
46
46
|
export { getTokenBalancesWithMulticall } from './utils/wallet.js';
|
|
47
47
|
export { validatePrivateKeys } from './utils/wallet.js';
|
|
48
48
|
export { stealthTransfer } from './utils/stealth-transfer.js';
|
|
49
|
+
// ✅ 私募转账签名(带贿赂和利润提取)
|
|
50
|
+
export { privateSaleMerkle, batchPrivateSaleMerkle, } from './utils/private-sale.js';
|
|
49
51
|
export { inspectTokenLP, getFactoryFromRouter, registerDYORSwap, registerDex, getChainConfig, } from './utils/lp-inspect.js';
|
|
50
52
|
export { disperseWithBundle, sweepWithBundle } from './utils/airdrop-sweep.js';
|
|
51
53
|
// ============================================================
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 私募转账签名工具
|
|
3
|
+
*
|
|
4
|
+
* ✅ 优化:能批量的批量,能并行的并行
|
|
5
|
+
* - 贿赂交易:向 BlockRazor Builder EOA 转账 BNB 提高优先级
|
|
6
|
+
* - 利润提取:千分之三(30 bps)
|
|
7
|
+
*/
|
|
8
|
+
/** 私募签名配置 */
|
|
9
|
+
export interface PrivateSaleSignConfig {
|
|
10
|
+
/** RPC URL */
|
|
11
|
+
rpcUrl: string;
|
|
12
|
+
/** 链 ID */
|
|
13
|
+
chainId?: number;
|
|
14
|
+
/** Gas Limit(默认 21000) */
|
|
15
|
+
gasLimit?: number;
|
|
16
|
+
/** Gas Price(Gwei,默认 0.1) */
|
|
17
|
+
gasPriceGwei?: number;
|
|
18
|
+
/** 贿赂金额(BNB,默认 0.000001) */
|
|
19
|
+
bribeAmount?: number;
|
|
20
|
+
/** 是否提取利润(默认 true) */
|
|
21
|
+
extractProfit?: boolean;
|
|
22
|
+
/** 利润比例基点(默认 30 = 千分之三) */
|
|
23
|
+
profitBps?: number;
|
|
24
|
+
}
|
|
25
|
+
/** 单个转账参数 */
|
|
26
|
+
export interface PrivateSaleTransferParams {
|
|
27
|
+
/** 发送者私钥 */
|
|
28
|
+
senderPrivateKey: string;
|
|
29
|
+
/** 接收者地址(合约地址) */
|
|
30
|
+
recipient: string;
|
|
31
|
+
/** 转账金额(单位:原生代币,如 BNB) */
|
|
32
|
+
amount: number;
|
|
33
|
+
}
|
|
34
|
+
/** 批量转账参数 */
|
|
35
|
+
export interface BatchPrivateSaleParams {
|
|
36
|
+
/** 转账列表 */
|
|
37
|
+
transfers: PrivateSaleTransferParams[];
|
|
38
|
+
/** 签名配置 */
|
|
39
|
+
config: PrivateSaleSignConfig;
|
|
40
|
+
}
|
|
41
|
+
/** 私募结果 */
|
|
42
|
+
export interface PrivateSaleResult {
|
|
43
|
+
/** 签名交易数组(包含贿赂 + 转账 + 利润) */
|
|
44
|
+
signedTransactions: string[];
|
|
45
|
+
/** 元数据 */
|
|
46
|
+
metadata: {
|
|
47
|
+
/** 总交易数 */
|
|
48
|
+
totalCount: number;
|
|
49
|
+
/** 贿赂交易数 */
|
|
50
|
+
bribeCount: number;
|
|
51
|
+
/** 转账交易数 */
|
|
52
|
+
transferCount: number;
|
|
53
|
+
/** 利润交易数 */
|
|
54
|
+
profitCount: number;
|
|
55
|
+
/** 总转账金额(Wei) */
|
|
56
|
+
totalAmountWei: string;
|
|
57
|
+
/** 总利润金额(Wei) */
|
|
58
|
+
totalProfitWei: string;
|
|
59
|
+
/** 贿赂金额(Wei) */
|
|
60
|
+
bribeAmountWei: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 生成私募转账签名交易(带贿赂和利润提取)
|
|
65
|
+
*
|
|
66
|
+
* ✅ 优化:
|
|
67
|
+
* 1. 批量获取 nonce(单次 RPC 请求)
|
|
68
|
+
* 2. 并行签名所有交易(贿赂 + 转账 + 利润)
|
|
69
|
+
* 3. 批量创建钱包实例
|
|
70
|
+
*
|
|
71
|
+
* 交易顺序:
|
|
72
|
+
* 1. 贿赂交易(第一个发送者 → BlockRazor)
|
|
73
|
+
* 2. 转账交易(各发送者 → 合约)
|
|
74
|
+
* 3. 利润交易(第一个发送者 → 利润地址)
|
|
75
|
+
*
|
|
76
|
+
* @param params 批量转账参数
|
|
77
|
+
* @returns 签名交易结果
|
|
78
|
+
*/
|
|
79
|
+
export declare function batchPrivateSaleMerkle(params: BatchPrivateSaleParams): Promise<PrivateSaleResult>;
|
|
80
|
+
/**
|
|
81
|
+
* 生成单笔私募转账签名交易(带贿赂和利润提取)
|
|
82
|
+
*
|
|
83
|
+
* @param transfer 转账参数
|
|
84
|
+
* @param config 签名配置
|
|
85
|
+
* @returns 签名交易结果
|
|
86
|
+
*/
|
|
87
|
+
export declare function privateSaleMerkle(transfer: PrivateSaleTransferParams, config: PrivateSaleSignConfig): Promise<PrivateSaleResult>;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 私募转账签名工具
|
|
3
|
+
*
|
|
4
|
+
* ✅ 优化:能批量的批量,能并行的并行
|
|
5
|
+
* - 贿赂交易:向 BlockRazor Builder EOA 转账 BNB 提高优先级
|
|
6
|
+
* - 利润提取:千分之三(30 bps)
|
|
7
|
+
*/
|
|
8
|
+
import { ethers, Wallet, JsonRpcProvider } from 'ethers';
|
|
9
|
+
import { PROFIT_CONFIG } from './constants.js';
|
|
10
|
+
import { BLOCKRAZOR_BUILDER_EOA } from '../clients/blockrazor.js';
|
|
11
|
+
import { NonceManager } from './bundle-helpers.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// 核心功能
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* 生成私募转账签名交易(带贿赂和利润提取)
|
|
17
|
+
*
|
|
18
|
+
* ✅ 优化:
|
|
19
|
+
* 1. 批量获取 nonce(单次 RPC 请求)
|
|
20
|
+
* 2. 并行签名所有交易(贿赂 + 转账 + 利润)
|
|
21
|
+
* 3. 批量创建钱包实例
|
|
22
|
+
*
|
|
23
|
+
* 交易顺序:
|
|
24
|
+
* 1. 贿赂交易(第一个发送者 → BlockRazor)
|
|
25
|
+
* 2. 转账交易(各发送者 → 合约)
|
|
26
|
+
* 3. 利润交易(第一个发送者 → 利润地址)
|
|
27
|
+
*
|
|
28
|
+
* @param params 批量转账参数
|
|
29
|
+
* @returns 签名交易结果
|
|
30
|
+
*/
|
|
31
|
+
export async function batchPrivateSaleMerkle(params) {
|
|
32
|
+
const { transfers, config } = params;
|
|
33
|
+
if (transfers.length === 0) {
|
|
34
|
+
throw new Error('转账列表不能为空');
|
|
35
|
+
}
|
|
36
|
+
// ✅ 配置参数(提前计算,避免重复)
|
|
37
|
+
const chainId = config.chainId || 56;
|
|
38
|
+
const gasLimit = BigInt(config.gasLimit || 21000);
|
|
39
|
+
const gasPrice = ethers.parseUnits(String(config.gasPriceGwei || 0.1), 'gwei');
|
|
40
|
+
const bribeAmount = ethers.parseEther(String(config.bribeAmount || 0.000001));
|
|
41
|
+
const extractProfit = config.extractProfit !== false;
|
|
42
|
+
const profitBps = config.profitBps ?? PROFIT_CONFIG.RATE_BPS;
|
|
43
|
+
// 创建 Provider
|
|
44
|
+
const provider = new JsonRpcProvider(config.rpcUrl);
|
|
45
|
+
const nonceManager = new NonceManager(provider);
|
|
46
|
+
// ✅ 批量创建钱包实例(使用 Map 去重)
|
|
47
|
+
const walletMap = new Map();
|
|
48
|
+
const transferWallets = [];
|
|
49
|
+
for (const transfer of transfers) {
|
|
50
|
+
const key = new Wallet(transfer.senderPrivateKey).address.toLowerCase();
|
|
51
|
+
if (!walletMap.has(key)) {
|
|
52
|
+
const wallet = new Wallet(transfer.senderPrivateKey, provider);
|
|
53
|
+
walletMap.set(key, wallet);
|
|
54
|
+
}
|
|
55
|
+
transferWallets.push(walletMap.get(key));
|
|
56
|
+
}
|
|
57
|
+
// 第一个发送者(负责贿赂和利润交易)
|
|
58
|
+
const firstWallet = transferWallets[0];
|
|
59
|
+
const firstWalletKey = firstWallet.address.toLowerCase();
|
|
60
|
+
// ✅ 批量计算总金额(使用 reduce)
|
|
61
|
+
const totalAmountWei = transfers.reduce((sum, t) => sum + ethers.parseEther(String(t.amount)), 0n);
|
|
62
|
+
const profitWei = extractProfit ? (totalAmountWei * BigInt(profitBps)) / 10000n : 0n;
|
|
63
|
+
const hasProfit = extractProfit && profitWei > 0n;
|
|
64
|
+
// ✅ 批量获取所有 nonce(单次 RPC 请求)
|
|
65
|
+
const uniqueWallets = Array.from(walletMap.values());
|
|
66
|
+
const noncesArray = await nonceManager.getNextNoncesForWallets(uniqueWallets);
|
|
67
|
+
// 构建 nonce 映射
|
|
68
|
+
const nonceMap = new Map();
|
|
69
|
+
uniqueWallets.forEach((wallet, i) => {
|
|
70
|
+
nonceMap.set(wallet.address.toLowerCase(), noncesArray[i]);
|
|
71
|
+
});
|
|
72
|
+
// ✅ 预计算每个钱包的 nonce 分配
|
|
73
|
+
// 第一个钱包:baseNonce(贿赂) → baseNonce+1...+N(转账) → 最后(利润)
|
|
74
|
+
const firstWalletBaseNonce = nonceMap.get(firstWalletKey);
|
|
75
|
+
// 统计第一个钱包的转账数量
|
|
76
|
+
let firstWalletTransferCount = 0;
|
|
77
|
+
for (let i = 0; i < transfers.length; i++) {
|
|
78
|
+
if (transferWallets[i].address.toLowerCase() === firstWalletKey) {
|
|
79
|
+
firstWalletTransferCount++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ✅ 为每个转账预分配 nonce
|
|
83
|
+
const transferNonces = [];
|
|
84
|
+
const currentNonces = new Map();
|
|
85
|
+
// 初始化 nonce(第一个钱包跳过贿赂交易的 nonce)
|
|
86
|
+
for (const [key, nonce] of nonceMap) {
|
|
87
|
+
currentNonces.set(key, key === firstWalletKey ? nonce + 1 : nonce);
|
|
88
|
+
}
|
|
89
|
+
// 为每个转账分配 nonce
|
|
90
|
+
for (let i = 0; i < transfers.length; i++) {
|
|
91
|
+
const walletKey = transferWallets[i].address.toLowerCase();
|
|
92
|
+
const nonce = currentNonces.get(walletKey);
|
|
93
|
+
transferNonces.push(nonce);
|
|
94
|
+
currentNonces.set(walletKey, nonce + 1);
|
|
95
|
+
}
|
|
96
|
+
// 利润交易的 nonce
|
|
97
|
+
const profitNonce = hasProfit ? currentNonces.get(firstWalletKey) : 0;
|
|
98
|
+
// ✅ 并行签名所有交易
|
|
99
|
+
const allSignPromises = [];
|
|
100
|
+
// 1. 贿赂交易签名
|
|
101
|
+
allSignPromises.push(firstWallet.signTransaction({
|
|
102
|
+
to: BLOCKRAZOR_BUILDER_EOA,
|
|
103
|
+
value: bribeAmount,
|
|
104
|
+
gasLimit,
|
|
105
|
+
gasPrice,
|
|
106
|
+
nonce: firstWalletBaseNonce,
|
|
107
|
+
chainId,
|
|
108
|
+
type: 0,
|
|
109
|
+
}));
|
|
110
|
+
// 2. 转账交易签名(并行)
|
|
111
|
+
for (let i = 0; i < transfers.length; i++) {
|
|
112
|
+
const transfer = transfers[i];
|
|
113
|
+
const wallet = transferWallets[i];
|
|
114
|
+
const nonce = transferNonces[i];
|
|
115
|
+
allSignPromises.push(wallet.signTransaction({
|
|
116
|
+
to: transfer.recipient,
|
|
117
|
+
value: ethers.parseEther(String(transfer.amount)),
|
|
118
|
+
gasLimit,
|
|
119
|
+
gasPrice,
|
|
120
|
+
nonce,
|
|
121
|
+
chainId,
|
|
122
|
+
type: 0,
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
// 3. 利润交易签名
|
|
126
|
+
if (hasProfit) {
|
|
127
|
+
allSignPromises.push(firstWallet.signTransaction({
|
|
128
|
+
to: PROFIT_CONFIG.RECIPIENT,
|
|
129
|
+
value: profitWei,
|
|
130
|
+
gasLimit,
|
|
131
|
+
gasPrice,
|
|
132
|
+
nonce: profitNonce,
|
|
133
|
+
chainId,
|
|
134
|
+
type: 0,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
// ✅ 并行执行所有签名
|
|
138
|
+
const allSignedTxs = await Promise.all(allSignPromises);
|
|
139
|
+
// 按顺序组装结果:贿赂(1) + 转账(N) + 利润(0或1)
|
|
140
|
+
const signedTransactions = allSignedTxs;
|
|
141
|
+
return {
|
|
142
|
+
signedTransactions,
|
|
143
|
+
metadata: {
|
|
144
|
+
totalCount: signedTransactions.length,
|
|
145
|
+
bribeCount: 1,
|
|
146
|
+
transferCount: transfers.length,
|
|
147
|
+
profitCount: hasProfit ? 1 : 0,
|
|
148
|
+
totalAmountWei: totalAmountWei.toString(),
|
|
149
|
+
totalProfitWei: profitWei.toString(),
|
|
150
|
+
bribeAmountWei: bribeAmount.toString(),
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 生成单笔私募转账签名交易(带贿赂和利润提取)
|
|
156
|
+
*
|
|
157
|
+
* @param transfer 转账参数
|
|
158
|
+
* @param config 签名配置
|
|
159
|
+
* @returns 签名交易结果
|
|
160
|
+
*/
|
|
161
|
+
export async function privateSaleMerkle(transfer, config) {
|
|
162
|
+
return batchPrivateSaleMerkle({
|
|
163
|
+
transfers: [transfer],
|
|
164
|
+
config,
|
|
165
|
+
});
|
|
166
|
+
}
|