Skip to content

Commit a424640

Browse files
authored
[ENG-33] Add cross_launch field to Market Map metadata JSON (Redo after changing main branch to Slinky v1.2.0)
1 parent 53c0d9c commit a424640

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

x/marketmap/types/tickermetadata/dydx.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ type DyDx struct {
1616
// AggregateIDs contains a list of AggregatorIDs associated with the ticker.
1717
// This field may not be populated if no aggregator currently indexes this Ticker.
1818
AggregateIDs []AggregatorID `json:"aggregate_ids"`
19+
// CrossLaunch is an optional bool that indicates whether this ticker should be
20+
// launched as a cross-margin market (instead of isolated margin).
21+
// If omitted, it is set to false by default.
22+
CrossLaunch bool `json:"cross_launch,omitempty"`
1923
}
2024

2125
// NewDyDx returns a new DyDx instance.
22-
func NewDyDx(referencePrice, liquidity uint64, aggregateIDs []AggregatorID) DyDx {
26+
func NewDyDx(referencePrice, liquidity uint64, aggregateIDs []AggregatorID, crossLaunch bool) DyDx {
2327
return DyDx{
2428
ReferencePrice: referencePrice,
2529
Liquidity: liquidity,
2630
AggregateIDs: aggregateIDs,
31+
CrossLaunch: crossLaunch,
2732
}
2833
}
2934

x/marketmap/types/tickermetadata/dydx_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func Test_UnmarshalDyDx(t *testing.T) {
1717
tickermetadata.NewAggregatorID("coingecko", "id"),
1818
tickermetadata.NewAggregatorID("cmc", "id"),
1919
},
20+
false,
2021
)
2122

2223
bz, err := tickermetadata.MarshalDyDx(elem)
@@ -28,7 +29,7 @@ func Test_UnmarshalDyDx(t *testing.T) {
2829
})
2930

3031
t.Run("can marshal and unmarshal the same struct and values with empty AggregatorIDs", func(t *testing.T) {
31-
elem := tickermetadata.NewDyDx(100, 1000, nil)
32+
elem := tickermetadata.NewDyDx(100, 1000, nil, false)
3233

3334
bz, err := tickermetadata.MarshalDyDx(elem)
3435
require.NoError(t, err)
@@ -50,6 +51,39 @@ func Test_UnmarshalDyDx(t *testing.T) {
5051
tickermetadata.NewAggregatorID("coingecko", "id"),
5152
tickermetadata.NewAggregatorID("cmc", "id"),
5253
},
54+
false,
55+
), elem)
56+
})
57+
58+
t.Run("can unmarshal a JSON string into a struct with empty CrossLaunch field", func(t *testing.T) {
59+
elemJSON := `{"reference_price":100,"liquidity":1000,"aggregate_ids":[{"venue":"coingecko","ID":"id"},{"venue":"cmc","ID":"id"}]}`
60+
elem, err := tickermetadata.DyDxFromJSONString(elemJSON)
61+
require.NoError(t, err)
62+
63+
require.Equal(t, tickermetadata.NewDyDx(
64+
100,
65+
1000,
66+
[]tickermetadata.AggregatorID{
67+
tickermetadata.NewAggregatorID("coingecko", "id"),
68+
tickermetadata.NewAggregatorID("cmc", "id"),
69+
},
70+
false,
71+
), elem)
72+
})
73+
74+
t.Run("can unmarshal a JSON string into a struct with CrossLaunch field set", func(t *testing.T) {
75+
elemJSON := `{"reference_price":100,"liquidity":1000,"aggregate_ids":[{"venue":"coingecko","ID":"id"},{"venue":"cmc","ID":"id"}],"cross_launch":true}`
76+
elem, err := tickermetadata.DyDxFromJSONString(elemJSON)
77+
require.NoError(t, err)
78+
79+
require.Equal(t, tickermetadata.NewDyDx(
80+
100,
81+
1000,
82+
[]tickermetadata.AggregatorID{
83+
tickermetadata.NewAggregatorID("coingecko", "id"),
84+
tickermetadata.NewAggregatorID("cmc", "id"),
85+
},
86+
true,
5387
), elem)
5488
})
5589
}

0 commit comments

Comments
 (0)