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

1.2.0.dev5 - Replace deprecated eth_account function #65

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 13 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,26 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["all"]

environment:
name: Tests

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up supported Python versions
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: |
3.8
3.9
3.10
3.11
- name: Install tox and any other packages
run: pip install tox
run: |
pip install -U pip
pip install tox
- name: Run tox
run: |
export WEB3_HTTP_PROVIDER_URL_ETHEREUM_MAINNET=${{ secrets.WEB3_HTTP_PROVIDER_URL_ETHEREUM_MAINNET }}
python --version
tox
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Add `build_transaction()` method: It's now possible to build the full transaction i/o just the input data.
- Add `fetch_permit2_allowance()`: Easy way to check the current Permit2 allowed amount, expiration and nonce.
- Make verifying contract (Permit2) configurable (Thanks to @speedssr and @freereaper)
- Replace deprecated `eth_account.encode_structured_data()` with `eth_account.messages.encode_typed_data()`
### v1.1.0
- Add support for the TRANSFER function
- Add support for decoding the "revert on fail" flag and prepare for encoding on UR functions that support it.
Expand Down
2 changes: 1 addition & 1 deletion coverage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"meta": {"format": 2, "version": "7.4.1", "timestamp": "2024-06-16T16:45:49.196380", "branch_coverage": false, "show_contexts": false}, "files": {"uniswap_universal_router_decoder/__init__.py": {"executed_lines": [1, 5, 8], "summary": {"covered_lines": 3, "num_statements": 3, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_abi_builder.py": {"executed_lines": [1, 8, 10, 14, 21, 23, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 38, 39, 42, 43, 44, 45, 48, 51, 52, 53, 55, 56, 57, 59, 60, 61, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 97, 98, 99, 112, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 140, 141, 142, 143, 144, 146, 147, 148, 149, 151, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 168, 169, 170, 171, 173, 174, 175, 176], "summary": {"covered_lines": 112, "num_statements": 112, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_constants.py": {"executed_lines": [1, 8, 13, 14, 17, 18, 19, 20, 21, 22, 25, 26, 28], "summary": {"covered_lines": 12, "num_statements": 12, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_decoder.py": {"executed_lines": [1, 8, 9, 17, 18, 19, 26, 27, 28, 34, 35, 36, 37, 38, 40, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 67, 76, 77, 78, 79, 80, 82, 83, 85, 86, 95, 96, 97, 98, 99, 100, 101, 108, 110, 111, 113], "summary": {"covered_lines": 51, "num_statements": 51, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_encoder.py": {"executed_lines": [1, 8, 10, 21, 22, 23, 24, 25, 26, 27, 36, 37, 45, 51, 54, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 81, 85, 88, 89, 90, 91, 92, 93, 94, 96, 97, 100, 105, 106, 107, 109, 114, 115, 116, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 131, 132, 134, 148, 149, 150, 151, 153, 154, 155, 156, 157, 159, 173, 174, 175, 176, 178, 185, 186, 187, 188, 189, 191, 212, 213, 214, 225, 227, 246, 255, 262, 263, 264, 265, 266, 268, 289, 290, 291, 302, 304, 311, 312, 313, 314, 315, 316, 318, 340, 341, 342, 353, 355, 375, 384, 391, 392, 393, 394, 395, 396, 398, 420, 421, 422, 433, 435, 439, 444, 445, 446, 447, 448, 450, 463, 464, 472, 474, 475, 476, 477, 478, 480, 496, 497, 498, 507, 509, 510, 511, 512, 513, 515, 532, 537, 539, 540, 541, 550, 552, 553, 554, 555, 556, 558, 576, 577, 578, 587, 589, 596, 597, 598, 600, 601, 603, 646, 648, 649, 651, 652, 654, 655, 656, 658, 659, 661, 662, 664, 665, 666, 672, 684, 685, 686, 688, 690], "summary": {"covered_lines": 203, "num_statements": 203, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_enums.py": {"executed_lines": [1, 10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 38, 39, 40, 43, 45, 46, 47, 48, 49, 52, 53, 54, 55, 56], "summary": {"covered_lines": 29, "num_statements": 29, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/router_codec.py": {"executed_lines": [1, 8, 9, 16, 20, 21, 28, 29, 35, 36, 39, 40, 41, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 56, 57, 61, 63, 64, 68, 70, 71, 75, 77, 78, 110, 116, 121, 122, 123, 124, 125, 127, 148, 149, 150, 151], "summary": {"covered_lines": 45, "num_statements": 45, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/utils.py": {"executed_lines": [1, 2, 8, 9, 15, 18, 26, 43, 44, 45, 51, 52, 54, 55, 57, 58, 60], "summary": {"covered_lines": 17, "num_statements": 17, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}}, "totals": {"covered_lines": 472, "num_statements": 472, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}}
{"meta": {"format": 2, "version": "7.4.1", "timestamp": "2024-06-17T16:07:58.305054", "branch_coverage": false, "show_contexts": false}, "files": {"uniswap_universal_router_decoder/__init__.py": {"executed_lines": [1, 5, 8], "summary": {"covered_lines": 3, "num_statements": 3, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_abi_builder.py": {"executed_lines": [1, 8, 10, 14, 21, 23, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 38, 39, 42, 43, 44, 45, 48, 51, 52, 53, 55, 56, 57, 59, 60, 61, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 97, 98, 99, 112, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 140, 141, 142, 143, 144, 146, 147, 148, 149, 151, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 168, 169, 170, 171, 173, 174, 175, 176], "summary": {"covered_lines": 112, "num_statements": 112, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_constants.py": {"executed_lines": [1, 8, 9, 12, 13, 14, 15, 16, 17, 20, 21, 23, 24], "summary": {"covered_lines": 12, "num_statements": 12, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_decoder.py": {"executed_lines": [1, 8, 9, 17, 18, 19, 26, 27, 28, 34, 35, 36, 37, 38, 40, 47, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 62, 63, 64, 65, 67, 76, 77, 78, 79, 80, 82, 83, 85, 86, 95, 96, 97, 98, 99, 100, 101, 108, 110, 111, 113], "summary": {"covered_lines": 51, "num_statements": 51, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_encoder.py": {"executed_lines": [1, 8, 10, 21, 22, 23, 24, 25, 26, 27, 36, 37, 45, 51, 54, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 81, 85, 88, 89, 90, 91, 92, 93, 94, 96, 97, 100, 105, 106, 107, 109, 114, 115, 116, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 131, 132, 134, 148, 149, 150, 151, 153, 154, 155, 156, 157, 159, 173, 174, 175, 176, 178, 185, 186, 187, 188, 189, 191, 212, 213, 214, 225, 227, 246, 255, 262, 263, 264, 265, 266, 268, 289, 290, 291, 302, 304, 311, 312, 313, 314, 315, 316, 318, 340, 341, 342, 353, 355, 375, 384, 391, 392, 393, 394, 395, 396, 398, 420, 421, 422, 433, 435, 439, 444, 445, 446, 447, 448, 450, 463, 464, 472, 474, 475, 476, 477, 478, 480, 496, 497, 498, 507, 509, 510, 511, 512, 513, 515, 532, 537, 539, 540, 541, 550, 552, 553, 554, 555, 556, 558, 576, 577, 578, 587, 589, 596, 597, 598, 600, 601, 603, 646, 648, 649, 651, 652, 654, 655, 656, 658, 659, 661, 662, 664, 665, 666, 672, 684, 685, 686, 688, 690], "summary": {"covered_lines": 203, "num_statements": 203, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/_enums.py": {"executed_lines": [1, 10, 12, 13, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 38, 39, 40, 43, 45, 46, 47, 48, 49, 52, 53, 54, 55, 56], "summary": {"covered_lines": 29, "num_statements": 29, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/router_codec.py": {"executed_lines": [1, 8, 9, 16, 20, 21, 28, 29, 36, 37, 40, 41, 42, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 57, 58, 62, 64, 65, 69, 71, 72, 76, 78, 79, 88, 94, 99, 100, 101, 102, 107, 109, 130, 131, 132, 133], "summary": {"covered_lines": 45, "num_statements": 45, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "uniswap_universal_router_decoder/utils.py": {"executed_lines": [1, 2, 8, 9, 15, 18, 26, 43, 44, 45, 51, 52, 54, 55, 57, 58, 60], "summary": {"covered_lines": 17, "num_statements": 17, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}}, "totals": {"covered_lines": 472, "num_statements": 472, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}}
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "uniswap-universal-router-decoder"
version = "1.2.0.dev4"
version = "1.2.0.dev5"
authors = [
{ name="Elnaril", email="[email protected]" },
]
Expand Down Expand Up @@ -36,5 +36,6 @@ packages = ["uniswap_universal_router_decoder"]
"Homepage" = "https://github.com/Elnaril/uniswap-universal-router-decoder"
"Bug Tracker" = "https://github.com/Elnaril/uniswap-universal-router-decoder/issues"
"Discussions" = "https://github.com/Elnaril/uniswap-universal-router-decoder/discussions"
"Fiverr" = "https://www.fiverr.com/freelancers/elnaril"
"Fiverr" = "https://www.fiverr.com/elnaril"
"Buy Me A Coffee" = "https://www.buymeacoffee.com/elnaril"
"Malt" = "https://www.malt.com/profile/elnaril"
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from uniswap_universal_router_decoder import RouterCodec


rpc_endpoint_address = "https://rpc.ankr.com/eth"
rpc_endpoint_address = "https://rpc.flashbots.net/"


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ use_parentheses = True
[testenv]
description = run tests
deps = -rrequirements.txt
passenv =
WEB3_HTTP_PROVIDER_URL_ETHEREUM_MAINNET
commands =
python --version
pytest tests

[testenv:lint]
Expand All @@ -42,6 +41,7 @@ commands =
description = run coverage and output json result
deps = -rrequirements.txt
commands =
python --version
coverage run -m pytest tests
coverage report -m
coverage json
43 changes: 13 additions & 30 deletions uniswap_universal_router_decoder/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* License: MIT.
* Doc: https://github.com/Elnaril/uniswap-universal-router-decoder
"""
from typing import (
Any,
Dict,
)

from web3 import Web3
from web3.types import HexStr

Expand All @@ -25,29 +20,17 @@
_permit2_address = Web3.to_checksum_address("0x000000000022D473030F116dDEE9F6B43aC78BA3")
_ur_address = Web3.to_checksum_address("0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD")

_structured_data_permit: Dict[str, Any] = {
'types': {
'EIP712Domain': [
{'name': 'name', 'type': 'string'},
{'name': 'chainId', 'type': 'uint256'},
{'name': 'verifyingContract', 'type': 'address'}
],
'PermitDetails': [
{'name': 'token', 'type': 'address'},
{'name': 'amount', 'type': 'uint160'},
{'name': 'expiration', 'type': 'uint48'},
{'name': 'nonce', 'type': 'uint48'},
],
'PermitSingle': [
{'name': 'details', 'type': 'PermitDetails'},
{'name': 'spender', 'type': 'address'},
{'name': 'sigDeadline', 'type': 'uint256'},
],
},
'primaryType': 'PermitSingle',
'domain': {
'name': 'Permit2',
'chainId': 1,
'verifyingContract': _permit2_address,
},
_permit2_domain_data = {'name': 'Permit2', 'chainId': 1, 'verifyingContract': _permit2_address}
_permit2_types = {
'PermitDetails': [
{'name': 'token', 'type': 'address'},
{'name': 'amount', 'type': 'uint160'},
{'name': 'expiration', 'type': 'uint48'},
{'name': 'nonce', 'type': 'uint48'},
],
'PermitSingle': [
{'name': 'details', 'type': 'PermitDetails'},
{'name': 'spender', 'type': 'address'},
{'name': 'sigDeadline', 'type': 'uint256'},
],
}
19 changes: 12 additions & 7 deletions uniswap_universal_router_decoder/router_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from eth_account.messages import (
encode_structured_data,
encode_typed_data,
SignableMessage,
)
from web3 import Web3
Expand All @@ -29,7 +29,8 @@
from uniswap_universal_router_decoder._constants import (
_permit2_abi,
_permit2_address,
_structured_data_permit,
_permit2_domain_data,
_permit2_types,
_ur_address,
)
from uniswap_universal_router_decoder._decoder import _Decoder
Expand Down Expand Up @@ -118,11 +119,15 @@ def create_permit2_signable_message(
"spender": spender,
"sigDeadline": deadline,
}
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)
domain_data = dict(_permit2_domain_data)
domain_data["chainId"] = chain_id
domain_data["verifyingContract"] = verifying_contract
signable_message = encode_typed_data(
domain_data=domain_data,
message_types=_permit2_types,
message_data=permit_single,
)
return permit_single, signable_message

def fetch_permit2_allowance(
self,
Expand Down
Loading