forked from Open-Attestation/token-registry
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move title escrow into deployer (Open-Attestation#101)
- Loading branch information
Showing
9 changed files
with
135 additions
and
98 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
contract TDocDeployer is OwnableUpgradeable, UUPSUpgradeable { | ||
event Deployment( | ||
address indexed deployed, | ||
address indexed implementation, | ||
address indexed deployer, | ||
address titleEscrowFactory, | ||
bytes params | ||
); | ||
|
||
// mapping: implementation => title escrow factory | ||
mapping(address => address) public implementations; | ||
|
||
constructor() initializer {} | ||
|
||
function initialize() external initializer { | ||
__Ownable_init(); | ||
} | ||
|
||
function _authorizeUpgrade(address) internal view override onlyOwner {} | ||
|
||
function deploy(address implementation, bytes memory params) external returns (address) { | ||
address titleEscrowFactory = implementations[implementation]; | ||
require(titleEscrowFactory != address(0), "TDocDeployer: Not whitelisted"); | ||
|
||
address deployed = ClonesUpgradeable.clone(implementation); | ||
bytes memory payload = abi.encodeWithSignature("initialize(bytes)", abi.encode(params, titleEscrowFactory)); | ||
(bool success, ) = address(deployed).call(payload); | ||
require(success, "TDocDeployer: Init fail"); | ||
|
||
emit Deployment(deployed, implementation, msg.sender, titleEscrowFactory, params); | ||
return deployed; | ||
} | ||
|
||
function addImplementation(address implementation, address titleEscrowFactory) external onlyOwner { | ||
require(implementations[implementation] == address(0), "TDocDeployer: Already added"); | ||
implementations[implementation] = titleEscrowFactory; | ||
} | ||
|
||
function removeImplementation(address implementation) external onlyOwner { | ||
require(implementations[implementation] != address(0), "TDocDeployer: Invalid implementation"); | ||
delete implementations[implementation]; | ||
} | ||
} |
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
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
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
Oops, something went wrong.