-
Notifications
You must be signed in to change notification settings - Fork 45
✨ ClaimIssuer factory #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pgonday
wants to merge
2
commits into
develop
Choose a base branch
from
claimissuer-factory
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.27; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
import { CREATE3 } from "solady/src/utils/CREATE3.sol"; | ||
|
||
import { ClaimIssuer, Identity } from "../ClaimIssuer.sol"; | ||
Check warning on line 8 in contracts/factory/ClaimIssuerFactory.sol
|
||
import { Errors } from "../libraries/Errors.sol"; | ||
|
||
contract ClaimIssuerFactory is Ownable { | ||
|
||
/// @notice Event emitted when a new ClaimIssuer is deployed | ||
event ClaimIssuerDeployed(address indexed managementKey, address indexed claimIssuer); | ||
|
||
/// @notice Event emitted when an address is blacklisted | ||
event Blacklisted(address indexed addr, bool blacklisted); | ||
|
||
/// @notice Event emitted when the implementation is updated | ||
event ImplementationUpdated(address indexed oldImplementation, address indexed newImplementation); | ||
|
||
address public implementation; | ||
mapping(address => address) public deployedClaimIssuers; | ||
mapping(address => bool) public blacklistedAddresses; | ||
|
||
constructor(address _implementation) Ownable() { | ||
implementation = _implementation; | ||
} | ||
|
||
/** | ||
* @dev Deploys a new ClaimIssuer contract using CREATE2 | ||
* @return The address of the deployed ClaimIssuer contract | ||
*/ | ||
function deployClaimIssuer() external returns (address) { | ||
return _deployClaimIssuer(msg.sender); | ||
} | ||
|
||
/** | ||
* @dev Deploys a ClaimIssuer on behalf of a management key (owner only) | ||
* @param managementKey The initial management key for the ClaimIssuer | ||
* @return The address of the deployed ClaimIssuer contract | ||
*/ | ||
function deployClaimIssuerOnBehalf(address managementKey) external onlyOwner returns (address) { | ||
return _deployClaimIssuer(managementKey); | ||
} | ||
|
||
/** | ||
* @dev Deploys a new ClaimIssuer contract using CREATE2 | ||
* @param managementKey The initial management key for the ClaimIssuer | ||
* @return The address of the deployed ClaimIssuer contract | ||
*/ | ||
function _deployClaimIssuer(address managementKey) internal returns (address) { | ||
require(managementKey != address(0), Errors.ZeroAddress()); | ||
require(!blacklistedAddresses[msg.sender], Errors.Blacklisted(msg.sender)); | ||
require(deployedClaimIssuers[managementKey] == address(0), Errors.ClaimIssuerAlreadyDeployed(managementKey)); | ||
|
||
address claimIssuer = CREATE3.deployDeterministic( | ||
abi.encodePacked( | ||
type(TransparentUpgradeableProxy).creationCode, | ||
// TransparentUpgradeableProxy constructor arguments: | ||
// - implementation address | ||
// - admin address | ||
// - data: call initialize(managementKey) | ||
abi.encode( | ||
implementation, | ||
owner(), | ||
abi.encodeWithSelector(bytes4(keccak256("initialize(address)")), managementKey) | ||
) | ||
), | ||
bytes32(uint256(uint160(managementKey))) | ||
); | ||
|
||
deployedClaimIssuers[managementKey] = claimIssuer; | ||
emit ClaimIssuerDeployed(managementKey, claimIssuer); | ||
|
||
return claimIssuer; | ||
} | ||
|
||
/** | ||
* @dev Blacklists an address from deploying ClaimIssuers | ||
* @param addr The address to blacklist | ||
*/ | ||
function blacklistAddress(address addr, bool blacklisted) external onlyOwner { | ||
require(addr != address(0), Errors.ZeroAddress()); | ||
blacklistedAddresses[addr] = blacklisted; | ||
emit Blacklisted(addr, blacklisted); | ||
} | ||
|
||
/** | ||
* @dev Updates the implementation address | ||
* @param newImplementation The new implementation address | ||
*/ | ||
function updateImplementation(address newImplementation) external onlyOwner { | ||
require(newImplementation != address(0), Errors.ZeroAddress()); | ||
|
||
address oldImplementation = implementation; | ||
implementation = newImplementation; | ||
emit ImplementationUpdated(oldImplementation, newImplementation); | ||
} | ||
|
||
} | ||
|
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint issue here to correct about order of functions, other than that the contract looks good