Skip to content

Commit

Permalink
Remove double import (#984)
Browse files Browse the repository at this point in the history
remove dependency
  • Loading branch information
amityadav0 authored Nov 22, 2024
1 parent e59c9f2 commit b51689f
Show file tree
Hide file tree
Showing 27 changed files with 139 additions and 163 deletions.
38 changes: 18 additions & 20 deletions x/accountedpool/keeper/accounted_pool_update_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"cosmossdk.io/math"
"testing"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -50,9 +49,8 @@ func TestAccountedPoolUpdate(t *testing.T) {
NonAmmPoolTokens: []sdk.Coin{},
}

for _, asset := range ammPool.PoolAssets {
accountedPool.PoolAssets = append(accountedPool.PoolAssets, asset)
}
accountedPool.PoolAssets = append(accountedPool.PoolAssets, ammPool.PoolAssets...)

// Set accounted pool
apk.SetAccountedPool(ctx, accountedPool)

Expand All @@ -62,33 +60,33 @@ func TestAccountedPoolUpdate(t *testing.T) {
BorrowInterestRate: sdkmath.LegacyNewDec(1),
PoolAssetsLong: []perpetualtypes.PoolAsset{
{
Liabilities: math.NewInt(400),
Custody: math.NewInt(50),
TakeProfitCustody: math.NewInt(10),
TakeProfitLiabilities: math.NewInt(20),
Liabilities: sdkmath.NewInt(400),
Custody: sdkmath.NewInt(50),
TakeProfitCustody: sdkmath.NewInt(10),
TakeProfitLiabilities: sdkmath.NewInt(20),
AssetDenom: ptypes.BaseCurrency,
},
{
Liabilities: math.NewInt(0),
Custody: math.NewInt(50),
TakeProfitCustody: math.ZeroInt(),
TakeProfitLiabilities: math.ZeroInt(),
Liabilities: sdkmath.NewInt(0),
Custody: sdkmath.NewInt(50),
TakeProfitCustody: sdkmath.ZeroInt(),
TakeProfitLiabilities: sdkmath.ZeroInt(),
AssetDenom: ptypes.ATOM,
},
},
PoolAssetsShort: []perpetualtypes.PoolAsset{
{
Liabilities: math.NewInt(400),
Custody: math.NewInt(70),
TakeProfitCustody: math.ZeroInt(),
TakeProfitLiabilities: math.ZeroInt(),
Liabilities: sdkmath.NewInt(400),
Custody: sdkmath.NewInt(70),
TakeProfitCustody: sdkmath.ZeroInt(),
TakeProfitLiabilities: sdkmath.ZeroInt(),
AssetDenom: ptypes.BaseCurrency,
},
{
Liabilities: math.NewInt(0),
Custody: math.NewInt(50),
TakeProfitCustody: math.ZeroInt(),
TakeProfitLiabilities: math.ZeroInt(),
Liabilities: sdkmath.NewInt(0),
Custody: sdkmath.NewInt(50),
TakeProfitCustody: sdkmath.ZeroInt(),
TakeProfitLiabilities: sdkmath.ZeroInt(),
AssetDenom: ptypes.ATOM,
},
},
Expand Down
3 changes: 1 addition & 2 deletions x/accountedpool/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

storetypes "cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -37,7 +36,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// Get accounted pool balance
func (k Keeper) GetAccountedBalance(ctx sdk.Context, poolId uint64, denom string) math.Int {
func (k Keeper) GetAccountedBalance(ctx sdk.Context, poolId uint64, denom string) sdkmath.Int {
pool, found := k.GetAccountedPool(ctx, poolId)
if !found {
return sdkmath.ZeroInt()
Expand Down
3 changes: 1 addition & 2 deletions x/amm/keeper/calc_in_route_spot_price.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
Expand Down Expand Up @@ -97,7 +96,7 @@ func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context,
// Estimate swap
snapshot := k.GetAccountedPoolSnapshotOrSet(ctx, pool)
cacheCtx, _ := ctx.CacheContext()
tokenOut, swapSlippage, _, weightBalanceBonus, err := k.SwapOutAmtGivenIn(cacheCtx, pool.PoolId, k.oracleKeeper, &snapshot, tokensIn, tokenOutDenom, swapFee, math.LegacyOneDec())
tokenOut, swapSlippage, _, weightBalanceBonus, err := k.SwapOutAmtGivenIn(cacheCtx, pool.PoolId, k.oracleKeeper, &snapshot, tokensIn, tokenOutDenom, swapFee, sdkmath.LegacyOneDec())
if err != nil {
return sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdk.Coin{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdk.Coin{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
}
Expand Down
3 changes: 1 addition & 2 deletions x/amm/keeper/calc_out_route_spot_price.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
Expand Down Expand Up @@ -54,7 +53,7 @@ func (k Keeper) CalcOutRouteSpotPrice(ctx sdk.Context, tokenOut sdk.Coin, routes
// Estimate swap
snapshot := k.GetAccountedPoolSnapshotOrSet(ctx, pool)
cacheCtx, _ := ctx.CacheContext()
swapResult, swapSlippage, _, weightBalanceBonus, err := k.SwapInAmtGivenOut(cacheCtx, pool.PoolId, k.oracleKeeper, &snapshot, tokensOut, tokenInDenom, swapFee, math.LegacyOneDec())
swapResult, swapSlippage, _, weightBalanceBonus, err := k.SwapInAmtGivenOut(cacheCtx, pool.PoolId, k.oracleKeeper, &snapshot, tokensOut, tokenInDenom, swapFee, sdkmath.LegacyOneDec())
if err != nil {
return sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdk.Coin{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdk.Coin{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
}
Expand Down
3 changes: 1 addition & 2 deletions x/amm/keeper/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
Expand Down Expand Up @@ -54,7 +53,7 @@ func (k Keeper) SwapFeesToRevenueToken(ctx sdk.Context, pool types.Pool, fee sdk
// Executes the swap in the pool and stores the output. Updates pool assets but
// does not actually transfer any tokens to or from the pool.
snapshot := k.GetAccountedPoolSnapshotOrSet(ctx, pool)
tokenOutCoin, _, _, _, err := pool.SwapOutAmtGivenIn(ctx, k.oracleKeeper, &snapshot, sdk.Coins{tokenIn}, pool.PoolParams.FeeDenom, sdkmath.LegacyZeroDec(), k.accountedPoolKeeper, math.LegacyOneDec(), params)
tokenOutCoin, _, _, _, err := pool.SwapOutAmtGivenIn(ctx, k.oracleKeeper, &snapshot, sdk.Coins{tokenIn}, pool.PoolParams.FeeDenom, sdkmath.LegacyZeroDec(), k.accountedPoolKeeper, sdkmath.LegacyOneDec(), params)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package keeper_test

import (
"fmt"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/keeper"
Expand Down Expand Up @@ -364,8 +364,8 @@ func (suite *AmmKeeperTestSuite) TestFeedMultipleExternalLiquidity() {

addr := suite.AddAccounts(1, nil)[0]

amount := math.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, math.LegacyZeroDec(), math.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))
amount := sdkmath.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))

suite.app.OracleKeeper.SetPriceFeeder(suite.ctx, oracletypes.PriceFeeder{
Feeder: addr.String(),
Expand Down
5 changes: 2 additions & 3 deletions x/amm/keeper/pool.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -210,7 +209,7 @@ func (k Keeper) GetAccountedPoolSnapshotOrSet(ctx sdk.Context, pool types.Pool)
}

// AddToPoolBalance Used in perpetual balance changes
func (k Keeper) AddToPoolBalance(ctx sdk.Context, pool *types.Pool, addShares math.Int, coins sdk.Coins) error {
func (k Keeper) AddToPoolBalance(ctx sdk.Context, pool *types.Pool, addShares sdkmath.Int, coins sdk.Coins) error {
err := pool.IncreaseLiquidity(addShares, coins)
if err != nil {
return err
Expand All @@ -220,7 +219,7 @@ func (k Keeper) AddToPoolBalance(ctx sdk.Context, pool *types.Pool, addShares ma
}

// RemoveFromPoolBalance Used in perpetual balance changes
func (k Keeper) RemoveFromPoolBalance(ctx sdk.Context, pool *types.Pool, removeShares math.Int, coins sdk.Coins) error {
func (k Keeper) RemoveFromPoolBalance(ctx sdk.Context, pool *types.Pool, removeShares sdkmath.Int, coins sdk.Coins) error {
err := pool.DecreaseLiquidity(removeShares, coins)
if err != nil {
return err
Expand Down
9 changes: 4 additions & 5 deletions x/amm/keeper/pool_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
simapp "github.com/elys-network/elys/app"
"github.com/elys-network/elys/x/amm/types"
atypes "github.com/elys-network/elys/x/amm/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -41,23 +40,23 @@ func TestCommitMintedLPTokenToCommitmentModule(t *testing.T) {
err = app.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr[0], usdcToken)
require.NoError(t, err)

var poolAssets []atypes.PoolAsset
var poolAssets []types.PoolAsset
// Elys
poolAssets = append(poolAssets, atypes.PoolAsset{
poolAssets = append(poolAssets, types.PoolAsset{
Weight: sdkmath.NewInt(50),
Token: sdk.NewCoin(ptypes.Elys, sdkmath.NewInt(100000)),
})

// USDC
poolAssets = append(poolAssets, atypes.PoolAsset{
poolAssets = append(poolAssets, types.PoolAsset{
Weight: sdkmath.NewInt(50),
Token: sdk.NewCoin(ptypes.BaseCurrency, sdkmath.NewInt(10000)),
})

argSwapFee, err := sdkmath.LegacyNewDecFromStr("0.01")
require.NoError(t, err)

poolParams := atypes.PoolParams{
poolParams := types.PoolParams{
SwapFee: argSwapFee,
}

Expand Down
25 changes: 12 additions & 13 deletions x/amm/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strconv"
"testing"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -161,10 +160,10 @@ func (suite *AmmKeeperTestSuite) TestPool() {
func() {
addr := suite.AddAccounts(1, nil)[0]

amount := math.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, math.LegacyZeroDec(), math.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))
amount := sdkmath.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))

err := suite.app.AmmKeeper.AddToPoolBalance(suite.ctx, &pool, math.ZeroInt(), sdk.NewCoins(sdk.NewCoin("non-existant-denom", amount)))
err := suite.app.AmmKeeper.AddToPoolBalance(suite.ctx, &pool, sdkmath.ZeroInt(), sdk.NewCoins(sdk.NewCoin("non-existant-denom", amount)))
suite.Require().Error(err)
},
},
Expand All @@ -177,10 +176,10 @@ func (suite *AmmKeeperTestSuite) TestPool() {
func() {
addr := suite.AddAccounts(1, nil)[0]

amount := math.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, math.LegacyZeroDec(), math.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))
amount := sdkmath.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))

err := suite.app.AmmKeeper.AddToPoolBalance(suite.ctx, &pool, math.ZeroInt(), sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, amount)))
err := suite.app.AmmKeeper.AddToPoolBalance(suite.ctx, &pool, sdkmath.ZeroInt(), sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, amount)))
suite.Require().NoError(err)
},
},
Expand All @@ -193,10 +192,10 @@ func (suite *AmmKeeperTestSuite) TestPool() {
func() {
addr := suite.AddAccounts(1, nil)[0]

amount := math.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, math.LegacyZeroDec(), math.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))
amount := sdkmath.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))

err := suite.app.AmmKeeper.RemoveFromPoolBalance(suite.ctx, &pool, math.ZeroInt(), sdk.NewCoins(sdk.NewCoin("non-existant-denom", amount)))
err := suite.app.AmmKeeper.RemoveFromPoolBalance(suite.ctx, &pool, sdkmath.ZeroInt(), sdk.NewCoins(sdk.NewCoin("non-existant-denom", amount)))
suite.Require().Error(err)
},
},
Expand All @@ -209,10 +208,10 @@ func (suite *AmmKeeperTestSuite) TestPool() {
func() {
addr := suite.AddAccounts(1, nil)[0]

amount := math.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, math.LegacyZeroDec(), math.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))
amount := sdkmath.NewInt(100000000000)
pool := suite.CreateNewAmmPool(addr, true, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), ptypes.ATOM, amount.MulRaw(10), amount.MulRaw(10))

err := suite.app.AmmKeeper.RemoveFromPoolBalance(suite.ctx, &pool, math.ZeroInt(), sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, amount)))
err := suite.app.AmmKeeper.RemoveFromPoolBalance(suite.ctx, &pool, sdkmath.ZeroInt(), sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, amount)))
suite.Require().NoError(err)
},
},
Expand Down
6 changes: 3 additions & 3 deletions x/amm/keeper/swap_out_amt_given_in.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package keeper

import (
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"fmt"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
)
Expand All @@ -16,7 +16,7 @@ func (k Keeper) SwapOutAmtGivenIn(
tokensIn sdk.Coins,
tokenOutDenom string,
swapFee sdkmath.LegacyDec,
weightBreakingFeePerpetualFactor math.LegacyDec,
weightBreakingFeePerpetualFactor sdkmath.LegacyDec,
) (tokenOut sdk.Coin, slippage sdkmath.LegacyDec, slippageAmount sdkmath.LegacyDec, weightBalanceBonus sdkmath.LegacyDec, err error) {
ammPool, found := k.GetPool(ctx, poolId)
if !found {
Expand Down
3 changes: 1 addition & 2 deletions x/amm/types/swap_in_amt_given_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"fmt"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -50,7 +49,7 @@ func (p Pool) CalcGivenOutSlippage(
// weightBreakingFeePerpetualFactor should be 1 if perpetual is not the one calling this function
func (p *Pool) SwapInAmtGivenOut(
ctx sdk.Context, oracleKeeper OracleKeeper, snapshot *Pool,
tokensOut sdk.Coins, tokenInDenom string, swapFee sdkmath.LegacyDec, accPoolKeeper AccountedPoolKeeper, weightBreakingFeePerpetualFactor math.LegacyDec, params Params) (
tokensOut sdk.Coins, tokenInDenom string, swapFee sdkmath.LegacyDec, accPoolKeeper AccountedPoolKeeper, weightBreakingFeePerpetualFactor sdkmath.LegacyDec, params Params) (
tokenIn sdk.Coin, slippage, slippageAmount sdkmath.LegacyDec, weightBalanceBonus sdkmath.LegacyDec, err error,
) {
// early return with balancer swap if normal amm pool
Expand Down
7 changes: 3 additions & 4 deletions x/amm/types/swap_in_amt_given_out_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types_test

import (
"cosmossdk.io/math"
"time"

sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -185,10 +184,10 @@ func (suite *TestSuite) TestSwapInAmtGivenOut() {
},
useOracle: false,
externalLiquidityRatio: sdkmath.LegacyNewDec(10),
thresholdWeightDiff: math.LegacyNewDecWithPrec(20, 2),
thresholdWeightDiff: sdkmath.LegacyNewDecWithPrec(20, 2),
tokenOut: sdk.NewInt64Coin("uusdt", 0),
inTokenDenom: ptypes.BaseCurrency,
swapFee: math.LegacyNewDecWithPrec(1, 2),
swapFee: sdkmath.LegacyNewDecWithPrec(1, 2),
expRecoveryBonus: sdkmath.LegacyZeroDec(),
expTokenIn: sdk.NewInt64Coin(ptypes.BaseCurrency, 0),
expErr: true,
Expand Down Expand Up @@ -226,7 +225,7 @@ func (suite *TestSuite) TestSwapInAmtGivenOut() {
params.WeightBreakingFeeMultiplier = sdkmath.LegacyNewDecWithPrec(2, 4)
params.WeightBreakingFeeExponent = sdkmath.LegacyNewDecWithPrec(25, 1) // 2.5
params.WeightRecoveryFeePortion = sdkmath.LegacyNewDecWithPrec(50, 2) // 50%
tokenOut, _, _, weightBonus, err := pool.SwapInAmtGivenOut(suite.ctx, suite.app.OracleKeeper, &pool, sdk.Coins{tc.tokenOut}, tc.inTokenDenom, tc.swapFee, suite.app.AccountedPoolKeeper, math.LegacyOneDec(), params)
tokenOut, _, _, weightBonus, err := pool.SwapInAmtGivenOut(suite.ctx, suite.app.OracleKeeper, &pool, sdk.Coins{tc.tokenOut}, tc.inTokenDenom, tc.swapFee, suite.app.AccountedPoolKeeper, sdkmath.LegacyOneDec(), params)
if tc.expErr {
suite.Require().Error(err)
suite.Require().EqualError(err, "amount too low")
Expand Down
3 changes: 1 addition & 2 deletions x/amm/types/swap_out_amt_given_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"fmt"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -178,7 +177,7 @@ func (p *Pool) SwapOutAmtGivenIn(
tokenOutDenom string,
swapFee sdkmath.LegacyDec,
accPoolKeeper AccountedPoolKeeper,
weightBreakingFeePerpetualFactor math.LegacyDec,
weightBreakingFeePerpetualFactor sdkmath.LegacyDec,
params Params,
) (tokenOut sdk.Coin, slippage, slippageAmount sdkmath.LegacyDec, weightBalanceBonus sdkmath.LegacyDec, err error) {
balancerOutCoin, slippage, err := p.CalcOutAmtGivenIn(ctx, oracleKeeper, snapshot, tokensIn, tokenOutDenom, swapFee, accPoolKeeper)
Expand Down
Loading

0 comments on commit b51689f

Please sign in to comment.