diff --git a/pkg/source/limitorder/pool_simulator.go b/pkg/source/limitorder/pool_simulator.go index 8daf437ec..ec90bd2d0 100644 --- a/pkg/source/limitorder/pool_simulator.go +++ b/pkg/source/limitorder/pool_simulator.go @@ -107,10 +107,6 @@ func (p *PoolSimulator) CalcAmountOut(param pool.CalcAmountOutParams) (*pool.Cal return p.calcAmountOut(param.TokenAmountIn, param.TokenOut, param.Limit) } -func (p *PoolSimulator) CalcAmountIn(param pool.CalcAmountInParams) (*pool.CalcAmountInResult, error) { - return p.calcAmountIn(param.TokenAmountOut, param.TokenIn, param.Limit) -} - func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) { swapInfo, ok := params.SwapInfo.(SwapInfo) if !ok { @@ -169,30 +165,6 @@ func (p *PoolSimulator) calcAmountOut( }, nil } -func (p *PoolSimulator) calcAmountIn( - tokenAmountOut pool.TokenAmount, - tokenIn string, - limit pool.SwapLimit, -) (*pool.CalcAmountInResult, error) { - swapSide := p.getSwapSide(tokenIn, tokenAmountOut.Token) - amountIn, swapInfo, feeAmount, err := p.calcAmountInWithSwapInfo(swapSide, tokenAmountOut, limit) - if err != nil { - return nil, err - } - return &pool.CalcAmountInResult{ - TokenAmountIn: &pool.TokenAmount{ - Token: tokenIn, - Amount: amountIn, - }, - Fee: &pool.TokenAmount{ - Token: tokenIn, - Amount: feeAmount, - }, - Gas: p.estimateGas(len(swapInfo.FilledOrders)), - SwapInfo: swapInfo, - }, nil -} - func addFilledMakingAmount( filledMakingAmountByMaker map[string]*big.Int, maker string, diff --git a/pkg/source/limitorder/pool_simulator_calc_amount_in.go b/pkg/source/limitorder/pool_simulator_calc_amount_in.go index c4f0af709..cc2a0ead9 100644 --- a/pkg/source/limitorder/pool_simulator_calc_amount_in.go +++ b/pkg/source/limitorder/pool_simulator_calc_amount_in.go @@ -8,6 +8,34 @@ import ( constant "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber" ) +func (p *PoolSimulator) CalcAmountIn(param pool.CalcAmountInParams) (*pool.CalcAmountInResult, error) { + return p.calcAmountIn(param.TokenAmountOut, param.TokenIn, param.Limit) +} + +func (p *PoolSimulator) calcAmountIn( + tokenAmountOut pool.TokenAmount, + tokenIn string, + limit pool.SwapLimit, +) (*pool.CalcAmountInResult, error) { + swapSide := p.getSwapSide(tokenIn, tokenAmountOut.Token) + amountIn, swapInfo, feeAmount, err := p.calcAmountInWithSwapInfo(swapSide, tokenAmountOut, limit) + if err != nil { + return nil, err + } + return &pool.CalcAmountInResult{ + TokenAmountIn: &pool.TokenAmount{ + Token: tokenIn, + Amount: amountIn, + }, + Fee: &pool.TokenAmount{ + Token: tokenIn, + Amount: feeAmount, + }, + Gas: p.estimateGas(len(swapInfo.FilledOrders)), + SwapInfo: swapInfo, + }, nil +} + func (p *PoolSimulator) calcAmountInWithSwapInfo(swapSide SwapSide, tokenAmountOut pool.TokenAmount, limit pool.SwapLimit) (*big.Int, SwapInfo, *big.Int, error) { orderIDs := p.getOrderIDsBySwapSide(swapSide) if len(orderIDs) == 0 {