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: export community pool #123

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading