I am trying to build a factory InterviewProxy using ERC1967Proxy. I am using Remix for deployment.
My implementation contract is Interview.Sol which is a UUPSUpgradeable.
First I deploy Interview and then try to pass its address as _Delegate to the constructor of InterviewProxy.
I am not sure what to pass for _Data. What is _Data for? I tried and passed some random Byte data, but I still got the error "Address: low-level delegate call failed".
Please let me know if you see any other issue with my proxy factory. Thanks.
I appreciate any help.
Here is my code:
'''
// SPDX-License-Identifier: GPL-3.0
Your proxy factory itself does not need to extend ERC1967Proxy since it is not a proxy.
_data is an encoded function call to your implementation contract's initializer, and this encoded function call should include the initializer function name and its arguments. This allows the proxy to be initialized at the same time as it is deployed.
Another quick question, I like my BuildInterview() function to be payable because my initializer() function is payable. Is there a way that I can pass {value: msg.value} in abi.encodeWithSelector(Interview(address(0)).initialize.selector, tx.origin, msg.sender, reward_per_finalist, number_of_finalists, number_of_interviews)?
Thanks again!
'''
contract InterviewFactory {
address immutable InterviewImplementation;
address[] private deployedInterviews;
event InterviewDeployed(address InterviewAddress);
constructor(){
InterviewImplementation = address(new Interview());
}
function BuildInterview(uint reward_per_finalist, uint number_of_finalists, uint number_of_interviews) public payable {
ERC1967Proxy proxy = new ERC1967Proxy(
InterviewImplementation,
abi.encodeWithSelector(Interview(address(0)).initialize.selector, tx.origin, msg.sender, reward_per_finalist, number_of_finalists, number_of_interviews)
);
emit InterviewDeployed(address(proxy));
deployedInterviews.push(address(proxy));
}
function getDeployedInterviews() public view returns (address[] memory) {
return deployedInterviews;
}
function getFactoryImplementation() public view returns (address) {
return InterviewImplementation;
}
This will create the proxy with value sent at construction. The proxy will set itself up, including a delegate call with to the Interview.initialize function. Thanks to the delegate call semantics, this you can use msg.value in the this initialize function to retrieve the value transfer. Possibly you could also use address(this).balance (this might even be better, just in case the address already hold eth.