Explanation of the proxy pattern used in CreateDAO.
DAOFactory
deploys a new DAO using createDAO
, it deploys several proxy contracts:
DAOProxy
DAOTokenProxy
DAOStakingProxy
DAOTreasuryProxy
proposePresale
proposal is executed, the DAO
contract deploys a DAOPresaleProxy
.
Each of these proxy contracts is initialized to point to the address of the corresponding implementation contract (e.g., DAO.sol
, DAOToken.sol
) registered in the DAOFactory
at the time of deployment.
upgradeToAndCall
) resides within the implementation contract itself, not the proxy._authorizeUpgrade
function) to control who can trigger an upgrade. For the DAO.sol
contract and its modules, upgrades are authorized only when called during the execution of a successful proposeUpgrade
or proposeModuleUpgrade
governance proposal.delegatecall
: Proxies use the delegatecall
opcode to forward calls to the implementation. This means the implementation contract’s code executes in the context of the proxy contract’s storage, allowing the implementation logic to modify the proxy’s state.initialize(...)
) instead of constructors, as the constructor code only runs when the implementation contract itself is deployed, not when the proxy is initialized.