Skip to content

Commit

Permalink
[TRA-654] add listing module state init into v7 upgrade handler (#2432)
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <[email protected]>
(cherry picked from commit 922a9b5)
  • Loading branch information
shrenujb authored and mergify[bot] committed Oct 3, 2024
1 parent 8e46636 commit 3d80cad
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (app *App) setupUpgradeHandlers() {
app.AccountKeeper,
app.PricesKeeper,
app.VaultKeeper,
app.ListingKeeper,
),
)
}
Expand Down
24 changes: 24 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
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"
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
}
36 changes: 36 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions protocol/x/listing/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ const (
DefaultQuantumConversionExponent = -9

ResolutionOffset = -6

DefaultMarketsHardCap = 500
)

0 comments on commit 3d80cad

Please sign in to comment.