four-flap-meme-sdk 1.4.49 → 1.4.50
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/abis/common.js +4 -0
- package/dist/utils/holders-maker.js +100 -14
- package/package.json +1 -1
package/dist/abis/common.js
CHANGED
|
@@ -234,6 +234,10 @@ export const FLAP_PORTAL_ABI = [
|
|
|
234
234
|
// Four TokenManager ABI
|
|
235
235
|
// ============================================================================
|
|
236
236
|
export const TM2_ABI = [
|
|
237
|
+
// 新版方法(Four.meme TokenManager2)
|
|
238
|
+
'function buyTokenAMAP(uint256 origin, address token, address to, uint256 funds, uint256 minAmount) external payable',
|
|
239
|
+
'function sellToken(uint256 origin, address token, uint256 amount, uint256 minFunds) external',
|
|
240
|
+
// 旧版兼容方法
|
|
237
241
|
'function buy(address token, uint256 minReceived) external payable returns (uint256)',
|
|
238
242
|
'function sell(address token, uint256 sellAmount, uint256 minReceived) external returns (uint256)',
|
|
239
243
|
'function trySell(address token, uint256 sellAmount) external view returns (uint256)',
|
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
* 一键完成:生成钱包 → 分发资金 → 批量买入(同一个 bundle 完成)
|
|
6
6
|
* 支持原生代币(BNB/MON)和 ERC20 代币(USDT/USDC)作为购买资金
|
|
7
7
|
*/
|
|
8
|
-
import { ethers, JsonRpcProvider, Wallet } from 'ethers';
|
|
8
|
+
import { ethers, JsonRpcProvider, Wallet, Contract } from 'ethers';
|
|
9
9
|
import { generateWallets } from './wallet.js';
|
|
10
|
-
import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT } from './bundle-helpers.js';
|
|
10
|
+
import { NonceManager, getOptimizedGasPrice, buildProfitHopTransactions, PROFIT_HOP_COUNT, getDeadline } from './bundle-helpers.js';
|
|
11
11
|
import { ADDRESSES, BLOCKRAZOR_BUILDER_EOA, PROFIT_CONFIG } from './constants.js';
|
|
12
12
|
import { FLAP_PORTAL_ADDRESSES } from '../flap/constants.js';
|
|
13
|
+
import { V2_ROUTER_ABI, V3_ROUTER02_ABI } from '../abis/common.js';
|
|
13
14
|
// Four 内盘 ABI
|
|
14
15
|
const FOUR_TM2_ABI = [
|
|
15
16
|
'function buyTokenAMAP(uint256 origin, address token, address to, uint256 funds, uint256 minAmount) payable'
|
|
16
17
|
];
|
|
18
|
+
// PancakeSwap Router 地址
|
|
19
|
+
const PANCAKE_V2_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV2Router;
|
|
20
|
+
const PANCAKE_V3_ROUTER_ADDRESS = ADDRESSES.BSC.PancakeV3Router;
|
|
21
|
+
const WBNB_ADDRESS = ADDRESSES.BSC.WBNB;
|
|
17
22
|
// ============================================================================
|
|
18
23
|
// 常量
|
|
19
24
|
// ============================================================================
|
|
@@ -136,6 +141,72 @@ async function buildFourBuyTx(wallet, tokenAddress, buyAmount, nonce, gasPrice,
|
|
|
136
141
|
}
|
|
137
142
|
return await wallet.signTransaction(tx);
|
|
138
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* 构建 V2 买入交易
|
|
146
|
+
* BNB → Token (使用 swapExactETHForTokensSupportingFeeOnTransferTokens)
|
|
147
|
+
*/
|
|
148
|
+
async function buildV2BuyTx(wallet, tokenAddress, buyAmount, nonce, gasPrice, gasLimit, chainId, txType, v2Path) {
|
|
149
|
+
// 默认路径: WBNB → Token
|
|
150
|
+
const path = v2Path ? [...v2Path].reverse() : [WBNB_ADDRESS, tokenAddress];
|
|
151
|
+
const deadline = getDeadline();
|
|
152
|
+
const v2Router = new Contract(PANCAKE_V2_ROUTER_ADDRESS, V2_ROUTER_ABI, wallet);
|
|
153
|
+
const unsigned = await v2Router.swapExactETHForTokensSupportingFeeOnTransferTokens.populateTransaction(0n, // amountOutMin(不设滑点保护)
|
|
154
|
+
path, wallet.address, deadline, { value: buyAmount });
|
|
155
|
+
const tx = {
|
|
156
|
+
...unsigned,
|
|
157
|
+
nonce,
|
|
158
|
+
gasLimit: BigInt(gasLimit),
|
|
159
|
+
chainId
|
|
160
|
+
};
|
|
161
|
+
if (txType === 2) {
|
|
162
|
+
tx.maxFeePerGas = gasPrice;
|
|
163
|
+
tx.maxPriorityFeePerGas = gasPrice / 10n || 1n;
|
|
164
|
+
tx.type = 2;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
tx.gasPrice = gasPrice;
|
|
168
|
+
tx.type = 0;
|
|
169
|
+
}
|
|
170
|
+
return await wallet.signTransaction(tx);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 构建 V3 单跳买入交易
|
|
174
|
+
* BNB → Token (使用 exactInputSingle + multicall)
|
|
175
|
+
*/
|
|
176
|
+
async function buildV3BuyTx(wallet, tokenAddress, buyAmount, nonce, gasPrice, gasLimit, chainId, txType, v3Fee = 2500 // 默认 0.25% 手续费
|
|
177
|
+
) {
|
|
178
|
+
const deadline = getDeadline();
|
|
179
|
+
const v3RouterIface = new ethers.Interface(V3_ROUTER02_ABI);
|
|
180
|
+
// 构建 exactInputSingle calldata
|
|
181
|
+
const exactInputSingleData = v3RouterIface.encodeFunctionData('exactInputSingle', [{
|
|
182
|
+
tokenIn: WBNB_ADDRESS,
|
|
183
|
+
tokenOut: tokenAddress,
|
|
184
|
+
fee: v3Fee,
|
|
185
|
+
recipient: wallet.address,
|
|
186
|
+
amountIn: buyAmount,
|
|
187
|
+
amountOutMinimum: 0n,
|
|
188
|
+
sqrtPriceLimitX96: 0n
|
|
189
|
+
}]);
|
|
190
|
+
// 使用 multicall 包装,传入 deadline 和 ETH value
|
|
191
|
+
const v3Router = new Contract(PANCAKE_V3_ROUTER_ADDRESS, V3_ROUTER02_ABI, wallet);
|
|
192
|
+
const unsigned = await v3Router.multicall.populateTransaction(deadline, [exactInputSingleData], { value: buyAmount });
|
|
193
|
+
const tx = {
|
|
194
|
+
...unsigned,
|
|
195
|
+
nonce,
|
|
196
|
+
gasLimit: BigInt(gasLimit),
|
|
197
|
+
chainId
|
|
198
|
+
};
|
|
199
|
+
if (txType === 2) {
|
|
200
|
+
tx.maxFeePerGas = gasPrice;
|
|
201
|
+
tx.maxPriorityFeePerGas = gasPrice / 10n || 1n;
|
|
202
|
+
tx.type = 2;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
tx.gasPrice = gasPrice;
|
|
206
|
+
tx.type = 0;
|
|
207
|
+
}
|
|
208
|
+
return await wallet.signTransaction(tx);
|
|
209
|
+
}
|
|
139
210
|
// ============================================================================
|
|
140
211
|
// 主方法
|
|
141
212
|
// ============================================================================
|
|
@@ -169,9 +240,10 @@ export async function holdersMaker(params) {
|
|
|
169
240
|
result.error = '一个 bundle 模式仅支持原生代币(BNB/MON),ERC20 模式需要分开提交';
|
|
170
241
|
return result;
|
|
171
242
|
}
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
243
|
+
// ✅ 支持 four、flap 内盘和 v2、v3 外盘
|
|
244
|
+
const supportedTradeTypes = ['four', 'flap', 'v2', 'v3'];
|
|
245
|
+
if (!supportedTradeTypes.includes(tradeType)) {
|
|
246
|
+
result.error = `不支持的交易类型: ${tradeType},支持: ${supportedTradeTypes.join(', ')}`;
|
|
175
247
|
return result;
|
|
176
248
|
}
|
|
177
249
|
try {
|
|
@@ -226,15 +298,29 @@ export async function holdersMaker(params) {
|
|
|
226
298
|
for (const newWallet of batch) {
|
|
227
299
|
const buyerWallet = new Wallet(newWallet.privateKey, provider);
|
|
228
300
|
let buyTx;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
301
|
+
switch (tradeType) {
|
|
302
|
+
case 'four':
|
|
303
|
+
// Four 内盘
|
|
304
|
+
buyTx = await buildFourBuyTx(buyerWallet, tokenAddress, buyAmountWei, 0, // 新钱包 nonce=0
|
|
305
|
+
gasPrice, gasLimit, chainId, txType);
|
|
306
|
+
break;
|
|
307
|
+
case 'flap':
|
|
308
|
+
// Flap 内盘
|
|
309
|
+
buyTx = await buildFlapBuyTx(buyerWallet, tokenAddress, buyAmountWei, 0, // 新钱包 nonce=0
|
|
310
|
+
gasPrice, gasLimit, chainId, txType, chain);
|
|
311
|
+
break;
|
|
312
|
+
case 'v2':
|
|
313
|
+
// PancakeSwap V2
|
|
314
|
+
buyTx = await buildV2BuyTx(buyerWallet, tokenAddress, buyAmountWei, 0, // 新钱包 nonce=0
|
|
315
|
+
gasPrice, gasLimit, chainId, txType, config.v2Path);
|
|
316
|
+
break;
|
|
317
|
+
case 'v3':
|
|
318
|
+
// PancakeSwap V3
|
|
319
|
+
buyTx = await buildV3BuyTx(buyerWallet, tokenAddress, buyAmountWei, 0, // 新钱包 nonce=0
|
|
320
|
+
gasPrice, gasLimit, chainId, txType, config.v3Fee);
|
|
321
|
+
break;
|
|
322
|
+
default:
|
|
323
|
+
throw new Error(`不支持的交易类型: ${tradeType}`);
|
|
238
324
|
}
|
|
239
325
|
signedTxs.push(buyTx);
|
|
240
326
|
}
|