GenesisFactory

Description:

Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "GenesisFactory.sol": {
      "content": "//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// GENERATED CODE - do not edit manually!!
// This code was generated by the Synthetix router project and deployed with Cannon.
// Learn more: https://usecannon.com/learn/guides/router
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

contract GenesisFactory {
    error UnknownSelector(bytes4 sel);

    address immutable private _ROUTER_ADDRESS;

    constructor() {
        _ROUTER_ADDRESS = address(this);

        bytes4[] memory selectors;
        selectors = new bytes4[](18);
        selectors[0] = 0x79ba5097;
        selectors[1] = 0x081705c1;
        selectors[2] = 0x5dfb1bba;
        selectors[3] = 0x02ae822b;
        selectors[4] = 0x6fb40af9;
        selectors[5] = 0x76a89bca;
        selectors[6] = 0x2b4245b6;
        selectors[7] = 0x7fcced05;
        selectors[8] = 0x2ba722eb;
        selectors[9] = 0xc9ade818;
        selectors[10] = 0xc4d66de8;
        selectors[11] = 0x8da5cb5b;
        selectors[12] = 0xe30c3978;
        selectors[13] = 0xfbdc9644;
        selectors[14] = 0x3b84f045;
        selectors[15] = 0xf2fde38b;
        selectors[16] = 0x99ace420;
        selectors[17] = 0xdcd68128;
        _facets().push(Facet(_CONFIGURATION_MODULE, selectors));
        selectors = new bytes4[](8);
        selectors[0] = 0x3656eec2;
        selectors[1] = 0x181e7b3b;
        selectors[2] = 0xdb2088f4;
        selectors[3] = 0xe2bbb158;
        selectors[4] = 0x0fd98948;
        selectors[5] = 0x589864da;
        selectors[6] = 0x94605857;
        selectors[7] = 0x441a3e70;
        _facets().push(Facet(_VAULT_MODULE, selectors));
        selectors = new bytes4[](8);
        selectors[0] = 0x7d838e1f;
        selectors[1] = 0x8d10c729;
        selectors[2] = 0x720ee314;
        selectors[3] = 0x0b46eae2;
        selectors[4] = 0xec7b3c1f;
        selectors[5] = 0x4daa704c;
        selectors[6] = 0xb0ba39ab;
        selectors[7] = 0xb55aa5f4;
        _facets().push(Facet(_STRATEGY_MODULE, selectors));
        selectors = new bytes4[](7);
        selectors[0] = 0x4d22bf1c;
        selectors[1] = 0x6d5f3c73;
        selectors[2] = 0x2752a567;
        selectors[3] = 0x18fd7858;
        selectors[4] = 0x2d99be42;
        selectors[5] = 0x438bdbb4;
        selectors[6] = 0x0e0cb1d6;
        _facets().push(Facet(_MIGRATION_MODULE, selectors));

        _emitDiamondCutEvent();
    }

    address private constant _CONFIGURATION_MODULE = 0x012E639E87aFD9c8c20c39A381117e6434E845Bd;
    address private constant _VAULT_MODULE = 0x0962E1871080084F3A42b045cb96A46C443d2c89;
    address private constant _STRATEGY_MODULE = 0x064714533116845f29A20f18300463bD5B8609c6;
    address private constant _MIGRATION_MODULE = 0x6ea201156C58aFDbC2A02dBd5E6EdB3DCAbB079C;

    fallback(bytes calldata cd) external payable returns (bytes memory) {
        // Lookup table: Function selector => implementation contract
        bytes4 sig4 = msg.sig;
        address implementation;

        assembly {
            let sig32 := shr(224, sig4)

            function findImplementation(sig) -> result {
                if lt(sig,0x720ee314) {
                    if lt(sig,0x3656eec2) {
                        if lt(sig,0x18fd7858) {
                            switch sig
                            case 0x02ae822b { result := _CONFIGURATION_MODULE } // ConfigurationModule.emergencySYTokenRecover()
                            case 0x081705c1 { result := _CONFIGURATION_MODULE } // ConfigurationModule.createSYTokenVault()
                            case 0x0b46eae2 { result := _STRATEGY_MODULE } // StrategyModule.getVaultStrategy()
                            case 0x0e0cb1d6 { result := _MIGRATION_MODULE } // MigrationModule.migrateVault()
                            case 0x0fd98948 { result := _VAULT_MODULE } // VaultModule.getUserAccountSummary()
                            case 0x181e7b3b { result := _VAULT_MODULE } // VaultModule.convertToAssets()
                            leave
                        }
                        switch sig
                        case 0x18fd7858 { result := _MIGRATION_MODULE } // MigrationModule.initiateMigration()
                        case 0x2752a567 { result := _MIGRATION_MODULE } // MigrationModule.getMigrationTimestamp()
                        case 0x2b4245b6 { result := _CONFIGURATION_MODULE } // ConfigurationModule.getSYToken()
                        case 0x2ba722eb { result := _CONFIGURATION_MODULE } // ConfigurationModule.getVaultConfiguration()
                        case 0x2d99be42 { result := _MIGRATION_MODULE } // MigrationModule.isMigrationInitiated()
                        leave
                    }
                    if lt(sig,0x4daa704c) {
                        switch sig
                        case 0x3656eec2 { result := _VAULT_MODULE } // VaultModule.balanceOf()
                        case 0x3b84f045 { result := _CONFIGURATION_MODULE } // ConfigurationModule.setWithdrawalPenalty()
                        case 0x438bdbb4 { result := _MIGRATION_MODULE } // MigrationModule.isVaultMigrated()
                        case 0x441a3e70 { result := _VAULT_MODULE } // VaultModule.withdraw()
                        case 0x4d22bf1c { result := _MIGRATION_MODULE } // MigrationModule.getMigrationDelay()
                        leave
                    }
                    switch sig
                    case 0x4daa704c { result := _STRATEGY_MODULE } // StrategyModule.setPerformanceFee()
                    case 0x589864da { result := _VAULT_MODULE } // VaultModule.getVaultState()
                    case 0x5dfb1bba { result := _CONFIGURATION_MODULE } // ConfigurationModule.createVault()
                    case 0x6d5f3c73 { result := _MIGRATION_MODULE } // MigrationModule.getMigrationProxy()
                    case 0x6fb40af9 { result := _CONFIGURATION_MODULE } // ConfigurationModule.getGlobalPauseState()
                    leave
                }
                if lt(sig,0xb55aa5f4) {
                    if lt(sig,0x8d10c729) {
                        switch sig
                        case 0x720ee314 { result := _STRATEGY_MODULE } // StrategyModule.getUnclaimedIncentives()
                        case 0x76a89bca { result := _CONFIGURATION_MODULE } // ConfigurationModule.getNextVaultId()
                        case 0x79ba5097 { result := _CONFIGURATION_MODULE } // ConfigurationModule.acceptOwnership()
                        case 0x7d838e1f { result := _STRATEGY_MODULE } // StrategyModule.claimStrategyIncentives()
                        case 0x7fcced05 { result := _CONFIGURATION_MODULE } // ConfigurationModule.getVaultConfig()
                        leave
                    }
                    switch sig
                    case 0x8d10c729 { result := _STRATEGY_MODULE } // StrategyModule.getPerformanceFee()
                    case 0x8da5cb5b { result := _CONFIGURATION_MODULE } // ConfigurationModule.owner()
                    case 0x94605857 { result := _VAULT_MODULE } // VaultModule.totalAssets()
                    case 0x99ace420 { result := _CONFIGURATION_MODULE } // ConfigurationModule.updateVault()
                    case 0xb0ba39ab { result := _STRATEGY_MODULE } // StrategyModule.switchStrategy()
                    leave
                }
                if lt(sig,0xe2bbb158) {
                    switch sig
                    case 0xb55aa5f4 { result := _STRATEGY_MODULE } // StrategyModule.unsetStrategy()
                    case 0xc4d66de8 { result := _CONFIGURATION_MODULE } // ConfigurationModule.initialize()
                    case 0xc9ade818 { result := _CONFIGURATION_MODULE } // ConfigurationModule.getWithdrawalPenalty()
                    case 0xdb2088f4 { result := _VAULT_MODULE } // VaultModule.convertToShares()
                    case 0xdcd68128 { result := _CONFIGURATION_MODULE } // ConfigurationModule.vaultExists()
                    leave
                }
                switch sig
                case 0xe2bbb158 { result := _VAULT_MODULE } // VaultModule.deposit()
                case 0xe30c3978 { result := _CONFIGURATION_MODULE } // ConfigurationModule.pendingOwner()
                case 0xec7b3c1f { result := _STRATEGY_MODULE } // StrategyModule.isStrategyInUse()
                case 0xf2fde38b { result := _CONFIGURATION_MODULE } // ConfigurationModule.transferOwnership()
                case 0xfbdc9644 { result := _CONFIGURATION_MODULE } // ConfigurationModule.setGlobalPauseState()
                leave
            }

            implementation := findImplementation(sig32)
        }

        if (implementation == address(0)) {
            // It's possible this contract is being called through yet another proxy. Call the router in order to make sure we have right data.
            if (address(this) != _ROUTER_ADDRESS) {
                (bool success, bytes memory result) = _ROUTER_ADDRESS.call(cd);
                if (success) {
                    return result;
                } else {
                    revert UnknownSelector(sig4);
                }
            } else {
                // Check for diamond compat call
                if (sig4 == 0x7a0ed627) {
                    return abi.encode(_facets());
                }
                if (sig4 == 0xadfca15e) {
                    (address facet) = abi.decode(cd[4:], (address));
                    return abi.encode(_facetFunctionSelectors(facet));
                }
                if (sig4 == 0x52ef6b2c) {
                    return abi.encode(_facetAddresses());
                }
                if (sig4 == 0xcdffacc6) {
                    (bytes4 sig) = abi.decode(cd[4:], (bytes4));
                    return abi.encode(_facetAddress(sig));
                }
                if (sig4 == 0x8cce96cb) {
                    return abi.encode(_emitDiamondCutEvent());
                }
            }
            revert UnknownSelector(sig4);
        }

        // Delegatecall to the implementation contract
        assembly {
            calldatacopy(0, 0, calldatasize())

            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())

            switch result
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    struct Facet {
        address facetAddress;
        bytes4[] functionSelectors;
    }

    enum FacetCutAction {Add, Replace, Remove}
    // Add=0, Replace=1, Remove=2

    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    /// @notice Gets all facet addresses and their four byte function selectors.
    /// @return facets_ Facet
    function _facets() internal pure returns (Facet[] storage facets_) {
        bytes32 s = keccak256("Router.GenesisFactory");
        assembly {
            facets_.slot := s
        }
    }

    /// @notice Gets all the function selectors supported by a specific facet.
    /// @param _facet The facet address.
    /// @return facetFunctionSelectors_
    function _facetFunctionSelectors(address _facet) internal view returns (bytes4[] memory facetFunctionSelectors_) {
        Facet[] storage facets = _facets();
        for (uint256 i = 0;i < facets.length;i++) {
            if (facets[i].facetAddress == _facet) {
                return facets[i].functionSelectors;
            }
        }
    }

    /// @notice Get all the facet addresses used by a diamond.
    /// @return facetAddresses_
    function _facetAddresses() internal pure returns (address[] memory facetAddresses_) {
        facetAddresses_ = new address[](4);
        facetAddresses_[0] = _CONFIGURATION_MODULE;
        facetAddresses_[1] = _VAULT_MODULE;
        facetAddresses_[2] = _STRATEGY_MODULE;
        facetAddresses_[3] = _MIGRATION_MODULE;
    }

    /// @notice Gets the facet that supports the given selector.
    /// @dev If facet is not found return address(0).
    /// @param _functionSelector The function selector.
    /// @return facetAddress_ The facet address.
    function _facetAddress(bytes4 _functionSelector) internal view returns (address facetAddress_) {
        Facet[] storage facets = _facets();
        for (uint256 i = 0;i < facets.length;i++) {
            for (uint256 j = 0;j < facets[i].functionSelectors.length;j++) {
                if (facets[i].functionSelectors[j] == _functionSelector) {
                    return facets[i].facetAddress;
                }
            }
        }
    }

    event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);

    /// @notice Emits the cut events that would be emitted if this was actually a diamond
    function _emitDiamondCutEvent() internal returns (bool) {
        FacetCut[] memory cuts = new FacetCut[](4);
        cuts[0] = FacetCut(_CONFIGURATION_MODULE, FacetCutAction.Add, _facetFunctionSelectors(_CONFIGURATION_MODULE));
        cuts[1] = FacetCut(_VAULT_MODULE, FacetCutAction.Add, _facetFunctionSelectors(_VAULT_MODULE));
        cuts[2] = FacetCut(_STRATEGY_MODULE, FacetCutAction.Add, _facetFunctionSelectors(_STRATEGY_MODULE));
        cuts[3] = FacetCut(_MIGRATION_MODULE, FacetCutAction.Add, _facetFunctionSelectors(_MIGRATION_MODULE));
        emit DiamondCut(cuts, address(0), new bytes(0));
        return true;
    }
}
"
    }
  },
  "settings": {
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "paris"
  }
}}

Tags:
Proxy, Upgradeable, Factory|addr:0x0dbee96b7d98bedd1c4561722bf30d939a6c3905|verified:true|block:23577919|tx:0x770fdfc9979710e439a8ea57a424effebfcbf6dcbab635090fbd1f4bc955ee95|first_check:1760512069

Submitted on: 2025-10-15 09:07:50

Comments

Log in to comment.

No comments yet.