From 719a1928536864ad37f9b6a1cbe8bd07a200599f Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Mon, 2 Dec 2024 18:43:43 +0800 Subject: [PATCH] fix: dynamically get order type for posting to service --- lib/providers/order/uniswapxService.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/providers/order/uniswapxService.ts b/lib/providers/order/uniswapxService.ts index e17e79f..bca27a0 100644 --- a/lib/providers/order/uniswapxService.ts +++ b/lib/providers/order/uniswapxService.ts @@ -4,9 +4,13 @@ import Logger from 'bunyan'; import { OrderServiceProvider, PostOrderArgs, UniswapXServiceResponse } from '.'; import { ErrorResponse } from '../../handlers/base'; import { ErrorCode } from '../../util/errors'; +import { CosignedV2DutchOrder, CosignedV3DutchOrder } from '@uniswap/uniswapx-sdk'; const ORDER_SERVICE_TIMEOUT_MS = 2000; -const V2_ORDER_TYPE = 'Dutch_V2'; +const ORDER_TYPE_MAP = new Map([ + [CosignedV2DutchOrder, 'Dutch_V2'], + [CosignedV3DutchOrder, 'Dutch_V3'] +]); export class UniswapXServiceProvider implements OrderServiceProvider { private log: Logger; @@ -19,6 +23,11 @@ export class UniswapXServiceProvider implements OrderServiceProvider { const { order, signature, quoteId, requestId } = args; this.log.info({ orderHash: order.hash() }, 'Posting order to UniswapX Service'); + const orderType = ORDER_TYPE_MAP.get(order.constructor); + if (!orderType) { + throw new Error(`Unsupported order type: ${order.constructor.name}`); + } + const axiosConfig = { timeout: ORDER_SERVICE_TIMEOUT_MS, }; @@ -31,7 +40,7 @@ export class UniswapXServiceProvider implements OrderServiceProvider { chainId: order.chainId, quoteId: quoteId, requestId: requestId, - orderType: V2_ORDER_TYPE, + orderType: orderType, }, axiosConfig );