four-flap-meme-sdk 1.4.31 → 1.4.32
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/pancake/bundle-swap.js +19 -6
- package/package.json +1 -1
|
@@ -57,18 +57,31 @@ async function quoteSellOutput({ routeParams, sellAmountWei, provider }) {
|
|
|
57
57
|
}
|
|
58
58
|
async function buildSwapTransactions({ routeParams, sellAmountWei, buyAmountBNB, buyer, seller, tokenAddress, useNativeToken = true }) {
|
|
59
59
|
const deadline = getDeadline();
|
|
60
|
-
// ✅ ERC20 购买时,value
|
|
61
|
-
const buyValue = useNativeToken ? buyAmountBNB + FLAT_FEE :
|
|
60
|
+
// ✅ ERC20 购买时,value = 0(通过代币授权支付)
|
|
61
|
+
const buyValue = useNativeToken ? buyAmountBNB + FLAT_FEE : 0n;
|
|
62
62
|
if (routeParams.routeType === 'v2') {
|
|
63
63
|
const { v2Path } = routeParams;
|
|
64
64
|
const reversePath = [...v2Path].reverse();
|
|
65
65
|
// ✅ 使用官方 V2 Router
|
|
66
66
|
const v2RouterSeller = new Contract(PANCAKE_V2_ROUTER_ADDRESS, PANCAKE_V2_ROUTER_ABI, seller);
|
|
67
67
|
const v2RouterBuyer = new Contract(PANCAKE_V2_ROUTER_ADDRESS, PANCAKE_V2_ROUTER_ABI, buyer);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
let sellUnsigned;
|
|
69
|
+
let buyUnsigned;
|
|
70
|
+
if (useNativeToken) {
|
|
71
|
+
// ✅ 原生代币模式(BNB)
|
|
72
|
+
// 卖出:Token → WBNB → BNB
|
|
73
|
+
sellUnsigned = await v2RouterSeller.swapExactTokensForETHSupportingFeeOnTransferTokens.populateTransaction(sellAmountWei, 0n, v2Path, seller.address, deadline);
|
|
74
|
+
// 买入:BNB → WBNB → Token
|
|
75
|
+
buyUnsigned = await v2RouterBuyer.swapExactETHForTokensSupportingFeeOnTransferTokens.populateTransaction(0n, reversePath, buyer.address, deadline, { value: buyValue });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// ✅ ERC20 模式(如 USDT)
|
|
79
|
+
// 卖出:Token → USDT
|
|
80
|
+
sellUnsigned = await v2RouterSeller.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(sellAmountWei, 0n, v2Path, seller.address, deadline);
|
|
81
|
+
// 买入:USDT → Token
|
|
82
|
+
buyUnsigned = await v2RouterBuyer.swapExactTokensForTokensSupportingFeeOnTransferTokens.populateTransaction(buyAmountBNB, // USDT 数量
|
|
83
|
+
0n, reversePath, buyer.address, deadline);
|
|
84
|
+
}
|
|
72
85
|
return { sellUnsigned, buyUnsigned };
|
|
73
86
|
}
|
|
74
87
|
if (routeParams.routeType === 'v3-single') {
|