diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts index 2408940f66..bde0abe52e 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts @@ -1,5 +1,63 @@ import * as _m0 from "protobufjs/minimal"; import { DeepPartial, Long } from "../../helpers"; +export enum PerpetualMarketType { + /** PERPETUAL_MARKET_TYPE_UNSPECIFIED - Unspecified market type. */ + PERPETUAL_MARKET_TYPE_UNSPECIFIED = 0, + + /** PERPETUAL_MARKET_TYPE_CROSS - Market type for cross margin perpetual markets. */ + PERPETUAL_MARKET_TYPE_CROSS = 1, + + /** PERPETUAL_MARKET_TYPE_ISOLATED - Market type for isolated margin perpetual markets. */ + PERPETUAL_MARKET_TYPE_ISOLATED = 2, + UNRECOGNIZED = -1, +} +export enum PerpetualMarketTypeSDKType { + /** PERPETUAL_MARKET_TYPE_UNSPECIFIED - Unspecified market type. */ + PERPETUAL_MARKET_TYPE_UNSPECIFIED = 0, + + /** PERPETUAL_MARKET_TYPE_CROSS - Market type for cross margin perpetual markets. */ + PERPETUAL_MARKET_TYPE_CROSS = 1, + + /** PERPETUAL_MARKET_TYPE_ISOLATED - Market type for isolated margin perpetual markets. */ + PERPETUAL_MARKET_TYPE_ISOLATED = 2, + UNRECOGNIZED = -1, +} +export function perpetualMarketTypeFromJSON(object: any): PerpetualMarketType { + switch (object) { + case 0: + case "PERPETUAL_MARKET_TYPE_UNSPECIFIED": + return PerpetualMarketType.PERPETUAL_MARKET_TYPE_UNSPECIFIED; + + case 1: + case "PERPETUAL_MARKET_TYPE_CROSS": + return PerpetualMarketType.PERPETUAL_MARKET_TYPE_CROSS; + + case 2: + case "PERPETUAL_MARKET_TYPE_ISOLATED": + return PerpetualMarketType.PERPETUAL_MARKET_TYPE_ISOLATED; + + case -1: + case "UNRECOGNIZED": + default: + return PerpetualMarketType.UNRECOGNIZED; + } +} +export function perpetualMarketTypeToJSON(object: PerpetualMarketType): string { + switch (object) { + case PerpetualMarketType.PERPETUAL_MARKET_TYPE_UNSPECIFIED: + return "PERPETUAL_MARKET_TYPE_UNSPECIFIED"; + + case PerpetualMarketType.PERPETUAL_MARKET_TYPE_CROSS: + return "PERPETUAL_MARKET_TYPE_CROSS"; + + case PerpetualMarketType.PERPETUAL_MARKET_TYPE_ISOLATED: + return "PERPETUAL_MARKET_TYPE_ISOLATED"; + + case PerpetualMarketType.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} /** Perpetual represents a perpetual on the dYdX exchange. */ export interface Perpetual { @@ -59,6 +117,9 @@ export interface PerpetualParams { /** The liquidity_tier that this perpetual is associated with. */ liquidityTier: number; + /** The market type specifying if this perpetual is cross or isolated */ + + marketType: PerpetualMarketType; } /** * PerpetualParams represents the parameters of a perpetual on the dYdX @@ -95,6 +156,9 @@ export interface PerpetualParamsSDKType { /** The liquidity_tier that this perpetual is associated with. */ liquidity_tier: number; + /** The market type specifying if this perpetual is cross or isolated */ + + market_type: PerpetualMarketTypeSDKType; } /** MarketPremiums stores a list of premiums for a single perpetual market. */ @@ -323,7 +387,8 @@ function createBasePerpetualParams(): PerpetualParams { marketId: 0, atomicResolution: 0, defaultFundingPpm: 0, - liquidityTier: 0 + liquidityTier: 0, + marketType: 0 }; } @@ -353,6 +418,10 @@ export const PerpetualParams = { writer.uint32(48).uint32(message.liquidityTier); } + if (message.marketType !== 0) { + writer.uint32(56).int32(message.marketType); + } + return writer; }, @@ -389,6 +458,10 @@ export const PerpetualParams = { message.liquidityTier = reader.uint32(); break; + case 7: + message.marketType = (reader.int32() as any); + break; + default: reader.skipType(tag & 7); break; @@ -406,6 +479,7 @@ export const PerpetualParams = { message.atomicResolution = object.atomicResolution ?? 0; message.defaultFundingPpm = object.defaultFundingPpm ?? 0; message.liquidityTier = object.liquidityTier ?? 0; + message.marketType = object.marketType ?? 0; return message; } diff --git a/proto/dydxprotocol/perpetuals/perpetual.proto b/proto/dydxprotocol/perpetuals/perpetual.proto index fd8e8390c4..c58188f0bb 100644 --- a/proto/dydxprotocol/perpetuals/perpetual.proto +++ b/proto/dydxprotocol/perpetuals/perpetual.proto @@ -19,6 +19,15 @@ message Perpetual { ]; } +enum PerpetualMarketType { + // Unspecified market type. + PERPETUAL_MARKET_TYPE_UNSPECIFIED = 0; + // Market type for cross margin perpetual markets. + PERPETUAL_MARKET_TYPE_CROSS = 1; + // Market type for isolated margin perpetual markets. + PERPETUAL_MARKET_TYPE_ISOLATED = 2; +} + // PerpetualParams represents the parameters of a perpetual on the dYdX // exchange. message PerpetualParams { @@ -45,6 +54,9 @@ message PerpetualParams { // The liquidity_tier that this perpetual is associated with. uint32 liquidity_tier = 6; + + // The market type specifying if this perpetual is cross or isolated + PerpetualMarketType market_type = 7; } // MarketPremiums stores a list of premiums for a single perpetual market. diff --git a/protocol/Makefile b/protocol/Makefile index 6c8b11fb94..b2f4f753a7 100644 --- a/protocol/Makefile +++ b/protocol/Makefile @@ -417,9 +417,9 @@ update-swagger-docs: statik # Run at `./protocol` directory. update-sample-pregenesis: - make build - ./scripts/genesis/prod_pregenesis.sh build/dydxprotocold - cp /tmp/prod-chain/.dydxprotocol/config/sorted_genesis.json ./scripts/genesis/sample_pregenesis.json + $(MAKE) localnet-build + @docker build . -t check-sample-pregenesis -f scripts/genesis/Dockerfile --no-cache + @docker run --entrypoint ./scripts/genesis/copy_sample_pregenesis.sh -v $(CURDIR):/workspace check-sample-pregenesis @echo "Updated ./scripts/genesis/sample_pregenesis.json" check-sample-pregenesis-up-to-date: diff --git a/protocol/mocks/PerpetualsKeeper.go b/protocol/mocks/PerpetualsKeeper.go index 40d54487bc..921b9a486e 100644 --- a/protocol/mocks/PerpetualsKeeper.go +++ b/protocol/mocks/PerpetualsKeeper.go @@ -30,23 +30,23 @@ func (_m *PerpetualsKeeper) AddPremiumVotes(ctx types.Context, votes []perpetual return r0 } -// CreatePerpetual provides a mock function with given fields: ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier -func (_m *PerpetualsKeeper) CreatePerpetual(ctx types.Context, id uint32, ticker string, marketId uint32, atomicResolution int32, defaultFundingPpm int32, liquidityTier uint32) (perpetualstypes.Perpetual, error) { - ret := _m.Called(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier) +// CreatePerpetual provides a mock function with given fields: ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier, marketType +func (_m *PerpetualsKeeper) CreatePerpetual(ctx types.Context, id uint32, ticker string, marketId uint32, atomicResolution int32, defaultFundingPpm int32, liquidityTier uint32, marketType perpetualstypes.PerpetualMarketType) (perpetualstypes.Perpetual, error) { + ret := _m.Called(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier, marketType) var r0 perpetualstypes.Perpetual var r1 error - if rf, ok := ret.Get(0).(func(types.Context, uint32, string, uint32, int32, int32, uint32) (perpetualstypes.Perpetual, error)); ok { - return rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier) + if rf, ok := ret.Get(0).(func(types.Context, uint32, string, uint32, int32, int32, uint32, perpetualstypes.PerpetualMarketType) (perpetualstypes.Perpetual, error)); ok { + return rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier, marketType) } - if rf, ok := ret.Get(0).(func(types.Context, uint32, string, uint32, int32, int32, uint32) perpetualstypes.Perpetual); ok { - r0 = rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier) + if rf, ok := ret.Get(0).(func(types.Context, uint32, string, uint32, int32, int32, uint32, perpetualstypes.PerpetualMarketType) perpetualstypes.Perpetual); ok { + r0 = rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier, marketType) } else { r0 = ret.Get(0).(perpetualstypes.Perpetual) } - if rf, ok := ret.Get(1).(func(types.Context, uint32, string, uint32, int32, int32, uint32) error); ok { - r1 = rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier) + if rf, ok := ret.Get(1).(func(types.Context, uint32, string, uint32, int32, int32, uint32, perpetualstypes.PerpetualMarketType) error); ok { + r1 = rf(ctx, id, ticker, marketId, atomicResolution, defaultFundingPpm, liquidityTier, marketType) } else { r1 = ret.Error(1) } diff --git a/protocol/scripts/genesis/copy_sample_pregenesis.sh b/protocol/scripts/genesis/copy_sample_pregenesis.sh new file mode 100755 index 0000000000..90ff402427 --- /dev/null +++ b/protocol/scripts/genesis/copy_sample_pregenesis.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +./scripts/genesis/prod_pregenesis.sh dydxprotocold +cp /tmp/prod-chain/.dydxprotocol/config/sorted_genesis.json ./scripts/genesis/sample_pregenesis.json diff --git a/protocol/scripts/genesis/sample_pregenesis.json b/protocol/scripts/genesis/sample_pregenesis.json index 58f7b7d594..7caf67d599 100644 --- a/protocol/scripts/genesis/sample_pregenesis.json +++ b/protocol/scripts/genesis/sample_pregenesis.json @@ -902,6 +902,7 @@ "id": 0, "liquidity_tier": 0, "market_id": 0, + "market_type": 1, "ticker": "BTC-USD" } }, @@ -912,6 +913,7 @@ "id": 1, "liquidity_tier": 0, "market_id": 1, + "market_type": 1, "ticker": "ETH-USD" } }, @@ -922,6 +924,7 @@ "id": 2, "liquidity_tier": 1, "market_id": 2, + "market_type": 1, "ticker": "LINK-USD" } }, @@ -932,6 +935,7 @@ "id": 3, "liquidity_tier": 1, "market_id": 3, + "market_type": 1, "ticker": "MATIC-USD" } }, @@ -942,6 +946,7 @@ "id": 4, "liquidity_tier": 1, "market_id": 4, + "market_type": 1, "ticker": "CRV-USD" } }, @@ -952,6 +957,7 @@ "id": 5, "liquidity_tier": 1, "market_id": 5, + "market_type": 1, "ticker": "SOL-USD" } }, @@ -962,6 +968,7 @@ "id": 6, "liquidity_tier": 1, "market_id": 6, + "market_type": 1, "ticker": "ADA-USD" } }, @@ -972,6 +979,7 @@ "id": 7, "liquidity_tier": 1, "market_id": 7, + "market_type": 1, "ticker": "AVAX-USD" } }, @@ -982,6 +990,7 @@ "id": 8, "liquidity_tier": 1, "market_id": 8, + "market_type": 1, "ticker": "FIL-USD" } }, @@ -992,6 +1001,7 @@ "id": 9, "liquidity_tier": 1, "market_id": 9, + "market_type": 1, "ticker": "LTC-USD" } }, @@ -1002,6 +1012,7 @@ "id": 10, "liquidity_tier": 1, "market_id": 10, + "market_type": 1, "ticker": "DOGE-USD" } }, @@ -1012,6 +1023,7 @@ "id": 11, "liquidity_tier": 1, "market_id": 11, + "market_type": 1, "ticker": "ATOM-USD" } }, @@ -1022,6 +1034,7 @@ "id": 12, "liquidity_tier": 1, "market_id": 12, + "market_type": 1, "ticker": "DOT-USD" } }, @@ -1032,6 +1045,7 @@ "id": 13, "liquidity_tier": 1, "market_id": 13, + "market_type": 1, "ticker": "UNI-USD" } }, @@ -1042,6 +1056,7 @@ "id": 14, "liquidity_tier": 1, "market_id": 14, + "market_type": 1, "ticker": "BCH-USD" } }, @@ -1052,6 +1067,7 @@ "id": 15, "liquidity_tier": 1, "market_id": 15, + "market_type": 1, "ticker": "TRX-USD" } }, @@ -1062,6 +1078,7 @@ "id": 16, "liquidity_tier": 1, "market_id": 16, + "market_type": 1, "ticker": "NEAR-USD" } }, @@ -1072,6 +1089,7 @@ "id": 17, "liquidity_tier": 2, "market_id": 17, + "market_type": 1, "ticker": "MKR-USD" } }, @@ -1082,6 +1100,7 @@ "id": 18, "liquidity_tier": 1, "market_id": 18, + "market_type": 1, "ticker": "XLM-USD" } }, @@ -1092,6 +1111,7 @@ "id": 19, "liquidity_tier": 1, "market_id": 19, + "market_type": 1, "ticker": "ETC-USD" } }, @@ -1102,6 +1122,7 @@ "id": 20, "liquidity_tier": 2, "market_id": 20, + "market_type": 1, "ticker": "COMP-USD" } }, @@ -1112,6 +1133,7 @@ "id": 21, "liquidity_tier": 1, "market_id": 21, + "market_type": 1, "ticker": "WLD-USD" } }, @@ -1122,6 +1144,7 @@ "id": 22, "liquidity_tier": 2, "market_id": 22, + "market_type": 1, "ticker": "APE-USD" } }, @@ -1132,6 +1155,7 @@ "id": 23, "liquidity_tier": 1, "market_id": 23, + "market_type": 1, "ticker": "APT-USD" } }, @@ -1142,6 +1166,7 @@ "id": 24, "liquidity_tier": 1, "market_id": 24, + "market_type": 1, "ticker": "ARB-USD" } }, @@ -1152,6 +1177,7 @@ "id": 25, "liquidity_tier": 2, "market_id": 25, + "market_type": 1, "ticker": "BLUR-USD" } }, @@ -1162,6 +1188,7 @@ "id": 26, "liquidity_tier": 2, "market_id": 26, + "market_type": 1, "ticker": "LDO-USD" } }, @@ -1172,6 +1199,7 @@ "id": 27, "liquidity_tier": 1, "market_id": 27, + "market_type": 1, "ticker": "OP-USD" } }, @@ -1182,6 +1210,7 @@ "id": 28, "liquidity_tier": 1, "market_id": 28, + "market_type": 1, "ticker": "PEPE-USD" } }, @@ -1192,6 +1221,7 @@ "id": 29, "liquidity_tier": 2, "market_id": 29, + "market_type": 1, "ticker": "SEI-USD" } }, @@ -1202,6 +1232,7 @@ "id": 30, "liquidity_tier": 1, "market_id": 30, + "market_type": 1, "ticker": "SHIB-USD" } }, @@ -1212,6 +1243,7 @@ "id": 31, "liquidity_tier": 1, "market_id": 31, + "market_type": 1, "ticker": "SUI-USD" } }, @@ -1222,6 +1254,7 @@ "id": 32, "liquidity_tier": 1, "market_id": 32, + "market_type": 1, "ticker": "XRP-USD" } } @@ -1782,7 +1815,7 @@ ] } }, - "app_version": "4.0.0-dev0-22-gd31fa077", + "app_version": "4.0.0-dev0-59-g5530ea29", "chain_id": "dydx-sample-1", "consensus": { "params": { diff --git a/protocol/testing/e2e/gov/perpetuals_test.go b/protocol/testing/e2e/gov/perpetuals_test.go index 83f56c4d61..2c8a8fbbce 100644 --- a/protocol/testing/e2e/gov/perpetuals_test.go +++ b/protocol/testing/e2e/gov/perpetuals_test.go @@ -25,6 +25,7 @@ var ( AtomicResolution: -8, DefaultFundingPpm: 545, LiquidityTier: 1, + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, } TEST_LIQUIDITY_TIER = perptypes.LiquidityTier{ Id: 1, @@ -329,7 +330,13 @@ func TestUpdatePerpetualsParams(t *testing.T) { if tc.expectedProposalStatus == govtypesv1.ProposalStatus_PROPOSAL_STATUS_PASSED { // If proposal is supposed to pass, verify that the perpetual's params have been updated. - require.Equal(t, tc.msg.PerpetualParams, updatedPerpetual.Params) + // All params except for MarketType should be updated. + require.Equal(t, tc.msg.PerpetualParams.Ticker, updatedPerpetual.Params.Ticker) + require.Equal(t, tc.msg.PerpetualParams.MarketId, updatedPerpetual.Params.MarketId) + require.Equal(t, tc.msg.PerpetualParams.DefaultFundingPpm, updatedPerpetual.Params.DefaultFundingPpm) + require.Equal(t, tc.msg.PerpetualParams.LiquidityTier, updatedPerpetual.Params.LiquidityTier) + require.Equal(t, tc.msg.PerpetualParams.AtomicResolution, updatedPerpetual.Params.AtomicResolution) + require.Equal(t, initialPerpetual.Params.MarketType, updatedPerpetual.Params.MarketType) } else { // If proposal is not supposed to succeed, verify that the perpetual's // params match the ones before proposal submission. diff --git a/protocol/testing/genesis.sh b/protocol/testing/genesis.sh index a782047697..452ad0ae0e 100755 --- a/protocol/testing/genesis.sh +++ b/protocol/testing/genesis.sh @@ -178,6 +178,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[0].params.atomic_resolution' -v '-10' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[0].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[0].params.liquidity_tier' -v '0' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[0].params.market_type' -v '1' # Perpetual: ETH-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -187,6 +188,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[1].params.atomic_resolution' -v '-9' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[1].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[1].params.liquidity_tier' -v '0' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[1].params.market_type' -v '1' # Perpetual: LINK-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -196,6 +198,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[2].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[2].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[2].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[2].params.market_type' -v '1' # Perpetual: MATIC-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -205,6 +208,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[3].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[3].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[3].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[3].params.market_type' -v '1' # Perpetual: CRV-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -214,6 +218,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[4].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[4].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[4].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[4].params.market_type' -v '1' # Perpetual: SOL-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -223,6 +228,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[5].params.atomic_resolution' -v '-7' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[5].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[5].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[5].params.market_type' -v '1' # Perpetual: ADA-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -232,6 +238,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[6].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[6].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[6].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[6].params.market_type' -v '1' # Perpetual: AVAX-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -241,6 +248,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[7].params.atomic_resolution' -v '-7' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[7].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[7].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[7].params.market_type' -v '1' # Perpetual: FIL-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -250,6 +258,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[8].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[8].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[8].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[8].params.market_type' -v '1' # Perpetual: LTC-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -259,6 +268,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[9].params.atomic_resolution' -v '-7' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[9].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[9].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[9].params.market_type' -v '1' # Perpetual: DOGE-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -268,6 +278,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[10].params.atomic_resolution' -v '-4' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[10].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[10].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[10].params.market_type' -v '1' # Perpetual: ATOM-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -277,6 +288,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[11].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[11].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[11].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[11].params.market_type' -v '1' # Perpetual: DOT-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -286,6 +298,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[12].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[12].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[12].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[12].params.market_type' -v '1' # Perpetual: UNI-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -295,6 +308,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[13].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[13].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[13].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[13].params.market_type' -v '1' # Perpetual: BCH-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -304,6 +318,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[14].params.atomic_resolution' -v '-8' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[14].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[14].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[14].params.market_type' -v '1' # Perpetual: TRX-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -313,6 +328,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[15].params.atomic_resolution' -v '-4' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[15].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[15].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[15].params.market_type' -v '1' # Perpetual: NEAR-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -322,6 +338,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[16].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[16].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[16].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[16].params.market_type' -v '1' # Perpetual: MKR-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -331,6 +348,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[17].params.atomic_resolution' -v '-9' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[17].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[17].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[17].params.market_type' -v '1' # Perpetual: XLM-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -340,6 +358,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[18].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[18].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[18].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[18].params.market_type' -v '1' # Perpetual: ETC-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -349,6 +368,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[19].params.atomic_resolution' -v '-7' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[19].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[19].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[19].params.market_type' -v '1' # Perpetual: COMP-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -358,6 +378,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[20].params.atomic_resolution' -v '-7' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[20].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[20].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[20].params.market_type' -v '1' # Perpetual: WLD-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -367,6 +388,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[21].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[21].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[21].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[21].params.market_type' -v '1' # Perpetual: APE-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -376,6 +398,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[22].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[22].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[22].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[22].params.market_type' -v '1' # Perpetual: APT-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -385,6 +408,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[23].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[23].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[23].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[23].params.market_type' -v '1' # Perpetual: ARB-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -394,6 +418,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[24].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[24].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[24].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[24].params.market_type' -v '1' # Perpetual: BLUR-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -403,6 +428,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[25].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[25].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[25].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[25].params.market_type' -v '1' # Perpetual: LDO-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -412,6 +438,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[26].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[26].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[26].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[26].params.market_type' -v '1' # Perpetual: OP-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -421,6 +448,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[27].params.atomic_resolution' -v '-6' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[27].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[27].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[27].params.market_type' -v '1' # Perpetual: PEPE-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -430,6 +458,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[28].params.atomic_resolution' -v '1' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[28].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[28].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[28].params.market_type' -v '1' # Perpetual: SEI-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -439,6 +468,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[29].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[29].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[29].params.liquidity_tier' -v '2' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[29].params.market_type' -v '1' # Perpetual: SHIB-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -448,6 +478,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[30].params.atomic_resolution' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[30].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[30].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[30].params.market_type' -v '1' # Perpetual: SUI-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -457,6 +488,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[31].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[31].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[31].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[31].params.market_type' -v '1' # Perpetual: XRP-USD dasel put -t json -f "$GENESIS" '.app_state.perpetuals.perpetuals.[]' -v "{}" @@ -466,6 +498,7 @@ function edit_genesis() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[32].params.atomic_resolution' -v '-5' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[32].params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[32].params.liquidity_tier' -v '1' + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.[32].params.market_type' -v '1' # Update prices module. # Market: BTC-USD @@ -1571,6 +1604,8 @@ function update_genesis_use_test_volatile_market() { dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.last().params.atomic_resolution' -v '-10' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.last().params.default_funding_ppm' -v '0' dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.last().params.liquidity_tier' -v "${NUM_LIQUIDITY_TIERS}" + dasel put -t int -f "$GENESIS" '.app_state.perpetuals.perpetuals.last().params.market_type' -v '1' + # Clob: TEST-USD NUM_CLOB_PAIRS=$(jq -c '.app_state.clob.clob_pairs | length' < ${GENESIS}) diff --git a/protocol/testutil/constants/genesis.go b/protocol/testutil/constants/genesis.go index 0dc9e7ab96..994a9706a7 100644 --- a/protocol/testutil/constants/genesis.go +++ b/protocol/testutil/constants/genesis.go @@ -901,7 +901,8 @@ const GenesisState = `{ "id": 0, "liquidity_tier": 0, "market_id": 0, - "ticker": "BTC-USD" + "ticker": "BTC-USD", + "market_type": 1 } }, { @@ -911,7 +912,8 @@ const GenesisState = `{ "id": 1, "liquidity_tier": 0, "market_id": 1, - "ticker": "ETH-USD" + "ticker": "ETH-USD", + "market_type": 1 } } ] diff --git a/protocol/testutil/constants/perpetuals.go b/protocol/testutil/constants/perpetuals.go index 9f9739d64c..2fc10cbb3c 100644 --- a/protocol/testutil/constants/perpetuals.go +++ b/protocol/testutil/constants/perpetuals.go @@ -115,6 +115,7 @@ var ( AtomicResolution: int32(-10), DefaultFundingPpm: int32(0), LiquidityTier: uint32(0), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -126,6 +127,7 @@ var ( AtomicResolution: int32(0), DefaultFundingPpm: int32(0), LiquidityTier: uint32(2), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -137,6 +139,7 @@ var ( AtomicResolution: int32(-10), DefaultFundingPpm: int32(-1_000), LiquidityTier: uint32(1), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -148,6 +151,7 @@ var ( AtomicResolution: int32(-10), DefaultFundingPpm: int32(0), LiquidityTier: uint32(1), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -159,6 +163,7 @@ var ( AtomicResolution: int32(-10), DefaultFundingPpm: int32(0), LiquidityTier: uint32(6), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -170,6 +175,7 @@ var ( AtomicResolution: int32(-10), DefaultFundingPpm: int32(1000), // 0.001% LiquidityTier: uint32(1), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -181,6 +187,7 @@ var ( AtomicResolution: int32(-8), DefaultFundingPpm: int32(0), LiquidityTier: uint32(8), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -192,6 +199,7 @@ var ( AtomicResolution: int32(-8), DefaultFundingPpm: int32(0), LiquidityTier: uint32(0), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -203,6 +211,7 @@ var ( AtomicResolution: int32(-8), DefaultFundingPpm: int32(0), LiquidityTier: uint32(4), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -214,6 +223,7 @@ var ( AtomicResolution: int32(-8), DefaultFundingPpm: int32(0), LiquidityTier: uint32(3), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -225,6 +235,7 @@ var ( AtomicResolution: int32(-8), DefaultFundingPpm: int32(0), LiquidityTier: uint32(7), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -236,6 +247,7 @@ var ( AtomicResolution: int32(-9), DefaultFundingPpm: int32(0), LiquidityTier: uint32(5), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -247,6 +259,7 @@ var ( AtomicResolution: int32(-9), DefaultFundingPpm: int32(0), LiquidityTier: uint32(7), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -258,6 +271,7 @@ var ( AtomicResolution: int32(-9), DefaultFundingPpm: int32(0), LiquidityTier: uint32(3), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -269,6 +283,7 @@ var ( AtomicResolution: int32(-9), DefaultFundingPpm: int32(0), LiquidityTier: uint32(0), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -280,6 +295,7 @@ var ( AtomicResolution: int32(-9), DefaultFundingPpm: int32(0), LiquidityTier: uint32(3), + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } @@ -346,6 +362,7 @@ var ( Id: uint32(0), Ticker: "genesis_test_ticker_0", LiquidityTier: 0, + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), }, @@ -354,6 +371,7 @@ var ( Id: uint32(1), Ticker: "genesis_test_ticker_1", LiquidityTier: 1, + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), }, diff --git a/protocol/testutil/keeper/perpetuals.go b/protocol/testutil/keeper/perpetuals.go index 0d731f7a1c..a7c9c3bef7 100644 --- a/protocol/testutil/keeper/perpetuals.go +++ b/protocol/testutil/keeper/perpetuals.go @@ -2,9 +2,10 @@ package keeper import ( "fmt" + "testing" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/gogoproto/proto" - "testing" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -53,33 +54,35 @@ func PerpetualsKeepersWithClobHelpers( t testing.TB, clobKeeper types.PerpetualsClobKeeper, ) (pc PerpKeepersTestContext) { - pc.Ctx = initKeepers(t, func( - db *dbm.MemDB, - registry codectypes.InterfaceRegistry, - cdc *codec.ProtoCodec, - stateStore storetypes.CommitMultiStore, - transientStoreKey storetypes.StoreKey, - ) []GenesisInitializer { - // Define necessary keepers here for unit tests - pc.PricesKeeper, _, pc.IndexPriceCache, _, pc.MockTimeProvider = createPricesKeeper( - stateStore, - db, - cdc, - transientStoreKey, - ) - pc.EpochsKeeper, _ = createEpochsKeeper(stateStore, db, cdc) - pc.PerpetualsKeeper, pc.StoreKey = createPerpetualsKeeperWithClobHelpers( - stateStore, - db, - cdc, - pc.PricesKeeper, - pc.EpochsKeeper, - clobKeeper, - transientStoreKey, - ) + pc.Ctx = initKeepers( + t, func( + db *dbm.MemDB, + registry codectypes.InterfaceRegistry, + cdc *codec.ProtoCodec, + stateStore storetypes.CommitMultiStore, + transientStoreKey storetypes.StoreKey, + ) []GenesisInitializer { + // Define necessary keepers here for unit tests + pc.PricesKeeper, _, pc.IndexPriceCache, _, pc.MockTimeProvider = createPricesKeeper( + stateStore, + db, + cdc, + transientStoreKey, + ) + pc.EpochsKeeper, _ = createEpochsKeeper(stateStore, db, cdc) + pc.PerpetualsKeeper, pc.StoreKey = createPerpetualsKeeperWithClobHelpers( + stateStore, + db, + cdc, + pc.PricesKeeper, + pc.EpochsKeeper, + clobKeeper, + transientStoreKey, + ) - return []GenesisInitializer{pc.PricesKeeper, pc.PerpetualsKeeper} - }) + return []GenesisInitializer{pc.PricesKeeper, pc.PerpetualsKeeper} + }, + ) // Mock time provider response for market creation. pc.MockTimeProvider.On("Now").Return(constants.TimeT) @@ -220,8 +223,10 @@ func CreateNPerpetuals( CreateNMarkets(t, ctx, pricesKeeper, n) var defaultFundingPpm int32 + marketType := types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS if i%3 == 0 { defaultFundingPpm = 1 + marketType = types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED } else if i%3 == 1 { defaultFundingPpm = -1 } else { @@ -236,6 +241,7 @@ func CreateNPerpetuals( int32(i), // AtomicResolution defaultFundingPpm, // DefaultFundingPpm allLiquidityTiers[i%len(allLiquidityTiers)].Id, // LiquidityTier + marketType, // MarketType ) if err != nil { return items, err @@ -285,6 +291,7 @@ func CreateTestPricesAndPerpetualMarkets( perp.Params.AtomicResolution, perp.Params.DefaultFundingPpm, perp.Params.LiquidityTier, + perp.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/testutil/perpetuals/perpetuals.go b/protocol/testutil/perpetuals/perpetuals.go index 6dec4027f7..451da22b7b 100644 --- a/protocol/testutil/perpetuals/perpetuals.go +++ b/protocol/testutil/perpetuals/perpetuals.go @@ -39,6 +39,12 @@ func WithLiquidityTier(liquidityTier uint32) PerpetualModifierOption { } } +func WithMarketType(marketType perptypes.PerpetualMarketType) PerpetualModifierOption { + return func(cp *perptypes.Perpetual) { + cp.Params.MarketType = marketType + } +} + // GeneratePerpetual returns a `Perpetual` object set to default values. // Passing in `PerpetualModifierOption` methods alters the value of the `Perpetual` returned. // It will start with the default, valid `Perpetual` value defined within the method @@ -58,6 +64,7 @@ func GeneratePerpetual(optionalModifications ...PerpetualModifierOption) *perpty AtomicResolution: -8, DefaultFundingPpm: 0, LiquidityTier: 0, + MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), } diff --git a/protocol/x/clob/abci_test.go b/protocol/x/clob/abci_test.go index 15d7f9d1fc..ca576285e6 100644 --- a/protocol/x/clob/abci_test.go +++ b/protocol/x/clob/abci_test.go @@ -685,6 +685,7 @@ func TestEndBlocker_Success(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1366,6 +1367,7 @@ func TestPrepareCheckState(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/clob/client/cli/query_clob_pair_test.go b/protocol/x/clob/client/cli/query_clob_pair_test.go index 0f4f2249ed..4dc9161956 100644 --- a/protocol/x/clob/client/cli/query_clob_pair_test.go +++ b/protocol/x/clob/client/cli/query_clob_pair_test.go @@ -50,6 +50,7 @@ func networkWithClobPairObjects(t *testing.T, n int) (*network.Network, []types. Id: uint32(i), Ticker: fmt.Sprintf("genesis_test_ticker_%d", i), LiquidityTier: 0, + MarketType: perpetualstypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), }, diff --git a/protocol/x/clob/keeper/deleveraging_test.go b/protocol/x/clob/keeper/deleveraging_test.go index 751daa3a27..da6a119876 100644 --- a/protocol/x/clob/keeper/deleveraging_test.go +++ b/protocol/x/clob/keeper/deleveraging_test.go @@ -353,6 +353,7 @@ func TestCanDeleverageSubaccount(t *testing.T) { perpetual.Params.AtomicResolution, perpetual.Params.DefaultFundingPpm, perpetual.Params.LiquidityTier, + perpetual.Params.MarketType, ) require.NoError(t, err) } @@ -721,6 +722,7 @@ func TestOffsetSubaccountPerpetualPosition(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1184,6 +1186,7 @@ func TestProcessDeleveraging(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1394,6 +1397,7 @@ func TestProcessDeleveragingAtOraclePrice(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1555,6 +1559,7 @@ func TestProcessDeleveraging_Rounding(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 50d6b384cb..e44f6804e7 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -294,6 +294,7 @@ func TestPlacePerpetualLiquidation(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -392,6 +393,7 @@ func TestPlacePerpetualLiquidation_validateLiquidationAgainstClobPairStatus(t *t p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1114,6 +1116,7 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { perpetual.Params.AtomicResolution, perpetual.Params.DefaultFundingPpm, perpetual.Params.LiquidityTier, + perpetual.Params.MarketType, ) require.NoError(t, err) } @@ -1995,6 +1998,7 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { perpetual.Params.AtomicResolution, perpetual.Params.DefaultFundingPpm, perpetual.Params.LiquidityTier, + perpetual.Params.MarketType, ) require.NoError(t, err) } @@ -2285,6 +2289,7 @@ func TestIsLiquidatable(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -2704,6 +2709,7 @@ func TestGetBankruptcyPriceInQuoteQuantums(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -3235,6 +3241,7 @@ func TestGetFillablePrice(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -3659,6 +3666,7 @@ func TestGetLiquidationInsuranceFundDelta(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -4383,6 +4391,7 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -4631,6 +4640,7 @@ func TestMaybeGetLiquidationOrder(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -4954,6 +4964,7 @@ func TestGetMaxAndMinPositionNotionalLiquidatable(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement.Params.AtomicResolution, constants.BtcUsd_100PercentMarginRequirement.Params.DefaultFundingPpm, constants.BtcUsd_100PercentMarginRequirement.Params.LiquidityTier, + constants.BtcUsd_100PercentMarginRequirement.Params.MarketType, ) require.NoError(t, err) @@ -5107,6 +5118,7 @@ func TestSortLiquidationOrders(t *testing.T) { constants.BtcUsd_100PercentMarginRequirement.Params.AtomicResolution, constants.BtcUsd_100PercentMarginRequirement.Params.DefaultFundingPpm, constants.BtcUsd_100PercentMarginRequirement.Params.LiquidityTier, + constants.BtcUsd_100PercentMarginRequirement.Params.MarketType, ) require.NoError(t, err) diff --git a/protocol/x/clob/keeper/mev_test.go b/protocol/x/clob/keeper/mev_test.go index a1853ad7f9..4697be5bd3 100644 --- a/protocol/x/clob/keeper/mev_test.go +++ b/protocol/x/clob/keeper/mev_test.go @@ -885,6 +885,7 @@ func TestRecordMevMetrics(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -1262,6 +1263,7 @@ func TestGetMidPrices(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/clob/keeper/msg_server_place_order_test.go b/protocol/x/clob/keeper/msg_server_place_order_test.go index a1b6a41e4c..48fd1547a1 100644 --- a/protocol/x/clob/keeper/msg_server_place_order_test.go +++ b/protocol/x/clob/keeper/msg_server_place_order_test.go @@ -131,6 +131,7 @@ func TestPlaceOrder_Error(t *testing.T) { perpetual.Params.AtomicResolution, perpetual.Params.DefaultFundingPpm, perpetual.Params.LiquidityTier, + perpetual.Params.MarketType, ) require.NoError(t, err) @@ -297,6 +298,7 @@ func TestPlaceOrder_Success(t *testing.T) { perpetual.Params.AtomicResolution, perpetual.Params.DefaultFundingPpm, perpetual.Params.LiquidityTier, + perpetual.Params.MarketType, ) require.NoError(t, err) diff --git a/protocol/x/clob/keeper/orders_test.go b/protocol/x/clob/keeper/orders_test.go index 9646f11257..79998ab3fe 100644 --- a/protocol/x/clob/keeper/orders_test.go +++ b/protocol/x/clob/keeper/orders_test.go @@ -679,6 +679,7 @@ func TestPlaceShortTermOrder(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -906,6 +907,7 @@ func TestAddPreexistingStatefulOrder(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/clob/keeper/process_operations_test.go b/protocol/x/clob/keeper/process_operations_test.go index bd5c2fb2cc..1bd06c54ee 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1,10 +1,11 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/app/module" "testing" "time" + "github.com/dydxprotocol/v4-chain/protocol/app/module" + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" "cosmossdk.io/store/prefix" @@ -2221,6 +2222,7 @@ func setupProcessProposerOperationsTestCase( p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/perpetuals/client/cli/query_perpetual_test.go b/protocol/x/perpetuals/client/cli/query_perpetual_test.go index b6b6f30ae6..09d532dce2 100644 --- a/protocol/x/perpetuals/client/cli/query_perpetual_test.go +++ b/protocol/x/perpetuals/client/cli/query_perpetual_test.go @@ -60,12 +60,19 @@ func networkWithLiquidityTierAndPerpetualObjects( } // Generate `n` Perpetuals. + for i := 0; i < n; i++ { + marketType := types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS + if i%2 == 1 { + marketType = types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED + } + perpetual := types.Perpetual{ Params: types.PerpetualParams{ Id: uint32(i), Ticker: fmt.Sprintf("test_query_ticker_%d", i), LiquidityTier: uint32(i % m), + MarketType: marketType, }, FundingIndex: dtypes.ZeroInt(), } diff --git a/protocol/x/perpetuals/genesis.go b/protocol/x/perpetuals/genesis.go index 373e51daa2..fc9e4c9ab6 100644 --- a/protocol/x/perpetuals/genesis.go +++ b/protocol/x/perpetuals/genesis.go @@ -43,6 +43,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) elem.Params.AtomicResolution, elem.Params.DefaultFundingPpm, elem.Params.LiquidityTier, + elem.Params.MarketType, ) if err != nil { diff --git a/protocol/x/perpetuals/genesis_test.go b/protocol/x/perpetuals/genesis_test.go index 7ec28797ee..314cbdb7ea 100644 --- a/protocol/x/perpetuals/genesis_test.go +++ b/protocol/x/perpetuals/genesis_test.go @@ -146,6 +146,7 @@ func TestGenesis_Failure(t *testing.T) { MarketId: tc.marketId, Ticker: tc.ticker, LiquidityTier: 0, + MarketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, }, FundingIndex: dtypes.ZeroInt(), }, diff --git a/protocol/x/perpetuals/keeper/msg_server_create_perpetual.go b/protocol/x/perpetuals/keeper/msg_server_create_perpetual.go index d23889c36f..f7acc7285c 100644 --- a/protocol/x/perpetuals/keeper/msg_server_create_perpetual.go +++ b/protocol/x/perpetuals/keeper/msg_server_create_perpetual.go @@ -32,6 +32,7 @@ func (k msgServer) CreatePerpetual( msg.Params.AtomicResolution, msg.Params.DefaultFundingPpm, msg.Params.LiquidityTier, + msg.Params.MarketType, ) if err != nil { return &types.MsgCreatePerpetualResponse{}, err diff --git a/protocol/x/perpetuals/keeper/msg_server_create_perpetual_test.go b/protocol/x/perpetuals/keeper/msg_server_create_perpetual_test.go index cfc195f37b..ec30abf710 100644 --- a/protocol/x/perpetuals/keeper/msg_server_create_perpetual_test.go +++ b/protocol/x/perpetuals/keeper/msg_server_create_perpetual_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/lib" "testing" + "github.com/dydxprotocol/v4-chain/protocol/lib" + sdk "github.com/cosmos/cosmos-sdk/types" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" perptest "github.com/dydxprotocol/v4-chain/protocol/testutil/perpetuals" @@ -24,7 +25,13 @@ func TestCreatePerpetual(t *testing.T) { perptest.WithId(2), perptest.WithMarketId(1), ) + testPerpIsolated := *perptest.GeneratePerpetual( + perptest.WithId(3), + perptest.WithMarketId(2), + perptest.WithMarketType(types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED), + ) testMarket1 := *pricestest.GenerateMarketParamPrice(pricestest.WithId(1)) + testMarket2 := *pricestest.GenerateMarketParamPrice(pricestest.WithId(2)) testCases := map[string]struct { setup func(*testing.T, sdk.Context, *perpkeeper.Keeper, *priceskeeper.Keeper) msg *types.MsgCreatePerpetual @@ -64,6 +71,27 @@ func TestCreatePerpetual(t *testing.T) { }, expectedPerpetuals: []types.Perpetual{testPerp1, testPerp2}, }, + "Succeeds: create new isolated market perpetual": { + setup: func( + t *testing.T, + ctx sdk.Context, + perpKeeper *perpkeeper.Keeper, + pricesKeeper *priceskeeper.Keeper, + ) { + keepertest.CreateTestLiquidityTiers(t, ctx, perpKeeper) + keepertest.CreateTestPriceMarkets( + t, + ctx, + pricesKeeper, + []pricestypes.MarketParamPrice{testMarket2}, + ) + }, + msg: &types.MsgCreatePerpetual{ + Authority: lib.GovModuleAddress.String(), + Params: testPerpIsolated.Params, + }, + expectedPerpetuals: []types.Perpetual{testPerpIsolated}, + }, "Failure: new perpetual id already exists in state": { setup: func(t *testing.T, ctx sdk.Context, perpKeeper *perpkeeper.Keeper, pricesKeeper *priceskeeper.Keeper) { keepertest.CreateTestPricesAndPerpetualMarkets( diff --git a/protocol/x/perpetuals/keeper/msg_server_update_perpetual_params_test.go b/protocol/x/perpetuals/keeper/msg_server_update_perpetual_params_test.go index 4640075c45..4589405fd7 100644 --- a/protocol/x/perpetuals/keeper/msg_server_update_perpetual_params_test.go +++ b/protocol/x/perpetuals/keeper/msg_server_update_perpetual_params_test.go @@ -1,9 +1,10 @@ package keeper_test import ( - "github.com/dydxprotocol/v4-chain/protocol/lib" "testing" + "github.com/dydxprotocol/v4-chain/protocol/lib" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" @@ -192,7 +193,20 @@ func TestUpdatePerpetualParams(t *testing.T) { // Verify updated perpetual params in state. updatedPerpetualInState, err := pc.PerpetualsKeeper.GetPerpetual(pc.Ctx, tc.msg.PerpetualParams.Id) require.NoError(t, err) - require.Equal(t, tc.msg.PerpetualParams, updatedPerpetualInState.Params) + require.Equal(t, tc.msg.PerpetualParams.Ticker, updatedPerpetualInState.Params.Ticker) + require.Equal(t, tc.msg.PerpetualParams.MarketId, updatedPerpetualInState.Params.MarketId) + require.Equal( + t, + tc.msg.PerpetualParams.DefaultFundingPpm, + updatedPerpetualInState.Params.DefaultFundingPpm, + ) + require.Equal(t, tc.msg.PerpetualParams.LiquidityTier, updatedPerpetualInState.Params.LiquidityTier) + require.Equal( + t, + tc.msg.PerpetualParams.AtomicResolution, + updatedPerpetualInState.Params.AtomicResolution, + ) + require.Equal(t, testPerp.Params.MarketType, updatedPerpetualInState.Params.MarketType) } }) } diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 87ce79edb1..01fbda8e5e 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -40,6 +40,7 @@ func (k Keeper) CreatePerpetual( atomicResolution int32, defaultFundingPpm int32, liquidityTier uint32, + marketType types.PerpetualMarketType, ) (types.Perpetual, error) { // Check if perpetual exists. if k.HasPerpetual(ctx, id) { @@ -49,6 +50,15 @@ func (k Keeper) CreatePerpetual( ) } + // Check if market type is valid + if marketType != types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS && + marketType != types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED { + return types.Perpetual{}, errorsmod.Wrap( + types.ErrInvalidMarketType, + fmt.Sprintf("market type %v", marketType), + ) + } + // Create the perpetual. perpetual := types.Perpetual{ Params: types.PerpetualParams{ @@ -58,6 +68,7 @@ func (k Keeper) CreatePerpetual( AtomicResolution: atomicResolution, DefaultFundingPpm: defaultFundingPpm, LiquidityTier: liquidityTier, + MarketType: marketType, }, FundingIndex: dtypes.ZeroInt(), } diff --git a/protocol/x/perpetuals/keeper/perpetual_test.go b/protocol/x/perpetuals/keeper/perpetual_test.go index 11e2d36725..95e569892e 100644 --- a/protocol/x/perpetuals/keeper/perpetual_test.go +++ b/protocol/x/perpetuals/keeper/perpetual_test.go @@ -2,13 +2,14 @@ package keeper_test import ( "fmt" - "github.com/cosmos/gogoproto/proto" - "github.com/dydxprotocol/v4-chain/protocol/app/module" "math" "math/big" "sort" "testing" + "github.com/cosmos/gogoproto/proto" + "github.com/dydxprotocol/v4-chain/protocol/app/module" + errorsmod "cosmossdk.io/errors" "github.com/dydxprotocol/v4-chain/protocol/dtypes" @@ -142,6 +143,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution int32 defaultFundingPpm int32 liquidityTier uint32 + marketType types.PerpetualMarketType expectedError error }{ "Price doesn't exist": { @@ -151,6 +153,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution: -10, defaultFundingPpm: 0, liquidityTier: 0, + marketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, expectedError: errorsmod.Wrap(pricestypes.ErrMarketPriceDoesNotExist, fmt.Sprint(999)), }, "Positive default funding magnitude exceeds maximum": { @@ -160,6 +163,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution: -10, defaultFundingPpm: int32(lib.OneMillion + 1), liquidityTier: 0, + marketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, expectedError: errorsmod.Wrap( types.ErrDefaultFundingPpmMagnitudeExceedsMax, fmt.Sprint(int32(lib.OneMillion+1)), @@ -172,6 +176,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution: -10, defaultFundingPpm: 0 - int32(lib.OneMillion) - 1, liquidityTier: 0, + marketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, expectedError: errorsmod.Wrap( types.ErrDefaultFundingPpmMagnitudeExceedsMax, fmt.Sprint(0-int32(lib.OneMillion)-1), @@ -184,6 +189,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution: -10, defaultFundingPpm: math.MinInt32, liquidityTier: 0, + marketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, expectedError: errorsmod.Wrap(types.ErrDefaultFundingPpmMagnitudeExceedsMax, fmt.Sprint(math.MinInt32)), }, "Ticker is an empty string": { @@ -193,8 +199,34 @@ func TestCreatePerpetual_Failure(t *testing.T) { atomicResolution: -10, defaultFundingPpm: 0, liquidityTier: 0, + marketType: types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, expectedError: types.ErrTickerEmptyString, }, + "Unspecified market type": { + id: 0, + ticker: "", + marketId: 0, + atomicResolution: -10, + defaultFundingPpm: 0, + liquidityTier: 0, + expectedError: errorsmod.Wrap( + types.ErrInvalidMarketType, + fmt.Sprintf("market type %v", types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED), + ), + }, + "Invalid market type": { + id: 0, + ticker: "", + marketId: 0, + atomicResolution: -10, + defaultFundingPpm: 0, + liquidityTier: 0, + marketType: 3, + expectedError: errorsmod.Wrap( + types.ErrInvalidMarketType, + fmt.Sprintf("market type %v", 3), + ), + }, } // Test setup. @@ -213,6 +245,7 @@ func TestCreatePerpetual_Failure(t *testing.T) { tc.atomicResolution, tc.defaultFundingPpm, tc.liquidityTier, + tc.marketType, ) require.Error(t, err) @@ -344,6 +377,7 @@ func TestHasPerpetual(t *testing.T) { perps[perp].Params.AtomicResolution, perps[perp].Params.DefaultFundingPpm, perps[perp].Params.LiquidityTier, + perps[perp].Params.MarketType, ) require.NoError(t, err) } @@ -421,6 +455,7 @@ func TestGetAllPerpetuals_Sorted(t *testing.T) { perps[perp].Params.AtomicResolution, perps[perp].Params.DefaultFundingPpm, perps[perp].Params.LiquidityTier, + perps[perp].Params.MarketType, ) require.NoError(t, err) } @@ -662,6 +697,7 @@ func TestGetMarginRequirements_Success(t *testing.T) { tc.baseCurrencyAtomicResolution, // AtomicResolution int32(0), // DefaultFundingPpm 0, // LiquidityTier + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, // MarketType ) require.NoError(t, err) @@ -862,6 +898,7 @@ func TestGetNetNotional_Success(t *testing.T) { tc.baseCurrencyAtomicResolution, // AtomicResolution int32(0), // DefaultFundingPpm 0, // LiquidityTier + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, // MarketType ) require.NoError(t, err) @@ -1023,6 +1060,7 @@ func TestGetNotionalInBaseQuantums_Success(t *testing.T) { tc.baseCurrencyAtomicResolution, // AtomicResolution int32(0), // DefaultFundingPpm 0, // LiquidityTier + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, // MarketType ) require.NoError(t, err) @@ -1185,6 +1223,7 @@ func TestGetNetCollateral_Success(t *testing.T) { tc.baseCurrencyAtomicResolution, // AtomicResolution int32(0), // DefaultFundingPpm 0, // LiquidityTier + types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS, // MarketType ) require.NoError(t, err) @@ -1871,6 +1910,7 @@ func TestMaybeProcessNewFundingTickEpoch_ProcessNewEpoch(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) oldPerps[i] = perp diff --git a/protocol/x/perpetuals/module_test.go b/protocol/x/perpetuals/module_test.go index db0db14e41..7802a105d1 100644 --- a/protocol/x/perpetuals/module_test.go +++ b/protocol/x/perpetuals/module_test.go @@ -3,12 +3,13 @@ package perpetuals_test import ( "bytes" "encoding/json" - "github.com/dydxprotocol/v4-chain/protocol/app/module" "net/http" "net/http/httptest" "reflect" "testing" + "github.com/dydxprotocol/v4-chain/protocol/app/module" + pricetypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" "github.com/cosmos/cosmos-sdk/client" @@ -271,7 +272,8 @@ func TestAppModule_InitExportGenesis(t *testing.T) { "params": { "ticker":"EXAM-USD", "market_id":0, - "liquidity_tier":0 + "liquidity_tier":0, + "market_type":"PERPETUAL_MARKET_TYPE_CROSS" } } ], @@ -309,7 +311,8 @@ func TestAppModule_InitExportGenesis(t *testing.T) { "market_id":0, "atomic_resolution":0, "default_funding_ppm":0, - "liquidity_tier":0 + "liquidity_tier":0, + "market_type":"PERPETUAL_MARKET_TYPE_CROSS" }, "funding_index":"0" } diff --git a/protocol/x/perpetuals/simulation/genesis.go b/protocol/x/perpetuals/simulation/genesis.go index 37ddc363e4..7addb08818 100644 --- a/protocol/x/perpetuals/simulation/genesis.go +++ b/protocol/x/perpetuals/simulation/genesis.go @@ -4,11 +4,12 @@ package simulation import ( "fmt" - v4module "github.com/dydxprotocol/v4-chain/protocol/app/module" "math" "math/big" "math/rand" + v4module "github.com/dydxprotocol/v4-chain/protocol/app/module" + "github.com/cosmos/cosmos-sdk/codec" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -188,6 +189,11 @@ func RandomizedGenState(simState *module.SimulationState) { for i := 0; i < numPerpetuals; i++ { marketId := marketsForPerp[i] + marketType := types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS + if i%2 == 0 { + marketType = types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED + } + perpetuals[i] = types.Perpetual{ Params: types.PerpetualParams{ Id: uint32(i), @@ -196,6 +202,7 @@ func RandomizedGenState(simState *module.SimulationState) { AtomicResolution: genAtomicResolution(r, isReasonableGenesis), DefaultFundingPpm: genDefaultFundingPpm(r), LiquidityTier: uint32(simtypes.RandIntBetween(r, 0, numLiquidityTiers)), + MarketType: marketType, }, FundingIndex: dtypes.ZeroInt(), } diff --git a/protocol/x/perpetuals/types/errors.go b/protocol/x/perpetuals/types/errors.go index a7efb2dd26..e7e0aed8c8 100644 --- a/protocol/x/perpetuals/types/errors.go +++ b/protocol/x/perpetuals/types/errors.go @@ -107,6 +107,11 @@ var ( 22, "MinNumVotesPerSample is zero", ) + ErrInvalidMarketType = errorsmod.Register( + ModuleName, + 23, + "Market type is invalid", + ) // Errors for Not Implemented ErrNotImplementedFunding = errorsmod.Register(ModuleName, 1001, "Not Implemented: Perpetuals Funding") diff --git a/protocol/x/perpetuals/types/perpetual.pb.go b/protocol/x/perpetuals/types/perpetual.pb.go index 8999eeef49..6072e4dbea 100644 --- a/protocol/x/perpetuals/types/perpetual.pb.go +++ b/protocol/x/perpetuals/types/perpetual.pb.go @@ -24,6 +24,37 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type PerpetualMarketType int32 + +const ( + // Unspecified market type. + PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED PerpetualMarketType = 0 + // Market type for cross margin perpetual markets. + PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS PerpetualMarketType = 1 + // Market type for isolated margin perpetual markets. + PerpetualMarketType_PERPETUAL_MARKET_TYPE_ISOLATED PerpetualMarketType = 2 +) + +var PerpetualMarketType_name = map[int32]string{ + 0: "PERPETUAL_MARKET_TYPE_UNSPECIFIED", + 1: "PERPETUAL_MARKET_TYPE_CROSS", + 2: "PERPETUAL_MARKET_TYPE_ISOLATED", +} + +var PerpetualMarketType_value = map[string]int32{ + "PERPETUAL_MARKET_TYPE_UNSPECIFIED": 0, + "PERPETUAL_MARKET_TYPE_CROSS": 1, + "PERPETUAL_MARKET_TYPE_ISOLATED": 2, +} + +func (x PerpetualMarketType) String() string { + return proto.EnumName(PerpetualMarketType_name, int32(x)) +} + +func (PerpetualMarketType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_ce7204eee10038be, []int{0} +} + // Perpetual represents a perpetual on the dYdX exchange. type Perpetual struct { // PerpetualParams is the parameters of the perpetual. @@ -94,6 +125,8 @@ type PerpetualParams struct { DefaultFundingPpm int32 `protobuf:"zigzag32,5,opt,name=default_funding_ppm,json=defaultFundingPpm,proto3" json:"default_funding_ppm,omitempty"` // The liquidity_tier that this perpetual is associated with. LiquidityTier uint32 `protobuf:"varint,6,opt,name=liquidity_tier,json=liquidityTier,proto3" json:"liquidity_tier,omitempty"` + // The market type specifying if this perpetual is cross or isolated + MarketType PerpetualMarketType `protobuf:"varint,7,opt,name=market_type,json=marketType,proto3,enum=dydxprotocol.perpetuals.PerpetualMarketType" json:"market_type,omitempty"` } func (m *PerpetualParams) Reset() { *m = PerpetualParams{} } @@ -171,6 +204,13 @@ func (m *PerpetualParams) GetLiquidityTier() uint32 { return 0 } +func (m *PerpetualParams) GetMarketType() PerpetualMarketType { + if m != nil { + return m.MarketType + } + return PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED +} + // MarketPremiums stores a list of premiums for a single perpetual market. type MarketPremiums struct { // perpetual_id is the Id of the perpetual market. @@ -399,6 +439,7 @@ func (m *LiquidityTier) GetImpactNotional() uint64 { } func init() { + proto.RegisterEnum("dydxprotocol.perpetuals.PerpetualMarketType", PerpetualMarketType_name, PerpetualMarketType_value) proto.RegisterType((*Perpetual)(nil), "dydxprotocol.perpetuals.Perpetual") proto.RegisterType((*PerpetualParams)(nil), "dydxprotocol.perpetuals.PerpetualParams") proto.RegisterType((*MarketPremiums)(nil), "dydxprotocol.perpetuals.MarketPremiums") @@ -411,45 +452,51 @@ func init() { } var fileDescriptor_ce7204eee10038be = []byte{ - // 595 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x4f, 0x4b, 0x1b, 0x4f, - 0x18, 0xce, 0xc4, 0xfc, 0x82, 0x8e, 0x49, 0x34, 0xa3, 0xf8, 0x5b, 0x2c, 0xc4, 0x34, 0x50, 0x0c, - 0xb4, 0xdd, 0x80, 0xed, 0xa1, 0x87, 0x1e, 0x4a, 0x0e, 0xd2, 0x40, 0x6d, 0xc3, 0x5a, 0x7a, 0x28, - 0x94, 0x65, 0xb2, 0x3b, 0xc6, 0x17, 0xe7, 0xcf, 0x76, 0x76, 0xb6, 0x68, 0x3f, 0x85, 0x9f, 0xa9, - 0x27, 0x8f, 0x1e, 0x8b, 0x07, 0x29, 0xfa, 0x3d, 0x4a, 0xd9, 0xd9, 0xc9, 0x26, 0x56, 0x84, 0x9e, - 0x32, 0xf3, 0x3e, 0xcf, 0xf3, 0xe6, 0x79, 0xe7, 0x99, 0x59, 0xbc, 0x1b, 0x9f, 0xc5, 0xa7, 0x89, - 0x56, 0x46, 0x45, 0x8a, 0x0f, 0x12, 0xa6, 0x13, 0x66, 0x32, 0xca, 0xd3, 0xf9, 0xd2, 0xb7, 0x28, - 0xf9, 0x7f, 0x91, 0xe8, 0xcf, 0x89, 0xdb, 0x9b, 0x53, 0x35, 0x55, 0x16, 0x18, 0xe4, 0xab, 0x82, - 0xde, 0xfb, 0x81, 0xf0, 0xca, 0x78, 0x46, 0x22, 0xfb, 0xb8, 0x9e, 0x50, 0x4d, 0x45, 0xea, 0xa1, - 0x2e, 0xea, 0xaf, 0xee, 0xf5, 0xfd, 0x07, 0xba, 0xf9, 0xa5, 0x66, 0x6c, 0xf9, 0xc3, 0xda, 0xc5, - 0xf5, 0x4e, 0x25, 0x70, 0x6a, 0x22, 0x70, 0xf3, 0x28, 0x93, 0x31, 0xc8, 0x69, 0x08, 0x32, 0x66, - 0xa7, 0x5e, 0xb5, 0x8b, 0xfa, 0x8d, 0xe1, 0xdb, 0x9c, 0x74, 0x75, 0xbd, 0xf3, 0x66, 0x0a, 0xe6, - 0x38, 0x9b, 0xf8, 0x91, 0x12, 0x83, 0x3b, 0x73, 0x7d, 0x7b, 0xf9, 0x3c, 0x3a, 0xa6, 0x20, 0x07, - 0x65, 0x25, 0x36, 0x67, 0x09, 0x4b, 0xfd, 0x43, 0xa6, 0x81, 0x72, 0xf8, 0x4e, 0x27, 0x9c, 0x8d, - 0xa4, 0x09, 0x1a, 0xae, 0xfd, 0x28, 0xef, 0xde, 0xbb, 0x42, 0x78, 0xed, 0x2f, 0x43, 0xa4, 0x85, - 0xab, 0x10, 0xdb, 0x31, 0x9a, 0x41, 0x15, 0x62, 0xb2, 0x85, 0xeb, 0x06, 0xa2, 0x13, 0xa6, 0xad, - 0x97, 0x95, 0xc0, 0xed, 0xc8, 0x23, 0xbc, 0x22, 0xa8, 0x3e, 0x61, 0x26, 0x84, 0xd8, 0x5b, 0xb2, - 0xf4, 0xe5, 0xa2, 0x30, 0x8a, 0xc9, 0x53, 0xdc, 0xa6, 0x46, 0x09, 0x88, 0x42, 0xcd, 0x52, 0xc5, - 0x33, 0x03, 0x4a, 0x7a, 0xb5, 0x2e, 0xea, 0xb7, 0x83, 0xf5, 0x02, 0x08, 0xca, 0x3a, 0xf1, 0xf1, - 0x46, 0xcc, 0x8e, 0x68, 0xc6, 0x4d, 0x38, 0x1b, 0x3e, 0x49, 0x84, 0xf7, 0x9f, 0xa5, 0xb7, 0x1d, - 0xb4, 0x5f, 0x20, 0xe3, 0x44, 0x90, 0x27, 0xb8, 0xc5, 0xe1, 0x6b, 0x06, 0x31, 0x98, 0xb3, 0xd0, - 0x00, 0xd3, 0x5e, 0xdd, 0xfe, 0x7d, 0xb3, 0xac, 0x7e, 0x04, 0xa6, 0x7b, 0x1f, 0x70, 0xeb, 0xc0, - 0xfa, 0x19, 0x6b, 0x26, 0x20, 0x13, 0x29, 0x79, 0x8c, 0x1b, 0x65, 0x12, 0x61, 0x39, 0xe4, 0x6a, - 0x59, 0x1b, 0xc5, 0x64, 0x1b, 0x2f, 0x27, 0x8e, 0xee, 0x55, 0xbb, 0x4b, 0xfd, 0x76, 0x50, 0xee, - 0x7b, 0xe7, 0x08, 0x37, 0x5c, 0xaf, 0x43, 0xa3, 0x34, 0x23, 0x5f, 0xf0, 0x06, 0xe5, 0x3c, 0x74, - 0xc7, 0x50, 0xea, 0x50, 0x77, 0xa9, 0xbf, 0xba, 0xb7, 0xfb, 0xe0, 0x15, 0xb8, 0xeb, 0xca, 0xdd, - 0x80, 0x36, 0xe5, 0xfc, 0xbe, 0x5d, 0x99, 0x89, 0x70, 0xc1, 0x8f, 0xb5, 0x2b, 0x33, 0x31, 0xa3, - 0xf4, 0x7e, 0x23, 0xdc, 0x7c, 0xb7, 0x38, 0xf5, 0xbd, 0xf8, 0x08, 0xae, 0x49, 0x2a, 0x98, 0x0b, - 0xcf, 0xae, 0xc9, 0x33, 0x4c, 0x40, 0x82, 0x01, 0x6a, 0xbd, 0x4f, 0x41, 0xda, 0xf3, 0x2e, 0x32, - 0x5c, 0x77, 0xc8, 0x81, 0x05, 0xf2, 0xe3, 0x7e, 0x85, 0x3d, 0x41, 0x41, 0x1a, 0x26, 0xa9, 0x8c, - 0x58, 0x78, 0xa4, 0x69, 0x94, 0xc7, 0x66, 0x35, 0x35, 0xab, 0xd9, 0x5a, 0xc0, 0xf7, 0x1d, 0x5c, - 0x28, 0xb7, 0x26, 0x34, 0x65, 0x61, 0xa2, 0x52, 0xb0, 0x12, 0xa9, 0xf2, 0x1f, 0xca, 0x6d, 0xb6, - 0xb5, 0x61, 0xd5, 0x43, 0xc1, 0x66, 0xce, 0x18, 0x3b, 0xc2, 0x7b, 0x87, 0x93, 0x5d, 0xbc, 0x06, - 0x22, 0xa1, 0x91, 0x99, 0x4b, 0xf2, 0x8c, 0x6b, 0x41, 0xab, 0x28, 0xcf, 0x88, 0xc3, 0x4f, 0x17, - 0x37, 0x1d, 0x74, 0x79, 0xd3, 0x41, 0xbf, 0x6e, 0x3a, 0xe8, 0xfc, 0xb6, 0x53, 0xb9, 0xbc, 0xed, - 0x54, 0x7e, 0xde, 0x76, 0x2a, 0x9f, 0x5f, 0xff, 0xfb, 0x5b, 0x39, 0x5d, 0xfc, 0x2e, 0xd8, 0x77, - 0x33, 0xa9, 0x5b, 0xf0, 0xc5, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf9, 0xc0, 0xd9, 0x87, 0x3f, - 0x04, 0x00, 0x00, + // 696 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0x4f, 0x4f, 0xdb, 0x3e, + 0x18, 0xae, 0x4b, 0x7f, 0xfd, 0x81, 0xfb, 0x87, 0xd6, 0x20, 0x16, 0x81, 0x54, 0x4a, 0x25, 0x44, + 0xb5, 0xb1, 0x56, 0x62, 0x3b, 0xec, 0xb0, 0xc3, 0x28, 0xb4, 0x5a, 0x35, 0x0a, 0x51, 0x5a, 0x26, + 0x6d, 0xd2, 0x14, 0xb9, 0x89, 0x29, 0x16, 0xb1, 0x93, 0x25, 0xce, 0x44, 0x77, 0xdb, 0x37, 0xe0, + 0x6b, 0xec, 0x6b, 0xec, 0xc4, 0x91, 0xe3, 0xb4, 0x03, 0x9a, 0xe0, 0x7b, 0x4c, 0x53, 0x1c, 0x37, + 0x14, 0x06, 0xda, 0x4e, 0x7d, 0xfd, 0x3e, 0xcf, 0xf3, 0xf6, 0xb1, 0xfd, 0xc4, 0x70, 0xc3, 0x1e, + 0xdb, 0xa7, 0x9e, 0xef, 0x0a, 0xd7, 0x72, 0x9d, 0xa6, 0x47, 0x7c, 0x8f, 0x88, 0x10, 0x3b, 0xc1, + 0x4d, 0xd9, 0x90, 0x28, 0x7a, 0x34, 0x4d, 0x6c, 0xdc, 0x10, 0x97, 0x17, 0x47, 0xee, 0xc8, 0x95, + 0x40, 0x33, 0xaa, 0x62, 0x7a, 0xed, 0x1b, 0x80, 0x73, 0xfa, 0x84, 0x84, 0x3a, 0x30, 0xeb, 0x61, + 0x1f, 0xb3, 0x40, 0x03, 0x55, 0x50, 0xcf, 0x6d, 0xd5, 0x1b, 0x0f, 0x4c, 0x6b, 0x24, 0x1a, 0x5d, + 0xf2, 0x5b, 0x99, 0xf3, 0xcb, 0xd5, 0x94, 0xa1, 0xd4, 0x88, 0xc1, 0xc2, 0x51, 0xc8, 0x6d, 0xca, + 0x47, 0x26, 0xe5, 0x36, 0x39, 0xd5, 0xd2, 0x55, 0x50, 0xcf, 0xb7, 0x5e, 0x47, 0xa4, 0x1f, 0x97, + 0xab, 0xaf, 0x46, 0x54, 0x1c, 0x87, 0xc3, 0x86, 0xe5, 0xb2, 0xe6, 0xad, 0x7d, 0x7d, 0x7a, 0xfe, + 0xd4, 0x3a, 0xc6, 0x94, 0x37, 0x93, 0x8e, 0x2d, 0xc6, 0x1e, 0x09, 0x1a, 0x7d, 0xe2, 0x53, 0xec, + 0xd0, 0xcf, 0x78, 0xe8, 0x90, 0x2e, 0x17, 0x46, 0x5e, 0x8d, 0xef, 0x46, 0xd3, 0x6b, 0x5f, 0xd3, + 0x70, 0xfe, 0x8e, 0x21, 0x54, 0x84, 0x69, 0x6a, 0xcb, 0x6d, 0x14, 0x8c, 0x34, 0xb5, 0xd1, 0x12, + 0xcc, 0x0a, 0x6a, 0x9d, 0x10, 0x5f, 0x7a, 0x99, 0x33, 0xd4, 0x0a, 0xad, 0xc0, 0x39, 0x86, 0xfd, + 0x13, 0x22, 0x4c, 0x6a, 0x6b, 0x33, 0x92, 0x3e, 0x1b, 0x37, 0xba, 0x36, 0x7a, 0x02, 0xcb, 0x58, + 0xb8, 0x8c, 0x5a, 0xa6, 0x4f, 0x02, 0xd7, 0x09, 0x05, 0x75, 0xb9, 0x96, 0xa9, 0x82, 0x7a, 0xd9, + 0x28, 0xc5, 0x80, 0x91, 0xf4, 0x51, 0x03, 0x2e, 0xd8, 0xe4, 0x08, 0x87, 0x8e, 0x30, 0x27, 0x9b, + 0xf7, 0x3c, 0xa6, 0xfd, 0x27, 0xe9, 0x65, 0x05, 0x75, 0x62, 0x44, 0xf7, 0x18, 0x5a, 0x87, 0x45, + 0x87, 0x7e, 0x0c, 0xa9, 0x4d, 0xc5, 0xd8, 0x14, 0x94, 0xf8, 0x5a, 0x56, 0xfe, 0x7d, 0x21, 0xe9, + 0x0e, 0x28, 0xf1, 0x51, 0x0f, 0xe6, 0x94, 0xc1, 0xe8, 0x28, 0xb4, 0xff, 0xab, 0xa0, 0x5e, 0xdc, + 0xda, 0xfc, 0xfb, 0xc5, 0xf4, 0xa4, 0x68, 0x30, 0xf6, 0x88, 0x01, 0x59, 0x52, 0xd7, 0x0e, 0x60, + 0x31, 0x46, 0x74, 0x9f, 0x30, 0x1a, 0xb2, 0x00, 0xad, 0xc1, 0x7c, 0xa2, 0x37, 0x93, 0x33, 0xcb, + 0x25, 0xbd, 0xae, 0x8d, 0x96, 0xe1, 0xac, 0xa7, 0xe8, 0x5a, 0xba, 0x3a, 0x53, 0x2f, 0x1b, 0xc9, + 0xba, 0x76, 0x06, 0x60, 0x5e, 0xcd, 0xea, 0x0b, 0xd7, 0x27, 0xe8, 0x03, 0x5c, 0xc0, 0x8e, 0x63, + 0x2a, 0xd3, 0x89, 0x0e, 0x54, 0x67, 0xea, 0xb9, 0xad, 0x8d, 0x07, 0x8d, 0xdf, 0x76, 0xa5, 0x02, + 0x55, 0xc6, 0x8e, 0xf3, 0xa7, 0x5d, 0x1e, 0x32, 0x73, 0xca, 0x8f, 0xb4, 0xcb, 0x43, 0x36, 0xa1, + 0xd4, 0x7e, 0x01, 0x58, 0xd8, 0xbb, 0x75, 0x88, 0x77, 0xd3, 0x80, 0x60, 0x86, 0x63, 0x46, 0x54, + 0x16, 0x64, 0x8d, 0x36, 0x21, 0xa2, 0x9c, 0x0a, 0x8a, 0xa5, 0xf7, 0x11, 0xe5, 0xf2, 0xfa, 0xe2, + 0x48, 0x94, 0x14, 0xd2, 0x93, 0x40, 0x74, 0x7b, 0x2f, 0xa0, 0xc6, 0x30, 0xe5, 0x82, 0x70, 0xcc, + 0x2d, 0x62, 0x1e, 0xf9, 0xd8, 0x8a, 0x52, 0x20, 0x35, 0x19, 0xa9, 0x59, 0x9a, 0xc2, 0x3b, 0x0a, + 0x8e, 0x95, 0x4b, 0x43, 0x1c, 0x10, 0xd3, 0x73, 0x03, 0x2a, 0x25, 0xdc, 0x8d, 0x7e, 0xb0, 0x23, + 0xa3, 0x92, 0x69, 0xa5, 0x35, 0x60, 0x2c, 0x46, 0x0c, 0x5d, 0x11, 0xf6, 0x15, 0x8e, 0x36, 0xe0, + 0x3c, 0x65, 0x1e, 0xb6, 0xc4, 0x8d, 0x24, 0x8a, 0x4c, 0xc6, 0x28, 0xc6, 0xed, 0x09, 0xf1, 0xf1, + 0x17, 0x00, 0x17, 0xee, 0x09, 0x02, 0x5a, 0x87, 0x6b, 0x7a, 0xdb, 0xd0, 0xdb, 0x83, 0xc3, 0xed, + 0x3d, 0xb3, 0xb7, 0x6d, 0xbc, 0x69, 0x0f, 0xcc, 0xc1, 0x3b, 0xbd, 0x6d, 0x1e, 0xee, 0xf7, 0xf5, + 0xf6, 0x4e, 0xb7, 0xd3, 0x6d, 0xef, 0x96, 0x52, 0x68, 0x15, 0xae, 0xdc, 0x4f, 0xdb, 0x31, 0x0e, + 0xfa, 0xfd, 0x12, 0x40, 0x35, 0x58, 0xb9, 0x9f, 0xd0, 0xed, 0x1f, 0xec, 0x6d, 0x0f, 0xda, 0xbb, + 0xa5, 0x74, 0xeb, 0xed, 0xf9, 0x55, 0x05, 0x5c, 0x5c, 0x55, 0xc0, 0xcf, 0xab, 0x0a, 0x38, 0xbb, + 0xae, 0xa4, 0x2e, 0xae, 0x2b, 0xa9, 0xef, 0xd7, 0x95, 0xd4, 0xfb, 0x97, 0xff, 0xfe, 0xf9, 0x9f, + 0x4e, 0x3f, 0x75, 0xf2, 0x29, 0x18, 0x66, 0x25, 0xf8, 0xec, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xc6, 0x3a, 0xfc, 0x1e, 0x12, 0x05, 0x00, 0x00, } func (m *Perpetual) Marshal() (dAtA []byte, err error) { @@ -515,6 +562,11 @@ func (m *PerpetualParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MarketType != 0 { + i = encodeVarintPerpetual(dAtA, i, uint64(m.MarketType)) + i-- + dAtA[i] = 0x38 + } if m.LiquidityTier != 0 { i = encodeVarintPerpetual(dAtA, i, uint64(m.LiquidityTier)) i-- @@ -743,6 +795,9 @@ func (m *PerpetualParams) Size() (n int) { if m.LiquidityTier != 0 { n += 1 + sovPerpetual(uint64(m.LiquidityTier)) } + if m.MarketType != 0 { + n += 1 + sovPerpetual(uint64(m.MarketType)) + } return n } @@ -1093,6 +1148,25 @@ func (m *PerpetualParams) Unmarshal(dAtA []byte) error { break } } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MarketType", wireType) + } + m.MarketType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPerpetual + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MarketType |= PerpetualMarketType(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPerpetual(dAtA[iNdEx:]) diff --git a/protocol/x/perpetuals/types/types.go b/protocol/x/perpetuals/types/types.go index f9a97f1a68..7b7489cf06 100644 --- a/protocol/x/perpetuals/types/types.go +++ b/protocol/x/perpetuals/types/types.go @@ -76,6 +76,7 @@ type PerpetualsKeeper interface { atomicResolution int32, defaultFundingPpm int32, liquidityTier uint32, + marketType PerpetualMarketType, ) (Perpetual, error) ModifyPerpetual( ctx sdk.Context, diff --git a/protocol/x/sending/keeper/transfer_test.go b/protocol/x/sending/keeper/transfer_test.go index 408f471fb8..10c4f0d3c4 100644 --- a/protocol/x/sending/keeper/transfer_test.go +++ b/protocol/x/sending/keeper/transfer_test.go @@ -1,14 +1,15 @@ package keeper_test import ( - sdkmath "cosmossdk.io/math" "errors" "fmt" - "github.com/cosmos/gogoproto/proto" - "github.com/dydxprotocol/v4-chain/protocol/lib" "math/big" "testing" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/gogoproto/proto" + "github.com/dydxprotocol/v4-chain/protocol/lib" + indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" "github.com/dydxprotocol/v4-chain/protocol/mocks" "github.com/dydxprotocol/v4-chain/protocol/x/sending/keeper" @@ -131,6 +132,7 @@ func runProcessTransferTest(t *testing.T, tc TransferTestCase) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -257,6 +259,7 @@ func TestProcessTransfer_CreateRecipientAccount(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } diff --git a/protocol/x/subaccounts/keeper/subaccount_test.go b/protocol/x/subaccounts/keeper/subaccount_test.go index eb56b9be29..30247ffd3a 100644 --- a/protocol/x/subaccounts/keeper/subaccount_test.go +++ b/protocol/x/subaccounts/keeper/subaccount_test.go @@ -2042,6 +2042,7 @@ func TestUpdateSubaccounts(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) @@ -2803,6 +2804,7 @@ func TestUpdateSubaccounts_WithdrawalsBlocked(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) @@ -3421,6 +3423,7 @@ func TestCanUpdateSubaccounts(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) } @@ -3817,6 +3820,7 @@ func TestGetNetCollateralAndMarginRequirements(t *testing.T) { p.Params.AtomicResolution, p.Params.DefaultFundingPpm, p.Params.LiquidityTier, + p.Params.MarketType, ) require.NoError(t, err) }