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

[OTE-829] upgrade handler for affiliates #2332

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (app *App) setupUpgradeHandlers() {
app.configurator,
app.PricesKeeper,
app.VaultKeeper,
app.AffiliatesKeeper,
),
)
}
Expand Down
10 changes: 10 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/lib/slinky"
affiliateskeeper "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/keeper"
affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
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 @@ -55,11 +57,16 @@ func migrateVaultQuotingParamsToVaultParams(ctx sdk.Context, k vaultkeeper.Keepe
}
}

func setDefaultTiersForAffiliates(ctx sdk.Context, k affiliateskeeper.Keeper) {
k.UpdateAffiliateTiers(ctx, affiliatetypes.DefaultAffiliateTiers)
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
pricesKeeper pricestypes.PricesKeeper,
vaultKeeper vaultkeeper.Keeper,
affiliatesKeeper affiliateskeeper.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 @@ -71,6 +78,9 @@ func CreateUpgradeHandler(
// Migrate vault quoting params to vault params.
migrateVaultQuotingParamsToVaultParams(sdkCtx, vaultKeeper)

// Set default tiers for affiliates.
setDefaultTiersForAffiliates(sdkCtx, affiliatesKeeper)

return mm.RunMigrations(ctx, configurator, vm)
}
}
21 changes: 21 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 @@ -11,6 +11,7 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/testing/containertest"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
affiliatestypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -48,6 +49,9 @@ func preUpgradeChecks(node *containertest.Node, t *testing.T) {
func postUpgradeChecks(node *containertest.Node, t *testing.T) {
// Add test for your upgrade handler logic below
postUpgradeVaultParamsCheck(node, t)

// Check that the affiliates module has been initialized with the default tiers.
postUpgradeAffiliatesModuleTiersCheck(node, t)
}

func postUpgradeVaultParamsCheck(node *containertest.Node, t *testing.T) {
Expand Down Expand Up @@ -96,3 +100,20 @@ func checkVaultParams(
require.Equal(t, expectedStatus, vaultParamsResp.VaultParams.Status)
require.Equal(t, expectedQuotingParams, vaultParamsResp.VaultParams.QuotingParams)
}

func postUpgradeAffiliatesModuleTiersCheck(node *containertest.Node, t *testing.T) {

resp, err := containertest.Query(
node,
affiliatestypes.NewQueryClient,
affiliatestypes.QueryClient.AllAffiliateTiers,
&affiliatestypes.AllAffiliateTiersRequest{},
)
require.NoError(t, err)
require.NotNil(t, resp)

affiliateTiersResp := affiliatestypes.AllAffiliateTiersResponse{}
err = proto.UnmarshalText(resp.String(), &affiliateTiersResp)
require.NoError(t, err)
require.Equal(t, affiliatestypes.DefaultAffiliateTiers, affiliateTiersResp.Tiers)
}
Loading