From 41918cad052e3df65e10ae4ea41c5b17fddb970a Mon Sep 17 00:00:00 2001 From: Pratik Date: Fri, 29 Mar 2024 11:14:14 +0530 Subject: [PATCH] updating slots revoke logic --- x/auctionsV2/keeper/auctions.go | 14 ++++++ x/liquidationsV2/keeper/liquidate.go | 72 ++++++++++------------------ 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/x/auctionsV2/keeper/auctions.go b/x/auctionsV2/keeper/auctions.go index c99b35ddf..fc002c2e3 100644 --- a/x/auctionsV2/keeper/auctions.go +++ b/x/auctionsV2/keeper/auctions.go @@ -336,6 +336,20 @@ func (k Keeper) UpdateDutchAuction(ctx sdk.Context, dutchAuction types.Auction) func (k Keeper) RestartEnglishAuction(ctx sdk.Context, englishAuction types.Auction) error { + // logic to revoke debt auction, instead of restarting + // get the locked vault for that auction and check initiator type = "debt" + lockedVault, _ := k.LiquidationsV2.GetLockedVault(ctx, 2, englishAuction.LockedVaultId) + if lockedVault.InitiatorType == "debt" { + // delete auction and the associated locked vault if no bids + if englishAuction.ActiveBiddingId == 0 { + err := k.DeleteAuction(ctx, englishAuction) + if err != nil { + return err + } + k.LiquidationsV2.DeleteLockedVault(ctx, englishAuction.AppId, englishAuction.LockedVaultId) + } + } + auctionParams, _ := k.GetAuctionParams(ctx) englishAuction.EndTime = ctx.BlockTime().Add(time.Second * time.Duration(auctionParams.AuctionDurationSeconds)) err := k.SetAuction(ctx, englishAuction) diff --git a/x/liquidationsV2/keeper/liquidate.go b/x/liquidationsV2/keeper/liquidate.go index 28f19b275..9f103b48b 100644 --- a/x/liquidationsV2/keeper/liquidate.go +++ b/x/liquidationsV2/keeper/liquidate.go @@ -24,13 +24,6 @@ func (k Keeper) Liquidate(ctx sdk.Context) error { return err } - // as soon as admin makes the debt auction true, then first check for all debt auctions that will be revoked - // so the previous slots with no bids will be revoked. - err = k.RevokeDebtAuction(ctx) - if err != nil { - return err - } - err = k.LiquidateForSurplusAndDebt(ctx) if err != nil { return err @@ -508,21 +501,35 @@ func (k Keeper) CheckStatsForSurplusAndDebt(ctx sdk.Context, appID, assetID uint // debt_lot_size = how much debt we want to recover from a single auction // lot_size = check param + // check if debt auction is already there, it won't create any additional debt auction for now + // as soon as after the end of 6 hours, the auctions with no bids will be revoked. + if netFeeCollectedData.NetFeesCollected.LTE(collector.DebtThreshold.Sub(collector.LotSize)) && auctionLookupTable.IsDebtAuction { - //slots := ((collector.DebtThreshold).Sub(netFeeCollectedData.NetFeesCollected.Add(collector.LotSize))).Quo(collector.LotSize).Int64() - slots := k.collector.GetSlots(ctx) - collateralToken, debtToken := k.DebtTokenAmount(ctx, collateralAssetID, debtAssetID, collector.LotSize, collector.DebtLotSize) - for i := uint64(0); i <= slots; i++ { - err := k.CreateLockedVault(ctx, 0, 0, "", collateralToken, debtToken, collateralToken, debtToken, sdk.ZeroDec(), appID, false, "", "", sdk.ZeroInt(), sdk.ZeroInt(), "debt", false, true, collateralAssetID, debtAssetID) - if err != nil { - return err + var auctionActive = false + auctions := k.auctionsV2.GetAuctions(ctx) + for _, auction := range auctions { + if !auction.AuctionType { + // get the locked vault for that auction and check initiator type = "debt" + lockedVault, _ := k.GetLockedVault(ctx, appID, auction.LockedVaultId) + if lockedVault.InitiatorType == "debt" { + auctionActive = true + break + } } } - // Now setting the flog for auctionLookupTable.IsDebtAuction to false - auctionLookupTable.IsDebtAuction = false - err1 := k.collector.SetAuctionMappingForApp(ctx, auctionLookupTable) - if err1 != nil { - return err1 + if !auctionActive { + actualSlots := ((collector.DebtThreshold).Sub(netFeeCollectedData.NetFeesCollected.Add(collector.LotSize))).Quo(collector.LotSize) + slots := k.collector.GetSlots(ctx) + if actualSlots.Uint64() < slots { + slots = actualSlots.Uint64() + } + collateralToken, debtToken := k.DebtTokenAmount(ctx, collateralAssetID, debtAssetID, collector.LotSize, collector.DebtLotSize) + for i := uint64(0); i < slots; i++ { + err := k.CreateLockedVault(ctx, 0, 0, "", collateralToken, debtToken, collateralToken, debtToken, sdk.ZeroDec(), appID, false, "", "", sdk.ZeroInt(), sdk.ZeroInt(), "debt", false, true, collateralAssetID, debtAssetID) + if err != nil { + return err + } + } } } @@ -838,30 +845,3 @@ func (k Keeper) MsgCloseDutchAuctionForBorrow(ctx sdk.Context, liquidationData t k.lend.DeleteBorrowInterestTracker(ctx, liquidationData.OriginalVaultId) return nil } - -func (k Keeper) RevokeDebtAuction(ctx sdk.Context) error { - // check if IsDebtAuction is true - // Get all debt auctions. - // now, auctions with no bids to be deleted - auctionLookupTable, _ := k.collector.GetAuctionMappingForApp(ctx, 2, 3) - if auctionLookupTable.IsDebtAuction { - auctions := k.auctionsV2.GetAuctions(ctx) - for _, auction := range auctions { - if !auction.AuctionType { - // get the locked vault for that auction and check initiator type = "debt" - lockedVault, _ := k.GetLockedVault(ctx, 2, auction.LockedVaultId) - if lockedVault.InitiatorType == "debt" { - // delete auction and the associated locked vault if no bids - if auction.ActiveBiddingId == 0 { - err := k.auctionsV2.DeleteAuction(ctx, auction) - if err != nil { - return err - } - k.DeleteLockedVault(ctx, 2, auction.LockedVaultId) - } - } - } - } - } - return nil -}