Skip to content

Latest commit

 

History

History
259 lines (244 loc) · 9.4 KB

ModulesProxy.md

File metadata and controls

259 lines (244 loc) · 9.4 KB

ModulesProxy.sol

View Source: contracts/proxy/modules/ModulesProxy.sol

↗ Extends: ModulesProxyRegistry

ModulesProxy contract

Functions


constructor

Fallback function delegates calls to modules. Returns whatever the implementation call returns. Has a hook to execute before delegating calls To activate register a module with beforeFallback() function

function () external payable
Source Code
function() external payable {
        /*
        // Commented to safe gas by default
        // Uncomment for using beforeFallback() hook 
        // Implement and register beforeFallback() function in a module
        address beforeFallback = _getFuncImplementation(BEFORE_FALLBACK_SIG_BYTES4);
        if (beforeFallback != address(0)) {
            (bool success, ) = beforeFallback.delegatecall(bytes(0x39b0111a)); // abi.encodeWithSignature("beforeFallback()")
            require(success, "ModulesProxy::fallback: beforeFallback() fail"); //MP02
        }
        */

        address target = _getFuncImplementation(msg.sig);
        require(target != address(0), "ModulesProxy:target module not registered"); // MP03

        bytes memory data = msg.data;
        assembly {
            let result := delegatecall(gas, target, add(data, 0x20), mload(data), 0, 0)
            let size := returndatasize
            let ptr := mload(0x40)
            returndatacopy(ptr, 0, size)
            switch result
                case 0 {
                    revert(ptr, size)
                }
                default {
                    return(ptr, size)
                }
        }
    }

Contracts