Skip to content

Commit

Permalink
return remaining amount (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberliem authored Feb 20, 2024
1 parent 71a06a9 commit eb4634d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions entities/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ type SwapResult struct {
amountCalculated *big.Int
sqrtRatioX96 *big.Int
liquidity *big.Int
remainingAmountIn *big.Int
currentTick int
crossInitTickLoops int
}

type GetAmountResult struct {
ReturnedAmount *entities.CurrencyAmount
RemainingAmountIn *entities.CurrencyAmount
NewPoolState *Pool
CrossInitTickLoops int
}
Expand Down Expand Up @@ -191,6 +193,7 @@ func (p *Pool) GetOutputAmount(inputAmount *entities.CurrencyAmount, sqrtPriceLi
}
return &GetAmountResult{
ReturnedAmount: entities.FromRawAmount(outputToken, new(big.Int).Mul(swapResult.amountCalculated, constants.NegativeOne)),
RemainingAmountIn: entities.FromRawAmount(inputAmount.Currency, swapResult.remainingAmountIn),
NewPoolState: pool,
CrossInitTickLoops: swapResult.crossInitTickLoops,
}, nil
Expand Down Expand Up @@ -375,11 +378,11 @@ func (p *Pool) swap(zeroForOne bool, amountSpecified, sqrtPriceLimitX96 *big.Int
}
}
return &SwapResult{
amountCalculated: state.amountCalculated,
sqrtRatioX96: state.sqrtPriceX96,
liquidity: state.liquidity,
currentTick: state.tick,

amountCalculated: state.amountCalculated,
sqrtRatioX96: state.sqrtPriceX96,
liquidity: state.liquidity,
currentTick: state.tick,
remainingAmountIn: state.amountSpecifiedRemaining,
crossInitTickLoops: crossInitTickLoops,
}, nil
}
Expand Down

0 comments on commit eb4634d

Please sign in to comment.