Hello,

I’m familiar with using a proxy to create an upgradable logic contract. But I’d like to go one step further. I’d like to use a proxy that allows me to route the delegatecall to a logic contract of my choosing based on a parameter that’s passed into the function call. The logic contracts will not be hard coded in the proxy nor will they be limited to just 1. I may have many of them and they will all be written by me.

For example, say I have 2 logic contracts, A and B. I will make a function call to the proxy with the function selector, function parameters, and some piece of information that tells the proxy which logic contract to use (A or B). My goal is to not only allow A and B to be upgradable, but also leave room for the future when I add new logic contracts C and D.

This is type of proxy I’m familiar with using. I feel like what I want to do is only be a small modification away from this example. Has anyone done this or can anyone point me in the right direction for how to do this?

It seems that I would want to add an extra parameter to the function call. Then have the proxy read that extra parameter and use that as its implementation address. Does that sound right? Thing is, in the fallback function, there’s no visible parameter here… I can see in assembly where it gets the parameters via calldatacopy . Maybe I should just use msg.data to extract the implementation address from the call parameters?

/** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function () payable external { address _impl = implementation(); require(_impl != address(0)); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } }

Thanks

Edit: I should note, I’m very familiar with writing inline assembly in the C language from back in the day But I haven’t ever written much assembly in Solidity and I’m not sure of the best way to write, test, and debug assembly in solidity.