{"compiler":{"version":"0.8.17+commit.8df45f5f"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"address","name":"registry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"poolAddress","type":"address"}],"name":"PoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"registry","type":"address"}],"name":"RegistryUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"baseToken","type":"address"}],"name":"createPool","outputs":[{"internalType":"address","name":"newPoolAddress","type":"address"},{"internalType":"bytes32","name":"poolId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parameters","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"bytes8","name":"symbol","type":"bytes8"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"baseToken","type":"address"}],"internalType":"struct IRigoblockPoolProxyFactory.Parameters","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"setImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newRegistry","type":"address"}],"name":"setRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"author":"Gabriele Rigo - <gab@rigoblock.com>","kind":"dev","methods":{"createPool(string,string,address)":{"params":{"baseToken":"Address of the base token.","name":"String of the name.","symbol":"String of the symbol."},"returns":{"newPoolAddress":"Address of the new pool.","poolId":"Id of the new pool."}},"getRegistry()":{"returns":{"_0":"Address of the registry."}},"parameters()":{"returns":{"_0":"Tuple of the pool parameters."}},"setImplementation(address)":{"params":{"newImplementation":"Address of the new implementation contract."}},"setRegistry(address)":{"params":{"newRegistry":"Address of the new registry."}}},"stateVariables":{"implementation":{"return":"Address of the implementation.","returns":{"_0":"Address of the implementation."}}},"title":"Rigoblock Pool Proxy Factory contract - allows creation of new Rigoblock pools.","version":1},"userdoc":{"events":{"PoolCreated(address)":{"notice":"Emitted when a new pool is created."},"RegistryUpgraded(address)":{"notice":"Emitted when registry address is upgraded by the Rigoblock Dao."},"Upgraded(address)":{"notice":"Emitted when a new implementation is set by the Rigoblock Dao."}},"kind":"user","methods":{"createPool(string,string,address)":{"notice":"Creates a new Rigoblock pool."},"getRegistry()":{"notice":"Returns the address of the pool registry."},"implementation()":{"notice":"Returns the implementation address for the pool proxies."},"parameters()":{"notice":"Returns the pool initialization parameters at proxy deploy."},"setImplementation(address)":{"notice":"Allows Rigoblock Dao to update factory pool implementation."},"setRegistry(address)":{"notice":"Allows owner to update the registry."}},"version":1}},"settings":{"compilationTarget":{"contracts/protocol/proxies/RigoblockPoolProxyFactory.sol":"RigoblockPoolProxyFactory"},"evmVersion":"london","libraries":{},"metadata":{"bytecodeHash":"ipfs","useLiteralContent":true},"optimizer":{"enabled":true,"runs":200},"remappings":[]},"sources":{"contracts/protocol/interfaces/IPoolRegistry.sol":{"content":"// SPDX-License-Identifier: Apache 2.0\n/*\n\n Copyright 2017-2022 RigoBlock, Rigo Investment Sagl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity >=0.7.0 <0.9.0;\n\n/// @title Pool Registry Interface - Allows external interaction with pool registry.\n/// @author Gabriele Rigo - <gab@rigoblock.com>\n// solhint-disable-next-line\ninterface IPoolRegistry {\n    /// @notice Mapping of pool meta by pool key.\n    /// @param meta Mapping of bytes32 key to bytes32 meta.\n    struct PoolMeta {\n        mapping(bytes32 => bytes32) meta;\n    }\n\n    /// @notice Emitted when Rigoblock Dao updates authority address.\n    /// @param authority Address of the new authority contract.\n    event AuthorityChanged(address indexed authority);\n\n    /// @notice Emitted when pool owner updates meta data for its pool.\n    /// @param pool Address of the pool.\n    /// @param key Bytes32 key for indexing.\n    /// @param value Bytes32 of the value associated with the key.\n    event MetaChanged(address indexed pool, bytes32 indexed key, bytes32 value);\n\n    /// @notice Emitted when a new pool is registered in registry.\n    /// @param group Address of the pool factory.\n    /// @param pool Address of the registered pool.\n    /// @param name String name of the pool.\n    /// @param symbol String name of the pool.\n    /// @param id Bytes32 id of the pool.\n    event Registered(\n        address indexed group,\n        address pool,\n        bytes32 indexed name, // client can prune sybil pools\n        bytes32 indexed symbol,\n        bytes32 id\n    );\n\n    /// @notice Emitted when rigoblock Dao address is updated.\n    /// @param rigoblockDao New Dao address.\n    event RigoblockDaoChanged(address indexed rigoblockDao);\n\n    /// @notice Returns the address of the Rigoblock authority contract.\n    /// @return Address of the authority contract.\n    function authority() external view returns (address);\n\n    /// @notice Returns the address of the Rigoblock Dao.\n    /// @return Address of the Rigoblock Dao.\n    function rigoblockDao() external view returns (address);\n\n    /// @notice Allows a factory which is an authority to register a pool.\n    /// @param pool Address of the pool.\n    /// @param name String name of the pool (31 characters/bytes or less).\n    /// @param symbol String symbol of the pool (3 to 5 characters/bytes).\n    /// @param poolId Bytes32 of the pool id.\n    function register(\n        address pool,\n        string calldata name,\n        string calldata symbol,\n        bytes32 poolId\n    ) external;\n\n    /// @notice Allows Rigoblock governance to update authority.\n    /// @param authority Address of the authority contract.\n    function setAuthority(address authority) external;\n\n    /// @notice Allows pool owner to set metadata for a pool.\n    /// @param pool Address of the pool.\n    /// @param key Bytes32 of the key.\n    /// @param value Bytes32 of the value.\n    function setMeta(\n        address pool,\n        bytes32 key,\n        bytes32 value\n    ) external;\n\n    /// @notice Allows Rigoblock Dao to update its address.\n    /// @dev Creates internal record.\n    /// @param newRigoblockDao Address of the Rigoblock Dao.\n    function setRigoblockDao(address newRigoblockDao) external;\n\n    /// @notice Returns metadata for a given pool.\n    /// @param pool Address of the pool.\n    /// @param key Bytes32 key.\n    /// @return poolMeta Meta by key.\n    function getMeta(address pool, bytes32 key) external view returns (bytes32 poolMeta);\n\n    /// @notice Returns the id of a pool from its address.\n    /// @param pool Address of the pool.\n    /// @return poolId bytes32 id of the pool.\n    function getPoolIdFromAddress(address pool) external view returns (bytes32 poolId);\n}\n","keccak256":"0x0da90f76eb6898effb3ed0409b3cd0c4153762a1ceff2731c536a8bfa19f2290","license":"Apache 2.0"},"contracts/protocol/interfaces/IRigoblockPoolProxy.sol":{"content":"// SPDX-License-Identifier: Apache-2.0-or-later\npragma solidity >=0.8.0 <0.9.0;\n\ninterface IRigoblockPoolProxy {\n    /// @notice Emitted when implementation written to proxy storage.\n    /// @dev Emitted also at first variable initialization.\n    /// @param newImplementation Address of the new implementation.\n    event Upgraded(address indexed newImplementation);\n}\n","keccak256":"0x07b9f6262233bbed8996756842245810757ddc3040848f4fad3fdc801334a6a9","license":"Apache-2.0-or-later"},"contracts/protocol/interfaces/IRigoblockPoolProxyFactory.sol":{"content":"// SPDX-License-Identifier: Apache-2.0-or-later\n/*\n\n Copyright 2017-2022 RigoBlock, Rigo Investment Sagl, Rigo Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity >=0.8.0 <0.9.0;\n\n/// @title Pool Proxy Factory Interface - Allows external interaction with Pool Proxy Factory.\n/// @author Gabriele Rigo - <gab@rigoblock.com>\n// solhint-disable-next-line\ninterface IRigoblockPoolProxyFactory {\n    /// @notice Emitted when a new pool is created.\n    /// @param poolAddress Address of the new pool.\n    event PoolCreated(address poolAddress);\n\n    /// @notice Emitted when a new implementation is set by the Rigoblock Dao.\n    /// @param implementation Address of the new implementation.\n    event Upgraded(address indexed implementation);\n\n    /// @notice Emitted when registry address is upgraded by the Rigoblock Dao.\n    /// @param registry Address of the new registry.\n    event RegistryUpgraded(address indexed registry);\n\n    /// @notice Returns the implementation address for the pool proxies.\n    /// @return Address of the implementation.\n    function implementation() external view returns (address);\n\n    /// @notice Creates a new Rigoblock pool.\n    /// @param name String of the name.\n    /// @param symbol String of the symbol.\n    /// @param baseToken Address of the base token.\n    /// @return newPoolAddress Address of the new pool.\n    /// @return poolId Id of the new pool.\n    function createPool(\n        string calldata name,\n        string calldata symbol,\n        address baseToken\n    ) external returns (address newPoolAddress, bytes32 poolId);\n\n    /// @notice Allows Rigoblock Dao to update factory pool implementation.\n    /// @param newImplementation Address of the new implementation contract.\n    function setImplementation(address newImplementation) external;\n\n    /// @notice Allows owner to update the registry.\n    /// @param newRegistry Address of the new registry.\n    function setRegistry(address newRegistry) external;\n\n    /// @notice Returns the address of the pool registry.\n    /// @return Address of the registry.\n    function getRegistry() external view returns (address);\n\n    /// @notice Pool initialization parameters.\n    /// @params name String of the name (max 31 characters).\n    /// @params symbol bytes8 symbol.\n    /// @params owner Address of the owner.\n    /// @params baseToken Address of the base token.\n    struct Parameters {\n        string name;\n        bytes8 symbol;\n        address owner;\n        address baseToken;\n    }\n\n    /// @notice Returns the pool initialization parameters at proxy deploy.\n    /// @return Tuple of the pool parameters.\n    function parameters() external view returns (Parameters memory);\n}\n","keccak256":"0x2b6dd6e20084094bf470798200415c5195cfbf9d2d744e318d2bd08bfb071a1a","license":"Apache-2.0-or-later"},"contracts/protocol/proxies/RigoblockPoolProxy.sol":{"content":"// SPDX-License-Identifier: Apache-2.0-or-later\n/*\n\n Copyright 2022 Rigo Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity >=0.8.0 <0.9.0;\n\nimport \"../interfaces/IRigoblockPoolProxy.sol\";\nimport \"../interfaces/IRigoblockPoolProxyFactory.sol\";\n\n/// @title RigoblockPoolProxy - Proxy contract forwards calls to the implementation address returned by the admin.\n/// @author Gabriele Rigo - <gab@rigoblock.com>\ncontract RigoblockPoolProxy is IRigoblockPoolProxy {\n    // implementation slot is used to store implementation address, a contract which implements the pool logic.\n    // Reduced deployment cost by using internal variable.\n    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n    /// @notice Sets address of implementation contract.\n    constructor() payable {\n        // store implementation address in implementation slot value\n        assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256(\"eip1967.proxy.implementation\")) - 1));\n        address implementation = IRigoblockPoolProxyFactory(msg.sender).implementation();\n        getImplementation().implementation = implementation;\n        emit Upgraded(implementation);\n\n        // initialize pool\n        // abi.encodeWithSelector(IRigoblockPool.initializePool.selector)\n        (, bytes memory returnData) = implementation.delegatecall(abi.encodeWithSelector(0x250e6de0));\n\n        // we must assert initialization didn't fail, otherwise it could fail silently and still deploy the pool.\n        require(returnData.length == 0, \"POOL_INITIALIZATION_FAILED_ERROR\");\n    }\n\n    /* solhint-disable no-complex-fallback */\n    /// @notice Fallback function forwards all transactions and returns all received return data.\n    fallback() external payable {\n        address implementation = getImplementation().implementation;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            calldatacopy(0, 0, calldatasize())\n            let success := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n            returndatacopy(0, 0, returndatasize())\n            if eq(success, 0) {\n                revert(0, returndatasize())\n            }\n            return(0, returndatasize())\n        }\n    }\n\n    /* solhint-enable no-complex-fallback */\n\n    /// @notice Implementation slot is accessed directly.\n    /// @dev Saves gas compared to using storage slot library.\n    /// @param implementation Address of the implementation.\n    struct ImplementationSlot {\n        address implementation;\n    }\n\n    /// @notice Method to read/write from/to implementation slot.\n    /// @return s Storage slot of the pool implementation.\n    function getImplementation() private pure returns (ImplementationSlot storage s) {\n        assembly {\n            s.slot := _IMPLEMENTATION_SLOT\n        }\n    }\n}\n","keccak256":"0x945fa529879c706c24ec8606d43e185a212c807c6f11151023919184042096c5","license":"Apache-2.0-or-later"},"contracts/protocol/proxies/RigoblockPoolProxyFactory.sol":{"content":"// SPDX-License-Identifier: Apache-2.0-or-later\n/*\n\n Copyright 2022 Rigo Intl.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\npragma solidity 0.8.17;\n\nimport \"./RigoblockPoolProxy.sol\";\nimport {IPoolRegistry as PoolRegistry} from \"../interfaces/IPoolRegistry.sol\";\nimport \"../interfaces/IRigoblockPoolProxyFactory.sol\";\n\n/// @title Rigoblock Pool Proxy Factory contract - allows creation of new Rigoblock pools.\n/// @author Gabriele Rigo - <gab@rigoblock.com>\n// solhint-disable-next-line\ncontract RigoblockPoolProxyFactory is IRigoblockPoolProxyFactory {\n    /// @inheritdoc IRigoblockPoolProxyFactory\n    address public override implementation;\n\n    address private _registry;\n\n    Parameters private _parameters;\n\n    modifier onlyRigoblockDao() {\n        require(PoolRegistry(getRegistry()).rigoblockDao() == msg.sender, \"FACTORY_CALLER_NOT_DAO_ERROR\");\n        _;\n    }\n\n    constructor(address newImplementation, address registry) {\n        implementation = newImplementation;\n        _registry = registry;\n    }\n\n    /*\n     * PUBLIC FUNCTIONS\n     */\n    /// @inheritdoc IRigoblockPoolProxyFactory\n    function createPool(\n        string calldata name,\n        string calldata symbol,\n        address baseToken\n    ) external override returns (address newPoolAddress, bytes32 poolId) {\n        (bytes32 newPoolId, RigoblockPoolProxy proxy) = _createPool(name, symbol, baseToken);\n        newPoolAddress = address(proxy);\n        poolId = newPoolId;\n        try PoolRegistry(getRegistry()).register(newPoolAddress, name, symbol, poolId) {\n            emit PoolCreated(newPoolAddress);\n        } catch Error(string memory reason) {\n            revert(reason);\n        } catch (bytes memory returnData) {\n            revert(string(returnData));\n        }\n    }\n\n    /// @inheritdoc IRigoblockPoolProxyFactory\n    function setImplementation(address newImplementation) external override onlyRigoblockDao {\n        require(newImplementation != implementation, \"FACTORY_SAME_INPUT_ADDRESS_ERROR\");\n        require(_isContract(newImplementation), \"FACTORY_NEW_IMPLEMENTATION_NOT_CONTRACT_ERROR\");\n        implementation = newImplementation;\n        emit Upgraded(newImplementation);\n    }\n\n    /// @inheritdoc IRigoblockPoolProxyFactory\n    function setRegistry(address newRegistry) external override onlyRigoblockDao {\n        require(newRegistry != getRegistry(), \"FACTORY_SAME_INPUT_ADDRESS_ERROR\");\n        require(_isContract(newRegistry), \"FACTORY_NEW_REGISTRY_NOT_CONTRACT_ERROR\");\n        _registry = newRegistry;\n        emit RegistryUpgraded(newRegistry);\n    }\n\n    /// @notice Returns the pool initialization parameters at proxy deploy.\n    /// @return Tuple of the pool parameters.\n    function parameters() external view override returns (Parameters memory) {\n        return _parameters;\n    }\n\n    /*\n     * CONSTANT PUBLIC FUNCTIONS\n     */\n    /// @inheritdoc IRigoblockPoolProxyFactory\n    function getRegistry() public view override returns (address) {\n        return _registry;\n    }\n\n    /*\n     * INTERNAL FUNCTIONS\n     */\n    /// @dev Creates a pool and routes to eventful.\n    /// @param name String of the name.\n    /// @param  symbol String of the symbol.\n    /// @param  baseToken Address of the base token.\n    function _createPool(\n        string calldata name,\n        string calldata symbol,\n        address baseToken\n    ) internal returns (bytes32 salt, RigoblockPoolProxy newProxy) {\n        // we omit the encoding params in the constructor in order to guarantee same address for name and owner\n        salt = keccak256(abi.encode(name, msg.sender));\n\n        // we write to storage to allow proxy to read initialization parameters\n        _parameters = Parameters({name: name, symbol: bytes8(bytes(symbol)), owner: msg.sender, baseToken: baseToken});\n\n        // constructor is null to guarantee same create2 deployed address\n        try new RigoblockPoolProxy{salt: salt}() returns (RigoblockPoolProxy proxy) {\n            newProxy = proxy;\n        } catch Error(string memory revertReason) {\n            revert(revertReason);\n        } catch (bytes memory) {\n            revert(\"FACTORY_CREATE2_FAILED_ERROR\");\n        }\n\n        delete _parameters;\n    }\n\n    /// @dev Returns whether an address is a contract.\n    /// @return Bool target address has code.\n    function _isContract(address target) private view returns (bool) {\n        return target.code.length > 0;\n    }\n}\n","keccak256":"0xe546427d143db20b6ea651366cfe6cbd0092e9271e65c6fcc8828530ccfa6dd0","license":"Apache-2.0-or-later"}},"version":1}