Skip to content

feat: decrease priority orders buffer to 2 #511

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion lib/handlers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export const DEFAULT_MAX_OPEN_ORDERS = 5
export const DEFAULT_MAX_OPEN_LIMIT_ORDERS = 100
export const HIGH_MAX_OPEN_ORDERS = 200

export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER = 3
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 20;
15 changes: 13 additions & 2 deletions lib/models/PriorityOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { KmsSigner } from '@uniswap/signer'
import { CosignedPriorityOrder as SDKPriorityOrder, OrderType } from '@uniswap/uniswapx-sdk'
import { BigNumber } from 'ethers'
import { ORDER_STATUS, PriorityOrderEntity, UniswapXOrderEntity } from '../entities'
import { PRIORITY_ORDER_TARGET_BLOCK_BUFFER } from '../handlers/constants'
import { GetPriorityOrderResponse } from '../handlers/get-orders/schema/GetPriorityOrderResponse'
import { Order } from './Order'
import { QuoteMetadata } from '../repositories/quote-metadata-repository'
import { ChainId } from '../util/chain'

export class PriorityOrder extends Order {
private static readonly DEFAULT_TARGET_BLOCK_BUFFER = 2

constructor(
readonly inner: SDKPriorityOrder,
readonly signature: string,
Expand All @@ -22,6 +24,15 @@ export class PriorityOrder extends Order {
super()
}

public get targetBlockBuffer(): number {
switch (this.chainId) {
case ChainId.BASE:
return 2
default:
return PriorityOrder.DEFAULT_TARGET_BLOCK_BUFFER
}
}

get orderType(): OrderType {
return OrderType.Priority
}
Expand Down Expand Up @@ -86,7 +97,7 @@ export class PriorityOrder extends Order {
public async reparameterizeAndCosign(provider: StaticJsonRpcProvider, cosigner: KmsSigner): Promise<this> {
const currentBlock = await provider.getBlockNumber()
this.inner.info.cosignerData = {
auctionTargetBlock: BigNumber.from(currentBlock).add(PRIORITY_ORDER_TARGET_BLOCK_BUFFER),
auctionTargetBlock: BigNumber.from(currentBlock).add(this.targetBlockBuffer),
}

this.inner.info.cosignature = await cosigner.signDigest(this.inner.cosignatureHash(this.inner.info.cosignerData))
Expand Down
7 changes: 3 additions & 4 deletions test/unit/handlers/post-order/post-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { mock } from 'jest-mock-extended'
import { ORDER_STATUS, UniswapXOrderEntity } from '../../../../lib/entities'
import { ErrorCode } from '../../../../lib/handlers/base'
import { FillEventLogger } from '../../../../lib/handlers/check-order-status/fill-event-logger'
import { DEFAULT_MAX_OPEN_ORDERS, PRIORITY_ORDER_TARGET_BLOCK_BUFFER } from '../../../../lib/handlers/constants'
import { DEFAULT_MAX_OPEN_ORDERS } from '../../../../lib/handlers/constants'
import { EventWatcherMap } from '../../../../lib/handlers/EventWatcherMap'
import { OnChainValidatorMap } from '../../../../lib/handlers/OnChainValidatorMap'
import { PostOrderHandler } from '../../../../lib/handlers/post-order/handler'
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Testing post order handler.', () => {
// cosignature and cosignerData gets overwritten within the handler
order.inner.info.cosignature = COSIGNATURE
order.inner.info.cosignerData = {
auctionTargetBlock: BigNumber.from(MOCK_LATEST_BLOCK + PRIORITY_ORDER_TARGET_BLOCK_BUFFER),
auctionTargetBlock: BigNumber.from(MOCK_LATEST_BLOCK + order.targetBlockBuffer),
}
const expectedOrderEntity = order.toEntity(ORDER_STATUS.OPEN)
expect(postOrderResponse.statusCode).toEqual(HttpStatusCode.Created)
Expand All @@ -343,8 +343,7 @@ describe('Testing post order handler.', () => {
requestId: expect.any(String),
cosignature: COSIGNATURE,
cosignerData: {
// MOCK_LATEST_BLOCK + 3
auctionTargetBlock: 103,
auctionTargetBlock: BigNumber.from(MOCK_LATEST_BLOCK).add(order.targetBlockBuffer).toNumber(),
},
})
)
Expand Down
Loading