Skip to content

Commit e6b8dcf

Browse files
anmolagrawal345mergify[bot]
authored andcommitted
add createdAt field to index orders table (#3327)
(cherry picked from commit 84d4664)
1 parent bb51260 commit e6b8dcf

File tree

12 files changed

+57
-16
lines changed

12 files changed

+57
-16
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Knex from 'knex';
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
return knex.schema.alterTable('orders', (table) => {
5+
table.timestamp('createdAt').nullable();
6+
});
7+
}
8+
9+
export async function down(knex: Knex): Promise<void> {
10+
return knex.schema.alterTable('orders', (table) => {
11+
table.dropColumn('createdAt');
12+
});
13+
}

indexer/packages/postgres/src/models/order-model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default class OrderModel extends BaseModel {
9696
goodTilBlock: { type: ['string', 'null'], default: null, pattern: IntegerPattern },
9797
goodTilBlockTime: { type: ['string', 'null'], default: null, format: 'date-time' },
9898
createdAtHeight: { type: ['string', 'null'], default: null, pattern: IntegerPattern },
99+
createdAt: { type: ['string', 'null'], default: null, format: 'date-time' },
99100
clientMetadata: { type: 'string', pattern: IntegerPattern },
100101
triggerPrice: { type: ['string', 'null'], default: null, pattern: NonNegativeNumericPattern },
101102
updatedAt: { type: 'string', format: 'date-time' },
@@ -134,6 +135,7 @@ export default class OrderModel extends BaseModel {
134135
goodTilBlock: 'string',
135136
goodTilBlockTime: 'date-time',
136137
createdAtHeight: 'string',
138+
createdAt: 'date-time',
137139
clientMetadata: 'string',
138140
triggerPrice: 'string',
139141
updatedAt: 'date-time',
@@ -181,6 +183,8 @@ export default class OrderModel extends BaseModel {
181183

182184
createdAtHeight?: string;
183185

186+
createdAt?: IsoString;
187+
184188
clientMetadata!: string;
185189

186190
triggerPrice?: string;

indexer/packages/postgres/src/types/db-model-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export interface OrderFromDatabase extends IdBasedModelFromDatabase {
7272
updatedAtHeight: string,
7373
goodTilBlock?: string,
7474
goodTilBlockTime?: string,
75-
// createdAtHeight is optional because short term orders do not have a createdAtHeight.
75+
// createdAtHeight and createdAt are optional because short term orders do not have them.
7676
createdAtHeight?: string,
77+
createdAt?: IsoString,
7778
clientMetadata: string,
7879
triggerPrice?: string,
7980
builderAddress?: string,

indexer/packages/postgres/src/types/order-types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ export interface OrderCreateObject {
6262
updatedAtHeight: string,
6363
goodTilBlock?: string,
6464
goodTilBlockTime?: string,
65-
// createdAtHeight is optional because short term orders do not have a createdAtHeight.
65+
// createdAtHeight and createdAt are optional because short term orders do not have them.
6666
createdAtHeight?: string,
67+
createdAt?: IsoString,
6768
clientMetadata: string,
6869
triggerPrice?: string,
6970
builderAddress?: string,
@@ -119,6 +120,7 @@ export enum OrderColumns {
119120
updatedAt = 'updatedAt',
120121
updatedAtHeight = 'updatedAtHeight',
121122
createdAtHeight = 'createdAtHeight',
123+
createdAt = 'createdAt',
122124
clientMetadata = 'clientMetadata',
123125
triggerPrice = 'triggerPrice',
124126
duration = 'duration',

indexer/services/comlink/public/api-documentation.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,7 @@ fetch(`${baseURL}/orders?address=string&subaccountNumber=0.1`,
23292329
"goodTilBlock": "string",
23302330
"goodTilBlockTime": "string",
23312331
"createdAtHeight": "string",
2332+
"createdAt": "string",
23322333
"clientMetadata": "string",
23332334
"triggerPrice": "string",
23342335
"builderAddress": "string",
@@ -2375,6 +2376,7 @@ Status Code **200**
23752376
|» goodTilBlock|string|false|none|none|
23762377
|» goodTilBlockTime|string|false|none|none|
23772378
|» createdAtHeight|string|false|none|none|
2379+
|» createdAt|[IsoString](#schemaisostring)|false|none|none|
23782380
|» clientMetadata|string|true|none|none|
23792381
|» triggerPrice|string|false|none|none|
23802382
|» builderAddress|string|false|none|none|
@@ -2542,6 +2544,7 @@ fetch(`${baseURL}/orders/parentSubaccountNumber?address=string&parentSubaccountN
25422544
"goodTilBlock": "string",
25432545
"goodTilBlockTime": "string",
25442546
"createdAtHeight": "string",
2547+
"createdAt": "string",
25452548
"clientMetadata": "string",
25462549
"triggerPrice": "string",
25472550
"builderAddress": "string",
@@ -2588,6 +2591,7 @@ Status Code **200**
25882591
|» goodTilBlock|string|false|none|none|
25892592
|» goodTilBlockTime|string|false|none|none|
25902593
|» createdAtHeight|string|false|none|none|
2594+
|» createdAt|[IsoString](#schemaisostring)|false|none|none|
25912595
|» clientMetadata|string|true|none|none|
25922596
|» triggerPrice|string|false|none|none|
25932597
|» builderAddress|string|false|none|none|
@@ -2725,6 +2729,7 @@ fetch(`${baseURL}/orders/{orderId}`,
27252729
"goodTilBlock": "string",
27262730
"goodTilBlockTime": "string",
27272731
"createdAtHeight": "string",
2732+
"createdAt": "string",
27282733
"clientMetadata": "string",
27292734
"triggerPrice": "string",
27302735
"builderAddress": "string",
@@ -6440,6 +6445,7 @@ or
64406445
"goodTilBlock": "string",
64416446
"goodTilBlockTime": "string",
64426447
"createdAtHeight": "string",
6448+
"createdAt": "string",
64436449
"clientMetadata": "string",
64446450
"triggerPrice": "string",
64456451
"builderAddress": "string",
@@ -6477,6 +6483,7 @@ or
64776483
|goodTilBlock|string|false|none|none|
64786484
|goodTilBlockTime|string|false|none|none|
64796485
|createdAtHeight|string|false|none|none|
6486+
|createdAt|[IsoString](#schemaisostring)|false|none|none|
64806487
|clientMetadata|string|true|none|none|
64816488
|triggerPrice|string|false|none|none|
64826489
|builderAddress|string|false|none|none|

indexer/services/comlink/public/swagger.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,9 @@
11081108
"createdAtHeight": {
11091109
"type": "string"
11101110
},
1111+
"createdAt": {
1112+
"$ref": "#/components/schemas/IsoString"
1113+
},
11111114
"clientMetadata": {
11121115
"type": "string"
11131116
},

indexer/services/comlink/src/request-helpers/request-transformer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ export function postgresOrderToResponseObject(
494494
goodTilBlock: order.goodTilBlock ?? undefined,
495495
goodTilBlockTime: order.goodTilBlockTime ?? undefined,
496496
createdAtHeight: order.createdAtHeight ?? undefined,
497+
createdAt: order.createdAt ?? undefined,
497498
ticker: perpetualMarketRefresher.getPerpetualMarketTicker(order.clobPairId)!,
498499
triggerPrice: order.triggerPrice ?? undefined,
499500
builderAddress: order.builderAddress ?? undefined,

indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ describe('conditionalOrderPlacementHandler', () => {
157157
goodTilBlock: null,
158158
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
159159
createdAtHeight: '3',
160+
createdAt: defaultDateTime.toISO(),
160161
clientMetadata: '0',
161162
triggerPrice: getTriggerPrice(defaultOrder, testConstants.defaultPerpetualMarket),
162163
updatedAt: defaultDateTime.toISO(),
@@ -225,6 +226,7 @@ describe('conditionalOrderPlacementHandler', () => {
225226
goodTilBlock: null,
226227
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
227228
createdAtHeight: '3',
229+
createdAt: defaultDateTime.toISO(),
228230
clientMetadata: '0',
229231
triggerPrice: getTriggerPrice(defaultOrder, testConstants.defaultPerpetualMarket),
230232
updatedAt: defaultDateTime.toISO(),

indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ describe('statefulOrderPlacementHandler', () => {
215215
goodTilBlock: null,
216216
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(testOrder),
217217
createdAtHeight: '3',
218+
createdAt: defaultDateTime.toISO(),
218219
clientMetadata: '0',
219220
triggerPrice: null,
220221
updatedAt: defaultDateTime.toISO(),
@@ -299,6 +300,7 @@ describe('statefulOrderPlacementHandler', () => {
299300
goodTilBlock: null,
300301
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(testOrder),
301302
createdAtHeight: '3',
303+
createdAt: defaultDateTime.toISO(),
302304
clientMetadata: '0',
303305
triggerPrice: null,
304306
updatedAt: defaultDateTime.toISO(),
@@ -367,6 +369,7 @@ describe('statefulOrderPlacementHandler', () => {
367369
goodTilBlock: null,
368370
goodTilBlockTime: protocolTranslations.getGoodTilBlockTime(defaultOrder),
369371
createdAtHeight: '3',
372+
createdAt: defaultDateTime.toISO(),
370373
clientMetadata: '0',
371374
triggerPrice: null,
372375
updatedAt: defaultDateTime.toISO(),

indexer/services/ender/src/scripts/handlers/dydx_stateful_order_handler.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ BEGIN
6060
order_record."goodTilBlockTime" = to_timestamp((order_->'goodTilBlockTime')::double precision);
6161
order_record."clientMetadata" = (order_->'clientMetadata')::bigint;
6262
order_record."createdAtHeight" = block_height;
63+
order_record."createdAt" = block_time;
6364
order_record."updatedAt" = block_time;
6465
order_record."updatedAtHeight" = block_height;
6566
order_record."orderRouterAddress" = order_->>'orderRouterAddress';
@@ -99,19 +100,19 @@ BEGIN
99100
INSERT INTO orders (
100101
"id", "subaccountId", "clientId", "clobPairId", "side", "size", "totalFilled",
101102
"price", "timeInForce", "reduceOnly", "orderFlags", "goodTilBlockTime",
102-
"clientMetadata", "createdAtHeight", "updatedAt", "updatedAtHeight",
103+
"clientMetadata", "createdAtHeight", "createdAt", "updatedAt", "updatedAtHeight",
103104
"orderRouterAddress", "type", "status", "triggerPrice", "builderAddress",
104105
"feePpm", "duration", "interval", "priceTolerance"
105106
) VALUES (
106107
order_record."id", order_record."subaccountId", order_record."clientId",
107108
order_record."clobPairId", order_record."side", order_record."size",
108109
order_record."totalFilled", order_record."price", order_record."timeInForce",
109110
order_record."reduceOnly", order_record."orderFlags", order_record."goodTilBlockTime",
110-
order_record."clientMetadata", order_record."createdAtHeight", order_record."updatedAt",
111-
order_record."updatedAtHeight", order_record."orderRouterAddress", order_record."type",
112-
order_record."status", order_record."triggerPrice", order_record."builderAddress",
113-
order_record."feePpm", order_record."duration", order_record."interval",
114-
order_record."priceTolerance"
111+
order_record."clientMetadata", order_record."createdAtHeight", order_record."createdAt",
112+
order_record."updatedAt", order_record."updatedAtHeight", order_record."orderRouterAddress",
113+
order_record."type", order_record."status", order_record."triggerPrice",
114+
order_record."builderAddress", order_record."feePpm", order_record."duration",
115+
order_record."interval", order_record."priceTolerance"
115116
) ON CONFLICT ("id") DO
116117
UPDATE SET
117118
"subaccountId" = order_record."subaccountId",

0 commit comments

Comments
 (0)