mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
fix some lint bugs
This commit is contained in:
parent
363c4f61aa
commit
1a04ffe396
@ -126,22 +126,24 @@ func (k Keeper) ClaimAtomicSwap(ctx sdk.Context, from sdk.AccAddress, swapID []b
|
||||
case types.Incoming:
|
||||
err := k.DecrementIncomingAssetSupply(ctx, atomicSwap.Amount[0])
|
||||
if err != nil {
|
||||
break
|
||||
return err
|
||||
}
|
||||
err = k.IncrementCurrentAssetSupply(ctx, atomicSwap.Amount[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case types.Outgoing:
|
||||
err = k.DecrementOutgoingAssetSupply(ctx, atomicSwap.Amount[0])
|
||||
if err != nil {
|
||||
break
|
||||
return err
|
||||
}
|
||||
err = k.DecrementCurrentAssetSupply(ctx, atomicSwap.Amount[0])
|
||||
default:
|
||||
err = fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String())
|
||||
}
|
||||
|
||||
// Send intended recipient coins
|
||||
err = k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, atomicSwap.Recipient, atomicSwap.Amount)
|
||||
@ -216,7 +218,7 @@ func (k Keeper) RefundAtomicSwap(ctx sdk.Context, from sdk.AccAddress, swapID []
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
types.EventTypeRefundAtomicSwap,
|
||||
sdk.NewAttribute(types.AttributeKeyRefundSender, fmt.Sprintf("%s", from)),
|
||||
sdk.NewAttribute(types.AttributeKeyRefundSender, from),
|
||||
sdk.NewAttribute(types.AttributeKeySender, fmt.Sprintf("%s", atomicSwap.Sender)),
|
||||
sdk.NewAttribute(types.AttributeKeyAtomicSwapID, fmt.Sprintf("%s", hex.EncodeToString(atomicSwap.GetSwapID()))),
|
||||
sdk.NewAttribute(types.AttributeKeyRandomNumberHash, fmt.Sprintf("%s", hex.EncodeToString(atomicSwap.RandomNumberHash))),
|
||||
|
@ -210,7 +210,9 @@ func (k Keeper) GetTotalDebt(ctx sdk.Context, accountName string) sdk.Int {
|
||||
|
||||
// RunSurplusAndDebtAuctions nets the surplus and debt balances and then creates surplus or debt auctions if the remaining balance is above the auction threshold parameter
|
||||
func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error {
|
||||
k.NetSurplusAndDebt(ctx)
|
||||
if err := k.NetSurplusAndDebt(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
remainingDebt := k.GetTotalDebt(ctx, types.LiquidatorMacc)
|
||||
params := k.GetParams(ctx)
|
||||
if remainingDebt.GTE(params.DebtAuctionThreshold) {
|
||||
|
@ -199,7 +199,7 @@ func (k Keeper) SetCDP(ctx sdk.Context, cdp types.CDP) error {
|
||||
store := prefix.NewStore(ctx.KVStore(k.key), types.CdpKeyPrefix)
|
||||
db, found := k.GetDenomPrefix(ctx, cdp.Collateral.Denom)
|
||||
if !found {
|
||||
sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom)
|
||||
return sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom)
|
||||
}
|
||||
bz := k.cdc.MustMarshalBinaryLengthPrefixed(cdp)
|
||||
store.Set(types.CdpKey(db, cdp.ID), bz)
|
||||
@ -211,7 +211,7 @@ func (k Keeper) DeleteCDP(ctx sdk.Context, cdp types.CDP) error {
|
||||
store := prefix.NewStore(ctx.KVStore(k.key), types.CdpKeyPrefix)
|
||||
db, found := k.GetDenomPrefix(ctx, cdp.Collateral.Denom)
|
||||
if !found {
|
||||
sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom)
|
||||
return sdkerrors.Wrapf(types.ErrDenomPrefixNotFound, "%s", cdp.Collateral.Denom)
|
||||
}
|
||||
store.Delete(types.CdpKey(db, cdp.ID))
|
||||
return nil
|
||||
|
@ -142,7 +142,10 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri
|
||||
// and remove the cdp and indexes from the store
|
||||
if cdp.Principal.IsZero() && cdp.AccumulatedFees.IsZero() {
|
||||
k.ReturnCollateral(ctx, cdp)
|
||||
k.DeleteCDP(ctx, cdp)
|
||||
if err := k.DeleteCDP(ctx, cdp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k.RemoveCdpOwnerIndex(ctx, cdp)
|
||||
|
||||
// emit cdp close event
|
||||
|
@ -56,14 +56,27 @@ func (k Keeper) UpdateFeesForAllCdps(ctx sdk.Context, collateralDenom string) er
|
||||
return false
|
||||
}
|
||||
// mint debt coins to the cdp account
|
||||
k.MintDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), newFees)
|
||||
err := k.MintDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), newFees)
|
||||
if err != nil {
|
||||
iterationErr = err
|
||||
return true
|
||||
}
|
||||
previousDebt := k.GetTotalPrincipal(ctx, collateralDenom, dp.Denom)
|
||||
newDebt := previousDebt.Add(newFees.Amount)
|
||||
k.SetTotalPrincipal(ctx, collateralDenom, dp.Denom, newDebt)
|
||||
|
||||
// mint surplus coins divided between the liquidator and savings module accounts.
|
||||
k.supplyKeeper.MintCoins(ctx, types.LiquidatorMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSurplus)))
|
||||
k.supplyKeeper.MintCoins(ctx, types.SavingsRateMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSavings)))
|
||||
err = k.supplyKeeper.MintCoins(ctx, types.LiquidatorMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSurplus)))
|
||||
if err != nil {
|
||||
iterationErr = err
|
||||
return true
|
||||
}
|
||||
|
||||
err = k.supplyKeeper.MintCoins(ctx, types.SavingsRateMacc, sdk.NewCoins(sdk.NewCoin(dp.Denom, newFeesSavings)))
|
||||
if err != nil {
|
||||
iterationErr = err
|
||||
return true
|
||||
}
|
||||
|
||||
// now add the new fees fees to the accumulated fees for the cdp
|
||||
cdp.AccumulatedFees = cdp.AccumulatedFees.Add(newFees)
|
||||
@ -72,7 +85,7 @@ func (k Keeper) UpdateFeesForAllCdps(ctx sdk.Context, collateralDenom string) er
|
||||
cdp.FeesUpdated = ctx.BlockTime()
|
||||
collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
|
||||
k.RemoveCdpCollateralRatioIndex(ctx, cdp.Collateral.Denom, cdp.ID, oldCollateralToDebtRatio)
|
||||
err := k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
if err != nil {
|
||||
iterationErr = err
|
||||
return true
|
||||
|
@ -61,8 +61,7 @@ func (k Keeper) SeizeCollateral(ctx sdk.Context, cdp types.CDP) error {
|
||||
// Delete CDP from state
|
||||
k.RemoveCdpOwnerIndex(ctx, cdp)
|
||||
k.RemoveCdpCollateralRatioIndex(ctx, cdp.Collateral.Denom, cdp.ID, oldCollateralToDebtRatio)
|
||||
k.DeleteCDP(ctx, cdp)
|
||||
return nil
|
||||
return k.DeleteCDP(ctx, cdp)
|
||||
}
|
||||
|
||||
// LiquidateCdps seizes collateral from all CDPs below the input liquidation ratio
|
||||
|
@ -162,7 +162,7 @@ func (suite *TypesTestSuite) TestCommittee_HasPermissionsFor() {
|
||||
},
|
||||
}},
|
||||
},
|
||||
pubProposal: UnregisteredPubProposal{govtypes.TextProposal{"A Title", "A description."}},
|
||||
pubProposal: UnregisteredPubProposal{govtypes.TextProposal{Title: "A Title", Description: "A description."}},
|
||||
expectHasPermissions: false,
|
||||
},
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
|
||||
"github.com/kava-labs/kava/x/incentive/types"
|
||||
@ -126,15 +125,3 @@ func genNextClaimPeriodIds(cps types.ClaimPeriods) types.GenesisClaimPeriodIDs {
|
||||
}
|
||||
return claimPeriodIDs
|
||||
}
|
||||
|
||||
// In a list of accounts, replace the first account found with the same address. If not found, append the account.
|
||||
func replaceOrAppendAccount(accounts []authexported.GenesisAccount, acc authexported.GenesisAccount) []authexported.GenesisAccount {
|
||||
newAccounts := accounts
|
||||
for i, a := range accounts {
|
||||
if a.GetAddress().Equals(acc.GetAddress()) {
|
||||
newAccounts[i] = acc
|
||||
return newAccounts
|
||||
}
|
||||
}
|
||||
return append(newAccounts, acc)
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
|
||||
@ -51,15 +50,12 @@ func SimulateMsgClaimReward(ak auth.AccountKeeper, sk types.SupplyKeeper, k keep
|
||||
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
||||
|
||||
// Load only account types that can claim rewards
|
||||
var accounts []authexported.Account
|
||||
validAccounts := make(map[string]bool)
|
||||
for _, acc := range accs {
|
||||
account := ak.GetAccount(ctx, acc.Address)
|
||||
switch account.(type) {
|
||||
case *vesting.PeriodicVestingAccount, *auth.BaseAccount: // Valid: BaseAccount, PeriodicVestingAccount
|
||||
accounts = append(accounts, account)
|
||||
validAccounts[account.GetAddress().String()] = true
|
||||
break
|
||||
default: // Invalid: ValidatorVestingAccount, DelayedVestingAccount, ContinuousVestingAccount
|
||||
break
|
||||
}
|
||||
|
@ -18,10 +18,7 @@ const (
|
||||
func genActive(r *rand.Rand) bool {
|
||||
threshold := 80
|
||||
value := simulation.RandIntBetween(r, 1, 100)
|
||||
if value > threshold {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return value <= threshold
|
||||
}
|
||||
|
||||
// ParamChanges defines the parameters that can be modified by param change proposals
|
||||
|
@ -157,7 +157,9 @@ func (k Keeper) ResetCurrentPeriodProgress(ctx sdk.Context, addr sdk.AccAddress)
|
||||
func (k Keeper) HandleVestingDebt(ctx sdk.Context, addr sdk.AccAddress, blockTime time.Time) {
|
||||
vv := k.GetAccountFromAuthKeeper(ctx, addr)
|
||||
|
||||
if !vv.DebtAfterFailedVesting.IsZero() {
|
||||
if vv.DebtAfterFailedVesting.IsZero() {
|
||||
return
|
||||
}
|
||||
spendableCoins := vv.SpendableCoins(blockTime)
|
||||
if spendableCoins.IsAllGTE(vv.DebtAfterFailedVesting) {
|
||||
if vv.ReturnAddress != nil {
|
||||
@ -181,12 +183,14 @@ func (k Keeper) HandleVestingDebt(ctx sdk.Context, addr sdk.AccAddress, blockTim
|
||||
// note that we cannot safely undelegate only an amount of shares that covers the debt,
|
||||
// because the value of those shares could change if a validator gets slashed.
|
||||
k.stakingKeeper.IterateDelegations(ctx, vv.Address, func(index int64, d stakingexported.DelegationI) (stop bool) {
|
||||
k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares())
|
||||
_, err := k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetDebt sets DebtAfterFailedVesting to zero
|
||||
func (k Keeper) ResetDebt(ctx sdk.Context, addr sdk.AccAddress) {
|
||||
|
@ -172,9 +172,12 @@ func ValidatorVestingTestAccount() *types.ValidatorVestingAccount {
|
||||
testConsAddr := sdk.ConsAddress(testPk.Address())
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := auth.NewBaseAccountWithAddress(testAddr)
|
||||
bacc.SetCoins(origCoins)
|
||||
err := bacc.SetCoins(origCoins)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
vva := types.NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90)
|
||||
err := vva.Validate()
|
||||
err = vva.Validate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -196,9 +199,12 @@ func ValidatorVestingTestAccounts(numAccounts int) []*types.ValidatorVestingAcco
|
||||
testConsAddr := sdk.ConsAddress(testPk[i].Address())
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
|
||||
bacc := auth.NewBaseAccountWithAddress(testAddr[i])
|
||||
bacc.SetCoins(origCoins)
|
||||
err := bacc.SetCoins(origCoins)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
vva := types.NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90)
|
||||
err := vva.Validate()
|
||||
err = vva.Validate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -218,9 +224,12 @@ func ValidatorVestingDelegatorTestAccount(startTime time.Time) *types.ValidatorV
|
||||
testConsAddr := sdk.ConsAddress(testPk.Address())
|
||||
origCoins := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 60000000)}
|
||||
bacc := auth.NewBaseAccountWithAddress(testAddr)
|
||||
bacc.SetCoins(origCoins)
|
||||
err := bacc.SetCoins(origCoins)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
vva := types.NewValidatorVestingAccount(&bacc, startTime.Unix(), periods, testConsAddr, nil, 90)
|
||||
err := vva.Validate()
|
||||
err = vva.Validate()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user