Hi
I am trying to get some clarity on how proxies we create with ProxyFactory can be used/called.
My use case :
- I have a implementation/logic contract called Cash.sol. This is Initializable, Ownable. The Cash contract should be able to generate cash tokens of multiple currencies when ether is paid in. So, a minimal proxy of the Cash contract we deploy for USD should be able to generate a USD token, and a minimal proxy of the Cash contract we deploy for EUR should be able to generate a EUR token, and so forth. The only things that are parametrized for the minimal proxies is therefore a ‘currency name’.
//initiliaze proxies. here, _owner is the Factory, name is the currency name/symbol
function initialize(bytes32 _name, address _owner) public {
Ownable.initialize(_owner);
factory = Factory(_owner);
name = _name;
symbol = _name;
}
- I have a Factory.sol which is a ProxyFactory. It creates proxies of the Cash (implementation) contract and stores the proxy addresses in an array.
function createToken(address _target, bytes32 tokenName, bytes32 tokenType) external{
address _owner = msg.sender;
bytes memory _payload = abi.encodeWithSignature("initialize(bytes32,address)", tokenName, _owner);
// Deploy proxy
address _via = deployMinimal(_target, _payload);
emit TokenCreated(_via, tokenName, tokenType);
if(tokenType == "Cash"){
token[_via] = via("ViaCash", tokenName);
tokens.push(_via);
}
}
- I deploy the Factory and call and parameterize createToken() in the Factory with any number and names of currencies I want to support.
deployer.deploy(Factory).then(async () => {
const factory = await Factory.new();
const cash = await Cash.new();
await factory.createToken(cash.address, web3.utils.utf8ToHex("USD"),
web3.utils.utf8ToHex("Cash")); await factory.createToken(cash.address,
web3.utils.utf8ToHex("EUR"), web3.utils.utf8ToHex("Cash"));});
Now, my rather (naive) question is - to use the proxies, do I obtain the cash proxy address stored in the Factory and then use that address to send ether to ? I do not see how calls are delegated to the proxies.
Thanks !