Skip to content

Commit

Permalink
feat: implement all universal router command encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
banteg committed Apr 27, 2024
1 parent 3d71b8f commit e7c1dea
Showing 1 changed file with 181 additions and 82 deletions.
263 changes: 181 additions & 82 deletions uniswap_sdk/universal_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,27 @@ class PERMIT2_TRANSFER_FROM(Command):
definition = [
ABIType(name="token", type="address"),
ABIType(name="recipient", type="address"),
ABIType(name="amount", type="uint256"),
ABIType(name="amount", type="uint160"),
]


# class PERMIT2_PERMIT_BATCH(Command):
# type = 0x03
#
# definition = []
class PERMIT2_PERMIT_BATCH(Command):
type = 0x03

definition = [
ABIType(
name="details",
type="tuple[]",
components=[
ABIType(name="token", type="address"),
ABIType(name="amount", type="uint160"),
ABIType(name="expiration", type="uint48"),
ABIType(name="nonce", type="uint48"),
],
),
ABIType(name="spender", type="address"),
ABIType(name="deadline", type="uint256"),
]


class SWEEP(Command):
Expand Down Expand Up @@ -197,10 +210,23 @@ class V2_SWAP_EXACT_OUT(Command):
]


# class PERMIT2_PERMIT(Command):
# type = 0x0A
#
# definition = []
class PERMIT2_PERMIT(Command):
type = 0x0A

definition = [
ABIType(
name="details",
type="tuple",
components=[
ABIType(name="token", type="address"),
ABIType(name="amount", type="uint160"),
ABIType(name="expiration", type="uint48"),
ABIType(name="nonce", type="uint48"),
],
),
ABIType(name="spender", type="address"),
ABIType(name="deadline", type="uint256"),
]


class WRAP_ETH(Command):
Expand All @@ -224,7 +250,18 @@ class UNWRAP_WETH(Command):
class PERMIT2_TRANSFER_FROM_BATCH(Command):
type = 0x0D

definition = []
definition = [
ABIType(
name="batch",
type="tuple[]",
components=[
ABIType(name="sender", type="address"),
ABIType(name="recipient", type="address"),
ABIType(name="amount", type="uint160"),
ABIType(name="token", type="address"),
],
)
]


class BALANCE_CHECK_ERC20(Command):
Expand All @@ -237,112 +274,174 @@ class BALANCE_CHECK_ERC20(Command):
]


# class SEAPORT_V1_5(Command):
# type = 0x10
#
# definition = []
class SEAPORT_V1_5(Command):
type = 0x10

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]

# class LOOKS_RARE_721(Command):
# type = 0x11
#
# definition = []

class LOOKS_RARE_V2(Command):
type = 0x11

# class NFTX(Command):
# type = 0x12
#
# definition = []
definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]


# class CRYPTOPUNKS(Command):
# type = 0x13
#
# definition = []
class NFTX(Command):
type = 0x12

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]

# class LOOKS_RARE_1155(Command):
# type = 0x14
#
# definition = []

class CRYPTOPUNKS(Command):
type = 0x13

# class OWNER_CHECK_721(Command):
# type = 0x15
#
# definition = []
definition = [
ABIType(name="punk_id", type="uint256"),
ABIType(name="recipient", type="address"),
ABIType(name="value", type="uint256"),
]


# class OWNER_CHECK_1155(Command):
# type = 0x16
#
# definition = []
class OWNER_CHECK_721(Command):
type = 0x15

definition = [
ABIType(name="owner", type="address"),
ABIType(name="token", type="address"),
ABIType(name="token_id", type="uint256"),
]

# class SWEEP_ERC721(Command):
# type = 0x17
#
# definition = []

class OWNER_CHECK_1155(Command):
type = 0x16

# class X2Y2_721(Command):
# type = 0x18
#
# definition = []
definition = [
ABIType(name="owner", type="address"),
ABIType(name="token", type="address"),
ABIType(name="token_id", type="uint256"),
ABIType(name="min_balance", type="uint256"),
]


# class SUDOSWAP(Command):
# type = 0x19
#
# definition = []
class SWEEP_ERC721(Command):
type = 0x17

definition = [
ABIType(name="token", type="address"),
ABIType(name="recipient", type="address"),
ABIType(name="token_id", type="uint256"),
]

# class NFT20(Command):
# type = 0x1A
#
# definition = []

class X2Y2_721(Command):
type = 0x18

# class X2Y2_1155(Command):
# type = 0x1B
#
# definition = []
definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
ABIType(name="recipient", type="address"),
ABIType(name="token", type="address"),
ABIType(name="token_id", type="uint256"),
]


# class FOUNDATION(Command):
# type = 0x1C
#
# definition = []
class SUDOSWAP(Command):
type = 0x19

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]

# class SWEEP_ERC1155(Command):
# type = 0x1D
#
# definition = []

class NFT20(Command):
type = 0x1A

# class ELEMENT_MARKET(Command):
# type = 0x1E
#
# definition = []
definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]


# class SEAPORT_V1_4(Command):
# type = 0x20
#
# definition = []
class X2Y2_1155(Command):
type = 0x1B

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
ABIType(name="recipient", type="address"),
ABIType(name="token", type="address"),
ABIType(name="token_id", type="uint256"),
ABIType(name="amount", type="uint256"),
]


class FOUNDATION(Command):
type = 0x1C

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
ABIType(name="recipient", type="address"),
ABIType(name="token", type="address"),
ABIType(name="token_id", type="uint256"),
]


class SWEEP_ERC1155(Command):
type = 0x1D

definition = [
ABIType(name="token", type="address"),
ABIType(name="recipient", type="address"),
ABIType(name="token_id", type="uint256"),
ABIType(name="amount", type="uint256"),
]


class ELEMENT_MARKET(Command):
type = 0x1E

definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]


class SEAPORT_V1_4(Command):
type = 0x20

# class EXECUTE_SUB_PLAN(Command):
# type = 0x21
#
# definition = []
definition = [
ABIType(name="value", type="uint256"),
ABIType(name="data", type="bytes"),
]


# class APPROVE_ERC20(Command):
# type = 0x22
#
# definition = []
class EXECUTE_SUB_PLAN(Command):
type = 0x21

definition = [
ABIType(name="commands", type="bytes"),
ABIType(name="inputs", type="bytes[]"),
]


class APPROVE_ERC20(Command):
type = 0x22

definition = [
ABIType(name="token", type="address"),
ABIType(name="spender", type="uint8"), # 0 = opensea condiut, 1 = sudoswap
]


# NOTE: Must come after all the subclassing action above
Expand Down

0 comments on commit e7c1dea

Please sign in to comment.