builder_relayer_client_rust/encode/
proxy.rs1use crate::types::ProxyTransaction;
2use alloy::primitives::{Address, U256};
3use alloy::sol;
4use alloy::sol_types::SolCall;
5use std::str::FromStr;
6
7sol! {
9 #[derive(Debug)]
10 contract ProxyFactory {
11 struct ProxyCall {
12 uint8 typeCode;
13 address to;
14 uint256 value;
15 bytes data;
16 }
17 function proxy(ProxyCall[] calls) returns (bytes[] returnValues);
18 }
19}
20
21pub fn encode_proxy_transaction_data(txns: &[ProxyTransaction]) -> String {
22 let calls: Vec<ProxyFactory::ProxyCall> = txns
23 .iter()
24 .map(|t| ProxyFactory::ProxyCall {
25 typeCode: t.type_code as u8,
26 to: Address::from_str(&t.to).unwrap_or(Address::ZERO),
27 value: U256::from_str_radix(&t.value, 10).unwrap_or(U256::ZERO),
28 data: hex::decode(t.data.trim_start_matches("0x"))
29 .unwrap_or_default()
30 .into(),
31 })
32 .collect();
33
34 let func_call = ProxyFactory::proxyCall { calls };
35 let encoded = func_call.abi_encode();
36 format!("0x{}", hex::encode(encoded))
37}