Hi there, suppose I’m using Clones.clone to create new contracts for a given template, as given in the code below. Now for a newly creately contract by cloning, the function calls to the new contract are delegated to the template contract as internal transactions. For example, in the graph below, the highlighted contract is the original template contract. And all newly created contracts are supposed to be independent from each other. I am wondering what is happening under the hood. Thanks.
Let’s say contract X deploys a clone Y of contract Z. Then if X.f() calls Y.g(), Y.g() will actually delegatecall Z.g() under the hood. That’s the expected behavior.
In my case, there is a contract factory, let’s say it’s called groupFactory, generating group contracts. In the groupFactory, a template group contract A is used to make clones B, C, D, etc. By design, B, C, D have all needed functions to perform actions independently from each other. But what I observed is a function call to B is actually delegated to A as shown in the graph above. This is unexpected, since no delegate call is designed in A and B, C, D, in my understanding, are just runtime code deployed at different addresses. Why is there a delegate call to A then?
Emmmm, I think, when you use groupFactory to clones A to get B, just like the common proxy pattern, B is the proxy, A is the implementation, that is B stores data, A stores logic.
Hey @Skyge , we can take the createpair function from psc for example. It is generating all independent pair contracts by create2. Is the Clones.clone function not doing the same?
Emmmmm, I think they are different, just like the original defined for the EIP-1167, it is Minimal Proxy Contract, so I think what you get after cloning is a proxy contract