mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-19 13:29:56 +00:00
fix(amm): reserve balance for exact-output slippage
This commit is contained in:
parent
7b595dc5da
commit
a8de6b498c
@ -79,11 +79,13 @@ Rectangle {
|
||||
readonly property string limitText: exactOutput
|
||||
? swapState.formatTokenAmount(maxSentAmount, sellToken ? sellToken.symbol : "")
|
||||
: swapState.formatTokenAmount(minReceivedAmount, buyToken ? buyToken.symbol : "")
|
||||
readonly property real sellBalanceRequirement: exactOutput
|
||||
? maxSentAmount : parsedSellAmount
|
||||
|
||||
readonly property bool hasAmount: editingSide === "sell" ? parsedSellInput > 0 : parsedBuyInput > 0
|
||||
readonly property bool tokensSelected: sellToken !== null && buyToken !== null
|
||||
readonly property bool sameTokenSelected: isSameToken(sellToken, buyToken)
|
||||
readonly property bool insufficientBalance: hasAmount && sellToken !== null && parsedSellAmount > (sellToken.balance || 0)
|
||||
readonly property bool insufficientBalance: hasAmount && sellToken !== null && sellBalanceRequirement > (sellToken.balance || 0)
|
||||
readonly property bool insufficientLiquidity: hasAmount && buyToken !== null && parsedBuyAmount > (buyToken.reserve || 0)
|
||||
readonly property bool canSubmit: tokensSelected && !sameTokenSelected && hasAmount && parsedSellAmount > 0 && parsedBuyAmount > 0 && !insufficientBalance && !insufficientLiquidity
|
||||
|
||||
|
||||
@ -108,6 +108,25 @@ Item {
|
||||
verify(Number(snapshot.minReceived) < Number(snapshot.buyAmount))
|
||||
}
|
||||
|
||||
function test_exactOutputRequiresBalanceForMaximumInput() {
|
||||
const page = createTemporaryObject(pageComponent, root)
|
||||
verify(page)
|
||||
|
||||
const card = findChild(page, "swapCard")
|
||||
verify(card)
|
||||
card.setToken("sell", page.tokens[0])
|
||||
card.setToken("buy", page.tokens[1])
|
||||
card.slippageTolerancePercent = 10
|
||||
card.buyInput = "11500"
|
||||
card.editingSide = "buy"
|
||||
|
||||
verify(card.parsedSellAmount < card.sellToken.balance)
|
||||
verify(card.maxSentAmount > card.sellToken.balance)
|
||||
verify(card.insufficientBalance)
|
||||
verify(!card.canSubmit)
|
||||
compare(card.submitButtonText, "Insufficient balance")
|
||||
}
|
||||
|
||||
function test_reselectingOppositeTokenSwapsPair() {
|
||||
const page = createTemporaryObject(pageComponent, root)
|
||||
verify(page)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user