2 level delegatecall (from custom proxy to upgradeable proxy and to implementation)


I'm trying to implement the next architecture: a factory contract that deploys custom proxies that are able to interact with upgradeable OZ proxy.


All custom proxies deployed through the factory should delegatecall to one OZ UPG proxy and OZ UPG proxy should delegatecall to the implementation contract.

Is it possible to implement 2 level delegatecall? I'm trying to do this and during the test, it fails to call the custom proxy and to execute code from the implementation contract.

The pattern you described sounds like the beacon proxy concept. Have you considered beacons? See BeaconProxy and UpgradeableBeacon in https://docs.openzeppelin.com/contracts/5.x/api/proxy

It would be similar to your diagram, but each Pool Proxy would be a BeaconProxy instead, and the Pool Upgradeable Proxy would be an UpgradeableBeacon.

Calling a BeaconProxy would do the following: it would retrieve the implementation address from its associated UpgradeableBeacon, then the BeaconProxy does a delegatecall directly to the implementation. There is no need for a 2 level delegatecall in this situation.

1 Like

Thank you @ericglau
It is really what I need

1 Like