Skip to content

✨ 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
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions contracts/factory/ClaimIssuerFactory.sol
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

View workflow job for this annotation

GitHub Actions / Lint (16.x)

imported name Identity is not used

Check warning on line 8 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

imported name ClaimIssuer is not used
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;

Check failure on line 22 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Function order is incorrect, state variable declaration can not go after event definition (line 20)
mapping(address => address) public deployedClaimIssuers;
Copy link
Contributor

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

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());

Check warning on line 53 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Use Custom Errors instead of require statements
require(!blacklistedAddresses[msg.sender], Errors.Blacklisted(msg.sender));

Check warning on line 54 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Use Custom Errors instead of require statements
require(deployedClaimIssuers[managementKey] == address(0), Errors.ClaimIssuerAlreadyDeployed(managementKey));

Check warning on line 55 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Use Custom Errors instead of require statements

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());

Check warning on line 84 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Use Custom Errors instead of require statements
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());

Check warning on line 94 in contracts/factory/ClaimIssuerFactory.sol

View workflow job for this annotation

GitHub Actions / Lint (16.x)

Use Custom Errors instead of require statements

address oldImplementation = implementation;
implementation = newImplementation;
emit ImplementationUpdated(oldImplementation, newImplementation);
}

}

8 changes: 8 additions & 0 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,12 @@ library Errors {
/// @notice The claim is invalid.
error InvalidClaim();

/* ----- ClaimIssuerFactory ----- */

/// @notice The claim issuer already exists.
error ClaimIssuerAlreadyDeployed(address managementKey);

/// @notice The address is blacklisted.
error Blacklisted(address addr);

}
Loading
Loading