-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnipe.py
124 lines (116 loc) · 3.6 KB
/
snipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from typing import List
import click
import sys
import yaml
from web3 import Web3
from config import Config
from services.ethereum.ethereum import Ethereum
from services.pools.loader import PoolLoader
from services.strategy.snipe import StrategySnipe
from services.ttypes.sniper import SnipingNoob
from services.ttypes.strategy import StrategyEnum
@click.command()
@click.option("--kovan", is_flag=True, help="Point to Kovan test network")
@click.option("--debug", is_flag=True, help="Display logs")
@click.option(
"--max-amount",
default=6.0,
help="Set max amount to trade with in WETH (Default: 6.0)",
)
@click.option(
"--min-amount",
default=3.0,
help="Set min Amount to trade with in WETH (Default: 3.0)",
)
@click.option(
"--min-liquidity",
default=20000,
help="Set minimum liquidity (Default: 30,000)",
)
@click.option(
"--max-liquidity",
default=10000000000,
help="Set max liquidity (Default: 500,000)",
)
@click.option("--send-tx", is_flag=True, help="Send the transaction on-chain")
@click.option(
"--gas-multiplier",
default=1.5,
help="Set gas price multipler (Default: 1.5)",
)
@click.option(
"--max-block",
default=3,
help="Set max number of block we allow the transaction to go through (Default: 3)",
)
@click.option(
"--since",
default="latest",
help="Since Block (latest|pending)(Default: latest)",
)
@click.option(
"--only-tokens",
default="all",
help="Only filter tokens by name (i.e: --only XIOT,XAMP,UNI) (Default: all)",
)
@click.option("--address", help="Specify a specific arbitrageur address to snipe")
def snipe(
kovan: bool,
debug: bool,
max_amount: float,
min_amount: float,
min_liquidity: int,
max_liquidity: int,
send_tx: bool,
gas_multiplier: float,
max_block: int,
since: str,
only_tokens: str,
address: str,
) -> None:
print(
f"-----------------------------------------------------------\n"
f"----------------- SNIPING SOME NOOOOOBS -------------------\n"
f"-----------------------------------------------------------\n"
f"Sniping Address: {address}\n"
f"Gas Multiplier: {gas_multiplier}\n"
f"Max Block Allowed: {max_block}\n"
f"Sending Transactions on-chain: {send_tx}\n"
f"Since Block: {since}\n"
f"Only Tokens: {only_tokens}\n"
f"-----------------------------------------------------------"
)
sys.stdout.flush()
config = Config(
strategy=StrategyEnum.SNIPE,
kovan=kovan,
debug=debug,
send_tx=send_tx,
max_amount=max_amount,
min_amount=min_amount,
min_liquidity=min_liquidity,
max_liquidity=max_liquidity,
gas_multiplier=gas_multiplier,
max_block=max_block,
since=since,
only_tokens=only_tokens,
)
pool_loader = PoolLoader(config=config)
pools = pool_loader.load_all_pools()
ethereum = Ethereum(config)
if address:
sniping_noobs = [SnipingNoob(address=Web3.toChecksumAddress(address))]
else:
sniping_noobs = _load_noobs_yaml(config)
strategy = StrategySnipe(ethereum, config, pools, sniping_noobs)
strategy.snipe_arbitrageur()
def _load_noobs_yaml(config: Config) -> List[SnipingNoob]:
noobs: List[SnipingNoob] = []
with open(config.get("SNIPING_NOOBS_YAML_PATH"), "r") as stream:
noobs_dict = yaml.safe_load(stream)
if noobs_dict["noobs"]:
for noob_yaml in noobs_dict["noobs"]:
noob = SnipingNoob(address=Web3.toChecksumAddress(noob_yaml["address"]))
noobs.append(noob)
return noobs
snipe()