Skip to content

Commit

Permalink
feat(uniswapx-sdk): Implement Dutch V3 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu authored Oct 24, 2024
1 parent 59420cc commit 6a0d553
Show file tree
Hide file tree
Showing 26 changed files with 4,690 additions and 39 deletions.
1 change: 1 addition & 0 deletions sdks/uniswapx-sdk/abis/V3DutchOrderReactor.json

Large diffs are not rendered by default.

833 changes: 833 additions & 0 deletions sdks/uniswapx-sdk/integration/test/V3DutchOrder.spec.ts

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions sdks/uniswapx-sdk/integration/test/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export class BlockchainTime {
return timestamp + secondsFromNow;
}

async blocksFromNow(blocksFromNow: number): Promise<number> {
const res = await hre.network.provider.send('eth_getBlockByNumber', [
'latest',
false,
]);
const blockNum = parseInt(res.number, 16);
return blockNum + blocksFromNow;
}

async increaseTime(seconds: number): Promise<void> {
await hre.network.provider.send('evm_increaseTime', [seconds]);
await hre.network.provider.send('evm_mine');
Expand Down
4 changes: 2 additions & 2 deletions sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe("V2DutchOrderBuilder", () => {
.outputOverrides([OUTPUT_START_AMOUNT.mul(102).div(100)])
.build()
).toThrow(
"Invariant failed: inputOverride not set or larger than original input"
"Invariant failed: inputOverride larger than original input"
);
});

Expand Down Expand Up @@ -574,7 +574,7 @@ describe("V2DutchOrderBuilder", () => {
});

describe("partial order tests", () => {
it("builds an unsigned partial order with default cosignerData values", () => {
it("builds an unsigned partial order with default cosignerData values", () => { //TODO: partial orders don't have cosignerData...
const deadline = Math.floor(Date.now() / 1000) + 1000;
const order = builder
.cosigner(constants.AddressZero)
Expand Down
11 changes: 2 additions & 9 deletions sdks/uniswapx-sdk/src/builder/V2DutchOrderBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -287,9 +287,8 @@ export class V2DutchOrderBuilder extends OrderBuilder {
"exclusivityOverrideBps not set"
);
invariant(
this.info.cosignerData.inputOverride !== undefined &&
this.info.cosignerData.inputOverride.lte(this.info.input.startAmount),
"inputOverride not set or larger than original input"
"inputOverride larger than original input"
);
invariant(
this.info.cosignerData.outputOverrides.length > 0,
Expand Down Expand Up @@ -339,9 +338,3 @@ export class V2DutchOrderBuilder extends OrderBuilder {
};
}
}

function isCosigned(
order: UnsignedV2DutchOrder | CosignedV2DutchOrder
): order is CosignedV2DutchOrder {
return (order as CosignedV2DutchOrder).info.cosignature !== undefined;
}
Loading

0 comments on commit 6a0d553

Please sign in to comment.