Skip to content

Commit

Permalink
feat: export community pool (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Nov 3, 2023
1 parent f0dc51f commit 8641019
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app/upgrades/v6/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/ethereum/go-ethereum/common"

"github.com/functionx/fx-core/v6/app/keepers"
crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper"
govtypes "github.com/functionx/fx-core/v6/x/gov/types"
fxgovtypes "github.com/functionx/fx-core/v6/x/gov/types"
layer2types "github.com/functionx/fx-core/v6/x/layer2/types"
migratekeeper "github.com/functionx/fx-core/v6/x/migrate/keeper"
fxstakingkeeper "github.com/functionx/fx-core/v6/x/staking/keeper"
Expand All @@ -33,6 +36,7 @@ func CreateUpgradeHandler(

MigrateMetadata(cacheCtx, app.BankKeeper)
MigrateLayer2Module(cacheCtx, app.Layer2Keeper)
ExportCommunityPool(cacheCtx, app.DistrKeeper, app.BankKeeper)

ctx.Logger().Info("start to run v6 migrations...", "module", "upgrade")
toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM)
Expand Down Expand Up @@ -77,7 +81,7 @@ func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error {
govTallyParams.VetoThreshold = sdk.OneDec().String() // 100%
app.GovKeeper.SetTallyParams(cacheCtx, govTallyParams)

app.GovKeeper.IterateParams(cacheCtx, func(param *govtypes.Params) (stop bool) {
app.GovKeeper.IterateParams(cacheCtx, func(param *fxgovtypes.Params) (stop bool) {
param.Quorum = sdk.OneDec().String() // 100%
param.Threshold = sdk.OneDec().String() // 100%
param.VetoThreshold = sdk.OneDec().String() // 100%
Expand All @@ -92,6 +96,22 @@ func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error {
return nil
}

func ExportCommunityPool(ctx sdk.Context, distrKeeper distrkeeper.Keeper, bankKeeper bankkeeper.Keeper) sdk.Coins {
feePool := distrKeeper.GetFeePool(ctx)
truncatedCoins, changeCoins := feePool.CommunityPool.TruncateDecimal()
feePool.CommunityPool = changeCoins
distrKeeper.SetFeePool(ctx, feePool)

if err := bankKeeper.SendCoinsFromModuleToModule(ctx, distrtypes.ModuleName, govtypes.ModuleName, truncatedCoins); err != nil {
panic(err)
}
if err := bankKeeper.BurnCoins(ctx, govtypes.ModuleName, truncatedCoins); err != nil {
panic(err)
}
ctx.Logger().Info("export community pool", "coins", truncatedCoins.String())
return truncatedCoins
}

func MigrateMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) {
bankKeeper.IterateAllDenomMetaData(ctx, func(metadata banktypes.Metadata) bool {
address, ok := Layer2GenesisTokenAddress[metadata.Symbol]
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v6/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (s *UpgradeTestSuite) TestUpdateParams() {
s.CommitBlock(10)
}

func (s *UpgradeTestSuite) TestExportCommunityPool() {
s.CommitBlock(10)
communityPool := v6.ExportCommunityPool(s.ctx, s.app.DistrKeeper, s.app.BankKeeper)
s.True(communityPool.IsAllPositive())
}

func (s *UpgradeTestSuite) TestMigrateMetadata() {
for symbol := range v6.Layer2GenesisTokenAddress {
hasDenomMetaData := s.app.BankKeeper.HasDenomMetaData(s.ctx, strings.ToLower(symbol))
Expand Down

0 comments on commit 8641019

Please sign in to comment.