four-flap-meme-sdk 1.4.98 → 1.4.99
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.
|
@@ -176,7 +176,21 @@ function resolveBuyerAmounts(buyers, totalAmountStr, useNativeToken, quoteTokenD
|
|
|
176
176
|
const provided = buyers.map(b => b?.buyAmount).filter(v => v != null && String(v).trim() !== '');
|
|
177
177
|
const allProvided = provided.length === buyers.length;
|
|
178
178
|
if (allProvided) {
|
|
179
|
-
|
|
179
|
+
// ✅ 所有买家都显式提供了 buyAmount:按传入金额构建,但要修正“浮点/四舍五入导致总和偏差”
|
|
180
|
+
const amounts = buyers.map(b => parseQuoteAmount(String(b.buyAmount), useNativeToken, quoteTokenDecimals));
|
|
181
|
+
const totalWei = parseQuoteAmount(totalAmountStr, useNativeToken, quoteTokenDecimals);
|
|
182
|
+
const sum = amounts.reduce((a, b) => a + b, 0n);
|
|
183
|
+
const delta = totalWei - sum;
|
|
184
|
+
if (delta !== 0n && amounts.length > 0) {
|
|
185
|
+
// 优先修正最后一个金额(对应 create-to-dex 里“最后一单可能触发毕业”的假设)
|
|
186
|
+
const lastIdx = amounts.length - 1;
|
|
187
|
+
const next = amounts[lastIdx] + delta;
|
|
188
|
+
if (next <= 0n) {
|
|
189
|
+
throw new Error(`买入金额总和与总额不一致且无法修正:sum=${sum} total=${totalWei} delta=${delta}`);
|
|
190
|
+
}
|
|
191
|
+
amounts[lastIdx] = next;
|
|
192
|
+
}
|
|
193
|
+
return amounts;
|
|
180
194
|
}
|
|
181
195
|
const totalWei = parseQuoteAmount(totalAmountStr, useNativeToken, quoteTokenDecimals);
|
|
182
196
|
return splitAmount(totalWei, buyers.length);
|