Skip to content

Commit

Permalink
[OTE-829] upgrade handler for affiliates (#2332)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6f9ede5)

# Conflicts:
#	protocol/app/upgrades/v7.0.0/upgrade_container_test.go
  • Loading branch information
affanv14 authored and mergify[bot] committed Sep 26, 2024
1 parent d0d22fa commit 5b85178
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
23 changes: 22 additions & 1 deletion protocol/app/testdata/default_genesis_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@
},
"affiliates": {
"affiliate_tiers": {
"tiers": []
"tiers": [
{
"req_referred_volume_quote_quantums": "0",
"req_staked_whole_coins": 0,
"taker_fee_share_ppm": 50000
},
{
"req_referred_volume_quote_quantums": "1000000000000",
"req_staked_whole_coins": 200,
"taker_fee_share_ppm": 100000
},
{
"req_referred_volume_quote_quantums": "5000000000000",
"req_staked_whole_coins": 1000,
"taker_fee_share_ppm": 125000
},
{
"req_referred_volume_quote_quantums": "25000000000000",
"req_staked_whole_coins": 5000,
"taker_fee_share_ppm": 150000
}
]
}
},
"auth": {
Expand Down
23 changes: 23 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 @@ -12,6 +12,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 @@ -49,7 +50,13 @@ 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)
<<<<<<< HEAD
postUpgradeMegavaultSharesCheck(node, t)
=======

// Check that the affiliates module has been initialized with the default tiers.
postUpgradeAffiliatesModuleTiersCheck(node, t)
>>>>>>> 6f9ede54 ([OTE-829] upgrade handler for affiliates (#2332))
}

func postUpgradeVaultParamsCheck(node *containertest.Node, t *testing.T) {
Expand Down Expand Up @@ -99,6 +106,7 @@ func checkVaultParams(
require.Equal(t, expectedQuotingParams, vaultParamsResp.VaultParams.QuotingParams)
}

<<<<<<< HEAD
func postUpgradeMegavaultSharesCheck(node *containertest.Node, t *testing.T) {
// Alice equity = vault_0_equity * 1 + vault_1_equity * 1/3 + vault_2_equity * 123_456/556_677
// = 1_000 + 2_000 * 1/3 + 3_000 * 123_456/556_677
Expand All @@ -124,10 +132,19 @@ func postUpgradeMegavaultSharesCheck(node *containertest.Node, t *testing.T) {
vaulttypes.NewQueryClient,
vaulttypes.QueryClient.MegavaultTotalShares,
&vaulttypes.QueryMegavaultTotalSharesRequest{},
=======
func postUpgradeAffiliatesModuleTiersCheck(node *containertest.Node, t *testing.T) {
resp, err := containertest.Query(
node,
affiliatestypes.NewQueryClient,
affiliatestypes.QueryClient.AllAffiliateTiers,
&affiliatestypes.AllAffiliateTiersRequest{},
>>>>>>> 6f9ede54 ([OTE-829] upgrade handler for affiliates (#2332))
)
require.NoError(t, err)
require.NotNil(t, resp)

<<<<<<< HEAD
totalSharesResp := vaulttypes.QueryMegavaultTotalSharesResponse{}
err = proto.UnmarshalText(resp.String(), &totalSharesResp)
require.NoError(t, err)
Expand Down Expand Up @@ -161,4 +178,10 @@ func postUpgradeMegavaultSharesCheck(node *containertest.Node, t *testing.T) {
require.Contains(t, gotOwnerShares, owner)
require.Equal(t, expectedShares, gotOwnerShares[owner])
}
=======
affiliateTiersResp := affiliatestypes.AllAffiliateTiersResponse{}
err = proto.UnmarshalText(resp.String(), &affiliateTiersResp)
require.NoError(t, err)
require.Equal(t, affiliatestypes.DefaultAffiliateTiers, affiliateTiersResp.Tiers)
>>>>>>> 6f9ede54 ([OTE-829] upgrade handler for affiliates (#2332))
}
25 changes: 23 additions & 2 deletions protocol/scripts/genesis/sample_pregenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@
"app_state": {
"affiliates": {
"affiliate_tiers": {
"tiers": []
"tiers": [
{
"req_referred_volume_quote_quantums": "0",
"req_staked_whole_coins": 0,
"taker_fee_share_ppm": 50000
},
{
"req_referred_volume_quote_quantums": "1000000000000",
"req_staked_whole_coins": 200,
"taker_fee_share_ppm": 100000
},
{
"req_referred_volume_quote_quantums": "5000000000000",
"req_staked_whole_coins": 1000,
"taker_fee_share_ppm": 125000
},
{
"req_referred_volume_quote_quantums": "25000000000000",
"req_staked_whole_coins": 5000,
"taker_fee_share_ppm": 150000
}
]
}
},
"assets": {
Expand Down Expand Up @@ -3995,7 +4016,7 @@
]
}
},
"app_version": "5.2.1-103-g5c95dd72",
"app_version": "5.2.1-172-g351fcccd",
"chain_id": "dydx-sample-1",
"consensus": {
"params": {
Expand Down
4 changes: 1 addition & 3 deletions protocol/x/affiliates/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package types
// DefaultGenesis returns the default stats genesis state.
func DefaultGenesis() *GenesisState {
return &GenesisState{
AffiliateTiers: AffiliateTiers{
Tiers: []AffiliateTiers_Tier{},
},
AffiliateTiers: DefaultAffiliateTiers,
}
}

Expand Down

0 comments on commit 5b85178

Please sign in to comment.