I'm trying to reason how a factory can make calls to a child contract that is owned by an EOA.
The goal of this project is to make a StoreFactory contract that allows anyone to deploy their own Store contract. The merchant that deploys the store should be the owner and should be the only one who can withdraw ETH from purchases. The following is some psuedocode that I'm trying to fix to enable this flow.
After a little research, I believe I need to use delegatecall, but I'm not sure.
StoreFactory:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "./Store.sol";
contract StoreFactory {
uint256 id;
mapping(uint256 => Store) storeMapping;
function createStore() public {
Store store = new Store();
store.transferOwnership(msg.sender());
storeMapping[id] = child;
id++;
}
function depositEth(uint256 _id) public {
storeMapping[_id].depositEth();
}
function withdrawEth(uint256 _id) public {
storeMapping[_id].withdrawEth();
}
}
Store (child) contract:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "openzeppelin-contracts/contracts/access/Ownable.sol";
contract Store is Ownable {
function depositEth() public payable {}
function withdrawEth() public onlyOwner {
uint amount = address(this).balance;
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Failed to send Ether");
}
}
If the factory is making the calls, how can funds be withdrawn by the original EOA account who created the store? This is what I'm trying to accomplish.