diff --git a/x/bep3/keeper/swap.go b/x/bep3/keeper/swap.go index 6e94e555..873f0883 100644 --- a/x/bep3/keeper/swap.go +++ b/x/bep3/keeper/swap.go @@ -126,21 +126,23 @@ 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]) + if err != nil { + return err + } default: - err = fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String()) - } - - if err != nil { - return err + return fmt.Errorf("invalid swap direction: %s", atomicSwap.Direction.String()) } // Send intended recipient coins @@ -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))), diff --git a/x/cdp/keeper/auctions.go b/x/cdp/keeper/auctions.go index 640a21e7..5228ef08 100644 --- a/x/cdp/keeper/auctions.go +++ b/x/cdp/keeper/auctions.go @@ -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) { diff --git a/x/cdp/keeper/cdp.go b/x/cdp/keeper/cdp.go index 6b2ad8e4..7c9fcc5d 100644 --- a/x/cdp/keeper/cdp.go +++ b/x/cdp/keeper/cdp.go @@ -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 diff --git a/x/cdp/keeper/draw.go b/x/cdp/keeper/draw.go index e1543a1f..1a0b14bc 100644 --- a/x/cdp/keeper/draw.go +++ b/x/cdp/keeper/draw.go @@ -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 diff --git a/x/cdp/keeper/fees.go b/x/cdp/keeper/fees.go index ec1e7a4e..1d2c4555 100644 --- a/x/cdp/keeper/fees.go +++ b/x/cdp/keeper/fees.go @@ -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 diff --git a/x/cdp/keeper/seize.go b/x/cdp/keeper/seize.go index 5a3fa8cf..67075bc7 100644 --- a/x/cdp/keeper/seize.go +++ b/x/cdp/keeper/seize.go @@ -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 diff --git a/x/committee/types/committee_test.go b/x/committee/types/committee_test.go index 8582b447..18df9f30 100644 --- a/x/committee/types/committee_test.go +++ b/x/committee/types/committee_test.go @@ -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, }, } diff --git a/x/incentive/simulation/genesis.go b/x/incentive/simulation/genesis.go index 88a28bd6..cd6513d1 100644 --- a/x/incentive/simulation/genesis.go +++ b/x/incentive/simulation/genesis.go @@ -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) -} diff --git a/x/incentive/simulation/operations.go b/x/incentive/simulation/operations.go index 03e143d8..40aeb4bc 100644 --- a/x/incentive/simulation/operations.go +++ b/x/incentive/simulation/operations.go @@ -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 } diff --git a/x/incentive/simulation/params.go b/x/incentive/simulation/params.go index a8306bf2..19cf0e2a 100644 --- a/x/incentive/simulation/params.go +++ b/x/incentive/simulation/params.go @@ -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 diff --git a/x/validator-vesting/keeper/keeper.go b/x/validator-vesting/keeper/keeper.go index 933d2adc..de51ffdf 100644 --- a/x/validator-vesting/keeper/keeper.go +++ b/x/validator-vesting/keeper/keeper.go @@ -157,34 +157,38 @@ 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() { - spendableCoins := vv.SpendableCoins(blockTime) - if spendableCoins.IsAllGTE(vv.DebtAfterFailedVesting) { - if vv.ReturnAddress != nil { - err := k.bk.SendCoins(ctx, addr, vv.ReturnAddress, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } - } else { - err := k.supplyKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } - err = k.supplyKeeper.BurnCoins(ctx, types.ModuleName, vv.DebtAfterFailedVesting) - if err != nil { - panic(err) - } + if vv.DebtAfterFailedVesting.IsZero() { + return + } + spendableCoins := vv.SpendableCoins(blockTime) + if spendableCoins.IsAllGTE(vv.DebtAfterFailedVesting) { + if vv.ReturnAddress != nil { + err := k.bk.SendCoins(ctx, addr, vv.ReturnAddress, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) } - k.ResetDebt(ctx, addr) } else { - // iterate over all delegations made from the validator vesting account and undelegate - // 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()) - return false - }) + err := k.supplyKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) + } + err = k.supplyKeeper.BurnCoins(ctx, types.ModuleName, vv.DebtAfterFailedVesting) + if err != nil { + panic(err) + } } + k.ResetDebt(ctx, addr) + } else { + // iterate over all delegations made from the validator vesting account and undelegate + // 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) { + _, err := k.stakingKeeper.Undelegate(ctx, d.GetDelegatorAddr(), d.GetValidatorAddr(), d.GetShares()) + if err != nil { + panic(err) + } + return false + }) } } diff --git a/x/validator-vesting/keeper/test_common.go b/x/validator-vesting/keeper/test_common.go index e3f45882..356013e4 100644 --- a/x/validator-vesting/keeper/test_common.go +++ b/x/validator-vesting/keeper/test_common.go @@ -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) }