Skip to content

Commit

Permalink
Merge pull request #397 from waves-exchange/wxdefi-457-fix-swap
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
JunkiJay authored Aug 16, 2023
2 parents ed7704c + fd1ad87 commit da04606
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ride/lp.ride
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,18 @@ func calculateAmountOutForSwapAndSendTokens(cleanAmountIn: Int, isReverse: Boole
strict checkK = newK >= oldK || "new K is fewer error".throw()
strict checkMin = amountOutMin <= amountOut || "Exchange result is fewer coins than expected".throw()

let amountAssetBalanceDelta = if (isReverse) then {
-amountOut
} else {
feePoolAmount
}
let priceAssetBalanceDelta = if (isReverse) then {
feePoolAmount
} else {
-amountOut
}
strict refreshKLpActions = refreshKLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)._1

strict rebalanceState = rebalanceAsset(assetIn)
strict withdrawState = withdrawAndRebalanceAsset(assetOut, amountOut)
( withdrawState ++
Expand Down
12 changes: 12 additions & 0 deletions ride/lp_stable.ride
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,18 @@ func calculateAmountOutForSwapAndSendTokens(cleanAmountIn: Int, isReverse: Boole
}
let newD = newXp.getD()
strict checkD = newD >= D || "new D is fewer error".throw()

let amountAssetBalanceDelta = if (isReverse) then {
-totalGetRaw
} else {
feePoolAmount
}
let priceAssetBalanceDelta = if (isReverse) then {
feePoolAmount
} else {
-totalGetRaw
}
strict refreshDLpActions = refreshDLpInternal(amountAssetBalanceDelta, priceAssetBalanceDelta, 0)._1

(
[
Expand Down

0 comments on commit da04606

Please sign in to comment.