Skip to content

Commit

Permalink
refactor: clean determination of cosigned status
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Sep 19, 2024
1 parent 0ca5a19 commit e18e677
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
5 changes: 2 additions & 3 deletions sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -40,7 +40,7 @@ export class V2DutchOrderBuilder extends OrderBuilder {
builder.output(output);
}

if (isCosigned<UnsignedV2DutchOrder, CosignedV2DutchOrder>(order)) {
if (order instanceof CosignedV2DutchOrder) {
builder.cosignature(order.info.cosignature);
builder.decayEndTime(order.info.cosignerData.decayEndTime);
builder.decayStartTime(order.info.cosignerData.decayStartTime);
Expand Down Expand Up @@ -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"
);
Expand Down
6 changes: 3 additions & 3 deletions sdks/uniswapx-sdk/src/builder/V3DutchOrderBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -29,7 +29,7 @@ export class V3DutchOrderBuilder extends OrderBuilder {
builder.output(output);
});

if (isCosigned<UnsignedV3DutchOrder, CosignedV3DutchOrder>(order)) {
if (order instanceof CosignedV3DutchOrder) {
builder.cosignature(order.info.cosignature);
builder.decayStartBlock(order.info.cosignerData.decayStartBlock);
builder.exclusiveFiller(order.info.cosignerData.exclusiveFiller);
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 0 additions & 8 deletions sdks/uniswapx-sdk/src/utils/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ export class RelayOrderParser extends OrderParser {
}
}

type UnsignedOrder = UnsignedV2DutchOrder | UnsignedV3DutchOrder;
type CosignedOrder = CosignedV2DutchOrder | CosignedV3DutchOrder;
export function isCosigned<T extends UnsignedOrder, U extends CosignedOrder>(
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;
}

0 comments on commit e18e677

Please sign in to comment.