Skip to content

Commit

Permalink
Merge pull request #363 from BitCannaGlobal/v3.1.0
Browse files Browse the repository at this point in the history
V3.1.0 - Burn module
  • Loading branch information
RaulBernal authored May 6, 2024
2 parents b6bce9b + f75e840 commit be10f9e
Show file tree
Hide file tree
Showing 81 changed files with 13,864 additions and 577 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
config.yml
.DS_Store
ts-client/*
release/*

25 changes: 23 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
Expand Down Expand Up @@ -119,6 +118,9 @@ import (
bcnamodule "github.com/BitCannaGlobal/bcna/x/bcna"
bcnamodulekeeper "github.com/BitCannaGlobal/bcna/x/bcna/keeper"
bcnamoduletypes "github.com/BitCannaGlobal/bcna/x/bcna/types"
burnmodule "github.com/BitCannaGlobal/bcna/x/burn"
burnmodulekeeper "github.com/BitCannaGlobal/bcna/x/burn/keeper"
burnmoduletypes "github.com/BitCannaGlobal/bcna/x/burn/types"

appparams "github.com/BitCannaGlobal/bcna/app/params"
"github.com/BitCannaGlobal/bcna/docs"
Expand Down Expand Up @@ -176,6 +178,7 @@ var (
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
bcnamodule.AppModuleBasic{},
burnmodule.AppModuleBasic{},
)

// module account permissions
Expand All @@ -188,6 +191,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
burnmoduletypes.ModuleName: {authtypes.Burner},
// nft.ModuleName: nil,
}
)
Expand Down Expand Up @@ -253,6 +257,7 @@ type App struct {

// Custom module keepers
BcnaKeeper bcnamodulekeeper.Keeper
BurnKeeper burnmodulekeeper.Keeper

// mm is the module manager
mm *module.Manager
Expand Down Expand Up @@ -315,6 +320,7 @@ func New(
// nftkeeper.StoreKey,
consensusparamtypes.StoreKey,
bcnamoduletypes.StoreKey,
burnmoduletypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -568,6 +574,16 @@ func New(
)
bcnaModule := bcnamodule.NewAppModule(appCodec, app.BcnaKeeper, app.AccountKeeper, app.BankKeeper)

app.BurnKeeper = *burnmodulekeeper.NewKeeper(
appCodec,
keys[burnmoduletypes.StoreKey],
keys[burnmoduletypes.MemStoreKey],
app.GetSubspace(burnmoduletypes.ModuleName),

app.BankKeeper,
)
burnModule := burnmodule.NewAppModule(appCodec, app.BurnKeeper, app.AccountKeeper, app.BankKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
Expand Down Expand Up @@ -625,6 +641,7 @@ func New(
icaModule,
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
bcnaModule,
burnModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -656,6 +673,7 @@ func New(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
bcnamoduletypes.ModuleName,
burnmoduletypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -682,6 +700,7 @@ func New(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
bcnamoduletypes.ModuleName,
burnmoduletypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -713,6 +732,7 @@ func New(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
bcnamoduletypes.ModuleName,
burnmoduletypes.ModuleName,
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
app.mm.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -935,13 +955,14 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(govtypes.ModuleName) //.WithKeyTable(govv1.ParamKeyTable()) //nolint: staticcheck // SA1019 //https://github.com/cosmos/cosmos-sdk/discussions/19832
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(bcnamoduletypes.ModuleName)
paramsKeeper.Subspace(burnmoduletypes.ModuleName)
// paramsKeeper.Subspace(nft.ModuleName)

return paramsKeeper
Expand Down
155 changes: 25 additions & 130 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,13 @@ package app
import (
"fmt"

burnmoduletypes "github.com/BitCannaGlobal/bcna/x/burn/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

// v047 migration
"github.com/cosmos/cosmos-sdk/baseapp"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

bcnamoduletypes "github.com/BitCannaGlobal/bcna/x/bcna/types"

icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

// "github.com/cosmos/cosmos-sdk/x/nft"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
)

var keyTableAssigned = false

// RegisterUpgradeHandlers registers upgrade handlers.

func (app App) RegisterUpgradeHandlers() {
Expand All @@ -44,98 +18,16 @@ func (app App) RegisterUpgradeHandlers() {
panic(err)
}

app.GanjaRevolution47(upgradeInfo)
app.GanjaRevolution47_burn(upgradeInfo)

}

func (app *App) GanjaRevolution47(_ upgradetypes.Plan) {
planName := "GanjaRevolution"
// Set param key table for params module migration
for _, subspace := range app.ParamsKeeper.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable

switch subspace.Name() {
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true

// ibc types
case ibcexported.ModuleName:
keyTable = icacontrollertypes.ParamKeyTable()
keyTableAssigned = true
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable()
keyTableAssigned = true
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable()
keyTableAssigned = true
case icacontrollertypes.SubModuleName:
keyTable = icacontrollertypes.ParamKeyTable()
keyTableAssigned = true

// Bitcanna types
case bcnamoduletypes.ModuleName:
keyTable = bcnamoduletypes.ParamKeyTable() //nolint:staticcheck
keyTableAssigned = true

// Debug:
default:
fmt.Println("No matching subspace found:", subspace.Name())
keyTableAssigned = false
}

if !subspace.HasKeyTable() {
if !keyTableAssigned {
fmt.Println("KeyTable is not assigned for subspace:", subspace.Name())
} else {
subspace.WithKeyTable(keyTable)
}
}
}

func (app *App) GanjaRevolution47_burn(_ upgradetypes.Plan) {
planName := "ganjarevolutionburn"
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("start to run module migrations...")
ctx.Logger().Info("start to run module migrations...adding x/burn module...")
logger := ctx.Logger().With("upgrade", planName)

// Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module.
baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.ConsensusParamsKeeper)

// ibc/go v7.0 migration
// OPTIONAL: prune expired tendermint consensus states to save storage space
if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.appCodec, app.IBCKeeper.ClientKeeper); err != nil {
return nil, err
}

// https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v7-to-v7_1.md
// explicitly update the IBC 02-client params, adding the localhost client type
params := app.IBCKeeper.ClientKeeper.GetParams(ctx)
params.AllowedClients = append(params.AllowedClients, ibcexported.Localhost)
app.IBCKeeper.ClientKeeper.SetParams(ctx, params)

// Run migrations
logger.Info(fmt.Sprintf("pre migrate version map: %v", fromVM))
versionMap, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
Expand All @@ -144,20 +36,26 @@ func (app *App) GanjaRevolution47(_ upgradetypes.Plan) {
}
logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap))

// Update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler
govParams := app.GovKeeper.GetParams(ctx)
govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String()
if err := app.GovKeeper.SetParams(ctx, govParams); err != nil {
return nil, err
}
// Inflation control mechanism
// Get the current params from Mint module
// mintParams := app.MintKeeper.GetParams(ctx)

// Update x/Staking - set minimum commission to 4,20% 0.042000000000000000
stakingParams := app.StakingKeeper.GetParams(ctx)
stakingParams.MinCommissionRate = sdk.NewDecWithPrec(420, 4)
err = app.StakingKeeper.SetParams(ctx, stakingParams)
if err != nil {
return nil, err
}
// // Log the params BEFORE apply the new values
// logger.Info(fmt.Sprintf("Current values for Mint value: InflationMax: %s, InflationMin: %s",
// mintParams.InflationMax.String(), mintParams.InflationMin.String()))

// // Set fixed values for InflationMax and InflationMin
// mintParams.InflationMin = sdk.NewDec(0) // 0%
// mintParams.InflationMax = sdk.NewDecWithPrec(7, 2) // 7%

// // Set the new values at Mint module
// if err := app.MintKeeper.SetParams(ctx, mintParams); err != nil {
// return nil, err
// }

// // Log the values after apply the changes
// logger.Info(fmt.Sprintf("New values for Mint value: InflationMax: %s, InflationMin: %s",
// mintParams.InflationMax.String(), mintParams.InflationMin.String()))

return versionMap, err
// return app.mm.RunMigrations(ctx, app.configurator, fromVM)
Expand All @@ -172,8 +70,7 @@ func (app *App) GanjaRevolution47(_ upgradetypes.Plan) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{

consensustypes.ModuleName,
crisistypes.ModuleName,
burnmoduletypes.ModuleName, // Create the Store for the new module: burn
// nft.ModuleName,
},
}
Expand All @@ -182,5 +79,3 @@ func (app *App) GanjaRevolution47(_ upgradetypes.Plan) {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// app.IBCKeeper.ClientKeeper
Loading

0 comments on commit be10f9e

Please sign in to comment.