From cf58c1b443bc4dfd201f39a0b59acf363e6a5789 Mon Sep 17 00:00:00 2001 From: Valentin <77051586+vkgnosis@users.noreply.github.com> Date: Tue, 13 Jul 2021 13:00:16 +0200 Subject: [PATCH] Upgrade ethcontract version --- Cargo.lock | 16 +- contracts/Cargo.toml | 8 +- contracts/build.rs | 190 +++++++++++++---------- contracts/src/bin/vendor.rs | 2 +- e2e/Cargo.toml | 2 +- orderbook/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- shared/src/sources/balancer/pool_init.rs | 67 ++++---- solver/Cargo.toml | 2 +- 9 files changed, 158 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57feb3011..814c80efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -693,9 +693,9 @@ dependencies = [ [[package]] name = "ethabi" -version = "14.0.0" +version = "14.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52991643379afc90bfe2df3c64d53983e59c35a82ba6e75c997cfc2880d8524" +checksum = "a01317735d563b3bad2d5f90d2e1799f414165408251abb762510f40e790e69a" dependencies = [ "anyhow", "ethereum-types", @@ -722,9 +722,9 @@ dependencies = [ [[package]] name = "ethcontract" -version = "0.12.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afbc9a707b7c084ab9fa73658178a2f06882da913d8e7d6eb2e057f07885f435" +checksum = "cb1a6aadd606b3b67db0b633c58a0c4c53e451c15fcd7d19310d4e70ea52a0cb" dependencies = [ "arrayvec 0.7.0", "ethcontract-common", @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "ethcontract-common" -version = "0.12.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874df0b4f39bc3e61cb0ded0b18f83927419ca03d0c3dd2961a3de6ccb3a649b" +checksum = "fcbca652571fb9bad74da74506cdbaa4d764c2c334f5e4099a66f2f4ba9aa1a5" dependencies = [ "ethabi", "hex", @@ -761,9 +761,9 @@ dependencies = [ [[package]] name = "ethcontract-generate" -version = "0.12.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ede8864ece8934a17c5d1900074bb0585d537a4b1b96f58fbb4617b8df1132a" +checksum = "e7d8cee6759d3cf3afa4430871090816b307b3b044fc6df0bd33b0ddb33b5039" dependencies = [ "Inflector", "anyhow", diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index 215c5a962..2534f3d8b 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -26,19 +26,19 @@ bin = [ ] [dependencies] -ethcontract = { version = "0.12.2", default-features = false, features = ["http"] } +ethcontract = { version = "0.13.1", default-features = false, features = ["http"] } serde = "1.0" # [bin-dependencies] anyhow = { version = "1.0", optional = true } env_logger = { version = "0.8", optional = true } -ethcontract-generate = { version = "0.12.2", optional = true} +ethcontract-generate = { version = "0.13.1", optional = true} filetime = { version = "0.2.14", optional = true } log = { version = "0.4", optional = true } serde_json = { version = "1.0", optional = true } tokio = { version = "1.8", optional = true, features = ["macros", "rt-multi-thread", "time"] } [build-dependencies] -ethcontract-generate = "0.12.2" -ethcontract = { version = "0.12.2", default-features = false, features = ["http"] } +ethcontract = { version = "0.13.1", default-features = false, features = ["http"] } +ethcontract-generate = "0.13.1" maplit = "1.0" diff --git a/contracts/build.rs b/contracts/build.rs index 3099ad4ea..5020fc430 100644 --- a/contracts/build.rs +++ b/contracts/build.rs @@ -1,5 +1,8 @@ -use ethcontract::common::DeploymentInformation; -use ethcontract_generate::{Address, Builder}; +use ethcontract::{ + common::{contract::Network, DeploymentInformation}, + Address, +}; +use ethcontract_generate::{loaders::TruffleLoader, ContractBuilder}; use std::{env, fs, path::Path}; #[path = "src/paths.rs"] @@ -17,55 +20,67 @@ fn main() { generate_contract_with_config("BalancerV2Vault", |builder| { builder - .with_contract_mod_override(Some("balancer_v2_vault")) - .add_deployment( - 1, - addr("0xBA12222222228d8Ba445958a75a0704d566BF2C8"), - Some(tx( - "0x28c44bb10d469cbd42accf97bd00b73eabbace138e9d44593e851231fbed1cb7", - )), + .contract_mod_override("balancer_v2_vault") + .add_network( + "1", + Network { + address: addr("0xBA12222222228d8Ba445958a75a0704d566BF2C8"), + deployment_information: Some(tx( + "0x28c44bb10d469cbd42accf97bd00b73eabbace138e9d44593e851231fbed1cb7", + )), + }, ) - .add_deployment( - 4, - addr("0xBA12222222228d8Ba445958a75a0704d566BF2C8"), - // - Some(DeploymentInformation::BlockNumber(8441702)), + .add_network( + "4", + Network { + address: addr("0xBA12222222228d8Ba445958a75a0704d566BF2C8"), + // + deployment_information: Some(DeploymentInformation::BlockNumber(8441702)), + }, ) }); generate_contract_with_config("BalancerV2WeightedPoolFactory", |builder| { builder - .with_contract_mod_override(Some("balancer_v2_weighted_pool_factory")) - .add_deployment( - 1, - addr("0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9"), - Some(tx( - "0x0f9bb3624c185b4e107eaf9176170d2dc9cb1c48d0f070ed18416864b3202792", - )), + .contract_mod_override("balancer_v2_weighted_pool_factory") + .add_network( + "1", + Network { + address: addr("0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9"), + deployment_information: Some(tx( + "0x0f9bb3624c185b4e107eaf9176170d2dc9cb1c48d0f070ed18416864b3202792", + )), + }, ) - .add_deployment( - 4, - addr("0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9"), - Some(tx( - "0xae8c45c1d40756d0eb312723a2993341e379ea6d8bef4adfae2709345939f8eb", - )), + .add_network( + "4", + Network { + address: addr("0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9"), + deployment_information: Some(tx( + "0xae8c45c1d40756d0eb312723a2993341e379ea6d8bef4adfae2709345939f8eb", + )), + }, ) }); generate_contract_with_config("BalancerV2WeightedPool2TokensFactory", |builder| { builder - .with_contract_mod_override(Some("balancer_v2_weighted_pool_2_tokens_factory")) - .add_deployment( - 1, - addr("0xa5bf2ddf098bb0ef6d120c98217dd6b141c74ee0"), - Some(tx( - "0xf40c05058422d730b7035c254f8b765722935a5d3003ac37b13a61860adbaf08", - )), + .contract_mod_override("balancer_v2_weighted_pool_2_tokens_factory") + .add_network( + "1", + Network { + address: addr("0xa5bf2ddf098bb0ef6d120c98217dd6b141c74ee0"), + deployment_information: Some(tx( + "0xf40c05058422d730b7035c254f8b765722935a5d3003ac37b13a61860adbaf08", + )), + }, ) - .add_deployment( - 4, - addr("0xa5bf2ddf098bb0ef6d120c98217dd6b141c74ee0"), - Some(tx( - "0xbe28062b575c2743b3b4525c3a175b9acad36695c15dba1c69af5f3fc3ceca37", - )), + .add_network( + "4", + Network { + address: addr("0xa5bf2ddf098bb0ef6d120c98217dd6b141c74ee0"), + deployment_information: Some(tx( + "be28062b575c2743b3b4525c3a175b9acad36695c15dba1c69af5f3fc3ceca37", + )), + }, ) }); generate_contract("BalancerV2WeightedPool"); @@ -74,60 +89,66 @@ fn main() { generate_contract("GPv2AllowListAuthentication"); generate_contract_with_config("GPv2Settlement", |builder| { builder - .with_contract_mod_override(Some("gpv2_settlement")) - .add_deployment( - 1, - addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), - Some(tx( - "0x34b7f9a340e663df934fcc662b3ec5fcd7cd0c93d3c46f8ce612e94fff803909", - )), + .contract_mod_override("gpv2_settlement") + .add_network( + "1", + Network { + address: addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), + deployment_information: Some(tx( + "34b7f9a340e663df934fcc662b3ec5fcd7cd0c93d3c46f8ce612e94fff803909", + )), + }, ) - .add_deployment( - 4, - addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), - Some(tx( - "0x52badda922fd91052e6682d125daa59dea3ce5c57add5a9d362bec2d6ccfd2b1", - )), + .add_network( + "4", + Network { + address: addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), + deployment_information: Some(tx( + "52badda922fd91052e6682d125daa59dea3ce5c57add5a9d362bec2d6ccfd2b1", + )), + }, ) - .add_deployment( - 100, - addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), - Some(tx( - "0x95bbefbca7162435eeb71bac6960aae4d7112abce87a51ad3952d7b7af0279e3", - )), + .add_network( + "100", + Network { + address: addr("0x3328f5f2cEcAF00a2443082B657CedEAf70bfAEf"), + deployment_information: Some(tx( + "95bbefbca7162435eeb71bac6960aae4d7112abce87a51ad3952d7b7af0279e3", + )), + }, ) }); generate_contract("IUniswapLikeRouter"); generate_contract("IUniswapLikePair"); generate_contract_with_config("SushiswapV2Router02", |builder| { builder - .add_deployment_str(1, "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F") - .add_deployment_str(4, "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506") - .add_deployment_str(100, "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506") + .add_network_str("1", "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F") + .add_network_str("4", "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506") + .add_network_str("100", "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506") }); generate_contract_with_config("SushiswapV2Factory", |builder| { builder - .add_deployment_str(1, "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac") - .add_deployment_str(4, "0xc35DADB65012eC5796536bD9864eD8773aBc74C4") - .add_deployment_str(100, "0xc35DADB65012eC5796536bD9864eD8773aBc74C4") + .add_network_str("1", "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac") + .add_network_str("4", "0xc35DADB65012eC5796536bD9864eD8773aBc74C4") + .add_network_str("100", "0xc35DADB65012eC5796536bD9864eD8773aBc74C4") }); generate_contract_with_config("UniswapV2Router02", |builder| { builder - .add_deployment_str(1, "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D") - .add_deployment_str(4, "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D") - .add_deployment_str(100, "0x1C232F01118CB8B424793ae03F870aa7D0ac7f77") + .add_network_str("1", "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D") + .add_network_str("4", "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D") + .add_network_str("100", "0x1C232F01118CB8B424793ae03F870aa7D0ac7f77") }); generate_contract_with_config("UniswapV2Factory", |builder| { builder - .add_deployment_str(1, "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") - .add_deployment_str(4, "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") - .add_deployment_str(100, "0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7") + .add_network_str("1", "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") + .add_network_str("4", "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") + .add_network_str("100", "0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7") }); generate_contract_with_config("WETH9", |builder| { builder - .add_deployment_str(1, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") - .add_deployment_str(4, "0xc778417E063141139Fce010982780140Aa0cD5Ab") - .add_deployment_str(100, "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d") + .add_network_str("1", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") + .add_network_str("4", "0xc778417E063141139Fce010982780140Aa0cD5Ab") + .add_network_str("100", "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d") }); } @@ -135,25 +156,30 @@ fn generate_contract(name: &str) { generate_contract_with_config(name, |builder| builder) } -fn generate_contract_with_config(name: &str, config: impl FnOnce(Builder) -> Builder) { - let artifact = paths::contract_artifacts_dir() +fn generate_contract_with_config( + name: &str, + config: impl FnOnce(ContractBuilder) -> ContractBuilder, +) { + let path = paths::contract_artifacts_dir() .join(name) .with_extension("json"); + let contract = TruffleLoader::new() + .name(name) + .load_contract_from_file(&path) + .unwrap(); let address_file = paths::contract_address_file(name); let dest = env::var("OUT_DIR").unwrap(); - println!("cargo:rerun-if-changed={}", artifact.display()); - let mut builder = Builder::new(artifact) - .with_contract_name_override(Some(name)) - .with_visibility_modifier(Some("pub")); + println!("cargo:rerun-if-changed={}", path.display()); + let mut builder = ContractBuilder::new().visibility_modifier("pub"); if let Ok(address) = fs::read_to_string(&address_file) { println!("cargo:rerun-if-changed={}", address_file.display()); - builder = builder.add_deployment_str(5777, address.trim()); + builder = builder.add_network_str("5777", address.trim()); } config(builder) - .generate() + .generate(&contract) .unwrap() .write_to_file(Path::new(&dest).join(format!("{}.rs", name))) .unwrap(); diff --git a/contracts/src/bin/vendor.rs b/contracts/src/bin/vendor.rs index f908cf09e..681f5a341 100644 --- a/contracts/src/bin/vendor.rs +++ b/contracts/src/bin/vendor.rs @@ -132,7 +132,7 @@ impl VendorContext<'_> { fn github(&self, name: &str, path: &str) -> Result<&Self> { self.vendor_source( name, - Source::http(format!("https://raw.githubusercontent.com/{}", path))?, + Source::http(&format!("https://raw.githubusercontent.com/{}", path))?, ) } diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index bf5f332af..03ac0e727 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -12,7 +12,7 @@ harness = false [dev-dependencies] contracts = { path = "../contracts" } criterion = "0.3" -ethcontract = { version = "0.12.2", default-features = false } +ethcontract = { version = "0.13.1", default-features = false } hex-literal = "0.3" lazy_static = "1.4" maplit = "1.0" diff --git a/orderbook/Cargo.toml b/orderbook/Cargo.toml index 924cc629b..6473e0c65 100644 --- a/orderbook/Cargo.toml +++ b/orderbook/Cargo.toml @@ -21,7 +21,7 @@ bigdecimal = "0.2" chrono = { version = "0.4", default-features = false, features = ["clock"] } contracts = { path = "../contracts" } either = "1.0" -ethcontract = { version = "0.12.2", default-features = false } +ethcontract = { version = "0.13.1", default-features = false } futures = "0.3.15" gas-estimation = { git = "https://github.com/gnosis/gp-gas-estimation.git", tag = "v0.2.0", features = ["web3_"] } hex = { version = "0.4", default-features = false } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 168a98a28..830bb6bc9 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -12,7 +12,7 @@ async-trait = "0.1" atty = "0.2" contracts = { path = "../contracts" } derivative = "2.2" -ethcontract = { version = "0.12.2", default-features = false } +ethcontract = { version = "0.13.1", default-features = false } futures = "0.3" gas-estimation = { git = "https://github.com/gnosis/gp-gas-estimation.git", tag = "v0.2.0", features = ["web3_"] } hex = { version = "0.4", default-features = false } diff --git a/shared/src/sources/balancer/pool_init.rs b/shared/src/sources/balancer/pool_init.rs index 766cadfa3..723be8ea7 100644 --- a/shared/src/sources/balancer/pool_init.rs +++ b/shared/src/sources/balancer/pool_init.rs @@ -13,8 +13,8 @@ use contracts::{ BalancerV2Vault, BalancerV2WeightedPool2TokensFactory, BalancerV2WeightedPoolFactory, }; use ethcontract::{ - common::{truffle::Network, DeploymentInformation}, - Artifact, H160, + common::{contract::Network, DeploymentInformation}, + Contract, H160, }; use futures::stream::{self, StreamExt as _, TryStreamExt as _}; use std::sync::Arc; @@ -40,7 +40,8 @@ pub struct EmptyPoolInitializer(u64); #[async_trait::async_trait] impl PoolInitializing for EmptyPoolInitializer { async fn initialize_pools(&self) -> Result { - let fetched_block_number = deployment_block(BalancerV2Vault::artifact(), self.0).await?; + let fetched_block_number = + deployment_block(BalancerV2Vault::raw_contract(), self.0).await?; Ok(BalancerRegisteredPools { fetched_block_number, ..Default::default() @@ -120,14 +121,14 @@ where weighted_pools: pools .pools_by_factory .remove(&deployment_address( - BalancerV2WeightedPoolFactory::artifact(), + BalancerV2WeightedPoolFactory::raw_contract(), self.chain_id, )?) .unwrap_or_default(), weighted_2token_pools: pools .pools_by_factory .remove(&deployment_address( - BalancerV2WeightedPool2TokensFactory::artifact(), + BalancerV2WeightedPool2TokensFactory::raw_contract(), self.chain_id, )?) .unwrap_or_default(), @@ -195,7 +196,7 @@ where pools .pools_by_factory .remove(&deployment_address( - BalancerV2WeightedPoolFactory::artifact(), + BalancerV2WeightedPoolFactory::raw_contract(), self.chain_id, )?) .unwrap_or_default(), @@ -207,7 +208,7 @@ where pools .pools_by_factory .remove(&deployment_address( - BalancerV2WeightedPool2TokensFactory::artifact(), + BalancerV2WeightedPool2TokensFactory::raw_contract(), self.chain_id, )?) .unwrap_or_default(), @@ -257,35 +258,24 @@ impl BalancerSubgraph for BalancerSubgraphClient { } } -fn deployment(artifact: &Artifact, chain_id: u64) -> Result<&Network> { - artifact +fn deployment(contract: &Contract, chain_id: u64) -> Result<&Network> { + contract .networks .get(&chain_id.to_string()) // Note that we are conflating network IDs with chain IDs. In general // they cannot be considered the same, but for the networks that we // support (xDAI, Rinkeby and Mainnet) they are. - .ok_or_else(|| { - anyhow!( - "missing {} deployment for {}", - artifact.contract_name, - chain_id, - ) - }) + .ok_or_else(|| anyhow!("missing {} deployment for {}", contract.name, chain_id)) } -fn deployment_address(artifact: &Artifact, chain_id: u64) -> Result { - Ok(deployment(artifact, chain_id)?.address) +fn deployment_address(contract: &Contract, chain_id: u64) -> Result { + Ok(deployment(contract, chain_id)?.address) } -async fn deployment_block(artifact: &Artifact, chain_id: u64) -> Result { - let deployment_info = deployment(artifact, chain_id)? +async fn deployment_block(contract: &Contract, chain_id: u64) -> Result { + let deployment_info = deployment(contract, chain_id)? .deployment_information - .ok_or_else(|| { - anyhow!( - "missing deployment information for {}", - artifact.contract_name - ) - })?; + .ok_or_else(|| anyhow!("missing deployment information for {}", contract.name))?; match deployment_info { DeploymentInformation::BlockNumber(block) => Ok(block), @@ -330,9 +320,12 @@ mod tests { let chain_id = 1; let weighted_factory = - deployment_address(BalancerV2WeightedPoolFactory::artifact(), chain_id).unwrap(); - let weighted_2token_factory = - deployment_address(BalancerV2WeightedPool2TokensFactory::artifact(), chain_id).unwrap(); + deployment_address(BalancerV2WeightedPoolFactory::raw_contract(), chain_id).unwrap(); + let weighted_2token_factory = deployment_address( + BalancerV2WeightedPool2TokensFactory::raw_contract(), + chain_id, + ) + .unwrap(); fn pool(seed: u8) -> RegisteredWeightedPool { RegisteredWeightedPool { @@ -387,8 +380,11 @@ mod tests { async fn supports_empty_and_missing_factories() { let chain_id = 4; - let weighted_2token_factory = - deployment_address(BalancerV2WeightedPool2TokensFactory::artifact(), chain_id).unwrap(); + let weighted_2token_factory = deployment_address( + BalancerV2WeightedPool2TokensFactory::raw_contract(), + chain_id, + ) + .unwrap(); let mut subgraph = MockBalancerSubgraph::new(); subgraph.expect_weighted_pools().returning(move || { @@ -453,9 +449,12 @@ mod tests { let chain_id = 1; let weighted_factory = - deployment_address(BalancerV2WeightedPoolFactory::artifact(), chain_id).unwrap(); - let weighted_2token_factory = - deployment_address(BalancerV2WeightedPool2TokensFactory::artifact(), chain_id).unwrap(); + deployment_address(BalancerV2WeightedPoolFactory::raw_contract(), chain_id).unwrap(); + let weighted_2token_factory = deployment_address( + BalancerV2WeightedPool2TokensFactory::raw_contract(), + chain_id, + ) + .unwrap(); let mut subgraph = MockBalancerSubgraph::new(); subgraph.expect_weighted_pools().returning(move || { diff --git a/solver/Cargo.toml b/solver/Cargo.toml index fd10911d2..436a4b2eb 100644 --- a/solver/Cargo.toml +++ b/solver/Cargo.toml @@ -20,7 +20,7 @@ bigdecimal = { version = "0.2", features = ["serde"] } chrono = { version = "0.4", default-features = false, features = ["clock"] } contracts = { path = "../contracts" } derivative = "2.2" -ethcontract = { version = "0.12.2", default-features = false } +ethcontract = { version = "0.13.1", default-features = false } futures = "0.3" gas-estimation = { git = "https://github.com/gnosis/gp-gas-estimation.git", tag = "v0.2.0", features = ["web3_"] } hex = "0.4"