Skip to content

Commit

Permalink
updating slots revoke logic
Browse files Browse the repository at this point in the history
pratikasr committed Mar 29, 2024
1 parent 1df0cb1 commit 41918ca
Showing 2 changed files with 40 additions and 46 deletions.
14 changes: 14 additions & 0 deletions x/auctionsV2/keeper/auctions.go
Original file line number Diff line number Diff line change
@@ -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)
72 changes: 26 additions & 46 deletions x/liquidationsV2/keeper/liquidate.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 41918ca

Please sign in to comment.