Skip to content

Commit

Permalink
Merge pull request #181 from DongLieu/dong/v2.0.1
Browse files Browse the repository at this point in the history
Dong/v2.0.1
  • Loading branch information
vuong177 authored Oct 23, 2024
2 parents a0901db + 14d5a26 commit c13b49a
Show file tree
Hide file tree
Showing 57 changed files with 61 additions and 7,827 deletions.
6 changes: 6 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import (
"github.com/onomyprotocol/onomy/app/upgrades"
v1_1_6 "github.com/onomyprotocol/onomy/app/upgrades/v1.1.6"
v2_0_0 "github.com/onomyprotocol/onomy/app/upgrades/v2.0.0"
v2_0_1 "github.com/onomyprotocol/onomy/app/upgrades/v2.0.1"
"github.com/onomyprotocol/onomy/docs"
)

Expand Down Expand Up @@ -460,6 +461,7 @@ func (app *OnomyApp) SimulationManager() *module.SimulationManager {
func (app *OnomyApp) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(v1_1_6.Name, v1_1_6.UpgradeHandler)
app.UpgradeKeeper.SetUpgradeHandler(v2_0_0.Name, v2_0_0.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers))
app.UpgradeKeeper.SetUpgradeHandler(v2_0_1.Name, v2_0_1.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers))

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
Expand All @@ -478,6 +480,10 @@ func (app *OnomyApp) setupUpgradeHandlers() {
storeUpgrades = &storetypes.StoreUpgrades{
Deleted: []string{"provider"},
}
case v2_0_1.Name:
storeUpgrades = &storetypes.StoreUpgrades{
Deleted: []string{"dao"},
}
default:
// no store upgrades.
}
Expand Down
37 changes: 6 additions & 31 deletions app/keepers/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ import (
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

"github.com/onomyprotocol/onomy/x/dao"
daokeeper "github.com/onomyprotocol/onomy/x/dao/keeper"
daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)

type AppKeepers struct {
Expand Down Expand Up @@ -93,8 +89,6 @@ type AppKeepers struct {

// Modules.
TransferModule transfer.AppModule

DaoKeeper daokeeper.Keeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -237,11 +231,6 @@ func NewAppKeeper(
)

// protect the dao module form the slashing.
appKeepers.StakingKeeper = appKeepers.StakingKeeper.SetSlashingProtestedModules(func() map[string]struct{} {
return map[string]struct{}{
daotypes.ModuleName: {},
}
})
// UpgradeKeeper must be created before IBCKeeper.
appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper(
skipUpgradeHeights,
Expand Down Expand Up @@ -291,12 +280,6 @@ func NewAppKeeper(
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
ibcmodule := transfer.NewIBCModule(appKeepers.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it.
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
appKeepers.IBCKeeper.SetRouter(ibcRouter)
// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
Expand All @@ -305,7 +288,6 @@ func NewAppKeeper(
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(daotypes.RouterKey, dao.NewProposalHandler(appKeepers.DaoKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))

// Set legacy router for backwards compatibility with gov v1beta1.
Expand Down Expand Up @@ -337,18 +319,12 @@ func NewAppKeeper(

appKeepers.TransferModule = transfer.NewAppModule(appKeepers.TransferKeeper)

appKeepers.DaoKeeper = *daokeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[daotypes.StoreKey]),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appKeepers.GetSubspace(daotypes.ModuleName),
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
appKeepers.DistrKeeper,
appKeepers.GovKeeper,
appKeepers.MintKeeper,
appKeepers.StakingKeeper,
)
ibcmodule := transfer.NewIBCModule(appKeepers.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it.
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
appKeepers.IBCKeeper.SetRouter(ibcRouter)

return appKeepers
}
Expand Down Expand Up @@ -379,7 +355,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) //nolint: staticcheck // SA1019
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(daotypes.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 0 additions & 3 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -43,7 +41,6 @@ func (appKeepers *AppKeepers) GenerateKeys() {
capabilitytypes.StoreKey,
feegrant.StoreKey,
authzkeeper.StoreKey,
daotypes.StoreKey,
consensusparamtypes.StoreKey,
)

Expand Down
12 changes: 0 additions & 12 deletions app/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ import (
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/onomyprotocol/onomy/x/dao"
daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)

var (
// module account permissions.
maccPerms = map[string][]string{ //nolint:gochecknoglobals // cosmos-sdk application style
authtypes.FeeCollectorName: nil,
daotypes.ModuleName: {authtypes.Minter},
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
Expand All @@ -66,7 +62,6 @@ var (
// module accounts that are allowed to receive tokens.
allowedReceivingModAcc = map[string]bool{ //nolint:gochecknoglobals // cosmos-sdk application style
distrtypes.ModuleName: true,
daotypes.ModuleName: true,
authtypes.FeeCollectorName: true,
}
)
Expand All @@ -81,7 +76,6 @@ func appModules(
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
dao.NewAppModule(appCodec, app.DaoKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
Expand Down Expand Up @@ -111,8 +105,6 @@ func newBasicManagerFromManager(app *OnomyApp) module.BasicManager {
govtypes.ModuleName: gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
dao.FundTreasuryProposalHandler,
dao.ExchangeWithTreasuryProposalProposalHandler,
},
),
})
Expand Down Expand Up @@ -141,7 +133,6 @@ func orderBeginBlockers() []string {
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
daotypes.ModuleName,
}
}

Expand All @@ -166,7 +157,6 @@ func orderEndBlockers() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
daotypes.ModuleName,
}
}

Expand All @@ -191,7 +181,6 @@ func orderInitBlockers() []string {
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
crisistypes.ModuleName,
daotypes.ModuleName,
}
}

Expand All @@ -203,7 +192,6 @@ func simulationModules(
return []module.AppModuleSimulation{
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
dao.NewAppModule(appCodec, app.DaoKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
Expand Down
8 changes: 0 additions & 8 deletions app/upgrades/v1.1.5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

daotypes "github.com/onomyprotocol/onomy/x/dao/types"
)

// Name is migration name.
Expand Down Expand Up @@ -80,12 +78,6 @@ func CreateUpgradeHandler(
// send to dao module account
// vesting account should be able to send coins normally after
// we converted it back to a base account.
bal := bk.GetAllBalances(ctx, sdk.MustAccAddressFromBech32(addr))
err = bk.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32(addr), daotypes.ModuleName, bal)
if err != nil {
sdkCtx.Logger().Error("Error reallocating funds")
return nil, err
}
}
sdkCtx.Logger().Info("Finished reallocating funds")

Expand Down
42 changes: 42 additions & 0 deletions app/upgrades/v2.0.1/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Package v1_1_4 is contains chain upgrade of the corresponding version.
package v2_0_1 //nolint:revive,stylecheck // app version

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/onomyprotocol/onomy/app/keepers"
)

// Name is migration name.
const Name = "v2.1.0"

// UpgradeHandler is an x/upgrade handler.
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {

return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)
baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).
WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper.ParamsStore)

// onomy1vwr8z00ty7mqnk4dtchr9mn9j96nuh6wrlww93
addrTreasury := sdk.MustAccAddressFromBech32("onomy1vwr8z00ty7mqnk4dtchr9mn9j96nuh6wrlww93")
treasuryTokens := keepers.BankKeeper.GetAllBalances(ctx, addrTreasury)
err := keepers.DistrKeeper.FundCommunityPool(ctx, treasuryTokens, addrTreasury)
if err != nil {
return vm, err
}

return vm, nil
}
}
Loading

0 comments on commit c13b49a

Please sign in to comment.