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,10 +32,12 @@ 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() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
for amountToAuction.GT(auctionSize) {
|
for amountToAuction.GT(auctionSize) {
|
||||||
debtCoveredByAuction := (sdk.NewDecFromInt(auctionSize).Quo(sdk.NewDecFromInt(totalCollateralAmount))).Mul(sdk.NewDecFromInt(debt)).RoundInt()
|
debtCoveredByAuction := (sdk.NewDecFromInt(auctionSize).Quo(sdk.NewDecFromInt(totalCollateralAmount))).Mul(sdk.NewDecFromInt(debt)).RoundInt()
|
||||||
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, debtCoveredByAuction)
|
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, debtCoveredByAuction)
|
||||||
@ -49,14 +51,13 @@ func (k Keeper) CreateAuctionsFromDeposit(
|
|||||||
remainingDebt = remainingDebt.Sub(debtCoveredByAuction)
|
remainingDebt = remainingDebt.Sub(debtCoveredByAuction)
|
||||||
}
|
}
|
||||||
penalty := k.ApplyLiquidationPenalty(ctx, collateral.Denom, remainingDebt)
|
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, amountToAuction), sdk.NewCoin(principalDenom, remainingDebt.Add(penalty)), []sdk.AccAddress{returnAddr},
|
||||||
[]sdk.Int{amountToAuction}, sdk.NewCoin(k.GetDebtDenom(ctx), remainingDebt))
|
[]sdk.Int{amountToAuction}, sdk.NewCoin(k.GetDebtDenom(ctx), remainingDebt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
amountToAuction = sdk.ZeroInt()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user