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

[OTE-877] deprecate OI indexer update event (backport #2499) #2507

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -1365,31 +1365,47 @@ export interface AddressTradingRewardSDKType {

denom_amount: Uint8Array;
}
/** OpenInterestUpdateEventV1 is used for open interest update events */
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
*/

/** @deprecated */

export interface OpenInterestUpdateEventV1 {
/** The list of all open interest updates in the block. */
openInterestUpdates: OpenInterestUpdate[];
}
/** OpenInterestUpdateEventV1 is used for open interest update events */
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
*/

/** @deprecated */

export interface OpenInterestUpdateEventV1SDKType {
/** The list of all open interest updates in the block. */
open_interest_updates: OpenInterestUpdateSDKType[];
}
/** OpenInterestUpdate contains a single open interest update for a perpetual */
/**
* OpenInterestUpdate contains a single open interest update for a perpetual
* Deprecated.
*/

/** @deprecated */

export interface OpenInterestUpdate {
/** The ID of the perpetual market. */
perpetualId: number;
/** The new open interest value for the perpetual market. */

openInterest: Uint8Array;
}
/** OpenInterestUpdate contains a single open interest update for a perpetual */
/**
* OpenInterestUpdate contains a single open interest update for a perpetual
* Deprecated.
*/

/** @deprecated */

export interface OpenInterestUpdateSDKType {
/** The ID of the perpetual market. */
perpetual_id: number;
/** The new open interest value for the perpetual market. */

Expand Down
4 changes: 4 additions & 0 deletions proto/dydxprotocol/indexer/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,18 @@ message AddressTradingReward {
}

// OpenInterestUpdateEventV1 is used for open interest update events
// Deprecated.
message OpenInterestUpdateEventV1 {
// The list of all open interest updates in the block.
option deprecated = true;
repeated OpenInterestUpdate open_interest_updates = 1;
}

// OpenInterestUpdate contains a single open interest update for a perpetual
// Deprecated.
message OpenInterestUpdate {
// The ID of the perpetual market.
option deprecated = true;
uint32 perpetual_id = 1;

// The new open interest value for the perpetual market.
Expand Down
214 changes: 109 additions & 105 deletions protocol/indexer/events/events.pb.go

Large diffs are not rendered by default.

64 changes: 0 additions & 64 deletions protocol/x/clob/e2e/long_term_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,22 +824,6 @@ func TestPlaceLongTermOrder(t *testing.T) {
EventIndex: 2,
Version: indexerevents.OrderFillEventVersion,
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewInt(10_000_000_000),
},
},
}),
},
},
TxHashes: []string{
string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
Expand Down Expand Up @@ -1167,22 +1151,6 @@ func TestPlaceLongTermOrder(t *testing.T) {
EventIndex: 2,
Version: indexerevents.OrderFillEventVersion,
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewInt(10_000_000_000),
},
},
}),
},
},
TxHashes: []string{
string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
Expand Down Expand Up @@ -1337,22 +1305,6 @@ func TestPlaceLongTermOrder(t *testing.T) {
EventIndex: 2,
Version: indexerevents.OrderFillEventVersion,
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewInt(20_000_000_000),
},
},
}),
},
},
TxHashes: []string{
string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
Expand Down Expand Up @@ -1735,22 +1687,6 @@ func TestRegression_InvalidTimeInForce(t *testing.T) {
EventIndex: 2,
Version: indexerevents.OrderFillEventVersion,
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewInt(10_000_000_000),
},
},
}),
},
},
TxHashes: []string{
string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
Expand Down
55 changes: 0 additions & 55 deletions protocol/x/clob/e2e/short_term_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/indexer"
indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events"
"github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager"
Expand Down Expand Up @@ -218,24 +217,6 @@ func TestPlaceOrder(t *testing.T) {
),
),
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewIntFromUint64(
PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetBigQuantums().Uint64(),
),
},
},
}),
},
},
TxHashes: []string{string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
OperationsQueue: []clobtypes.OperationRaw{
Expand Down Expand Up @@ -397,24 +378,6 @@ func TestPlaceOrder(t *testing.T) {
),
),
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewIntFromUint64(
PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBigQuantums().Uint64(),
),
},
},
}),
},
},
TxHashes: []string{string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
OperationsQueue: []clobtypes.OperationRaw{
Expand Down Expand Up @@ -576,24 +539,6 @@ func TestPlaceOrder(t *testing.T) {
),
),
},
{
Subtype: indexerevents.SubtypeOpenInterestUpdate,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{
BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
},
Version: indexerevents.OpenInterestUpdateVersion,
DataBytes: indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: []*indexerevents.OpenInterestUpdate{
{
PerpetualId: Clob_0.MustGetPerpetualId(),
OpenInterest: dtypes.NewIntFromUint64(
PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBigQuantums().Uint64(),
),
},
},
}),
},
},
TxHashes: []string{string(lib.GetTxHash(testtx.MustGetTxBytes(&clobtypes.MsgProposedOperations{
OperationsQueue: []clobtypes.OperationRaw{
Expand Down
1 change: 0 additions & 1 deletion protocol/x/perpetuals/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ func EndBlocker(ctx sdk.Context, k types.PerpetualsKeeper) {
// first so that new samples are processed in `MaybeProcessNewFundingTickEpoch`.
k.MaybeProcessNewFundingSampleEpoch(ctx)
k.MaybeProcessNewFundingTickEpoch(ctx)
k.SendOIUpdatesToIndexer(ctx)
}
4 changes: 0 additions & 4 deletions protocol/x/perpetuals/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func TestEndBlocker(t *testing.T) {
"MaybeProcessNewFundingSampleEpoch",
ctx,
).Return(nil)
mck.On(
"SendOIUpdatesToIndexer",
ctx,
)
},
expectedErr: nil,
},
Expand Down
45 changes: 0 additions & 45 deletions protocol/x/perpetuals/keeper/perpetual.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"encoding/binary"
"fmt"
"math/big"
"math/rand"
Expand Down Expand Up @@ -1041,14 +1040,6 @@ func (k Keeper) ModifyOpenInterest(
perpetual.OpenInterest = dtypes.NewIntFromBigInt(bigOpenInterest)
k.setPerpetual(ctx, perpetual)

if ctx.ExecMode() == sdk.ExecModeFinalize {
updatedOIStore := prefix.NewStore(ctx.TransientStore(k.transientStoreKey), []byte(types.UpdatedOIKeyPrefix))
openInterestInBytes, err := perpetual.OpenInterest.Marshal()
if err != nil {
return err
}
updatedOIStore.Set(lib.Uint32ToKey(perpetualId), openInterestInBytes)
}
return nil
}

Expand Down Expand Up @@ -1481,42 +1472,6 @@ func (k Keeper) IsPositionUpdatable(
return true, nil
}

func (k Keeper) SendOIUpdatesToIndexer(ctx sdk.Context) {
updatedOIStore := prefix.NewStore(ctx.TransientStore(k.transientStoreKey), []byte(types.UpdatedOIKeyPrefix))
iterator := updatedOIStore.Iterator(nil, nil)
defer iterator.Close()

OIMessageArray := make([]*indexerevents.OpenInterestUpdate, 0)

for ; iterator.Valid(); iterator.Next() {
openInterestSerializableInt := dtypes.SerializableInt{}
if err := openInterestSerializableInt.Unmarshal(iterator.Value()); err != nil {
panic(errorsmod.Wrap(err, "failed to unmarshal open interest"))
}
OIMessage := indexerevents.OpenInterestUpdate{
PerpetualId: binary.BigEndian.Uint32(iterator.Key()),
OpenInterest: openInterestSerializableInt,
}
OIMessageArray = append(OIMessageArray, &OIMessage)
}

if len(OIMessageArray) == 0 {
return
}

k.GetIndexerEventManager().AddBlockEvent(
ctx,
indexerevents.SubtypeOpenInterestUpdate,
indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK,
indexerevents.OpenInterestUpdateVersion,
indexer_manager.GetBytes(
&indexerevents.OpenInterestUpdateEventV1{
OpenInterestUpdates: OIMessageArray,
},
),
)
}

// GetNextPerpetualID returns the next perpetual id to be used from the module store
func (k Keeper) GetNextPerpetualID(ctx sdk.Context) uint32 {
store := ctx.KVStore(k.storeKey)
Expand Down
26 changes: 0 additions & 26 deletions protocol/x/perpetuals/keeper/perpetual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3013,32 +3013,6 @@ func TestIsPositionUpdatable(t *testing.T) {
}
}

func TestModifyOpenInterest_store(t *testing.T) {
pc := keepertest.PerpetualsKeepers(t)
perps := keepertest.CreateLiquidityTiersAndNPerpetuals(t, pc.Ctx, pc.PerpetualsKeeper, pc.PricesKeeper, 100)
pc.Ctx = pc.Ctx.WithExecMode(sdk.ExecModeFinalize)
for _, perp := range perps {
openInterestDeltaBaseQuantums := big.NewInt(2_000_000 * (int64(perp.Params.Id)))

err := pc.PerpetualsKeeper.ModifyOpenInterest(
pc.Ctx,
perp.Params.Id,
openInterestDeltaBaseQuantums,
)
require.NoError(t, err)
}

transientStore := prefix.NewStore(pc.Ctx.TransientStore(pc.TransientStoreKey), []byte(types.UpdatedOIKeyPrefix))
for _, perp := range perps {
perpetualObject, err := pc.PerpetualsKeeper.GetPerpetual(pc.Ctx, perp.Params.Id)
require.NoError(t, err)
serializedOpenInterest := dtypes.SerializableInt{}
err = serializedOpenInterest.Unmarshal(transientStore.Get(lib.Uint32ToKey(perpetualObject.Params.Id)))
require.NoError(t, err)
require.Equal(t, perpetualObject.OpenInterest, serializedOpenInterest)
}
}

func TestIsIsolatedPerpetual(t *testing.T) {
testCases := map[string]struct {
perp types.Perpetual
Expand Down
1 change: 0 additions & 1 deletion protocol/x/perpetuals/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ type PerpetualsKeeper interface {
ctx sdk.Context,
) []Perpetual
GetAllLiquidityTiers(ctx sdk.Context) (list []LiquidityTier)
SendOIUpdatesToIndexer(ctx sdk.Context)
ValidateAndSetPerpetual(
ctx sdk.Context,
perpetual Perpetual,
Expand Down
Loading