Skip to content

Commit

Permalink
[CT-645] Add protos for orderbook stream query service
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Mar 1, 2024
1 parent 7fd1d4f commit 1df8a76
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package dydxprotocol.indexer.off_chain_updates;
import "dydxprotocol/indexer/shared/removal_reason.proto";
import "dydxprotocol/indexer/protocol/v1/clob.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates";
option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates/types";

// Do not make any breaking changes to these protos, a new version should be
// created if a breaking change is needed.
Expand Down
2 changes: 1 addition & 1 deletion proto/dydxprotocol/indexer/protocol/v1/clob.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package dydxprotocol.indexer.protocol.v1;
import "dydxprotocol/indexer/protocol/v1/subaccount.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1";
option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1/types";

// Initial copy of protos from dYdX chain application state protos for the clob
// module for use to send Indexer specific messages. Do not make any breaking
Expand Down
2 changes: 1 addition & 1 deletion proto/dydxprotocol/indexer/protocol/v1/subaccount.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package dydxprotocol.indexer.protocol.v1;
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1";
option go_package = "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1/types";

// Initial copy of protos from dYdX chain application state protos for the
// subaccount module for use to send Indexer specific messages. Do not make any
Expand Down
114 changes: 57 additions & 57 deletions protocol/indexer/events/events.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions protocol/indexer/events/perpetual_market_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package events
import (
"testing"

v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
v1types "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1/types"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"

"github.com/stretchr/testify/require"
Expand All @@ -27,7 +27,7 @@ func TestNewPerpetualMarketCreateEvent_Success(t *testing.T) {
ClobPairId: 0,
Ticker: "BTC",
MarketId: 0,
Status: v1.ClobPairStatus_CLOB_PAIR_STATUS_ACTIVE,
Status: v1types.ClobPairStatus_CLOB_PAIR_STATUS_ACTIVE,
QuantumConversionExponent: -8,
AtomicResolution: 8,
SubticksPerTick: 5,
Expand Down
34 changes: 18 additions & 16 deletions protocol/indexer/off_chain_updates/off_chain_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"crypto/sha256"
"errors"
"fmt"

"github.com/cosmos/gogoproto/proto"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/indexer/msgsender"
ocutypes "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates/types"
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
"github.com/dydxprotocol/v4-chain/protocol/indexer/shared"
"github.com/dydxprotocol/v4-chain/protocol/lib/log"
Expand Down Expand Up @@ -113,7 +115,7 @@ func MustCreateOrderRemoveMessageWithReason(
ctx sdk.Context,
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
removalStatus OrderRemoveV1_OrderRemovalStatus,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
) msgsender.Message {
msg, ok := CreateOrderRemoveMessageWithReason(ctx, orderId, reason, removalStatus)
if !ok {
Expand All @@ -128,7 +130,7 @@ func CreateOrderRemoveMessageWithReason(
ctx sdk.Context,
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
removalStatus OrderRemoveV1_OrderRemovalStatus,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
) (message msgsender.Message, success bool) {
errMessage := "Error creating off-chain update message for removing order."

Expand Down Expand Up @@ -167,7 +169,7 @@ func MustCreateOrderRemoveMessage(
orderId clobtypes.OrderId,
orderStatus clobtypes.OrderStatus,
orderError error,
removalStatus OrderRemoveV1_OrderRemovalStatus,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
) msgsender.Message {
msg, ok := CreateOrderRemoveMessage(ctx, orderId, orderStatus, orderError, removalStatus)
if !ok {
Expand All @@ -183,7 +185,7 @@ func CreateOrderRemoveMessage(
orderId clobtypes.OrderId,
orderStatus clobtypes.OrderStatus,
orderError error,
removalStatus OrderRemoveV1_OrderRemovalStatus,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
) (message msgsender.Message, success bool) {
reason, err := shared.GetOrderRemovalReason(orderStatus, orderError)
if err != nil {
Expand All @@ -210,7 +212,7 @@ func CreateOrderRemoveMessageWithDefaultReason(
orderId clobtypes.OrderId,
orderStatus clobtypes.OrderStatus,
orderError error,
removalStatus OrderRemoveV1_OrderRemovalStatus,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
defaultRemovalReason shared.OrderRemovalReason,
) (message msgsender.Message, success bool) {
if defaultRemovalReason == shared.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED {
Expand Down Expand Up @@ -243,12 +245,12 @@ func newOrderPlaceMessage(
order clobtypes.Order,
) ([]byte, error) {
indexerOrder := v1.OrderToIndexerOrder(order)
update := OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderPlace{
&OrderPlaceV1{
update := ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderPlace{
OrderPlace: &ocutypes.OrderPlaceV1{
Order: &indexerOrder,
// Protocol will always send best effort opened messages to indexer.
PlacementStatus: OrderPlaceV1_ORDER_PLACEMENT_STATUS_BEST_EFFORT_OPENED,
PlacementStatus: ocutypes.OrderPlaceV1_ORDER_PLACEMENT_STATUS_BEST_EFFORT_OPENED,
},
},
}
Expand All @@ -261,12 +263,12 @@ func newOrderPlaceMessage(
func newOrderRemoveMessage(
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
status OrderRemoveV1_OrderRemovalStatus,
status ocutypes.OrderRemoveV1_OrderRemovalStatus,
) ([]byte, error) {
indexerOrderId := v1.OrderIdToIndexerOrderId(orderId)
update := OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderRemove{
&OrderRemoveV1{
update := ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderRemove{
OrderRemove: &ocutypes.OrderRemoveV1{
RemovedOrderId: &indexerOrderId,
Reason: reason,
RemovalStatus: status,
Expand All @@ -284,9 +286,9 @@ func newOrderUpdateMessage(
totalFilled satypes.BaseQuantums,
) ([]byte, error) {
indexerOrderId := v1.OrderIdToIndexerOrderId(orderId)
update := OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderUpdate{
&OrderUpdateV1{
update := ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderUpdate{
OrderUpdate: &ocutypes.OrderUpdateV1{
OrderId: &indexerOrderId,
TotalFilledQuantums: totalFilled.ToUint64(),
},
Expand Down
35 changes: 18 additions & 17 deletions protocol/indexer/off_chain_updates/off_chain_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/gogoproto/proto"
"github.com/dydxprotocol/v4-chain/protocol/indexer/msgsender"
ocutypes "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates/types"
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
"github.com/dydxprotocol/v4-chain/protocol/indexer/shared"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
Expand All @@ -24,36 +25,36 @@ var (
orderStatus = clobtypes.Undercollateralized
orderError error = nil
reason = shared.OrderRemovalReason_ORDER_REMOVAL_REASON_UNDERCOLLATERALIZED
status = OrderRemoveV1_ORDER_REMOVAL_STATUS_BEST_EFFORT_CANCELED
status = ocutypes.OrderRemoveV1_ORDER_REMOVAL_STATUS_BEST_EFFORT_CANCELED
defaultRemovalReason = shared.OrderRemovalReason_ORDER_REMOVAL_REASON_INTERNAL_ERROR
offchainUpdateOrderPlace = OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderPlace{
&OrderPlaceV1{
offchainUpdateOrderPlace = ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderPlace{
OrderPlace: &ocutypes.OrderPlaceV1{
Order: &indexerOrder,
PlacementStatus: OrderPlaceV1_ORDER_PLACEMENT_STATUS_BEST_EFFORT_OPENED,
PlacementStatus: ocutypes.OrderPlaceV1_ORDER_PLACEMENT_STATUS_BEST_EFFORT_OPENED,
},
},
}
offchainUpdateOrderUpdate = OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderUpdate{
&OrderUpdateV1{
offchainUpdateOrderUpdate = ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderUpdate{
OrderUpdate: &ocutypes.OrderUpdateV1{
OrderId: &indexerOrder.OrderId,
TotalFilledQuantums: totalFilledAmount.ToUint64(),
},
},
}
offchainUpdateOrderRemove = OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderRemove{
&OrderRemoveV1{
offchainUpdateOrderRemove = ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderRemove{
OrderRemove: &ocutypes.OrderRemoveV1{
RemovedOrderId: &indexerOrder.OrderId,
Reason: reason,
RemovalStatus: status,
},
},
}
offchainUpdateOrderRemoveWithDefaultRemovalReason = OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderRemove{
&OrderRemoveV1{
offchainUpdateOrderRemoveWithDefaultRemovalReason = ocutypes.OffChainUpdateV1{
UpdateMessage: &ocutypes.OffChainUpdateV1_OrderRemove{
OrderRemove: &ocutypes.OrderRemoveV1{
RemovedOrderId: &indexerOrder.OrderId,
Reason: defaultRemovalReason,
RemovalStatus: status,
Expand Down Expand Up @@ -212,7 +213,7 @@ func TestNewOrderPlaceMessage(t *testing.T) {
err,
"Encoding OffchainUpdateV1 proto into bytes should not result in an error.",
)
actualUpdate := &OffChainUpdateV1{}
actualUpdate := &ocutypes.OffChainUpdateV1{}
err = proto.Unmarshal(actualUpdateBytes, actualUpdate)
require.NoError(
t,
Expand All @@ -234,7 +235,7 @@ func TestNewOrderUpdateMessage(t *testing.T) {
err,
"Encoding OffchainUpdateV1 proto into bytes should not result in an error.",
)
actualUpdate := &OffChainUpdateV1{}
actualUpdate := &ocutypes.OffChainUpdateV1{}
err = proto.Unmarshal(actualUpdateBytes, actualUpdate)
require.NoError(
t,
Expand All @@ -256,7 +257,7 @@ func TestNewOrderRemoveMessage(t *testing.T) {
err,
"Encoding OffchainUpdateV1 proto into bytes should not result in an error.",
)
actualUpdate := &OffChainUpdateV1{}
actualUpdate := &ocutypes.OffChainUpdateV1{}
err = proto.Unmarshal(actualUpdateBytes, actualUpdate)
require.NoError(
t,
Expand Down
Loading

0 comments on commit 1df8a76

Please sign in to comment.