four-flap-meme-sdk 1.2.83 → 1.2.85

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.
@@ -84,54 +84,73 @@ export async function createTokenWithBundleBuyMerkle(params) {
84
84
  const signedTxs = [];
85
85
  const tmCreateAddr = ADDRESSES.BSC.TokenManagerOriginal;
86
86
  const tmBuyAddr = ADDRESSES.BSC.TokenManagerOriginal;
87
+ // ✅ 单笔交易: 和 Four.meme 官网一样
88
+ // 计算利润
89
+ const extractProfit = shouldExtractProfit(config);
90
+ const originalBuyAmount = ethers.parseEther(buyAmounts[0]);
91
+ let actualBuyFunds;
92
+ let profitAmount;
93
+ if (extractProfit) {
94
+ const { remaining, profit } = calculateProfit(originalBuyAmount, config);
95
+ actualBuyFunds = remaining;
96
+ profitAmount = profit;
97
+ console.log(`💰 利润刮取: 原始 ${ethers.formatEther(originalBuyAmount)} BNB → 实际买入 ${ethers.formatEther(actualBuyFunds)} BNB + 利润 ${ethers.formatEther(profitAmount)} BNB`);
98
+ }
99
+ else {
100
+ actualBuyFunds = originalBuyAmount;
101
+ profitAmount = 0n;
102
+ }
87
103
  const b0AmountWei = ethers.parseEther(params.b0Amount ?? '0');
88
104
  const preSaleWei = tokenInfo.preSale ? ethers.parseEther(tokenInfo.preSale) : 0n;
89
- const valueWei = PLATFORM_CREATE_FEE + b0AmountWei + preSaleWei;
105
+ // 关键: value = 创建费用 + b0Amount + preSale + 买入金额
106
+ // Four.meme 合约会自动处理: 如果 value > 创建费用,会自动用多余的金额买入
107
+ const valueWei = PLATFORM_CREATE_FEE + b0AmountWei + preSaleWei + actualBuyFunds;
90
108
  const tmCreate = new ethers.Contract(tmCreateAddr, TM2_ABI, devWallet);
91
- const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei });
109
+ const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei } // ✅ 包含买入金额
110
+ );
92
111
  const createTxRequest = {
93
112
  ...createTxUnsigned,
94
113
  from: devWallet.address,
95
114
  nonce: await nonceManager.getNextNonce(devWallet),
96
- gasLimit: getGasLimit(config),
115
+ gasLimit: getGasLimit(config, 1500000), // ✅ 增加 gas limit (创建+买入)
97
116
  gasPrice,
98
117
  chainId,
99
118
  type: getTxType(config),
100
119
  value: valueWei
101
120
  };
102
121
  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 creatorBuyAmountWei = ethers.parseEther(buyAmounts[0]);
109
- const tmBuy = new ethers.Contract(tmBuyAddr, TM2_ABI, devWallet);
110
- const buyTxUnsigned = await tmBuy.buyTokenAMAP.populateTransaction(0, // origin
111
- predictedTokenAddress, // token (0x0 占位符)
112
- devWallet.address, // to
113
- creatorBuyAmountWei, // funds
114
- 0n, // minAmount
115
- { value: creatorBuyAmountWei });
116
- const buyTxRequest = {
117
- ...buyTxUnsigned,
118
- from: devWallet.address,
119
- nonce: await nonceManager.getNextNonce(devWallet),
120
- gasLimit: getGasLimit(config),
121
- gasPrice,
122
- chainId,
123
- type: txType,
124
- value: creatorBuyAmountWei
125
- };
126
- signedTxs.push(await devWallet.signTransaction(buyTxRequest));
122
+ console.log(`✅ 生成创建+买入交易: value = ${ethers.formatEther(valueWei)} BNB (0.01创建 + ${ethers.formatEther(actualBuyFunds)}买入)`);
123
+ // 添加利润转账交易
124
+ if (extractProfit && profitAmount > 0n) {
125
+ const profitNonce = await nonceManager.getNextNonce(devWallet);
126
+ const profitTx = await devWallet.signTransaction({
127
+ to: getProfitRecipient(),
128
+ value: profitAmount,
129
+ nonce: profitNonce,
130
+ gasPrice,
131
+ gasLimit: 21000n,
132
+ chainId,
133
+ type: txType
134
+ });
135
+ signedTxs.push(profitTx);
136
+ console.log(`💸 利润转账交易已生成: ${ethers.formatEther(profitAmount)} BNB → ${getProfitRecipient()}`);
137
+ }
127
138
  nonceManager.clearTemp();
128
- console.log(`✅ 总共生成了 ${signedTxs.length} 个交易签名 (1创建 + 1买入)`);
139
+ console.log(`✅ 总共生成了 ${signedTxs.length} 个交易签名 (1创建+买入${extractProfit && profitAmount > 0n ? ' + 1利润' : ''})`);
129
140
  // ⚠️ 只返回签名交易,不提交
130
141
  console.log('📦 交易已签名完成');
131
- console.log('⚠️ 重要: 这2笔交易必须通过 48.club Bundle 原子提交,不能单独提交!');
142
+ console.log('💡 提示: 可以通过 Merkle Bundle 提交,或直接 broadcastTransaction');
143
+ // 构建元数据
144
+ const metadata = extractProfit && profitAmount > 0n ? {
145
+ totalBuyAmount: ethers.formatEther(originalBuyAmount),
146
+ profitAmount: ethers.formatEther(profitAmount),
147
+ profitRecipient: getProfitRecipient(),
148
+ buyerCount: 1
149
+ } : undefined;
132
150
  return {
133
151
  signedTransactions: signedTxs,
134
152
  tokenAddress: ZERO_ADDRESS, // ⚠️ 占位符,实际地址需要等交易确认后从事件解析
153
+ metadata
135
154
  };
136
155
  }
137
156
  export async function batchBuyWithBundleMerkle(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.83",
3
+ "version": "1.2.85",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",