diff --git a/ride/lp.ride b/ride/lp.ride index 92621fa5..0798fab2 100644 --- a/ride/lp.ride +++ b/ride/lp.ride @@ -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 ++ diff --git a/ride/lp_stable.ride b/ride/lp_stable.ride index cfe334a0..7cf09df7 100644 --- a/ride/lp_stable.ride +++ b/ride/lp_stable.ride @@ -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 ( [