four-flap-meme-sdk 1.4.69 → 1.4.70

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.
@@ -45,7 +45,8 @@ function validateSwapCounts(buyCount, sellCount) {
45
45
  }
46
46
  }
47
47
  /**
48
- * 将金额均匀拆分成多份
48
+ * ✅ 将金额随机拆分成多份(更自然,不像机器人)
49
+ * 每份金额在平均值的 50%-150% 之间随机浮动
49
50
  */
50
51
  function splitAmount(totalAmount, count) {
51
52
  if (count <= 0) {
@@ -54,13 +55,31 @@ function splitAmount(totalAmount, count) {
54
55
  if (count === 1) {
55
56
  return [totalAmount];
56
57
  }
57
- const baseAmount = totalAmount / BigInt(count);
58
- const remainder = totalAmount % BigInt(count);
58
+ // 生成随机权重(0.5 - 1.5 之间)
59
+ const weights = [];
60
+ for (let i = 0; i < count; i++) {
61
+ // 随机值在 0.5 - 1.5 之间,使每份金额有 ±50% 的浮动
62
+ weights.push(0.5 + Math.random());
63
+ }
64
+ // 计算权重总和
65
+ const totalWeight = weights.reduce((a, b) => a + b, 0);
66
+ // 根据权重分配金额
59
67
  const amounts = [];
68
+ let allocated = 0n;
60
69
  for (let i = 0; i < count - 1; i++) {
61
- amounts.push(baseAmount);
70
+ // 按权重比例分配
71
+ const ratio = weights[i] / totalWeight;
72
+ const amount = BigInt(Math.floor(Number(totalAmount) * ratio));
73
+ amounts.push(amount);
74
+ allocated += amount;
75
+ }
76
+ // 最后一份分配剩余的全部(确保总和精确)
77
+ amounts.push(totalAmount - allocated);
78
+ // 随机打乱顺序(让大小金额交错出现)
79
+ for (let i = amounts.length - 1; i > 0; i--) {
80
+ const j = Math.floor(Math.random() * (i + 1));
81
+ [amounts[i], amounts[j]] = [amounts[j], amounts[i]];
62
82
  }
63
- amounts.push(baseAmount + remainder);
64
83
  return amounts;
65
84
  }
66
85
  export async function fourBundleBuyFirstMerkle(params) {
@@ -405,10 +405,10 @@ function calculateMultiProfitAmount(expectedFunds, rateBps) {
405
405
  return (expectedFunds * BigInt(rateBps)) / 10000n;
406
406
  }
407
407
  /**
408
- * 将金额均匀拆分成多份
408
+ * ✅ 将金额随机拆分成多份(更自然,不像机器人)
409
409
  * @param totalAmount - 总金额
410
410
  * @param count - 拆分份数
411
- * @returns 拆分后的金额数组(最后一份包含余数)
411
+ * @returns 拆分后的金额数组(随机分配,总和精确)
412
412
  */
413
413
  function splitAmount(totalAmount, count) {
414
414
  if (count <= 0) {
@@ -417,14 +417,31 @@ function splitAmount(totalAmount, count) {
417
417
  if (count === 1) {
418
418
  return [totalAmount];
419
419
  }
420
- const baseAmount = totalAmount / BigInt(count);
421
- const remainder = totalAmount % BigInt(count);
422
- // count-1 份使用基础金额,最后一份包含余数
420
+ // 生成随机权重(0.5 - 1.5 之间)
421
+ const weights = [];
422
+ for (let i = 0; i < count; i++) {
423
+ // 随机值在 0.5 - 1.5 之间,使每份金额有 ±50% 的浮动
424
+ weights.push(0.5 + Math.random());
425
+ }
426
+ // 计算权重总和
427
+ const totalWeight = weights.reduce((a, b) => a + b, 0);
428
+ // 根据权重分配金额
423
429
  const amounts = [];
430
+ let allocated = 0n;
424
431
  for (let i = 0; i < count - 1; i++) {
425
- amounts.push(baseAmount);
432
+ // 按权重比例分配
433
+ const ratio = weights[i] / totalWeight;
434
+ const amount = BigInt(Math.floor(Number(totalAmount) * ratio));
435
+ amounts.push(amount);
436
+ allocated += amount;
437
+ }
438
+ // 最后一份分配剩余的全部(确保总和精确)
439
+ amounts.push(totalAmount - allocated);
440
+ // 随机打乱顺序(让大小金额交错出现)
441
+ for (let i = amounts.length - 1; i > 0; i--) {
442
+ const j = Math.floor(Math.random() * (i + 1));
443
+ [amounts[i], amounts[j]] = [amounts[j], amounts[i]];
426
444
  }
427
- amounts.push(baseAmount + remainder);
428
445
  return amounts;
429
446
  }
430
447
  /**
@@ -72,7 +72,8 @@ function validateSwapCounts(buyCount, sellCount) {
72
72
  }
73
73
  }
74
74
  /**
75
- * 将金额均匀拆分成多份
75
+ * ✅ 将金额随机拆分成多份(更自然,不像机器人)
76
+ * 每份金额在平均值的 50%-150% 之间随机浮动
76
77
  */
77
78
  function splitAmount(totalAmount, count) {
78
79
  if (count <= 0) {
@@ -81,13 +82,31 @@ function splitAmount(totalAmount, count) {
81
82
  if (count === 1) {
82
83
  return [totalAmount];
83
84
  }
84
- const baseAmount = totalAmount / BigInt(count);
85
- const remainder = totalAmount % BigInt(count);
85
+ // 生成随机权重(0.5 - 1.5 之间)
86
+ const weights = [];
87
+ for (let i = 0; i < count; i++) {
88
+ // 随机值在 0.5 - 1.5 之间,使每份金额有 ±50% 的浮动
89
+ weights.push(0.5 + Math.random());
90
+ }
91
+ // 计算权重总和
92
+ const totalWeight = weights.reduce((a, b) => a + b, 0);
93
+ // 根据权重分配金额
86
94
  const amounts = [];
95
+ let allocated = 0n;
87
96
  for (let i = 0; i < count - 1; i++) {
88
- amounts.push(baseAmount);
97
+ // 按权重比例分配
98
+ const ratio = weights[i] / totalWeight;
99
+ const amount = BigInt(Math.floor(Number(totalAmount) * ratio));
100
+ amounts.push(amount);
101
+ allocated += amount;
102
+ }
103
+ // 最后一份分配剩余的全部(确保总和精确)
104
+ amounts.push(totalAmount - allocated);
105
+ // 随机打乱顺序(让大小金额交错出现)
106
+ for (let i = amounts.length - 1; i > 0; i--) {
107
+ const j = Math.floor(Math.random() * (i + 1));
108
+ [amounts[i], amounts[j]] = [amounts[j], amounts[i]];
89
109
  }
90
- amounts.push(baseAmount + remainder);
91
110
  return amounts;
92
111
  }
93
112
  export async function pancakeBundleBuyFirstMerkle(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.4.69",
3
+ "version": "1.4.70",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",