Skip to content

Commit

Permalink
[IND-474] Update ender transfer handler to execute updates via a SQL …
Browse files Browse the repository at this point in the history
…function. (#763)
  • Loading branch information
lcwik authored Nov 6, 2023
1 parent cc9317d commit 51aca39
Show file tree
Hide file tree
Showing 22 changed files with 679 additions and 283 deletions.
2 changes: 2 additions & 0 deletions indexer/packages/postgres/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import OrderModel from './models/order-model';
import PerpetualMarketModel from './models/perpetual-market-model';
import PerpetualPositionModel from './models/perpetual-position-model';
import SubaccountModel from './models/subaccount-model';
import TransferModel from './models/transfer-model';
import {
APITimeInForce,
CandleResolution,
Expand Down Expand Up @@ -95,6 +96,7 @@ export const SQL_TO_JSON_DEFINED_MODELS = [
PerpetualMarketModel,
PerpetualPositionModel,
SubaccountModel,
TransferModel,
];

export type SpecifiedClobPairStatus =
Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { default as OraclePriceModel } from './models/oracle-price-model';
export { default as OrderModel } from './models/order-model';
export { default as PerpetualMarketModel } from './models/perpetual-market-model';
export { default as PerpetualPositionModel } from './models/perpetual-position-model';
export { default as TransferModel } from './models/transfer-model';

export * as AssetTable from './stores/asset-table';
export * as AssetPositionTable from './stores/asset-position-table';
Expand Down
22 changes: 22 additions & 0 deletions indexer/packages/postgres/src/models/transfer-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ export default class TransferModel extends Model {
};
}

/**
* A mapping from column name to JSON conversion expected.
* See getSqlConversionForDydxModelTypes for valid conversions.
*
* TODO(IND-239): Ensure that jsonSchema() / sqlToJsonConversions() / model fields match.
*/
static get sqlToJsonConversions() {
return {
id: 'string',
senderSubaccountId: 'string',
recipientSubaccountId: 'string',
senderWalletAddress: 'string',
recipientWalletAddress: 'string',
assetId: 'string',
size: 'string',
eventId: 'hex-string',
transactionHash: 'string',
createdAt: 'date-time',
createdAtHeight: 'string',
};
}

id!: string;

senderSubaccountId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../types';

export function uuid(subaccountId: string, assetId: string): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${subaccountId}-${assetId}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/candle-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../types';

export function uuid(startedAt: IsoString, ticker: string, resolution: CandleResolution): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${startedAt}-${ticker}-${resolution}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/fill-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../types';

export function uuid(eventId: Buffer, liquidity: Liquidity): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${eventId.toString('hex')}-${liquidity}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function uuid(
eventId: Buffer,
perpetualId: string,
): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${blockHeight}-${eventId.toString('hex')}-${perpetualId}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/oracle-price-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
export function uuid(
marketId: number, height: string,
): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${marketId.toString()}-${height}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/order-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function uuid(
clobPairId: string,
orderFlags: string,
): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(
Buffer.from(
`${subaccountId}-${clientId}-${clobPairId}-${orderFlags}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const DEFAULT_SUBACCOUNT_UPDATE_DEFAULT_POSITION_FIELDS = {
};

export function uuid(subaccountId: string, openEventId: Buffer): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${subaccountId}-${openEventId.toString('hex')}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/pnl-ticks-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function uuid(
subaccountId: string,
createdAt: string,
): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(
Buffer.from(
`${subaccountId}-${createdAt}`,
Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/subaccount-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../types';

export function uuid(address: string, subaccountNumber: number): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${address}-${subaccountNumber}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/transaction-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../types';

export function uuid(blockHeight: string, transactionIndex: number): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(Buffer.from(`${blockHeight}-${transactionIndex}`, BUFFER_ENCODING_UTF_8));
}

Expand Down
1 change: 1 addition & 0 deletions indexer/packages/postgres/src/stores/transfer-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function uuid(
senderWalletAddress?: string,
recipientWalletAddress?: string,
): string {
// TODO(IND-483): Fix all uuid string substitutions to use Array.join.
return getUuid(
Buffer.from(
`${senderSubaccountId}-${recipientSubaccountId}-${senderWalletAddress}-${recipientWalletAddress}-${eventId.toString('hex')}-${assetId}`,
Expand Down
Loading

0 comments on commit 51aca39

Please sign in to comment.