mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
decrement/increment coin counters on auctions (#809)
This commit is contained in:
parent
7d4235ca87
commit
7465c643b8
@ -187,6 +187,10 @@ func (k Keeper) StartAuctions(ctx sdk.Context, borrower sdk.AccAddress, borrows,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return liquidatedCoins, err
|
return liquidatedCoins, err
|
||||||
}
|
}
|
||||||
|
// Decrement supplied coins and increment borrowed coins optimistically
|
||||||
|
k.DecrementSuppliedCoins(ctx, sdk.Coins{lot})
|
||||||
|
k.IncrementBorrowedCoins(ctx, sdk.Coins{bid})
|
||||||
|
|
||||||
// Add lot to liquidated coins
|
// Add lot to liquidated coins
|
||||||
liquidatedCoins = liquidatedCoins.Add(lot)
|
liquidatedCoins = liquidatedCoins.Add(lot)
|
||||||
|
|
||||||
@ -232,6 +236,10 @@ func (k Keeper) StartAuctions(ctx sdk.Context, borrower sdk.AccAddress, borrows,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return liquidatedCoins, err
|
return liquidatedCoins, err
|
||||||
}
|
}
|
||||||
|
// Decrement supplied coins and increment borrowed coins optimistically
|
||||||
|
k.DecrementSuppliedCoins(ctx, sdk.Coins{lot})
|
||||||
|
k.IncrementBorrowedCoins(ctx, sdk.Coins{bid})
|
||||||
|
|
||||||
// Add lot to liquidated coins
|
// Add lot to liquidated coins
|
||||||
liquidatedCoins = liquidatedCoins.Add(lot)
|
liquidatedCoins = liquidatedCoins.Add(lot)
|
||||||
|
|
||||||
|
@ -18,19 +18,21 @@ import (
|
|||||||
|
|
||||||
func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
||||||
type args struct {
|
type args struct {
|
||||||
borrower sdk.AccAddress
|
borrower sdk.AccAddress
|
||||||
keeper sdk.AccAddress
|
keeper sdk.AccAddress
|
||||||
keeperRewardPercent sdk.Dec
|
keeperRewardPercent sdk.Dec
|
||||||
initialModuleCoins sdk.Coins
|
initialModuleCoins sdk.Coins
|
||||||
initialBorrowerCoins sdk.Coins
|
initialBorrowerCoins sdk.Coins
|
||||||
initialKeeperCoins sdk.Coins
|
initialKeeperCoins sdk.Coins
|
||||||
depositCoins []sdk.Coin
|
depositCoins []sdk.Coin
|
||||||
borrowCoins sdk.Coins
|
borrowCoins sdk.Coins
|
||||||
liquidateAfter int64
|
liquidateAfter int64
|
||||||
auctionSize sdk.Int
|
expectedLiquidatedCoins sdk.Coins
|
||||||
expectedKeeperCoins sdk.Coins // coins keeper address should have after successfully liquidating position
|
expectedBidCoins sdk.Coins
|
||||||
expectedBorrowerCoins sdk.Coins // additional coins (if any) the borrower address should have after successfully liquidating position
|
auctionSize sdk.Int
|
||||||
expectedAuctions auctypes.Auctions // the auctions we should expect to find have been started
|
expectedKeeperCoins sdk.Coins // coins keeper address should have after successfully liquidating position
|
||||||
|
expectedBorrowerCoins sdk.Coins // additional coins (if any) the borrower address should have after successfully liquidating position
|
||||||
|
expectedAuctions auctypes.Auctions // the auctions we should expect to find have been started
|
||||||
}
|
}
|
||||||
|
|
||||||
type errArgs struct {
|
type errArgs struct {
|
||||||
@ -62,18 +64,20 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
{
|
{
|
||||||
"valid: keeper liquidates borrow",
|
"valid: keeper liquidates borrow",
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(10*KAVA_CF))),
|
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(10*KAVA_CF))),
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(8*KAVA_CF))),
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(8*KAVA_CF))),
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
expectedLiquidatedCoins: sdk.NewCoins(sdk.NewInt64Coin("ukava", 9500390)),
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100500020))),
|
expectedBidCoins: sdk.NewCoins(sdk.NewInt64Coin("ukava", 8004766)),
|
||||||
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(98000001))), // initial - deposit + borrow + liquidation leftovers
|
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
||||||
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100500020))),
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(98000001))), // initial - deposit + borrow + liquidation leftovers
|
||||||
expectedAuctions: auctypes.Auctions{
|
expectedAuctions: auctypes.Auctions{
|
||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
@ -100,18 +104,20 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
{
|
{
|
||||||
"valid: single deposit, multiple borrows",
|
"valid: single deposit, multiple borrows",
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(1000*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1000*BTCB_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(1000*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1000*BTCB_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(50*KAVA_CF))), // $100 * 0.8 = $80 borrowable
|
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(50*KAVA_CF))), // $100 * 0.8 = $80 borrowable
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(20*KAVA_CF)), sdk.NewCoin("ukava", sdk.NewInt(10*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(2*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.2*BTCB_CF))), // $20+$20+$20 = $80 borrowed
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(20*KAVA_CF)), sdk.NewCoin("ukava", sdk.NewInt(10*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(2*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.2*BTCB_CF))), // $20+$20+$20 = $80 borrowed
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
expectedLiquidatedCoins: sdk.NewCoins(sdk.NewInt64Coin("ukava", 47500032)),
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(102500001))),
|
expectedBidCoins: sdk.NewCoins(sdk.NewInt64Coin("bnb", 200003287), sdk.NewInt64Coin("btc", 20000032), sdk.NewInt64Coin("ukava", 10000782), sdk.NewInt64Coin("usdc", 20003284)),
|
||||||
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(20*KAVA_CF)), sdk.NewCoin("ukava", sdk.NewInt(60000002)), sdk.NewCoin("bnb", sdk.NewInt(2*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.2*BTCB_CF))), // initial - deposit + borrow + liquidation leftovers
|
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
||||||
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(102500001))),
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(20*KAVA_CF)), sdk.NewCoin("ukava", sdk.NewInt(60000002)), sdk.NewCoin("bnb", sdk.NewInt(2*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.2*BTCB_CF))), // initial - deposit + borrow + liquidation leftovers
|
||||||
expectedAuctions: auctypes.Auctions{
|
expectedAuctions: auctypes.Auctions{
|
||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
@ -183,18 +189,20 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
{
|
{
|
||||||
"valid: multiple deposits, single borrow",
|
"valid: multiple deposits, single borrow",
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(100*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(100*BTCB_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(100*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(100*BTCB_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(50*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF))), // $100 + $100 + $100 = $300 * 0.8 = $240 borrowable // $100 * 0.8 = $80 borrowable
|
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(50*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF))), // $100 + $100 + $100 = $300 * 0.8 = $240 borrowable // $100 * 0.8 = $80 borrowable
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(120*KAVA_CF))), // $240 borrowed
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(120*KAVA_CF))), // $240 borrowed
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
expectedLiquidatedCoins: sdk.NewCoins(sdk.NewInt64Coin("bnb", 950000000), sdk.NewInt64Coin("btc", 95000000), sdk.NewInt64Coin("ukava", 47504818)),
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(102500253)), sdk.NewCoin("bnb", sdk.NewInt(0.5*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.05*BTCB_CF))), // 5% of each seized coin + initial balances
|
expectedBidCoins: sdk.NewCoins(sdk.NewInt64Coin("ukava", 120112133)),
|
||||||
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(170.000001*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(90*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(99*BTCB_CF))),
|
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
||||||
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(102500253)), sdk.NewCoin("bnb", sdk.NewInt(0.5*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(0.05*BTCB_CF))), // 5% of each seized coin + initial balances
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(170.000001*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(90*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(99*BTCB_CF))),
|
||||||
expectedAuctions: auctypes.Auctions{
|
expectedAuctions: auctypes.Auctions{
|
||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
@ -252,18 +260,20 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
"valid: mutliple stablecoin deposits, multiple variable coin borrows",
|
"valid: mutliple stablecoin deposits, multiple variable coin borrows",
|
||||||
// Auctions: total lot value = $285 ($300 of deposits - $15 keeper reward), total max bid value = $270
|
// Auctions: total lot value = $285 ($300 of deposits - $15 keeper reward), total max bid value = $270
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(1000*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1000*BTCB_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(1000*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1000*BTCB_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(100*KAVA_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(100*KAVA_CF))), // $100 + $100 + $100 = $300 * 0.9 = $270 borrowable
|
depositCoins: sdk.NewCoins(sdk.NewCoin("usdc", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(100*KAVA_CF))), // $100 + $100 + $100 = $300 * 0.9 = $270 borrowable
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(35*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF))), // $270 borrowed
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(35*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF))), // $270 borrowed
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
expectedLiquidatedCoins: sdk.NewCoins(sdk.NewInt64Coin("usdc", 95000000), sdk.NewInt64Coin("usdt", 95000000), sdk.NewInt64Coin("usdx", 94999999)),
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(5*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(5*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(5*KAVA_CF))), // 5% of each seized coin + initial balances
|
expectedBidCoins: sdk.NewCoins(sdk.NewInt64Coin("bnb", 1000082154), sdk.NewInt64Coin("btc", 100000821), sdk.NewInt64Coin("ukava", 35010052)),
|
||||||
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(135*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF)), sdk.NewCoin("usdx", sdk.NewInt(0.000001*KAVA_CF))),
|
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
||||||
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(5*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(5*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(5*KAVA_CF))), // 5% of each seized coin + initial balances
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(135*KAVA_CF)), sdk.NewCoin("bnb", sdk.NewInt(10*BNB_CF)), sdk.NewCoin("btc", sdk.NewInt(1*BTCB_CF)), sdk.NewCoin("usdx", sdk.NewInt(0.000001*KAVA_CF))),
|
||||||
expectedAuctions: auctypes.Auctions{
|
expectedAuctions: auctypes.Auctions{
|
||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
@ -350,18 +360,20 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
{
|
{
|
||||||
"valid: multiple stablecoin deposits, multiple stablecoin borrows",
|
"valid: multiple stablecoin deposits, multiple stablecoin borrows",
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("dai", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1000*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(350*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(200*KAVA_CF))),
|
depositCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(350*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(200*KAVA_CF))),
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("usdt", sdk.NewInt(250*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(245*KAVA_CF))),
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("usdt", sdk.NewInt(250*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(245*KAVA_CF))),
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 100000),
|
expectedLiquidatedCoins: sdk.NewCoins(sdk.NewInt64Coin("dai", 332500000), sdk.NewInt64Coin("usdc", 189999999)),
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(1017.50*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1010*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF))),
|
expectedBidCoins: sdk.NewCoins(sdk.NewInt64Coin("usdx", 245487894), sdk.NewInt64Coin("usdt", 250507897)),
|
||||||
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(650*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(800000001)), sdk.NewCoin("usdt", sdk.NewInt(1250*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(1245*KAVA_CF))),
|
auctionSize: sdk.NewInt(KAVA_CF * 100000),
|
||||||
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(1017.50*KAVA_CF)), sdk.NewCoin("usdt", sdk.NewInt(1000*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(1010*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(1000*KAVA_CF))),
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(sdk.NewCoin("dai", sdk.NewInt(650*KAVA_CF)), sdk.NewCoin("usdc", sdk.NewInt(800000001)), sdk.NewCoin("usdt", sdk.NewInt(1250*KAVA_CF)), sdk.NewCoin("usdx", sdk.NewInt(1245*KAVA_CF))),
|
||||||
expectedAuctions: auctypes.Auctions{
|
expectedAuctions: auctypes.Auctions{
|
||||||
auctypes.CollateralAuction{
|
auctypes.CollateralAuction{
|
||||||
BaseAuction: auctypes.BaseAuction{
|
BaseAuction: auctypes.BaseAuction{
|
||||||
@ -418,19 +430,21 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
{
|
{
|
||||||
"invalid: borrow not liquidatable",
|
"invalid: borrow not liquidatable",
|
||||||
args{
|
args{
|
||||||
borrower: borrower,
|
borrower: borrower,
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
keeperRewardPercent: sdk.MustNewDecFromStr("0.05"),
|
||||||
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialModuleCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialBorrowerCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
initialKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100*KAVA_CF))),
|
||||||
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(20*KAVA_CF))), // Deposit 20 KAVA
|
depositCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(20*KAVA_CF))), // Deposit 20 KAVA
|
||||||
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(5*KAVA_CF))), // Borrow 5 KAVA
|
borrowCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(5*KAVA_CF))), // Borrow 5 KAVA
|
||||||
liquidateAfter: oneMonthInSeconds,
|
liquidateAfter: oneMonthInSeconds,
|
||||||
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
expectedLiquidatedCoins: sdk.Coins{},
|
||||||
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100.5*KAVA_CF))),
|
expectedBidCoins: sdk.Coins{},
|
||||||
expectedBorrowerCoins: sdk.NewCoins(),
|
auctionSize: sdk.NewInt(KAVA_CF * 1000),
|
||||||
expectedAuctions: auctypes.Auctions{},
|
expectedKeeperCoins: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(100.5*KAVA_CF))),
|
||||||
|
expectedBorrowerCoins: sdk.NewCoins(),
|
||||||
|
expectedAuctions: auctypes.Auctions{},
|
||||||
},
|
},
|
||||||
errArgs{
|
errArgs{
|
||||||
expectPass: false,
|
expectPass: false,
|
||||||
@ -616,6 +630,12 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
_, foundDepositBefore := suite.keeper.GetDeposit(liqCtx, tc.args.borrower)
|
_, foundDepositBefore := suite.keeper.GetDeposit(liqCtx, tc.args.borrower)
|
||||||
suite.Require().True(foundDepositBefore)
|
suite.Require().True(foundDepositBefore)
|
||||||
|
|
||||||
|
// Fetch supplied and borrowed coins pre-liquidation
|
||||||
|
suppliedCoinsPre, foundSuppliedCoinsPre := suite.keeper.GetSuppliedCoins(liqCtx)
|
||||||
|
suite.Require().True(foundSuppliedCoinsPre)
|
||||||
|
borrowedCoinsPre, foundBorrowedCoinsPre := suite.keeper.GetBorrowedCoins(liqCtx)
|
||||||
|
suite.Require().True(foundBorrowedCoinsPre)
|
||||||
|
|
||||||
// Attempt to liquidate
|
// Attempt to liquidate
|
||||||
err = suite.keeper.AttemptKeeperLiquidation(liqCtx, tc.args.keeper, tc.args.borrower)
|
err = suite.keeper.AttemptKeeperLiquidation(liqCtx, tc.args.keeper, tc.args.borrower)
|
||||||
if tc.errArgs.expectPass {
|
if tc.errArgs.expectPass {
|
||||||
@ -640,6 +660,13 @@ func (suite *KeeperTestSuite) TestKeeperLiquidation() {
|
|||||||
auctions := suite.auctionKeeper.GetAllAuctions(liqCtx)
|
auctions := suite.auctionKeeper.GetAllAuctions(liqCtx)
|
||||||
suite.Require().True(len(auctions) > 0)
|
suite.Require().True(len(auctions) > 0)
|
||||||
suite.Require().Equal(tc.args.expectedAuctions, auctions)
|
suite.Require().Equal(tc.args.expectedAuctions, auctions)
|
||||||
|
|
||||||
|
// Check that supplied and borrowed coins have been updated post-liquidation
|
||||||
|
suppliedCoinsPost, _ := suite.keeper.GetSuppliedCoins(liqCtx)
|
||||||
|
suite.Require().Equal(suppliedCoinsPre.Sub(tc.args.expectedLiquidatedCoins), suppliedCoinsPost)
|
||||||
|
borrowedCoinsPost, _ := suite.keeper.GetBorrowedCoins(liqCtx)
|
||||||
|
|
||||||
|
suite.Require().Equal(borrowedCoinsPre.Add(tc.args.expectedBidCoins...), borrowedCoinsPost)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
suite.Require().True(strings.Contains(err.Error(), tc.errArgs.contains))
|
||||||
|
Loading…
Reference in New Issue
Block a user