mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
Hard Audit: remove liquidation account from Hard module (#810)
* remove liquidator macc * remove legacy if statement
This commit is contained in:
parent
7465c643b8
commit
b620275165
@ -103,7 +103,6 @@ var (
|
|||||||
kavadist.ModuleName: {supply.Minter},
|
kavadist.ModuleName: {supply.Minter},
|
||||||
issuance.ModuleAccountName: {supply.Minter, supply.Burner},
|
issuance.ModuleAccountName: {supply.Minter, supply.Burner},
|
||||||
hard.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
|
// module accounts that are allowed to receive tokens
|
||||||
|
@ -29,7 +29,6 @@ const (
|
|||||||
EventTypeHardLPDistribution = types.EventTypeHardLPDistribution
|
EventTypeHardLPDistribution = types.EventTypeHardLPDistribution
|
||||||
EventTypeHardRepay = types.EventTypeHardRepay
|
EventTypeHardRepay = types.EventTypeHardRepay
|
||||||
EventTypeHardWithdrawal = types.EventTypeHardWithdrawal
|
EventTypeHardWithdrawal = types.EventTypeHardWithdrawal
|
||||||
LiquidatorAccount = types.LiquidatorAccount
|
|
||||||
ModuleAccountName = types.ModuleAccountName
|
ModuleAccountName = types.ModuleAccountName
|
||||||
ModuleName = types.ModuleName
|
ModuleName = types.ModuleName
|
||||||
QuerierRoute = types.QuerierRoute
|
QuerierRoute = types.QuerierRoute
|
||||||
|
@ -43,13 +43,6 @@ func InitGenesis(ctx sdk.Context, k Keeper, supplyKeeper types.SupplyKeeper, gs
|
|||||||
if DepositModuleAccount == nil {
|
if DepositModuleAccount == nil {
|
||||||
panic(fmt.Sprintf("%s module account has not been set", DepositModuleAccount))
|
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
|
// ExportGenesis export genesis state for hard module
|
||||||
|
@ -76,14 +76,11 @@ func (k Keeper) SeizeDeposits(ctx sdk.Context, keeper sdk.AccAddress, deposit ty
|
|||||||
keeperRewardCoins := sdk.Coins{}
|
keeperRewardCoins := sdk.Coins{}
|
||||||
for _, depCoin := range deposit.Amount {
|
for _, depCoin := range deposit.Amount {
|
||||||
mm, _ := k.GetMoneyMarket(ctx, depCoin.Denom)
|
mm, _ := k.GetMoneyMarket(ctx, depCoin.Denom)
|
||||||
// No keeper rewards if liquidated by LTV index
|
keeperReward := mm.KeeperRewardPercentage.MulInt(depCoin.Amount).TruncateInt()
|
||||||
if !keeper.Equals(sdk.AccAddress(types.LiquidatorAccount)) {
|
if keeperReward.GT(sdk.ZeroInt()) {
|
||||||
keeperReward := mm.KeeperRewardPercentage.MulInt(depCoin.Amount).TruncateInt()
|
// Send keeper their reward
|
||||||
if keeperReward.GT(sdk.ZeroInt()) {
|
keeperCoin := sdk.NewCoin(depCoin.Denom, keeperReward)
|
||||||
// Send keeper their reward
|
keeperRewardCoins = append(keeperRewardCoins, keeperCoin)
|
||||||
keeperCoin := sdk.NewCoin(depCoin.Denom, keeperReward)
|
|
||||||
keeperRewardCoins = append(keeperRewardCoins, keeperCoin)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !keeperRewardCoins.Empty() {
|
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
|
// Start auction: bid = full borrow amount, lot = maxLotSize
|
||||||
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, types.LiquidatorAccount, sdk.NewCoins(lot))
|
_, err := k.auctionKeeper.StartCollateralAuction(ctx, types.ModuleAccountName, lot, bid, returnAddrs, weights, debt)
|
||||||
if err != nil {
|
|
||||||
return liquidatedCoins, err
|
|
||||||
}
|
|
||||||
_, err = k.auctionKeeper.StartCollateralAuction(ctx, types.LiquidatorAccount, lot, bid, returnAddrs, weights, debt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return liquidatedCoins, err
|
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
|
// Start auction: bid = maxBid, lot = whole deposit amount
|
||||||
err := k.supplyKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleAccountName, types.LiquidatorAccount, sdk.NewCoins(lot))
|
_, err := k.auctionKeeper.StartCollateralAuction(ctx, types.ModuleAccountName, lot, bid, returnAddrs, weights, debt)
|
||||||
if err != nil {
|
|
||||||
return liquidatedCoins, err
|
|
||||||
}
|
|
||||||
_, err = k.auctionKeeper.StartCollateralAuction(ctx, types.LiquidatorAccount, lot, bid, returnAddrs, weights, debt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return liquidatedCoins, err
|
return liquidatedCoins, err
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 9500390),
|
Lot: sdk.NewInt64Coin("ukava", 9500390),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -122,7 +122,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 11874430),
|
Lot: sdk.NewInt64Coin("ukava", 11874430),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("bnb", 0),
|
Bid: sdk.NewInt64Coin("bnb", 0),
|
||||||
@ -137,7 +137,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 11874254),
|
Lot: sdk.NewInt64Coin("ukava", 11874254),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("btc", 0),
|
Bid: sdk.NewInt64Coin("btc", 0),
|
||||||
@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 11875163),
|
Lot: sdk.NewInt64Coin("ukava", 11875163),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 4,
|
ID: 4,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 11876185),
|
Lot: sdk.NewInt64Coin("ukava", 11876185),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("usdc", 0),
|
Bid: sdk.NewInt64Coin("usdc", 0),
|
||||||
@ -207,7 +207,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("bnb", 950000000),
|
Lot: sdk.NewInt64Coin("bnb", 950000000),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("btc", 95000000),
|
Lot: sdk.NewInt64Coin("btc", 95000000),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -237,7 +237,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("ukava", 47504818),
|
Lot: sdk.NewInt64Coin("ukava", 47504818),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -278,7 +278,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdc", 95000000), // $95.00
|
Lot: sdk.NewInt64Coin("usdc", 95000000), // $95.00
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("bnb", 0),
|
Bid: sdk.NewInt64Coin("bnb", 0),
|
||||||
@ -293,7 +293,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdt", 10552835), // $10.55
|
Lot: sdk.NewInt64Coin("usdt", 10552835), // $10.55
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("bnb", 0),
|
Bid: sdk.NewInt64Coin("bnb", 0),
|
||||||
@ -308,7 +308,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdt", 84447165), // $84.45
|
Lot: sdk.NewInt64Coin("usdt", 84447165), // $84.45
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("btc", 0),
|
Bid: sdk.NewInt64Coin("btc", 0),
|
||||||
@ -323,7 +323,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 4,
|
ID: 4,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdx", 21097866), // $21.10
|
Lot: sdk.NewInt64Coin("usdx", 21097866), // $21.10
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("btc", 0),
|
Bid: sdk.NewInt64Coin("btc", 0),
|
||||||
@ -338,7 +338,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 5,
|
ID: 5,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdx", 73902133), //$73.90
|
Lot: sdk.NewInt64Coin("usdx", 73902133), //$73.90
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("ukava", 0),
|
Bid: sdk.NewInt64Coin("ukava", 0),
|
||||||
@ -378,7 +378,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("dai", 263894126),
|
Lot: sdk.NewInt64Coin("dai", 263894126),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("usdt", 0),
|
Bid: sdk.NewInt64Coin("usdt", 0),
|
||||||
@ -393,7 +393,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("dai", 68605874),
|
Lot: sdk.NewInt64Coin("dai", 68605874),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("usdx", 0),
|
Bid: sdk.NewInt64Coin("usdx", 0),
|
||||||
@ -408,7 +408,7 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
Initiator: "hard_liquidator",
|
Initiator: "hard",
|
||||||
Lot: sdk.NewInt64Coin("usdc", 189999999),
|
Lot: sdk.NewInt64Coin("usdc", 189999999),
|
||||||
Bidder: nil,
|
Bidder: nil,
|
||||||
Bid: sdk.NewInt64Coin("usdx", 0),
|
Bid: sdk.NewInt64Coin("usdx", 0),
|
||||||
|
@ -299,19 +299,19 @@ func (suite *KeeperTestSuite) TestSendTimeLockedCoinsToAccount() {
|
|||||||
ak.SetAccount(ctx, pva)
|
ak.SetAccount(ctx, pva)
|
||||||
}
|
}
|
||||||
supplyKeeper := tApp.GetSupplyKeeper()
|
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()
|
keeper := tApp.GetHardKeeper()
|
||||||
suite.app = tApp
|
suite.app = tApp
|
||||||
suite.ctx = ctx
|
suite.ctx = ctx
|
||||||
suite.keeper = keeper
|
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 {
|
if tc.errArgs.expectPass {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
acc := suite.getAccount(tc.args.accArgs.addr)
|
acc := suite.getAccount(tc.args.accArgs.addr)
|
||||||
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
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())
|
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
||||||
vacc, ok := acc.(*vesting.PeriodicVestingAccount)
|
vacc, ok := acc.(*vesting.PeriodicVestingAccount)
|
||||||
if tc.args.accArgs.vestingAccountAfter {
|
if tc.args.accArgs.vestingAccountAfter {
|
||||||
|
@ -4,9 +4,6 @@ const (
|
|||||||
// ModuleName name that will be used throughout the module
|
// ModuleName name that will be used throughout the module
|
||||||
ModuleName = "hard"
|
ModuleName = "hard"
|
||||||
|
|
||||||
// LiquidatorAccount module account for liquidator
|
|
||||||
LiquidatorAccount = "hard_liquidator"
|
|
||||||
|
|
||||||
// ModuleAccountName name of module account used to hold deposits
|
// ModuleAccountName name of module account used to hold deposits
|
||||||
ModuleAccountName = "hard"
|
ModuleAccountName = "hard"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user