From b620275165d51a33bd193e4fa4479e74de8d2078 Mon Sep 17 00:00:00 2001 From: Denali Marsh Date: Tue, 9 Feb 2021 21:33:58 +0100 Subject: [PATCH] Hard Audit: remove liquidation account from Hard module (#810) * remove liquidator macc * remove legacy if statement --- app/app.go | 1 - x/hard/alias.go | 1 - x/hard/genesis.go | 7 ------- x/hard/keeper/liquidation.go | 25 +++++++----------------- x/hard/keeper/liquidation_test.go | 32 +++++++++++++++---------------- x/hard/keeper/timelock_test.go | 6 +++--- x/hard/types/keys.go | 3 --- 7 files changed, 26 insertions(+), 49 deletions(-) diff --git a/app/app.go b/app/app.go index d4dc2228..17d643f1 100644 --- a/app/app.go +++ b/app/app.go @@ -103,7 +103,6 @@ var ( kavadist.ModuleName: {supply.Minter}, issuance.ModuleAccountName: {supply.Minter, supply.Burner}, hard.ModuleAccountName: {supply.Minter, supply.Burner}, - hard.LiquidatorAccount: {supply.Minter, supply.Burner}, } // module accounts that are allowed to receive tokens diff --git a/x/hard/alias.go b/x/hard/alias.go index 8eab46d7..7c57139c 100644 --- a/x/hard/alias.go +++ b/x/hard/alias.go @@ -29,7 +29,6 @@ const ( EventTypeHardLPDistribution = types.EventTypeHardLPDistribution EventTypeHardRepay = types.EventTypeHardRepay EventTypeHardWithdrawal = types.EventTypeHardWithdrawal - LiquidatorAccount = types.LiquidatorAccount ModuleAccountName = types.ModuleAccountName ModuleName = types.ModuleName QuerierRoute = types.QuerierRoute diff --git a/x/hard/genesis.go b/x/hard/genesis.go index 61489c2b..1fa8957a 100644 --- a/x/hard/genesis.go +++ b/x/hard/genesis.go @@ -43,13 +43,6 @@ func InitGenesis(ctx sdk.Context, k Keeper, supplyKeeper types.SupplyKeeper, gs if DepositModuleAccount == nil { panic(fmt.Sprintf("%s module account has not been set", DepositModuleAccount)) } - - // check if the module account exists - LiquidatorModuleAcc := supplyKeeper.GetModuleAccount(ctx, LiquidatorAccount) - if LiquidatorModuleAcc == nil { - panic(fmt.Sprintf("%s module account has not been set", LiquidatorAccount)) - } - } // ExportGenesis export genesis state for hard module diff --git a/x/hard/keeper/liquidation.go b/x/hard/keeper/liquidation.go index 9298f965..0588780f 100644 --- a/x/hard/keeper/liquidation.go +++ b/x/hard/keeper/liquidation.go @@ -76,14 +76,11 @@ func (k Keeper) SeizeDeposits(ctx sdk.Context, keeper sdk.AccAddress, deposit ty keeperRewardCoins := sdk.Coins{} for _, depCoin := range deposit.Amount { mm, _ := k.GetMoneyMarket(ctx, depCoin.Denom) - // No keeper rewards if liquidated by LTV index - if !keeper.Equals(sdk.AccAddress(types.LiquidatorAccount)) { - keeperReward := mm.KeeperRewardPercentage.MulInt(depCoin.Amount).TruncateInt() - if keeperReward.GT(sdk.ZeroInt()) { - // Send keeper their reward - keeperCoin := sdk.NewCoin(depCoin.Denom, keeperReward) - keeperRewardCoins = append(keeperRewardCoins, keeperCoin) - } + keeperReward := mm.KeeperRewardPercentage.MulInt(depCoin.Amount).TruncateInt() + if keeperReward.GT(sdk.ZeroInt()) { + // Send keeper their reward + keeperCoin := sdk.NewCoin(depCoin.Denom, keeperReward) + keeperRewardCoins = append(keeperRewardCoins, keeperCoin) } } if !keeperRewardCoins.Empty() { @@ -179,11 +176,7 @@ func (k Keeper) StartAuctions(ctx sdk.Context, borrower sdk.AccAddress, borrows, } // Start auction: bid = full borrow amount, lot = maxLotSize - err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, types.LiquidatorAccount, sdk.NewCoins(lot)) - if err != nil { - return liquidatedCoins, err - } - _, err = k.auctionKeeper.StartCollateralAuction(ctx, types.LiquidatorAccount, lot, bid, returnAddrs, weights, debt) + _, err := k.auctionKeeper.StartCollateralAuction(ctx, types.ModuleAccountName, lot, bid, returnAddrs, weights, debt) if err != nil { return liquidatedCoins, err } @@ -228,11 +221,7 @@ func (k Keeper) StartAuctions(ctx sdk.Context, borrower sdk.AccAddress, borrows, } // Start auction: bid = maxBid, lot = whole deposit amount - err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, types.LiquidatorAccount, sdk.NewCoins(lot)) - if err != nil { - return liquidatedCoins, err - } - _, err = k.auctionKeeper.StartCollateralAuction(ctx, types.LiquidatorAccount, lot, bid, returnAddrs, weights, debt) + _, err := k.auctionKeeper.StartCollateralAuction(ctx, types.ModuleAccountName, lot, bid, returnAddrs, weights, debt) if err != nil { return liquidatedCoins, err } diff --git a/x/hard/keeper/liquidation_test.go b/x/hard/keeper/liquidation_test.go index 4286fd34..a395f325 100644 --- a/x/hard/keeper/liquidation_test.go +++ b/x/hard/keeper/liquidation_test.go @@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 1, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 9500390), Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -122,7 +122,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 1, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 11874430), Bidder: nil, Bid: sdk.NewInt64Coin("bnb", 0), @@ -137,7 +137,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 2, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 11874254), Bidder: nil, Bid: sdk.NewInt64Coin("btc", 0), @@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 3, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 11875163), Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 4, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 11876185), Bidder: nil, Bid: sdk.NewInt64Coin("usdc", 0), @@ -207,7 +207,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 1, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("bnb", 950000000), Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 2, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("btc", 95000000), Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -237,7 +237,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 3, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("ukava", 47504818), Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -278,7 +278,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 1, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdc", 95000000), // $95.00 Bidder: nil, Bid: sdk.NewInt64Coin("bnb", 0), @@ -293,7 +293,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 2, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdt", 10552835), // $10.55 Bidder: nil, Bid: sdk.NewInt64Coin("bnb", 0), @@ -308,7 +308,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 3, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdt", 84447165), // $84.45 Bidder: nil, Bid: sdk.NewInt64Coin("btc", 0), @@ -323,7 +323,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 4, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdx", 21097866), // $21.10 Bidder: nil, Bid: sdk.NewInt64Coin("btc", 0), @@ -338,7 +338,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 5, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdx", 73902133), //$73.90 Bidder: nil, Bid: sdk.NewInt64Coin("ukava", 0), @@ -378,7 +378,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 1, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("dai", 263894126), Bidder: nil, Bid: sdk.NewInt64Coin("usdt", 0), @@ -393,7 +393,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 2, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("dai", 68605874), Bidder: nil, Bid: sdk.NewInt64Coin("usdx", 0), @@ -408,7 +408,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() { auctypes.CollateralAuction{ BaseAuction: auctypes.BaseAuction{ ID: 3, - Initiator: "hard_liquidator", + Initiator: "hard", Lot: sdk.NewInt64Coin("usdc", 189999999), Bidder: nil, Bid: sdk.NewInt64Coin("usdx", 0), diff --git a/x/hard/keeper/timelock_test.go b/x/hard/keeper/timelock_test.go index 3e2cf3ca..f45f9233 100644 --- a/x/hard/keeper/timelock_test.go +++ b/x/hard/keeper/timelock_test.go @@ -299,19 +299,19 @@ func (suite *KeeperTestSuite) TestSendTimeLockedCoinsToAccount() { ak.SetAccount(ctx, pva) } supplyKeeper := tApp.GetSupplyKeeper() - supplyKeeper.MintCoins(ctx, types.LiquidatorAccount, sdk.NewCoins(sdk.NewCoin("hard", sdk.NewInt(1000)))) + supplyKeeper.MintCoins(ctx, types.ModuleAccountName, sdk.NewCoins(sdk.NewCoin("hard", sdk.NewInt(1000)))) keeper := tApp.GetHardKeeper() suite.app = tApp suite.ctx = ctx suite.keeper = keeper - err := suite.keeper.SendTimeLockedCoinsToAccount(suite.ctx, types.LiquidatorAccount, tc.args.accArgs.addr, tc.args.period.Amount, tc.args.period.Length) + err := suite.keeper.SendTimeLockedCoinsToAccount(suite.ctx, types.ModuleAccountName, tc.args.accArgs.addr, tc.args.period.Amount, tc.args.period.Length) if tc.errArgs.expectPass { suite.Require().NoError(err) acc := suite.getAccount(tc.args.accArgs.addr) suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins()) - mAcc := suite.getModuleAccount(types.LiquidatorAccount) + mAcc := suite.getModuleAccount(types.ModuleAccountName) suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins()) vacc, ok := acc.(*vesting.PeriodicVestingAccount) if tc.args.accArgs.vestingAccountAfter { diff --git a/x/hard/types/keys.go b/x/hard/types/keys.go index 268deb67..2e01daed 100644 --- a/x/hard/types/keys.go +++ b/x/hard/types/keys.go @@ -4,9 +4,6 @@ const ( // ModuleName name that will be used throughout the module ModuleName = "hard" - // LiquidatorAccount module account for liquidator - LiquidatorAccount = "hard_liquidator" - // ModuleAccountName name of module account used to hold deposits ModuleAccountName = "hard"