Files
lez-programs/apps/amm/qml/state/DummySwapState.qml
r4bbit 4363f13912 feat(apps/amm): submit exact-output swaps and drop client-side swap math
Wire the Buy direction to submit: AmmUiBackend gains a swapExactOutput slot
(guarded like swapExactInput), SwapCard.executeSwap branches on direction —
sell -> swapExactInput(minReceivedRaw), buy -> swapExactOutput(maxInRaw) — and
canSubmit/submitButtonText/buildSnapshot handle both. The confirmation dialog
switches wording by mode ("You pay at most" / "You receive exactly" for exact
output). The Buy field is now digitsOnly since its value is submitted as a raw
base-units integer.

With both directions priced and oriented by the module, the client no longer
needs any pool math. Remove the reserve-orientation chain (sellIsPoolA,
buy/sellReserveNum, poolReserveA/B, poolDefAHex) — resolvePool now reports only
existence and fee — and the now-dead helpers (formatBaseUnits/formatAmountValue,
DummySwapState.amountInFor/minReceived/priceImpactPercent/maxSent). The
impossible-swap guard moves from a client reserve compare to the module's
output_exceeds_liquidity error, surfaced as "Insufficient liquidity".
2026-08-06 23:15:02 +02:00

43 lines
1.1 KiB
QML

import QtQuick 2.15
QtObject {
id: root
property int feeBps: 30
function parseAmount(value) {
return Math.max(0, Number(value) || 0);
}
function clampSlippagePercent(value) {
return Math.max(0, Math.min(50, Number(value) || 0));
}
function feeAmount(amountIn) {
return parseAmount(amountIn) * root.feeBps / 10000;
}
function formatAmountValue(value) {
const amount = Math.max(0, Number(value) || 0);
if (amount >= 1) return amount.toFixed(2);
if (amount >= 0.0001) return amount.toFixed(6);
return amount.toFixed(8);
}
function formatTokenAmount(value, symbol) {
const formatted = formatAmountValue(value);
return symbol ? formatted + " " + symbol : formatted;
}
function formatPercent(value) {
const amount = Number(value) || 0;
if (amount > 0 && amount < 0.01) return "<0.01%";
return amount.toFixed(2) + "%";
}
function formatSlippagePercent(value) {
const amount = clampSlippagePercent(value);
return amount.toFixed(2).replace(/0+$/, "").replace(/[.]$/, "") + "%";
}
}