Skip to content
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
@@ -0,0 +1,13 @@
import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable('orders', (table) => {
table.timestamp('createdAt').nullable();
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable('orders', (table) => {
table.dropColumn('createdAt');
});
}
4 changes: 4 additions & 0 deletions indexer/packages/postgres/src/models/order-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default class OrderModel extends BaseModel {
goodTilBlock: { type: ['string', 'null'], default: null, pattern: IntegerPattern },
goodTilBlockTime: { type: ['string', 'null'], default: null, format: 'date-time' },
createdAtHeight: { type: ['string', 'null'], default: null, pattern: IntegerPattern },
createdAt: { type: ['string', 'null'], default: null, format: 'date-time' },
clientMetadata: { type: 'string', pattern: IntegerPattern },
triggerPrice: { type: ['string', 'null'], default: null, pattern: NonNegativeNumericPattern },
updatedAt: { type: 'string', format: 'date-time' },
Expand Down Expand Up @@ -134,6 +135,7 @@ export default class OrderModel extends BaseModel {
goodTilBlock: 'string',
goodTilBlockTime: 'date-time',
createdAtHeight: 'string',
createdAt: 'date-time',
clientMetadata: 'string',
triggerPrice: 'string',
updatedAt: 'date-time',
Expand Down Expand Up @@ -181,6 +183,8 @@ export default class OrderModel extends BaseModel {

createdAtHeight?: string;

createdAt?: IsoString;

clientMetadata!: string;

triggerPrice?: string;
Expand Down
3 changes: 2 additions & 1 deletion indexer/packages/postgres/src/types/db-model-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export interface OrderFromDatabase extends IdBasedModelFromDatabase {
updatedAtHeight: string,
goodTilBlock?: string,
goodTilBlockTime?: string,
// createdAtHeight is optional because short term orders do not have a createdAtHeight.
// createdAtHeight and createdAt are optional because short term orders do not have them.
createdAtHeight?: string,
createdAt?: IsoString,
clientMetadata: string,
triggerPrice?: string,
builderAddress?: string,
Expand Down
4 changes: 3 additions & 1 deletion indexer/packages/postgres/src/types/order-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export interface OrderCreateObject {
updatedAtHeight: string,
goodTilBlock?: string,
goodTilBlockTime?: string,
// createdAtHeight is optional because short term orders do not have a createdAtHeight.
// createdAtHeight and createdAt are optional because short term orders do not have them.
createdAtHeight?: string,
createdAt?: IsoString,
clientMetadata: string,
triggerPrice?: string,
builderAddress?: string,
Expand Down Expand Up @@ -119,6 +120,7 @@ export enum OrderColumns {
updatedAt = 'updatedAt',
updatedAtHeight = 'updatedAtHeight',
createdAtHeight = 'createdAtHeight',
createdAt = 'createdAt',
clientMetadata = 'clientMetadata',
triggerPrice = 'triggerPrice',
duration = 'duration',
Expand Down
7 changes: 7 additions & 0 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,7 @@ fetch(`${baseURL}/orders?address=string&subaccountNumber=0.1`,
"goodTilBlock": "string",
"goodTilBlockTime": "string",
"createdAtHeight": "string",
"createdAt": "string",
"clientMetadata": "string",
"triggerPrice": "string",
"builderAddress": "string",
Expand Down Expand Up @@ -2428,6 +2429,7 @@ Status Code **200**
|» goodTilBlock|string|false|none|none|
|» goodTilBlockTime|string|false|none|none|
|» createdAtHeight|string|false|none|none|
|» createdAt|[IsoString](#schemaisostring)|false|none|none|
|» clientMetadata|string|true|none|none|
|» triggerPrice|string|false|none|none|
|» builderAddress|string|false|none|none|
Expand Down Expand Up @@ -2615,6 +2617,7 @@ fetch(`${baseURL}/orders/parentSubaccountNumber?address=string&parentSubaccountN
"goodTilBlock": "string",
"goodTilBlockTime": "string",
"createdAtHeight": "string",
"createdAt": "string",
"clientMetadata": "string",
"triggerPrice": "string",
"builderAddress": "string",
Expand Down Expand Up @@ -2661,6 +2664,7 @@ Status Code **200**
|» goodTilBlock|string|false|none|none|
|» goodTilBlockTime|string|false|none|none|
|» createdAtHeight|string|false|none|none|
|» createdAt|[IsoString](#schemaisostring)|false|none|none|
|» clientMetadata|string|true|none|none|
|» triggerPrice|string|false|none|none|
|» builderAddress|string|false|none|none|
Expand Down Expand Up @@ -2798,6 +2802,7 @@ fetch(`${baseURL}/orders/{orderId}`,
"goodTilBlock": "string",
"goodTilBlockTime": "string",
"createdAtHeight": "string",
"createdAt": "string",
"clientMetadata": "string",
"triggerPrice": "string",
"builderAddress": "string",
Expand Down Expand Up @@ -6513,6 +6518,7 @@ or
"goodTilBlock": "string",
"goodTilBlockTime": "string",
"createdAtHeight": "string",
"createdAt": "string",
"clientMetadata": "string",
"triggerPrice": "string",
"builderAddress": "string",
Expand Down Expand Up @@ -6550,6 +6556,7 @@ or
|goodTilBlock|string|false|none|none|
|goodTilBlockTime|string|false|none|none|
|createdAtHeight|string|false|none|none|
|createdAt|[IsoString](#schemaisostring)|false|none|none|
|clientMetadata|string|true|none|none|
|triggerPrice|string|false|none|none|
|builderAddress|string|false|none|none|
Expand Down
3 changes: 3 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@
"createdAtHeight": {
"type": "string"
},
"createdAt": {
"$ref": "#/components/schemas/IsoString"
},
"clientMetadata": {
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export function postgresOrderToResponseObject(
goodTilBlock: order.goodTilBlock ?? undefined,
goodTilBlockTime: order.goodTilBlockTime ?? undefined,
createdAtHeight: order.createdAtHeight ?? undefined,
createdAt: order.createdAt ?? undefined,
ticker: perpetualMarketRefresher.getPerpetualMarketTicker(order.clobPairId)!,
triggerPrice: order.triggerPrice ?? undefined,
builderAddress: order.builderAddress ?? undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ describe('conditionalOrderPlacementHandler', () => {
goodTilBlock: null,
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
createdAtHeight: '3',
createdAt: defaultDateTime.toISO(),
clientMetadata: '0',
triggerPrice: getTriggerPrice(defaultOrder, testConstants.defaultPerpetualMarket),
updatedAt: defaultDateTime.toISO(),
Expand Down Expand Up @@ -225,6 +226,7 @@ describe('conditionalOrderPlacementHandler', () => {
goodTilBlock: null,
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
createdAtHeight: '3',
createdAt: defaultDateTime.toISO(),
clientMetadata: '0',
triggerPrice: getTriggerPrice(defaultOrder, testConstants.defaultPerpetualMarket),
updatedAt: defaultDateTime.toISO(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ describe('statefulOrderPlacementHandler', () => {
goodTilBlock: null,
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(testOrder),
createdAtHeight: '3',
createdAt: defaultDateTime.toISO(),
clientMetadata: '0',
triggerPrice: null,
updatedAt: defaultDateTime.toISO(),
Expand Down Expand Up @@ -299,6 +300,7 @@ describe('statefulOrderPlacementHandler', () => {
goodTilBlock: null,
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(testOrder),
createdAtHeight: '3',
createdAt: defaultDateTime.toISO(),
clientMetadata: '0',
triggerPrice: null,
updatedAt: defaultDateTime.toISO(),
Expand Down Expand Up @@ -367,6 +369,7 @@ describe('statefulOrderPlacementHandler', () => {
goodTilBlock: null,
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
createdAtHeight: '3',
createdAt: defaultDateTime.toISO(),
clientMetadata: '0',
triggerPrice: null,
updatedAt: defaultDateTime.toISO(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ BEGIN
order_record."goodTilBlockTime" = to_timestamp((order_->'goodTilBlockTime')::double precision);
order_record."clientMetadata" = (order_->'clientMetadata')::bigint;
order_record."createdAtHeight" = block_height;
order_record."createdAt" = block_time;
order_record."updatedAt" = block_time;
order_record."updatedAtHeight" = block_height;
order_record."orderRouterAddress" = order_->>'orderRouterAddress';
Expand Down Expand Up @@ -99,19 +100,19 @@ BEGIN
INSERT INTO orders (
"id", "subaccountId", "clientId", "clobPairId", "side", "size", "totalFilled",
"price", "timeInForce", "reduceOnly", "orderFlags", "goodTilBlockTime",
"clientMetadata", "createdAtHeight", "updatedAt", "updatedAtHeight",
"clientMetadata", "createdAtHeight", "createdAt", "updatedAt", "updatedAtHeight",
"orderRouterAddress", "type", "status", "triggerPrice", "builderAddress",
"feePpm", "duration", "interval", "priceTolerance"
) VALUES (
order_record."id", order_record."subaccountId", order_record."clientId",
order_record."clobPairId", order_record."side", order_record."size",
order_record."totalFilled", order_record."price", order_record."timeInForce",
order_record."reduceOnly", order_record."orderFlags", order_record."goodTilBlockTime",
order_record."clientMetadata", order_record."createdAtHeight", order_record."updatedAt",
order_record."updatedAtHeight", order_record."orderRouterAddress", order_record."type",
order_record."status", order_record."triggerPrice", order_record."builderAddress",
order_record."feePpm", order_record."duration", order_record."interval",
order_record."priceTolerance"
order_record."clientMetadata", order_record."createdAtHeight", order_record."createdAt",
order_record."updatedAt", order_record."updatedAtHeight", order_record."orderRouterAddress",
order_record."type", order_record."status", order_record."triggerPrice",
order_record."builderAddress", order_record."feePpm", order_record."duration",
order_record."interval", order_record."priceTolerance"
) ON CONFLICT ("id") DO
UPDATE SET
"subaccountId" = order_record."subaccountId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ BEGIN
order_record."totalFilled" = fill_amount;
order_record."status" = dydx_get_order_status(fill_amount, order_size, 'NOT_CANCELED', order_record."orderFlags", order_record."timeInForce");
order_record."createdAtHeight" = block_height;
order_record."createdAt" = block_time;

IF jsonb_extract_path(order_, 'orderId', 'orderFlags')::bigint = constants.order_flag_twap_suborder() THEN
-- This is a handled case but is not expected for twap. Parent orders should always exist
Expand All @@ -200,16 +201,17 @@ BEGIN
INSERT INTO orders
("id", "subaccountId", "clientId", "clobPairId", "side", "size", "totalFilled", "price", "type",
"status", "timeInForce", "reduceOnly", "orderFlags", "goodTilBlock", "goodTilBlockTime", "createdAtHeight",
"clientMetadata", "triggerPrice", "updatedAt", "updatedAtHeight", "builderAddress", "feePpm",
"createdAt", "clientMetadata", "triggerPrice", "updatedAt", "updatedAtHeight", "builderAddress", "feePpm",
"orderRouterAddress", "duration", "interval", "priceTolerance")
VALUES (
order_record."id", order_record."subaccountId", order_record."clientId", order_record."clobPairId",
order_record."side", order_record."size", order_record."totalFilled", order_record."price", order_record."type",
order_record."status", order_record."timeInForce", order_record."reduceOnly", order_record."orderFlags",
order_record."goodTilBlock", order_record."goodTilBlockTime", order_record."createdAtHeight",
order_record."clientMetadata", order_record."triggerPrice", order_record."updatedAt", order_record."updatedAtHeight",
order_record."builderAddress", order_record."feePpm", order_record."orderRouterAddress", order_record."duration",
order_record."interval", order_record."priceTolerance"
order_record."createdAt", order_record."clientMetadata", order_record."triggerPrice",
order_record."updatedAt", order_record."updatedAtHeight",
order_record."builderAddress", order_record."feePpm", order_record."orderRouterAddress",
order_record."duration", order_record."interval", order_record."priceTolerance"
);
END IF;
END IF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ BEGIN
order_record."totalFilled" = fill_amount;
order_record."status" = dydx_get_order_status(fill_amount, order_size, order_canceled_status, order_record."orderFlags", order_record."timeInForce");
order_record."createdAtHeight" = block_height;
order_record."createdAt" = block_time;

order_record."duration" = NULL;
order_record."interval" = NULL;
Expand All @@ -190,16 +191,17 @@ BEGIN
INSERT INTO orders
("id", "subaccountId", "clientId", "clobPairId", "side", "size", "totalFilled", "price", "type",
"status", "timeInForce", "reduceOnly", "orderFlags", "goodTilBlock", "goodTilBlockTime", "createdAtHeight",
"clientMetadata", "triggerPrice", "updatedAt", "updatedAtHeight", "builderAddress", "feePpm",
"createdAt", "clientMetadata", "triggerPrice", "updatedAt", "updatedAtHeight", "builderAddress", "feePpm",
"orderRouterAddress", "duration", "interval", "priceTolerance")
VALUES (
order_record."id", order_record."subaccountId", order_record."clientId", order_record."clobPairId",
order_record."side", order_record."size", order_record."totalFilled", order_record."price", order_record."type",
order_record."status", order_record."timeInForce", order_record."reduceOnly", order_record."orderFlags",
order_record."goodTilBlock", order_record."goodTilBlockTime", order_record."createdAtHeight",
order_record."clientMetadata", order_record."triggerPrice", order_record."updatedAt", order_record."updatedAtHeight",
order_record."builderAddress", order_record."feePpm", order_record."orderRouterAddress", order_record."duration",
order_record."interval", order_record."priceTolerance"
order_record."createdAt", order_record."clientMetadata", order_record."triggerPrice",
order_record."updatedAt", order_record."updatedAtHeight",
order_record."builderAddress", order_record."feePpm", order_record."orderRouterAddress",
order_record."duration", order_record."interval", order_record."priceTolerance"
);
END IF;

Expand Down
Loading