Skip to content

Commit

Permalink
Encode create2 function for eip712 transaction request
Browse files Browse the repository at this point in the history
  • Loading branch information
IAvecilla committed Dec 22, 2023
1 parent 285c6e5 commit cab86bd
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/eip712/transaction_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,19 @@ impl TryFrom<DeployRequest> for Eip712TransactionRequest {
fn try_from(request: DeployRequest) -> Result<Self, Self::Error> {
let mut contract_deployer_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
contract_deployer_path.push("src/abi/ContractDeployer.json");

let custom_data = Eip712Meta::new().factory_deps({
let mut factory_deps = Vec::new();
if let Some(factory_dependencies) = request.factory_deps {
factory_deps.extend(factory_dependencies);
}
factory_deps.push(request.contract_bytecode.clone());
factory_deps
});
// TODO: User could provide this instead of defaulting.
let salt = [1_u8; 32];

let custom_data = Eip712Meta::new()
.factory_deps({
let mut factory_deps = Vec::new();
if let Some(factory_dependencies) = request.factory_deps {
factory_deps.extend(factory_dependencies);
}
factory_deps.push(request.contract_bytecode.clone());
factory_deps
})
.salt(Bytes::from(salt));

let contract_deployer = Abi::load(BufReader::new(
File::open(contract_deployer_path).map_err(|e| {
Expand All @@ -299,10 +303,8 @@ impl TryFrom<DeployRequest> for Eip712TransactionRequest {
))
})?,
))?;
let create = contract_deployer.function("create")?;
let create_function = contract_deployer.function(&request.deploy_type)?;

// TODO: User could provide this instead of defaulting.
let salt = [0_u8; 32];
let bytecode_hash = hash_bytecode(&request.contract_bytecode).map_err(|e| {
ZKRequestError::CustomError(format!("Error hashing contract bytecode {e:?}"))
})?;
Expand All @@ -322,7 +324,7 @@ impl TryFrom<DeployRequest> for Eip712TransactionRequest {
}
};

let data = encode_function_data(create, (salt, bytecode_hash, call_data))?;
let data = encode_function_data(create_function, (salt, bytecode_hash, call_data))?;

let contract_deployer_address = Address::from_str(CONTRACT_DEPLOYER_ADDR).map_err(|e| {
ZKRequestError::CustomError(format!("Error getting contract deployer address {e:?}"))
Expand Down

0 comments on commit cab86bd

Please sign in to comment.