From 3b0b3132473dd72b3a8b5efbdb9b2917d9aa6c26 Mon Sep 17 00:00:00 2001 From: Rohit Narurkar Date: Sun, 9 Jan 2022 17:30:13 +0100 Subject: [PATCH] Uniswap weth addrbook (#779) * chore: docs for ethers-addressbook crate * chore: add uniswap and weth contract addresses for various networks --- .../src/contracts/contracts.json | 37 ++++++++++++++++++- ethers-addressbook/src/lib.rs | 5 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ethers-addressbook/src/contracts/contracts.json b/ethers-addressbook/src/contracts/contracts.json index b60d9b48..c852e000 100644 --- a/ethers-addressbook/src/contracts/contracts.json +++ b/ethers-addressbook/src/contracts/contracts.json @@ -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" } } } diff --git a/ethers-addressbook/src/lib.rs b/ethers-addressbook/src/lib.rs index 3abe61df..2acbfc42 100644 --- a/ethers-addressbook/src/lib.rs +++ b/ethers-addressbook/src/lib.rs @@ -9,17 +9,22 @@ const CONTRACTS_JSON: &str = include_str!("./contracts/contracts.json"); static ADDRESSBOOK: Lazy> = 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, } 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
{ 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>(name: S) -> Option { ADDRESSBOOK.get(&name.into()).cloned() }