Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-645] Move off chain updates and v1 to a different package #1131

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion proto/dydxprotocol/indexer/shared/removal_reason.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package dydxprotocol.indexer.shared;

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

// TODO(DEC-869): Update reasons/statuses for Advanced Orders.

Expand Down
124 changes: 62 additions & 62 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
6 changes: 3 additions & 3 deletions protocol/indexer/events/stateful_order.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package events

import (
"github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
"github.com/dydxprotocol/v4-chain/protocol/indexer/shared"
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
sharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
)

Expand All @@ -22,7 +22,7 @@ func NewLongTermOrderPlacementEvent(

func NewStatefulOrderRemovalEvent(
removedOrderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
reason sharedtypes.OrderRemovalReason,
) *StatefulOrderEventV1 {
orderId := v1.OrderIdToIndexerOrderId(removedOrderId)
orderRemoval := StatefulOrderEventV1_StatefulOrderRemovalV1{
Expand Down
6 changes: 3 additions & 3 deletions protocol/indexer/events/stateful_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/dydxprotocol/v4-chain/protocol/indexer/events"
"github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
"github.com/dydxprotocol/v4-chain/protocol/indexer/shared"
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
sharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,7 +15,7 @@ var (
indexerOrder = v1.OrderToIndexerOrder(order)
orderId = constants.OrderId_Alice_Num0_ClientId0_Clob0
indexerOrderId = v1.OrderIdToIndexerOrderId(orderId)
reason = shared.OrderRemovalReason_ORDER_REMOVAL_REASON_REPLACED
reason = sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_REPLACED
)

func TestLongTermOrderPlacementEvent_Success(t *testing.T) {
Expand Down
45 changes: 24 additions & 21 deletions protocol/indexer/off_chain_updates/off_chain_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ 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"
sharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types"
"github.com/dydxprotocol/v4-chain/protocol/lib/log"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
Expand Down Expand Up @@ -112,8 +115,8 @@ func CreateOrderUpdateMessage(
func MustCreateOrderRemoveMessageWithReason(
ctx sdk.Context,
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
removalStatus OrderRemoveV1_OrderRemovalStatus,
reason sharedtypes.OrderRemovalReason,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
) msgsender.Message {
msg, ok := CreateOrderRemoveMessageWithReason(ctx, orderId, reason, removalStatus)
if !ok {
Expand All @@ -127,8 +130,8 @@ func MustCreateOrderRemoveMessageWithReason(
func CreateOrderRemoveMessageWithReason(
ctx sdk.Context,
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
removalStatus OrderRemoveV1_OrderRemovalStatus,
reason sharedtypes.OrderRemovalReason,
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 +170,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 +186,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,10 +213,10 @@ func CreateOrderRemoveMessageWithDefaultReason(
orderId clobtypes.OrderId,
orderStatus clobtypes.OrderStatus,
orderError error,
removalStatus OrderRemoveV1_OrderRemovalStatus,
defaultRemovalReason shared.OrderRemovalReason,
removalStatus ocutypes.OrderRemoveV1_OrderRemovalStatus,
defaultRemovalReason sharedtypes.OrderRemovalReason,
) (message msgsender.Message, success bool) {
if defaultRemovalReason == shared.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED {
if defaultRemovalReason == sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED {
panic(
fmt.Errorf(
"Invalid parameter: " +
Expand Down Expand Up @@ -243,12 +246,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 @@ -260,13 +263,13 @@ func newOrderPlaceMessage(
// The `OrderRemove` struct is instantiated with the given orderId, reason and status parameters.
func newOrderRemoveMessage(
orderId clobtypes.OrderId,
reason shared.OrderRemovalReason,
status OrderRemoveV1_OrderRemovalStatus,
reason sharedtypes.OrderRemovalReason,
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 +287,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
43 changes: 22 additions & 21 deletions protocol/indexer/off_chain_updates/off_chain_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ 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"
sharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"github.com/dydxprotocol/v4-chain/protocol/testutil/sdk"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
Expand All @@ -23,37 +24,37 @@ var (
totalFilledAmount = satypes.BaseQuantums(5)
orderStatus = clobtypes.Undercollateralized
orderError error = nil
reason = shared.OrderRemovalReason_ORDER_REMOVAL_REASON_UNDERCOLLATERALIZED
status = OrderRemoveV1_ORDER_REMOVAL_STATUS_BEST_EFFORT_CANCELED
defaultRemovalReason = shared.OrderRemovalReason_ORDER_REMOVAL_REASON_INTERNAL_ERROR
offchainUpdateOrderPlace = OffChainUpdateV1{
UpdateMessage: &OffChainUpdateV1_OrderPlace{
&OrderPlaceV1{
reason = sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_UNDERCOLLATERALIZED
status = ocutypes.OrderRemoveV1_ORDER_REMOVAL_STATUS_BEST_EFFORT_CANCELED
defaultRemovalReason = sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_INTERNAL_ERROR
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 @@ -177,7 +178,7 @@ func TestCreateOrderRemoveMessageWithDefaultReason_InvalidDefault(t *testing.T)
clobtypes.Success,
orderError,
status,
shared.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED,
sharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED,
)
},
)
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
Loading