Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Nov 14, 2024
1 parent 54913b4 commit 57bceea
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions tests/dex/state_cancel_limit_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func (s *DexStateTestSuite) setupCancelTest(params cancelLimitOrderTestParams) (
t := time.Now()
expTime = &t
}
res := s.makePlaceLOSuccess(s.creator, coinA, coinB.Denom, DefaultSellPrice, dextypes.LimitOrderType(params.OrderType), expTime)
res := s.makePlaceLOSuccess(s.creator, coinA, coinB.Denom, DefaultSellPrice, params.OrderType, expTime)

totalDeposited := BaseTokenAmountInt
if params.ExistingTokenAHolders == OneOtherAndCreatorLO {
totalDeposited = totalDeposited.MulRaw(2)
s.FundAcc(s.alice, sdk.NewCoins(coinA))
s.makePlaceLOSuccess(s.alice, coinA, coinB.Denom, DefaultSellPrice, dextypes.LimitOrderType(params.OrderType), expTime)
s.makePlaceLOSuccess(s.alice, coinA, coinB.Denom, DefaultSellPrice, params.OrderType, expTime)
}

if params.Filled > 0 {
Expand Down
38 changes: 16 additions & 22 deletions tests/dex/state_deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"

math_utils "github.com/neutron-org/neutron/v5/utils/math"
"github.com/neutron-org/neutron/v5/x/dex/types"
dextypes "github.com/neutron-org/neutron/v5/x/dex/types"
)

Expand Down Expand Up @@ -133,7 +132,6 @@ func CalcDepositAmountNoAutoswap(params depositTestParams) (resultAmountA, resul
}

func calcCurrentShareValue(params depositTestParams, existingValue math_utils.PrecDec) math_utils.PrecDec {

initialValueA := params.ExistingLiquidityDistribution.TokenA.Amount
initialValueB := params.ExistingLiquidityDistribution.TokenB.Amount

Expand All @@ -147,13 +145,13 @@ func calcCurrentShareValue(params depositTestParams, existingValue math_utils.Pr
return currentShareValue
}

func calcAutoswapAmount(params depositTestParams) (swapAmountA math.Int, swapAmountB math.Int) {
func calcAutoswapAmount(params depositTestParams) (swapAmountA, swapAmountB math.Int) {
existingLiquidity := CalcTotalPreDepositLiquidity(params)
existingA := existingLiquidity.TokenA.Amount
existingB := existingLiquidity.TokenB.Amount
depositAmountA := params.DepositAmounts.TokenA.Amount
depositAmountB := params.DepositAmounts.TokenB.Amount
price1To0 := types.MustCalcPrice(-params.Tick)
price1To0 := dextypes.MustCalcPrice(-params.Tick)
if existingA.IsZero() && existingB.IsZero() {
return math.ZeroInt(), math.ZeroInt()
}
Expand All @@ -177,7 +175,6 @@ func calcAutoswapAmount(params depositTestParams) (swapAmountA math.Int, swapAmo
amountSwapped0 := amountSwappedAs1.Quo(price1To0)
return amountSwapped0.Ceil().TruncateInt(), math.ZeroInt()
}

}

func calcExpectedDepositAmounts(params depositTestParams) (tokenAAmount, tokenBAmount, sharesIssued math.Int) {
Expand All @@ -198,28 +195,25 @@ func calcExpectedDepositAmounts(params depositTestParams) (tokenAAmount, tokenBA
sharesIssued = depositValueAsToken0.Mul(shareValue).TruncateInt()

return inAmountA, inAmountB, sharesIssued
} else {
autoSwapAmountA, autoswapAmountB := calcAutoswapAmount(params)
autoswapValueAsToken0 := calcDepositValueAsToken0(params.Tick, autoSwapAmountA, autoswapAmountB)

autoswapFeeAsPrice := types.MustCalcPrice(-int64(params.Fee))
autoswapFeePct := math_utils.OnePrecDec().Sub(autoswapFeeAsPrice)
autoswapFee := autoswapValueAsToken0.Mul(autoswapFeePct)
} // else
autoSwapAmountA, autoswapAmountB := calcAutoswapAmount(params)
autoswapValueAsToken0 := calcDepositValueAsToken0(params.Tick, autoSwapAmountA, autoswapAmountB)

inAmountA := params.DepositAmounts.TokenA.Amount
inAmountB := params.DepositAmounts.TokenB.Amount
autoswapFeeAsPrice := dextypes.MustCalcPrice(-int64(params.Fee))
autoswapFeePct := math_utils.OnePrecDec().Sub(autoswapFeeAsPrice)
autoswapFee := autoswapValueAsToken0.Mul(autoswapFeePct)

fullDepositValueAsToken0 := calcDepositValueAsToken0(params.Tick, inAmountA, inAmountB)
depositAmountMinusFee := fullDepositValueAsToken0.Sub(autoswapFee)
currentValueWithAutoswapFee := existingValueAsToken0.Add(autoswapFee)
shareValue := calcCurrentShareValue(params, currentValueWithAutoswapFee)
inAmountA = params.DepositAmounts.TokenA.Amount
inAmountB = params.DepositAmounts.TokenB.Amount

sharesIssued = depositAmountMinusFee.Mul(shareValue).TruncateInt()
fullDepositValueAsToken0 := calcDepositValueAsToken0(params.Tick, inAmountA, inAmountB)
depositAmountMinusFee := fullDepositValueAsToken0.Sub(autoswapFee)
currentValueWithAutoswapFee := existingValueAsToken0.Add(autoswapFee)
shareValue := calcCurrentShareValue(params, currentValueWithAutoswapFee)

return inAmountA, inAmountB, sharesIssued

}
sharesIssued = depositAmountMinusFee.Mul(shareValue).TruncateInt()

return inAmountA, inAmountB, sharesIssued
}

func (s *DexStateTestSuite) handleBaseFailureCases(params depositTestParams, err error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/dex/state_place_limit_order_maker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func TestPlaceLimitOrderMaker(t *testing.T) {
}
expectedSwapTakerDenom := s.expectedInOutTokensAmount(amountIn, tc.PairID.Token1)
totalExpectedToSwap = totalExpectedToSwap.Add(expectedSwapTakerDenom)
resp, err := s.makePlaceLO(s.creator, amountIn, tc.PairID.Token1, DefaultSellPrice, dextypes.LimitOrderType(tc.OrderType), expTime)
resp, err := s.makePlaceLO(s.creator, amountIn, tc.PairID.Token1, DefaultSellPrice, tc.OrderType, expTime)
s.Require().NoError(err)

// 1. generic liquidity check assertion
Expand Down
7 changes: 3 additions & 4 deletions tests/dex/state_place_limit_order_taker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func ExpectedInOut(params placeLimitOrderTakerTestParams) (math.Int, math.Int) {

availableLiquidity := tickLiquidity
outGivenIn := math_utils.NewPrecDecFromInt(remainingIn).Quo(price).TruncateInt()
amountOut := math.ZeroInt()
var amountOut math.Int
var amountIn math.Int
if params.MaxAmountOut != nil {
maxAmountOut := params.MaxAmountOut.Sub(TotalOut)
if !maxAmountOut.IsPositive() {
Expand All @@ -202,12 +203,10 @@ func ExpectedInOut(params placeLimitOrderTakerTestParams) (math.Int, math.Int) {
amountOut = utils.MinIntArr([]math.Int{availableLiquidity, outGivenIn, maxAmountOut})
} else {
amountOut = utils.MinIntArr([]math.Int{availableLiquidity, outGivenIn})

}

amountInRaw := price.MulInt(amountOut)

amountIn := math.ZeroInt()
if params.LiquidityType == LOLP {
// Simulate rounding on two different tickLiquidities
amountIn = amountInRaw.QuoInt(math.NewInt(2)).Ceil().TruncateInt().MulRaw(2)
Expand Down Expand Up @@ -263,7 +262,7 @@ func TestPlaceLimitOrderTaker(t *testing.T) {
s.fundCreatorBalanceDefault(tc.PairID)
//

resp, err := s.makePlaceTakerLO(s.creator, tc.AmountIn, tc.PairID.Token0, tc.LimitPrice.String(), dextypes.LimitOrderType(tc.OrderType), tc.MaxAmountOut)
resp, err := s.makePlaceTakerLO(s.creator, tc.AmountIn, tc.PairID.Token0, tc.LimitPrice.String(), tc.OrderType, tc.MaxAmountOut)

s.handleTakerErrors(tc, err)

Expand Down
1 change: 0 additions & 1 deletion tests/dex/state_withdraw_limit_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,4 @@ func TestWithdrawLimitOrder(t *testing.T) {
*/
})
}

}

0 comments on commit 57bceea

Please sign in to comment.