Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uniswapx-sdk): Implement Dutch V3 #84

Merged
merged 50 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ec6cb33
feat: V3DutchOrder
alanhwu Sep 3, 2024
5ea0ce8
feat, test: create orders from JSON
alanhwu Sep 3, 2024
89cbd0e
feat, test: cosigning v3 orders
alanhwu Sep 3, 2024
c409254
fix: linting
alanhwu Sep 3, 2024
fdd909e
fix: more linting
alanhwu Sep 3, 2024
612d1bf
refactor: update relativeAmounts name
alanhwu Sep 3, 2024
7222b53
feat, test: resolve & decay with math tests
alanhwu Sep 5, 2024
080d616
test: extra resolve v3 test, comments
alanhwu Sep 6, 2024
cebaa8a
feat, test: MVP v3 OrderBuilder
alanhwu Sep 6, 2024
f8430de
refactor: clean reuse of v2 for v3
alanhwu Sep 6, 2024
f50e745
feat, test: robust testing, helpers for v3 cosignerData building
alanhwu Sep 6, 2024
4138f2c
feat, test: v3 buildPartial
alanhwu Sep 6, 2024
4a93058
feat, test: v3 builder fromOrder
alanhwu Sep 6, 2024
e221b4a
feat, test: v3 orderTrade
alanhwu Sep 6, 2024
73db687
fix: cosigned order detection
alanhwu Sep 6, 2024
54888da
fix: tiny, linting
alanhwu Sep 11, 2024
8ef21c7
refactor: rename CosignerData types
alanhwu Sep 11, 2024
adae9f2
refactor: move order amount helper to utils
alanhwu Sep 11, 2024
d21c580
refactor: relativeBlocks decoding for clarity
alanhwu Sep 11, 2024
69fa516
refactor: update v3 curve type name to new name in contract
alanhwu Sep 11, 2024
81710ab
style: linting
alanhwu Sep 11, 2024
d63c65e
fix, test: dutchBlockDecay rounding math
alanhwu Sep 11, 2024
5af9cf1
feat, test: support negative relativeAmounts with BigInt
alanhwu Sep 12, 2024
e58c9ee
fix: BigInt -> bigint
alanhwu Sep 12, 2024
d63c629
test: dutchBlockDecay
alanhwu Sep 12, 2024
ed7ad9c
fix: fully serialize V3 JSONs
alanhwu Sep 12, 2024
e85054c
feat: relax V3 upward decay restraint
alanhwu Sep 12, 2024
3c8690e
style: linting
alanhwu Sep 12, 2024
ad14a17
refactor: cleaner type & reuse
alanhwu Sep 12, 2024
64f8d35
feat: align dutchBlockDecay with updated contract
alanhwu Sep 12, 2024
4382181
fix, test: stricter calculation of minOut maxIn
alanhwu Sep 12, 2024
10516d7
style: linting
alanhwu Sep 12, 2024
fcf99b4
feat: generic for checking cosigned status
alanhwu Sep 13, 2024
efecbc0
feat, test: V3 decay curve validity invariants
alanhwu Sep 13, 2024
0cec87d
style: linting
alanhwu Sep 13, 2024
7c8d8c4
refactor: clean invariants
alanhwu Sep 13, 2024
361f559
feat, test: Cosigned toJSON, fromJSON
alanhwu Sep 16, 2024
0ca5a19
refactor: use length to decode relativeBlocks
alanhwu Sep 19, 2024
e18e677
refactor: clean determination of cosigned status
alanhwu Sep 19, 2024
a8759dc
fix: test description typos
alanhwu Sep 19, 2024
40d17f0
feat: helper for getting maxAmountOut from V3 curve
alanhwu Sep 19, 2024
3657f09
Merge branch 'main' into v3-dutch-sdk
alanhwu Sep 19, 2024
c4a5acf
Merge branch 'main' into v3-dutch-sdk
alanhwu Sep 23, 2024
f47cac1
feat(uniswapx-sdk): Update Structs & ABI functionality for Dutch V3 G…
alanhwu Oct 11, 2024
c1e9bb1
Merge branch 'main' into v3-dutch-sdk
alanhwu Oct 11, 2024
0faf75b
feat: use real reactor address
alanhwu Oct 23, 2024
cd391b3
Merge branch 'main' into v3-dutch-sdk
alanhwu Oct 24, 2024
0d896ea
feat, test: curve helper supports empty array and strict negative slope
alanhwu Oct 24, 2024
5686917
refactor: export all from V3DutchOrderTrade and V3DutchOrderBuilder
alanhwu Oct 24, 2024
eeca2d4
refactor: find maxAmount more efficiently
alanhwu Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...
alanhwu marked this conversation as resolved.
Show resolved Hide resolved
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
Loading