Hard Audit: remove liquidation account from Hard module (#810)

* remove liquidator macc

* remove legacy if statement
This commit is contained in:
Denali Marsh 2021-02-09 21:33:58 +01:00 committed by GitHub
parent 7465c643b8
commit b620275165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 49 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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),

View File

@ -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 {

View File

@ -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"