Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!feat: Intergrate multi-staking module #104

Merged
merged 61 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7d17bd4
add multi staking
GNaD13 Dec 26, 2023
aa48f6d
upgrade handler
GNaD13 Dec 29, 2023
a89ddca
go mod
GNaD13 Dec 29, 2023
6776105
upgrade name:
GNaD13 Dec 29, 2023
c9793d2
comment
GNaD13 Dec 29, 2023
3da645e
nit
GNaD13 Jan 3, 2024
7ec63b3
nit
GNaD13 Jan 3, 2024
b729c16
nit
GNaD13 Jan 3, 2024
d3b22b9
step
GNaD13 Jan 3, 2024
aaeeefa
new migrate
GNaD13 Jan 3, 2024
21b213f
comment
GNaD13 Jan 3, 2024
f76d9af
add key to upgrade handler
GNaD13 Jan 3, 2024
c3d4282
migrate staking module
hieuvubk Jan 3, 2024
88c1969
migrate bank
GNaD13 Jan 3, 2024
9ae1519
Merge pull request #1 from decentrio/migrate-bank
GNaD13 Jan 3, 2024
e568450
nit
GNaD13 Jan 3, 2024
6b4b492
upgrade hanlder
GNaD13 Jan 3, 2024
6ababc8
nit
GNaD13 Jan 3, 2024
b0460db
resolve conflict
hieuvubk Jan 3, 2024
5d0e806
change cm
GNaD13 Jan 3, 2024
6f9ab27
tidy
GNaD13 Jan 3, 2024
8af3bf9
go mod
GNaD13 Jan 3, 2024
f1e8c94
nit
GNaD13 Jan 3, 2024
b9fb09e
add log
GNaD13 Jan 3, 2024
8250c6f
nit
GNaD13 Jan 3, 2024
400d376
home
hieuvubk Jan 3, 2024
8880a97
state test
GNaD13 Jan 3, 2024
654d5fd
nit
GNaD13 Jan 3, 2024
2cbe664
Merge branch 'intergrate-multistaking' of https://github.com/decentri…
hieuvubk Jan 3, 2024
fdfaa48
mock types
hieuvubk Jan 3, 2024
64686cb
fix
hieuvubk Jan 3, 2024
4cccb49
no need import
hieuvubk Jan 3, 2024
aaad598
test
GNaD13 Jan 3, 2024
7c02451
nit
GNaD13 Jan 3, 2024
1ed7bb4
add migrate distribution
GNaD13 Jan 5, 2024
5e01c61
use IntermediaryDelegator
hieuvubk Jan 6, 2024
7b77af7
Merge branch 'intergrate-multistaking' of https://github.com/decentri…
hieuvubk Jan 6, 2024
4e69cac
new multi-staking module
GNaD13 Jan 17, 2024
9e212f5
Merge remote-tracking branch 'decent/intergrate-multistaking' into in…
GNaD13 Jan 17, 2024
39b1473
merge
GNaD13 Jan 17, 2024
60194ac
done
GNaD13 Jan 17, 2024
8d1cf1b
remove unused code
GNaD13 Jan 17, 2024
8eca95c
nit
GNaD13 Jan 17, 2024
388ecef
nit
GNaD13 Jan 17, 2024
3914449
nit
GNaD13 Jan 19, 2024
478ccbb
nit
GNaD13 Jan 19, 2024
17fbc06
module permission:
GNaD13 Jan 19, 2024
ca17423
update multi-staking
GNaD13 Jan 19, 2024
9bc1794
create module account in upgrade handler
GNaD13 Jan 19, 2024
c975933
add migrate multistaking unlock:
GNaD13 Jan 19, 2024
105cd03
update multi-staking module
GNaD13 Jan 25, 2024
822c761
release multi staking
GNaD13 Jan 26, 2024
8a65176
fix setup test
GNaD13 Jan 28, 2024
c35fd1b
nit
GNaD13 Jan 28, 2024
afc8a64
nit
GNaD13 Jan 29, 2024
1fddfea
validate genesis
GNaD13 Jan 29, 2024
e6cedb1
Change release version to v1.0.0-rc2
neitdung Jan 30, 2024
27fc5da
Remove unused files
neitdung Jan 31, 2024
951118d
nit
GNaD13 Jan 31, 2024
2815270
nit
GNaD13 Feb 1, 2024
d164330
nit
GNaD13 Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 43 additions & 55 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import (
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/staking"

// staking
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

// multi-staking
multistaking "github.com/realio-tech/multi-staking-module/x/multi-staking"
multistakingkeeper "github.com/realio-tech/multi-staking-module/x/multi-staking/keeper"
multistakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types"

evmante "github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/encoding"
srvflags "github.com/evmos/ethermint/server/flags"
Expand Down Expand Up @@ -141,7 +149,7 @@ var (
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catShaark should we keep the staking module here to? We are still using the staking keeper down here.

Copy link
Contributor Author

@GNaD13 GNaD13 Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We change to multi-staking module, which is wrap staking module

multistaking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
Expand Down Expand Up @@ -177,6 +185,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
assetmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
multistakingtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -217,22 +226,23 @@ type RealioNetwork struct {
memKeys map[string]*storetypes.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
MultiStakingKeeper multistakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper

// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
Expand Down Expand Up @@ -289,6 +299,8 @@ func New(
assetmoduletypes.StoreKey,
// ethermint keys
evmtypes.StoreKey, feemarkettypes.StoreKey,
// multi-staking keys
multistakingtypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)

Expand Down Expand Up @@ -376,6 +388,15 @@ func New(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

// multi-staking keeper
app.MultiStakingKeeper = *multistakingkeeper.NewKeeper(
appCodec,
app.AccountKeeper,
app.StakingKeeper,
app.BankKeeper,
keys[multistakingtypes.StoreKey],
)

// realio keeper
app.AssetKeeper = *assetmodulekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -460,7 +481,7 @@ func New(
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
multistaking.NewAppModule(appCodec, app.MultiStakingKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
Expand Down Expand Up @@ -494,7 +515,7 @@ func New(
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
multistakingtypes.ModuleName,
ibchost.ModuleName,
// no-op modules
ibctransfertypes.ModuleName,
Expand All @@ -516,7 +537,7 @@ func New(
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
multistakingtypes.ModuleName,
evmtypes.ModuleName,
feemarkettypes.ModuleName,
// no-op modules
Expand Down Expand Up @@ -550,7 +571,7 @@ func New(
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
multistakingtypes.ModuleName,
vestingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
Expand Down Expand Up @@ -635,7 +656,7 @@ func New(

app.SetAnteHandler(ante.NewAnteHandler(options))

app.setupUpgradeHandlers()
app.setupUpgradeHandlers(appOpts)

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -851,36 +872,3 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

func (app *RealioNetwork) setupUpgradeHandlers() {
//// "v0.7.2" is a coordinated upgrade on testnet to upgrade sdk to v0.46.7
// planName := "v0.0.0"
// app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
//
// return app.mm.RunMigrations(ctx, app.configurator, fromVM)
// })
//
////// When a planned update height is reached, the old binary will panic
////// writing on disk the height and name of the update that triggered it
////// This will read that value, and execute the preparations for the upgrade.
// upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
// if err != nil {
// panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
//}
//
// if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// return
//}
//
// var storeUpgrades *storetypes.StoreUpgrades
//
// switch upgradeInfo.Name {
// case planName:
// // no store upgrades here
//}
//
// if storeUpgrades != nil {
// // configure store loader that checks if version == upgradeHeight and applies store upgrades
// app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
//}
}
114 changes: 81 additions & 33 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
multistakingtypes "github.com/realio-tech/multi-staking-module/x/multi-staking/types"

"github.com/evmos/ethermint/encoding"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
Expand All @@ -40,22 +41,34 @@

// DefaultConsensusParams defines the default Tendermint consensus params used in
// Evmos testing.
var DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: -1, // no limit
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
var (
DefaultConsensusParams = &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: 200000,
MaxGas: -1, // no limit
},
},
}
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: 302400,
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration
MaxBytes: 10000,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: []string{
tmtypes.ABCIPubKeyTypeEd25519,
},
},
}
MultiStakingCoinA = multistakingtypes.MultiStakingCoin{
Denom: "ario",
Amount: sdk.NewIntFromUint64(1000000000000000000),
BondWeight: sdk.MustNewDecFromStr("1.23"),
}
MultiStakingCoinB = multistakingtypes.MultiStakingCoin{
Denom: "arst",
Amount: sdk.NewIntFromUint64(1000000000000000000),
BondWeight: sdk.MustNewDecFromStr("0.12"),
}
)

func init() {
feemarkettypes.DefaultMinGasPrice = sdk.ZeroDec()
Expand Down Expand Up @@ -128,58 +141,93 @@
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

// set multi staking genesis state
msCoinAInfo := multistakingtypes.MultiStakingCoinInfo{
Denom: MultiStakingCoinA.Denom,
BondWeight: MultiStakingCoinA.BondWeight,
}
msCoinBInfo := multistakingtypes.MultiStakingCoinInfo{
Denom: MultiStakingCoinB.Denom,
BondWeight: MultiStakingCoinB.BondWeight,
}
msCoinInfos := []multistakingtypes.MultiStakingCoinInfo{msCoinAInfo, msCoinBInfo}
validatorMsCoins := make([]multistakingtypes.ValidatorMultiStakingCoin, 0, len(valSet.Validators))
locks := make([]multistakingtypes.MultiStakingLock, 0, len(valSet.Validators))
lockCoins := sdk.NewCoins()

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))
bondCoins := sdk.NewCoins()

for i, val := range valSet.Validators {
valMsCoin := MultiStakingCoinA
if i%2 == 1 {
valMsCoin = MultiStakingCoinB
}

validatorMsCoins = append(validatorMsCoins, multistakingtypes.ValidatorMultiStakingCoin{
ValAddr: sdk.ValAddress(val.Address).String(),
CoinDenom: valMsCoin.Denom,
})

lockId := multistakingtypes.MultiStakingLockID(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String())

Check warning on line 173 in app/test_helpers.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var lockId should be lockID (revive)
lockRecord := multistakingtypes.NewMultiStakingLock(lockId, valMsCoin)

bondAmt := sdk.DefaultPowerReduction
locks = append(locks, lockRecord)
lockCoins = lockCoins.Add(valMsCoin.ToCoin())

for _, val := range valSet.Validators {
pk, _ := cryptocodec.FromTmPubKeyInterface(val.PubKey)
pkAny, _ := codectypes.NewAnyWithValue(pk)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
Tokens: valMsCoin.BondValue(),
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
}

validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))

bondCoins = bondCoins.Add(sdk.NewCoin(sdk.DefaultBondDenom, valMsCoin.BondValue()))
}
// set validators and delegations
stakingparams := stakingtypes.DefaultParams()
stakingparams.BondDenom = types.BaseDenom
stakingGenesis := stakingtypes.NewGenesisState(stakingparams, validators, delegations)
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations)

multistakingGenesis := multistakingtypes.GenesisState{
MultiStakingLocks: locks,
MultiStakingUnlocks: []multistakingtypes.MultiStakingUnlock{},
MultiStakingCoinInfo: msCoinInfos,
ValidatorMultiStakingCoins: validatorMsCoins,
StakingGenesisState: *stakingGenesis,
}
genesisState[multistakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(&multistakingGenesis)

// set mint genesis
mintGenesis := minttypes.DefaultGenesisState()
genesisState[minttypes.ModuleName] = app.AppCodec().MustMarshalJSON(mintGenesis)

balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: bondCoins,
})
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(multistakingtypes.ModuleName).String(),
Coins: lockCoins,
})

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(types.BaseDenom, bondAmt))
}

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(types.BaseDenom, bondAmt)},
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)
Expand Down
Loading
Loading