Verified contractExactBUSL-1.1
ManagementRequestLibrary
Address0x1f5a2885c2d5670c75f7c4a03fd1ef8a1bc4befe
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.22
- Same code
1 more contract
Details
- Compiler
- solc 0.8.22+commit.4fc1097e
- Language
- solidity
- Optimization
- Yes, 1,000,000 runs
- EVM version
- paris
- License
- BUSL-1.1
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,377,652
- Creation transaction
- 0xe8b8c2d74e…422cfc6019
18 files
- contracts/multisig/libraries/ManagementRequestLibrary.solmain32.57 KB
- @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol8.91 KB
- @openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol1.18 KB
- @openzeppelin/contracts/access/AccessControl.sol7.05 KB
- @openzeppelin/contracts/access/IAccessControl.sol3.26 KB
- @openzeppelin/contracts/access/Ownable.sol3.1 KB
- @openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol2.69 KB
- @openzeppelin/contracts/access/extensions/IAccessControlEnumerable.sol1.28 KB
- @openzeppelin/contracts/utils/Context.sol860 B
- @openzeppelin/contracts/utils/introspection/ERC165.sol911 B
- @openzeppelin/contracts/utils/introspection/IERC165.sol869 B
- @openzeppelin/contracts/utils/structs/EnumerableSet.sol12.97 KB
- contracts/interfaces/base/IERC165Extended.sol1.18 KB
- contracts/interfaces/compiler/ILiquidityPoolsController.sol5.34 KB
- contracts/interfaces/compliance/IWhitelistingController.sol11.3 KB
- contracts/interfaces/compliance/IWhitelistingControllerAgreement.sol4.37 KB
- contracts/interfaces/diamond/IDiamondCut.sol868 B
- contracts/interfaces/multisig/IUpgradeMultisig.sol23.59 KB
contracts/multisig/libraries/ManagementRequestLibrary.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
import {
AccessControlEnumerable
} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IUpgradeMultisig} from "contracts/interfaces/multisig/IUpgradeMultisig.sol";
/**
* @title ManagementRequestLibrary
* @notice Library for submitting, validating, and executing management requests
*/
library ManagementRequestLibrary {
struct RequestSubmissionResult {
bytes32 requestId;
uint80 newNonce;
bytes32 newPendingRequestId;
}
struct ExecutionResult {
uint80 newLastExecutedNonce;
bytes32 newPendingRequestId;
uint8 newThreshold;
uint128 newTimelockDuration;
}
bytes32 public constant UPGRADE_PROPOSAL_OFFICER_ROLE =
keccak256("Upgrade Proposal Officer Role");
bytes32 public constant UPGRADE_APPROVAL_OFFICER_ROLE =
keccak256("Upgrade Approval Officer Role");
bytes32 public constant ARKIS_SECURITY_OFFICER_ROLE = keccak256("Arkis Security Officer Role");
uint128 public constant MIN_TIMELOCK_DURATION = 1 hours;
uint128 public constant MAX_TIMELOCK_DURATION = 30 days;
uint256 public constant MIN_OPERATORS = 2;
/**
* @notice Execute a management request
*/
function execute(
IUpgradeMultisig.ManagementRequest storage request,
bytes32 pendingManagementRequestId,
uint80 lastExecutedNonce,
uint8 threshold,
uint128 timelockDuration
) external returns (ExecutionResult memory result) {
if (request.status == IUpgradeMultisig.Status.Rejected) {
revert IUpgradeMultisig.CannotExecuteRejectedManagementRequest();
}
// Nonce ordering is enforced again at execution time.
// Allow the special case of the first execution where both nonces are 0.
// However, we keep a safety check for the first execution case
// solhint-disable-next-line no-empty-blocks
if (lastExecutedNonce == 0 && request.nonce == 0) {
// First execution - allow nonce 0
} else if (request.nonce != lastExecutedNonce + 1) {
revert IUpgradeMultisig.ManagementRequestOutOfOrder(
lastExecutedNonce + 1,
request.nonce
);
}
request.status = IUpgradeMultisig.Status.Executed;
result.newLastExecutedNonce = request.nonce;
if (pendingManagementRequestId == request.requestId) {
result.newPendingRequestId = bytes32(0);
} else {
result.newPendingRequestId = pendingManagementRequestId;
}
result.newThreshold = threshold;
result.newTimelockDuration = timelockDuration;
}
/**
* @notice Emit the appropriate event for a management request submission
*/
function emitRequestSubmitted(
IUpgradeMultisig.ManagementRequestType requestType,
bytes32 requestId,
bytes calldata requestData,
address submitter
) external {
if (requestType == IUpgradeMultisig.ManagementRequestType.AddApprover) {
address _approver = abi.decode(requestData, (address));
emit IUpgradeMultisig.AddApproverRequestSubmitted(
requestId,
submitter,
_approver,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveApprover) {
address _approver = abi.decode(requestData, (address));
emit IUpgradeMultisig.RemoveApproverRequestSubmitted(
requestId,
submitter,
_approver,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.ChangeThreshold) {
uint8 _newThreshold = abi.decode(requestData, (uint8));
emit IUpgradeMultisig.ChangeThresholdRequestSubmitted(
requestId,
submitter,
_newThreshold,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.AddOperator) {
address _operator = abi.decode(requestData, (address));
emit IUpgradeMultisig.AddOperatorRequestSubmitted(
requestId,
submitter,
_operator,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveOperator) {
address _operator = abi.decode(requestData, (address));
emit IUpgradeMultisig.RemoveOperatorRequestSubmitted(
requestId,
submitter,
_operator,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.ChangeTimelock) {
uint128 _newTimelockDuration = abi.decode(requestData, (uint128));
emit IUpgradeMultisig.ChangeTimelockRequestSubmitted(
requestId,
submitter,
_newTimelockDuration,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.AddSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
emit IUpgradeMultisig.AddSecurityOfficerRequestSubmitted(
requestId,
submitter,
_securityOfficer,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
emit IUpgradeMultisig.RemoveSecurityOfficerRequestSubmitted(
requestId,
submitter,
_securityOfficer,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RenounceOwnership) {
address _targetContract = abi.decode(requestData, (address));
emit IUpgradeMultisig.RenounceOwnershipRequestSubmitted(
requestId,
submitter,
_targetContract,
block.timestamp
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.TransferOwnership) {
(address[] memory _targetContracts, address _newOwner) = abi.decode(
requestData,
(address[], address)
);
emit IUpgradeMultisig.TransferOwnershipRequestSubmitted(
requestId,
submitter,
_newOwner,
_targetContracts,
block.timestamp
);
}
}
/**
* @notice Generic function to submit any type of management request
* @dev Routes to the appropriate specific function based on requestType
*/
function submitManagementRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
uint8 threshold,
IUpgradeMultisig.ManagementRequestType requestType,
bytes calldata requestData,
address multisigAddress,
AccessControlEnumerable accessControl
) external returns (RequestSubmissionResult memory result) {
if (requestType == IUpgradeMultisig.ManagementRequestType.AddApprover) {
address _approver = abi.decode(requestData, (address));
return submitAddApproverRequest(managementRequests, nonce, _approver, multisigAddress);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveApprover) {
address _approver = abi.decode(requestData, (address));
return
submitRemoveApproverRequest(
managementRequests,
nonce,
threshold,
_approver,
multisigAddress,
accessControl
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.ChangeThreshold) {
uint8 _newThreshold = abi.decode(requestData, (uint8));
return
submitChangeThresholdRequest(
managementRequests,
nonce,
_newThreshold,
multisigAddress,
accessControl
);
} else if (
requestType == IUpgradeMultisig.ManagementRequestType.AddOperator ||
requestType == IUpgradeMultisig.ManagementRequestType.RemoveOperator
) {
address _operator = abi.decode(requestData, (address));
return
submitOperatorRequest(
managementRequests,
nonce,
requestType,
_operator,
multisigAddress,
accessControl
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.ChangeTimelock) {
uint128 _newTimelockDuration = abi.decode(requestData, (uint128));
return
submitChangeTimelockRequest(
managementRequests,
nonce,
_newTimelockDuration,
multisigAddress
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.AddSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
return
submitAddSecurityOfficerRequest(
managementRequests,
nonce,
_securityOfficer,
multisigAddress
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
return
submitRemoveSecurityOfficerRequest(
managementRequests,
nonce,
_securityOfficer,
multisigAddress,
accessControl
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RenounceOwnership) {
address _targetContract = abi.decode(requestData, (address));
return
submitRenounceOwnershipRequest(
managementRequests,
nonce,
_targetContract,
multisigAddress
);
} else if (requestType == IUpgradeMultisig.ManagementRequestType.TransferOwnership) {
(address[] memory _targetContracts, address _newOwner) = abi.decode(
requestData,
(address[], address)
);
return
submitTransferOwnershipRequest(
managementRequests,
nonce,
_targetContracts,
_newOwner,
multisigAddress
);
} else {
revert IUpgradeMultisig.InvalidManagementRequestType();
}
}
/**
* @notice Validate management request based on type
*/
function validateRequest(
IUpgradeMultisig.ManagementRequestType requestType,
bytes calldata requestData,
AccessControlEnumerable accessControl
) external view {
if (requestType == IUpgradeMultisig.ManagementRequestType.AddApprover) {
address _approver = abi.decode(requestData, (address));
if (accessControl.hasRole(UPGRADE_APPROVAL_OFFICER_ROLE, _approver)) {
revert IUpgradeMultisig.ApproverAlreadyExists();
}
if (accessControl.hasRole(UPGRADE_PROPOSAL_OFFICER_ROLE, _approver)) {
revert IUpgradeMultisig.OperatorCannotBeApprover();
}
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveApprover) {
address _approver = abi.decode(requestData, (address));
if (!accessControl.hasRole(UPGRADE_APPROVAL_OFFICER_ROLE, _approver)) {
revert IUpgradeMultisig.ApproverDoesNotExist();
}
} else if (requestType == IUpgradeMultisig.ManagementRequestType.AddOperator) {
address _operator = abi.decode(requestData, (address));
if (accessControl.hasRole(UPGRADE_PROPOSAL_OFFICER_ROLE, _operator)) {
revert IUpgradeMultisig.OperatorAlreadyExists();
}
if (accessControl.hasRole(UPGRADE_APPROVAL_OFFICER_ROLE, _operator)) {
revert IUpgradeMultisig.ApproverCannotBeOperator();
}
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveOperator) {
address _operator = abi.decode(requestData, (address));
if (!accessControl.hasRole(UPGRADE_PROPOSAL_OFFICER_ROLE, _operator)) {
revert IUpgradeMultisig.OperatorDoesNotExist();
}
} else if (requestType == IUpgradeMultisig.ManagementRequestType.AddSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
if (_securityOfficer == address(accessControl)) {
revert IUpgradeMultisig.InvalidAddress();
}
if (accessControl.hasRole(ARKIS_SECURITY_OFFICER_ROLE, _securityOfficer)) {
revert IUpgradeMultisig.SecurityOfficerAlreadyExists();
}
} else if (requestType == IUpgradeMultisig.ManagementRequestType.RemoveSecurityOfficer) {
address _securityOfficer = abi.decode(requestData, (address));
if (!accessControl.hasRole(ARKIS_SECURITY_OFFICER_ROLE, _securityOfficer)) {
revert IUpgradeMultisig.SecurityOfficerDoesNotExist();
}
}
}
/**
* @notice Validate that a management request exists and can be approved
*/
function validateForApproval(IUpgradeMultisig.ManagementRequest storage request) external view {
if (request.requestId == bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestDoesNotExist();
}
if (request.status == IUpgradeMultisig.Status.Executed) {
revert IUpgradeMultisig.ManagementRequestAlreadyExecuted();
}
if (request.status == IUpgradeMultisig.Status.Rejected) {
revert IUpgradeMultisig.CannotApproveRejectedManagementRequest();
}
}
/**
* @notice Validate that a management request exists and can be rejected
*/
function validateForRejection(
IUpgradeMultisig.ManagementRequest storage request
) external view {
if (request.requestId == bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestDoesNotExist();
}
if (request.status == IUpgradeMultisig.Status.Executed) {
revert IUpgradeMultisig.ManagementRequestAlreadyExecuted();
}
if (request.status == IUpgradeMultisig.Status.Rejected) {
revert IUpgradeMultisig.ManagementRequestAlreadyRejected();
}
}
/**
* @notice Validate that a management request can be executed (timelock must have passed)
* @param request The management request to validate
* @param threshold The current approval threshold
* @param approvalCount The current number of approvals for the request
*/
function validateExecution(
IUpgradeMultisig.ManagementRequest storage request,
uint8 threshold,
uint256 approvalCount
) external view {
if (request.requestId == bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestDoesNotExist();
}
if (request.status == IUpgradeMultisig.Status.Executed) {
revert IUpgradeMultisig.ManagementRequestAlreadyExecuted();
} else if (request.status == IUpgradeMultisig.Status.Rejected) {
revert IUpgradeMultisig.CannotExecuteRejectedManagementRequest();
}
if (approvalCount < threshold) {
revert IUpgradeMultisig.InsufficientApprovals();
}
if (request.timelockStart == 0) {
revert IUpgradeMultisig.ManagementRequestNotReady();
}
uint256 timelockEnd = request.timelockStart + request.timelockDuration;
if (block.timestamp < timelockEnd) {
revert IUpgradeMultisig.TimelockNotPassed();
}
}
/**
* @notice Submit an add approver request
* @dev Internal function called by submitManagementRequest
*/
function submitAddApproverRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
address _approver,
address multisigAddress
) internal returns (RequestSubmissionResult memory result) {
if (_approver == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.AddApprover,
_approver
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.AddApprover;
request.nonce = nonce;
request.targetApprover = _approver;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a remove approver request
* @dev Internal function called by submitManagementRequest
*/
function submitRemoveApproverRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
uint8 threshold,
address _approver,
address multisigAddress,
AccessControlEnumerable accessControl
) internal returns (RequestSubmissionResult memory result) {
if (_approver == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
if (accessControl.getRoleMemberCount(UPGRADE_APPROVAL_OFFICER_ROLE) - 1 < threshold) {
revert IUpgradeMultisig.InsufficientApprovers();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.RemoveApprover,
_approver
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.RemoveApprover;
request.nonce = nonce;
request.targetApprover = _approver;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a change threshold request
* @dev Internal function called by submitManagementRequest
*/
function submitChangeThresholdRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
uint8 _newThreshold,
address multisigAddress,
AccessControlEnumerable accessControl
) internal returns (RequestSubmissionResult memory result) {
if (_newThreshold == 0) {
revert IUpgradeMultisig.InvalidThreshold();
}
if (_newThreshold > accessControl.getRoleMemberCount(UPGRADE_APPROVAL_OFFICER_ROLE)) {
revert IUpgradeMultisig.InsufficientApprovers();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.ChangeThreshold,
_newThreshold
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.ChangeThreshold;
request.nonce = nonce;
request.newThreshold = _newThreshold;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit an add or remove operator request
* @dev Internal function called by submitManagementRequest
* @dev A removal must leave at least MIN_OPERATORS, so a lost key can always be replaced by another
* operator: add the replacement first, then remove
*/
function submitOperatorRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
IUpgradeMultisig.ManagementRequestType requestType,
address _operator,
address multisigAddress,
AccessControlEnumerable accessControl
) internal returns (RequestSubmissionResult memory result) {
if (_operator == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
if (
requestType == IUpgradeMultisig.ManagementRequestType.RemoveOperator &&
accessControl.getRoleMemberCount(UPGRADE_PROPOSAL_OFFICER_ROLE) <= MIN_OPERATORS
) {
revert IUpgradeMultisig.InsufficientOperators();
}
result.requestId = keccak256(abi.encode(multisigAddress, nonce, requestType, _operator));
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = requestType;
request.nonce = nonce;
request.targetOperator = _operator;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a change timelock request
* @dev Internal function called by submitManagementRequest
*/
function submitChangeTimelockRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
uint128 _newTimelockDuration,
address multisigAddress
) internal returns (RequestSubmissionResult memory result) {
if (
_newTimelockDuration < MIN_TIMELOCK_DURATION ||
_newTimelockDuration > MAX_TIMELOCK_DURATION
) {
revert IUpgradeMultisig.InvalidTimelockDuration();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.ChangeTimelock,
_newTimelockDuration
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.ChangeTimelock;
request.nonce = nonce;
request.newTimelockDuration = _newTimelockDuration;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit an add security officer request
* @dev Internal function called by submitManagementRequest
*/
function submitAddSecurityOfficerRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
address _securityOfficer,
address multisigAddress
) internal returns (RequestSubmissionResult memory result) {
if (_securityOfficer == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.AddSecurityOfficer,
_securityOfficer
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.AddSecurityOfficer;
request.nonce = nonce;
request.targetApprover = _securityOfficer;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a remove security officer request
* @dev Internal function called by submitManagementRequest
* @dev Prevents removing the last security officer to maintain emergency rejection capability
*/
function submitRemoveSecurityOfficerRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
address _securityOfficer,
address multisigAddress,
AccessControlEnumerable accessControl
) internal returns (RequestSubmissionResult memory result) {
if (_securityOfficer == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
// Prevent removing the last security officer
// Security officers are required to reject timelocked releases
if (accessControl.getRoleMemberCount(ARKIS_SECURITY_OFFICER_ROLE) <= 1) {
revert IUpgradeMultisig.CannotRemoveLastSecurityOfficer();
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.RemoveSecurityOfficer,
_securityOfficer
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.RemoveSecurityOfficer;
request.nonce = nonce;
request.targetApprover = _securityOfficer;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a renounce ownership request
* @dev Internal function called by submitManagementRequest
*/
function submitRenounceOwnershipRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
address _targetContract,
address multisigAddress
) internal returns (RequestSubmissionResult memory result) {
if (_targetContract == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
_validateOwnableTarget(_targetContract, multisigAddress);
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.RenounceOwnership,
_targetContract
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.RenounceOwnership;
request.nonce = nonce;
request.targetContract = _targetContract;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Submit a transfer ownership request
* @dev Internal function called by submitManagementRequest
* @dev Targets must be strictly ascending, which also rules out duplicates.
* Every target must be owned by the multisig at submission. Only one request can be pending.
*/
function submitTransferOwnershipRequest(
mapping(bytes32 => IUpgradeMultisig.ManagementRequest) storage managementRequests,
uint80 nonce,
address[] memory _targetContracts,
address _newOwner,
address multisigAddress
) internal returns (RequestSubmissionResult memory result) {
if (_targetContracts.length == 0) {
revert IUpgradeMultisig.EmptyTargetContracts();
}
if (_newOwner == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
for (uint256 i = 0; i < _targetContracts.length; i++) {
if (_targetContracts[i] == address(0)) {
revert IUpgradeMultisig.InvalidAddress();
}
if (i > 0 && _targetContracts[i] <= _targetContracts[i - 1]) {
revert IUpgradeMultisig.AddressesNotAscending(
_targetContracts[i - 1],
_targetContracts[i]
);
}
_validateOwnableTarget(_targetContracts[i], multisigAddress);
}
result.requestId = keccak256(
abi.encode(
multisigAddress,
nonce,
IUpgradeMultisig.ManagementRequestType.TransferOwnership,
_targetContracts,
_newOwner
)
);
if (managementRequests[result.requestId].requestId != bytes32(0)) {
revert IUpgradeMultisig.ManagementRequestAlreadyExists();
}
IUpgradeMultisig.ManagementRequest storage request = managementRequests[result.requestId];
request.requestId = result.requestId;
request.requestType = IUpgradeMultisig.ManagementRequestType.TransferOwnership;
request.nonce = nonce;
request.targetContracts = _targetContracts;
request.newOwner = _newOwner;
request.status = IUpgradeMultisig.Status.Pending;
result.newPendingRequestId = result.requestId;
result.newNonce = nonce + 1;
}
/**
* @notice Validates that a target contract is Ownable and owned by the multisig
* @dev Prevents stuck requests by validating upfront that:
* 1. Target is a contract (not EOA)
* 2. Target implements Ownable (has owner() function)
* 3. Multisig is the current owner
* @param _targetContract The contract to validate
* @param multisigAddress The multisig address that should be the owner
*/
function _validateOwnableTarget(address _targetContract, address multisigAddress) private view {
if (_targetContract.code.length == 0) {
revert IUpgradeMultisig.NotOwnable(_targetContract);
}
try Ownable(_targetContract).owner() returns (address currentOwner) {
if (currentOwner != multisigAddress) {
revert IUpgradeMultisig.NotOwner(_targetContract, multisigAddress, currentOwner);
}
} catch {
revert IUpgradeMultisig.NotOwnable(_targetContract);
}
}
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165Upgradeable is Initializable, IERC165 {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {AccessControl-_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
bool granted = super._grantRole(role, account);
if (granted) {
_roleMembers[role].add(account);
}
return granted;
}
/**
* @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
bool revoked = super._revokeRole(role, account);
if (revoked) {
_roleMembers[role].remove(account);
}
return revoked;
}
}
@openzeppelin/contracts/access/extensions/IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts/utils/structs/EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
contracts/interfaces/base/IERC165Extended.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
/* solhint-disable no-unused-import */
import {
IERC165
} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
/* solhint-enable no-unused-import */
/**
* @notice An error indicating that an address does not support the expected interface
* @param implementation The address that does not implement the required interface
*/
error UnsupportedInterface(address implementation);
/**
* @dev Extended interface of the ERC165 standard to ensure compatibility
* with Diamond facets as defined in EIP-2535.
*
* This interface extends the basic ERC165 mechanism to provide additional
* flexibility for querying supported interfaces, which can then be
* dynamically resolved by one of facets in a Diamond.
*/
interface IERC165Extended {
/**
* @notice Checks if the given interface ID is supported by the contract.
* @param interfaceId The ID of the interface to query.
* @return isSupported Boolean value indicating whether the interface is supported.
*/
function supportsInterfaceExtended(bytes4 interfaceId) external pure returns (bool isSupported);
}
contracts/interfaces/compiler/ILiquidityPoolsController.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
import {Status} from "../compliance/IWhitelistingController.sol";
/**
* @notice Represents a record for an evaluator associated with a specific protocol.
* @param protocol The name of the protocol that the evaluator is associated with.
* @param evaluator The address of the evaluator.
*/
struct EvaluatorRecord {
string protocol;
address evaluator;
}
/**
* @title WhitelistingBytesRecord
* @notice A struct used to store encoded pool data and its support status.
* @dev This struct is employed in the [`ILiquidityPoolsController`](/interfaces/compiler/ILiquidityPoolsController.sol/interface.ILiquidityPoolsController.html) interface.
* @dev `encoded`: Encoded pool data. The encoding depends on the underlying protocol.
* For example UniswapV3 protocol expects this as `(address token0, address token1, uint24 fee)`.
* To find out which encoding does `ProtocolName` expects,
* check `{ProtocolName}LiquidityPoolsRepository.initializePool()`
* @dev `supported`: Indicates whether the pool is supported.
*/
struct WhitelistingBytesRecord {
bytes encoded;
bool supported;
}
/**
* @title ILiquidityPoolsController
* @notice Interface for managing liquidity pools and their support status for different protocols.
*/
interface ILiquidityPoolsController {
/**
* @notice Emitted when an evaluator is updated for a specific protocol.
* @param protocol The name of the protocol associated with the updated evaluator.
* @param evaluator The address of the updated evaluator.
*/
event EvaluatorUpdated(string protocol, address evaluator);
/**
* @dev Emitted when the support status of a pool changes.
* @param protocol The `protocol` identifier.
* @param encodedPool The encoded pool data.
* @param poolId The unique identifier of the pool.
* @param supported Whether the pool is supported or not.
*/
event PoolSupportChanged(
string protocol,
bytes encodedPool,
uint256 indexed poolId,
bool supported
);
/**
* @notice Updates the evaluators for the specified protocols.
* @dev This function allows updating the evaluators by passing an array of [`EvaluatorRecord`](#evaluatorrecord) structs.
* @param records An array of [`EvaluatorRecord`](#evaluatorrecord) structs, each containing the protocol name and the new evaluator address.
*/
function updateEvaluators(EvaluatorRecord[] calldata records) external;
/**
* @notice Update the support status of multiple liquidity pools for a specific protocol.
* @dev Reverts with an [`AlreadyUpToDate`](/interfaces/base/CommonErrors.sol/error.AlreadyUpToDate.html) error if status didn't change for any given pool.
* @dev Emits a [`PoolSupportChanged`](#poolsupportchanged) event for each pool.
* @param _protocol The `protocol` identifier.
* @param _pools An array of [`WhitelistingBytesRecord`](/interfaces/compiler/ILiquidityPoolsController.sol/struct.WhitelistingBytesRecord.html#whitelistingbytesrecord) structs containing pool data and support status.
*/
function updatePoolsSupport(
string calldata _protocol,
WhitelistingBytesRecord[] calldata _pools
) external;
/**
* @notice Returns the role identifier required to manage all master set whitelists.
* @return A bytes32 value representing the ARKIS_WHITELIST_OFFICER_ROLE.
*/
/* solhint-disable-next-line func-name-mixedcase*/
function ARKIS_WHITELIST_OFFICER_ROLE() external view returns (bytes32);
/* solhint-disable ordering */
/**
* @notice Retrieves the evaluator address for a given protocol.
* @dev This function returns the address of the evaluator associated with the specified protocol.
* @param protocol The name of the protocol for which to retrieve the evaluator address.
* @return The address of the evaluator associated with the specified protocol.
*/
function getProtocolEvaluator(string calldata protocol) external view returns (address);
/**
* @notice Get the status of a specific pool and its associated protocol.
* @param _protocol The `protocol` identifier.
* @param _poolId The unique identifier of the pool.
* @return poolStatus_ The [`Status`](/interfaces/compliance/IWhitelistingController.sol/enum.Status.html)
* of the pool.
*/
function getPoolStatus(
string calldata _protocol,
uint256 _poolId
) external returns (Status poolStatus_);
/**
* @notice Get the unique identifier (pool ID) of a specific pool.
* @param _protocol The `protocol` identifier.
* @param _encodedPool The encoded pool data. The encoding depends on the underlying protocol.
* For example UniswapV3 protocol expects this as (address token0, address token1, uint24 fee).
* To find out which encoding does `ProtocolName` expects,
* check {ProtocolName}LiquidityPoolsRepository.getPoolIdFromTokens()
* @dev `supported`: Indicates whether the pool is supported.
* @return poolId_ The unique identifier of the pool.
*/
function getPoolId(
string calldata _protocol,
bytes calldata _encodedPool
) external returns (uint256 poolId_);
/* solhint-enable ordering */
}
contracts/interfaces/compliance/IWhitelistingController.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
import {IERC165Extended} from "../base/IERC165Extended.sol";
import {IWhitelistingControllerAgreement} from "./IWhitelistingControllerAgreement.sol";
/**
* @title Status
* @notice Enum representing status of a record (e.g., token, protocol, operator)
* used for operation validation.
* @notice Validators must adhere to the following rules for different operations and contexts:
* 1) For exchanges: `operator`, `pool`, and `input token` *MAY* be either supported or suspended, but the `output token` *MUST* be supported.
* 2) For deposits: `operator`, `pool`, and every `token` in the `pool` *MUST* be supported.
* 3) For withdrawals: `operator`, `pool`, and each `token` *MAY* be either supported or suspended.
*
* @dev **Note** that deposit denotes **all** ways of acquiring liquidity such
* as token deposit, LP tokens stake, NFT mint etc.
*/
enum Status {
Undefined,
Supported,
Suspended
}
/**
* @title WhitelistingAddressRecord
* @notice A struct to store an address and its support status.
* @dev This struct stores an address and its support status.
* @dev `source`: The address to be stored.
* @dev `supported`: Indicates whether the address is supported or not.
*/
struct WhitelistingAddressRecord {
address source;
bool supported;
}
/**
* @title WhitelistingTokenRecord
* @notice This struct stores an address and its support status for whitelisting, collateral and leverage.
* @dev `source`: The address of the token.
* @dev `supported`: Whether the token can be received from a protocol trades.
*/
struct WhitelistingTokenRecord {
address source;
bool supported;
}
/**
* @title TreasuryStorage
* @notice ERC-7201 namespaced storage for the protocol treasury address.
* @dev `treasury`: The address that receives protocol fees on close.
*/
struct TreasuryStorage {
address treasury;
}
/**
* @notice An error indicating that a token is not supported by the whitelisting controller.
* @dev This error is thrown when an unsupported token is used.
* @dev `token`: The address of the unsupported token.
*/
error TokenIsNotSupported(address token);
/**
* @notice An error indicating that a token is suspended by the whitelisting controller.
* @dev This error is thrown when a suspended token is used.
* @dev `token`: The address of the suspended token.
*/
error TokenIsSuspended(address token);
/**
* @notice An error indicating that an operator is not supported by the whitelisting controller.
* @dev This error is thrown when an unsupported operator is used.
* @dev `operator`: The address of the unsupported operator.
*/
error OperatorIsNotSupported(address operator);
/**
* @notice An error indicating that an operator is suspended by the whitelisting controller.
* @dev This error is thrown when a suspended operator is used.
* @dev `operator`: The address of the suspended operator.
*/
error OperatorIsSuspended(address operator);
/**
* @notice An error indicating that a protocol is not supported by the whitelisting controller.
* @dev This error is thrown when an unsupported protocol is used.
* @dev `protocol`: The identification string of the unsupported protocol.
*/
error ProtocolIsNotSupported(bytes31 protocolNameHash);
/**
* @notice An error indicating that a protocol is suspended by the whitelisting controller.
* @dev This error is thrown when a suspended protocol is used.
* @dev `protocol`: The identification string of the unsupported protocol.
*/
error ProtocolIsSuspended(bytes31 protocolNameHash);
interface ITenant {
function factory() external view returns (address);
}
/**
* @title IWhitelistingController
* @notice Interface for managing whitelisting of tokens, protocols, and operators.
*/
interface IWhitelistingController is IWhitelistingControllerAgreement, IERC165Extended {
/**
* @dev Emitted when the support status of a protocol changes.
* @dev `protocol`: The identification string of the protocol.
* @dev `supported`: Whether the protocol is supported or not.
*/
event ProtocolSupportChanged(string indexed protocol, bool supported);
/**
* @dev Emitted when the support status of a token changes.
* @dev `token`: The address of the token.
* @dev `supported`: Whether the token is supported or not.
*/
event TokenSupportChanged(address indexed token, bool supported);
/**
* @dev Emitted when the support status of an operator changes for a specific protocol.
* @dev `protocol`: The identification string of the protocol.
* @dev `operator`: The address of the operator.
* @dev `supported`: Whether the operator is supported or not.
*/
event OperatorSupportChanged(string indexed protocol, address indexed operator, bool supported);
/**
* @dev Emitted when the protocol treasury address is changed.
* @dev `previousTreasury`: The treasury address before the change.
* @dev `newTreasury`: The treasury address after the change.
*/
event TreasuryChanged(address indexed previousTreasury, address indexed newTreasury);
/**
* @notice Reverts when the agreement was deployed by a different factory version.
* @dev This error is used by the `onlyAgreementFactory` modifier to prevent
* `addTokens` and `addOperators` calls from wrong factory.
* @param factory The address of the factory attempting to interact.
* @param agreement The agreement contract whose associated factory version did not match the caller.
*/
error AgreementFactoryVersionMismatch(address factory, address agreement);
/**
* @notice Reverts when the caller contract supports a prohibited interface.
* @dev This error is used by the `notMarginAccount` modifier to prevent
* function calls from contracts that implement the `IAccount` interface.
* @param caller The address of the caller contract
*/
error CallerSupportsForbiddenInterface(address caller);
/**
* @notice An error indicating that the provided address is not a valid token address.
* @dev This error is thrown when the address does not conform to the expected token interface.
* @param token The address that failed the token validation check.
*/
error InvalidTokenAddress(address token);
/**
* @notice Update the support status of multiple tokens.
* @dev Emits a [`TokenSupportChanged()`](#tokensupportchanged) event for each token whose status changed.
* @dev Reverts with an [`AlreadyUpToDate()`](/interfaces/base/CommonErrors.sol/error.AlreadyUpToDate.html)
* error if no token status changed.
* @param _tokens An array of [`WhitelistingTokenRecord`](./struct.WhitelistingTokenRecord.html)
* structs containing token addresses and support.
*/
function updateTokensSupport(WhitelistingTokenRecord[] calldata _tokens) external;
/**
* @notice Update the support status of a protocol.
* @dev Emits a [`ProtocolSupportChanged()`](#protocolsupportchanged) event.
* @dev Reverts with an [`AlreadyUpToDate()`](/interfaces/base/CommonErrors.sol/error.AlreadyUpToDate.html)
* error if protocol status is up to date.
* @param _protocol The identification string of the protocol.
* @param _supported Whether the protocol is supported or not.
*/
function updateProtocolSupport(string calldata _protocol, bool _supported) external;
/**
* @notice Update the support status of multiple operators for a specific protocol.
* @dev Emits a [`OperatorSupportChanged()`](#operatorsupportchanged) event for each token whose status changed.
* @dev Reverts with an [`AlreadyUpToDate()`](/interfaces/base/CommonErrors.sol/error.AlreadyUpToDate.html)
* error if no operator status changed.
* @param _protocol The identification string of the protocol.
* @param _operators An array of `WhitelistingAddressRecord` structs containing operator addresses and support statuses.
*/
function updateOperatorsSupport(
string calldata _protocol,
WhitelistingAddressRecord[] calldata _operators
) external;
/**
* @notice Sets the protocol treasury address.
* @dev Only callable by an account with `ARKIS_SECURITY_OFFICER_ROLE`.
* Emits a [`TreasuryChanged()`](#treasurychanged) event.
* @param newTreasury The new treasury address.
*/
function setTreasury(address newTreasury) external;
/**
* @notice Returns the role identifier required to manage all master set whitelists.
* @return A bytes32 value representing the ARKIS_WHITELIST_OFFICER_ROLE.
*/
/* solhint-disable-next-line func-name-mixedcase*/
function ARKIS_WHITELIST_OFFICER_ROLE() external view returns (bytes32);
/**
* @notice Returns the support status of a token.
* @param _token The address of the token.
* @return The [`Status`](./enum.Status.html) of the token.
*/
function getTokenStatus(address _token) external view returns (Status);
/**
* @notice Checks whether a specific token is supported by a tenant.
* @dev This function returns a boolean indicating if the given token is supported by the specified tenant.
* @param tenant The address of the tenant to check.
* @param token The address of the token to check for support.
* @return A boolean value indicating whether the token is supported by the tenant.
*/
function getTokenSupport(address tenant, address token) external view returns (bool);
/**
* @notice Retrieves the list of tokens supported by a specific tenant.
* @dev This function returns an array of token addresses that are supported by the specified tenant.
* @param tenant The address of the tenant whose supported tokens are to be retrieved.
* @return An array of addresses representing the tokens supported by the tenant.
*/
function getTokens(address tenant) external view returns (address[] memory);
/**
* @notice Returns the support status of a protocol.
* @param protocol The identification string of the protocol.
* @return The [`Status`](./enum.Status.html)
* of the protocol.
*/
function getProtocolStatus(string calldata protocol) external view returns (Status);
/**
* @notice Returns the support status of an operator for a specific protocol.
* @param _operator The address of the operator.
* @return operatorStatus_ The [`Status`](./enum.Status.html)
* of the operator.
* @return protocolStatus_ The [`Status`](./enum.Status.html)
* of the protocol.
*/
function getOperatorStatus(
address _operator
) external view returns (Status operatorStatus_, Status protocolStatus_);
/**
* @notice Returns role identifier for unpause operators
* @return bytes32 keccak256 hash of ARKIS_SECURITY_OFFICER_ROLE
*/
/* solhint-disable-next-line func-name-mixedcase*/
function ARKIS_SECURITY_OFFICER_ROLE() external view returns (bytes32);
/**
* @notice Returns the protocol treasury address that receives protocol fees on close.
* @return The treasury address.
*/
function treasury() external view returns (address);
}
contracts/interfaces/compliance/IWhitelistingControllerAgreement.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
/**
* @title IWhitelistingControllerAgreement
* @notice Interface for managing whitelisting of tokens and operators for Agreements.
*/
interface IWhitelistingControllerAgreement {
/**
* @notice Emitted when a new token is added for a specific tenant.
* @param tenant The address of the tenant to whom the token is added.
* @param token The address of the token that has been added.
*/
event TokenAdded(address tenant, address token);
/**
* @notice Emitted when a new operator is added for a specific tenant.
* @param tenant The address of the tenant to whom the operator is added.
* @param operator The address of the operator that has been added.
*/
event OperatorAdded(address tenant, address operator);
/**
* @notice Adds a list of tokens to the specified tenant.
* @param tenant The address of the tenant to which the tokens will be added.
* @param tokens An array of addresses representing the tokens to be added.
* @dev This function can be used to update the list of supported tokens for a given tenant.
*/
function addTokens(address tenant, address[] calldata tokens) external;
/**
* @notice Adds a list of operators to the specified tenant.
* @param tenant The address of the tenant to which the operators will be added.
* @param operators An array of addresses representing the operators to be added.
* @dev This function updates the list of authorized operators for a given tenant.
*/
function addOperators(address tenant, address[] calldata operators) external;
/**
* @notice Returns the address of the agreement factory contract.
* @return The address of the agreement factory.
* @dev The agreement factory is used to create and manage agreements.
*/
function agreementFactory() external view returns (address);
/**
* @notice Returns the address of the agreement V2 factory contract.
* @return The address of the agreement V2 factory.
* @dev The agreement V2 factory is used to create and manage agreements V2.
*/
function agreementV2Factory() external view returns (address);
/**
* @notice Checks if a specific token is supported for a given tenant.
* @param tenant The address of the tenant whose supported tokens are being queried.
* @param token The address of the token to check for support.
* @return A boolean indicating whether the token is supported by the tenant.
* @dev This function will return `true` if the token is supported, and `false` otherwise.
*/
function getTokenSupport(address tenant, address token) external view returns (bool);
/**
* @notice Retrieves a list of tokens supported by a specific tenant.
* @param tenant The address of the tenant whose supported tokens are being queried.
* @return An array of token addresses supported by the specified tenant.
* @dev This function returns an array containing the addresses of tokens that the tenant supports.
* It is a view function and does not modify the contract state.
*/
function getTokens(address tenant) external view returns (address[] memory);
/**
* @notice Checks if a specific operator is supported by a given tenant.
* @param tenant The address of the tenant whose supported operators are being queried.
* @param operator The address of the operator to check for support.
* @return A boolean value indicating whether the operator is supported by the tenant.
* @dev This function returns `true` if the operator is supported by the specified tenant, and `false` otherwise.
* It is a view function and does not modify the contract state.
*/
function getOperatorSupport(address tenant, address operator) external view returns (bool);
/**
* @notice Retrieves the list of operators associated with a specific tenant.
* @param tenant The address of the tenant whose operators are being queried.
* @return A dynamically-sized array of addresses representing the operators associated with the tenant.
* @dev This function is a view function and does not modify the contract state.
*/
function getOperators(address tenant) external view returns (address[] memory);
}
contracts/interfaces/diamond/IDiamondCut.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
interface IDiamondCut {
enum FacetCutAction {
Add,
Replace,
Remove
}
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
/// @notice Add/replace/remove any number of functions and optionally execute
/// a function with delegatecall
/// @param _diamondCut Contains the facet addresses and function selectors
/// @param _init The address of the contract or facet to execute _calldata
/// @param _calldata A function call, including function selector and arguments
/// _calldata is executed with delegatecall on _init
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external;
}
contracts/interfaces/multisig/IUpgradeMultisig.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.22;
import {EvaluatorRecord} from "contracts/interfaces/compiler/ILiquidityPoolsController.sol";
import {IDiamondCut} from "contracts/interfaces/diamond/IDiamondCut.sol";
/**
* @title IUpgradeMultisig
* @dev Interface for multisig contract managing smart contract upgrades
* @notice Operators submit releases, approvers approve, then anyone executes after the timelock
*/
interface IUpgradeMultisig {
// ============ Structs ============
struct BeaconUpgrade {
address beacon;
address newImplementation;
}
struct ProxyUpgrade {
address proxy;
address newImplementation;
bytes initData;
uint256 value;
}
struct DiamondCut {
address diamond;
IDiamondCut.FacetCut[] cuts;
address init;
bytes initData;
}
struct EvaluatorUpdate {
EvaluatorRecord[] records;
}
struct ReleaseData {
BeaconUpgrade[] beaconUpgrades;
ProxyUpgrade[] proxyUpgrades;
DiamondCut[] diamondCuts;
EvaluatorUpdate[] evaluatorUpdates;
}
enum ManagementRequestType {
AddApprover,
RemoveApprover,
ChangeThreshold,
AddOperator,
RemoveOperator,
ChangeTimelock,
AddSecurityOfficer,
RemoveSecurityOfficer,
RenounceOwnership,
TransferOwnership
}
enum Status {
Pending,
Executed,
Rejected
}
struct ManagementRequest {
bytes32 requestId;
address targetApprover;
uint80 nonce;
uint8 newThreshold;
ManagementRequestType requestType;
uint128 newTimelockDuration;
Status status;
address targetOperator;
address targetContract;
address[] targetContracts;
address newOwner;
uint128 timelockDuration;
uint256 timelockStart;
mapping(address => bool) approvals;
mapping(address => bool) rejections;
}
struct Release {
address operator;
uint80 nonce;
Status status;
uint128 timelockDuration;
uint256 timelockStart;
BeaconUpgrade[] beaconUpgrades;
ProxyUpgrade[] proxyUpgrades;
DiamondCut[] diamondCuts;
EvaluatorUpdate[] evaluatorUpdates;
}
// ============ Events ============
/**
* @dev Emitted when a new release is submitted
* @param releaseId The unique identifier for the release
* @param operator The address of the operator who submitted the release
* @param releaseHash The hash of the release data (keccak256(abi.encode(releaseData)))
* @param beaconCount Number of beacon upgrades in the release
* @param proxyCount Number of proxy upgrades in the release
* @param diamondCount Number of diamond cuts in the release
* @param evaluatorCount Number of evaluator updates in the release
* @param timestamp Block timestamp when the release was submitted
*/
event ReleaseSubmitted(
bytes32 indexed releaseId,
address indexed operator,
bytes32 releaseHash,
uint256 beaconCount,
uint256 proxyCount,
uint256 diamondCount,
uint256 evaluatorCount,
uint256 timestamp
);
/**
* @dev Emitted when a release is approved by a signer
* @param releaseId The unique identifier for the release
* @param approver The address of the signer who approved
* @param timestamp Block timestamp when the release was approved
*/
event ReleaseApproved(bytes32 indexed releaseId, address indexed approver, uint256 timestamp);
/**
* @dev Emitted when a release is rejected by a signer
* @param releaseId The unique identifier for the release
* @param rejector The address of the signer who rejected
* @param timestamp Block timestamp when the release was rejected
*/
event ReleaseRejected(bytes32 indexed releaseId, address indexed rejector, uint256 timestamp);
/**
* @dev Emitted when a release is ready for execution (threshold approvals reached)
* @param releaseId The unique identifier for the release
* @param timestamp Block timestamp when the release became ready for execution
*/
event ReleaseTimelockStarted(bytes32 indexed releaseId, uint256 timestamp);
/**
* @dev Emitted when a release is executed
* @param releaseId The unique identifier for the release
* @param executor The address of the executor
* @param timestamp Block timestamp when the release was executed
*/
event ReleaseExecuted(bytes32 indexed releaseId, address indexed executor, uint256 timestamp);
event AddApproverRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed approver,
uint256 timestamp
);
event RemoveApproverRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed approver,
uint256 timestamp
);
event ChangeThresholdRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
uint8 newThreshold,
uint256 timestamp
);
event AddOperatorRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed targetOperator,
uint256 timestamp
);
event RemoveOperatorRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed targetOperator,
uint256 timestamp
);
event ChangeTimelockRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
uint128 newTimelockDuration,
uint256 timestamp
);
event ManagementRequestApproved(
bytes32 indexed requestId,
address indexed approver,
uint256 timestamp
);
event ManagementRequestRejected(
bytes32 indexed requestId,
address indexed rejector,
uint256 timestamp
);
/**
* @dev Emitted when a management request rejection threshold is reached and the request is finalized as rejected
* @param requestId The unique identifier for the management request
* @param timestamp Block timestamp when the rejection threshold was reached
*/
event ManagementRequestRejectionThresholdReached(bytes32 indexed requestId, uint256 timestamp);
event ManagementRequestTimelockStarted(bytes32 indexed requestId, uint256 timestamp);
event ManagementRequestExecuted(
bytes32 indexed requestId,
address indexed executor,
uint256 timestamp
);
event ApproverAdded(bytes32 indexed requestId, address indexed approver);
event ApproverRemoved(bytes32 indexed requestId, address indexed approver);
event ThresholdChanged(bytes32 indexed requestId, uint8 oldThreshold, uint8 newThreshold);
event OperatorAdded(bytes32 indexed requestId, address indexed operator);
event OperatorRemoved(bytes32 indexed requestId, address indexed operator);
event TimelockChanged(bytes32 indexed requestId, uint128 oldTimelock, uint128 newTimelock);
event AddSecurityOfficerRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed securityOfficer,
uint256 timestamp
);
event RemoveSecurityOfficerRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed securityOfficer,
uint256 timestamp
);
event SecurityOfficerAdded(bytes32 indexed requestId, address indexed securityOfficer);
event SecurityOfficerRemoved(bytes32 indexed requestId, address indexed securityOfficer);
event RenounceOwnershipRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed targetContract,
uint256 timestamp
);
event OwnershipRenounced(bytes32 indexed requestId, address indexed targetContract);
event TransferOwnershipRequestSubmitted(
bytes32 indexed requestId,
address indexed operator,
address indexed newOwner,
address[] targetContracts,
uint256 timestamp
);
event OwnershipTransferred(
bytes32 indexed requestId,
address indexed targetContract,
address indexed newOwner
);
// ============ Errors ============
/**
* @dev Thrown when an unauthorized signer attempts to perform an action
*/
error UnauthorizedSigner();
/**
* @dev Thrown when attempting to create a release that already exists
*/
error ReleaseAlreadyExists();
/**
* @dev Thrown when attempting to perform an action on a non-existent release
*/
error ReleaseDoesNotExist();
/**
* @dev Thrown when attempting to perform an action on an already executed release
*/
error ReleaseAlreadyExecuted();
/**
* @dev Thrown when attempting to perform an action on a rejected release
*/
error CannotApproveRejectedRelease();
/**
* @dev Thrown when attempting to reject a release that is already rejected
*/
error ReleaseAlreadyRejected();
/**
* @dev Thrown when attempting to execute a rejected release
*/
error CannotExecuteRejectedRelease();
/**
* @dev Thrown when attempting to approve a release that has already been approved
*/
error AlreadyApproved();
/**
* @dev Thrown when attempting to perform an action that requires approval but hasn't been approved
*/
error NotApproved();
/**
* @dev Thrown when an invalid address is provided (zero address or duplicate addresses)
*/
error InvalidAddress();
/**
* @dev Thrown when initData is provided but is invalid:
* - Shorter than 4 bytes (minimum function selector size)
* - Not properly ABI-encoded (length % 32 != 4, i.e., must be 4 bytes selector + 32-byte aligned parameters)
*/
error InvalidInitData();
/**
* @dev Thrown when a proxy is not an EIP-1967 proxy (implementation slot is zero)
*/
error NotEip1967Proxy();
/**
* @dev Thrown when a proxy's admin doesn't match the expected proxyAdmin
*/
error WrongAdmin();
/**
* @dev Thrown when attempting to submit an empty release
*/
error EmptyRelease();
error ManagementRequestAlreadyExists();
error ManagementRequestDoesNotExist();
error ManagementRequestAlreadyExecuted();
error ManagementRequestAlreadyRejected();
error CannotApproveRejectedManagementRequest();
error CannotExecuteRejectedManagementRequest();
error CannotRejectAfterApproving();
error CannotApproveAfterRejecting();
error CannotRenounceBelowThreshold();
error InsufficientOperators();
error InvalidThreshold();
error ApproverAlreadyExists();
error ApproverDoesNotExist();
error ApproverCannotBeOperator();
error CannotRenounceWhileManagementRequestPending();
error InsufficientApprovers();
error InsufficientApprovals();
error InsufficientValue(uint256 required, uint256 provided);
error OperatorAlreadyExists();
error OperatorDoesNotExist();
error RateLimit(address operator, uint256 lastProposed);
error OperatorCannotBeApprover();
error EmptyTargetContracts();
error AddressesNotAscending(address previous, address current);
error InvalidManagementRequestType();
error SecurityOfficerAlreadyExists();
error SecurityOfficerDoesNotExist();
error CannotRemoveLastSecurityOfficer();
error CannotRenounceLastSecurityOfficer();
error InvalidReleaseHash();
error TimelockNotPassed();
/**
* @dev Thrown when a target contract does not implement Ownable (no owner() function)
* @param target The address that is not Ownable
*/
error NotOwnable(address target);
/**
* @dev Thrown when the multisig is not the owner of the target contract
* @param target The target contract address
* @param expectedOwner The expected owner (multisig address)
* @param actualOwner The actual owner of the contract
*/
error NotOwner(address target, address expectedOwner, address actualOwner);
/**
* @dev Thrown when timelock duration would cause overflow or is invalid
*/
error InvalidTimelockDuration();
error ReleaseNotReady();
error ManagementRequestNotReady();
/**
* @dev Thrown when attempting to execute a release out of order
* @param expectedNonce The expected nonce for the next release
* @param actualNonce The nonce of the release being executed
*/
error ReleaseOutOfOrder(uint80 expectedNonce, uint80 actualNonce);
/**
* @dev Thrown when attempting to execute a management request out of order
* @param expectedNonce The expected nonce for the next management request
* @param actualNonce The nonce of the management request being executed
*/
error ManagementRequestOutOfOrder(uint80 expectedNonce, uint80 actualNonce);
/**
* @dev Thrown when attempting to submit a release while a management request is pending
*/
error ManagementRequestPending();
/**
* @dev Thrown when attempting to submit a management request while a release is pending
*/
error ReleasePending();
/**
* @dev Thrown when a beacon upgrade fails during execution
* @param index The index of the failed upgrade in the beaconUpgrades array
* @param beacon The address of the beacon that failed to upgrade
* @param reason The original error reason bytes
*/
error BeaconUpgradeFailed(uint256 index, address beacon, bytes reason);
/**
* @dev Thrown when beacon upgrade validation fails after execution
* @param index The index of the failed upgrade in the beaconUpgrades array
* @param beacon The address of the beacon that failed validation
* @param expectedImplementation The expected implementation address
* @param actualImplementation The actual implementation address returned by beacon.implementation()
*/
error BeaconUpgradeValidationFailed(
uint256 index,
address beacon,
address expectedImplementation,
address actualImplementation
);
/**
* @dev Thrown when a proxy upgrade fails during execution
* @param index The index of the failed upgrade in the proxyUpgrades array
* @param proxy The address of the proxy that failed to upgrade
* @param isUpgradeAndCall Whether this was an upgradeAndCall operation
* @param reason The original error reason bytes
*/
error ProxyUpgradeFailed(uint256 index, address proxy, bool isUpgradeAndCall, bytes reason);
/**
* @dev Thrown when proxy upgrade validation fails after execution
* @param index The index of the failed upgrade in the proxyUpgrades array
* @param proxy The address of the proxy that failed validation
* @param isUpgradeAndCall Whether this was an upgradeAndCall operation
* @param expectedImplementation The expected implementation address
* @param actualImplementation The actual implementation address returned by proxy.implementation()
*/
error ProxyUpgradeValidationFailed(
uint256 index,
address proxy,
bool isUpgradeAndCall,
address expectedImplementation,
address actualImplementation
);
/**
* @dev Thrown when a proxy admin slot validation fails after upgrade
* @param index The index of the failed upgrade in the proxyUpgrades array
* @param proxy The address of the proxy that failed validation
* @param expectedAdmin The expected admin address (proxyAdmin)
* @param actualAdmin The actual admin address after upgrade
*/
error ProxyAdminValidationFailed(
uint256 index,
address proxy,
address expectedAdmin,
address actualAdmin
);
/**
* @dev Thrown when a diamond cut fails during execution
* @param index The index of the failed cut in the diamondCuts array
* @param diamond The address of the diamond that failed to cut
* @param reason The original error reason bytes
*/
error DiamondCutFailed(uint256 index, address diamond, bytes reason);
/**
* @dev Thrown when an evaluator update fails during execution
* @param index The index of the failed update in the evaluatorUpdates array
* @param reason The original error reason bytes
*/
error EvaluatorUpdateFailed(uint256 index, bytes reason);
/**
* @dev Thrown when diamond cut validation fails after execution
* @param cutIndex The index of the failed cut in the diamondCuts array
* @param diamond The address of the diamond that failed validation
* @param facetCutIndex The index of the facet cut within the cuts array
* @param selectorIndex The index of the selector within the functionSelectors array
* @param selector The function selector that failed validation
* @param action The FacetCutAction (Add/Replace/Remove)
* @param expectedFacet The expected facet address
* @param actualFacet The actual facet address returned by facetAddress(selector)
*/
error DiamondCutValidationFailed(
uint256 cutIndex,
address diamond,
uint256 facetCutIndex,
uint256 selectorIndex,
bytes4 selector,
IDiamondCut.FacetCutAction action,
address expectedFacet,
address actualFacet
);
/**
* @dev Thrown when a diamond doesn't support IDiamondLoupe interface
*/
error InvalidDiamond();
/**
* @dev Thrown when FacetCutAction enum value is out of bounds
*/
error InvalidFacetCutAction();
/**
* @dev Thrown when a selector appears multiple times in a diamond cut batch
*/
error DuplicateSelector(bytes4 selector);
/**
* @dev Thrown when a selector is bytes4(0)
*/
error InvalidSelector();
/**
* @dev Thrown when trying to add a selector that already exists
*/
error SelectorAlreadyExists(bytes4 selector);
/**
* @dev Thrown when trying to replace/remove a selector that doesn't exist
*/
error SelectorDoesNotExist(bytes4 selector);
/**
* @dev Thrown when trying to remove an immutable selector (implemented directly in diamond)
*/
error SelectorImmutable(bytes4 selector);
/**
* @dev Thrown when init and initData are not coherent
*/
error InvalidInitCoherence();
// ============ Functions ============
/**
* @dev Submit a new release with upgrade operations
* @param releaseData Struct containing all upgrade operations
* @param releaseHash Hash of the release data for validation
* @return releaseId The generated release ID
*/
function submitRelease(
ReleaseData calldata releaseData,
bytes32 releaseHash
) external returns (bytes32 releaseId);
/**
* @dev Approve a release
* @param releaseId The release ID to approve
*/
function approveRelease(bytes32 releaseId) external;
/**
* @dev Execute an approved release after timelock period
* @param releaseId The release ID to execute
*/
function executeRelease(bytes32 releaseId) external payable;
/**
* @dev Reject a release (clears all approvals)
* @param releaseId The release ID to reject
*/
function rejectRelease(bytes32 releaseId) external;
// ============ Management Functions ============
/**
* @dev Submit a management request (generic function for all request types)
* @param requestType The type of management request to submit
* @param requestData ABI-encoded request parameters:
* - AddApprover: abi.encode(address _approver)
* - RemoveApprover: abi.encode(address _approver)
* - ChangeThreshold: abi.encode(uint8 _newThreshold)
* - AddOperator: abi.encode(address _operator)
* - RemoveOperator: abi.encode(address _operator)
* - ChangeTimelock: abi.encode(uint128 _newTimelockDuration)
* - AddSecurityOfficer: abi.encode(address _securityOfficer)
* - RemoveSecurityOfficer: abi.encode(address _securityOfficer)
* - RenounceOwnership: abi.encode(address _targetContract)
* - TransferOwnership: abi.encode(address[] _targetContracts, address _newOwner), targets strictly ascending
* @return requestId The unique identifier for the management request
*/
function submitManagementRequest(
ManagementRequestType requestType,
bytes calldata requestData
) external returns (bytes32 requestId);
/**
* @dev Approve a management request
* @param requestId The management request ID to approve
*/
function approveManagementRequest(bytes32 requestId) external;
/**
* @dev Reject a management request
* @param requestId The management request ID to reject
*/
function rejectManagementRequest(bytes32 requestId) external;
/**
* @dev Execute an approved management request after timelock period
* @param requestId The management request ID to execute
*/
function executeManagementRequest(bytes32 requestId) external;
// ============ View Functions ============
/**
* @dev Get the list of approvers
* @return Array of approver addresses
*/
function getApprovers() external view returns (address[] memory);
/**
* @dev Get management request information
* @param requestId The management request ID
* @return requestType The type of management request
* @return targetApprover The target approver (for add/remove operations)
* @return newThreshold The new threshold (for threshold change operations)
* @return targetOperator The operator to add or remove (for operator operations)
* @return newTimelockDuration The new timelock duration (for timelock change operations)
* @return targetContract The target contract address (for renounce ownership operations)
* @return newOwner The new owner (for transfer ownership operations)
* @return status The status of the request (Pending, Executed, or Rejected)
*/
function getManagementRequestInfo(
bytes32 requestId
)
external
view
returns (
ManagementRequestType requestType,
address targetApprover,
uint8 newThreshold,
address targetOperator,
uint128 newTimelockDuration,
address targetContract,
address newOwner,
Status status
);
/**
* @dev Get the target contracts of a transfer ownership request
* @param requestId The management request ID
* @return The contracts whose ownership the request transfers
*/
function getManagementRequestTargetContracts(
bytes32 requestId
) external view returns (address[] memory);
/**
* @dev Get management request approval and rejection status
* @param requestId The management request ID
* @param approver The approver address to check
* @return approved Whether the approver has approved this management request
* @return rejected Whether the approver has rejected this management request
*/
function getManagementRequestApprovalStatus(
bytes32 requestId,
address approver
) external view returns (bool approved, bool rejected);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"useLiteralContent": true
},
"optimizer": {
"runs": 1000000,
"details": {
"yulDetails": {
"optimizerSteps": "u"
}
},
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.