Skip to content

Commit a0ca089

Browse files
codybornclaude
andauthored
fix: guard REACTOR_ADDRESS_MAPPING[chainId] against undefined (#669)
PR #654 expanded SUPPORTED_CHAINS from 7 to 18, but not every new chain has an entry in the SDK's REACTOR_ADDRESS_MAPPING. Five call sites indexed REACTOR_ADDRESS_MAPPING[chainId][orderType] without guarding the parent, so an unmapped chain produced "TypeError: Cannot read properties of undefined (reading 'Relay')". EventWatcherMap.createRelayEventWatcherMap() runs at module load of get-orders/index.ts. With beta provisioned concurrency reset to 0 (#666), every cold start re-evaluated the module, the TypeError aborted init, and API Gateway surfaced 502s for requests that should have been 4xx (e.g. e2e Error Handling > should handle invalid parameters). Optional-chain the lookups so unmapped chains fall through to existing guard branches: - EventWatcherMap: skip the chain instead of throwing at module load. - OffChain{Relay,UniswapX}OrderValidator: return "Invalid reactor address" (400) instead of TypeError (500). - check-order-status/util.getWatcher: existing throw fires with the intended message instead of a TypeError. - gs-reaper.processBlockRange: short-circuit the orderType loop when the chain has no reactor mapping; the cron keeps running for other chains. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0fb5730 commit a0ca089

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/crons/gs-reaper/gs-reaper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ async function processBlockRange(
266266
): Promise<{ updates: Record<string, OrderUpdate>, remainingHashes: Set<string> }> {
267267
const orderUpdates = { ...existingUpdates }
268268

269-
for (const orderType of Object.keys(REACTOR_ADDRESS_MAPPING[chainId])) {
270-
const reactorAddress = REACTOR_ADDRESS_MAPPING[chainId][orderType as OrderType]
269+
const reactorMap = REACTOR_ADDRESS_MAPPING[chainId]
270+
if (!reactorMap) {
271+
log.info(`No reactor mapping for chainId ${chainId}, skipping block range`)
272+
return { updates: orderUpdates, remainingHashes: orderHashSet }
273+
}
274+
for (const orderType of Object.keys(reactorMap)) {
275+
const reactorAddress = reactorMap[orderType as OrderType]
271276
if (!reactorAddress || reactorAddress === "0x0000000000000000000000000000000000000000") continue
272277
log.info(`Processing block range ${fromBlock} to ${toBlock} for chainId ${chainId} orderType ${orderType}`)
273278

lib/handlers/EventWatcherMap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export class EventWatcherMap<T extends UniswapXEventWatcher | RelayEventWatcher>
2929
public static createRelayEventWatcherMap() {
3030
const map = new EventWatcherMap<RelayEventWatcher>()
3131
for (const chainId of SUPPORTED_CHAINS) {
32-
const address = REACTOR_ADDRESS_MAPPING[chainId][OrderType.Relay]
32+
const address = REACTOR_ADDRESS_MAPPING[chainId]?.[OrderType.Relay]
3333
if (!address) {
34-
throw new Error(`No Reactor Address Configured for ${chainId}, ${OrderType.Relay}`)
34+
continue
3535
}
3636
map.set(
3737
chainId,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export function getWatcher(
284284
orderType: OrderType
285285
): UniswapXEventWatcher {
286286
const reactorType = orderType === OrderType.Limit ? OrderType.Dutch : orderType
287-
const address = REACTOR_ADDRESS_MAPPING[chainId][reactorType]
287+
const address = REACTOR_ADDRESS_MAPPING[chainId]?.[reactorType]
288288
if (!address) {
289289
throw new Error(`No Reactor Address Defined in UniswapX SDK for chainId:${chainId}, orderType:${reactorType}`)
290290
}

lib/util/OffChainRelayOrderValidator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export class OffChainRelayOrderValidator {
7272
}
7373

7474
private validateReactorAddress(reactor: string, chainId: number): OrderValidationResponse {
75-
if (reactor.toLowerCase() != REACTOR_ADDRESS_MAPPING[chainId][OrderType.Relay]!.toLowerCase()) {
75+
const expected = REACTOR_ADDRESS_MAPPING[chainId]?.[OrderType.Relay]
76+
if (!expected || reactor.toLowerCase() != expected.toLowerCase()) {
7677
return {
7778
valid: false,
7879
errorString: `Invalid reactor address`,

lib/util/OffChainUniswapXOrderValidator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export class OffChainUniswapXOrderValidator {
254254
chainId: number,
255255
orderType: OrderType | undefined
256256
): OrderValidationResponse {
257-
if (!orderType || reactor.toLowerCase() != REACTOR_ADDRESS_MAPPING[chainId][orderType]!.toLowerCase()) {
257+
const expected = orderType ? REACTOR_ADDRESS_MAPPING[chainId]?.[orderType] : undefined
258+
if (!expected || reactor.toLowerCase() != expected.toLowerCase()) {
258259
return {
259260
valid: false,
260261
errorString: `Invalid reactor address`,

0 commit comments

Comments
 (0)