Skip to content

Commit

Permalink
Merge pull request #62 from Elnaril/1.2.0.dev2
Browse files Browse the repository at this point in the history
1.2.0.dev2 - add fetch_permit2_allowance()
  • Loading branch information
Elnaril authored May 17, 2024
2 parents f43e320 + 0a73af6 commit c8d2894
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ data, signable_message = codec.create_permit2_signable_message(
token_address,
amount, # max = 2**160 - 1
expiration,
nonce, # Permit2 nonce
nonce, # Permit2 nonce, see below how to get it
spender, # The UR checksum address
deadline,
1, # chain id
Expand All @@ -332,6 +332,12 @@ transaction["data"] = encoded_data
```
After that, you can swap tokens using the Uniswap universal router.

#### How to get the current permit2 allowance, expiration and nonce
You can get the nonce you need to build the permit2 signable message like this:
```python
amount, expiration, nonce = codec.fetch_permit2_allowance(acc.address, token_address) # where acc is your LocalAccount
```

### How to chain a call to PERMIT2_PERMIT and V2_SWAP_EXACT_IN in the same transaction
Don't forget to give a token allowance to the Permit2 contract as well.

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-05-15T19:56:21.419329", "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, 24, 25, 27], "summary": {"covered_lines": 11, "num_statements": 11, "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, 26, 27, 31, 32, 35, 36, 37, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 52, 53, 57, 59, 60, 64, 66, 67, 71, 73, 74, 106, 112, 117, 118, 119, 120, 121], "summary": {"covered_lines": 40, "num_statements": 40, "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": 466, "num_statements": 466, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}}
{"meta": {"format": 2, "version": "7.4.1", "timestamp": "2024-05-16T09:59:53.915249", "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, 24, 25, 27], "summary": {"covered_lines": 11, "num_statements": 11, "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, 26, 27, 31, 32, 35, 36, 37, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 52, 53, 57, 59, 60, 64, 66, 67, 71, 73, 74, 106, 112, 117, 118, 119, 120, 121], "summary": {"covered_lines": 40, "num_statements": 40, "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": 466, "num_statements": 466, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}}
Loading

0 comments on commit c8d2894

Please sign in to comment.