Skip to content

Commit

Permalink
feat: add x/marketmap module (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Johnson authored Jul 16, 2024
1 parent ad43f46 commit 00c0627
Show file tree
Hide file tree
Showing 18 changed files with 1,354 additions and 176 deletions.
19 changes: 19 additions & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ import (
vestmodule "github.com/dydxprotocol/v4-chain/protocol/x/vest"
vestmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/vest/keeper"
vestmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/vest/types"
marketmapmodule "github.com/skip-mev/slinky/x/marketmap"
marketmapmodulekeeper "github.com/skip-mev/slinky/x/marketmap/keeper"
marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types"

// IBC
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
Expand Down Expand Up @@ -292,6 +295,8 @@ type App struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
GovPlusKeeper govplusmodulekeeper.Keeper

MarketMapKeeper marketmapmodulekeeper.Keeper

PricesKeeper pricesmodulekeeper.Keeper

AssetsKeeper assetsmodulekeeper.Keeper
Expand Down Expand Up @@ -436,6 +441,7 @@ func New(
govplusmoduletypes.StoreKey,
vaultmoduletypes.StoreKey,
revsharemoduletypes.StoreKey,
marketmapmoduletypes.StoreKey,
)
keys[authtypes.StoreKey] = keys[authtypes.StoreKey].WithLocking()
tkeys := storetypes.NewTransientStoreKeys(
Expand Down Expand Up @@ -898,6 +904,14 @@ func New(
)
revShareModule := revsharemodule.NewAppModule(appCodec, app.RevShareKeeper)

app.MarketMapKeeper = *marketmapmodulekeeper.NewKeeper(
runtime.NewKVStoreService(keys[marketmapmoduletypes.StoreKey]),
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName),
)

marketmapModule := marketmapmodule.NewAppModule(appCodec, &app.MarketMapKeeper)

app.PricesKeeper = *pricesmodulekeeper.NewKeeper(
appCodec,
keys[pricesmoduletypes.StoreKey],
Expand Down Expand Up @@ -1206,6 +1220,7 @@ func New(
vaultModule,
listingModule,
revShareModule,
marketmapModule,
)

app.ModuleManager.SetOrderPreBlockers(
Expand Down Expand Up @@ -1255,6 +1270,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
)

app.ModuleManager.SetOrderPrepareCheckStaters(
Expand Down Expand Up @@ -1300,6 +1316,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName, // No-op.
blocktimemoduletypes.ModuleName, // Must be last
)
Expand Down Expand Up @@ -1346,6 +1363,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,
)

Expand Down Expand Up @@ -1388,6 +1406,7 @@ func New(
vaultmoduletypes.ModuleName,
listingmoduletypes.ModuleName,
revsharemoduletypes.ModuleName,
marketmapmoduletypes.ModuleName,
authz.ModuleName,

// Auth must be migrated after staking.
Expand Down
4 changes: 4 additions & 0 deletions protocol/app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app_test

import (
marketmapmodule "github.com/skip-mev/slinky/x/marketmap"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -219,6 +220,9 @@ func TestModuleBasics(t *testing.T) {
vaultmodule.AppModuleBasic{},
listingmodule.AppModuleBasic{},
revsharemodule.AppModuleBasic{},

// slinky marketmap
marketmapmodule.AppModuleBasic{},
)

app := testapp.DefaultTestApp(nil)
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/basic_manager/basic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
subaccountsmodule "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts"
vaultmodule "github.com/dydxprotocol/v4-chain/protocol/x/vault"
vestmodule "github.com/dydxprotocol/v4-chain/protocol/x/vest"
marketmapmodule "github.com/skip-mev/slinky/x/marketmap"

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
Expand Down Expand Up @@ -97,5 +98,6 @@ var (
vaultmodule.AppModuleBasic{},
revsharemodule.AppModuleBasic{},
listingmodule.AppModuleBasic{},
marketmapmodule.AppModuleBasic{},
)
)
3 changes: 2 additions & 1 deletion protocol/app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package app_test

import (
"encoding/json"
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
"os"
"testing"

"github.com/stretchr/testify/require"

testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
)

func TestDefaultGenesisState(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions protocol/app/module_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
rewardsmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/rewards/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
vestmoduletypes "github.com/dydxprotocol/v4-chain/protocol/x/vest/types"
marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types"

"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -49,6 +50,8 @@ var (
vestmoduletypes.CommunityTreasuryAccountName: nil,
// community vester account vests funds into the community treasury.
vestmoduletypes.CommunityVesterAccountName: nil,
// Slinky marketmap module permissions.
marketmapmoduletypes.ModuleName: nil,
}
// Blocked module accounts which cannot receive external funds.
// By default, all non-custom modules (except for gov) are blocked. This prevents
Expand Down
7 changes: 6 additions & 1 deletion protocol/app/module_accounts_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app_test

import (
marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types"
"testing"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -34,9 +35,11 @@ func TestModuleAccountsToAddresses(t *testing.T) {
vestmoduletypes.CommunityTreasuryAccountName: "dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn",
vestmoduletypes.CommunityVesterAccountName: "dydx1wxje320an3karyc6mjw4zghs300dmrjkwn7xtk",
icatypes.ModuleName: "dydx1vlthgax23ca9syk7xgaz347xmf4nunefw3cnv8",
marketmapmoduletypes.ModuleName: "dydx16j3d86dww8p2rzdlqsv7wle98cxzjxw6gjjyzn",
}

require.True(t, len(expectedModuleAccToAddresses) == len(app.GetMaccPerms()))
require.True(t, len(expectedModuleAccToAddresses) == len(app.GetMaccPerms()),
"expected %d, got %d", len(expectedModuleAccToAddresses), len(app.GetMaccPerms()))
for acc, address := range expectedModuleAccToAddresses {
expectedAddr := authtypes.NewModuleAddress(acc).String()
require.Equal(t, address, expectedAddr, "module (%v) should have address (%s)", acc, expectedAddr)
Expand Down Expand Up @@ -72,6 +75,7 @@ func TestMaccPerms(t *testing.T) {
"rewards_vester": nil,
"community_treasury": nil,
"community_vester": nil,
"marketmap": nil,
}
require.Equal(t, expectedMaccPerms, maccPerms, "default macc perms list does not match expected")
}
Expand All @@ -92,6 +96,7 @@ func TestModuleAccountAddrs(t *testing.T) {
"dydx1ltyc6y4skclzafvpznpt2qjwmfwgsndp458rmp": true, // x/rewards.vester
"dydx15ztc7xy42tn2ukkc0qjthkucw9ac63pgp70urn": true, // x/vest.communityTreasury
"dydx1wxje320an3karyc6mjw4zghs300dmrjkwn7xtk": true, // x/vest.communityVester
"dydx16j3d86dww8p2rzdlqsv7wle98cxzjxw6gjjyzn": true, // x/marketmap
}

require.Equal(t, expectedModuleAccAddresses, app.ModuleAccountAddrs())
Expand Down
12 changes: 12 additions & 0 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ var (
"/ibc.applications.interchain_accounts.controller.v1.MsgUpdateParamsResponse": {},
"/ibc.applications.interchain_accounts.host.v1.MsgUpdateParams": {},
"/ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse": {},

// slinky marketmap messages
"/slinky.marketmap.v1.MsgCreateMarkets": {},
"/slinky.marketmap.v1.MsgCreateMarketsResponse": {},
"/slinky.marketmap.v1.MsgParams": {},
"/slinky.marketmap.v1.MsgParamsResponse": {},
"/slinky.marketmap.v1.MsgRemoveMarketAuthorities": {},
"/slinky.marketmap.v1.MsgRemoveMarketAuthoritiesResponse": {},
"/slinky.marketmap.v1.MsgUpdateMarkets": {},
"/slinky.marketmap.v1.MsgUpdateMarketsResponse": {},
"/slinky.marketmap.v1.MsgUpsertMarkets": {},
"/slinky.marketmap.v1.MsgUpsertMarketsResponse": {},
}

// DisallowMsgs are messages that cannot be externally submitted.
Expand Down
17 changes: 16 additions & 1 deletion protocol/app/msgs/normal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
clob "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
sending "github.com/dydxprotocol/v4-chain/protocol/x/sending/types"
vault "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
marketmapmoduletypes "github.com/skip-mev/slinky/x/marketmap/types"
)

var (
// NormalMsgs are messages that can be submitted by external users.
NormalMsgs = lib.MergeAllMapsMustHaveDistinctKeys(NormalMsgsDefault, NormalMsgsDydxCustom)
NormalMsgs = lib.MergeAllMapsMustHaveDistinctKeys(NormalMsgsDefault, NormalMsgsDydxCustom, NormalMsgsSlinky)

// Default modules
NormalMsgsDefault = map[string]sdk.Msg{
Expand Down Expand Up @@ -239,4 +240,18 @@ var (
"/dydxprotocol.vault.MsgDepositToVault": &vault.MsgDepositToVault{},
"/dydxprotocol.vault.MsgDepositToVaultResponse": nil,
}

NormalMsgsSlinky = map[string]sdk.Msg{
// slinky marketmap messages
"/slinky.marketmap.v1.MsgCreateMarkets": &marketmapmoduletypes.MsgCreateMarkets{},
"/slinky.marketmap.v1.MsgCreateMarketsResponse": nil,
"/slinky.marketmap.v1.MsgParams": &marketmapmoduletypes.MsgParams{},
"/slinky.marketmap.v1.MsgParamsResponse": nil,
"/slinky.marketmap.v1.MsgRemoveMarketAuthorities": &marketmapmoduletypes.MsgRemoveMarketAuthorities{},
"/slinky.marketmap.v1.MsgRemoveMarketAuthoritiesResponse": nil,
"/slinky.marketmap.v1.MsgUpdateMarkets": &marketmapmoduletypes.MsgUpdateMarkets{},
"/slinky.marketmap.v1.MsgUpdateMarketsResponse": nil,
"/slinky.marketmap.v1.MsgUpsertMarkets": &marketmapmoduletypes.MsgUpsertMarkets{},
"/slinky.marketmap.v1.MsgUpsertMarketsResponse": nil,
}
)
12 changes: 12 additions & 0 deletions protocol/app/msgs/normal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ func TestNormalMsgs_Key(t *testing.T) {
"/ibc.lightclients.tendermint.v1.ConsensusState",
"/ibc.lightclients.tendermint.v1.Header",
"/ibc.lightclients.tendermint.v1.Misbehaviour",

// slinky marketmap messages
"/slinky.marketmap.v1.MsgCreateMarkets",
"/slinky.marketmap.v1.MsgCreateMarketsResponse",
"/slinky.marketmap.v1.MsgParams",
"/slinky.marketmap.v1.MsgParamsResponse",
"/slinky.marketmap.v1.MsgRemoveMarketAuthorities",
"/slinky.marketmap.v1.MsgRemoveMarketAuthoritiesResponse",
"/slinky.marketmap.v1.MsgUpdateMarkets",
"/slinky.marketmap.v1.MsgUpdateMarketsResponse",
"/slinky.marketmap.v1.MsgUpsertMarkets",
"/slinky.marketmap.v1.MsgUpsertMarketsResponse",
}

require.Equal(t, expectedMsgs, lib.GetSortedKeys[sort.StringSlice](msgs.NormalMsgs))
Expand Down
12 changes: 12 additions & 0 deletions protocol/app/testdata/default_genesis_state.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{
"assets": {
"assets": [
Expand Down Expand Up @@ -351,6 +352,17 @@
"min_num_votes_per_sample": 15
}
},
"marketmap": {
"last_updated": "0",
"market_map": {
"markets": {
}
},
"params": {
"admin": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky",
"market_authorities": ["dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky"]
}
},
"prices": {
"market_params": [
{
Expand Down
3 changes: 2 additions & 1 deletion protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func (app *App) setupUpgradeHandlers() {
app.ModuleManager,
app.configurator,
app.ClobKeeper,
app.RevShareKeeper,
app.PricesKeeper,
app.MarketMapKeeper,
app.RevShareKeeper,
),
)
}
Expand Down
Loading

0 comments on commit 00c0627

Please sign in to comment.