mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
Update GetTotalSurplus and GetTotalDebt to be consistent (#567)
* update GetTotalSurplus and GetTotalDebt code blocks to be consistent and resolve feedback in exhibit 13 * spelling fix * remove uneeded temp variables * address PR feedback - use suite.Require() instead of default assertions
This commit is contained in:
parent
a22ecd2f67
commit
3f043b90ac
@ -88,18 +88,14 @@ func (k Keeper) NetSurplusAndDebt(ctx sdk.Context) error {
|
||||
// GetTotalSurplus returns the total amount of surplus tokens held by the liquidator module account
|
||||
func (k Keeper) GetTotalSurplus(ctx sdk.Context, accountName string) sdk.Int {
|
||||
acc := k.supplyKeeper.GetModuleAccount(ctx, accountName)
|
||||
totalSurplus := sdk.ZeroInt()
|
||||
dp := k.GetParams(ctx).DebtParam
|
||||
surplus := acc.GetCoins().AmountOf(dp.Denom)
|
||||
totalSurplus = totalSurplus.Add(surplus)
|
||||
return totalSurplus
|
||||
return acc.GetCoins().AmountOf(dp.Denom)
|
||||
}
|
||||
|
||||
// GetTotalDebt returns the total amount of debt tokens held by the liquidator module account
|
||||
func (k Keeper) GetTotalDebt(ctx sdk.Context, accountName string) sdk.Int {
|
||||
acc := k.supplyKeeper.GetModuleAccount(ctx, accountName)
|
||||
debt := acc.GetCoins().AmountOf(k.GetDebtDenom(ctx))
|
||||
return debt
|
||||
return acc.GetCoins().AmountOf(k.GetDebtDenom(ctx))
|
||||
}
|
||||
|
||||
// RunSurplusAndDebtAuctions nets the surplus and debt balances and then creates surplus or debt auctions if the remaining balance is above the auction threshold parameter
|
||||
|
@ -92,6 +92,66 @@ func (suite *AuctionTestSuite) TestDebtAuction() {
|
||||
suite.Equal(cs(c("debt", 90000000000)), acc.GetCoins())
|
||||
}
|
||||
|
||||
func (suite *AuctionTestSuite) TestGetTotalSurplus() {
|
||||
sk := suite.app.GetSupplyKeeper()
|
||||
|
||||
// liquidator account has zero coins
|
||||
suite.Require().Equal(sdk.NewInt(0), suite.keeper.GetTotalSurplus(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// mint some coins
|
||||
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 100e6)))
|
||||
suite.Require().NoError(err)
|
||||
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 200e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator account has 300e6 total usdx
|
||||
suite.Require().Equal(sdk.NewInt(300e6), suite.keeper.GetTotalSurplus(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// mint some debt
|
||||
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 500e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator account still has 300e6 total usdx -- debt balance is ignored
|
||||
suite.Require().Equal(sdk.NewInt(300e6), suite.keeper.GetTotalSurplus(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// burn some usdx
|
||||
err = sk.BurnCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 50e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator usdx decreases
|
||||
suite.Require().Equal(sdk.NewInt(250e6), suite.keeper.GetTotalSurplus(suite.ctx, types.LiquidatorMacc))
|
||||
}
|
||||
|
||||
func (suite *AuctionTestSuite) TestGetTotalDebt() {
|
||||
sk := suite.app.GetSupplyKeeper()
|
||||
|
||||
// liquidator account has zero debt
|
||||
suite.Require().Equal(sdk.NewInt(0), suite.keeper.GetTotalSurplus(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// mint some debt
|
||||
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 100e6)))
|
||||
suite.Require().NoError(err)
|
||||
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 200e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator account has 300e6 total debt
|
||||
suite.Require().Equal(sdk.NewInt(300e6), suite.keeper.GetTotalDebt(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// mint some usdx
|
||||
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 500e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator account still has 300e6 total debt -- usdx balance is ignored
|
||||
suite.Require().Equal(sdk.NewInt(300e6), suite.keeper.GetTotalDebt(suite.ctx, types.LiquidatorMacc))
|
||||
|
||||
// burn some debt
|
||||
err = sk.BurnCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 50e6)))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// liquidator debt decreases
|
||||
suite.Require().Equal(sdk.NewInt(250e6), suite.keeper.GetTotalDebt(suite.ctx, types.LiquidatorMacc))
|
||||
}
|
||||
|
||||
func TestAuctionTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(AuctionTestSuite))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user