four-flap-meme-sdk 1.2.82 → 1.2.84
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.
|
@@ -86,33 +86,88 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
86
86
|
const tmBuyAddr = ADDRESSES.BSC.TokenManagerOriginal;
|
|
87
87
|
const b0AmountWei = ethers.parseEther(params.b0Amount ?? '0');
|
|
88
88
|
const preSaleWei = tokenInfo.preSale ? ethers.parseEther(tokenInfo.preSale) : 0n;
|
|
89
|
-
const
|
|
90
|
-
// ✅ 单笔交易: value = 创建费用 + b0Amount + preSale + 买入金额
|
|
91
|
-
const valueWei = PLATFORM_CREATE_FEE + b0AmountWei + preSaleWei + buyAmountWei;
|
|
89
|
+
const valueWei = PLATFORM_CREATE_FEE + b0AmountWei + preSaleWei;
|
|
92
90
|
const tmCreate = new ethers.Contract(tmCreateAddr, TM2_ABI, devWallet);
|
|
93
|
-
|
|
94
|
-
// Four.meme 合约会自动处理: 如果 value 大于创建费用,会自动买入
|
|
95
|
-
const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei } // ✅ 包含买入金额
|
|
96
|
-
);
|
|
91
|
+
const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei });
|
|
97
92
|
const createTxRequest = {
|
|
98
93
|
...createTxUnsigned,
|
|
99
94
|
from: devWallet.address,
|
|
100
95
|
nonce: await nonceManager.getNextNonce(devWallet),
|
|
101
|
-
gasLimit: getGasLimit(config
|
|
96
|
+
gasLimit: getGasLimit(config),
|
|
102
97
|
gasPrice,
|
|
103
98
|
chainId,
|
|
104
99
|
type: getTxType(config),
|
|
105
100
|
value: valueWei
|
|
106
101
|
};
|
|
107
102
|
signedTxs.push(await devWallet.signTransaction(createTxRequest));
|
|
103
|
+
// ✅ Four.meme Bundle 机制:使用 0x0 地址作为占位符
|
|
104
|
+
// ⚠️ 关键:这2笔交易必须在同一个 Bundle 中原子执行!
|
|
105
|
+
const predictedTokenAddress = ZERO_ADDRESS;
|
|
106
|
+
console.log('✅ 使用 Four.meme Bundle 机制:0x0 地址将在 Bundle 执行时被解析为新创建的代币地址');
|
|
107
|
+
// ✅ 生成创建者的买入交易 (支持利润刮取)
|
|
108
|
+
const extractProfit = shouldExtractProfit(config);
|
|
109
|
+
const originalBuyAmount = ethers.parseEther(buyAmounts[0]);
|
|
110
|
+
let actualBuyFunds;
|
|
111
|
+
let profitAmount;
|
|
112
|
+
if (extractProfit) {
|
|
113
|
+
const { remaining, profit } = calculateProfit(originalBuyAmount, config);
|
|
114
|
+
actualBuyFunds = remaining;
|
|
115
|
+
profitAmount = profit;
|
|
116
|
+
console.log(`💰 利润刮取: 原始 ${ethers.formatEther(originalBuyAmount)} BNB → 实际买入 ${ethers.formatEther(actualBuyFunds)} BNB + 利润 ${ethers.formatEther(profitAmount)} BNB`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
actualBuyFunds = originalBuyAmount;
|
|
120
|
+
profitAmount = 0n;
|
|
121
|
+
}
|
|
122
|
+
const tmBuy = new ethers.Contract(tmBuyAddr, TM2_ABI, devWallet);
|
|
123
|
+
const buyTxUnsigned = await tmBuy.buyTokenAMAP.populateTransaction(0, // origin
|
|
124
|
+
predictedTokenAddress, // token (0x0 占位符)
|
|
125
|
+
devWallet.address, // to
|
|
126
|
+
actualBuyFunds, // funds (扣除利润后的金额)
|
|
127
|
+
0n, // minAmount
|
|
128
|
+
{ value: actualBuyFunds });
|
|
129
|
+
const buyTxRequest = {
|
|
130
|
+
...buyTxUnsigned,
|
|
131
|
+
from: devWallet.address,
|
|
132
|
+
nonce: await nonceManager.getNextNonce(devWallet),
|
|
133
|
+
gasLimit: getGasLimit(config),
|
|
134
|
+
gasPrice,
|
|
135
|
+
chainId,
|
|
136
|
+
type: txType,
|
|
137
|
+
value: actualBuyFunds
|
|
138
|
+
};
|
|
139
|
+
signedTxs.push(await devWallet.signTransaction(buyTxRequest));
|
|
140
|
+
// ✅ 添加利润转账交易
|
|
141
|
+
if (extractProfit && profitAmount > 0n) {
|
|
142
|
+
const profitNonce = await nonceManager.getNextNonce(devWallet);
|
|
143
|
+
const profitTx = await devWallet.signTransaction({
|
|
144
|
+
to: getProfitRecipient(),
|
|
145
|
+
value: profitAmount,
|
|
146
|
+
nonce: profitNonce,
|
|
147
|
+
gasPrice,
|
|
148
|
+
gasLimit: 21000n,
|
|
149
|
+
chainId,
|
|
150
|
+
type: txType
|
|
151
|
+
});
|
|
152
|
+
signedTxs.push(profitTx);
|
|
153
|
+
console.log(`💸 利润转账交易已生成: ${ethers.formatEther(profitAmount)} BNB → ${getProfitRecipient()}`);
|
|
154
|
+
}
|
|
108
155
|
nonceManager.clearTemp();
|
|
109
|
-
console.log(`✅
|
|
156
|
+
console.log(`✅ 总共生成了 ${signedTxs.length} 个交易签名 (1创建 + 1买入${extractProfit && profitAmount > 0n ? ' + 1利润' : ''})`);
|
|
110
157
|
// ⚠️ 只返回签名交易,不提交
|
|
111
158
|
console.log('📦 交易已签名完成');
|
|
112
|
-
console.log('
|
|
159
|
+
console.log('⚠️ 重要: 这些交易必须通过 48.club Bundle 原子提交,不能单独提交!');
|
|
160
|
+
// 构建元数据
|
|
161
|
+
const metadata = extractProfit && profitAmount > 0n ? {
|
|
162
|
+
totalBuyAmount: ethers.formatEther(originalBuyAmount),
|
|
163
|
+
profitAmount: ethers.formatEther(profitAmount),
|
|
164
|
+
profitRecipient: getProfitRecipient(),
|
|
165
|
+
buyerCount: 1
|
|
166
|
+
} : undefined;
|
|
113
167
|
return {
|
|
114
168
|
signedTransactions: signedTxs,
|
|
115
169
|
tokenAddress: ZERO_ADDRESS, // ⚠️ 占位符,实际地址需要等交易确认后从事件解析
|
|
170
|
+
metadata
|
|
116
171
|
};
|
|
117
172
|
}
|
|
118
173
|
export async function batchBuyWithBundleMerkle(params) {
|