diff --git a/protocol/app/upgrades.go b/protocol/app/upgrades.go index 3103802ac6..8c16de0aab 100644 --- a/protocol/app/upgrades.go +++ b/protocol/app/upgrades.go @@ -33,6 +33,7 @@ func (app *App) setupUpgradeHandlers() { app.AccountKeeper, app.PricesKeeper, app.VaultKeeper, + app.ListingKeeper, ), ) } diff --git a/protocol/app/upgrades/v7.0.0/upgrade.go b/protocol/app/upgrades/v7.0.0/upgrade.go index afc87cfada..e0543670b9 100644 --- a/protocol/app/upgrades/v7.0.0/upgrade.go +++ b/protocol/app/upgrades/v7.0.0/upgrade.go @@ -5,6 +5,8 @@ import ( "fmt" "math/big" + listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -12,6 +14,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/lib/slinky" + listingkeeper "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" vaultkeeper "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" @@ -194,12 +197,30 @@ func migrateVaultSharesToMegavaultShares(ctx sdk.Context, k vaultkeeper.Keeper) ctx.Logger().Info("Successfully migrated vault shares to megavault shares") } +func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) { + // Set hard cap on listed markets + err := listingKeeper.SetMarketsHardCap(ctx, listingtypes.DefaultMarketsHardCap) + if err != nil { + panic(fmt.Sprintf("failed to set markets hard cap: %s", err)) + } + + // Set listing vault deposit params + err = listingKeeper.SetListingVaultDepositParams( + ctx, + listingtypes.DefaultParams(), + ) + if err != nil { + panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err)) + } +} + func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, accountKeeper authkeeper.AccountKeeper, pricesKeeper pricestypes.PricesKeeper, vaultKeeper vaultkeeper.Keeper, + listingKeeper listingkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades") @@ -217,6 +238,9 @@ func CreateUpgradeHandler( // Migrate vault shares to megavault shares. migrateVaultSharesToMegavaultShares(sdkCtx, vaultKeeper) + // Initialize listing module state. + initListingModuleState(sdkCtx, listingKeeper) + return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/protocol/app/upgrades/v7.0.0/upgrade_container_test.go b/protocol/app/upgrades/v7.0.0/upgrade_container_test.go index 60ad046b37..52e454bdc5 100644 --- a/protocol/app/upgrades/v7.0.0/upgrade_container_test.go +++ b/protocol/app/upgrades/v7.0.0/upgrade_container_test.go @@ -6,6 +6,8 @@ import ( "math/big" "testing" + listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" + "github.com/cosmos/gogoproto/proto" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -58,6 +60,9 @@ func postUpgradeChecks(node *containertest.Node, t *testing.T) { // Check that the affiliates module has been initialized with the default tiers. postUpgradeAffiliatesModuleTiersCheck(node, t) + + // Check that the listing module state has been initialized with the hard cap and default deposit params. + postUpgradeListingModuleStateCheck(node, t) } func postUpgradeVaultParamsCheck(node *containertest.Node, t *testing.T) { @@ -202,3 +207,34 @@ func postUpgradeMegavaultModuleAccCheck(node *containertest.Node, t *testing.T) err = proto.UnmarshalText(resp.String(), &moduleAccResp) require.NoError(t, err) } + +func postUpgradeListingModuleStateCheck(node *containertest.Node, t *testing.T) { + // Check that the listing module state has been initialized with the hard cap and default deposit params. + resp, err := containertest.Query( + node, + listingtypes.NewQueryClient, + listingtypes.QueryClient.ListingVaultDepositParams, + &listingtypes.QueryListingVaultDepositParams{}, + ) + require.NoError(t, err) + require.NotNil(t, resp) + + listingVaultDepositParamsResp := listingtypes.QueryListingVaultDepositParamsResponse{} + err = proto.UnmarshalText(resp.String(), &listingVaultDepositParamsResp) + require.NoError(t, err) + require.Equal(t, listingtypes.DefaultParams(), listingVaultDepositParamsResp.Params) + + resp, err = containertest.Query( + node, + listingtypes.NewQueryClient, + listingtypes.QueryClient.MarketsHardCap, + &listingtypes.QueryMarketsHardCap{}, + ) + require.NoError(t, err) + require.NotNil(t, resp) + + marketsHardCapResp := listingtypes.QueryMarketsHardCapResponse{} + err = proto.UnmarshalText(resp.String(), &marketsHardCapResp) + require.NoError(t, err) + require.Equal(t, uint32(500), marketsHardCapResp.HardCap) +} diff --git a/protocol/x/listing/types/constants.go b/protocol/x/listing/types/constants.go index b428add511..b473f78360 100644 --- a/protocol/x/listing/types/constants.go +++ b/protocol/x/listing/types/constants.go @@ -14,4 +14,6 @@ const ( DefaultQuantumConversionExponent = -9 ResolutionOffset = -6 + + DefaultMarketsHardCap = 500 )