Skip to content

Commit

Permalink
feat: add fillBlock to table & V3 queries
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Jan 6, 2025
1 parent 7fa1515 commit 90369ba
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/entities/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type SharedXOrderEntity = {
requestId?: string
// TxHash field is defined when the order has been filled and there is a txHash associated with the fill.
txHash?: string
fillBlock?: number
// SettledAmount field is defined when the order has been filled and the fill amounts have been recorded.
settledAmounts?: SettledAmount[]
}
Expand Down
8 changes: 7 additions & 1 deletion lib/handlers/check-order-status/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type CheckOrderStatusRequest = {
export type ExtraUpdateInfo = {
orderStatus: ORDER_STATUS
txHash?: string
fillBlock?: number
settledAmounts?: SettledAmount[]
getFillLogAttempts?: number
}
Expand Down Expand Up @@ -163,13 +164,15 @@ export class CheckOrderStatusService {
extraUpdateInfo = {
orderStatus: ORDER_STATUS.FILLED,
txHash: fillEvent.txHash,
fillBlock: fillEvent.blockNumber,
settledAmounts,
}
} catch (e) {
log.error('error processing fill event', { error: e })
extraUpdateInfo = {
orderStatus: ORDER_STATUS.FILLED,
txHash: '',
fillBlock: -1,
settledAmounts: [],
}
}
Expand Down Expand Up @@ -227,6 +230,7 @@ export class CheckOrderStatusUtils {
validation: OrderValidation
quoteId: string
txHash?: string
fillBlock?: number
settledAmounts?: SettledAmount[]
getFillLogAttempts?: number
}): Promise<SfnStateInputOutput> {
Expand All @@ -239,6 +243,7 @@ export class CheckOrderStatusUtils {
lastStatus,
orderStatus,
txHash,
fillBlock,
settledAmounts,
getFillLogAttempts,
validation,
Expand All @@ -253,7 +258,7 @@ export class CheckOrderStatusUtils {
this.analyticsService.logCancelled(orderHash, this.serviceOrderType, quoteId)
}
log.info('calling updateOrderStatus', { orderHash, orderStatus, lastStatus })
await this.repository.updateOrderStatus(orderHash, orderStatus, txHash, settledAmounts)
await this.repository.updateOrderStatus(orderHash, orderStatus, txHash, fillBlock, settledAmounts)
if (IS_TERMINAL_STATE(orderStatus)) {
metrics.putMetric(`OrderSfn-${orderStatus}`, 1)
metrics.putMetric(`OrderSfn-${orderStatus}-chain-${chainId}`, 1)
Expand Down Expand Up @@ -286,6 +291,7 @@ export class CheckOrderStatusUtils {
chainId: chainId,
...(settledAmounts && { settledAmounts }),
...(txHash && { txHash }),
...(fillBlock && { fillBlock }),
...(getFillLogAttempts && { getFillLogAttempts }),
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/handlers/get-orders/schema/GetDutchV3OrderResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type GetDutchV3OrderResponse = {
reactor: string

txHash: string | undefined
fillBlock: number | undefined
deadline: number
input: {
token: string
Expand Down Expand Up @@ -69,6 +70,7 @@ export const GetDutchV3OrderResponseEntryJoi = Joi.object({
chainId: FieldValidator.isValidChainId().required(),
startingBaseFee: FieldValidator.isValidAmount(),
txHash: FieldValidator.isValidTxHash(),
fillBlock: FieldValidator.isValidNumber(),
input: Joi.object({
token: FieldValidator.isValidEthAddress().required(),
startAmount: FieldValidator.isValidAmount().required(),
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/post-order/PostOrderBodyParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class PostOrderBodyParser {
): DutchV3Order {
try {
const order = CosignedV3DutchOrder.parse(encodedOrder, chainId)
return new DutchV3Order(order as SDKV3DutchOrder, signature, chainId, undefined, undefined, quoteId, requestId)
return new DutchV3Order(order as SDKV3DutchOrder, signature, chainId, undefined, undefined, undefined, quoteId, requestId)
} catch (err) {
this.logger.error('Unable to parse DutchV3 order', {
err,
Expand Down
4 changes: 4 additions & 0 deletions lib/models/DutchV3Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class DutchV3Order extends Order {
readonly chainId: number,
readonly orderStatus?: ORDER_STATUS,
readonly txHash?: string,
readonly fillBlock?: number,
readonly quoteId?: string,
readonly requestId?: string,
readonly createdAt?: number
Expand Down Expand Up @@ -65,6 +66,7 @@ export class DutchV3Order extends Order {
outputOverrides: decodedOrder.info.cosignerData.outputOverrides.map((o) => o.toString()),
},
txHash: this.txHash,
fillBlock: this.fillBlock,
cosignature: decodedOrder.info.cosignature,
quoteId: this.quoteId,
requestId: this.requestId,
Expand All @@ -81,6 +83,7 @@ export class DutchV3Order extends Order {
entity.chainId,
entity.orderStatus,
entity.txHash,
entity.fillBlock,
entity.quoteId,
entity.requestId,
entity.createdAt
Expand All @@ -96,6 +99,7 @@ export class DutchV3Order extends Order {
chainId: this.chainId,
nonce: this.inner.info.nonce.toString(),
txHash: this.txHash,
fillBlock: this.fillBlock,
orderHash: this.inner.hash(),
swapper: this.inner.info.swapper,
reactor: this.inner.info.reactor,
Expand Down
1 change: 1 addition & 0 deletions lib/repositories/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface BaseOrdersRepository<T extends OrderEntityType> {
orderHash: string,
status: ORDER_STATUS,
txHash?: string,
fillBlock?: number,
settledAmounts?: SettledAmount[]
) => Promise<void>
deleteOrders: (orderHashes: string[]) => Promise<void>
Expand Down
1 change: 1 addition & 0 deletions lib/repositories/dutch-orders-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class DutchOrdersRepository extends GenericOrdersRepository<string, strin
quoteId: { type: DYNAMODB_TYPES.STRING },
requestId: { type: DYNAMODB_TYPES.STRING },
txHash: { type: DYNAMODB_TYPES.STRING },
fillBlock: { type: DYNAMODB_TYPES.NUMBER },
settledAmounts: { type: DYNAMODB_TYPES.LIST },

//indexes
Expand Down
2 changes: 2 additions & 0 deletions lib/repositories/generic-orders-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export abstract class GenericOrdersRepository<
orderHash: string,
status: ORDER_STATUS,
txHash?: string,
fillBlock?: number,
settledAmounts?: SettledAmount[]
): Promise<void> {
try {
Expand All @@ -117,6 +118,7 @@ export abstract class GenericOrdersRepository<
[TABLE_KEY.ORDER_HASH]: orderHash,
...this.indexMapper.getIndexFieldsForStatusUpdate(order, status),
...(txHash && { txHash }),
...(fillBlock && { fillBlock }),
...(settledAmounts && { settledAmounts }),
})
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion test/integ/repositories/dynamo-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ describe('OrdersRepository get order count by offerer test', () => {

describe('OrdersRepository update status test', () => {
it('should successfully update orderStatus of an order identified by orderHash', async () => {
await ordersRepository.updateOrderStatus('0x1', ORDER_STATUS.FILLED, 'txHash', [
await ordersRepository.updateOrderStatus('0x1', ORDER_STATUS.FILLED, 'txHash', 1, [
{ tokenOut: '0x1', amountOut: '1' } as SettledAmount,
])
await expect(ordersRepository.getByHash('0x1')).resolves.toMatchObject({
Expand All @@ -644,6 +644,7 @@ describe('OrdersRepository update status test', () => {
chainId_orderStatus: `${MOCK_ORDER_1.chainId}_${ORDER_STATUS.FILLED}`,
chainId_orderStatus_filler: `${MOCK_ORDER_1.chainId}_${ORDER_STATUS.FILLED}_undefined`,
txHash: 'txHash',
fillBlock: 1,
settledAmounts: [{ tokenOut: '0x1', amountOut: '1' }],
})
})
Expand Down
3 changes: 2 additions & 1 deletion test/integ/repositories/limit-orders-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ describe('OrdersRepository get order count by offerer test', () => {

describe('OrdersRepository update status test', () => {
it('should successfully update orderStatus of an order identified by orderHash', async () => {
await ordersRepository.updateOrderStatus('0x1', ORDER_STATUS.FILLED, 'txHash', [
await ordersRepository.updateOrderStatus('0x1', ORDER_STATUS.FILLED, 'txHash', 1, [
{ tokenOut: '0x1', amountOut: '1' } as any,
])
await expect(ordersRepository.getByHash('0x1')).resolves.toMatchObject({
Expand All @@ -545,6 +545,7 @@ describe('OrdersRepository update status test', () => {
chainId_orderStatus: `${MOCK_ORDER_1.chainId}_${ORDER_STATUS.FILLED}`,
chainId_orderStatus_filler: `${MOCK_ORDER_1.chainId}_${ORDER_STATUS.FILLED}_${(MOCK_ORDER_1 as any).filler}`,
txHash: 'txHash',
fillBlock: 1,
settledAmounts: [{ tokenOut: '0x1', amountOut: '1' }],
})
})
Expand Down
2 changes: 2 additions & 0 deletions test/unit/models/DutchV3Order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('DutchV3 Model', () => {
undefined,
undefined,
undefined,
undefined,
100
)
const entity: UniswapXOrderEntity = order.toEntity(ORDER_STATUS.OPEN)
Expand All @@ -45,6 +46,7 @@ describe('DutchV3 Model', () => {
undefined,
undefined,
undefined,
undefined,
100
)
const response: GetDutchV3OrderResponse = order.toGetResponse()
Expand Down

0 comments on commit 90369ba

Please sign in to comment.