Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove alias.go #512

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ func New(
wasm.NewAppModule(app.cdc, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
auction.NewAppModule(app.cdc, app.AuctionKeeper, app.AccountKeeper, app.BankKeeper),
tokenmint.NewAppModule(app.cdc, app.TokenmintKeeper, app.AccountKeeper, app.BankKeeper),
liquidity.NewAppModule(app.cdc, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper),
liquidity.NewAppModule(app.cdc, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.AssetKeeper),
rewards.NewAppModule(app.cdc, app.Rewardskeeper, app.AccountKeeper, app.BankKeeper),
)

Expand Down
9 changes: 5 additions & 4 deletions x/liquidity/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

utils "github.com/comdex-official/comdex/types"
expected "github.com/comdex-official/comdex/x/liquidity/expected"
"github.com/comdex-official/comdex/x/liquidity/keeper"
"github.com/comdex-official/comdex/x/liquidity/types"
)

func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKeeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, ctx.BlockTime(), telemetry.MetricKeyBeginBlocker)

_ = utils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
allApps, found := k.GetApps(ctx)
allApps, found := assetKeeper.GetApps(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if found {
for _, app := range allApps {
k.DeleteOutdatedRequests(ctx, app.Id)
Expand All @@ -26,11 +27,11 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
})
}

func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
func EndBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKeeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, ctx.BlockTime(), telemetry.MetricKeyEndBlocker)

_ = utils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
allApps, found := k.GetApps(ctx)
allApps, found := assetKeeper.GetApps(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if found {
for _, app := range allApps {
params, err := k.GetGenericParams(ctx, app.Id)
Expand Down
11 changes: 0 additions & 11 deletions x/liquidity/keeper/alias.go

This file was deleted.

12 changes: 6 additions & 6 deletions x/liquidity/keeper/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ func (s *KeeperTestSuite) TestOrderExpiration() {

s.ctx = s.ctx.WithBlockTime(utils.ParseTime("2022-03-01T12:00:00Z"))
order := s.LimitOrder(appID1, s.addr(1), pair.Id, types.OrderDirectionSell, utils.ParseDec("1.0"), sdk.NewInt(10000), 10*time.Second)
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

s.ctx = s.ctx.WithBlockTime(utils.ParseTime("2022-03-01T12:00:06Z"))
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
order, found := s.keeper.GetOrder(s.ctx, appID1, order.PairId, order.Id)
s.Require().True(found) // The order is not yet deleted.
// A buy order comes in.
s.LimitOrder(appID1, s.addr(2), pair.Id, types.OrderDirectionBuy, utils.ParseDec("1.0"), sdk.NewInt(5000), 0)
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

s.ctx = s.ctx.WithBlockTime(utils.ParseTime("2022-03-01T12:00:12Z"))
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
order, found = s.keeper.GetOrder(s.ctx, appID1, order.PairId, order.Id)
s.Require().True(found)
s.Require().Equal(types.OrderStatusPartiallyMatched, order.Status)
// Another buy order comes in, but this time the first order has been expired,
// so there is no match.
s.LimitOrder(appID1, s.addr(3), pair.Id, types.OrderDirectionBuy, utils.ParseDec("1.0"), sdk.NewInt(5000), 0)
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
order, _ = s.keeper.GetOrder(s.ctx, appID1, order.PairId, order.Id)
s.Require().Equal(types.OrderStatusExpired, order.Status)
s.Require().True(sdk.NewInt(5000).Equal(order.OpenAmount))

liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
_, found = s.keeper.GetOrder(s.ctx, appID1, order.PairId, order.Id)
s.Require().False(found) // The order is gone.
}
2 changes: 1 addition & 1 deletion x/liquidity/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (k Keeper) GetActiveAndQueuedFarmersForGenesis(ctx sdk.Context, appID uint6

// ExportGenesis returns the capability module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
allApps, found := k.GetApps(ctx)
allApps, found := k.assetKeeper.GetApps(ctx)

appGenesisState := []types.AppGenesisState{}

Expand Down
6 changes: 3 additions & 3 deletions x/liquidity/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func (s *KeeperTestSuite) TestIndexesAfterImport() {
s.Deposit(appID1, pool1.Id, s.addr(4), "1000000denom1,1000000denom2")
s.Deposit(appID1, pool2.Id, s.addr(5), "1000000denom2,1000000denom3")

liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

depositReq1 := s.Deposit(appID1, pool1.Id, s.addr(4), "1000000denom1,1000000denom2")
depositReq2 := s.Deposit(appID1, pool2.Id, s.addr(5), "1000000denom2,1000000denom3")
Expand All @@ -140,7 +140,7 @@ func (s *KeeperTestSuite) TestIndexesAfterImport() {
order1 := s.LimitOrder(appID1, s.addr(6), pair1.Id, types.OrderDirectionBuy, utils.ParseDec("1.0"), sdk.NewInt(10000), time.Minute)
order2 := s.LimitOrder(appID1, s.addr(7), pair2.Id, types.OrderDirectionSell, utils.ParseDec("1.0"), sdk.NewInt(10000), time.Minute)

liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

genState := s.keeper.ExportGenesis(s.ctx)
s.SetupTest()
Expand Down
4 changes: 2 additions & 2 deletions x/liquidity/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (s *KeeperTestSuite) sendCoins(fromAddr, toAddr sdk.AccAddress, amt sdk.Coi
}

func (s *KeeperTestSuite) nextBlock() {
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
}

// Below are useful helpers to write test code easily.
Expand Down
16 changes: 8 additions & 8 deletions x/liquidity/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,19 +585,19 @@ func (s *KeeperTestSuite) TestDepositRefund() {
pool := s.CreateNewLiquidityPool(appID1, pair.Id, addr1, "1000000uasset1,1500000uasset2")

req := s.Deposit(appID1, pool.Id, addr1, "20000uasset1,15000uasset2")
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
req, _ = s.keeper.GetDepositRequest(s.ctx, appID1, req.PoolId, req.Id)
s.Require().Equal(types.RequestStatusSucceeded, req.Status)

s.Require().True(utils.ParseCoin("10000uasset1").IsEqual(s.getBalance(addr1, "uasset1")))
s.Require().True(utils.ParseCoin("0uasset2").IsEqual(s.getBalance(addr1, "uasset2")))
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

pair = s.CreateNewLiquidityPair(appID1, addr1, asset2.Denom, asset1.Denom)
pool = s.CreateNewLiquidityPool(appID1, pair.Id, addr1, "1000000000uasset2,1000000000000000uasset1")

req = s.Deposit(appID1, pool.Id, addr2, "1uasset1,1uasset2")
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
req, _ = s.keeper.GetDepositRequest(s.ctx, appID1, req.PoolId, req.Id)
s.Require().Equal(types.RequestStatusFailed, req.Status)
s.Require().True(req.DepositCoins.IsEqual(s.getBalances(addr2)))
Expand All @@ -617,19 +617,19 @@ func (s *KeeperTestSuite) TestDepositRefundTooSmallMintedPoolCoin() {
pool := s.CreateNewLiquidityPool(appID1, pair.Id, addr1, "1000000uasset1,1500000uasset2")

req := s.Deposit(appID1, pool.Id, addr2, "20000uasset1,15000uasset2")
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
req, _ = s.keeper.GetDepositRequest(s.ctx, appID1, req.PoolId, req.Id)
s.Require().Equal(types.RequestStatusSucceeded, req.Status)

s.Require().True(utils.ParseCoin("10000uasset1").IsEqual(s.getBalance(addr2, "uasset1")))
s.Require().True(utils.ParseCoin("0uasset2").IsEqual(s.getBalance(addr2, "uasset2")))
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

pair = s.CreateNewLiquidityPair(appID1, addr1, asset2.Denom, asset1.Denom)
pool = s.CreateNewLiquidityPool(appID1, pair.Id, addr1, "1000000000uasset2,1000000000000000uasset1")

req = s.Deposit(appID1, pool.Id, addr3, "1uasset1,1uasset2")
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
req, _ = s.keeper.GetDepositRequest(s.ctx, appID1, req.PoolId, req.Id)
s.Require().Equal(types.RequestStatusFailed, req.Status)

Expand Down Expand Up @@ -661,7 +661,7 @@ func (s *KeeperTestSuite) TestDepositToDisabledPool() {
s.Require().Equal(types.RequestStatusFailed, req.Status)

// Delete the previous request and refund coins to the depositor.
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

// Now any deposits will result in an error.
_, err = s.keeper.Deposit(s.ctx, types.NewMsgDeposit(appID1, addr2, pool.Id, req.DepositCoins))
Expand Down Expand Up @@ -846,7 +846,7 @@ func (s *KeeperTestSuite) TestWithdrawFromDisabledPool() {
s.Require().Equal(types.RequestStatusFailed, req.Status)

// Delete the previous request and refund coins to the withdrawer.
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)

// Now any withdrawals will result in an error.
_, err = s.keeper.Withdraw(s.ctx, types.NewMsgWithdraw(appID1, addr1, pool.Id, s.getBalance(addr1, pool.PoolCoinDenom)))
Expand Down
8 changes: 4 additions & 4 deletions x/liquidity/keeper/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ func (s *KeeperTestSuite) TestSingleOrderNoMatch() {

order := s.LimitOrder(appID1, s.addr(1), pair.Id, types.OrderDirectionBuy, utils.ParseDec("1.0"), sdk.NewInt(1000000), 10*time.Second)
// Execute matching
liquidity.EndBlocker(ctx, k)
liquidity.EndBlocker(ctx, k, s.app.AssetKeeper)

order, found := k.GetOrder(ctx, appID1, order.PairId, order.Id)
s.Require().True(found)
Expand All @@ -1295,7 +1295,7 @@ func (s *KeeperTestSuite) TestSingleOrderNoMatch() {
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(10 * time.Second))
// Expire the order, here BeginBlocker is not called to check
// the request's changed status
liquidity.EndBlocker(ctx, k)
liquidity.EndBlocker(ctx, k, s.app.AssetKeeper)

order, _ = k.GetOrder(ctx, appID1, order.PairId, order.Id)
s.Require().Equal(types.OrderStatusExpired, order.Status)
Expand All @@ -1315,7 +1315,7 @@ func (s *KeeperTestSuite) TestTwoOrderExactMatch() {

req1 := s.LimitOrder(appID1, s.addr(1), pair.Id, types.OrderDirectionBuy, utils.ParseDec("1.0"), newInt(10000), time.Hour)
req2 := s.LimitOrder(appID1, s.addr(2), pair.Id, types.OrderDirectionSell, utils.ParseDec("1.0"), newInt(10000), time.Hour)
liquidity.EndBlocker(ctx, k)
liquidity.EndBlocker(ctx, k, s.app.AssetKeeper)

req1, _ = k.GetOrder(ctx, appID1, req1.PairId, req1.Id)
s.Require().Equal(types.OrderStatusCompleted, req1.Status)
Expand Down Expand Up @@ -1368,7 +1368,7 @@ func (s *KeeperTestSuite) TestMatchWithLowPricePool() {
// Create a pool with very low price.
s.CreateNewLiquidityPool(appID1, pair.Id, s.addr(0), "10000000000000000000000000000000000000000denom1,1000000denom2")
order := s.LimitOrder(appID1, s.addr(1), pair.Id, types.OrderDirectionBuy, utils.ParseDec("0.000000000001000000"), sdk.NewInt(100000000000000000), 10*time.Second)
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
order, found := s.keeper.GetOrder(s.ctx, appID1, order.PairId, order.Id)
s.Require().True(found)
s.Require().Equal(types.OrderStatusNotMatched, order.Status)
Expand Down
8 changes: 5 additions & 3 deletions x/liquidity/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ type AppModule struct {
keeper keeper.Keeper
accountKeeper expected.AccountKeeper
bankKeeper expected.BankKeeper
assetKeeper expected.AssetKeeper
}

func NewAppModule(cdc codec.Codec, keeper keeper.Keeper,
accountKeeper expected.AccountKeeper, bankKeeper expected.BankKeeper,
accountKeeper expected.AccountKeeper, bankKeeper expected.BankKeeper, assetKeeper expected.AssetKeeper,
) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
assetKeeper: assetKeeper,
}
}

Expand Down Expand Up @@ -164,12 +166,12 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
BeginBlocker(ctx, am.keeper)
BeginBlocker(ctx, am.keeper, am.assetKeeper)
}

// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
// returns no validator updates.
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
EndBlocker(ctx, am.keeper)
EndBlocker(ctx, am.keeper, am.assetKeeper)
return []abci.ValidatorUpdate{}
}
4 changes: 2 additions & 2 deletions x/liquidity/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (suite *ModuleTestSuite) addr(addrNum int) sdk.AccAddress {
}

func (s *ModuleTestSuite) nextBlock() {
liquidity.EndBlocker(s.ctx, s.keeper)
liquidity.BeginBlocker(s.ctx, s.keeper)
liquidity.EndBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
liquidity.BeginBlocker(s.ctx, s.keeper, s.app.AssetKeeper)
}

func (suite *ModuleTestSuite) fundAddr(addr sdk.AccAddress, amt sdk.Coins) {
Expand Down