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

Pair Addresses #38

Merged
merged 3 commits into from
Jan 22, 2021
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
621 changes: 621 additions & 0 deletions res/sushipairs.csv

Large diffs are not rendered by default.

3,908 changes: 3,908 additions & 0 deletions res/v1pairs.csv

Large diffs are not rendered by default.

28,864 changes: 28,864 additions & 0 deletions res/v2pairs.csv

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions scripts/addrs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Script to get all Uni V1, V2 and Sushiswap pair addresses.
# Requires web3.py installed (`pip install web3`)
# URL=http://localhost:8545 python addrs.py
from web3 import Web3, HTTPProvider
import os

# abis
v1abi = [{"name": "NewExchange", "inputs": [{"type": "address", "name": "token", "indexed": True}, {"type": "address", "name": "exchange", "indexed": True}], "anonymous": False, "type": "event"}]
v2abi = [{"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"payable":False,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":False,"inputs":[{"indexed":True,"internalType":"address","name":"token0","type":"address"},{"indexed":True,"internalType":"address","name":"token1","type":"address"},{"indexed":False,"internalType":"address","name":"pair","type":"address"},{"indexed":False,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":True,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":False,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":True,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":False,"stateMutability":"view","type":"function"},{"constant":False,"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":False,"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":False,"stateMutability":"nonpayable","type":"function"}]

# addrs
V1FACTORY = "0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95"
V2FACTORY = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
SUSHIFACTORY = "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"

# deployed at blocks
V1DEPLOY = 0x65224d
V2DEPLOY = 0x9899c3
SUSHIDEPLOY = 0xa4b4f5

URL = os.environ["URL"]
w3 = Web3(HTTPProvider(URL))

def dump(fname, data):
with open(fname, 'w') as f:
for item in data:
f.write("%s\n" % item)

# if you get RPC errors, run each section separately
contract = w3.eth.contract(address = V1FACTORY, abi=v1abi)
events = contract.events.NewExchange.createFilter(fromBlock=V1DEPLOY).get_all_entries()
pairs = [e.args.exchange for e in events]
dump("./res/v1pairs.csv", pairs)

contract = w3.eth.contract(address = V2FACTORY, abi=v2abi)
events = contract.events.PairCreated.createFilter(fromBlock=V2DEPLOY).get_all_entries()
pairs = [e.args.pair for e in events]
dump("./res/v2pairs.csv", pairs)

contract = w3.eth.contract(address = SUSHIFACTORY, abi=v2abi)
events = contract.events.PairCreated.createFilter(fromBlock=SUSHIDEPLOY).get_all_entries()
pairs = [e.args.pair for e in events]
dump("./res/sushipairs.csv", pairs)
49 changes: 44 additions & 5 deletions src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use ethers::types::Address;

use once_cell::sync::Lazy;
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

pub fn lookup(address: Address) -> String {
ADDRESSBOOK
Expand All @@ -23,6 +26,16 @@ fn insert_many<T: Clone>(
map
}

// reads line-separated addresses from a file path and returns them as a vector
fn read_addrs<P>(path: P) -> Vec<Address>
where
P: AsRef<Path>,
{
let file = File::open(path).unwrap();
let lines = io::BufReader::new(file).lines();
lines.map(|line| parse_address(&line.unwrap())).collect()
}

// Protocol Addrs
pub static PROTOCOLS: Lazy<HashMap<Address, Protocol>> = Lazy::new(|| {
let map = HashMap::new();
Expand All @@ -39,7 +52,7 @@ pub static PROTOCOLS: Lazy<HashMap<Address, Protocol>> = Lazy::new(|| {
Protocol::Uniswap,
);

let map = insert_many(
let mut map = insert_many(
map,
&[
// sUSD - WETH
Expand All @@ -52,10 +65,34 @@ pub static PROTOCOLS: Lazy<HashMap<Address, Protocol>> = Lazy::new(|| {
Protocol::Sushiswap,
);

let map = insert_many(
map,
&["0x89ba27e73c929ebef87c9ff4b43052012ea838d9"],
Protocol::SakeSwap,
for addr in read_addrs("./res/v1pairs.csv") {
map.insert(addr, Protocol::UniswapV1);
}

for addr in read_addrs("./res/v2pairs.csv") {
map.insert(addr, Protocol::Uniswap);
}

for addr in read_addrs("./res/sushipairs.csv") {
map.insert(addr, Protocol::Sushiswap);
}

// uni router 02
map.insert(
parse_address("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"),
Protocol::Uniswap,
);

// uni router 01
map.insert(
parse_address("f164fC0Ec4E93095b804a4795bBe1e041497b92a"),
Protocol::Uniswap,
);

// sushi router
map.insert(
"d9e1cE17f2641f24aE83637ab66a2cca9C378B9F".parse().unwrap(),
Protocol::Sushiswap,
);

insert_many(
Expand All @@ -76,6 +113,8 @@ pub static FILTER: Lazy<HashSet<Address>> = Lazy::new(|| {
set.insert(parse_address("0x57805e5a227937bac2b0fdacaa30413ddac6b8e1"));
// yearn recycler
set.insert(parse_address("0x5F07257145fDd889c6E318F99828E68A449A5c7A"));
// drc, weird deflationary token
set.insert(parse_address("0xc66d62a2f9ff853d9721ec94fa17d469b40dde8d"));
set
});

Expand Down
2 changes: 1 addition & 1 deletion src/inspectors/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ mod tests {
assert_eq!(inspection.status, Status::Success);
assert_eq!(
inspection.protocols,
set![Protocol::Aave, Protocol::Uniswappy]
set![Protocol::Uniswap, Protocol::Aave]
);
let liquidation = known
.iter()
Expand Down
3 changes: 2 additions & 1 deletion src/inspectors/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ pub mod tests {
&both,
),
(
// sakeswap is uniswappy
"0xd9df5ae2e9e18099913559f71473866758df3fd25919be605c71c300e64165fd",
&crate::set![Protocol::Uniswap, Protocol::SakeSwap],
&crate::set![Protocol::Uniswappy, Protocol::Uniswap],
),
(
"0xfd24e512dc90bd1ca8a4f7987be6122c1fa3221b261e8728212f2f4d980ee4cd",
Expand Down
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Status {
/// The supported protocols
pub enum Protocol {
// Uniswap & Forks
UniswapV1,
Uniswap,
Uniswappy,
Sushiswap,
Expand Down