Skip to content

Commit

Permalink
fix: dynamically get order type for posting to service (#394)
Browse files Browse the repository at this point in the history
* fix: dynamically get order type for posting to service

* Use SDK constants

---------

Co-authored-by: Cody Born <cody.born@uniswap.org>
  • Loading branch information
alanhwu and codyborn authored Dec 2, 2024
1 parent c3dc16b commit 57bf532
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/providers/order/uniswapxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, OrderType } from '@uniswap/uniswapx-sdk';

const ORDER_SERVICE_TIMEOUT_MS = 2000;
const V2_ORDER_TYPE = 'Dutch_V2';
const ORDER_TYPE_MAP = new Map<Function, string>([
[CosignedV2DutchOrder, OrderType.Dutch_V2],
[CosignedV3DutchOrder, OrderType.Dutch_V3]
]);

export class UniswapXServiceProvider implements OrderServiceProvider {
private log: Logger;
Expand All @@ -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,
};
Expand All @@ -31,7 +40,7 @@ export class UniswapXServiceProvider implements OrderServiceProvider {
chainId: order.chainId,
quoteId: quoteId,
requestId: requestId,
orderType: V2_ORDER_TYPE,
orderType: orderType,
},
axiosConfig
);
Expand Down

0 comments on commit 57bf532

Please sign in to comment.