four-flap-meme-sdk 1.4.69 → 1.4.71
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/contracts/tm-bundle-merkle/swap-buy-first.d.ts +2 -0
- package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +36 -11
- package/dist/flap/portal-bundle-merkle/swap-buy-first.d.ts +2 -0
- package/dist/flap/portal-bundle-merkle/swap-buy-first.js +28 -8
- package/dist/pancake/bundle-buy-first.d.ts +2 -0
- package/dist/pancake/bundle-buy-first.js +38 -11
- package/package.json +1 -1
|
@@ -47,6 +47,8 @@ export type FourBuyFirstResult = {
|
|
|
47
47
|
profitAmount?: string;
|
|
48
48
|
buyCount?: number;
|
|
49
49
|
sellCount?: number;
|
|
50
|
+
buyAmounts?: string[];
|
|
51
|
+
sellAmounts?: string[];
|
|
50
52
|
};
|
|
51
53
|
};
|
|
52
54
|
export declare function fourBundleBuyFirstMerkle(params: FourBundleBuyFirstSignParams): Promise<FourBuyFirstResult>;
|
|
@@ -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
|
-
|
|
58
|
-
const
|
|
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
|
-
|
|
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) {
|
|
@@ -120,11 +139,14 @@ export async function fourBundleBuyFirstMerkle(params) {
|
|
|
120
139
|
if (!estimatedTokenAmount || estimatedTokenAmount <= 0n) {
|
|
121
140
|
throw new Error('报价失败:无法估算可买入的代币数量');
|
|
122
141
|
}
|
|
123
|
-
// ✅
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
// ✅ 多笔买入时添加安全系数:减少 1% 卖出数量以应对报价误差/税/滑点
|
|
143
|
+
// 原因:多笔买入会产生滑点累积,实际获得的代币可能少于报价
|
|
144
|
+
// 单笔买入时不需要安全系数(与普通捆绑换手一致)
|
|
145
|
+
let sellAmountWei = estimatedTokenAmount;
|
|
146
|
+
if (buyCount > 1) {
|
|
147
|
+
const SELL_SAFETY_BPS = 100n; // 1% = 100 bps(仅多笔时)
|
|
148
|
+
sellAmountWei = estimatedTokenAmount * (10000n - SELL_SAFETY_BPS) / 10000n;
|
|
149
|
+
}
|
|
128
150
|
// 卖方余额检查
|
|
129
151
|
if (!sameAddress && sellerTokenBal < sellAmountWei) {
|
|
130
152
|
throw new Error(`卖方代币余额不足: 需要 ${ethers.formatUnits(sellAmountWei, decimals)},实际 ${ethers.formatUnits(sellerTokenBal, decimals)}`);
|
|
@@ -233,7 +255,10 @@ export async function fourBundleBuyFirstMerkle(params) {
|
|
|
233
255
|
profitAmount: extractProfit ? ethers.formatEther(profitAmount) : undefined,
|
|
234
256
|
// ✅ 返回多笔买卖信息
|
|
235
257
|
buyCount,
|
|
236
|
-
sellCount
|
|
258
|
+
sellCount,
|
|
259
|
+
// ✅ 返回每笔交易的具体金额(随机分配后的数组)
|
|
260
|
+
buyAmounts: buyAmountsWei.map(amt => ethers.formatEther(amt)),
|
|
261
|
+
sellAmounts: sellAmountsWei.map(amt => ethers.formatUnits(amt, decimals))
|
|
237
262
|
}
|
|
238
263
|
};
|
|
239
264
|
}
|
|
@@ -54,6 +54,8 @@ export type FlapBuyFirstResult = {
|
|
|
54
54
|
profitAmount?: string;
|
|
55
55
|
buyCount?: number;
|
|
56
56
|
sellCount?: number;
|
|
57
|
+
buyAmounts?: string[];
|
|
58
|
+
sellAmounts?: string[];
|
|
57
59
|
};
|
|
58
60
|
};
|
|
59
61
|
export declare function flapBundleBuyFirstMerkle(params: FlapBundleBuyFirstSignParams): Promise<FlapBuyFirstResult>;
|
|
@@ -279,7 +279,10 @@ export async function flapBundleBuyFirstMerkle(params) {
|
|
|
279
279
|
profitAmount: nativeProfitAmount > 0n ? ethers.formatEther(nativeProfitAmount) : undefined,
|
|
280
280
|
// ✅ 返回多笔买卖信息
|
|
281
281
|
buyCount,
|
|
282
|
-
sellCount
|
|
282
|
+
sellCount,
|
|
283
|
+
// ✅ 返回每笔交易的具体金额(随机分配后的数组)
|
|
284
|
+
buyAmounts: buyAmountsWei.map(amt => ethers.formatEther(amt)),
|
|
285
|
+
sellAmounts: sellAmountsWei.map(amt => ethers.formatUnits(amt, sellerInfo.decimals))
|
|
283
286
|
}
|
|
284
287
|
};
|
|
285
288
|
}
|
|
@@ -405,10 +408,10 @@ function calculateMultiProfitAmount(expectedFunds, rateBps) {
|
|
|
405
408
|
return (expectedFunds * BigInt(rateBps)) / 10000n;
|
|
406
409
|
}
|
|
407
410
|
/**
|
|
408
|
-
*
|
|
411
|
+
* ✅ 将金额随机拆分成多份(更自然,不像机器人)
|
|
409
412
|
* @param totalAmount - 总金额
|
|
410
413
|
* @param count - 拆分份数
|
|
411
|
-
* @returns
|
|
414
|
+
* @returns 拆分后的金额数组(随机分配,总和精确)
|
|
412
415
|
*/
|
|
413
416
|
function splitAmount(totalAmount, count) {
|
|
414
417
|
if (count <= 0) {
|
|
@@ -417,14 +420,31 @@ function splitAmount(totalAmount, count) {
|
|
|
417
420
|
if (count === 1) {
|
|
418
421
|
return [totalAmount];
|
|
419
422
|
}
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
+
// 生成随机权重(0.5 - 1.5 之间)
|
|
424
|
+
const weights = [];
|
|
425
|
+
for (let i = 0; i < count; i++) {
|
|
426
|
+
// 随机值在 0.5 - 1.5 之间,使每份金额有 ±50% 的浮动
|
|
427
|
+
weights.push(0.5 + Math.random());
|
|
428
|
+
}
|
|
429
|
+
// 计算权重总和
|
|
430
|
+
const totalWeight = weights.reduce((a, b) => a + b, 0);
|
|
431
|
+
// 根据权重分配金额
|
|
423
432
|
const amounts = [];
|
|
433
|
+
let allocated = 0n;
|
|
424
434
|
for (let i = 0; i < count - 1; i++) {
|
|
425
|
-
|
|
435
|
+
// 按权重比例分配
|
|
436
|
+
const ratio = weights[i] / totalWeight;
|
|
437
|
+
const amount = BigInt(Math.floor(Number(totalAmount) * ratio));
|
|
438
|
+
amounts.push(amount);
|
|
439
|
+
allocated += amount;
|
|
440
|
+
}
|
|
441
|
+
// 最后一份分配剩余的全部(确保总和精确)
|
|
442
|
+
amounts.push(totalAmount - allocated);
|
|
443
|
+
// 随机打乱顺序(让大小金额交错出现)
|
|
444
|
+
for (let i = amounts.length - 1; i > 0; i--) {
|
|
445
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
446
|
+
[amounts[i], amounts[j]] = [amounts[j], amounts[i]];
|
|
426
447
|
}
|
|
427
|
-
amounts.push(baseAmount + remainder);
|
|
428
448
|
return amounts;
|
|
429
449
|
}
|
|
430
450
|
/**
|
|
@@ -79,6 +79,8 @@ export type PancakeBuyFirstResult = {
|
|
|
79
79
|
profitAmount?: string;
|
|
80
80
|
buyCount?: number;
|
|
81
81
|
sellCount?: number;
|
|
82
|
+
buyAmounts?: string[];
|
|
83
|
+
sellAmounts?: string[];
|
|
82
84
|
};
|
|
83
85
|
};
|
|
84
86
|
export declare function pancakeBundleBuyFirstMerkle(params: PancakeBundleBuyFirstSignParams): Promise<PancakeBuyFirstResult>;
|
|
@@ -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
|
-
|
|
85
|
-
const
|
|
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
|
-
|
|
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) {
|
|
@@ -121,11 +140,14 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
121
140
|
buyerFundsWei: buyerFundsInfo.buyerFundsWei,
|
|
122
141
|
provider: context.provider
|
|
123
142
|
});
|
|
124
|
-
// ✅
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
// ✅ 多笔买入时添加安全系数:减少 1% 卖出数量以应对报价误差/税/滑点
|
|
144
|
+
// 原因:多笔买入会产生滑点累积,实际获得的代币可能少于报价
|
|
145
|
+
// 单笔买入时不需要安全系数(与普通捆绑换手一致)
|
|
146
|
+
let adjustedSellAmount = quoteResult.quotedTokenOut;
|
|
147
|
+
if (buyCount > 1) {
|
|
148
|
+
const SELL_SAFETY_BPS = 100n; // 1% = 100 bps(仅多笔时)
|
|
149
|
+
adjustedSellAmount = quoteResult.quotedTokenOut * (10000n - SELL_SAFETY_BPS) / 10000n;
|
|
150
|
+
}
|
|
129
151
|
// ✅ 拆分买入和卖出金额
|
|
130
152
|
const buyAmountsWei = splitAmount(buyerFundsInfo.buyerFundsWei, buyCount);
|
|
131
153
|
const sellAmountsWei = splitAmount(adjustedSellAmount, sellCount);
|
|
@@ -259,7 +281,12 @@ export async function pancakeBundleBuyFirstMerkle(params) {
|
|
|
259
281
|
profitAmount: profitAmount > 0n ? ethers.formatEther(profitAmount) : undefined,
|
|
260
282
|
// ✅ 返回多笔买卖信息
|
|
261
283
|
buyCount,
|
|
262
|
-
sellCount
|
|
284
|
+
sellCount,
|
|
285
|
+
// ✅ 返回每笔交易的具体金额(随机分配后的数组)
|
|
286
|
+
buyAmounts: buyAmountsWei.map(amt => useNativeToken
|
|
287
|
+
? ethers.formatEther(amt)
|
|
288
|
+
: ethers.formatUnits(amt, quoteTokenDecimals)),
|
|
289
|
+
sellAmounts: sellAmountsWei.map(amt => amt.toString())
|
|
263
290
|
}
|
|
264
291
|
};
|
|
265
292
|
}
|