Uniswap weth addrbook (#779)
* chore: docs for ethers-addressbook crate * chore: add uniswap and weth contract addresses for various networks
This commit is contained in:
parent
1287614e53
commit
3b0b313247
|
@ -13,7 +13,42 @@
|
|||
"weth": {
|
||||
"addresses": {
|
||||
"mainnet": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"rinkeby": "0xc778417E063141139Fce010982780140Aa0cD5Ab"
|
||||
"rinkeby": "0xc778417E063141139Fce010982780140Aa0cD5Ab",
|
||||
"ropsten": "0xc778417E063141139Fce010982780140Aa0cD5Ab",
|
||||
"goerli": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
|
||||
"kovan": "0xd0A1E359811322d97991E03f863a0C30C2cF029C",
|
||||
"optimism": "0x4200000000000000000000000000000000000006",
|
||||
"optimism_kovan": "0x4200000000000000000000000000000000000006"
|
||||
}
|
||||
},
|
||||
"uniswapV3SwapRouter": {
|
||||
"addresses": {
|
||||
"mainnet": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
||||
"rinkeby": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
||||
"ropsten": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
||||
"goerli": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
||||
"kovan": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
|
||||
"optimism": "0xE592427A0AEce92De3Edee1F18E0157C05861564"
|
||||
}
|
||||
},
|
||||
"uniswapV3SwapRouter02": {
|
||||
"addresses": {
|
||||
"mainnet": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
||||
"rinkeby": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
||||
"ropsten": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
||||
"goerli": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
||||
"kovan": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
||||
"optimism": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45"
|
||||
}
|
||||
},
|
||||
"uniswapV3Factory": {
|
||||
"addresses": {
|
||||
"mainnet": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||
"rinkeby": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||
"ropsten": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||
"goerli": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||
"kovan": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
|
||||
"optimism": "0x1F98431c8aD98523631AE4a59f267346ea31F984"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,17 +9,22 @@ const CONTRACTS_JSON: &str = include_str!("./contracts/contracts.json");
|
|||
static ADDRESSBOOK: Lazy<HashMap<String, Contract>> =
|
||||
Lazy::new(|| serde_json::from_str(CONTRACTS_JSON).unwrap());
|
||||
|
||||
/// Wrapper around a hash map that maps a [chain](https://github.com/gakonst/ethers-rs/blob/master/ethers-core/src/types/chain.rs) to the contract's deployed address on that chain.
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Contract {
|
||||
addresses: HashMap<Chain, Address>,
|
||||
}
|
||||
|
||||
impl Contract {
|
||||
/// Returns the address of the contract on the specified chain. If the contract's address is
|
||||
/// not found in the addressbook, the getter returns None.
|
||||
pub fn address(&self, chain: Chain) -> Option<Address> {
|
||||
self.addresses.get(&chain).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch the addressbook for a contract by its name. If the contract name is not a part of
|
||||
/// [ethers-addressbook](https://github.com/gakonst/ethers-rs/tree/master/ethers-addressbook) we return None.
|
||||
pub fn contract<S: Into<String>>(name: S) -> Option<Contract> {
|
||||
ADDRESSBOOK.get(&name.into()).cloned()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue