Skip to content

Commit

Permalink
Merge pull request #63 from Elnaril/1.2.0.dev3
Browse files Browse the repository at this point in the history
1.2.0.dev3 - add support for SEAPORT_V1_5, OWNER_CHECK_721 and SWEEP_ERC721
  • Loading branch information
Elnaril committed May 25, 2024
2 parents c8d2894 + 7c5e203 commit cbbcf39
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 7 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ The object of this library is to decode & encode the transaction input sent to t
on Ethereum Mainnet). It is based on, and is intended to be used with [web3.py](https://github.com/ethereum/web3.py)
The target audience is Python developers who are familiar with the Ethereum blockchain concepts and web3.py, and how DEXes work.

⚠ This library has not been audited, so use at your own risk !
This library has not been audited, so use at your own risk !

⚠ Before using this library, ensure you are familiar with general blockchain concepts and [web3.py](https://github.com/ethereum/web3.py) in particular.
Before using this library, ensure you are familiar with general blockchain concepts and [web3.py](https://github.com/ethereum/web3.py) in particular.

⚠ This project is a work in progress so not all commands are decoded yet. Below the list of the already implemented ones.
This project is a work in progress so not all commands are decoded yet. Below the list of the already implemented ones.

| Command Id | Function Name | Decode | Encode
| ---------- | ------------- |:------:|:------:
Expand All @@ -67,7 +67,12 @@ The target audience is Python developers who are familiar with the Ethereum bloc
| 0x0c | UNWRAP_WETH | ✅ | ✅
| 0x0d | PERMIT2_TRANSFER_FROM_BATCH | ❌ | ❌
| 0x0e - 0x0f | placeholders | N/A | N/A
| 0x10 - 0x1d | | ❌ | ❌
| 0x10 | SEAPORT_V1_5 | ✅ | ✅
| 0x11 - 0x14 | | ❌ | ❌
| 0x15 | OWNER_CHECK_721 | ✅ | ✅
| 0x16 | OWNER_CHECK_1155 | ❌ | ❌
| 0x17 | SWEEP_ERC721 | ✅ | ✅
| 0x18 - 0x1d | | ❌ | ❌
| 0x1e - 0x3f | placeholders | N/A | N/A

---
Expand Down Expand Up @@ -398,6 +403,27 @@ Example where an USDC amount is sent to a recipient:
.transfer(FunctionRecipient.CUSTOM, usdc_address, usdc_amount, recipient_address)
```

#### SEAPORT_V1_5, OWNER_CHECK_721 and SWEEP_ERC721
`SEAPORT_V1_5` encodes the call to the function SEAPORT_V1_5 which allows interacting with the OpenSea protocol,
ie: buy, sell, ... NFTs.
As the Universal Router is, in this case, mostly a gateway for Seaport,
building the `call_data` is not managed by this SDK and thus left to the users.

⚠️ Important when buying a NFT:
1. chain `sweep_erc721()` after `seaport_v1_5()` to get the NFT.
2. chain `owner_check_721()` after `sweep_erc721()` to confirm the new owner.
```python
encoded_input = (
codec
.encode
.chain()
.seaport_v1_5(value, call_data) # buy nft for value ETH (in Wei) with the call_data for Seaport
.sweep_erc721(FunctionRecipient.SENDER, nft_address, nft_id) # get nft
.owner_check_721(sender_address, nft_address, nft_id) # you want to be sure you're the new owner otherwise revert the trx
.build()
)
```

### How to build directly a transaction
The SDK provides a handy method to build very easily the full transaction in addition to the input data.
It can compute most of the transaction parameters (if the codec has been instantiated with a valid w3 or rpc url)
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-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}}
{"meta": {"format": 2, "version": "7.4.1", "timestamp": "2024-05-24T18:21:40.570630", "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, 115, 117, 118, 119, 120, 121, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 143, 144, 145, 146, 147, 149, 150, 151, 152, 154, 155, 156, 157, 158, 160, 161, 162, 163, 164, 166, 167, 168, 169, 171, 172, 173, 174, 176, 177, 178, 179, 181, 182, 183, 184, 186, 187, 188, 189, 191, 192, 193, 194], "summary": {"covered_lines": 124, "num_statements": 124, "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, 37, 38, 46, 52, 55, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 82, 86, 89, 90, 91, 92, 93, 94, 95, 97, 98, 101, 106, 107, 108, 110, 115, 116, 117, 119, 120, 121, 122, 124, 125, 126, 127, 129, 130, 131, 132, 133, 135, 149, 150, 151, 152, 154, 155, 156, 157, 158, 160, 174, 175, 176, 177, 179, 186, 187, 188, 189, 190, 192, 213, 214, 215, 226, 228, 247, 256, 263, 264, 265, 266, 267, 269, 290, 291, 292, 303, 305, 312, 313, 314, 315, 316, 317, 319, 341, 342, 343, 354, 356, 376, 385, 392, 393, 394, 395, 396, 397, 399, 421, 422, 423, 434, 436, 440, 445, 446, 447, 448, 449, 451, 464, 465, 473, 475, 476, 477, 478, 479, 481, 497, 498, 499, 508, 510, 511, 512, 513, 514, 516, 533, 538, 540, 541, 542, 551, 553, 554, 555, 556, 557, 559, 577, 578, 579, 588, 590, 591, 592, 593, 594, 596, 597, 598, 599, 607, 609, 614, 615, 616, 617, 619, 625, 626, 627, 636, 638, 643, 644, 645, 646, 648, 653, 654, 663, 665, 672, 673, 674, 676, 677, 679, 722, 724, 725, 727, 728, 730, 731, 732, 734, 735, 737, 738, 740, 741, 742, 748, 760, 761, 762, 764, 766], "summary": {"covered_lines": 232, "num_statements": 232, "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, 28, 29, 30, 33, 34, 41, 42, 43, 46, 48, 49, 50, 51, 52, 55, 56, 57, 58, 59], "summary": {"covered_lines": 32, "num_statements": 32, "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": 516, "num_statements": 516, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}}
Loading

0 comments on commit cbbcf39

Please sign in to comment.