|
1 | 1 | use crate::artifacts; |
2 | 2 | use anyhow::Result; |
3 | | -use ethers::{abi::Token, prelude::*}; |
| 3 | +use ethers::prelude::*; |
4 | 4 | use std::sync::Arc; |
5 | 5 |
|
6 | 6 | pub async fn deploy_contract( |
7 | 7 | contract_name: &str, |
8 | 8 | provider: Provider<Http>, |
9 | 9 | wallet: LocalWallet, |
10 | 10 | ) -> Result<Address> { |
11 | | - let endpoint_address = "0x0000000000000000000000000000000000000001".parse::<Address>()?; |
12 | | - let constructor_args = vec![ |
13 | | - abi::Token::Address(endpoint_address), |
14 | | - abi::Token::Address(endpoint_address), |
15 | | - ]; |
| 11 | + // TODO Extract |
| 12 | + let endpoint_address = "0x6EDCE65403992e310A62460808c4b910D972f10f".parse::<Address>()?; |
| 13 | + let delegator_address = "0x6EDCE65403992e310A62460808c4b910D972f10f".parse::<Address>()?; |
16 | 14 |
|
17 | | - let abi = artifacts::load_abi(contract_name)?; |
18 | | - let bytecode = artifacts::load_bytecode(contract_name)?; |
19 | | - println!("ABI {:?}\nBytecode {:?}", abi, bytecode); |
20 | | - let client = Arc::new(SignerMiddleware::new(provider, wallet)); |
21 | | - |
22 | | - let factory = ContractFactory::new(abi, bytecode, Arc::new(client.clone())); |
| 15 | + // FIXME abi is not used, is replaced by abigen! macro. Remove from artifacts module |
| 16 | + // let abi = artifacts::load_abi(contract_name)?; |
| 17 | + // TODO Move closer to artifact reading |
| 18 | + abigen!(MyOApp, "core/src/solidity/artifacts/MyOApp.sol/MyOApp.json"); |
23 | 19 |
|
24 | | - println!("Factory {:?}", factory); |
| 20 | + // FIXME bytecode is not used, is replaced by abigen! macro. Remove from artifacts module |
| 21 | + // let bytecode = artifacts::load_bytecode(contract_name)?; |
| 22 | + let client = Arc::new(SignerMiddleware::new(provider, wallet)); |
25 | 23 |
|
26 | | - let deployed = factory.deploy(constructor_args)?.send().await?; |
| 24 | + // Tuples are used. |
| 25 | + let deployed = MyOApp::deploy(client, (endpoint_address, delegator_address)) |
| 26 | + .map_err(|e| { |
| 27 | + println!("Deployment preparation error: {:?}", e); |
| 28 | + anyhow::Error::from(e) |
| 29 | + })? |
| 30 | + .send() |
| 31 | + .await |
| 32 | + .map_err(|e| { |
| 33 | + println!("Deployment execution error: {:?}", e); |
| 34 | + anyhow::Error::from(e) |
| 35 | + })?; |
27 | 36 |
|
28 | 37 | Ok(deployed.address()) |
29 | 38 | } |
0 commit comments