Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fillBlock to table & V3 queries #503

Merged
merged 4 commits into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion bin/stacks/dashboard-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class DashboardStack extends cdk.NestedStack {
x: 0,
type: 'log',
properties: {
query: `SOURCE '/aws/lambda/${orderStatusLambdaName}' | fields orderInfo.orderHash as orderHash, orderInfo.tokenInChainId as chainId, orderInfo.offerer as offerer,orderInfo.exclusiveFiller as exclusiveFiller, orderInfo.filler as filler, orderInfo.tokenOut as tokenOut, orderInfo.amountOut as amountOut, orderInfo.blockNumber as blockNumber, orderInfo.txHash as txHash, orderInfo.gasUsed as gasUsed, orderInfo.gasCostInETH as gasCostInEth\n| filter ispresent(orderInfo.orderStatus) and orderInfo.orderStatus = 'filled'\n| sort @timestamp desc`,
query: `SOURCE '/aws/lambda/${orderStatusLambdaName}' | fields orderInfo.orderHash as orderHash, orderInfo.tokenInChainId as chainId, orderInfo.offerer as offerer,orderInfo.exclusiveFiller as exclusiveFiller, orderInfo.filler as filler, orderInfo.tokenOut as tokenOut, orderInfo.amountOut as amountOut, orderInfo.blockNumber as blockNumber, orderInfo.txHash as txHash, orderInfo.fillBlock as fillBlock, orderInfo.gasUsed as gasUsed, orderInfo.gasCostInETH as gasCostInEth\n| filter ispresent(orderInfo.orderStatus) and orderInfo.orderStatus = 'filled'\n| sort @timestamp desc`,
region,
stacked: false,
view: 'table',
Expand Down
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/RelayOrderRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class RelayOrderRepository extends GenericOrdersRepository<string, string
relayFee: { type: DYNAMODB_TYPES.MAP },
quoteId: { type: DYNAMODB_TYPES.STRING },
txHash: { type: DYNAMODB_TYPES.STRING },
fillBlock: { type: DYNAMODB_TYPES.NUMBER },
settledAmounts: { type: DYNAMODB_TYPES.LIST },

offerer_orderStatus: { type: DYNAMODB_TYPES.STRING },
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
4 changes: 3 additions & 1 deletion 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,7 +118,8 @@ export abstract class GenericOrdersRepository<
[TABLE_KEY.ORDER_HASH]: orderHash,
...this.indexMapper.getIndexFieldsForStatusUpdate(order, status),
...(txHash && { txHash }),
...(settledAmounts && { settledAmounts }),
...(fillBlock && { fillBlock }),
...(settledAmounts && { settledAmounts })
})
} catch (e) {
log.error('updateOrderStatus error', { error: e })
Expand Down
1 change: 1 addition & 0 deletions lib/repositories/limit-orders-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class LimitOrdersRepository extends GenericOrdersRepository<string, strin
filler_offerer_orderStatus: { type: DYNAMODB_TYPES.STRING },
quoteId: { type: DYNAMODB_TYPES.STRING },
txHash: { type: DYNAMODB_TYPES.STRING },
fillBlock: { type: DYNAMODB_TYPES.NUMBER },
settledAmounts: { type: DYNAMODB_TYPES.LIST },
},
table: limitOrdersTable,
Expand Down
4 changes: 4 additions & 0 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@
"description": "TxHash field is defined when the order has been filled and there is a txHash associated with the fill.",
"type": "string"
},
"fillBlock": {
"description": "Fill block field is defined when the order has been filled and the fill block has been recorded.",
"type": "number"
},
"settledAmounts": {
"description": "SettledAmount field is defined when the order has been filled and the fill amounts have been recorded.",
"type": "array",
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
2 changes: 1 addition & 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 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
Loading