Skip to content

Commit a942da1

Browse files
codybornclaude
andcommitted
refactor: re-export ChainId from @uniswap/sdk-core
Drop the local enum in lib/util/chain.ts; consumers keep importing from the same path. Loosen PRIORITY_/HYBRID_ORDER_TARGET_BLOCK_BUFFER from Record<ChainId, number> to Partial<Record<...>> since sdk-core's enum has many more chains than x-service supports, and the sentinel-0 entries for V3-only chains are now unreachable (the validator rejects them upstream); callers throw if a buffer is missing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1972c3a commit a942da1

7 files changed

Lines changed: 24 additions & 65 deletions

File tree

lib/handlers/check-order-status/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class CheckOrderStatusService {
174174
fillTimeBlocks = fillBlock - order.cosignerData.decayStartBlock;
175175
break;
176176
case OrderType.Priority: { // Approximation
177-
const orderCreationBlock = order.cosignerData.auctionTargetBlock - PRIORITY_ORDER_TARGET_BLOCK_BUFFER[chainId as ChainId];
177+
const orderCreationBlock = order.cosignerData.auctionTargetBlock - (PRIORITY_ORDER_TARGET_BLOCK_BUFFER[chainId as ChainId] ?? 0);
178178
fillTimeBlocks = fillBlock - orderCreationBlock;
179179
break;
180180
}

lib/handlers/constants.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ export const DEFAULT_MAX_OPEN_ORDERS = 5
1515
export const DEFAULT_MAX_OPEN_LIMIT_ORDERS = 100
1616
export const HIGH_MAX_OPEN_ORDERS = 200
1717

18-
// Chains that register Dutch_V3 only (no priority/hybrid reactor in
19-
// @uniswap/uniswapx-sdk's REACTOR_ADDRESS_MAPPING) get sentinel-0 entries
20-
// here to satisfy Record<ChainId, number> typing.
2118
// OffChainUniswapXOrderValidator.validateReactorAddress rejects
22-
// priority/hybrid orders for those chainIds before these buffers are
23-
// consulted, so the values are unreachable in practice.
24-
export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER: Record<ChainId, number> = {
19+
// priority/hybrid orders for chains not listed here before these buffers
20+
// are consulted, so callers can safely treat a missing entry as unreachable.
21+
export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER: Partial<Record<ChainId, number>> = {
2522
[ChainId.MAINNET]: 3,
2623
[ChainId.UNICHAIN]: 4,
2724
[ChainId.BASE]: 3,
@@ -30,23 +27,9 @@ export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER: Record<ChainId, number> = {
3027
[ChainId.POLYGON]: 3,
3128
[ChainId.SEPOLIA]: 3,
3229
[ChainId.UNICHAIN_SEPOLIA]: 4,
33-
// V3-rollout chains: priority orders unreachable (see comment above).
34-
[ChainId.TEMPO]: 0,
35-
[ChainId.BNB]: 0,
36-
[ChainId.MONAD]: 0,
37-
[ChainId.XLAYER]: 0,
38-
[ChainId.WORLDCHAIN]: 0,
39-
[ChainId.SONEIUM]: 0,
40-
[ChainId.CELO]: 0,
41-
[ChainId.AVALANCHE]: 0,
42-
[ChainId.BLAST]: 0,
43-
[ChainId.ZORA]: 0,
4430
}
4531

46-
// Hybrid orders use target block to determine when the price curve starts.
47-
// Same reasoning as PRIORITY_ORDER_TARGET_BLOCK_BUFFER above: V3-rollout chains
48-
// have no hybrid reactor, so the entries below are unreachable sentinel-0s.
49-
export const HYBRID_ORDER_TARGET_BLOCK_BUFFER: Record<ChainId, number> = {
32+
export const HYBRID_ORDER_TARGET_BLOCK_BUFFER: Partial<Record<ChainId, number>> = {
5033
[ChainId.MAINNET]: 3,
5134
[ChainId.UNICHAIN]: 4,
5235
[ChainId.BASE]: 3,
@@ -55,17 +38,6 @@ export const HYBRID_ORDER_TARGET_BLOCK_BUFFER: Record<ChainId, number> = {
5538
[ChainId.POLYGON]: 3,
5639
[ChainId.SEPOLIA]: 3,
5740
[ChainId.UNICHAIN_SEPOLIA]: 4,
58-
// V3-rollout chains: hybrid orders unreachable (see comment above).
59-
[ChainId.TEMPO]: 0,
60-
[ChainId.BNB]: 0,
61-
[ChainId.MONAD]: 0,
62-
[ChainId.XLAYER]: 0,
63-
[ChainId.WORLDCHAIN]: 0,
64-
[ChainId.SONEIUM]: 0,
65-
[ChainId.CELO]: 0,
66-
[ChainId.AVALANCHE]: 0,
67-
[ChainId.BLAST]: 0,
68-
[ChainId.ZORA]: 0,
6941
}
7042

7143
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 20

lib/models/HybridOrder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ export class HybridOrder extends Order {
158158
// If the difference is more than 75% of the block time, add an extra block
159159
const extraBlock = timeDifference > blockTimeSeconds * 0.75 ? 1 : 0
160160

161-
const targetBlock = BigNumber.from(block.number)
162-
.add(HYBRID_ORDER_TARGET_BLOCK_BUFFER[this.chainId as ChainId])
163-
.add(extraBlock)
161+
const buffer = HYBRID_ORDER_TARGET_BLOCK_BUFFER[this.chainId as ChainId]
162+
if (buffer === undefined) {
163+
throw new Error(`HYBRID_ORDER_TARGET_BLOCK_BUFFER missing for chainId ${this.chainId}`)
164+
}
165+
const targetBlock = BigNumber.from(block.number).add(buffer).add(extraBlock)
164166

165167
const scaleWorse = process.env['SCALE_WORSE'] === 'true'
166168

lib/models/PriorityOrder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ export class PriorityOrder extends Order {
121121
// If the difference is more than 75% of the block time, add an extra block
122122
const extraBlock = timeDifference > blockTimeSeconds * 0.75 ? 1 : 0
123123

124+
const buffer = PRIORITY_ORDER_TARGET_BLOCK_BUFFER[this.chainId as ChainId]
125+
if (buffer === undefined) {
126+
throw new Error(`PRIORITY_ORDER_TARGET_BLOCK_BUFFER missing for chainId ${this.chainId}`)
127+
}
124128
this.inner.info.cosignerData = {
125-
auctionTargetBlock: BigNumber.from(block.number)
126-
.add(PRIORITY_ORDER_TARGET_BLOCK_BUFFER[this.chainId as ChainId])
127-
.add(extraBlock),
129+
auctionTargetBlock: BigNumber.from(block.number).add(buffer).add(extraBlock),
128130
}
129131

130132
this.inner.info.cosignature = await cosigner.signDigest(this.inner.cosignatureHash(this.inner.info.cosignerData))

lib/util/chain.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
export enum ChainId {
2-
MAINNET = 1,
3-
UNICHAIN = 130,
4-
BASE = 8453,
5-
OPTIMISM = 10,
6-
ARBITRUM_ONE = 42161,
7-
POLYGON = 137,
8-
SEPOLIA = 11155111,
9-
UNICHAIN_SEPOLIA = 1301,
10-
TEMPO = 4217,
11-
BNB = 56,
12-
MONAD = 143,
13-
XLAYER = 196,
14-
WORLDCHAIN = 480,
15-
SONEIUM = 1868,
16-
CELO = 42220,
17-
AVALANCHE = 43114,
18-
BLAST = 81457,
19-
ZORA = 7777777,
20-
}
1+
import { ChainId } from '@uniswap/sdk-core'
2+
3+
export { ChainId }
214

225
// Each chain in SUPPORTED_CHAINS needs an RPC URL resolvable by
236
// getRpcUrl(chainId) (Config.ts), which appends the chainId to

test/unit/handlers/post-order/post-order.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('Testing post order handler.', () => {
336336
// cosignature and cosignerData gets overwritten within the handler
337337
order.inner.info.cosignature = COSIGNATURE
338338
order.inner.info.cosignerData = {
339-
auctionTargetBlock: BigNumber.from(MOCK_LATEST_BLOCK + PRIORITY_ORDER_TARGET_BLOCK_BUFFER[order.chainId as ChainId]), // No extra block since timestamp difference should be 0
339+
auctionTargetBlock: BigNumber.from(MOCK_LATEST_BLOCK + PRIORITY_ORDER_TARGET_BLOCK_BUFFER[order.chainId as ChainId]!), // No extra block since timestamp difference should be 0
340340
}
341341
const expectedOrderEntity = order.toEntity(ORDER_STATUS.OPEN)
342342
expect(postOrderResponse.statusCode).toEqual(HttpStatusCode.Created)
@@ -349,7 +349,7 @@ describe('Testing post order handler.', () => {
349349
cosignature: COSIGNATURE,
350350
cosignerData: {
351351
// MOCK_LATEST_BLOCK + 3
352-
auctionTargetBlock: MOCK_LATEST_BLOCK + PRIORITY_ORDER_TARGET_BLOCK_BUFFER[order.chainId as ChainId],
352+
auctionTargetBlock: MOCK_LATEST_BLOCK + PRIORITY_ORDER_TARGET_BLOCK_BUFFER[order.chainId as ChainId]!,
353353
},
354354
})
355355
)
@@ -467,7 +467,7 @@ describe('Testing post order handler.', () => {
467467

468468
expect(postOrderResponse.statusCode).toEqual(HttpStatusCode.Created)
469469

470-
const expectedBuffer = PRIORITY_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]
470+
const expectedBuffer = PRIORITY_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]!
471471
const expectedTargetBlock = MOCK_LATEST_BLOCK + expectedBuffer + 1 // +1 for extra block
472472

473473
expect(putOrderAndUpdateNonceTransactionMock).toBeCalledWith(

test/unit/models/HybridOrder.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('HybridOrder Model', () => {
143143

144144
await order.reparameterizeAndCosign(mockProvider, mockCosigner)
145145

146-
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]
146+
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]!
147147
expect(order.inner.info.cosignerData.auctionTargetBlock.toNumber()).toEqual(expectedTargetBlock)
148148
})
149149

@@ -165,7 +165,7 @@ describe('HybridOrder Model', () => {
165165
await order.reparameterizeAndCosign(mockProvider, mockCosigner)
166166

167167
// Should add extra block due to stale timestamp
168-
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET] + 1
168+
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]! + 1
169169
expect(order.inner.info.cosignerData.auctionTargetBlock.toNumber()).toEqual(expectedTargetBlock)
170170
})
171171
})
@@ -309,7 +309,7 @@ describe('HybridOrder Model', () => {
309309

310310
await order.reparameterizeAndCosign(mockProvider, mockCosigner)
311311

312-
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]
312+
const expectedTargetBlock = MOCK_LATEST_BLOCK + HYBRID_ORDER_TARGET_BLOCK_BUFFER[ChainId.MAINNET]!
313313
expect(order.inner.info.cosignerData.auctionTargetBlock.toNumber()).toEqual(expectedTargetBlock)
314314
expect(order.inner.info.cosignerData.supplementalPriceCurve).toEqual([])
315315
})

0 commit comments

Comments
 (0)