mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 23:35:19 +00:00
minor refactor
This commit is contained in:
parent
89b63a3cba
commit
6b478a0f95
@ -32,31 +32,32 @@ func (k Keeper) CreateAuctionsFromDeposit(
|
|||||||
ctx sdk.Context, collateral sdk.Coin, returnAddr sdk.AccAddress, debt, auctionSize sdk.Int,
|
ctx sdk.Context, collateral sdk.Coin, returnAddr sdk.AccAddress, debt, auctionSize sdk.Int,
|
||||||
principalDenom string) (err error) {
|
principalDenom string) (err error) {
|
||||||
|
|
||||||
amountToAuction := sdk.NewInt(collateral.Amount.Int64())
|
amountToAuction := collateral.Amount
|
||||||
totalCollateralAmount := sdk.NewInt(collateral.Amount.Int64())
|
totalCollateralAmount := collateral.Amount
|
||||||
remainingDebt := sdk.NewInt(debt.Int64())
|
remainingDebt := debt
|
||||||
for amountToAuction.GT(sdk.ZeroInt()) {
|
if !amountToAuction.IsPositive() {
|
||||||
for amountToAuction.GT(auctionSize) {
|
return nil
|
||||||
debtCoveredByAuction := (sdk.NewDecFromInt(auctionSize).Quo(sdk.NewDecFromInt(totalCollateralAmount))).Mul(sdk.NewDecFromInt(debt)).RoundInt()
|
}
|
||||||
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, debtCoveredByAuction)
|
for amountToAuction.GT(auctionSize) {
|
||||||
_, err := k.auctionKeeper.StartCollateralAuction(
|
debtCoveredByAuction := (sdk.NewDecFromInt(auctionSize).Quo(sdk.NewDecFromInt(totalCollateralAmount))).Mul(sdk.NewDecFromInt(debt)).RoundInt()
|
||||||
ctx, types.LiquidatorMacc, sdk.NewCoin(collateral.Denom, auctionSize), sdk.NewCoin(principalDenom, debtCoveredByAuction.Add(penalty)), []sdk.AccAddress{returnAddr},
|
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, debtCoveredByAuction)
|
||||||
[]sdk.Int{auctionSize}, sdk.NewCoin(k.GetDebtDenom(ctx), debtCoveredByAuction))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
amountToAuction = amountToAuction.Sub(auctionSize)
|
|
||||||
remainingDebt = remainingDebt.Sub(debtCoveredByAuction)
|
|
||||||
}
|
|
||||||
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, remainingDebt)
|
|
||||||
_, err := k.auctionKeeper.StartCollateralAuction(
|
_, err := k.auctionKeeper.StartCollateralAuction(
|
||||||
ctx, types.LiquidatorMacc, sdk.NewCoin(collateral.Denom, amountToAuction), sdk.NewCoin(principalDenom, remainingDebt.Add(penalty)), []sdk.AccAddress{returnAddr},
|
ctx, types.LiquidatorMacc, sdk.NewCoin(collateral.Denom, auctionSize), sdk.NewCoin(principalDenom, debtCoveredByAuction.Add(penalty)), []sdk.AccAddress{returnAddr},
|
||||||
[]sdk.Int{amountToAuction}, sdk.NewCoin(k.GetDebtDenom(ctx), remainingDebt))
|
[]sdk.Int{auctionSize}, sdk.NewCoin(k.GetDebtDenom(ctx), debtCoveredByAuction))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
amountToAuction = sdk.ZeroInt()
|
amountToAuction = amountToAuction.Sub(auctionSize)
|
||||||
|
remainingDebt = remainingDebt.Sub(debtCoveredByAuction)
|
||||||
}
|
}
|
||||||
|
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, remainingDebt)
|
||||||
|
_, err = k.auctionKeeper.StartCollateralAuction(
|
||||||
|
ctx, types.LiquidatorMacc, sdk.NewCoin(collateral.Denom, amountToAuction), sdk.NewCoin(principalDenom, remainingDebt.Add(penalty)), []sdk.AccAddress{returnAddr},
|
||||||
|
[]sdk.Int{amountToAuction}, sdk.NewCoin(k.GetDebtDenom(ctx), remainingDebt))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user