Skip to content

Commit

Permalink
Fix Trading reward event processing (#913) (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Li authored Jan 2, 2024
1 parent cc235f0 commit 33b8245
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-fun
import { TradingRewardsHandler } from '../../src/handlers/trading-rewards-handler';
import { intToSerializedInt } from '../helpers/conversion-helpers';

const defaultTransactionIndex: number = 0;
const defaultTransactionIndex: number = -2; // end block

describe('tradingRewardHandler', () => {
beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion indexer/services/ender/src/lib/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const TXN_EVENT_SUBTYPE_VERSION_TO_VALIDATOR_MAPPING: Record<string, ValidatorIn
[serializeSubtypeAndVersion(DydxIndexerSubtypes.UPDATE_PERPETUAL.toString(), 1)]: UpdatePerpetualValidator,
[serializeSubtypeAndVersion(DydxIndexerSubtypes.UPDATE_CLOB_PAIR.toString(), 1)]: UpdateClobPairValidator,
[serializeSubtypeAndVersion(DydxIndexerSubtypes.DELEVERAGING.toString(), 1)]: DeleveragingValidator,
[serializeSubtypeAndVersion(DydxIndexerSubtypes.TRADING_REWARD.toString(), 1)]: TradingRewardsValidator,
};

const BLOCK_EVENT_SUBTYPE_VERSION_TO_VALIDATOR_MAPPING: Record<string, ValidatorInitializer> = {
[serializeSubtypeAndVersion(DydxIndexerSubtypes.FUNDING.toString(), 1)]: FundingValidator,
[serializeSubtypeAndVersion(DydxIndexerSubtypes.TRADING_REWARD.toString(), 1)]: TradingRewardsValidator,
};

function serializeSubtypeAndVersion(
Expand Down
8 changes: 8 additions & 0 deletions indexer/services/scripts/src/helpers/block-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PerpetualMarketCreateEventV1,
StatefulOrderEventV1,
SubaccountUpdateEventV1,
TradingRewardsEventV1,
TransferEventV1,
UpdateClobPairEventV1,
UpdatePerpetualEventV1,
Expand Down Expand Up @@ -98,6 +99,13 @@ export function annotateIndexerTendermintEvent(
data: JSON.stringify(UpdateClobPairEventV1.decode(eventDataBinary)),
};
}
case (DydxIndexerSubtypes.TRADING_REWARD.toString()): {
return {
...event,
dataBytes: new Uint8Array(),
data: JSON.stringify(TradingRewardsEventV1.decode(eventDataBinary)),
};
}
default: {
const message: string = `Unable to parse event subtype: ${event.subtype}`;
logger.error({
Expand Down
1 change: 1 addition & 0 deletions indexer/services/scripts/src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export enum DydxIndexerSubtypes {
LIQUIDITY_TIER = 'liquidity_tier',
UPDATE_PERPETUAL = 'update_perpetual',
UPDATE_CLOB_PAIR = 'update_clob_pair',
TRADING_REWARD = 'trading_reward',
}

0 comments on commit 33b8245

Please sign in to comment.