-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathchained.rs
More file actions
59 lines (49 loc) · 1.67 KB
/
Copy pathchained.rs
File metadata and controls
59 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use alloy::{
primitives::{Address, Bytes},
sol,
};
use engine_core::{
chain::Chain,
error::{ContractErrorToEngineError, EngineError},
};
use super::AccountFactory;
pub struct ChainedAccountFactory<'a, C: Chain> {
pub chain: &'a C,
pub factory_address: Address,
}
sol! {
#[sol(rpc)]
contract AccountFactoryContract {
function getAddress(address _adminSigner, bytes _data) view returns (address);
function accountImplementation() external view returns (address);
}
}
impl<C: Chain> AccountFactory for ChainedAccountFactory<'_, C> {
fn factory_address(&self) -> &Address {
&self.factory_address
}
async fn predict_address(
&self,
signer: &Address,
salt_data: &Bytes,
) -> Result<Address, EngineError> {
let account_factory_contract =
AccountFactoryContract::new(self.factory_address, self.chain.provider().clone());
let predicted_address = account_factory_contract
.getAddress(signer.to_owned(), salt_data.to_owned())
.call()
.await
.map_err(|e| e.to_engine_error(self.chain.chain_id(), Some(self.factory_address)))?;
Ok(predicted_address)
}
async fn implementation_address(&self) -> Result<Address, EngineError> {
let account_factory_contract =
AccountFactoryContract::new(self.factory_address, self.chain.provider().clone());
let predicted_address = account_factory_contract
.accountImplementation()
.call()
.await
.map_err(|e| e.to_engine_error(self.chain.chain_id(), Some(self.factory_address)))?;
Ok(predicted_address)
}
}