Skip to content

Commit c7f9349

Browse files
committed
[+] structure
1 parent ba51204 commit c7f9349

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+260
-106
lines changed

README.md

+100-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,105 @@
1-
# w3py
2-
- Various scripts, and examples written for users while working as Sushi support.
3-
- - No promises on versioning, everything should be good but the web3 library has received some updates in the past couple of years that these can be from.
1+
The previous repository structure can be found <a href="https://github.com/0xMaka/w3py/tree/archive">here</a>
42

5-
Will add as found, where appropriate, and can hopefully be of an assist to some.
6-
1 love
3+
---
74

5+
<img src="misc/makas_py_on_chain.png">
86

9-
> **NOTE** The repo root directory is getting very crowded but I don't want to make a sweeping change that might have any negative effect, so will be creating a new branch that should be better organised, and at will at the same time make an effort to update code broken by changes to the web3 library.
10-
If appears a much better structure without much downside can look to keep an archive and make the switch.
11-
Always love to see examples be of use, and often happy to take requests if you might be struggling with something.
7+
---
8+
9+
Hi! Originally this repo started as a bunch of _scripts and examples,_ written for users while handling support queries as a contributor at Sushiswap. However the repository had grown to encompass many more protocols and areas of defi, as well as outgrowing its initial lack of structure.
10+
11+
To make it easier to find things that might be useful, as well to know which related scripts are worth skimming through. I have attempted to better organise into folders, adding an index with short descriptions.
12+
13+
Always love to hear which examples can been useful, and am often happy to take requests if you might be struggling with something.
14+
Can find me in the ethereum python discord with any questions.
15+
All the best on your journey. - Maka
1216

1317
- [Ethereum Python Community](https://discord.gg/J8XFujprRA)
18+
19+
---
20+
21+
| folder | script | description |
22+
|---------------------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------|
23+
| > [ aave ]( aave/ ) | | **Aave lending protocol** |
24+
| | [ v3_supply_and_withdraw.py ]( aave/v3_supply_and_withdraw.py ) | Approve, supply and withdraw from a v3 aave pool. |
25+
| > [ beraswap ]( beraswap/ ) | | **Berachain DEX** |
26+
| | [ bera_swap.py ]( beraswap/bera_swap.py ) | Swap using `batchSwap` with their `ERC20_DEX`. |
27+
| > [ flashbots ]( flashbots/ ) | | Call structures and direct calls to flashbots endpoints. |
28+
| | [ eth_send_bundle.py ]( flashbots/eth_send_bundle.py ) | Building and sending a classic bundle. |
29+
| | [ eth_send_private.py ]( flashbots/eth_send_private.py ) | Using Flashbots endpoint to send a private transaction. |
30+
| | [ mev_send_bundle.py ]( flashbots/mev_send_bundle.py ) | Building and sending a classic bundle. |
31+
| > [ general ]( general ) | | **Overrides, bloom filters, log topics and wider EVM** |
32+
| | [ bloom_filter.py ]( general/bloom_filter.py ) | filtering the `logsBloom` for more efficient searches. |
33+
| | [ multi2.py ]( general/multi2.py ) | Using a popular mulicall contract, to batch static requests. |
34+
| | [ swap_topic.py ]( general/swap_topic.py ) | How to encode and pull a `Event` topic. |
35+
| | [ transfer_override.py ]( general/transfer_override.py ) | Overiding an accounts ERC20 balance, prior to an `eth_call`. |
36+
| > [ raw_calls ]( raw_calls/ ) | [ ]( ) | **Contract calls sending raw calldata** |
37+
| | [ raw_approval.py ]( raw_calls/raw_approval.py ) | Send a token approval using pre prepared calldata. |
38+
| | [ raw_deploy.py ]( raw_calls/raw_deploy.py ) | Deploy a contract using pre prepared calldata. |
39+
| | [ raw_deposit.py ]( raw_calls/raw_deposit.py ) | Deposit ETH to receive WETH using pre prepared calldata. |
40+
| | [ raw_transfer.py ]( raw_calls/raw_transfer.py ) | Make an ERC20 transfer using pre prepared calldata. |
41+
| > [ scrap_bots ]( scrap_bots/) | | **Basic bot flow** |
42+
| | [ skym_bot/ ]( scrap_bots/skym_bot/ ) | Monitor a v2 pair for imbalance, skim with contract if so. |
43+
| | [ flash_bot.py ]( scrap_bots/flash_bot.py ) | A basic flashbot script, using flashbots py library. |
44+
| | [ voly.py ]( scrap_bots/voly.py ) | Polls a v2 pair for price, buys or sells, tracks if holding. |
45+
| > [ signing ]( signing/ ) | | **Offchain signing, permits, EIP712** |
46+
| | [ pysign.py ]( signing/pysign.py ) | Deprectated signing pattern. |
47+
| | [ setMasterContractApproval.py ]( signing/setMasterContractApproval.py ) | Building and signing an EIP712 digest. |
48+
| > [ sushiswap ]( sushiswap/ ) | | **Sushi specific** |
49+
| | [ exact_input.py ]( sushiswap/exact_input.py ) | Trident single hop swap. |
50+
| | [ get_kava_farms.py ]( sushiswap/get_kava_farms.py ) | Get a list of all farms from a chef. |
51+
| | [ get_rewards.py ]( sushiswap/get_rewards.py ) | Calculating rewards from a Minichef. |
52+
| | [ graph_call.py ]( sushiswap/graph_call.py ) | Outdated: Exchange subgraph call (Pre needing a key). |
53+
| | [ route_processor.md ]( sushiswap/route_processor.md ) | Notes Sushi's router processor. |
54+
| | [ route_processor.py ]( sushiswap/route_processor.py ) | Single hop swap using Sushi route processor. |
55+
| | [ route_processor_multi.py ]( sushiswap/route_processor_multi.py ) | Multi hop swap using Sushi route processor. |
56+
| | [ swap_volume_since_midnight.py ]( sushiswap/swap_volume_since_midnight.py ) | Outdated: Use a subgraph to get volume day data. |
57+
| | [ trident_help_sheet.md ]( sushiswap/trident_help_sheet.md ) | Notes on Sushi Trident. |
58+
| | [ trident_multicall.py ]( sushiswap/trident_multicall.py ) | Trident multi hop swap. |
59+
| | [ xSwap.py ]( sushiswap/xSwap.py ) | Extensive cross chain swap, encoding, off chain signing etc. |
60+
| > [ syncswap ]( syncswap/ ) | | **How to swap on Syncwap DEX.** |
61+
| | [ sync_swap.py ]( syncswap/sync_swap.py ) | Basic syncswap router interaction. |
62+
| | [ sync_swap_with_permit.py ]( syncswap/sync_swap_with_permit.py ) | Basic syncswap router interaction using a permit. |
63+
| > [ uniswapv2 ]( uniswapv2/ ) | | **Examples for Uniswap v2 and clones** |
64+
| | [ mempool_filter.py ]( uniswapv2/mempool_filter.py ) | IPC filter the tx pool for swaps and decode them. |
65+
| | [ scale4whale.py ]( uniswapv2/scale4whale.py ) | Get an amount required to buy a tokens total supply. |
66+
| | [ v2path_encode.md ]( uniswapv2/v2path_encode.md ) | Step through of the ABI encoding. |
67+
| > [ uniswapv3 ]( uniswapv3/ ) | | **Examples for Uniswap v3 and clones** |
68+
| | [ v3exactOutput.py ]( uniswapv3/v3exactOutput.py ) | Uniswap v3 swap, multihop. |
69+
| | [ v3exactOutputSingle.py ]( uniswapv3/v3exactOutputSingle.py ) | Uniswap v3 swap, single hop. |
70+
| | [ v3quoter_iterations.py ]( uniswapv3/v3quoter_iterations.py ) | Uniswap v3 quoter discrepancies, example calls to each. |
71+
| > [ uni_router ]( uni_router/) | | **Uniswaps Universal router** |
72+
| | [ universal_router_swap.md ]( uni_router/universal_router_swap.md ) | Notes on Uniswaps Universal Router. |
73+
| | [ universal_router_swap.py ]( uni_router/universal_router_swap.py ) | Wrap and swap from Eth using Universal router.. |
74+
| | [ universal_swap_from_token.py ]( uni_router/universal_swap_from_token.py ) | Swap from token using Universal router (needs permit). |
75+
| > [ zk ]( zk/ ) | | **Anything ZK specific** |
76+
| | [ check_balance.py ]( zk/check_balance.py ) | Simple balance check, using the sdk. |
77+
| | [ transfer.py ]( zk/transfer.py ) | Simple eth transfer, using the sdk. |
78+
| <img width=145/> | | <img width=430/> |
79+
80+
<!--
81+
<table class="fixed-align">
82+
<tbody>
83+
<tr>
84+
<th>
85+
🐍
86+
</th>
87+
</tr>
88+
<tr>
89+
<td valign="top", valign="center">
90+
91+
```python
92+
# clone repo
93+
# ...
94+
# instructions for using search tag tool
95+
# ...
96+
```
97+
98+
</td>
99+
</tr>
100+
<tr>
101+
<td>
102+
<img width=800/>
103+
</td>
104+
</tr>
105+
</table>

aave/v3_supply_and_withdraw.py

+74
Large diffs are not rendered by default.

bera_swap.py beraswap/bera_swap.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
RPC = 'https://artio.rpc.berachain.com'
44
CHAIN_ID = 80085
55

6-
from web3 import Web3 as w, HTTPProvider as hp
7-
w3 = w(hp(RPC))
6+
from web3 import Web3 as w, HTTPProvider as hp ; w3 = w(hp(RPC))
87

98
from os import getenv
109
from dotenv import load_dotenv
@@ -13,7 +12,6 @@
1312
EOA = getenv('TRON')
1413
#----------------------
1514

16-
1715
ERC20_DEX = '0x0d5862FDbdd12490f9b4De54c236cff63B038074'
1816
NATIVE = '0x0000000000000000000000000000000000000000'
1917
USDC = '0x6581e59A1C8dA66eD0D313a0d4029DcE2F746Cc5'
@@ -43,18 +41,14 @@
4341
'nonce': w3.eth.get_transaction_count(EOA)
4442
})
4543

46-
w3.eth.call(swap)
44+
w3.eth.call(swap) # should throw if there is an issue
4745

4846
# helpers
4947
def sign_tx(tx, key):
50-
sig = w3.eth.account.sign_transaction
51-
signed_tx = sig(tx, private_key=key)
52-
return signed_tx
48+
return w3.eth.account.sign_transaction(tx, private_key=key)
5349

5450
def send_tx(signed_tx):
55-
w3.eth.send_raw_transaction(signed_tx.rawTransaction)
56-
tx_hash = w3.to_hex(w3.keccak(signed_tx.rawTransaction))
57-
return tx_hash
51+
return w3.eth.send_raw_transaction(signed_tx.rawTransaction)
5852

5953
def main():
6054
('[-] Attempting swap...')

exact_input.py

-71
This file was deleted.
File renamed without changes.

multi2.py general/multi2.py

File renamed without changes.
File renamed without changes.
File renamed without changes.

con/net.py misc/con/net.py

File renamed without changes.

misc/makas_py_on_chain.png

4.07 MB
Loading

migrations.py misc/migrations.py

File renamed without changes.

0 commit comments

Comments
 (0)