Skip to content

Commit

Permalink
fix #47 - wrong permit2 address in the permit2 signed message.
Browse files Browse the repository at this point in the history
add verifying_contract parameter to create permit2 message.

Signed-off-by: freereaper <[email protected]>
  • Loading branch information
speedssr authored and freereaper committed Apr 1, 2024
1 parent 66aedd7 commit 2175059
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion uniswap_universal_router_decoder/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)

from web3.types import HexStr
from web3 import Web3


_execution_function_input_types = ["bytes", "bytes[]", "int"]
Expand All @@ -19,6 +20,8 @@
_execution_without_deadline_function_selector = HexStr("0x24856bc3")
_router_abi = '[{"inputs":[{"components":[{"internalType":"address","name":"permit2","type":"address"},{"internalType":"address","name":"weth9","type":"address"},{"internalType":"address","name":"seaportV1_5","type":"address"},{"internalType":"address","name":"seaportV1_4","type":"address"},{"internalType":"address","name":"openseaConduit","type":"address"},{"internalType":"address","name":"nftxZap","type":"address"},{"internalType":"address","name":"x2y2","type":"address"},{"internalType":"address","name":"foundation","type":"address"},{"internalType":"address","name":"sudoswap","type":"address"},{"internalType":"address","name":"elementMarket","type":"address"},{"internalType":"address","name":"nft20Zap","type":"address"},{"internalType":"address","name":"cryptopunks","type":"address"},{"internalType":"address","name":"looksRareV2","type":"address"},{"internalType":"address","name":"routerRewardsDistributor","type":"address"},{"internalType":"address","name":"looksRareRewardsDistributor","type":"address"},{"internalType":"address","name":"looksRareToken","type":"address"},{"internalType":"address","name":"v2Factory","type":"address"},{"internalType":"address","name":"v3Factory","type":"address"},{"internalType":"bytes32","name":"pairInitCodeHash","type":"bytes32"},{"internalType":"bytes32","name":"poolInitCodeHash","type":"bytes32"}],"internalType":"struct RouterParameters","name":"params","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BalanceTooLow","type":"error"},{"inputs":[],"name":"BuyPunkFailed","type":"error"},{"inputs":[],"name":"ContractLocked","type":"error"},{"inputs":[],"name":"ETHNotAccepted","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandIndex","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"ExecutionFailed","type":"error"},{"inputs":[],"name":"FromAddressIsNotOwner","type":"error"},{"inputs":[],"name":"InsufficientETH","type":"error"},{"inputs":[],"name":"InsufficientToken","type":"error"},{"inputs":[],"name":"InvalidBips","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandType","type":"uint256"}],"name":"InvalidCommandType","type":"error"},{"inputs":[],"name":"InvalidOwnerERC1155","type":"error"},{"inputs":[],"name":"InvalidOwnerERC721","type":"error"},{"inputs":[],"name":"InvalidPath","type":"error"},{"inputs":[],"name":"InvalidReserves","type":"error"},{"inputs":[],"name":"InvalidSpender","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"SliceOutOfBounds","type":"error"},{"inputs":[],"name":"TransactionDeadlinePassed","type":"error"},{"inputs":[],"name":"UnableToClaim","type":"error"},{"inputs":[],"name":"UnsafeCast","type":"error"},{"inputs":[],"name":"V2InvalidPath","type":"error"},{"inputs":[],"name":"V2TooLittleReceived","type":"error"},{"inputs":[],"name":"V2TooMuchRequested","type":"error"},{"inputs":[],"name":"V3InvalidAmountOut","type":"error"},{"inputs":[],"name":"V3InvalidCaller","type":"error"},{"inputs":[],"name":"V3InvalidSwap","type":"error"},{"inputs":[],"name":"V3TooLittleReceived","type":"error"},{"inputs":[],"name":"V3TooMuchRequested","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsSent","type":"event"},{"inputs":[{"internalType":"bytes","name":"looksRareClaim","type":"bytes"}],"name":"collectRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"commands","type":"bytes"},{"internalType":"bytes[]","name":"inputs","type":"bytes[]"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"commands","type":"bytes"},{"internalType":"bytes[]","name":"inputs","type":"bytes[]"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]' # noqa

_permit2_address = Web3.to_checksum_address("0x000000000022D473030F116dDEE9F6B43aC78BA3")

_structured_data_permit: Dict[str, Any] = {
'types': {
'EIP712Domain': [
Expand All @@ -42,6 +45,6 @@
'domain': {
'name': 'Permit2',
'chainId': 1,
'verifyingContract': '0x000000000022D473030F116dDEE9F6B43aC78BA3',
'verifyingContract': _permit2_address,
},
}
10 changes: 8 additions & 2 deletions uniswap_universal_router_decoder/router_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
)

from uniswap_universal_router_decoder._abi_builder import _ABIBuilder
from uniswap_universal_router_decoder._constants import _structured_data_permit
from uniswap_universal_router_decoder._constants import (
_structured_data_permit,
_permit2_address,
)
from uniswap_universal_router_decoder._decoder import _Decoder
from uniswap_universal_router_decoder._encoder import _Encoder

Expand Down Expand Up @@ -75,7 +78,8 @@ def create_permit2_signable_message(
nonce: int,
spender: ChecksumAddress,
deadline: int,
chain_id: int = 1) -> Tuple[Dict[str, Any], SignableMessage]:
chain_id: int = 1,
verifying_contract: ChecksumAddress = _permit2_address) -> Tuple[Dict[str, Any], SignableMessage]:
"""
Create a eth_account.messages.SignableMessage that will be sent to the UR/Permit2 contracts
to set token permissions through signature validation.
Expand All @@ -93,6 +97,7 @@ def create_permit2_signable_message(
:param spender: The spender (ie: the UR) address
:param deadline: The deadline, as a Unix timestamp, on the permit signature
:param chain_id: What it says on the box. Default to 1.
:param verifying_contract: the permit2 contract address. Default to uniswap permit2 address.
:return: A tuple: (PermitSingle, SignableMessage).
The first element is the first parameter of permit2_permit().
The second element must be signed with eth_account.signers.local.LocalAccount.sign_message() in your code
Expand All @@ -111,5 +116,6 @@ def create_permit2_signable_message(
}
structured_data = dict(_structured_data_permit)
structured_data["domain"]["chainId"] = chain_id
structured_data["domain"]["verifyingContract"] = verifying_contract
structured_data["message"] = permit_single
return permit_single, encode_structured_data(primitive=structured_data)

0 comments on commit 2175059

Please sign in to comment.