-
-
Save OxideDall/7546ebd40500f5a8125ea8e9f52ea40e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.17; | |
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; | |
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | |
contract Implementation is Initializable { | |
address internal weth; | |
constructor() { | |
_disableInitializers(); | |
} | |
function init(address _weth) external initializer { | |
weth = _weth; | |
} | |
} | |
contract ProxyFactory { | |
error ZeroAdmin(); | |
error Unauthorized(); | |
event NewProxy(address proxy, address implementation); | |
address immutable admin; | |
constructor(address _admin) { | |
if (_admin == address(0)) revert ZeroAdmin(); | |
admin = _admin; | |
} | |
function createProxy(IWETH _weth, address _proxyAdmin) external { | |
if (msg.sender != admin) revert Unauthorized(); | |
address firstImpl = address(new Implementation()); | |
bytes memory proxyInitCalldata = abi.encodeCall( | |
Implementation.init, | |
(_weth) | |
); | |
address proxy = address( | |
new TransparentUpgradeableProxy( | |
firstImpl, | |
_proxyAdmin, | |
proxyInitCalldata | |
) | |
); | |
emit NewProxy(proxy, firstImpl); | |
} | |
} | |
contract ProxyFactoryDeployer { | |
error AlreadyDeployed(); | |
address constant SAFE_SINGLETON_FACTORY = | |
0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7; | |
bytes32 constant SALT = keccak256("<custom-salt>"); | |
address public immutable factoryAddress; | |
address constant ADMIN = <multichain proxy admin address>; | |
constructor() { | |
(bool success, bytes memory result) = SAFE_SINGLETON_FACTORY.call( | |
abi.encodePacked( | |
SALT, | |
type(ProxyFactory).creationCode, | |
abi.encode(ADMIN) | |
) | |
); | |
if (!success) { | |
revert AlreadyDeployed(); | |
} | |
factoryAddress = address(bytes20(result)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment