four-flap-meme-sdk 1.7.73 → 1.7.75

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.
@@ -47,6 +47,8 @@ export interface DirectRouterSignConfig {
47
47
  slippageBps?: number;
48
48
  /** BlockRazor 贿赂金额(BNB),仅 BSC 链有效,用于提高 bundle 打包优先级 */
49
49
  bribeAmount?: number;
50
+ /** ✅ 利润模式:'single'(默认,从最大钱包统一扣)或 'distributed'(每个钱包独立扣) */
51
+ profitMode?: 'single' | 'distributed';
50
52
  }
51
53
  export interface DirectV2BuyParams {
52
54
  chain: 'BSC' | 'MONAD' | 'XLAYER';
@@ -101,6 +103,7 @@ export interface DirectRouterResult {
101
103
  signedTransactions: string[];
102
104
  profitHopWallets?: GeneratedWallet[];
103
105
  metadata?: {
106
+ profitMode?: 'single' | 'distributed';
104
107
  profitAmount: string;
105
108
  profitRecipient: string;
106
109
  totalFlow: string;
@@ -605,18 +605,57 @@ export async function directV2BatchBuy(params) {
605
605
  const bribeTxs = signedResults.filter(r => r.type === 'bribe').map(r => r.tx);
606
606
  const swapTxs = signedResults.filter(r => r.type === 'swap').sort((a, b) => a.index - b.index).map(r => r.tx);
607
607
  const signedTxs = [...bribeTxs, ...swapTxs];
608
- // ✅ 利润多跳转账(强制 2 跳中转)
608
+ // ✅ 检查是否使用分布式利润模式
609
+ const profitMode = config.profitMode || 'single';
610
+ console.log('🔧 [SDK directV2BatchBuy] profitMode:', profitMode, 'wallets:', wallets.length);
611
+ // 利润多跳转账
609
612
  let profitHopWallets;
610
613
  if (hasProfit) {
611
- const profitNonce = nonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
612
- const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxFlowIndex], profitWei, profitNonce, gasPrice, chainId, txType);
613
- signedTxs.push(...profitResult.signedTransactions);
614
- profitHopWallets = profitResult.hopWallets; // 收集利润多跳钱包
614
+ if (profitMode === 'distributed') {
615
+ // 分布式模式:每个钱包独立扣除自己的利润
616
+ const MAX_DISTRIBUTED_WALLETS = 12;
617
+ if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
618
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
619
+ }
620
+ profitHopWallets = [];
621
+ // 计算每个钱包的利润(按比例分配)
622
+ for (let i = 0; i < wallets.length; i++) {
623
+ const walletProfit = totalFlowWei > 0n
624
+ ? (profitWei * flowAmounts[i]) / totalFlowWei
625
+ : 0n;
626
+ if (walletProfit > 0n) {
627
+ const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
628
+ const profitResult = await buildProfitHopTransactions({
629
+ provider,
630
+ payerWallet: wallets[i],
631
+ profitAmount: walletProfit,
632
+ profitRecipient: PROFIT_CONFIG.RECIPIENT,
633
+ hopCount: PROFIT_HOP_COUNT,
634
+ gasPrice,
635
+ chainId,
636
+ txType,
637
+ startNonce: walletProfitNonce
638
+ });
639
+ signedTxs.push(...profitResult.signedTransactions);
640
+ if (profitResult.hopWallets) {
641
+ profitHopWallets.push(...profitResult.hopWallets);
642
+ }
643
+ }
644
+ }
645
+ }
646
+ else {
647
+ // ✅ 单一模式(默认):从金额最大的钱包统一扣除
648
+ const profitNonce = nonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
649
+ const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxFlowIndex], profitWei, profitNonce, gasPrice, chainId, txType);
650
+ signedTxs.push(...profitResult.signedTransactions);
651
+ profitHopWallets = profitResult.hopWallets;
652
+ }
615
653
  }
616
654
  return {
617
655
  signedTransactions: signedTxs,
618
- profitHopWallets, // ✅ 返回利润多跳钱包
656
+ profitHopWallets,
619
657
  metadata: {
658
+ profitMode, // ✅ 返回使用的利润模式
620
659
  profitAmount: ethers.formatEther(profitWei),
621
660
  profitRecipient: PROFIT_CONFIG.RECIPIENT,
622
661
  totalFlow: ethers.formatUnits(totalFlowWei, quoteTokenDecimals),
@@ -765,14 +804,52 @@ export async function directV2BatchSell(params) {
765
804
  nativeProfitPromise
766
805
  ]);
767
806
  const profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
768
- // 利润多跳转账(强制 2 跳中转)
807
+ // 检查是否使用分布式利润模式
808
+ const profitMode = config.profitMode || 'single';
809
+ console.log('🔧 [SDK directV2BatchSell] profitMode:', profitMode, 'wallets:', wallets.length);
810
+ // 利润多跳转账
769
811
  let profitTxs = [];
770
812
  let profitHopWallets;
771
813
  if (profitWei > 0n && wallets.length > 0) {
772
- const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
773
- const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType);
774
- profitTxs = profitResult.signedTransactions;
775
- profitHopWallets = profitResult.hopWallets; // 收集利润多跳钱包
814
+ if (profitMode === 'distributed') {
815
+ // 分布式模式:每个钱包独立扣除自己的利润
816
+ const MAX_DISTRIBUTED_WALLETS = 12;
817
+ if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
818
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
819
+ }
820
+ profitHopWallets = [];
821
+ // 计算每个钱包的利润(按卖出金额比例分配)
822
+ for (let i = 0; i < wallets.length; i++) {
823
+ const walletProfit = totalSellAmount > 0n
824
+ ? (profitWei * sellAmountsWei[i]) / totalSellAmount
825
+ : 0n;
826
+ if (walletProfit > 0n) {
827
+ const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
828
+ const profitResult = await buildProfitHopTransactions({
829
+ provider,
830
+ payerWallet: wallets[i],
831
+ profitAmount: walletProfit,
832
+ profitRecipient: PROFIT_CONFIG.RECIPIENT,
833
+ hopCount: PROFIT_HOP_COUNT,
834
+ gasPrice,
835
+ chainId,
836
+ txType,
837
+ startNonce: walletProfitNonce
838
+ });
839
+ profitTxs.push(...profitResult.signedTransactions);
840
+ if (profitResult.hopWallets) {
841
+ profitHopWallets.push(...profitResult.hopWallets);
842
+ }
843
+ }
844
+ }
845
+ }
846
+ else {
847
+ // ✅ 单一模式(默认):从卖出金额最大的钱包统一扣除
848
+ const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
849
+ const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType);
850
+ profitTxs = profitResult.signedTransactions;
851
+ profitHopWallets = profitResult.hopWallets;
852
+ }
776
853
  }
777
854
  // 按类型分组并按顺序组装
778
855
  const validResults = signedResults.filter((r) => r !== null);
@@ -781,8 +858,9 @@ export async function directV2BatchSell(params) {
781
858
  const signedTxs = [...bribeTxs, ...swapTxs, ...profitTxs];
782
859
  return {
783
860
  signedTransactions: signedTxs,
784
- profitHopWallets, // ✅ 返回利润多跳钱包
861
+ profitHopWallets,
785
862
  metadata: {
863
+ profitMode, // ✅ 返回使用的利润模式
786
864
  profitAmount: ethers.formatEther(profitWei),
787
865
  profitRecipient: PROFIT_CONFIG.RECIPIENT,
788
866
  totalFlow: ethers.formatEther(totalSellAmount),
@@ -878,20 +956,59 @@ export async function directV3BatchBuy(params) {
878
956
  const signedResults = await Promise.all(signPromises);
879
957
  const bribeTxs = signedResults.filter(r => r.type === 'bribe').map(r => r.tx);
880
958
  const swapTxs = signedResults.filter(r => r.type === 'swap').sort((a, b) => a.index - b.index).map(r => r.tx);
881
- // 利润多跳转账(强制 2 跳中转)
959
+ // 检查是否使用分布式利润模式
960
+ const profitMode = config.profitMode || 'single';
961
+ console.log('🔧 [SDK directV3BatchBuy] profitMode:', profitMode, 'wallets:', wallets.length);
962
+ // 利润多跳转账
882
963
  let profitTxs = [];
883
964
  let profitHopWallets;
884
965
  if (hasProfit) {
885
- const profitNonce = nonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
886
- const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxFlowIndex], profitWei, profitNonce, gasPrice, chainId, txType);
887
- profitTxs = profitResult.signedTransactions;
888
- profitHopWallets = profitResult.hopWallets; // 收集利润多跳钱包
966
+ if (profitMode === 'distributed') {
967
+ // 分布式模式:每个钱包独立扣除自己的利润
968
+ const MAX_DISTRIBUTED_WALLETS = 12;
969
+ if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
970
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
971
+ }
972
+ profitHopWallets = [];
973
+ // 计算每个钱包的利润(按比例分配)
974
+ for (let i = 0; i < wallets.length; i++) {
975
+ const walletProfit = totalFlowWei > 0n
976
+ ? (profitWei * flowAmounts[i]) / totalFlowWei
977
+ : 0n;
978
+ if (walletProfit > 0n) {
979
+ const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
980
+ const profitResult = await buildProfitHopTransactions({
981
+ provider,
982
+ payerWallet: wallets[i],
983
+ profitAmount: walletProfit,
984
+ profitRecipient: PROFIT_CONFIG.RECIPIENT,
985
+ hopCount: PROFIT_HOP_COUNT,
986
+ gasPrice,
987
+ chainId,
988
+ txType,
989
+ startNonce: walletProfitNonce
990
+ });
991
+ profitTxs.push(...profitResult.signedTransactions);
992
+ if (profitResult.hopWallets) {
993
+ profitHopWallets.push(...profitResult.hopWallets);
994
+ }
995
+ }
996
+ }
997
+ }
998
+ else {
999
+ // ✅ 单一模式(默认):从金额最大的钱包统一扣除
1000
+ const profitNonce = nonces[maxFlowIndex] + nonceOffsets[maxFlowIndex] + 1;
1001
+ const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxFlowIndex], profitWei, profitNonce, gasPrice, chainId, txType);
1002
+ profitTxs = profitResult.signedTransactions;
1003
+ profitHopWallets = profitResult.hopWallets;
1004
+ }
889
1005
  }
890
1006
  const signedTxs = [...bribeTxs, ...swapTxs, ...profitTxs];
891
1007
  return {
892
1008
  signedTransactions: signedTxs,
893
- profitHopWallets, // ✅ 返回利润多跳钱包
1009
+ profitHopWallets,
894
1010
  metadata: {
1011
+ profitMode, // ✅ 返回使用的利润模式
895
1012
  profitAmount: ethers.formatEther(profitWei),
896
1013
  profitRecipient: PROFIT_CONFIG.RECIPIENT,
897
1014
  totalFlow: ethers.formatUnits(totalFlowWei, quoteTokenDecimals),
@@ -1026,14 +1143,52 @@ export async function directV3BatchSell(params) {
1026
1143
  nativeProfitPromise
1027
1144
  ]);
1028
1145
  const profitWei = nativeProfitWei > 0n ? nativeProfitWei : 0n;
1029
- // 利润多跳转账(强制 2 跳中转)
1146
+ // 检查是否使用分布式利润模式
1147
+ const profitMode = config.profitMode || 'single';
1148
+ console.log('🔧 [SDK directV3BatchSell] profitMode:', profitMode, 'wallets:', wallets.length);
1149
+ // 利润多跳转账
1030
1150
  let profitTxs = [];
1031
1151
  let profitHopWallets;
1032
1152
  if (profitWei > 0n && wallets.length > 0) {
1033
- const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
1034
- const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType);
1035
- profitTxs = profitResult.signedTransactions;
1036
- profitHopWallets = profitResult.hopWallets; // 收集利润多跳钱包
1153
+ if (profitMode === 'distributed') {
1154
+ // 分布式模式:每个钱包独立扣除自己的利润
1155
+ const MAX_DISTRIBUTED_WALLETS = 12;
1156
+ if (wallets.length > MAX_DISTRIBUTED_WALLETS) {
1157
+ throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${wallets.length} 个`);
1158
+ }
1159
+ profitHopWallets = [];
1160
+ // 计算每个钱包的利润(按卖出金额比例分配)
1161
+ for (let i = 0; i < wallets.length; i++) {
1162
+ const walletProfit = totalSellAmount > 0n
1163
+ ? (profitWei * sellAmountsWei[i]) / totalSellAmount
1164
+ : 0n;
1165
+ if (walletProfit > 0n) {
1166
+ const walletProfitNonce = nonces[i] + nonceOffsets[i] + 1;
1167
+ const profitResult = await buildProfitHopTransactions({
1168
+ provider,
1169
+ payerWallet: wallets[i],
1170
+ profitAmount: walletProfit,
1171
+ profitRecipient: PROFIT_CONFIG.RECIPIENT,
1172
+ hopCount: PROFIT_HOP_COUNT,
1173
+ gasPrice,
1174
+ chainId,
1175
+ txType,
1176
+ startNonce: walletProfitNonce
1177
+ });
1178
+ profitTxs.push(...profitResult.signedTransactions);
1179
+ if (profitResult.hopWallets) {
1180
+ profitHopWallets.push(...profitResult.hopWallets);
1181
+ }
1182
+ }
1183
+ }
1184
+ }
1185
+ else {
1186
+ // ✅ 单一模式(默认):从卖出金额最大的钱包统一扣除
1187
+ const profitNonce = nonces[maxOutputIndex] + nonceOffsets[maxOutputIndex] + 1;
1188
+ const profitResult = await buildProfitTransactionWithHops(provider, wallets[maxOutputIndex], profitWei, profitNonce, gasPrice, chainId, txType);
1189
+ profitTxs = profitResult.signedTransactions;
1190
+ profitHopWallets = profitResult.hopWallets;
1191
+ }
1037
1192
  }
1038
1193
  // 按类型分组并按顺序组装
1039
1194
  const validResults = signedResults.filter((r) => r !== null);
@@ -1042,8 +1197,9 @@ export async function directV3BatchSell(params) {
1042
1197
  const signedTxs = [...bribeTxs, ...swapTxs, ...profitTxs];
1043
1198
  return {
1044
1199
  signedTransactions: signedTxs,
1045
- profitHopWallets, // ✅ 返回利润多跳钱包
1200
+ profitHopWallets,
1046
1201
  metadata: {
1202
+ profitMode, // ✅ 返回使用的利润模式
1047
1203
  profitAmount: ethers.formatEther(profitWei),
1048
1204
  profitRecipient: PROFIT_CONFIG.RECIPIENT,
1049
1205
  totalFlow: ethers.formatEther(totalSellAmount),
@@ -343,11 +343,13 @@ export async function batchBuyWithBundleMerkle(params) {
343
343
  let profitHopWallets;
344
344
  // ✅ 检查是否使用分布式利润模式
345
345
  const profitMode = config.profitMode || 'single';
346
+ console.log('🔧 [SDK batchBuyWithBundleMerkle] config.profitMode:', config.profitMode, '-> resolved:', profitMode, 'wallets:', buyers.length);
346
347
  if (extractProfit && nativeProfitAmount > 0n) {
347
348
  if (profitMode === 'distributed') {
348
349
  // ✅ 分布式模式:每个钱包独立扣除自己的利润,每个都有独立的多跳
349
350
  // 最多支持 12 个钱包(12 交易 + 36 多跳 + 1 贿赂 = 49 笔)
350
351
  const MAX_DISTRIBUTED_WALLETS = 12;
352
+ console.log('🔧 [SDK] 使用分布式利润模式,钱包数:', buyers.length);
351
353
  if (buyers.length > MAX_DISTRIBUTED_WALLETS) {
352
354
  throw new Error(`分布式利润模式最多支持 ${MAX_DISTRIBUTED_WALLETS} 个钱包,当前 ${buyers.length} 个`);
353
355
  }
@@ -552,6 +554,7 @@ export async function batchSellWithBundleMerkle(params) {
552
554
  let profitHopWallets;
553
555
  // ✅ 检查是否使用分布式利润模式
554
556
  const profitMode = config.profitMode || 'single';
557
+ console.log('🔧 [SDK batchSellWithBundleMerkle] config.profitMode:', config.profitMode, '-> resolved:', profitMode, 'wallets:', wallets.length);
555
558
  if (needProfitTx) {
556
559
  // ERC20 输出时:获取代币利润等值的原生代币(BNB)报价
557
560
  let totalNativeProfitAmount = totalTokenProfit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.7.73",
3
+ "version": "1.7.75",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",