diff --git a/pkg/source/smardex/pool_simulator.go b/pkg/source/smardex/pool_simulator.go index f167ddfda..0e04a4893 100644 --- a/pkg/source/smardex/pool_simulator.go +++ b/pkg/source/smardex/pool_simulator.go @@ -112,6 +112,7 @@ func (p *PoolSimulator) CalcAmountOut(tokenAmountIn poolpkg.TokenAmount, tokenOu amount0, amount1 := tokenAmountIn.Amount, result.amountOut feeToAmount0, feeToAmount1 := p.FeeToAmount.Fees0, p.FeeToAmount.Fees1 newPriceAverageIn, newPriceAverageOut := priceAverageIn, priceAverageOut + newFictiveReserveIn, newFictiveReserveOut := result.newFictiveReserveIn, result.newFictiveReserveOut if zeroForOne { feeToAmount0 = feeToAmount0.Add( feeToAmount0, @@ -122,6 +123,7 @@ func (p *PoolSimulator) CalcAmountOut(tokenAmountIn poolpkg.TokenAmount, tokenOu feeToAmount1, new(big.Int).Div(new(big.Int).Mul(amount1, p.PairFee.FeesPool), p.PairFee.FeesBase)) newPriceAverageIn, newPriceAverageOut = priceAverageOut, priceAverageIn + newFictiveReserveIn, newFictiveReserveOut = result.newFictiveReserveOut, result.newFictiveReserveIn } if zeroForOne { @@ -138,8 +140,8 @@ func (p *PoolSimulator) CalcAmountOut(tokenAmountIn poolpkg.TokenAmount, tokenOu SwapInfo: SwapInfo{ NewReserveIn: new(big.Int).Sub(result.newReserveIn, feeToAmount0), NewReserveOut: new(big.Int).Sub(result.newReserveOut, feeToAmount1), - NewFictiveReserveIn: result.newFictiveReserveIn, - NewFictiveReserveOut: result.newFictiveReserveOut, + NewFictiveReserveIn: newFictiveReserveIn, + NewFictiveReserveOut: newFictiveReserveOut, NewPriceAverageIn: newPriceAverageIn, NewPriceAverageOut: newPriceAverageOut, PriceAverageLastTimestamp: big.NewInt(userTradeTimestamp), @@ -162,8 +164,8 @@ func (p *PoolSimulator) CalcAmountOut(tokenAmountIn poolpkg.TokenAmount, tokenOu SwapInfo: SwapInfo{ NewReserveIn: new(big.Int).Sub(result.newReserveIn, feeToAmount0), NewReserveOut: new(big.Int).Sub(result.newReserveOut, feeToAmount1), - NewFictiveReserveIn: result.newFictiveReserveIn, - NewFictiveReserveOut: result.newFictiveReserveOut, + NewFictiveReserveIn: newFictiveReserveIn, + NewFictiveReserveOut: newFictiveReserveOut, NewPriceAverageIn: newPriceAverageIn, NewPriceAverageOut: newPriceAverageOut, PriceAverageLastTimestamp: big.NewInt(userTradeTimestamp), diff --git a/pkg/source/smardex/pool_simulator_test.go b/pkg/source/smardex/pool_simulator_test.go index e5259d711..50d3e8764 100644 --- a/pkg/source/smardex/pool_simulator_test.go +++ b/pkg/source/smardex/pool_simulator_test.go @@ -155,6 +155,25 @@ func TestGetAmountOut(t *testing.T) { expectedResFictive0: parseString("85593526029"), expectedResFictive1: parseString("7289358689105108450240064"), }, + { + name: "Test case 3", + amountParams: GetAmountParameters{ + amount: big.NewInt(2000000000000000000), + reserveIn: parseString("3278796445628485066"), + reserveOut: parseString("6213633437"), + fictiveReserveIn: parseString("1602466039436492633"), + fictiveReserveOut: parseString("3179127537"), + priceAverageIn: parseString("1602466039436492633"), + priceAverageOut: parseString("3179127537"), + feesLP: FEES_LP_DEFAULT_ETHEREUM, + feesPool: FEES_POOL_DEFAULT_ETHEREUM, + feesBase: FEES_BASE_ETHEREUM}, + expectedAmountOutT0: parseString("1719846589"), + expectedReserve0: parseString("5278396445628485066"), + expectedReserve1: parseString("4493786848"), + expectedResFictive0: parseString("3530568934927624489"), + expectedResFictive1: parseString("1317438058"), + }, } for _, tc := range testCases {