|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: MIT |
| 3 | + * |
| 4 | + * Copyright (c) 2021-2022 Backed Finance AG |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +pragma solidity 0.8.9; |
| 26 | + |
| 27 | +import "@openzeppelin/contracts/access/Ownable.sol"; |
| 28 | +import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; |
| 29 | +import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 30 | +import "./WrappedBackedTokenImplementation.sol"; |
| 31 | + |
| 32 | +/** |
| 33 | + * @dev |
| 34 | + * TransparentUpgradeableProxy contract, renamed as WrappedBackedTokenProxy. |
| 35 | + */ |
| 36 | +contract WrappedBackedTokenProxy is TransparentUpgradeableProxy { |
| 37 | + constructor( |
| 38 | + address _logic, |
| 39 | + address admin_, |
| 40 | + bytes memory _data |
| 41 | + ) payable TransparentUpgradeableProxy(_logic, admin_, _data) {} |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * @dev |
| 46 | + * |
| 47 | + * Factory contract, used for creating new, upgradable wrapped tokens. |
| 48 | + * |
| 49 | + * The contract contains one role: |
| 50 | + * - An owner, which can deploy new tokens |
| 51 | + * |
| 52 | + */ |
| 53 | +contract WrappedBackedTokenFactory is Ownable { |
| 54 | + ProxyAdmin public immutable proxyAdmin; |
| 55 | + WrappedBackedTokenImplementation public wrappedTokenImplementation; |
| 56 | + |
| 57 | + event NewToken(address indexed newToken, string name, string symbol); |
| 58 | + event NewImplementation(address indexed newImplementation); |
| 59 | + |
| 60 | + /** |
| 61 | + * @param proxyAdminOwner The address of the account that will be set as owner of the deployed ProxyAdmin |
| 62 | + */ |
| 63 | + constructor(address proxyAdminOwner) { |
| 64 | + require( |
| 65 | + proxyAdminOwner != address(0), |
| 66 | + "Factory: address should not be 0" |
| 67 | + ); |
| 68 | + |
| 69 | + wrappedTokenImplementation = new WrappedBackedTokenImplementation(); |
| 70 | + proxyAdmin = new ProxyAdmin(); |
| 71 | + proxyAdmin.transferOwnership(proxyAdminOwner); |
| 72 | + } |
| 73 | + |
| 74 | + struct TokenDeploymentConfiguration { |
| 75 | + string name; // The name that the newly created token will have |
| 76 | + string symbol; // The symbol that the newly created token will have |
| 77 | + address underlying; // The address of the wrapped token underlying |
| 78 | + address tokenOwner; // The address of the account to which the owner role will be assigned |
| 79 | + address pauser; // The address of the account to which the pauser role will be assigned |
| 80 | + address sanctionsList; // The address of sanctions list contract |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @dev Deploy and configures new instance of Wrapped BackedFi Token. Callable only by the factory owner |
| 85 | + * |
| 86 | + * Emits a { NewToken } event |
| 87 | + * |
| 88 | + * @param configuration Configuration structure for token deployment |
| 89 | + */ |
| 90 | + function deployToken( |
| 91 | + TokenDeploymentConfiguration calldata configuration |
| 92 | + ) external onlyOwner returns (address) { |
| 93 | + require( |
| 94 | + configuration.tokenOwner != address(0) && |
| 95 | + configuration.underlying != address(0) && |
| 96 | + configuration.pauser != address(0), |
| 97 | + "Factory: address should not be 0" |
| 98 | + ); |
| 99 | + |
| 100 | + bytes32 salt = keccak256( |
| 101 | + abi.encodePacked(configuration.name, configuration.symbol) |
| 102 | + ); |
| 103 | + |
| 104 | + WrappedBackedTokenProxy newProxy = new WrappedBackedTokenProxy{salt: salt}( |
| 105 | + address(wrappedTokenImplementation), |
| 106 | + address(proxyAdmin), |
| 107 | + abi.encodeWithSelector( |
| 108 | + bytes4( |
| 109 | + keccak256( |
| 110 | + "initialize(string,string,address)" |
| 111 | + ) |
| 112 | + ), |
| 113 | + configuration.name, |
| 114 | + configuration.symbol, |
| 115 | + configuration.underlying |
| 116 | + ) |
| 117 | + ); |
| 118 | + |
| 119 | + WrappedBackedTokenImplementation newToken = WrappedBackedTokenImplementation( |
| 120 | + address(newProxy) |
| 121 | + ); |
| 122 | + |
| 123 | + newToken.setPauser(configuration.pauser); |
| 124 | + newToken.setSanctionsList(configuration.sanctionsList); |
| 125 | + newToken.transferOwnership(configuration.tokenOwner); |
| 126 | + |
| 127 | + emit NewToken( |
| 128 | + address(newToken), |
| 129 | + configuration.name, |
| 130 | + configuration.symbol |
| 131 | + ); |
| 132 | + |
| 133 | + return (address(newToken)); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @dev Update the implementation for future deployments |
| 138 | + * |
| 139 | + * Emits a { NewImplementation } event |
| 140 | + * |
| 141 | + * @param newImplementation address of the new implementation |
| 142 | + */ |
| 143 | + function updateImplementation( |
| 144 | + address newImplementation |
| 145 | + ) external onlyOwner { |
| 146 | + require( |
| 147 | + newImplementation != address(0), |
| 148 | + "Factory: address should not be 0" |
| 149 | + ); |
| 150 | + |
| 151 | + wrappedTokenImplementation = WrappedBackedTokenImplementation( |
| 152 | + newImplementation |
| 153 | + ); |
| 154 | + |
| 155 | + emit NewImplementation(newImplementation); |
| 156 | + } |
| 157 | +} |
0 commit comments