Skip to content

Commit

Permalink
Merge pull request #241 from terra-money/feat/v2.10/vesting
Browse files Browse the repository at this point in the history
feat(v2.10): remove vesting tokens code
  • Loading branch information
emidev98 authored Jan 12, 2024
2 parents ac87c37 + b1ce893 commit 7e9128d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 88 deletions.
84 changes: 0 additions & 84 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app

import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -48,7 +47,6 @@ import (
cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
Expand Down Expand Up @@ -325,9 +323,6 @@ func (app *TerraApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abc
res := app.mm.InitGenesis(ctx, app.appCodec, genesisState)
app.Keepers.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())

// stake all vesting tokens
app.enforceStakingForVestingTokens(ctx, genesisState)

return res
}

Expand Down Expand Up @@ -437,85 +432,6 @@ func RegisterSwaggerAPI(rtr *mux.Router) {
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}

// enforceStakingForVestingTokens enforce vesting tokens to be staked
// CONTRACT: validator's gentx account must not be a vesting account
func (app *TerraApp) enforceStakingForVestingTokens(ctx sdk.Context, genesisState GenesisState) {

var authState authtypes.GenesisState
app.appCodec.MustUnmarshalJSON(genesisState[authtypes.ModuleName], &authState)

allValidators := app.Keepers.StakingKeeper.GetAllValidators(ctx)

// Filter out validators which have huge max commission than 20%
var validators []stakingtypes.Validator
maxCommissionCondition := sdk.NewDecWithPrec(20, 2)
for _, val := range allValidators {
if val.Commission.CommissionRates.MaxRate.LTE(maxCommissionCondition) {
validators = append(validators, val)
}
}

validatorLen := len(validators)

// ignore when validator len is zero
if validatorLen == 0 {
return
}

i := 0
stakeSplitCondition := sdk.NewInt(1_000_000_000_000)
powerReduction := app.Keepers.StakingKeeper.PowerReduction(ctx)
for _, acc := range authState.GetAccounts() {
var account authtypes.AccountI
if err := app.InterfaceRegistry().UnpackAny(acc, &account); err != nil {
panic(err)
}

bondDenom := app.Keepers.StakingKeeper.BondDenom(ctx)

if vestingAcc, ok := account.(*vestingtypes.BaseVestingAccount); ok {
amt := vestingAcc.GetOriginalVesting().AmountOf(bondDenom)

// to prevent staking multiple times over the same validator
// adjust split amount for the whale account
splitAmt := stakeSplitCondition
if amt.GT(stakeSplitCondition.MulRaw(int64(validatorLen))) {
splitAmt = amt.QuoRaw(int64(validatorLen))
}

// if a vesting account has more staking token than `stakeSplitCondition`,
// split staking balance to distribute staking power evenly
// Ex) 2_200_000_000_000
// stake 1_000_000_000_000 to val1
// stake 1_000_000_000_000 to val2
// stake 200_000_000_000 to val3
for ; amt.GTE(powerReduction); amt = amt.Sub(splitAmt) {
validator := validators[i%validatorLen]
address := vestingAcc.GetAddress().String()
fmt.Print(address)
if _, err := app.Keepers.StakingKeeper.Delegate(
ctx,
vestingAcc.GetAddress(),
sdk.MinInt(amt, splitAmt),
stakingtypes.Unbonded,
validator,
true,
); err != nil {
panic(err)
}

// reload validator to avoid power index problem
validator, _ = app.Keepers.StakingKeeper.GetValidator(ctx, validator.GetOperator())
validators[i%validatorLen] = validator

// increase index only when staking happened
i++
}

}
}
}

func (app *TerraApp) SimulationManager() *module.SimulationManager {
appCodec := app.appCodec
// create the simulation manager and define the order of the modules for deterministic simulations
Expand Down
6 changes: 2 additions & 4 deletions integration-tests/src/modules/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ describe("Auth Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0
// Validate the vesting end has been set in the past
expect(vestAcc.base_vesting_account.end_time)
.toBeGreaterThan(moment().unix());
// Validate the original vesting and delegated vesting
// Validate the original vesting
expect(vestAcc.base_vesting_account.original_vesting)
.toStrictEqual(Coins.fromString("10000000000uluna"));
expect(vestAcc.base_vesting_account.delegated_vesting)
.toStrictEqual(Coins.fromString("10000000000uluna"));

// Validate other params from base account
expect(vestAcc.base_vesting_account.base_account.address)
Expand All @@ -58,7 +56,7 @@ describe("Auth Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0

// Validate the unlocked balance is still available
expect(vestAccBalance[0].get("uluna"))
.toStrictEqual(Coin.fromString("990000000000uluna"));
.toStrictEqual(Coin.fromString("1000000000000uluna"));
});

test('Must create a random vesting account', async () => {
Expand Down

0 comments on commit 7e9128d

Please sign in to comment.