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 #2499

Merged
merged 1 commit into from
Oct 16, 2024
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 @@ -1372,31 +1372,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 */
Comment on lines +1375 to +1380
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Combine @deprecated annotation with the JSDoc comment block

The @deprecated tag for OpenInterestUpdateEventV1 should be included within the JSDoc comment block to properly document the deprecation.

Apply this diff:

 /**
  * OpenInterestUpdateEventV1 is used for open interest update events
  * Deprecated.
+ * @deprecated
  */
- /** @deprecated */

 export interface OpenInterestUpdateEventV1 {
   openInterestUpdates: OpenInterestUpdate[];
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
*/
/** @deprecated */
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
* @deprecated
*/
export interface OpenInterestUpdateEventV1 {
openInterestUpdates: OpenInterestUpdate[];
}

💡 Codebase verification

Deprecated Interfaces Still in Use

The deprecated interfaces OpenInterestUpdateEventV1 and OpenInterestUpdate are still being used in the file indexer/services/ender/__tests__/helpers/constants.ts. Please remove these usages to complete the deprecation process.

🔗 Analysis chain

Verify that deprecated interfaces are no longer used in the codebase

Now that OpenInterestUpdateEventV1 and OpenInterestUpdate have been deprecated, ensure that they are not used elsewhere in the codebase.

Run the following script to check for usage:

Also applies to: 1399-1405

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of deprecated interfaces in TypeScript files
# Expected: No occurrences of the deprecated interfaces

rg --type ts 'OpenInterestUpdateEventV1|OpenInterestUpdate' --glob '!events.ts'

Length of output: 726


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 */
Comment on lines +1385 to +1390
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Combine @deprecated annotation with the JSDoc comment block

Similarly, include the @deprecated tag within the JSDoc comment block for OpenInterestUpdateEventV1SDKType.

Apply this diff:

 /**
  * OpenInterestUpdateEventV1 is used for open interest update events
  * Deprecated.
+ * @deprecated
  */
- /** @deprecated */

 export interface OpenInterestUpdateEventV1SDKType {
   open_interest_updates: OpenInterestUpdateSDKType[];
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
*/
/** @deprecated */
/**
* OpenInterestUpdateEventV1 is used for open interest update events
* Deprecated.
* @deprecated
*/
export interface OpenInterestUpdateEventV1SDKType {
open_interest_updates: OpenInterestUpdateSDKType[];
}


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. */

Comment on lines +1399 to 1405
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Include @deprecated annotation within the JSDoc comment block

For OpenInterestUpdate, the @deprecated tag should be placed inside the JSDoc comment block.

Apply this diff:

 /**
  * OpenInterestUpdate contains a single open interest update for a perpetual
  * Deprecated.
+ * @deprecated
  */
- /** @deprecated */

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** @deprecated */
export interface OpenInterestUpdate {
/** The ID of the perpetual market. */
perpetualId: number;
/** The new open interest value for the perpetual market. */
/**
* OpenInterestUpdate contains a single open interest update for a perpetual
* Deprecated.
* @deprecated
*/
export interface OpenInterestUpdate {
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. */
Comment on lines +1412 to 1417
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Include @deprecated annotation within the JSDoc comment block

Similarly, for OpenInterestUpdateSDKType, include the @deprecated tag within the JSDoc comment block.

Apply this diff:

 /**
  * OpenInterestUpdate contains a single open interest update for a perpetual
  * Deprecated.
+ * @deprecated
  */
- /** @deprecated */

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** @deprecated */
export interface OpenInterestUpdateSDKType {
/** The ID of the perpetual market. */
perpetual_id: number;
/** The new open interest value for the perpetual market. */
/**
* OpenInterestUpdate contains a single open interest update for a perpetual
* Deprecated.
* @deprecated
*/
export interface OpenInterestUpdateSDKType {
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 @@ -534,14 +534,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
316 changes: 160 additions & 156 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 @@ -825,22 +825,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 @@ -1169,22 +1153,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 @@ -1340,22 +1308,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 @@ -1739,22 +1691,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 @@ -219,24 +218,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 @@ -399,24 +380,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 @@ -579,24 +542,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