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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: more linting
alanhwu committed Sep 3, 2024

Verified

This commit was signed with the committer’s verified signature.
alanhwu Alan Wu
commit fdd909e3a1579fb28d9d0b3c57a1a648b86e594a
6 changes: 3 additions & 3 deletions sdks/uniswapx-sdk/src/order/V3DutchOrder.test.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const COSIGNER_DATA = {
exclusiveFiller: ethers.constants.AddressZero,
exclusivityOverrideBps: BigNumber.from(0),
inputOverride: RAW_AMOUNT,
outputOverrides: [RAW_AMOUNT.mul(102).div(100)]
outputOverrides: [RAW_AMOUNT.mul(102).div(100)],
};

describe("V3DutchOrder", () => {
@@ -91,8 +91,8 @@ describe("V3DutchOrder", () => {
relativeAmount: [BigNumber.from(1), BigNumber.from(2), BigNumber.from(3), BigNumber.from(4)],
},
recipient: ethers.constants.AddressZero,
}
]
},
],
};
const order = UnsignedV3DutchOrder.fromJSON(orderInfoJSON, CHAIN_ID);
expect(order.info.input.startAmount.toString()).to.equal("1000000");
7 changes: 4 additions & 3 deletions sdks/uniswapx-sdk/src/order/V3DutchOrder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getPermit2 } from "../utils";
import { V3DutchInput, OffChainOrder, OrderInfo, V3DutchInputJSON, V3DutchOutput, V3DutchOutputJSON, BlockOverrides } from "./types";
import { BigNumber, ethers } from "ethers";

Check failure on line 1 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

`ethers` import should occur after import of `@uniswap/permit2-sdk`
import { PermitTransferFromData, SignatureTransfer, PermitTransferFrom, Witness } from "@uniswap/permit2-sdk";
import { SignatureLike } from "@ethersproject/bytes";
import { PermitTransferFrom, PermitTransferFromData, SignatureTransfer, Witness } from "@uniswap/permit2-sdk";

import { V3DutchInput, OffChainOrder, OrderInfo, V3DutchInputJSON, V3DutchOutput, V3DutchOutputJSON, BlockOverrides } from "./types";

Check failure on line 5 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

There should be at least one empty line between import groups

Check failure on line 5 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

`./types` import should occur after import of `../utils`

Check failure on line 5 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Member 'OffChainOrder' of the import declaration should be sorted alphabetically
import { getPermit2 } from "../utils";

export type CosignerDataJSON = {
alanhwu marked this conversation as resolved.
Show resolved Hide resolved
decayStartBlock: number;
@@ -78,7 +79,7 @@
V3Decay: [
{ name: "relativeBlocks", type: "uint256" },
{ name: "relativeAmount", type: "int256[]" },
]

Check failure on line 82 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Missing trailing comma
};

const V3_DUTCH_ORDER_ABI = [
@@ -89,8 +90,8 @@
"tuple(address,uint256,tuple(uint256,int256[]),uint256)", // V3DutchInput
"tuple(address,uint256,tuple(uint256,int256[]),address)[]", // V3DutchOutput
COSIGNER_DATA_TUPLE_ABI,
"bytes" // Cosignature

Check failure on line 93 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Missing trailing comma
].join(",") + ")"

Check failure on line 94 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Missing trailing comma
];

export class UnsignedV3DutchOrder implements OffChainOrder {
@@ -118,9 +119,9 @@
startAmount: BigNumber.from(json.input.startAmount),
curve: {
relativeBlocks: json.input.curve.relativeBlocks,
relativeAmount: json.input.curve.relativeAmount.map(BigNumber.from)

Check failure on line 122 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Missing trailing comma
},
maxAmount: BigNumber.from(json.input.maxAmount)

Check failure on line 124 in sdks/uniswapx-sdk/src/order/V3DutchOrder.ts

GitHub Actions / Lint, Build, and Test

Missing trailing comma
},
outputs: json.outputs.map(output => ({
...output,

Unchanged files with check annotations Beta

* Returns the resolved order with the given options
* @return The resolved order
*/
resolve(_options: PriorityOrderResolutionOptions): ResolvedUniswapXOrder {

Check warning on line 297 in sdks/uniswapx-sdk/src/order/PriorityOrder.ts

GitHub Actions / Lint, Build, and Test

'_options' is defined but never used
// no cosigner data so no resolution possible
throw new Error("Method not implemented.");
}
params: MulticallSameContractParams<TFunctionParams>,
stateOverrrides?: {
code?: string;
state?: any

Check warning on line 54 in sdks/uniswapx-sdk/src/utils/multicall.ts

GitHub Actions / Lint, Build, and Test

Unexpected any. Specify a different type
},
blockOverrides?: BlockOverrides
): Promise<MulticallResult[]> {
params: MulticallSameFunctionParams<TFunctionParams>,
stateOverrrides?: {
code?: string;
state?: any

Check warning on line 84 in sdks/uniswapx-sdk/src/utils/multicall.ts

GitHub Actions / Lint, Build, and Test

Unexpected any. Specify a different type
},
blockOverrides?: BlockOverrides
): Promise<MulticallResult[]> {
calls: Call[],
stateOverrides?: {
code?: string;
state?: any

Check warning on line 110 in sdks/uniswapx-sdk/src/utils/multicall.ts

GitHub Actions / Lint, Build, and Test

Unexpected any. Specify a different type
},
blockOverrides?: BlockOverrides
): Promise<MulticallResult[]> {
let response;
if (code.length > 2) {
const multicall = Multicall2__factory.connect(multicallAddressOn(chainId), provider);
const params: any[] = [

Check warning on line 119 in sdks/uniswapx-sdk/src/utils/multicall.ts

GitHub Actions / Lint, Build, and Test

Unexpected any. Specify a different type
{
from: ethers.constants.AddressZero,
to: multicall.address,
const args = deploylessInterface.encodeDeploy([false, calls]);
const data = hexConcat([DEPLOYLESS_MULTICALL_BYTECODE, args]);
const params: any[] = [

Check warning on line 136 in sdks/uniswapx-sdk/src/utils/multicall.ts

GitHub Actions / Lint, Build, and Test

Unexpected any. Specify a different type
{
from: ethers.constants.AddressZero,
to: ethers.constants.AddressZero,