From e18e677ec17df09520a3991362b2828ae8494c50 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Thu, 19 Sep 2024 15:19:11 -0400 Subject: [PATCH] refactor: clean determination of cosigned status --- sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts | 5 ++--- sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts | 6 +++--- sdks/uniswapx-sdk/src/utils/order.ts | 8 -------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts b/sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts index 509997ec2..79e396a2b 100644 --- a/sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts +++ b/sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts @@ -11,7 +11,7 @@ import { UnsignedV2DutchOrder, } from "../order"; import { ValidationInfo } from "../order/validation"; -import { getPermit2, getReactor, isCosigned } from "../utils"; +import { getPermit2, getReactor } from "../utils"; import { OrderBuilder } from "./OrderBuilder"; @@ -40,7 +40,7 @@ export class V2DutchOrderBuilder extends OrderBuilder { builder.output(output); } - if (isCosigned(order)) { + if (order instanceof CosignedV2DutchOrder) { builder.cosignature(order.info.cosignature); builder.decayEndTime(order.info.cosignerData.decayEndTime); builder.decayStartTime(order.info.cosignerData.decayStartTime); @@ -287,7 +287,6 @@ export class V2DutchOrderBuilder extends OrderBuilder { "exclusivityOverrideBps not set" ); invariant( - this.info.cosignerData.inputOverride !== undefined && // inputOverride is defaulted to 0 because enforced to be of type BigNumber this.info.cosignerData.inputOverride.lte(this.info.input.startAmount), "inputOverride larger than original input" ); diff --git a/sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts b/sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts index 15031b8fd..907349c62 100644 --- a/sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts +++ b/sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts @@ -5,7 +5,7 @@ import { OrderType } from "../constants"; import { CosignedV3DutchOrder, CosignedV3DutchOrderInfo, UnsignedV3DutchOrder, UnsignedV3DutchOrderInfo, V3CosignerData } from "../order/V3DutchOrder"; import { V3DutchInput, V3DutchOutput } from "../order/types"; import { ValidationInfo } from "../order/validation"; -import { getPermit2, getReactor, isCosigned } from "../utils"; +import { getPermit2, getReactor } from "../utils"; import { OrderBuilder } from "./OrderBuilder"; @@ -29,7 +29,7 @@ export class V3DutchOrderBuilder extends OrderBuilder { builder.output(output); }); - if (isCosigned(order)) { + if (order instanceof CosignedV3DutchOrder) { builder.cosignature(order.info.cosignature); builder.decayStartBlock(order.info.cosignerData.decayStartBlock); builder.exclusiveFiller(order.info.cosignerData.exclusiveFiller); @@ -167,7 +167,7 @@ export class V3DutchOrderBuilder extends OrderBuilder { "outputOverride smaller than original output" ); }); - // We are not checking if the decayStartTime is before the deadline because it is not enforced in the smart contract + // We are not checking if the decayStartBlock is before the deadline because it is not enforced in the smart contract } input(input: V3DutchInput): this { diff --git a/sdks/uniswapx-sdk/src/utils/order.ts b/sdks/uniswapx-sdk/src/utils/order.ts index 13a9d78a2..67a2bf389 100644 --- a/sdks/uniswapx-sdk/src/utils/order.ts +++ b/sdks/uniswapx-sdk/src/utils/order.ts @@ -159,14 +159,6 @@ export class RelayOrderParser extends OrderParser { } } -type UnsignedOrder = UnsignedV2DutchOrder | UnsignedV3DutchOrder; -type CosignedOrder = CosignedV2DutchOrder | CosignedV3DutchOrder; -export function isCosigned( - order: T | U -): order is U { - return 'cosignature' in (order as U).info; -} - export function originalIfZero(value: BigNumber, original: BigNumber): BigNumber { return value.isZero() ? original : value; } \ No newline at end of file