hyperdrive_wrappers/
lib.rs1#[rustfmt::skip]
2#[allow(clippy::all)]
3pub mod wrappers;
4
5
6pub mod linked_factory {
7 use std::sync::Arc;
8
9 use ethers::{abi::Abi, prelude::*, utils::hex};
10 use ethers_solc::utils::library_hash_placeholder;
11
12 pub fn create<M, I, S>(
15 abi: Abi,
16 bytecode_str: &str,
17 libs: I,
18 client: Arc<M>,
19 ) -> std::io::Result<ContractFactory<M>>
20 where
21 M: Middleware,
22 I: IntoIterator<Item = (S, Address)>,
23 S: AsRef<str>,
24 {
25 let mut linked_bytecode: String = bytecode_str.to_string();
26
27 for (lib, addr) in libs {
28 let hex_addr = hex::encode(addr);
29 let place_holder = library_hash_placeholder(lib.as_ref());
30 linked_bytecode = linked_bytecode.replace(&format!("__{place_holder}__"), &hex_addr);
31 }
32
33 let raw_bytecode: Bytes = hex::decode(&linked_bytecode).unwrap().into();
34 let factory = ContractFactory::new(abi, raw_bytecode, client);
35 Ok(factory)
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use std::{sync::Arc, time::Duration};
42
43 use ethers::{
44 abi::Address,
45 core::utils::Anvil,
46 middleware::SignerMiddleware,
47 providers::{Http, Provider},
48 signers::{LocalWallet, Signer},
49 types::U256,
50 };
51 use eyre::Result;
52
53 use crate::wrappers::erc4626_target0::{ERC4626Target0, ERC4626Target0Libs, Fees, PoolConfig};
54
55 #[tokio::test]
56 async fn test_link_and_deploy() -> Result<()> {
57 let anvil = Anvil::new().spawn();
58 let wallet: LocalWallet = anvil.keys()[0].clone().into();
59 let provider =
60 Provider::<Http>::try_from(anvil.endpoint())?.interval(Duration::from_millis(10u64));
61 let client = Arc::new(SignerMiddleware::new(
62 provider,
63 wallet.with_chain_id(anvil.chain_id()),
64 ));
65
66 let pool_config: PoolConfig = PoolConfig {
67 base_token: Address::zero(),
68 vault_shares_token: Address::zero(),
69 linker_factory: Address::zero(),
70 linker_code_hash: [0u8; 32],
71 initial_vault_share_price: U256::from(0),
72 minimum_share_reserves: U256::from(0),
73 minimum_transaction_amount: U256::from(0),
74 position_duration: U256::from(0),
75 checkpoint_duration: U256::from(0),
76 time_stretch: U256::from(0),
77 governance: Address::zero(),
78 fee_collector: Address::zero(),
79 sweep_collector: Address::zero(),
80 checkpoint_rewarder: Address::zero(),
81 fees: Fees {
82 curve: U256::from(0),
83 flat: U256::from(0),
84 governance_lp: U256::from(0),
85 governance_zombie: U256::from(0),
86 },
87 circuit_breaker_delta: U256::from(0),
88 };
89
90 let erc4626_target0 = ERC4626Target0::link_and_deploy(
91 client.clone(),
92 (pool_config,),
93 ERC4626Target0Libs {
94 lp_math: Address::zero(),
95 },
96 )
97 .unwrap()
98 .send()
99 .await
100 .unwrap();
101
102 println!(
103 "ERC4626Target0 deployed at: {:?}",
104 erc4626_target0.address()
105 );
106
107 Ok(())
108 }
109}