Source Code
Overview
MON Balance
MON Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 11 internal transactions
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 37738697 | 53 days ago | Contract Creation | 0 MON | |||
| 37727685 | 53 days ago | Contract Creation | 0 MON | |||
| 37717983 | 53 days ago | Contract Creation | 0 MON | |||
| 37717815 | 53 days ago | Contract Creation | 0 MON | |||
| 37702277 | 53 days ago | Contract Creation | 0 MON | |||
| 37701475 | 53 days ago | Contract Creation | 0 MON | |||
| 37696233 | 53 days ago | Contract Creation | 0 MON | |||
| 37035599 | 56 days ago | Contract Creation | 0 MON | |||
| 36854969 | 57 days ago | Contract Creation | 0 MON | |||
| 36824841 | 57 days ago | Contract Creation | 0 MON | |||
| 34746369 | 67 days ago | Contract Creation | 0 MON |
Loading...
Loading
Contract Name:
GovernanceFactory
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 0 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;
import { TimelockController } from "@openzeppelin/governance/TimelockController.sol";
import { Governance, IVotes } from "src/Governance.sol";
import { IGovernanceFactory } from "src/interfaces/IGovernanceFactory.sol";
import { ImmutableAirlock } from "src/base/ImmutableAirlock.sol";
/// @custom:security-contact [email protected]
contract GovernanceFactory is IGovernanceFactory, ImmutableAirlock {
TimelockFactory public immutable timelockFactory;
constructor(
address airlock_
) ImmutableAirlock(airlock_) {
timelockFactory = new TimelockFactory();
}
function create(address asset, bytes calldata data) external onlyAirlock returns (address, address) {
(string memory name, uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold) =
abi.decode(data, (string, uint48, uint32, uint256));
TimelockController timelockController = timelockFactory.create();
address governance = address(
new Governance(
string.concat(name, " Governance"),
IVotes(asset),
timelockController,
initialVotingDelay,
initialVotingPeriod,
initialProposalThreshold
)
);
timelockController.grantRole(keccak256("PROPOSER_ROLE"), governance);
timelockController.grantRole(keccak256("CANCELLER_ROLE"), governance);
timelockController.grantRole(keccak256("EXECUTOR_ROLE"), address(0));
timelockController.renounceRole(bytes32(0x00), address(this));
return (governance, address(timelockController));
}
}
contract TimelockFactory {
function create() external returns (TimelockController) {
return new TimelockController(1 days, new address[](0), new address[](0), msg.sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/TimelockController.sol)
pragma solidity ^0.8.20;
import {AccessControl} from "../access/AccessControl.sol";
import {ERC721Holder} from "../token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "../token/ERC1155/utils/ERC1155Holder.sol";
import {Address} from "../utils/Address.sol";
/**
* @dev Contract module which acts as a timelocked controller. When set as the
* owner of an `Ownable` smart contract, it enforces a timelock on all
* `onlyOwner` maintenance operations. This gives time for users of the
* controlled contract to exit before a potentially dangerous maintenance
* operation is applied.
*
* By default, this contract is self administered, meaning administration tasks
* have to go through the timelock process. The proposer (resp executor) role
* is in charge of proposing (resp executing) operations. A common use case is
* to position this {TimelockController} as the owner of a smart contract, with
* a multisig or a DAO as the sole proposer.
*/
contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
uint256 internal constant _DONE_TIMESTAMP = uint256(1);
mapping(bytes32 id => uint256) private _timestamps;
uint256 private _minDelay;
enum OperationState {
Unset,
Waiting,
Ready,
Done
}
/**
* @dev Mismatch between the parameters length for an operation call.
*/
error TimelockInvalidOperationLength(uint256 targets, uint256 payloads, uint256 values);
/**
* @dev The schedule operation doesn't meet the minimum delay.
*/
error TimelockInsufficientDelay(uint256 delay, uint256 minDelay);
/**
* @dev The current state of an operation is not as required.
* The `expectedStates` is a bitmap with the bits enabled for each OperationState enum position
* counting from right to left.
*
* See {_encodeStateBitmap}.
*/
error TimelockUnexpectedOperationState(bytes32 operationId, bytes32 expectedStates);
/**
* @dev The predecessor to an operation not yet done.
*/
error TimelockUnexecutedPredecessor(bytes32 predecessorId);
/**
* @dev The caller account is not authorized.
*/
error TimelockUnauthorizedCaller(address caller);
/**
* @dev Emitted when a call is scheduled as part of operation `id`.
*/
event CallScheduled(
bytes32 indexed id,
uint256 indexed index,
address target,
uint256 value,
bytes data,
bytes32 predecessor,
uint256 delay
);
/**
* @dev Emitted when a call is performed as part of operation `id`.
*/
event CallExecuted(bytes32 indexed id, uint256 indexed index, address target, uint256 value, bytes data);
/**
* @dev Emitted when new proposal is scheduled with non-zero salt.
*/
event CallSalt(bytes32 indexed id, bytes32 salt);
/**
* @dev Emitted when operation `id` is cancelled.
*/
event Cancelled(bytes32 indexed id);
/**
* @dev Emitted when the minimum delay for future operations is modified.
*/
event MinDelayChange(uint256 oldDuration, uint256 newDuration);
/**
* @dev Initializes the contract with the following parameters:
*
* - `minDelay`: initial minimum delay in seconds for operations
* - `proposers`: accounts to be granted proposer and canceller roles
* - `executors`: accounts to be granted executor role
* - `admin`: optional account to be granted admin role; disable with zero address
*
* IMPORTANT: The optional admin can aid with initial configuration of roles after deployment
* without being subject to delay, but this role should be subsequently renounced in favor of
* administration through timelocked proposals. Previous versions of this contract would assign
* this admin to the deployer automatically and should be renounced as well.
*/
constructor(uint256 minDelay, address[] memory proposers, address[] memory executors, address admin) {
// self administration
_grantRole(DEFAULT_ADMIN_ROLE, address(this));
// optional admin
if (admin != address(0)) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
// register proposers and cancellers
for (uint256 i = 0; i < proposers.length; ++i) {
_grantRole(PROPOSER_ROLE, proposers[i]);
_grantRole(CANCELLER_ROLE, proposers[i]);
}
// register executors
for (uint256 i = 0; i < executors.length; ++i) {
_grantRole(EXECUTOR_ROLE, executors[i]);
}
_minDelay = minDelay;
emit MinDelayChange(0, minDelay);
}
/**
* @dev Modifier to make a function callable only by a certain role. In
* addition to checking the sender's role, `address(0)` 's role is also
* considered. Granting a role to `address(0)` is equivalent to enabling
* this role for everyone.
*/
modifier onlyRoleOrOpenRole(bytes32 role) {
if (!hasRole(role, address(0))) {
_checkRole(role, _msgSender());
}
_;
}
/**
* @dev Contract might receive/hold ETH as part of the maintenance process.
*/
receive() external payable {}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(AccessControl, ERC1155Holder) returns (bool) {
return super.supportsInterface(interfaceId);
}
/**
* @dev Returns whether an id corresponds to a registered operation. This
* includes both Waiting, Ready, and Done operations.
*/
function isOperation(bytes32 id) public view returns (bool) {
return getOperationState(id) != OperationState.Unset;
}
/**
* @dev Returns whether an operation is pending or not. Note that a "pending" operation may also be "ready".
*/
function isOperationPending(bytes32 id) public view returns (bool) {
OperationState state = getOperationState(id);
return state == OperationState.Waiting || state == OperationState.Ready;
}
/**
* @dev Returns whether an operation is ready for execution. Note that a "ready" operation is also "pending".
*/
function isOperationReady(bytes32 id) public view returns (bool) {
return getOperationState(id) == OperationState.Ready;
}
/**
* @dev Returns whether an operation is done or not.
*/
function isOperationDone(bytes32 id) public view returns (bool) {
return getOperationState(id) == OperationState.Done;
}
/**
* @dev Returns the timestamp at which an operation becomes ready (0 for
* unset operations, 1 for done operations).
*/
function getTimestamp(bytes32 id) public view virtual returns (uint256) {
return _timestamps[id];
}
/**
* @dev Returns operation state.
*/
function getOperationState(bytes32 id) public view virtual returns (OperationState) {
uint256 timestamp = getTimestamp(id);
if (timestamp == 0) {
return OperationState.Unset;
} else if (timestamp == _DONE_TIMESTAMP) {
return OperationState.Done;
} else if (timestamp > block.timestamp) {
return OperationState.Waiting;
} else {
return OperationState.Ready;
}
}
/**
* @dev Returns the minimum delay in seconds for an operation to become valid.
*
* This value can be changed by executing an operation that calls `updateDelay`.
*/
function getMinDelay() public view virtual returns (uint256) {
return _minDelay;
}
/**
* @dev Returns the identifier of an operation containing a single
* transaction.
*/
function hashOperation(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32) {
return keccak256(abi.encode(target, value, data, predecessor, salt));
}
/**
* @dev Returns the identifier of an operation containing a batch of
* transactions.
*/
function hashOperationBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata payloads,
bytes32 predecessor,
bytes32 salt
) public pure virtual returns (bytes32) {
return keccak256(abi.encode(targets, values, payloads, predecessor, salt));
}
/**
* @dev Schedule an operation containing a single transaction.
*
* Emits {CallSalt} if salt is nonzero, and {CallScheduled}.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/
function schedule(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_schedule(id, delay);
emit CallScheduled(id, 0, target, value, data, predecessor, delay);
if (salt != bytes32(0)) {
emit CallSalt(id, salt);
}
}
/**
* @dev Schedule an operation containing a batch of transactions.
*
* Emits {CallSalt} if salt is nonzero, and one {CallScheduled} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/
function scheduleBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata payloads,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
if (targets.length != values.length || targets.length != payloads.length) {
revert TimelockInvalidOperationLength(targets.length, payloads.length, values.length);
}
bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);
_schedule(id, delay);
for (uint256 i = 0; i < targets.length; ++i) {
emit CallScheduled(id, i, targets[i], values[i], payloads[i], predecessor, delay);
}
if (salt != bytes32(0)) {
emit CallSalt(id, salt);
}
}
/**
* @dev Schedule an operation that is to become valid after a given delay.
*/
function _schedule(bytes32 id, uint256 delay) private {
if (isOperation(id)) {
revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Unset));
}
uint256 minDelay = getMinDelay();
if (delay < minDelay) {
revert TimelockInsufficientDelay(delay, minDelay);
}
_timestamps[id] = block.timestamp + delay;
}
/**
* @dev Cancel an operation.
*
* Requirements:
*
* - the caller must have the 'canceller' role.
*/
function cancel(bytes32 id) public virtual onlyRole(CANCELLER_ROLE) {
if (!isOperationPending(id)) {
revert TimelockUnexpectedOperationState(
id,
_encodeStateBitmap(OperationState.Waiting) | _encodeStateBitmap(OperationState.Ready)
);
}
delete _timestamps[id];
emit Cancelled(id);
}
/**
* @dev Execute an (ready) operation containing a single transaction.
*
* Emits a {CallExecuted} event.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/
// This function can reenter, but it doesn't pose a risk because _afterCall checks that the proposal is pending,
// thus any modifications to the operation during reentrancy should be caught.
// slither-disable-next-line reentrancy-eth
function execute(
address target,
uint256 value,
bytes calldata payload,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
bytes32 id = hashOperation(target, value, payload, predecessor, salt);
_beforeCall(id, predecessor);
_execute(target, value, payload);
emit CallExecuted(id, 0, target, value, payload);
_afterCall(id);
}
/**
* @dev Execute an (ready) operation containing a batch of transactions.
*
* Emits one {CallExecuted} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/
// This function can reenter, but it doesn't pose a risk because _afterCall checks that the proposal is pending,
// thus any modifications to the operation during reentrancy should be caught.
// slither-disable-next-line reentrancy-eth
function executeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata payloads,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
if (targets.length != values.length || targets.length != payloads.length) {
revert TimelockInvalidOperationLength(targets.length, payloads.length, values.length);
}
bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);
_beforeCall(id, predecessor);
for (uint256 i = 0; i < targets.length; ++i) {
address target = targets[i];
uint256 value = values[i];
bytes calldata payload = payloads[i];
_execute(target, value, payload);
emit CallExecuted(id, i, target, value, payload);
}
_afterCall(id);
}
/**
* @dev Execute an operation's call.
*/
function _execute(address target, uint256 value, bytes calldata data) internal virtual {
(bool success, bytes memory returndata) = target.call{value: value}(data);
Address.verifyCallResult(success, returndata);
}
/**
* @dev Checks before execution of an operation's calls.
*/
function _beforeCall(bytes32 id, bytes32 predecessor) private view {
if (!isOperationReady(id)) {
revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Ready));
}
if (predecessor != bytes32(0) && !isOperationDone(predecessor)) {
revert TimelockUnexecutedPredecessor(predecessor);
}
}
/**
* @dev Checks after execution of an operation's calls.
*/
function _afterCall(bytes32 id) private {
if (!isOperationReady(id)) {
revert TimelockUnexpectedOperationState(id, _encodeStateBitmap(OperationState.Ready));
}
_timestamps[id] = _DONE_TIMESTAMP;
}
/**
* @dev Changes the minimum timelock duration for future operations.
*
* Emits a {MinDelayChange} event.
*
* Requirements:
*
* - the caller must be the timelock itself. This can only be achieved by scheduling and later executing
* an operation where the timelock is the target and the data is the ABI-encoded call to this function.
*/
function updateDelay(uint256 newDelay) external virtual {
address sender = _msgSender();
if (sender != address(this)) {
revert TimelockUnauthorizedCaller(sender);
}
emit MinDelayChange(_minDelay, newDelay);
_minDelay = newDelay;
}
/**
* @dev Encodes a `OperationState` into a `bytes32` representation where each bit enabled corresponds to
* the underlying position in the `OperationState` enum. For example:
*
* 0x000...1000
* ^^^^^^----- ...
* ^---- Done
* ^--- Ready
* ^-- Waiting
* ^- Unset
*/
function _encodeStateBitmap(OperationState operationState) internal pure returns (bytes32) {
return bytes32(1 << uint8(operationState));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { Governor } from "@openzeppelin/governance/Governor.sol";
import { GovernorSettings } from "@openzeppelin/governance/extensions/GovernorSettings.sol";
import { GovernorCountingSimple } from "@openzeppelin/governance/extensions/GovernorCountingSimple.sol";
import { GovernorVotes } from "@openzeppelin/governance/extensions/GovernorVotes.sol";
import { GovernorVotesQuorumFraction } from "@openzeppelin/governance/extensions/GovernorVotesQuorumFraction.sol";
import { GovernorTimelockControl } from "@openzeppelin/governance/extensions/GovernorTimelockControl.sol";
import { TimelockController } from "@openzeppelin/governance/TimelockController.sol";
import { IVotes } from "@openzeppelin/governance/utils/IVotes.sol";
/// @notice Thrown if propose is called before the proposal period starts.
error ProposalPeriodNotStarted();
/// @custom:security-contact [email protected]
contract Governance is
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
/// @notice Timestamp at which the proposal period starts
uint32 public immutable proposalPeriodStart;
constructor(
string memory name_,
IVotes _token,
TimelockController _timelock,
uint48 initialVotingDelay,
uint32 initialVotingPeriod,
uint256 initialProposalThreshold
)
Governor(name_)
GovernorSettings(initialVotingDelay, initialVotingPeriod, initialProposalThreshold)
GovernorVotes(_token)
GovernorVotesQuorumFraction(8)
GovernorTimelockControl(_timelock)
{
proposalPeriodStart = uint32(block.timestamp + 90 days);
}
// The following functions are overrides required by Solidity.
function votingDelay() public view override(Governor, GovernorSettings) returns (uint256) {
return super.votingDelay();
}
function votingPeriod() public view override(Governor, GovernorSettings) returns (uint256) {
return super.votingPeriod();
}
function quorum(
uint256 blockNumber
) public view override(Governor, GovernorVotesQuorumFraction) returns (uint256) {
return super.quorum(blockNumber);
}
function state(
uint256 proposalId
) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
return super.state(proposalId);
}
function proposalNeedsQueuing(
uint256 proposalId
) public view override(Governor, GovernorTimelockControl) returns (bool) {
return super.proposalNeedsQueuing(proposalId);
}
function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}
/// @inheritdoc Governor
function _propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description,
address proposer
) internal override returns (uint256 proposalId) {
require(block.timestamp >= proposalPeriodStart, ProposalPeriodNotStarted());
return super._propose(targets, values, calldatas, description, proposer);
}
function _queueOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) returns (uint48) {
return super._queueOperations(proposalId, targets, values, calldatas, descriptionHash);
}
function _executeOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._executeOperations(proposalId, targets, values, calldatas, descriptionHash);
}
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
return super._cancel(targets, values, calldatas, descriptionHash);
}
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IGovernanceFactory {
function create(
address asset,
bytes calldata governanceData
) external returns (address governance, address timelockController);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { Airlock } from "../Airlock.sol";
/// @notice Thrown when the caller is not the Airlock contract
error SenderNotAirlock();
abstract contract ImmutableAirlock {
Airlock public immutable airlock;
constructor(
address _airlock
) {
airlock = Airlock(payable(_airlock));
}
/// @notice Throws `SenderNotAirlock` if the caller is not the Airlock contract
modifier onlyAirlock() {
require(msg.sender == address(airlock), SenderNotAirlock());
_;
}
}// 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;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.20;
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
/**
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*/
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/Governor.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../token/ERC721/IERC721Receiver.sol";
import {IERC1155Receiver} from "../token/ERC1155/IERC1155Receiver.sol";
import {EIP712} from "../utils/cryptography/EIP712.sol";
import {SignatureChecker} from "../utils/cryptography/SignatureChecker.sol";
import {IERC165, ERC165} from "../utils/introspection/ERC165.sol";
import {SafeCast} from "../utils/math/SafeCast.sol";
import {DoubleEndedQueue} from "../utils/structs/DoubleEndedQueue.sol";
import {Address} from "../utils/Address.sol";
import {Context} from "../utils/Context.sol";
import {Nonces} from "../utils/Nonces.sol";
import {IGovernor, IERC6372} from "./IGovernor.sol";
/**
* @dev Core of the governance system, designed to be extended through various modules.
*
* This contract is abstract and requires several functions to be implemented in various modules:
*
* - A counting module must implement {quorum}, {_quorumReached}, {_voteSucceeded} and {_countVote}
* - A voting module must implement {_getVotes}
* - Additionally, {votingPeriod} must also be implemented
*/
abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC721Receiver, IERC1155Receiver {
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
bytes32 public constant BALLOT_TYPEHASH =
keccak256("Ballot(uint256 proposalId,uint8 support,address voter,uint256 nonce)");
bytes32 public constant EXTENDED_BALLOT_TYPEHASH =
keccak256(
"ExtendedBallot(uint256 proposalId,uint8 support,address voter,uint256 nonce,string reason,bytes params)"
);
struct ProposalCore {
address proposer;
uint48 voteStart;
uint32 voteDuration;
bool executed;
bool canceled;
uint48 etaSeconds;
}
bytes32 private constant ALL_PROPOSAL_STATES_BITMAP = bytes32((2 ** (uint8(type(ProposalState).max) + 1)) - 1);
string private _name;
mapping(uint256 proposalId => ProposalCore) private _proposals;
// This queue keeps track of the governor operating on itself. Calls to functions protected by the {onlyGovernance}
// modifier needs to be whitelisted in this queue. Whitelisting is set in {execute}, consumed by the
// {onlyGovernance} modifier and eventually reset after {_executeOperations} completes. This ensures that the
// execution of {onlyGovernance} protected calls can only be achieved through successful proposals.
DoubleEndedQueue.Bytes32Deque private _governanceCall;
/**
* @dev Restricts a function so it can only be executed through governance proposals. For example, governance
* parameter setters in {GovernorSettings} are protected using this modifier.
*
* The governance executing address may be different from the Governor's own address, for example it could be a
* timelock. This can be customized by modules by overriding {_executor}. The executor is only able to invoke these
* functions during the execution of the governor's {execute} function, and not under any other circumstances. Thus,
* for example, additional timelock proposers are not able to change governance parameters without going through the
* governance protocol (since v4.6).
*/
modifier onlyGovernance() {
_checkGovernance();
_;
}
/**
* @dev Sets the value for {name} and {version}
*/
constructor(string memory name_) EIP712(name_, version()) {
_name = name_;
}
/**
* @dev Function to receive ETH that will be handled by the governor (disabled if executor is a third party contract)
*/
receive() external payable virtual {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return
interfaceId == type(IGovernor).interfaceId ||
interfaceId == type(IERC1155Receiver).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IGovernor-name}.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev See {IGovernor-version}.
*/
function version() public view virtual returns (string memory) {
return "1";
}
/**
* @dev See {IGovernor-hashProposal}.
*
* The proposal id is produced by hashing the ABI encoded `targets` array, the `values` array, the `calldatas` array
* and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id
* can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in
* advance, before the proposal is submitted.
*
* Note that the chainId and the governor address are not part of the proposal id computation. Consequently, the
* same proposal (with same operation and same description) will have the same id if submitted on multiple governors
* across multiple networks. This also means that in order to execute the same operation twice (on the same
* governor) the proposer will have to change the description in order to avoid proposal id conflicts.
*/
function hashProposal(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public pure virtual returns (uint256) {
return uint256(keccak256(abi.encode(targets, values, calldatas, descriptionHash)));
}
/**
* @dev See {IGovernor-state}.
*/
function state(uint256 proposalId) public view virtual returns (ProposalState) {
// We read the struct fields into the stack at once so Solidity emits a single SLOAD
ProposalCore storage proposal = _proposals[proposalId];
bool proposalExecuted = proposal.executed;
bool proposalCanceled = proposal.canceled;
if (proposalExecuted) {
return ProposalState.Executed;
}
if (proposalCanceled) {
return ProposalState.Canceled;
}
uint256 snapshot = proposalSnapshot(proposalId);
if (snapshot == 0) {
revert GovernorNonexistentProposal(proposalId);
}
uint256 currentTimepoint = clock();
if (snapshot >= currentTimepoint) {
return ProposalState.Pending;
}
uint256 deadline = proposalDeadline(proposalId);
if (deadline >= currentTimepoint) {
return ProposalState.Active;
} else if (!_quorumReached(proposalId) || !_voteSucceeded(proposalId)) {
return ProposalState.Defeated;
} else if (proposalEta(proposalId) == 0) {
return ProposalState.Succeeded;
} else {
return ProposalState.Queued;
}
}
/**
* @dev See {IGovernor-proposalThreshold}.
*/
function proposalThreshold() public view virtual returns (uint256) {
return 0;
}
/**
* @dev See {IGovernor-proposalSnapshot}.
*/
function proposalSnapshot(uint256 proposalId) public view virtual returns (uint256) {
return _proposals[proposalId].voteStart;
}
/**
* @dev See {IGovernor-proposalDeadline}.
*/
function proposalDeadline(uint256 proposalId) public view virtual returns (uint256) {
return _proposals[proposalId].voteStart + _proposals[proposalId].voteDuration;
}
/**
* @dev See {IGovernor-proposalProposer}.
*/
function proposalProposer(uint256 proposalId) public view virtual returns (address) {
return _proposals[proposalId].proposer;
}
/**
* @dev See {IGovernor-proposalEta}.
*/
function proposalEta(uint256 proposalId) public view virtual returns (uint256) {
return _proposals[proposalId].etaSeconds;
}
/**
* @dev See {IGovernor-proposalNeedsQueuing}.
*/
function proposalNeedsQueuing(uint256) public view virtual returns (bool) {
return false;
}
/**
* @dev Reverts if the `msg.sender` is not the executor. In case the executor is not this contract
* itself, the function reverts if `msg.data` is not whitelisted as a result of an {execute}
* operation. See {onlyGovernance}.
*/
function _checkGovernance() internal virtual {
if (_executor() != _msgSender()) {
revert GovernorOnlyExecutor(_msgSender());
}
if (_executor() != address(this)) {
bytes32 msgDataHash = keccak256(_msgData());
// loop until popping the expected operation - throw if deque is empty (operation not authorized)
while (_governanceCall.popFront() != msgDataHash) {}
}
}
/**
* @dev Amount of votes already cast passes the threshold limit.
*/
function _quorumReached(uint256 proposalId) internal view virtual returns (bool);
/**
* @dev Is the proposal successful or not.
*/
function _voteSucceeded(uint256 proposalId) internal view virtual returns (bool);
/**
* @dev Get the voting weight of `account` at a specific `timepoint`, for a vote as described by `params`.
*/
function _getVotes(address account, uint256 timepoint, bytes memory params) internal view virtual returns (uint256);
/**
* @dev Register a vote for `proposalId` by `account` with a given `support`, voting `weight` and voting `params`.
*
* Note: Support is generic and can represent various things depending on the voting system used.
*/
function _countVote(
uint256 proposalId,
address account,
uint8 support,
uint256 weight,
bytes memory params
) internal virtual;
/**
* @dev Default additional encoded parameters used by castVote methods that don't include them
*
* Note: Should be overridden by specific implementations to use an appropriate value, the
* meaning of the additional params, in the context of that implementation
*/
function _defaultParams() internal view virtual returns (bytes memory) {
return "";
}
/**
* @dev See {IGovernor-propose}. This function has opt-in frontrunning protection, described in {_isValidDescriptionForProposer}.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual returns (uint256) {
address proposer = _msgSender();
// check description restriction
if (!_isValidDescriptionForProposer(proposer, description)) {
revert GovernorRestrictedProposer(proposer);
}
// check proposal threshold
uint256 proposerVotes = getVotes(proposer, clock() - 1);
uint256 votesThreshold = proposalThreshold();
if (proposerVotes < votesThreshold) {
revert GovernorInsufficientProposerVotes(proposer, proposerVotes, votesThreshold);
}
return _propose(targets, values, calldatas, description, proposer);
}
/**
* @dev Internal propose mechanism. Can be overridden to add more logic on proposal creation.
*
* Emits a {IGovernor-ProposalCreated} event.
*/
function _propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description,
address proposer
) internal virtual returns (uint256 proposalId) {
proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
if (targets.length != values.length || targets.length != calldatas.length || targets.length == 0) {
revert GovernorInvalidProposalLength(targets.length, calldatas.length, values.length);
}
if (_proposals[proposalId].voteStart != 0) {
revert GovernorUnexpectedProposalState(proposalId, state(proposalId), bytes32(0));
}
uint256 snapshot = clock() + votingDelay();
uint256 duration = votingPeriod();
ProposalCore storage proposal = _proposals[proposalId];
proposal.proposer = proposer;
proposal.voteStart = SafeCast.toUint48(snapshot);
proposal.voteDuration = SafeCast.toUint32(duration);
emit ProposalCreated(
proposalId,
proposer,
targets,
values,
new string[](targets.length),
calldatas,
snapshot,
snapshot + duration,
description
);
// Using a named return variable to avoid stack too deep errors
}
/**
* @dev See {IGovernor-queue}.
*/
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Succeeded));
uint48 etaSeconds = _queueOperations(proposalId, targets, values, calldatas, descriptionHash);
if (etaSeconds != 0) {
_proposals[proposalId].etaSeconds = etaSeconds;
emit ProposalQueued(proposalId, etaSeconds);
} else {
revert GovernorQueueNotImplemented();
}
return proposalId;
}
/**
* @dev Internal queuing mechanism. Can be overridden (without a super call) to modify the way queuing is
* performed (for example adding a vault/timelock).
*
* This is empty by default, and must be overridden to implement queuing.
*
* This function returns a timestamp that describes the expected ETA for execution. If the returned value is 0
* (which is the default value), the core will consider queueing did not succeed, and the public {queue} function
* will revert.
*
* NOTE: Calling this function directly will NOT check the current state of the proposal, or emit the
* `ProposalQueued` event. Queuing a proposal should be done using {queue}.
*/
function _queueOperations(
uint256 /*proposalId*/,
address[] memory /*targets*/,
uint256[] memory /*values*/,
bytes[] memory /*calldatas*/,
bytes32 /*descriptionHash*/
) internal virtual returns (uint48) {
return 0;
}
/**
* @dev See {IGovernor-execute}.
*/
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public payable virtual returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
_validateStateBitmap(
proposalId,
_encodeStateBitmap(ProposalState.Succeeded) | _encodeStateBitmap(ProposalState.Queued)
);
// mark as executed before calls to avoid reentrancy
_proposals[proposalId].executed = true;
// before execute: register governance call in queue.
if (_executor() != address(this)) {
for (uint256 i = 0; i < targets.length; ++i) {
if (targets[i] == address(this)) {
_governanceCall.pushBack(keccak256(calldatas[i]));
}
}
}
_executeOperations(proposalId, targets, values, calldatas, descriptionHash);
// after execute: cleanup governance call queue.
if (_executor() != address(this) && !_governanceCall.empty()) {
_governanceCall.clear();
}
emit ProposalExecuted(proposalId);
return proposalId;
}
/**
* @dev Internal execution mechanism. Can be overridden (without a super call) to modify the way execution is
* performed (for example adding a vault/timelock).
*
* NOTE: Calling this function directly will NOT check the current state of the proposal, set the executed flag to
* true or emit the `ProposalExecuted` event. Executing a proposal should be done using {execute} or {_execute}.
*/
function _executeOperations(
uint256 /* proposalId */,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 /*descriptionHash*/
) internal virtual {
for (uint256 i = 0; i < targets.length; ++i) {
(bool success, bytes memory returndata) = targets[i].call{value: values[i]}(calldatas[i]);
Address.verifyCallResult(success, returndata);
}
}
/**
* @dev See {IGovernor-cancel}.
*/
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual returns (uint256) {
// The proposalId will be recomputed in the `_cancel` call further down. However we need the value before we
// do the internal call, because we need to check the proposal state BEFORE the internal `_cancel` call
// changes it. The `hashProposal` duplication has a cost that is limited, and that we accept.
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
// public cancel restrictions (on top of existing _cancel restrictions).
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Pending));
if (_msgSender() != proposalProposer(proposalId)) {
revert GovernorOnlyProposer(_msgSender());
}
return _cancel(targets, values, calldatas, descriptionHash);
}
/**
* @dev Internal cancel mechanism with minimal restrictions. A proposal can be cancelled in any state other than
* Canceled, Expired, or Executed. Once cancelled a proposal can't be re-submitted.
*
* Emits a {IGovernor-ProposalCanceled} event.
*/
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
_validateStateBitmap(
proposalId,
ALL_PROPOSAL_STATES_BITMAP ^
_encodeStateBitmap(ProposalState.Canceled) ^
_encodeStateBitmap(ProposalState.Expired) ^
_encodeStateBitmap(ProposalState.Executed)
);
_proposals[proposalId].canceled = true;
emit ProposalCanceled(proposalId);
return proposalId;
}
/**
* @dev See {IGovernor-getVotes}.
*/
function getVotes(address account, uint256 timepoint) public view virtual returns (uint256) {
return _getVotes(account, timepoint, _defaultParams());
}
/**
* @dev See {IGovernor-getVotesWithParams}.
*/
function getVotesWithParams(
address account,
uint256 timepoint,
bytes memory params
) public view virtual returns (uint256) {
return _getVotes(account, timepoint, params);
}
/**
* @dev See {IGovernor-castVote}.
*/
function castVote(uint256 proposalId, uint8 support) public virtual returns (uint256) {
address voter = _msgSender();
return _castVote(proposalId, voter, support, "");
}
/**
* @dev See {IGovernor-castVoteWithReason}.
*/
function castVoteWithReason(
uint256 proposalId,
uint8 support,
string calldata reason
) public virtual returns (uint256) {
address voter = _msgSender();
return _castVote(proposalId, voter, support, reason);
}
/**
* @dev See {IGovernor-castVoteWithReasonAndParams}.
*/
function castVoteWithReasonAndParams(
uint256 proposalId,
uint8 support,
string calldata reason,
bytes memory params
) public virtual returns (uint256) {
address voter = _msgSender();
return _castVote(proposalId, voter, support, reason, params);
}
/**
* @dev See {IGovernor-castVoteBySig}.
*/
function castVoteBySig(
uint256 proposalId,
uint8 support,
address voter,
bytes memory signature
) public virtual returns (uint256) {
bool valid = SignatureChecker.isValidSignatureNow(
voter,
_hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support, voter, _useNonce(voter)))),
signature
);
if (!valid) {
revert GovernorInvalidSignature(voter);
}
return _castVote(proposalId, voter, support, "");
}
/**
* @dev See {IGovernor-castVoteWithReasonAndParamsBySig}.
*/
function castVoteWithReasonAndParamsBySig(
uint256 proposalId,
uint8 support,
address voter,
string calldata reason,
bytes memory params,
bytes memory signature
) public virtual returns (uint256) {
bool valid = SignatureChecker.isValidSignatureNow(
voter,
_hashTypedDataV4(
keccak256(
abi.encode(
EXTENDED_BALLOT_TYPEHASH,
proposalId,
support,
voter,
_useNonce(voter),
keccak256(bytes(reason)),
keccak256(params)
)
)
),
signature
);
if (!valid) {
revert GovernorInvalidSignature(voter);
}
return _castVote(proposalId, voter, support, reason, params);
}
/**
* @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve
* voting weight using {IGovernor-getVotes} and call the {_countVote} internal function. Uses the _defaultParams().
*
* Emits a {IGovernor-VoteCast} event.
*/
function _castVote(
uint256 proposalId,
address account,
uint8 support,
string memory reason
) internal virtual returns (uint256) {
return _castVote(proposalId, account, support, reason, _defaultParams());
}
/**
* @dev Internal vote casting mechanism: Check that the vote is pending, that it has not been cast yet, retrieve
* voting weight using {IGovernor-getVotes} and call the {_countVote} internal function.
*
* Emits a {IGovernor-VoteCast} event.
*/
function _castVote(
uint256 proposalId,
address account,
uint8 support,
string memory reason,
bytes memory params
) internal virtual returns (uint256) {
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Active));
uint256 weight = _getVotes(account, proposalSnapshot(proposalId), params);
_countVote(proposalId, account, support, weight, params);
if (params.length == 0) {
emit VoteCast(account, proposalId, support, weight, reason);
} else {
emit VoteCastWithParams(account, proposalId, support, weight, reason, params);
}
return weight;
}
/**
* @dev Relays a transaction or function call to an arbitrary target. In cases where the governance executor
* is some contract other than the governor itself, like when using a timelock, this function can be invoked
* in a governance proposal to recover tokens or Ether that was sent to the governor contract by mistake.
* Note that if the executor is simply the governor itself, use of `relay` is redundant.
*/
function relay(address target, uint256 value, bytes calldata data) external payable virtual onlyGovernance {
(bool success, bytes memory returndata) = target.call{value: value}(data);
Address.verifyCallResult(success, returndata);
}
/**
* @dev Address through which the governor executes action. Will be overloaded by module that execute actions
* through another contract such as a timelock.
*/
function _executor() internal view virtual returns (address) {
return address(this);
}
/**
* @dev See {IERC721Receiver-onERC721Received}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC721Received.selector;
}
/**
* @dev See {IERC1155Receiver-onERC1155Received}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC1155Received.selector;
}
/**
* @dev See {IERC1155Receiver-onERC1155BatchReceived}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC1155BatchReceived.selector;
}
/**
* @dev Encodes a `ProposalState` into a `bytes32` representation where each bit enabled corresponds to
* the underlying position in the `ProposalState` enum. For example:
*
* 0x000...10000
* ^^^^^^------ ...
* ^----- Succeeded
* ^---- Defeated
* ^--- Canceled
* ^-- Active
* ^- Pending
*/
function _encodeStateBitmap(ProposalState proposalState) internal pure returns (bytes32) {
return bytes32(1 << uint8(proposalState));
}
/**
* @dev Check that the current state of a proposal matches the requirements described by the `allowedStates` bitmap.
* This bitmap should be built using `_encodeStateBitmap`.
*
* If requirements are not met, reverts with a {GovernorUnexpectedProposalState} error.
*/
function _validateStateBitmap(uint256 proposalId, bytes32 allowedStates) private view returns (ProposalState) {
ProposalState currentState = state(proposalId);
if (_encodeStateBitmap(currentState) & allowedStates == bytes32(0)) {
revert GovernorUnexpectedProposalState(proposalId, currentState, allowedStates);
}
return currentState;
}
/*
* @dev Check if the proposer is authorized to submit a proposal with the given description.
*
* If the proposal description ends with `#proposer=0x???`, where `0x???` is an address written as a hex string
* (case insensitive), then the submission of this proposal will only be authorized to said address.
*
* This is used for frontrunning protection. By adding this pattern at the end of their proposal, one can ensure
* that no other address can submit the same proposal. An attacker would have to either remove or change that part,
* which would result in a different proposal id.
*
* If the description does not match this pattern, it is unrestricted and anyone can submit it. This includes:
* - If the `0x???` part is not a valid hex string.
* - If the `0x???` part is a valid hex string, but does not contain exactly 40 hex digits.
* - If it ends with the expected suffix followed by newlines or other whitespace.
* - If it ends with some other similar suffix, e.g. `#other=abc`.
* - If it does not end with any such suffix.
*/
function _isValidDescriptionForProposer(
address proposer,
string memory description
) internal view virtual returns (bool) {
uint256 len = bytes(description).length;
// Length is too short to contain a valid proposer suffix
if (len < 52) {
return true;
}
// Extract what would be the `#proposer=0x` marker beginning the suffix
bytes12 marker;
assembly {
// - Start of the string contents in memory = description + 32
// - First character of the marker = len - 52
// - Length of "#proposer=0x0000000000000000000000000000000000000000" = 52
// - We read the memory word starting at the first character of the marker:
// - (description + 32) + (len - 52) = description + (len - 20)
// - Note: Solidity will ignore anything past the first 12 bytes
marker := mload(add(description, sub(len, 20)))
}
// If the marker is not found, there is no proposer suffix to check
if (marker != bytes12("#proposer=0x")) {
return true;
}
// Parse the 40 characters following the marker as uint160
uint160 recovered = 0;
for (uint256 i = len - 40; i < len; ++i) {
(bool isHex, uint8 value) = _tryHexToUint(bytes(description)[i]);
// If any of the characters is not a hex digit, ignore the suffix entirely
if (!isHex) {
return true;
}
recovered = (recovered << 4) | value;
}
return recovered == uint160(proposer);
}
/**
* @dev Try to parse a character from a string as a hex value. Returns `(true, value)` if the char is in
* `[0-9a-fA-F]` and `(false, 0)` otherwise. Value is guaranteed to be in the range `0 <= value < 16`
*/
function _tryHexToUint(bytes1 char) private pure returns (bool, uint8) {
uint8 c = uint8(char);
unchecked {
// Case 0-9
if (47 < c && c < 58) {
return (true, c - 48);
}
// Case A-F
else if (64 < c && c < 71) {
return (true, c - 55);
}
// Case a-f
else if (96 < c && c < 103) {
return (true, c - 87);
}
// Else: not a hex char
else {
return (false, 0);
}
}
}
/**
* @inheritdoc IERC6372
*/
function clock() public view virtual returns (uint48);
/**
* @inheritdoc IERC6372
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public view virtual returns (string memory);
/**
* @inheritdoc IGovernor
*/
function votingDelay() public view virtual returns (uint256);
/**
* @inheritdoc IGovernor
*/
function votingPeriod() public view virtual returns (uint256);
/**
* @inheritdoc IGovernor
*/
function quorum(uint256 timepoint) public view virtual returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/extensions/GovernorSettings.sol)
pragma solidity ^0.8.20;
import {Governor} from "../Governor.sol";
/**
* @dev Extension of {Governor} for settings updatable through governance.
*/
abstract contract GovernorSettings is Governor {
// amount of token
uint256 private _proposalThreshold;
// timepoint: limited to uint48 in core (same as clock() type)
uint48 private _votingDelay;
// duration: limited to uint32 in core
uint32 private _votingPeriod;
event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);
event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);
event ProposalThresholdSet(uint256 oldProposalThreshold, uint256 newProposalThreshold);
/**
* @dev Initialize the governance parameters.
*/
constructor(uint48 initialVotingDelay, uint32 initialVotingPeriod, uint256 initialProposalThreshold) {
_setVotingDelay(initialVotingDelay);
_setVotingPeriod(initialVotingPeriod);
_setProposalThreshold(initialProposalThreshold);
}
/**
* @dev See {IGovernor-votingDelay}.
*/
function votingDelay() public view virtual override returns (uint256) {
return _votingDelay;
}
/**
* @dev See {IGovernor-votingPeriod}.
*/
function votingPeriod() public view virtual override returns (uint256) {
return _votingPeriod;
}
/**
* @dev See {Governor-proposalThreshold}.
*/
function proposalThreshold() public view virtual override returns (uint256) {
return _proposalThreshold;
}
/**
* @dev Update the voting delay. This operation can only be performed through a governance proposal.
*
* Emits a {VotingDelaySet} event.
*/
function setVotingDelay(uint48 newVotingDelay) public virtual onlyGovernance {
_setVotingDelay(newVotingDelay);
}
/**
* @dev Update the voting period. This operation can only be performed through a governance proposal.
*
* Emits a {VotingPeriodSet} event.
*/
function setVotingPeriod(uint32 newVotingPeriod) public virtual onlyGovernance {
_setVotingPeriod(newVotingPeriod);
}
/**
* @dev Update the proposal threshold. This operation can only be performed through a governance proposal.
*
* Emits a {ProposalThresholdSet} event.
*/
function setProposalThreshold(uint256 newProposalThreshold) public virtual onlyGovernance {
_setProposalThreshold(newProposalThreshold);
}
/**
* @dev Internal setter for the voting delay.
*
* Emits a {VotingDelaySet} event.
*/
function _setVotingDelay(uint48 newVotingDelay) internal virtual {
emit VotingDelaySet(_votingDelay, newVotingDelay);
_votingDelay = newVotingDelay;
}
/**
* @dev Internal setter for the voting period.
*
* Emits a {VotingPeriodSet} event.
*/
function _setVotingPeriod(uint32 newVotingPeriod) internal virtual {
if (newVotingPeriod == 0) {
revert GovernorInvalidVotingPeriod(0);
}
emit VotingPeriodSet(_votingPeriod, newVotingPeriod);
_votingPeriod = newVotingPeriod;
}
/**
* @dev Internal setter for the proposal threshold.
*
* Emits a {ProposalThresholdSet} event.
*/
function _setProposalThreshold(uint256 newProposalThreshold) internal virtual {
emit ProposalThresholdSet(_proposalThreshold, newProposalThreshold);
_proposalThreshold = newProposalThreshold;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/extensions/GovernorCountingSimple.sol)
pragma solidity ^0.8.20;
import {Governor} from "../Governor.sol";
/**
* @dev Extension of {Governor} for simple, 3 options, vote counting.
*/
abstract contract GovernorCountingSimple is Governor {
/**
* @dev Supported vote types. Matches Governor Bravo ordering.
*/
enum VoteType {
Against,
For,
Abstain
}
struct ProposalVote {
uint256 againstVotes;
uint256 forVotes;
uint256 abstainVotes;
mapping(address voter => bool) hasVoted;
}
mapping(uint256 proposalId => ProposalVote) private _proposalVotes;
/**
* @dev See {IGovernor-COUNTING_MODE}.
*/
// solhint-disable-next-line func-name-mixedcase
function COUNTING_MODE() public pure virtual override returns (string memory) {
return "support=bravo&quorum=for,abstain";
}
/**
* @dev See {IGovernor-hasVoted}.
*/
function hasVoted(uint256 proposalId, address account) public view virtual override returns (bool) {
return _proposalVotes[proposalId].hasVoted[account];
}
/**
* @dev Accessor to the internal vote counts.
*/
function proposalVotes(
uint256 proposalId
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) {
ProposalVote storage proposalVote = _proposalVotes[proposalId];
return (proposalVote.againstVotes, proposalVote.forVotes, proposalVote.abstainVotes);
}
/**
* @dev See {Governor-_quorumReached}.
*/
function _quorumReached(uint256 proposalId) internal view virtual override returns (bool) {
ProposalVote storage proposalVote = _proposalVotes[proposalId];
return quorum(proposalSnapshot(proposalId)) <= proposalVote.forVotes + proposalVote.abstainVotes;
}
/**
* @dev See {Governor-_voteSucceeded}. In this module, the forVotes must be strictly over the againstVotes.
*/
function _voteSucceeded(uint256 proposalId) internal view virtual override returns (bool) {
ProposalVote storage proposalVote = _proposalVotes[proposalId];
return proposalVote.forVotes > proposalVote.againstVotes;
}
/**
* @dev See {Governor-_countVote}. In this module, the support follows the `VoteType` enum (from Governor Bravo).
*/
function _countVote(
uint256 proposalId,
address account,
uint8 support,
uint256 weight,
bytes memory // params
) internal virtual override {
ProposalVote storage proposalVote = _proposalVotes[proposalId];
if (proposalVote.hasVoted[account]) {
revert GovernorAlreadyCastVote(account);
}
proposalVote.hasVoted[account] = true;
if (support == uint8(VoteType.Against)) {
proposalVote.againstVotes += weight;
} else if (support == uint8(VoteType.For)) {
proposalVote.forVotes += weight;
} else if (support == uint8(VoteType.Abstain)) {
proposalVote.abstainVotes += weight;
} else {
revert GovernorInvalidVoteType();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/extensions/GovernorVotes.sol)
pragma solidity ^0.8.20;
import {Governor} from "../Governor.sol";
import {IVotes} from "../utils/IVotes.sol";
import {IERC5805} from "../../interfaces/IERC5805.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Time} from "../../utils/types/Time.sol";
/**
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes}
* token.
*/
abstract contract GovernorVotes is Governor {
IERC5805 private immutable _token;
constructor(IVotes tokenAddress) {
_token = IERC5805(address(tokenAddress));
}
/**
* @dev The token that voting power is sourced from.
*/
function token() public view virtual returns (IERC5805) {
return _token;
}
/**
* @dev Clock (as specified in EIP-6372) is set to match the token's clock. Fallback to block numbers if the token
* does not implement EIP-6372.
*/
function clock() public view virtual override returns (uint48) {
try token().clock() returns (uint48 timepoint) {
return timepoint;
} catch {
return Time.blockNumber();
}
}
/**
* @dev Machine-readable description of the clock as specified in EIP-6372.
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public view virtual override returns (string memory) {
try token().CLOCK_MODE() returns (string memory clockmode) {
return clockmode;
} catch {
return "mode=blocknumber&from=default";
}
}
/**
* Read the voting weight from the token's built in snapshot mechanism (see {Governor-_getVotes}).
*/
function _getVotes(
address account,
uint256 timepoint,
bytes memory /*params*/
) internal view virtual override returns (uint256) {
return token().getPastVotes(account, timepoint);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
pragma solidity ^0.8.20;
import {GovernorVotes} from "./GovernorVotes.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
/**
* @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a
* fraction of the total supply.
*/
abstract contract GovernorVotesQuorumFraction is GovernorVotes {
using Checkpoints for Checkpoints.Trace208;
Checkpoints.Trace208 private _quorumNumeratorHistory;
event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator);
/**
* @dev The quorum set is not a valid fraction.
*/
error GovernorInvalidQuorumFraction(uint256 quorumNumerator, uint256 quorumDenominator);
/**
* @dev Initialize quorum as a fraction of the token's total supply.
*
* The fraction is specified as `numerator / denominator`. By default the denominator is 100, so quorum is
* specified as a percent: a numerator of 10 corresponds to quorum being 10% of total supply. The denominator can be
* customized by overriding {quorumDenominator}.
*/
constructor(uint256 quorumNumeratorValue) {
_updateQuorumNumerator(quorumNumeratorValue);
}
/**
* @dev Returns the current quorum numerator. See {quorumDenominator}.
*/
function quorumNumerator() public view virtual returns (uint256) {
return _quorumNumeratorHistory.latest();
}
/**
* @dev Returns the quorum numerator at a specific timepoint. See {quorumDenominator}.
*/
function quorumNumerator(uint256 timepoint) public view virtual returns (uint256) {
uint256 length = _quorumNumeratorHistory._checkpoints.length;
// Optimistic search, check the latest checkpoint
Checkpoints.Checkpoint208 storage latest = _quorumNumeratorHistory._checkpoints[length - 1];
uint48 latestKey = latest._key;
uint208 latestValue = latest._value;
if (latestKey <= timepoint) {
return latestValue;
}
// Otherwise, do the binary search
return _quorumNumeratorHistory.upperLookupRecent(SafeCast.toUint48(timepoint));
}
/**
* @dev Returns the quorum denominator. Defaults to 100, but may be overridden.
*/
function quorumDenominator() public view virtual returns (uint256) {
return 100;
}
/**
* @dev Returns the quorum for a timepoint, in terms of number of votes: `supply * numerator / denominator`.
*/
function quorum(uint256 timepoint) public view virtual override returns (uint256) {
return (token().getPastTotalSupply(timepoint) * quorumNumerator(timepoint)) / quorumDenominator();
}
/**
* @dev Changes the quorum numerator.
*
* Emits a {QuorumNumeratorUpdated} event.
*
* Requirements:
*
* - Must be called through a governance proposal.
* - New numerator must be smaller or equal to the denominator.
*/
function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance {
_updateQuorumNumerator(newQuorumNumerator);
}
/**
* @dev Changes the quorum numerator.
*
* Emits a {QuorumNumeratorUpdated} event.
*
* Requirements:
*
* - New numerator must be smaller or equal to the denominator.
*/
function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {
uint256 denominator = quorumDenominator();
if (newQuorumNumerator > denominator) {
revert GovernorInvalidQuorumFraction(newQuorumNumerator, denominator);
}
uint256 oldQuorumNumerator = quorumNumerator();
_quorumNumeratorHistory.push(clock(), SafeCast.toUint208(newQuorumNumerator));
emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/extensions/GovernorTimelockControl.sol)
pragma solidity ^0.8.20;
import {IGovernor, Governor} from "../Governor.sol";
import {TimelockController} from "../TimelockController.sol";
import {IERC165} from "../../interfaces/IERC165.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
/**
* @dev Extension of {Governor} that binds the execution process to an instance of {TimelockController}. This adds a
* delay, enforced by the {TimelockController} to all successful proposal (in addition to the voting duration). The
* {Governor} needs the proposer (and ideally the executor) roles for the {Governor} to work properly.
*
* Using this model means the proposal will be operated by the {TimelockController} and not by the {Governor}. Thus,
* the assets and permissions must be attached to the {TimelockController}. Any asset sent to the {Governor} will be
* inaccessible from a proposal, unless executed via {Governor-relay}.
*
* WARNING: Setting up the TimelockController to have additional proposers or cancellers besides the governor is very
* risky, as it grants them the ability to: 1) execute operations as the timelock, and thus possibly performing
* operations or accessing funds that are expected to only be accessible through a vote, and 2) block governance
* proposals that have been approved by the voters, effectively executing a Denial of Service attack.
*
* NOTE: `AccessManager` does not support scheduling more than one operation with the same target and calldata at
* the same time. See {AccessManager-schedule} for a workaround.
*/
abstract contract GovernorTimelockControl is Governor {
TimelockController private _timelock;
mapping(uint256 proposalId => bytes32) private _timelockIds;
/**
* @dev Emitted when the timelock controller used for proposal execution is modified.
*/
event TimelockChange(address oldTimelock, address newTimelock);
/**
* @dev Set the timelock.
*/
constructor(TimelockController timelockAddress) {
_updateTimelock(timelockAddress);
}
/**
* @dev Overridden version of the {Governor-state} function that considers the status reported by the timelock.
*/
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
ProposalState currentState = super.state(proposalId);
if (currentState != ProposalState.Queued) {
return currentState;
}
bytes32 queueid = _timelockIds[proposalId];
if (_timelock.isOperationPending(queueid)) {
return ProposalState.Queued;
} else if (_timelock.isOperationDone(queueid)) {
// This can happen if the proposal is executed directly on the timelock.
return ProposalState.Executed;
} else {
// This can happen if the proposal is canceled directly on the timelock.
return ProposalState.Canceled;
}
}
/**
* @dev Public accessor to check the address of the timelock
*/
function timelock() public view virtual returns (address) {
return address(_timelock);
}
/**
* @dev See {IGovernor-proposalNeedsQueuing}.
*/
function proposalNeedsQueuing(uint256) public view virtual override returns (bool) {
return true;
}
/**
* @dev Function to queue a proposal to the timelock.
*/
function _queueOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override returns (uint48) {
uint256 delay = _timelock.getMinDelay();
bytes32 salt = _timelockSalt(descriptionHash);
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, salt);
_timelock.scheduleBatch(targets, values, calldatas, 0, salt, delay);
return SafeCast.toUint48(block.timestamp + delay);
}
/**
* @dev Overridden version of the {Governor-_executeOperations} function that runs the already queued proposal
* through the timelock.
*/
function _executeOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override {
// execute
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, _timelockSalt(descriptionHash));
// cleanup for refund
delete _timelockIds[proposalId];
}
/**
* @dev Overridden version of the {Governor-_cancel} function to cancel the timelocked proposal if it has already
* been queued.
*/
// This function can reenter through the external call to the timelock, but we assume the timelock is trusted and
// well behaved (according to TimelockController) and this will not happen.
// slither-disable-next-line reentrancy-no-eth
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override returns (uint256) {
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
bytes32 timelockId = _timelockIds[proposalId];
if (timelockId != 0) {
// cancel
_timelock.cancel(timelockId);
// cleanup
delete _timelockIds[proposalId];
}
return proposalId;
}
/**
* @dev Address through which the governor executes action. In this case, the timelock.
*/
function _executor() internal view virtual override returns (address) {
return address(_timelock);
}
/**
* @dev Public endpoint to update the underlying timelock instance. Restricted to the timelock itself, so updates
* must be proposed, scheduled, and executed through governance proposals.
*
* CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.
*/
function updateTimelock(TimelockController newTimelock) external virtual onlyGovernance {
_updateTimelock(newTimelock);
}
function _updateTimelock(TimelockController newTimelock) private {
emit TimelockChange(address(_timelock), address(newTimelock));
_timelock = newTimelock;
}
/**
* @dev Computes the {TimelockController} operation salt.
*
* It is computed with the governor address itself to avoid collisions across governor instances using the
* same timelock.
*/
function _timelockSalt(bytes32 descriptionHash) private view returns (bytes32) {
return bytes20(address(this)) ^ descriptionHash;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.20;
/**
* @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
*/
interface IVotes {
/**
* @dev The signature used has expired.
*/
error VotesExpiredSignature(uint256 expiry);
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/**
* @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of voting units.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes);
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*/
function getPastVotes(address account, uint256 timepoint) external view returns (uint256);
/**
* @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*/
function getPastTotalSupply(uint256 timepoint) external view returns (uint256);
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) external view returns (address);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) external;
/**
* @dev Delegates votes from signer to `delegatee`.
*/
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;
import { Ownable } from "@openzeppelin/access/Ownable.sol";
import { Math } from "@openzeppelin/utils/math/Math.sol";
import { SafeTransferLib, ERC20 } from "@solmate/utils/SafeTransferLib.sol";
import { ITokenFactory } from "src/interfaces/ITokenFactory.sol";
import { IGovernanceFactory } from "src/interfaces/IGovernanceFactory.sol";
import { IPoolInitializer } from "src/interfaces/IPoolInitializer.sol";
import { ILiquidityMigrator } from "src/interfaces/ILiquidityMigrator.sol";
import { DERC20 } from "src/DERC20.sol";
enum ModuleState {
NotWhitelisted,
TokenFactory,
GovernanceFactory,
PoolInitializer,
LiquidityMigrator
}
/// @notice Thrown when the module state is not the expected one
error WrongModuleState(address module, ModuleState expected, ModuleState actual);
/// @notice Thrown when the lengths of two arrays do not match
error ArrayLengthsMismatch();
/**
* @notice Data related to the asset token
* @param numeraire Address of the numeraire token
* @param timelock Address of the timelock contract
* @param governance Address of the governance contract
* @param liquidityMigrator Address of the liquidity migrator contract
* @param poolInitializer Address of the pool initializer contract
* @param pool Address of the liquidity pool
* @param migrationPool Address of the liquidity pool after migration
* @param numTokensToSell Amount of tokens to sell
* @param totalSupply Total supply of the token
* @param integrator Address of the front-end integrator
*/
struct AssetData {
address numeraire;
address timelock;
address governance;
ILiquidityMigrator liquidityMigrator;
IPoolInitializer poolInitializer;
address pool;
address migrationPool;
uint256 numTokensToSell;
uint256 totalSupply;
address integrator;
}
/**
* @notice Data used to create a new asset token
* @param initialSupply Total supply of the token (might be increased later on)
* @param numTokensToSell Amount of tokens to sell in the Doppler hook
* @param numeraire Address of the numeraire token
* @param tokenFactory Address of the factory contract deploying the ERC20 token
* @param tokenFactoryData Arbitrary data to pass to the token factory
* @param governanceFactory Address of the factory contract deploying the governance
* @param governanceFactoryData Arbitrary data to pass to the governance factory
* @param poolInitializer Address of the pool initializer contract
* @param poolInitializerData Arbitrary data to pass to the pool initializer
* @param liquidityMigrator Address of the liquidity migrator contract
* @param integrator Address of the front-end integrator
* @param salt Salt used by the different factories to deploy the contracts using CREATE2
*/
struct CreateParams {
uint256 initialSupply;
uint256 numTokensToSell;
address numeraire;
ITokenFactory tokenFactory;
bytes tokenFactoryData;
IGovernanceFactory governanceFactory;
bytes governanceFactoryData;
IPoolInitializer poolInitializer;
bytes poolInitializerData;
ILiquidityMigrator liquidityMigrator;
bytes liquidityMigratorData;
address integrator;
bytes32 salt;
}
/**
* @notice Emitted when a new asset token is created
* @param asset Address of the asset token
* @param numeraire Address of the numeraire token
* @param initializer Address of the pool initializer contract, either based on uniswapV3 or uniswapV4
* @param poolOrHook Address of the liquidity pool (if uniswapV3) or hook (if uniswapV4)
*/
event Create(address asset, address indexed numeraire, address initializer, address poolOrHook);
/**
* @notice Emitted when an asset token is migrated
* @param asset Address of the asset token
* @param pool Address of the liquidity pool
*/
event Migrate(address indexed asset, address indexed pool);
/**
* @notice Emitted when the state of a module is set
* @param module Address of the module
* @param state State of the module
*/
event SetModuleState(address indexed module, ModuleState indexed state);
/**
* @notice Emitted when fees are collected, either protocol or integrator
* @param to Address receiving the fees
* @param token Token from which the fees are collected
* @param amount Amount of fees collected
*/
event Collect(address indexed to, address indexed token, uint256 amount);
/// @custom:security-contact [email protected]
contract Airlock is Ownable {
using SafeTransferLib for ERC20;
mapping(address module => ModuleState state) public getModuleState;
mapping(address asset => AssetData data) public getAssetData;
mapping(address token => uint256 amount) public getProtocolFees;
mapping(address integrator => mapping(address token => uint256 amount)) public getIntegratorFees;
receive() external payable { }
/**
* @param owner_ Address receiving the ownership of the Airlock contract
*/
constructor(
address owner_
) Ownable(owner_) { }
/**
* @notice Deploys a new token with the associated governance, timelock and hook contracts
* @param createData Data used to create the new token (see `CreateParams` struct)
* @return asset Address of the deployed asset token
* @return pool Address of the created liquidity pool
* @return governance Address of the deployed governance contract
* @return timelock Address of the deployed timelock contract
* @return migrationPool Address of the created migration pool
*/
function create(
CreateParams calldata createData
) external returns (address asset, address pool, address governance, address timelock, address migrationPool) {
_validateModuleState(address(createData.tokenFactory), ModuleState.TokenFactory);
_validateModuleState(address(createData.governanceFactory), ModuleState.GovernanceFactory);
_validateModuleState(address(createData.poolInitializer), ModuleState.PoolInitializer);
_validateModuleState(address(createData.liquidityMigrator), ModuleState.LiquidityMigrator);
asset = createData.tokenFactory.create(
createData.initialSupply, address(this), address(this), createData.salt, createData.tokenFactoryData
);
(governance, timelock) = createData.governanceFactory.create(asset, createData.governanceFactoryData);
ERC20(asset).approve(address(createData.poolInitializer), createData.numTokensToSell);
pool = createData.poolInitializer.initialize(
asset, createData.numeraire, createData.numTokensToSell, createData.salt, createData.poolInitializerData
);
migrationPool =
createData.liquidityMigrator.initialize(asset, createData.numeraire, createData.liquidityMigratorData);
DERC20(asset).lockPool(migrationPool);
uint256 excessAsset = ERC20(asset).balanceOf(address(this));
if (excessAsset > 0) {
ERC20(asset).safeTransfer(timelock, excessAsset);
}
getAssetData[asset] = AssetData({
numeraire: createData.numeraire,
timelock: timelock,
governance: governance,
liquidityMigrator: createData.liquidityMigrator,
poolInitializer: createData.poolInitializer,
pool: pool,
migrationPool: migrationPool,
numTokensToSell: createData.numTokensToSell,
totalSupply: createData.initialSupply,
integrator: createData.integrator == address(0) ? owner() : createData.integrator
});
emit Create(asset, createData.numeraire, address(createData.poolInitializer), pool);
}
/**
* @notice Triggers the migration from the initial liquidity pool to the next one
* @dev Since anyone can call this function, the conditions for the migration are checked by the
* `poolInitializer` contract
* @param asset Address of the token to migrate
*/
function migrate(
address asset
) external {
AssetData memory assetData = getAssetData[asset];
DERC20(asset).unlockPool();
Ownable(asset).transferOwnership(assetData.timelock);
(
uint160 sqrtPriceX96,
address token0,
uint128 fees0,
uint128 balance0,
address token1,
uint128 fees1,
uint128 balance1
) = assetData.poolInitializer.exitLiquidity(assetData.pool);
_handleFees(token0, assetData.integrator, balance0, fees0);
_handleFees(token1, assetData.integrator, balance1, fees1);
address liquidityMigrator = address(assetData.liquidityMigrator);
if (token0 == address(0)) {
SafeTransferLib.safeTransferETH(liquidityMigrator, balance0 - fees0);
} else {
ERC20(token0).safeTransfer(liquidityMigrator, balance0 - fees0);
}
ERC20(token1).safeTransfer(liquidityMigrator, balance1 - fees1);
assetData.liquidityMigrator.migrate(sqrtPriceX96, token0, token1, assetData.timelock);
emit Migrate(asset, assetData.migrationPool);
}
/**
* @dev Computes and stores the protocol and integrators fees. Protocol fees are either 5% of the
* trading fees or 0.1% of the proceeds (token balance excluding fees) capped at a maximum of 20%
* of the trading fees
* @param token Address of the token to handle fees from
* @param integrator Address of the integrator to handle fees from
* @param balance Balance of the token including fees
* @param fees Trading fees
*/
function _handleFees(address token, address integrator, uint256 balance, uint256 fees) internal {
if (fees > 0) {
uint256 protocolLpFees = fees / 20;
uint256 protocolProceedsFees = (balance - fees) / 1000;
uint256 protocolFees = Math.max(protocolLpFees, protocolProceedsFees);
uint256 maxProtocolFees = fees / 5;
uint256 integratorFees;
(integratorFees, protocolFees) = protocolFees > maxProtocolFees
? (fees - maxProtocolFees, maxProtocolFees)
: (fees - protocolFees, protocolFees);
getProtocolFees[token] += protocolFees;
getIntegratorFees[integrator][token] += integratorFees;
}
}
/**
* @notice Sets the state of the givens modules
* @param modules Array of module addresses
* @param states Array of module states
*/
function setModuleState(address[] calldata modules, ModuleState[] calldata states) external onlyOwner {
uint256 length = modules.length;
if (length != states.length) {
revert ArrayLengthsMismatch();
}
for (uint256 i; i < length; ++i) {
getModuleState[modules[i]] = states[i];
emit SetModuleState(modules[i], states[i]);
}
}
/**
* @notice Collects protocol fees
* @param to Address receiving the fees
* @param token Address of the token to collect fees from
* @param amount Amount of fees to collect
*/
function collectProtocolFees(address to, address token, uint256 amount) external onlyOwner {
getProtocolFees[token] -= amount;
if (token == address(0)) {
SafeTransferLib.safeTransferETH(to, amount);
} else {
ERC20(token).safeTransfer(to, amount);
}
emit Collect(to, token, amount);
}
/**
* @notice Collects integrator fees
* @param to Address receiving the fees
* @param token Address of the token to collect fees from
* @param amount Amount of fees to collect
*/
function collectIntegratorFees(address to, address token, uint256 amount) external {
getIntegratorFees[msg.sender][token] -= amount;
if (token == address(0)) {
SafeTransferLib.safeTransferETH(to, amount);
} else {
ERC20(token).safeTransfer(to, amount);
}
emit Collect(to, token, amount);
}
/**
* @dev Validates the state of a module
* @param module Address of the module
* @param state Expected state of the module
*/
function _validateModuleState(address module, ModuleState state) internal view {
require(getModuleState[address(module)] == state, WrongModuleState(module, state, getModuleState[module]));
}
}// 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;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// 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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {IERC-5267}.
*/
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/SignatureChecker.sol)
pragma solidity ^0.8.20;
import {ECDSA} from "./ECDSA.sol";
import {IERC1271} from "../../interfaces/IERC1271.sol";
/**
* @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
* signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
* Argent and Safe Wallet (previously Gnosis Safe).
*/
library SignatureChecker {
/**
* @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
* signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
*
* NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
* change through time. It could return true at block N and false at block N+1 (or the opposite).
*/
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
(address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
return
(error == ECDSA.RecoverError.NoError && recovered == signer) ||
isValidERC1271SignatureNow(signer, hash, signature);
}
/**
* @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
* against the signer smart contract using ERC1271.
*
* NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
* change through time. It could return true at block N and false at block N+1 (or the opposite).
*/
function isValidERC1271SignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(bool success, bytes memory result) = signer.staticcall(
abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
);
return (success &&
result.length >= 32 &&
abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/DoubleEndedQueue.sol)
pragma solidity ^0.8.20;
/**
* @dev A sequence of items with the ability to efficiently push and pop items (i.e. insert and remove) on both ends of
* the sequence (called front and back). Among other access patterns, it can be used to implement efficient LIFO and
* FIFO queues. Storage use is optimized, and all operations are O(1) constant time. This includes {clear}, given that
* the existing queue contents are left in storage.
*
* The struct is called `Bytes32Deque`. Other types can be cast to and from `bytes32`. This data structure can only be
* used in storage, and not in memory.
* ```solidity
* DoubleEndedQueue.Bytes32Deque queue;
* ```
*/
library DoubleEndedQueue {
/**
* @dev An operation (e.g. {front}) couldn't be completed due to the queue being empty.
*/
error QueueEmpty();
/**
* @dev A push operation couldn't be completed due to the queue being full.
*/
error QueueFull();
/**
* @dev An operation (e.g. {at}) couldn't be completed due to an index being out of bounds.
*/
error QueueOutOfBounds();
/**
* @dev Indices are 128 bits so begin and end are packed in a single storage slot for efficient access.
*
* Struct members have an underscore prefix indicating that they are "private" and should not be read or written to
* directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and
* lead to unexpected behavior.
*
* The first item is at data[begin] and the last item is at data[end - 1]. This range can wrap around.
*/
struct Bytes32Deque {
uint128 _begin;
uint128 _end;
mapping(uint128 index => bytes32) _data;
}
/**
* @dev Inserts an item at the end of the queue.
*
* Reverts with {QueueFull} if the queue is full.
*/
function pushBack(Bytes32Deque storage deque, bytes32 value) internal {
unchecked {
uint128 backIndex = deque._end;
if (backIndex + 1 == deque._begin) revert QueueFull();
deque._data[backIndex] = value;
deque._end = backIndex + 1;
}
}
/**
* @dev Removes the item at the end of the queue and returns it.
*
* Reverts with {QueueEmpty} if the queue is empty.
*/
function popBack(Bytes32Deque storage deque) internal returns (bytes32 value) {
unchecked {
uint128 backIndex = deque._end;
if (backIndex == deque._begin) revert QueueEmpty();
--backIndex;
value = deque._data[backIndex];
delete deque._data[backIndex];
deque._end = backIndex;
}
}
/**
* @dev Inserts an item at the beginning of the queue.
*
* Reverts with {QueueFull} if the queue is full.
*/
function pushFront(Bytes32Deque storage deque, bytes32 value) internal {
unchecked {
uint128 frontIndex = deque._begin - 1;
if (frontIndex == deque._end) revert QueueFull();
deque._data[frontIndex] = value;
deque._begin = frontIndex;
}
}
/**
* @dev Removes the item at the beginning of the queue and returns it.
*
* Reverts with `QueueEmpty` if the queue is empty.
*/
function popFront(Bytes32Deque storage deque) internal returns (bytes32 value) {
unchecked {
uint128 frontIndex = deque._begin;
if (frontIndex == deque._end) revert QueueEmpty();
value = deque._data[frontIndex];
delete deque._data[frontIndex];
deque._begin = frontIndex + 1;
}
}
/**
* @dev Returns the item at the beginning of the queue.
*
* Reverts with `QueueEmpty` if the queue is empty.
*/
function front(Bytes32Deque storage deque) internal view returns (bytes32 value) {
if (empty(deque)) revert QueueEmpty();
return deque._data[deque._begin];
}
/**
* @dev Returns the item at the end of the queue.
*
* Reverts with `QueueEmpty` if the queue is empty.
*/
function back(Bytes32Deque storage deque) internal view returns (bytes32 value) {
if (empty(deque)) revert QueueEmpty();
unchecked {
return deque._data[deque._end - 1];
}
}
/**
* @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at
* `length(deque) - 1`.
*
* Reverts with `QueueOutOfBounds` if the index is out of bounds.
*/
function at(Bytes32Deque storage deque, uint256 index) internal view returns (bytes32 value) {
if (index >= length(deque)) revert QueueOutOfBounds();
// By construction, length is a uint128, so the check above ensures that index can be safely downcast to uint128
unchecked {
return deque._data[deque._begin + uint128(index)];
}
}
/**
* @dev Resets the queue back to being empty.
*
* NOTE: The current items are left behind in storage. This does not affect the functioning of the queue, but misses
* out on potential gas refunds.
*/
function clear(Bytes32Deque storage deque) internal {
deque._begin = 0;
deque._end = 0;
}
/**
* @dev Returns the number of items in the queue.
*/
function length(Bytes32Deque storage deque) internal view returns (uint256) {
unchecked {
return uint256(deque._end - deque._begin);
}
}
/**
* @dev Returns true if the queue is empty.
*/
function empty(Bytes32Deque storage deque) internal view returns (bool) {
return deque._end == deque._begin;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides tracking nonces for addresses. Nonces will only increment.
*/
abstract contract Nonces {
/**
* @dev The nonce used for an `account` is not the expected current nonce.
*/
error InvalidAccountNonce(address account, uint256 currentNonce);
mapping(address account => uint256) private _nonces;
/**
* @dev Returns the next unused nonce for an address.
*/
function nonces(address owner) public view virtual returns (uint256) {
return _nonces[owner];
}
/**
* @dev Consumes a nonce.
*
* Returns the current value and increments nonce.
*/
function _useNonce(address owner) internal virtual returns (uint256) {
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return _nonces[owner]++;
}
}
/**
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
*/
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
uint256 current = _useNonce(owner);
if (nonce != current) {
revert InvalidAccountNonce(owner, current);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/IGovernor.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../interfaces/IERC165.sol";
import {IERC6372} from "../interfaces/IERC6372.sol";
/**
* @dev Interface of the {Governor} core.
*/
interface IGovernor is IERC165, IERC6372 {
enum ProposalState {
Pending,
Active,
Canceled,
Defeated,
Succeeded,
Queued,
Expired,
Executed
}
/**
* @dev Empty proposal or a mismatch between the parameters length for a proposal call.
*/
error GovernorInvalidProposalLength(uint256 targets, uint256 calldatas, uint256 values);
/**
* @dev The vote was already cast.
*/
error GovernorAlreadyCastVote(address voter);
/**
* @dev Token deposits are disabled in this contract.
*/
error GovernorDisabledDeposit();
/**
* @dev The `account` is not a proposer.
*/
error GovernorOnlyProposer(address account);
/**
* @dev The `account` is not the governance executor.
*/
error GovernorOnlyExecutor(address account);
/**
* @dev The `proposalId` doesn't exist.
*/
error GovernorNonexistentProposal(uint256 proposalId);
/**
* @dev The current state of a proposal is not the required for performing an operation.
* The `expectedStates` is a bitmap with the bits enabled for each ProposalState enum position
* counting from right to left.
*
* NOTE: If `expectedState` is `bytes32(0)`, the proposal is expected to not be in any state (i.e. not exist).
* This is the case when a proposal that is expected to be unset is already initiated (the proposal is duplicated).
*
* See {Governor-_encodeStateBitmap}.
*/
error GovernorUnexpectedProposalState(uint256 proposalId, ProposalState current, bytes32 expectedStates);
/**
* @dev The voting period set is not a valid period.
*/
error GovernorInvalidVotingPeriod(uint256 votingPeriod);
/**
* @dev The `proposer` does not have the required votes to create a proposal.
*/
error GovernorInsufficientProposerVotes(address proposer, uint256 votes, uint256 threshold);
/**
* @dev The `proposer` is not allowed to create a proposal.
*/
error GovernorRestrictedProposer(address proposer);
/**
* @dev The vote type used is not valid for the corresponding counting module.
*/
error GovernorInvalidVoteType();
/**
* @dev Queue operation is not implemented for this governor. Execute should be called directly.
*/
error GovernorQueueNotImplemented();
/**
* @dev The proposal hasn't been queued yet.
*/
error GovernorNotQueuedProposal(uint256 proposalId);
/**
* @dev The proposal has already been queued.
*/
error GovernorAlreadyQueuedProposal(uint256 proposalId);
/**
* @dev The provided signature is not valid for the expected `voter`.
* If the `voter` is a contract, the signature is not valid using {IERC1271-isValidSignature}.
*/
error GovernorInvalidSignature(address voter);
/**
* @dev Emitted when a proposal is created.
*/
event ProposalCreated(
uint256 proposalId,
address proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 voteStart,
uint256 voteEnd,
string description
);
/**
* @dev Emitted when a proposal is queued.
*/
event ProposalQueued(uint256 proposalId, uint256 etaSeconds);
/**
* @dev Emitted when a proposal is executed.
*/
event ProposalExecuted(uint256 proposalId);
/**
* @dev Emitted when a proposal is canceled.
*/
event ProposalCanceled(uint256 proposalId);
/**
* @dev Emitted when a vote is cast without params.
*
* Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
*/
event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason);
/**
* @dev Emitted when a vote is cast with params.
*
* Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used.
* `params` are additional encoded parameters. Their interpepretation also depends on the voting module used.
*/
event VoteCastWithParams(
address indexed voter,
uint256 proposalId,
uint8 support,
uint256 weight,
string reason,
bytes params
);
/**
* @notice module:core
* @dev Name of the governor instance (used in building the ERC712 domain separator).
*/
function name() external view returns (string memory);
/**
* @notice module:core
* @dev Version of the governor instance (used in building the ERC712 domain separator). Default: "1"
*/
function version() external view returns (string memory);
/**
* @notice module:voting
* @dev A description of the possible `support` values for {castVote} and the way these votes are counted, meant to
* be consumed by UIs to show correct vote options and interpret the results. The string is a URL-encoded sequence of
* key-value pairs that each describe one aspect, for example `support=bravo&quorum=for,abstain`.
*
* There are 2 standard keys: `support` and `quorum`.
*
* - `support=bravo` refers to the vote options 0 = Against, 1 = For, 2 = Abstain, as in `GovernorBravo`.
* - `quorum=bravo` means that only For votes are counted towards quorum.
* - `quorum=for,abstain` means that both For and Abstain votes are counted towards quorum.
*
* If a counting module makes use of encoded `params`, it should include this under a `params` key with a unique
* name that describes the behavior. For example:
*
* - `params=fractional` might refer to a scheme where votes are divided fractionally between for/against/abstain.
* - `params=erc721` might refer to a scheme where specific NFTs are delegated to vote.
*
* NOTE: The string can be decoded by the standard
* https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams[`URLSearchParams`]
* JavaScript class.
*/
// solhint-disable-next-line func-name-mixedcase
function COUNTING_MODE() external view returns (string memory);
/**
* @notice module:core
* @dev Hashing function used to (re)build the proposal id from the proposal details..
*/
function hashProposal(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) external pure returns (uint256);
/**
* @notice module:core
* @dev Current state of a proposal, following Compound's convention
*/
function state(uint256 proposalId) external view returns (ProposalState);
/**
* @notice module:core
* @dev The number of votes required in order for a voter to become a proposer.
*/
function proposalThreshold() external view returns (uint256);
/**
* @notice module:core
* @dev Timepoint used to retrieve user's votes and quorum. If using block number (as per Compound's Comp), the
* snapshot is performed at the end of this block. Hence, voting for this proposal starts at the beginning of the
* following block.
*/
function proposalSnapshot(uint256 proposalId) external view returns (uint256);
/**
* @notice module:core
* @dev Timepoint at which votes close. If using block number, votes close at the end of this block, so it is
* possible to cast a vote during this block.
*/
function proposalDeadline(uint256 proposalId) external view returns (uint256);
/**
* @notice module:core
* @dev The account that created a proposal.
*/
function proposalProposer(uint256 proposalId) external view returns (address);
/**
* @notice module:core
* @dev The time when a queued proposal becomes executable ("ETA"). Unlike {proposalSnapshot} and
* {proposalDeadline}, this doesn't use the governor clock, and instead relies on the executor's clock which may be
* different. In most cases this will be a timestamp.
*/
function proposalEta(uint256 proposalId) external view returns (uint256);
/**
* @notice module:core
* @dev Whether a proposal needs to be queued before execution.
*/
function proposalNeedsQueuing(uint256 proposalId) external view returns (bool);
/**
* @notice module:user-config
* @dev Delay, between the proposal is created and the vote starts. The unit this duration is expressed in depends
* on the clock (see EIP-6372) this contract uses.
*
* This can be increased to leave time for users to buy voting power, or delegate it, before the voting of a
* proposal starts.
*
* NOTE: While this interface returns a uint256, timepoints are stored as uint48 following the ERC-6372 clock type.
* Consequently this value must fit in a uint48 (when added to the current clock). See {IERC6372-clock}.
*/
function votingDelay() external view returns (uint256);
/**
* @notice module:user-config
* @dev Delay between the vote start and vote end. The unit this duration is expressed in depends on the clock
* (see EIP-6372) this contract uses.
*
* NOTE: The {votingDelay} can delay the start of the vote. This must be considered when setting the voting
* duration compared to the voting delay.
*
* NOTE: This value is stored when the proposal is submitted so that possible changes to the value do not affect
* proposals that have already been submitted. The type used to save it is a uint32. Consequently, while this
* interface returns a uint256, the value it returns should fit in a uint32.
*/
function votingPeriod() external view returns (uint256);
/**
* @notice module:user-config
* @dev Minimum number of cast voted required for a proposal to be successful.
*
* NOTE: The `timepoint` parameter corresponds to the snapshot used for counting vote. This allows to scale the
* quorum depending on values such as the totalSupply of a token at this timepoint (see {ERC20Votes}).
*/
function quorum(uint256 timepoint) external view returns (uint256);
/**
* @notice module:reputation
* @dev Voting power of an `account` at a specific `timepoint`.
*
* Note: this can be implemented in a number of ways, for example by reading the delegated balance from one (or
* multiple), {ERC20Votes} tokens.
*/
function getVotes(address account, uint256 timepoint) external view returns (uint256);
/**
* @notice module:reputation
* @dev Voting power of an `account` at a specific `timepoint` given additional encoded parameters.
*/
function getVotesWithParams(
address account,
uint256 timepoint,
bytes memory params
) external view returns (uint256);
/**
* @notice module:voting
* @dev Returns whether `account` has cast a vote on `proposalId`.
*/
function hasVoted(uint256 proposalId, address account) external view returns (bool);
/**
* @dev Create a new proposal. Vote start after a delay specified by {IGovernor-votingDelay} and lasts for a
* duration specified by {IGovernor-votingPeriod}.
*
* Emits a {ProposalCreated} event.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) external returns (uint256 proposalId);
/**
* @dev Queue a proposal. Some governors require this step to be performed before execution can happen. If queuing
* is not necessary, this function may revert.
* Queuing a proposal requires the quorum to be reached, the vote to be successful, and the deadline to be reached.
*
* Emits a {ProposalQueued} event.
*/
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) external returns (uint256 proposalId);
/**
* @dev Execute a successful proposal. This requires the quorum to be reached, the vote to be successful, and the
* deadline to be reached. Depending on the governor it might also be required that the proposal was queued and
* that some delay passed.
*
* Emits a {ProposalExecuted} event.
*
* NOTE: Some modules can modify the requirements for execution, for example by adding an additional timelock.
*/
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) external payable returns (uint256 proposalId);
/**
* @dev Cancel a proposal. A proposal is cancellable by the proposer, but only while it is Pending state, i.e.
* before the vote starts.
*
* Emits a {ProposalCanceled} event.
*/
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) external returns (uint256 proposalId);
/**
* @dev Cast a vote
*
* Emits a {VoteCast} event.
*/
function castVote(uint256 proposalId, uint8 support) external returns (uint256 balance);
/**
* @dev Cast a vote with a reason
*
* Emits a {VoteCast} event.
*/
function castVoteWithReason(
uint256 proposalId,
uint8 support,
string calldata reason
) external returns (uint256 balance);
/**
* @dev Cast a vote with a reason and additional encoded parameters
*
* Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
*/
function castVoteWithReasonAndParams(
uint256 proposalId,
uint8 support,
string calldata reason,
bytes memory params
) external returns (uint256 balance);
/**
* @dev Cast a vote using the voter's signature, including ERC-1271 signature support.
*
* Emits a {VoteCast} event.
*/
function castVoteBySig(
uint256 proposalId,
uint8 support,
address voter,
bytes memory signature
) external returns (uint256 balance);
/**
* @dev Cast a vote with a reason and additional encoded parameters using the voter's signature,
* including ERC-1271 signature support.
*
* Emits a {VoteCast} or {VoteCastWithParams} event depending on the length of params.
*/
function castVoteWithReasonAndParamsBySig(
uint256 proposalId,
uint8 support,
address voter,
string calldata reason,
bytes memory params,
bytes memory signature
) external returns (uint256 balance);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5805.sol)
pragma solidity ^0.8.20;
import {IVotes} from "../governance/utils/IVotes.sol";
import {IERC6372} from "./IERC6372.sol";
interface IERC5805 is IERC6372, IVotes {}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/types/Time.sol)
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
import {SafeCast} from "../math/SafeCast.sol";
/**
* @dev This library provides helpers for manipulating time-related objects.
*
* It uses the following types:
* - `uint48` for timepoints
* - `uint32` for durations
*
* While the library doesn't provide specific types for timepoints and duration, it does provide:
* - a `Delay` type to represent duration that can be programmed to change value automatically at a given point
* - additional helper functions
*/
library Time {
using Time for *;
/**
* @dev Get the block timestamp as a Timepoint.
*/
function timestamp() internal view returns (uint48) {
return SafeCast.toUint48(block.timestamp);
}
/**
* @dev Get the block number as a Timepoint.
*/
function blockNumber() internal view returns (uint48) {
return SafeCast.toUint48(block.number);
}
// ==================================================== Delay =====================================================
/**
* @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the
* future. The "effect" timepoint describes when the transitions happens from the "old" value to the "new" value.
* This allows updating the delay applied to some operation while keeping some guarantees.
*
* In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for
* some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set
* the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should
* still apply for some time.
*
*
* The `Delay` type is 112 bits long, and packs the following:
*
* ```
* | [uint48]: effect date (timepoint)
* | | [uint32]: value before (duration)
* ↓ ↓ ↓ [uint32]: value after (duration)
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
* ```
*
* NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
* supported.
*/
type Delay is uint112;
/**
* @dev Wrap a duration into a Delay to add the one-step "update in the future" feature
*/
function toDelay(uint32 duration) internal pure returns (Delay) {
return Delay.wrap(duration);
}
/**
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
*/
function _getFullAt(Delay self, uint48 timepoint) private pure returns (uint32, uint32, uint48) {
(uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
}
/**
* @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the
* effect timepoint is 0, then the pending value should not be considered.
*/
function getFull(Delay self) internal view returns (uint32, uint32, uint48) {
return _getFullAt(self, timestamp());
}
/**
* @dev Get the current value.
*/
function get(Delay self) internal view returns (uint32) {
(uint32 delay, , ) = self.getFull();
return delay;
}
/**
* @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to
* enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
* new delay becomes effective.
*/
function withUpdate(
Delay self,
uint32 newValue,
uint32 minSetback
) internal view returns (Delay updatedDelay, uint48 effect) {
uint32 value = self.get();
uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
effect = timestamp() + setback;
return (pack(value, newValue, effect), effect);
}
/**
* @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
*/
function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
uint112 raw = Delay.unwrap(self);
valueAfter = uint32(raw);
valueBefore = uint32(raw >> 32);
effect = uint48(raw >> 64);
return (valueBefore, valueAfter, effect);
}
/**
* @dev pack the components into a Delay object.
*/
function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {
return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/Checkpoints.sol)
// This file was procedurally generated from scripts/generate/templates/Checkpoints.js.
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
/**
* @dev This library defines the `Trace*` struct, for checkpointing values as they change at different points in
* time, and later looking up past values by block number. See {Votes} as an example.
*
* To create a history of checkpoints define a variable type `Checkpoints.Trace*` in your contract, and store a new
* checkpoint for the current transaction block using the {push} function.
*/
library Checkpoints {
/**
* @dev A value was attempted to be inserted on a past checkpoint.
*/
error CheckpointUnorderedInsertion();
struct Trace224 {
Checkpoint224[] _checkpoints;
}
struct Checkpoint224 {
uint32 _key;
uint224 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace224 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint32).max` key set will disable the
* library.
*/
function push(Trace224 storage self, uint32 key, uint224 value) internal returns (uint224, uint224) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace224 storage self) internal view returns (uint224) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace224 storage self) internal view returns (bool exists, uint32 _key, uint224 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint224 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace224 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace224 storage self, uint32 pos) internal view returns (Checkpoint224 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint224[] storage self, uint32 key, uint224 value) private returns (uint224, uint224) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint224 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint224({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint224({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint224[] storage self,
uint32 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint224[] storage self,
uint32 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint224[] storage self,
uint256 pos
) private pure returns (Checkpoint224 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
struct Trace208 {
Checkpoint208[] _checkpoints;
}
struct Checkpoint208 {
uint48 _key;
uint208 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace208 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the
* library.
*/
function push(Trace208 storage self, uint48 key, uint208 value) internal returns (uint208, uint208) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace208 storage self) internal view returns (uint208) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace208 storage self) internal view returns (bool exists, uint48 _key, uint208 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint208 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace208 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace208 storage self, uint32 pos) internal view returns (Checkpoint208 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint208[] storage self, uint48 key, uint208 value) private returns (uint208, uint208) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint208 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint208({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint208({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint208[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint208[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint208[] storage self,
uint256 pos
) private pure returns (Checkpoint208 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
struct Trace160 {
Checkpoint160[] _checkpoints;
}
struct Checkpoint160 {
uint96 _key;
uint160 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace160 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint96).max` key set will disable the
* library.
*/
function push(Trace160 storage self, uint96 key, uint160 value) internal returns (uint160, uint160) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace160 storage self) internal view returns (uint160) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace160 storage self) internal view returns (bool exists, uint96 _key, uint160 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint160 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace160 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace160 storage self, uint32 pos) internal view returns (Checkpoint160 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint160[] storage self, uint96 key, uint160 value) private returns (uint160, uint160) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint160 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint160({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint160({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint160[] storage self,
uint96 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint160[] storage self,
uint96 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint160[] storage self,
uint256 pos
) private pure returns (Checkpoint160 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.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);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title Token Factory Interface
* @notice Contracts deploying new asset token must implement this interface.
*/
interface ITokenFactory {
/**
* @notice Deploys a new asset token.
* @param initialSupply Initial supply that will be minted
* @param recipient Address receiving the initial supply
* @param owner Address receiving the ownership of the token
* @param tokenData Extra data to be used by the factory
* @param salt Salt used in create2 deployment to determine contract address
* @return Address of the newly deployed token
*/
function create(
uint256 initialSupply,
address recipient,
address owner,
bytes32 salt,
bytes calldata tokenData
) external returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @notice Contracts inheriting from this interface are in charge of creating new
* liquidity pools and migrating liquidity under specific conditions
*/
interface IPoolInitializer {
/**
* @notice Creates a new pool to bootstrap liquidity
* @param numTokensToSell Amount of asset tokens to sell
* @param salt Salt for the create2 deployment
* @param data Arbitrary data to pass
* @param pool Address of the freshly deployed pool or the hook
*/
function initialize(
address asset,
address numeraire,
uint256 numTokensToSell,
bytes32 salt,
bytes calldata data
) external returns (address pool);
/**
* @notice Removes liquidity from a pool
* @param target Address to target for the migration (pool or hook)
* @return sqrtPriceX96 Square root of the price of the pool in the Q96 format
* @return token0 Address of the token0
* @return fees0 Amount of fees accrued for token0
* @return balance0 Amount of token0 in the pool
* @return token1 Address of the token1
* @return fees1 Amount of fees accrued for token1
* @return balance1 Amount of token1 in the pool
*/
function exitLiquidity(
address target
)
external
returns (
uint160 sqrtPriceX96,
address token0,
uint128 fees0,
uint128 balance0,
address token1,
uint128 fees1,
uint128 balance1
);
/**
* @notice Emitted when a pool or hook is created
* @param poolOrHook Address of the pool or hook
* @param asset Address of the asset
* @param numeraire Address of the numeraire
*/
event Create(address indexed poolOrHook, address indexed asset, address indexed numeraire);
}
interface IHook {
/**
* @notice Triggers the migration stage of the hook contract
* @return Price of the pool
*/
function migrate(
address recipient
) external returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/**
* @notice Generic interface to migrate current liquidity to a new pool
*/
interface ILiquidityMigrator {
function initialize(address asset, address numeraire, bytes calldata data) external returns (address pool);
function migrate(
uint160 sqrtPriceX96,
address token0,
address token1,
address recipient
) external payable returns (uint256 liquidity);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;
import { ERC20 } from "@openzeppelin/token/ERC20/ERC20.sol";
import { ERC20Votes } from "@openzeppelin/token/ERC20/extensions/ERC20Votes.sol";
import { Ownable } from "@openzeppelin/access/Ownable.sol";
import { ERC20Permit } from "@openzeppelin/token/ERC20/extensions/ERC20Permit.sol";
import { Nonces } from "@openzeppelin/utils/Nonces.sol";
/// @dev Thrown when trying to mint before the start date
error MintingNotStartedYet();
/// @dev Thrown when trying to mint more than the yearly cap
error ExceedsYearlyMintCap();
/// @dev Thrown when there is no amount to mint
error NoMintableAmount();
/// @dev Thrown when trying to transfer tokens into the pool while it is locked
error PoolLocked();
/// @dev Thrown when two arrays have different lengths
error ArrayLengthsMismatch();
/// @dev Thrown when trying to release tokens before the end of the vesting period
error ReleaseAmountInvalid();
/// @dev Thrown when trying to premint more than the maximum allowed per address
error MaxPreMintPerAddressExceeded(uint256 amount, uint256 limit);
/// @dev Thrown when trying to premint more than the maximum allowed in total
error MaxTotalPreMintExceeded(uint256 amount, uint256 limit);
/// @dev Thrown when trying to mint more than the maximum allowed in total
error MaxTotalVestedExceeded(uint256 amount, uint256 limit);
/// @dev Thrown when trying to release tokens before the vesting period has started
error VestingNotStartedYet();
/// @dev Thrown when trying to set the mint rate to a value higher than the maximum allowed
error MaxYearlyMintRateExceeded(uint256 amount, uint256 limit);
/// @dev Max amount of tokens that can be pre-minted per address (% expressed in WAD)
uint256 constant MAX_PRE_MINT_PER_ADDRESS_WAD = 0.2 ether;
/// @dev Max amount of tokens that can be pre-minted in total (% expressed in WAD)
uint256 constant MAX_TOTAL_PRE_MINT_WAD = 0.2 ether;
/// @dev Maximum amount of tokens that can be minted in a year (% expressed in WAD)
uint256 constant MAX_YEARLY_MINT_RATE_WAD = 0.02 ether;
/// @dev Address of the canonical Permit2 contract
address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/**
* @notice Vesting data for a specific address
* @param totalAmount Total amount of vested tokens
* @param releasedAmount Amount of tokens already released
*/
struct VestingData {
uint256 totalAmount;
uint256 releasedAmount;
}
/// @custom:security-contact [email protected]
contract DERC20 is ERC20, ERC20Votes, ERC20Permit, Ownable {
/// @notice Timestamp of the start of the vesting period
uint256 public immutable vestingStart;
/// @notice Duration of the vesting period (in seconds)
uint256 public immutable vestingDuration;
/// @notice Total amount of vested tokens
uint256 public immutable vestedTotalAmount;
/// @notice Address of the liquidity pool
address public pool;
/// @notice Whether the pool can receive tokens (unlocked) or not
bool public isPoolUnlocked;
/// @notice Maximum rate of tokens that can be minted in a year
uint256 public yearlyMintRate;
/// @notice Timestamp of the start of the current year
uint256 public currentYearStart;
/// @notice Timestamp of the last inflation mint
uint256 public lastMintTimestamp;
/// @notice Uniform Resource Identifier (URI)
string public tokenURI;
/// @notice Returns vesting data for a specific address
mapping(address account => VestingData vestingData) public getVestingDataOf;
modifier hasVestingStarted() {
require(vestingStart > 0, VestingNotStartedYet());
_;
}
/**
* @param name_ Name of the token
* @param symbol_ Symbol of the token
* @param initialSupply Initial supply of the token
* @param recipient Address receiving the initial supply
* @param owner_ Address receiving the ownership of the token
* @param yearlyMintRate_ Maximum inflation rate of token in a year
* @param vestingDuration_ Duration of the vesting period (in seconds)
* @param recipients_ Array of addresses receiving vested tokens
* @param amounts_ Array of amounts of tokens to be vested
* @param tokenURI_ Uniform Resource Identifier (URI)
*/
constructor(
string memory name_,
string memory symbol_,
uint256 initialSupply,
address recipient,
address owner_,
uint256 yearlyMintRate_,
uint256 vestingDuration_,
address[] memory recipients_,
uint256[] memory amounts_,
string memory tokenURI_
) ERC20(name_, symbol_) ERC20Permit(name_) Ownable(owner_) {
require(
yearlyMintRate_ <= MAX_YEARLY_MINT_RATE_WAD,
MaxYearlyMintRateExceeded(yearlyMintRate_, MAX_YEARLY_MINT_RATE_WAD)
);
yearlyMintRate = yearlyMintRate_;
vestingStart = block.timestamp;
vestingDuration = vestingDuration_;
tokenURI = tokenURI_;
uint256 length = recipients_.length;
require(length == amounts_.length, ArrayLengthsMismatch());
uint256 vestedTokens;
uint256 maxPreMintPerAddress = initialSupply * MAX_PRE_MINT_PER_ADDRESS_WAD / 1 ether;
for (uint256 i; i < length; ++i) {
uint256 amount = amounts_[i];
getVestingDataOf[recipients_[i]].totalAmount += amount;
require(
getVestingDataOf[recipients_[i]].totalAmount <= maxPreMintPerAddress,
MaxPreMintPerAddressExceeded(getVestingDataOf[recipients_[i]].totalAmount, maxPreMintPerAddress)
);
vestedTokens += amount;
}
uint256 maxTotalPreMint = initialSupply * MAX_TOTAL_PRE_MINT_WAD / 1 ether;
require(vestedTokens <= maxTotalPreMint, MaxTotalPreMintExceeded(vestedTokens, maxTotalPreMint));
require(vestedTokens < initialSupply, MaxTotalVestedExceeded(vestedTokens, initialSupply));
vestedTotalAmount = vestedTokens;
if (vestedTokens > 0) {
_mint(address(this), vestedTokens);
}
_mint(recipient, initialSupply - vestedTokens);
}
/**
* @notice Locks the pool, preventing it from receiving tokens
* @param pool_ Address of the pool to lock
*/
function lockPool(
address pool_
) external onlyOwner {
pool = pool_;
isPoolUnlocked = false;
}
/// @notice Unlocks the pool, allowing it to receive tokens
function unlockPool() external onlyOwner {
isPoolUnlocked = true;
currentYearStart = lastMintTimestamp = block.timestamp;
}
/**
* @notice Mints inflation tokens to the owner
*/
function mintInflation() public {
require(currentYearStart != 0, MintingNotStartedYet());
uint256 mintableAmount;
uint256 yearMint;
uint256 timeLeftInCurrentYear;
uint256 supply = totalSupply();
uint256 currentYearStart_ = currentYearStart;
uint256 lastMintTimestamp_ = lastMintTimestamp;
uint256 yearlyMintRate_ = yearlyMintRate;
// Handle any outstanding full years and updates to maintain inflation rate
while (block.timestamp > currentYearStart_ + 365 days) {
timeLeftInCurrentYear = (currentYearStart_ + 365 days - lastMintTimestamp_);
yearMint = (supply * yearlyMintRate_ * timeLeftInCurrentYear) / (1 ether * 365 days);
supply += yearMint;
mintableAmount += yearMint;
currentYearStart_ += 365 days;
lastMintTimestamp_ = currentYearStart_;
}
// Handle partial current year
if (block.timestamp > lastMintTimestamp_) {
uint256 partialYearMint =
(supply * yearlyMintRate_ * (block.timestamp - lastMintTimestamp_)) / (1 ether * 365 days);
mintableAmount += partialYearMint;
}
require(mintableAmount > 0, NoMintableAmount());
currentYearStart = currentYearStart_;
lastMintTimestamp = block.timestamp;
_mint(owner(), mintableAmount);
}
/**
* @notice Burns `amount` of tokens from the address `owner`
* @param amount Amount of tokens to burn
*/
function burn(
uint256 amount
) external onlyOwner {
_burn(owner(), amount);
}
/**
* @notice Updates the maximum rate of tokens that can be minted in a year
* @param newMintRate New maximum rate of tokens that can be minted in a year
*/
function updateMintRate(
uint256 newMintRate
) external onlyOwner {
// Inflation can't be more than 2% of token supply per year
require(
newMintRate <= MAX_YEARLY_MINT_RATE_WAD, MaxYearlyMintRateExceeded(newMintRate, MAX_YEARLY_MINT_RATE_WAD)
);
if (currentYearStart != 0 && (block.timestamp - lastMintTimestamp) != 0) {
mintInflation();
}
yearlyMintRate = newMintRate;
}
/**
* @notice Updates the token Uniform Resource Identifier (URI)
* @param tokenURI_ New token Uniform Resource Identifier (URI)
*/
function updateTokenURI(
string memory tokenURI_
) external onlyOwner {
tokenURI = tokenURI_;
}
/**
* @notice Releases all available vested tokens
*/
function release() external hasVestingStarted {
uint256 availableAmount = computeAvailableVestedAmount(msg.sender);
getVestingDataOf[msg.sender].releasedAmount += availableAmount;
_transfer(address(this), msg.sender, availableAmount);
}
/**
* @notice Computes the amount of vested tokens available for a specific address
* @param account Recipient of the vested tokens
* @return Amount of vested tokens available
*/
function computeAvailableVestedAmount(
address account
) public view returns (uint256) {
uint256 vestedAmount;
if (block.timestamp < vestingStart + vestingDuration) {
vestedAmount = getVestingDataOf[account].totalAmount * (block.timestamp - vestingStart) / vestingDuration;
} else {
vestedAmount = getVestingDataOf[account].totalAmount;
}
return vestedAmount - getVestingDataOf[account].releasedAmount;
}
/// @inheritdoc Nonces
function nonces(
address owner_
) public view override(ERC20Permit, Nonces) returns (uint256) {
return super.nonces(owner_);
}
/// @inheritdoc ERC20
function allowance(address owner, address spender) public view override returns (uint256) {
if (spender == PERMIT_2) return type(uint256).max;
return super.allowance(owner, spender);
}
/// @inheritdoc ERC20
function _update(address from, address to, uint256 value) internal override(ERC20, ERC20Votes) {
if (to == pool && isPoolUnlocked == false) revert PoolLocked();
super._update(from, to, value);
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.20;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC6372.sol)
pragma solidity ^0.8.20;
interface IERC6372 {
/**
* @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
*/
function clock() external view returns (uint48);
/**
* @dev Description of the clock
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() external view returns (string memory);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Votes.sol)
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
import {Votes} from "../../../governance/utils/Votes.sol";
import {Checkpoints} from "../../../utils/structs/Checkpoints.sol";
/**
* @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,
* and supports token supply up to 2^208^ - 1, while COMP is limited to 2^96^ - 1.
*
* NOTE: This contract does not provide interface compatibility with Compound's COMP token.
*
* This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either
* by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting
* power can be queried through the public accessors {getVotes} and {getPastVotes}.
*
* By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it
* requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.
*/
abstract contract ERC20Votes is ERC20, Votes {
/**
* @dev Total supply cap has been exceeded, introducing a risk of votes overflowing.
*/
error ERC20ExceededSafeSupply(uint256 increasedSupply, uint256 cap);
/**
* @dev Maximum token supply. Defaults to `type(uint208).max` (2^208^ - 1).
*
* This maximum is enforced in {_update}. It limits the total supply of the token, which is otherwise a uint256,
* so that checkpoints can be stored in the Trace208 structure used by {{Votes}}. Increasing this value will not
* remove the underlying limitation, and will cause {_update} to fail because of a math overflow in
* {_transferVotingUnits}. An override could be used to further restrict the total supply (to a lower value) if
* additional logic requires it. When resolving override conflicts on this function, the minimum should be
* returned.
*/
function _maxSupply() internal view virtual returns (uint256) {
return type(uint208).max;
}
/**
* @dev Move voting power when tokens are transferred.
*
* Emits a {IVotes-DelegateVotesChanged} event.
*/
function _update(address from, address to, uint256 value) internal virtual override {
super._update(from, to, value);
if (from == address(0)) {
uint256 supply = totalSupply();
uint256 cap = _maxSupply();
if (supply > cap) {
revert ERC20ExceededSafeSupply(supply, cap);
}
}
_transferVotingUnits(from, to, value);
}
/**
* @dev Returns the voting units of an `account`.
*
* WARNING: Overriding this function may compromise the internal vote accounting.
* `ERC20Votes` assumes tokens map to voting units 1:1 and this is not easy to change.
*/
function _getVotingUnits(address account) internal view virtual override returns (uint256) {
return balanceOf(account);
}
/**
* @dev Get number of checkpoints for `account`.
*/
function numCheckpoints(address account) public view virtual returns (uint32) {
return _numCheckpoints(account);
}
/**
* @dev Get the `pos`-th checkpoint for `account`.
*/
function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoints.Checkpoint208 memory) {
return _checkpoints(account, pos);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)
pragma solidity ^0.8.20;
import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";
/**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
bytes32 private constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Permit deadline has expired.
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Mismatched signature.
*/
error ERC2612InvalidSigner(address signer, address owner);
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @inheritdoc IERC20Permit
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > deadline) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != owner) {
revert ERC2612InvalidSigner(signer, owner);
}
_approve(owner, spender, value);
}
/**
* @inheritdoc IERC20Permit
*/
function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
return super.nonces(owner);
}
/**
* @inheritdoc IERC20Permit
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparatorV4();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (governance/utils/Votes.sol)
pragma solidity ^0.8.20;
import {IERC5805} from "../../interfaces/IERC5805.sol";
import {Context} from "../../utils/Context.sol";
import {Nonces} from "../../utils/Nonces.sol";
import {EIP712} from "../../utils/cryptography/EIP712.sol";
import {Checkpoints} from "../../utils/structs/Checkpoints.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {ECDSA} from "../../utils/cryptography/ECDSA.sol";
import {Time} from "../../utils/types/Time.sol";
/**
* @dev This is a base abstract contract that tracks voting units, which are a measure of voting power that can be
* transferred, and provides a system of vote delegation, where an account can delegate its voting units to a sort of
* "representative" that will pool delegated voting units from different accounts and can then use it to vote in
* decisions. In fact, voting units _must_ be delegated in order to count as actual votes, and an account has to
* delegate those votes to itself if it wishes to participate in decisions and does not have a trusted representative.
*
* This contract is often combined with a token contract such that voting units correspond to token units. For an
* example, see {ERC721Votes}.
*
* The full history of delegate votes is tracked on-chain so that governance protocols can consider votes as distributed
* at a particular block number to protect against flash loans and double voting. The opt-in delegate system makes the
* cost of this history tracking optional.
*
* When using this module the derived contract must implement {_getVotingUnits} (for example, make it return
* {ERC721-balanceOf}), and can use {_transferVotingUnits} to track a change in the distribution of those units (in the
* previous example, it would be included in {ERC721-_update}).
*/
abstract contract Votes is Context, EIP712, Nonces, IERC5805 {
using Checkpoints for Checkpoints.Trace208;
bytes32 private constant DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
mapping(address account => address) private _delegatee;
mapping(address delegatee => Checkpoints.Trace208) private _delegateCheckpoints;
Checkpoints.Trace208 private _totalCheckpoints;
/**
* @dev The clock was incorrectly modified.
*/
error ERC6372InconsistentClock();
/**
* @dev Lookup to future votes is not available.
*/
error ERC5805FutureLookup(uint256 timepoint, uint48 clock);
/**
* @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based
* checkpoints (and voting), in which case {CLOCK_MODE} should be overridden as well to match.
*/
function clock() public view virtual returns (uint48) {
return Time.blockNumber();
}
/**
* @dev Machine-readable description of the clock as specified in EIP-6372.
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public view virtual returns (string memory) {
// Check that the clock was not modified
if (clock() != Time.blockNumber()) {
revert ERC6372InconsistentClock();
}
return "mode=blocknumber&from=default";
}
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) public view virtual returns (uint256) {
return _delegateCheckpoints[account].latest();
}
/**
* @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*
* Requirements:
*
* - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
*/
function getPastVotes(address account, uint256 timepoint) public view virtual returns (uint256) {
uint48 currentTimepoint = clock();
if (timepoint >= currentTimepoint) {
revert ERC5805FutureLookup(timepoint, currentTimepoint);
}
return _delegateCheckpoints[account].upperLookupRecent(SafeCast.toUint48(timepoint));
}
/**
* @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*
* Requirements:
*
* - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.
*/
function getPastTotalSupply(uint256 timepoint) public view virtual returns (uint256) {
uint48 currentTimepoint = clock();
if (timepoint >= currentTimepoint) {
revert ERC5805FutureLookup(timepoint, currentTimepoint);
}
return _totalCheckpoints.upperLookupRecent(SafeCast.toUint48(timepoint));
}
/**
* @dev Returns the current total supply of votes.
*/
function _getTotalSupply() internal view virtual returns (uint256) {
return _totalCheckpoints.latest();
}
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) public view virtual returns (address) {
return _delegatee[account];
}
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) public virtual {
address account = _msgSender();
_delegate(account, delegatee);
}
/**
* @dev Delegates votes from signer to `delegatee`.
*/
function delegateBySig(
address delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > expiry) {
revert VotesExpiredSignature(expiry);
}
address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
v,
r,
s
);
_useCheckedNonce(signer, nonce);
_delegate(signer, delegatee);
}
/**
* @dev Delegate all of `account`'s voting units to `delegatee`.
*
* Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.
*/
function _delegate(address account, address delegatee) internal virtual {
address oldDelegate = delegates(account);
_delegatee[account] = delegatee;
emit DelegateChanged(account, oldDelegate, delegatee);
_moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));
}
/**
* @dev Transfers, mints, or burns voting units. To register a mint, `from` should be zero. To register a burn, `to`
* should be zero. Total supply of voting units will be adjusted with mints and burns.
*/
function _transferVotingUnits(address from, address to, uint256 amount) internal virtual {
if (from == address(0)) {
_push(_totalCheckpoints, _add, SafeCast.toUint208(amount));
}
if (to == address(0)) {
_push(_totalCheckpoints, _subtract, SafeCast.toUint208(amount));
}
_moveDelegateVotes(delegates(from), delegates(to), amount);
}
/**
* @dev Moves delegated votes from one delegate to another.
*/
function _moveDelegateVotes(address from, address to, uint256 amount) private {
if (from != to && amount > 0) {
if (from != address(0)) {
(uint256 oldValue, uint256 newValue) = _push(
_delegateCheckpoints[from],
_subtract,
SafeCast.toUint208(amount)
);
emit DelegateVotesChanged(from, oldValue, newValue);
}
if (to != address(0)) {
(uint256 oldValue, uint256 newValue) = _push(
_delegateCheckpoints[to],
_add,
SafeCast.toUint208(amount)
);
emit DelegateVotesChanged(to, oldValue, newValue);
}
}
}
/**
* @dev Get number of checkpoints for `account`.
*/
function _numCheckpoints(address account) internal view virtual returns (uint32) {
return SafeCast.toUint32(_delegateCheckpoints[account].length());
}
/**
* @dev Get the `pos`-th checkpoint for `account`.
*/
function _checkpoints(
address account,
uint32 pos
) internal view virtual returns (Checkpoints.Checkpoint208 memory) {
return _delegateCheckpoints[account].at(pos);
}
function _push(
Checkpoints.Trace208 storage store,
function(uint208, uint208) view returns (uint208) op,
uint208 delta
) private returns (uint208, uint208) {
return store.push(clock(), op(store.latest(), delta));
}
function _add(uint208 a, uint208 b) private pure returns (uint208) {
return a + b;
}
function _subtract(uint208 a, uint208 b) private pure returns (uint208) {
return a - b;
}
/**
* @dev Must return the voting units held by an account.
*/
function _getVotingUnits(address) internal view virtual returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}{
"remappings": [
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-core/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"permit2/=lib/v4-periphery/lib/permit2/",
"@solmate/=lib/v4-core/lib/solmate/src/",
"@solady/=lib/solady/src/",
"src:@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/contracts/",
"test:@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/contracts/",
"@v4-periphery/=lib/v4-periphery/src/",
"@v4-periphery-test/=lib/v4-periphery/test/",
"@v4-core-test/=lib/v4-periphery/lib/v4-core/test/",
"@v4-core/=lib/v4-periphery/lib/v4-core/src/",
"@v3-periphery/=lib/v3-periphery/contracts/",
"@v3-core/=lib/v3-core/contracts/",
"@uniswap/v3-core/=lib/v3-core/",
"@universal-router/=lib/universal-router/contracts/",
"@uniswap/v2-core/contracts/interfaces/=src/interfaces/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"@uniswap/v3-periphery/=lib/universal-router/lib/v3-periphery/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"@uniswap/v4-periphery/=lib/universal-router/lib/v4-periphery/",
"openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"solady/=lib/solady/src/",
"solmate/=lib/universal-router/lib/solmate/",
"universal-router/=lib/universal-router/",
"v3-core/=lib/v3-core/",
"v3-periphery/=lib/v3-periphery/contracts/",
"v4-core/=lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/",
"view-quoter-v4/=lib/view-quoter-v4/src/"
],
"optimizer": {
"enabled": true,
"runs": 0
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"airlock_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"SenderNotAirlock","type":"error"},{"inputs":[],"name":"airlock","outputs":[{"internalType":"contract Airlock","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"create","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timelockFactory","outputs":[{"internalType":"contract TimelockFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60c0346100cf57601f6166ef38819003918201601f19168301916001600160401b038311848410176100bb578084926020946040528339810103126100cf57516001600160a01b038116908190036100cf57608052604051611b5c8082016001600160401b038111838210176100bb578291614b93833903905ff080156100b05760a052604051614abf90816100d482396080518181816054015260ed015260a0518181816101d5015261050e0152f35b6040513d5f823e3d90fd5b634e487b7160e01b5f52604160045260245ffd5b5f80fdfe6080806040526004361015610012575f80fd5b5f905f3560e01c908163601846df146104fc57508063a3f697ba146100865763f78a8a3e1461003f575f80fd5b346100835780600319360112610083576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b80fd5b5034610491576040366003190112610491576004356001600160a01b03811690819003610491576024356001600160401b03811161049157366023820112156104915760048101356001600160401b038111610491578101916024830192368411610491577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633036104ed57608090839003126104915760248201356001600160401b03811161049157820192806043850112156104915760248401356001600160401b0381116104955760405194610172601f8301601f19166020018761053d565b81865260208601926044828401011161049157815f9260446020930185378601015260448301359365ffffffffffff85168095036104915760648401359063ffffffff821680920361049157604051633bf206a360e21b8152916020836004815f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af1928315610486575f936104a9575b50610248600b6020604051809782820196518091885e81016a20476f7665726e616e636560a81b83820152030160141981018752018561053d565b60405195614552808801949092906001600160401b038611898710176104955760e09789976084956105618a3960c088525180968160c08a01528a89015e5f898789010152602087015260018060a01b03169889604087015260608601526080850152013560a0830152601f8019910116010301905ff08015610486576001600160a01b031690803b1561049157604051632f2ff15d60e01b81527fb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc16004820152602481018390525f8160448183865af1801561048657610471575b50803b1561042d5782604051632f2ff15d60e01b81527ffd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f7836004820152836024820152818160448183875af180156104515761045c575b5050803b1561042d5782604051632f2ff15d60e01b81527fd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e636004820152816024820152818160448183875af180156104515761043c575b5050803b1561042d57604051631b2b455f60e11b815260048101849052306024820152838160448183865af1801561043157610418575b6040838382519182526020820152f35b61042384809261053d565b61042d5782610408565b8280fd5b6040513d86823e3d90fd5b816104469161053d565b61042d57825f6103d1565b6040513d84823e3d90fd5b816104669161053d565b61042d57825f61037a565b61047e9193505f9061053d565b5f915f610324565b6040513d5f823e3d90fd5b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b9092506020813d6020116104e5575b816104c56020938361053d565b8101031261049157516001600160a01b038116810361049157915f61020d565b3d91506104b8565b633617fe5360e11b5f5260045ffd5b34610491575f366003190112610491577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b601f909101601f19168101906001600160401b038211908210176104955760405256fe6101a0604052346100c557610021610015610169565b9493909392919261024d565b6040516139c59081610b8d823960805181613042015260a051816130f9015260c0518161300c015260e05181613091015261010051816130b70152610120518161139f015261014051816113cb0152610160518181816115f101528181611a5101528181611b8c01528181611c2b01528181611df80152818161210d015281816121c20152818161294201526137f50152610180518181816103ef0152612b360152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761010057604052565b6100c9565b604051906101146040836100dd565b565b6001600160401b03811161010057601f01601f191660200190565b51906001600160a01b03821682036100c557565b519065ffffffffffff821682036100c557565b519063ffffffff821682036100c557565b61455290813803806040519361017f82866100dd565b843982019060c0838303126100c55782516001600160401b0381116100c557830182601f820112156100c5578051906101b782610116565b936101c560405195866100dd565b828552602083830101116100c557815f9260208093018387015e840101526101ef60208401610131565b926101fc60408201610131565b9261020960608301610145565b9260a061021860808501610158565b93015191959493929190565b634e487b7160e01b5f52601160045260245ffd5b906276a700820180921161024857565b610224565b610320929461031661033a97939561031161031b946040516102706040826100dd565b6001815260208101603160f81b8152610288836106b9565b610120526102958261079c565b6101405282516020840120918260e05251902080610100524660a0526040519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604083015260608201524660808201523060a082015260a0815261030260c0826100dd565b5190206080523060c0526103ee565b6105b2565b6105ff565b610680565b6001600160a01b031661016052610335610519565b6104c6565b61034f61034642610238565b63ffffffff1690565b61018052565b90600182811c92168015610383575b602083101461036f57565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610364565b601f821161039a57505050565b5f5260205f20906020601f840160051c830193106103d2575b601f0160051c01905b8181106103c7575050565b5f81556001016103bc565b90915081906103b3565b8160011b915f199060031b1c19161790565b80519091906001600160401b0381116101005761041781610410600354610355565b600361038d565b602092601f821160011461044a5761043a929382915f9261043f575b50506103dc565b600355565b015190505f80610433565b60035f52601f198216937fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b915f5b8681106104ae5750836001959610610496575b505050811b01600355565b01515f1960f88460031b161c191690555f808061048b565b91926020600181928685015181550194019201610478565b600b54604080516001600160a01b03808416825290931660208401819052927f08f74ea46ef7894f65eabfb5e6e695de773a000b47c529ab559178069b2264019190a16001600160a01b03191617600b55565b600a548061057957505f5b6001600160d01b0316610535610881565b7f0553476bf02ef2726e8ce5ced78d63e26e602e4a2257b1f559418e24b463399791600891610565908390610a58565b5050604080519182526020820192909252a1565b805f1981011161024857600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a7015460301c610524565b6008547fc565b045403dc03c2eea82b81a0465edad9e2e7fc4d97e11421c209da93d7a93604065ffffffffffff81519481851686521693846020820152a165ffffffffffff191617600855565b63ffffffff811690811561066d5769ffffffff000000000000907f7e3f7f0708a84de9203036abaa450dccc85ad5ff52f78c170f3edb55cf5e882860406008549481519063ffffffff8760301c1682526020820152a160301b169069ffffffff000000000000191617600855565b63f1cfbf0560e01b5f525f60045260245ffd5b60075460408051918252602082018390527fccb45da8d5717e6c4544694297c4ba5cf151d455c9bb0ed4fc7a38411bc0546191a1600755565b908151602081105f146106d45750906106d190610923565b90565b6001600160401b038111610100576106f6816106f05f54610355565b5f61038d565b602092601f821160011461071f57610718929382915f9261043f5750506103dc565b5f5560ff90565b5f8052601f198216937f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563915f5b868110610784575083600195961061076c575b505050811b015f5560ff90565b01515f1960f88460031b161c191690555f808061075f565b9192602060018192868501518155019401920161074c565b908151602081105f146107b45750906106d190610923565b6001600160401b038111610100576107d8816107d1600154610355565b600161038d565b602092601f8211600114610802576107fa929382915f9261043f5750506103dc565b60015560ff90565b60015f52601f198216937fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6915f5b8681106108695750836001959610610851575b505050811b0160015560ff90565b01515f1960f88460031b161c191690555f8080610843565b91926020600181928685015181550194019201610830565b610160516040516324776b7d60e21b815290602090829060049082906001600160a01b03165afa5f91816108e7575b506106d1575065ffffffffffff43116108cf5765ffffffffffff431690565b6306dfcc6560e41b5f5260306004524360245260445ffd5b9091506020813d60201161091b575b81610903602093836100dd565b810103126100c55761091490610145565b905f6108b0565b3d91506108f6565b601f81511161094e57602081519101516020821061093f571790565b5f198260200360031b1b161790565b604460209160405192839163305a27a960e01b83528160048401528051918291826024860152018484015e5f828201840152601f01601f19168101030190fd5b5f1981019190821161024857565b9065ffffffffffff82549181199060301b169116179055565b908154680100000000000000008110156101005760018101808455811015610a0e57610114925f5260205f20019065ffffffffffff81511665ffffffffffff19835416178255602060018060d01b03910151169061099c565b634e487b7160e01b5f52603260045260245ffd5b604080519192919081016001600160401b0381118282101761010057604052915465ffffffffffff8116835260301c6020830152565b600a54919291908115610b635781610aaa610aa5610a7c65ffffffffffff9561098e565b600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80190565b610a22565b90610abb825165ffffffffffff1690565b8484169485911611610b545785602093610b1595610aed610ae2865165ffffffffffff1690565b65ffffffffffff1690565b03610b195750610b02610a7c610b079361098e565b61099c565b01516001600160d01b031690565b9190565b9050610b4f9150610b39610b2b610105565b65ffffffffffff9092168252565b6001600160d01b038716818501525b600a6109b5565b610b07565b632520601d60e01b5f5260045ffd5b610b879150610b73610b2b610105565b6001600160d01b0384166020820152610b48565b5f919056fe60806040526004361015610022575b3615610018575f80fd5b6100206123f9565b005b5f3560e01c806301ffc9a71461033157806302a251a31461032c57806305c44b9a1461032757806306f3f9e61461032257806306fdde031461031d578063143489d014610318578063150b7a0214610313578063160cbed71461030e5780632656227d146103095780632d63f693146103045780632fe3e261146102ff5780633932abb1146102fa5780633e4f49e6146102f557806343859632146102f0578063452115d6146102eb5780634bf5d7e9146102e6578063544ffc9c146102e157806354fd4d50146102dc57806356781388146102d75780635b8d0e0d146102d25780635f398a14146102cd57806360c4247f146102c857806379051887146102c35780637b3c71d3146102be5780637d5e81e2146102b95780637ecebe00146102b457806384b0196e146102af5780638ff262e3146102aa57806391ddadf4146102a557806397c3d334146102a05780639a802a6d1461029b578063a7713a7014610296578063a890c91014610291578063a9a952941461028c578063ab58fb8e14610287578063b58131b014610282578063bc197c811461027d578063c01f9e3714610278578063c28bc2fa14610273578063c59057e41461026e578063d33219b414610269578063dd4e2ba514610264578063deaaa7cc1461025f578063e540d01d1461025a578063eb9019d414610255578063ece40cc114610250578063f23a6e611461024b578063f8ce560a146102465763fc0c546a0361000e57611c16565b611b5b565b611ae9565b611a94565b6119ef565b61194e565b611927565b6118c8565b6118a0565b611884565b611819565b6117fb565b61174e565b611731565b611713565b6116f7565b61167f565b611654565b61157f565b611564565b61153a565b611457565b611387565b611319565b61126b565b611216565b6111a4565b611176565b6110ff565b611057565b610fe9565b610f96565b610f55565b610f26565b610de7565b610da2565b610d73565b610d1d565b610cf6565b610cc1565b610b76565b61094d565b610704565b610608565b610511565b610413565b6103d3565b6103ad565b3461039f57602036600319011261039f5760043563ffffffff60e01b811680910361039f576020906332a2ad4360e11b811490811561038e575b811561037d575b506040519015158152f35b6301ffc9a760e01b1490505f610372565b630271189760e51b8114915061036b565b5f80fd5b5f91031261039f57565b3461039f575f36600319011261039f57602063ffffffff60085460301c16604051908152f35b3461039f575f36600319011261039f57602060405163ffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b3461039f57602036600319011261039f5760043561042f61240f565b606481116104c2576001600160d01b03610447612d46565b16906104516121ad565b916001600160d01b0382116104aa577f0553476bf02ef2726e8ce5ced78d63e26e602e4a2257b1f559418e24b463399792610496906001600160d01b038416906136ae565b5050604080519182526020820192909252a1005b506306dfcc6560e41b5f5260d060045260245260445ffd5b63243e544560e01b5f52600452606460245260445ffd5b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602061050e9281815201906104d9565b90565b3461039f575f36600319011261039f576040515f60035461053181611c5a565b80845290600181169081156105c75750600114610569575b610565836105598185038261065f565b604051918291826104fd565b0390f35b60035f9081527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b939250905b8082106105ad57509091508101602001610559610549565b919260018160209254838588010152019101909291610595565b60ff191660208086019190915291151560051b840190910191506105599050610549565b6001600160a01b031690565b6001600160a01b0316600452602490565b3461039f57602036600319011261039f576004355f526004602052602060018060a01b0360405f205416604051908152f35b6001600160a01b0381160361039f57565b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761068257604052565b61064b565b6040519061069660408361065f565b565b6001600160401b03811161068257601f01601f191660200190565b9291926106bf82610698565b916106cd604051938461065f565b82948184528183011161039f578281602093845f960137010152565b9080601f8301121561039f5781602061050e933591016106b3565b3461039f57608036600319011261039f5761072060043561063a565b61072b60243561063a565b6064356001600160401b03811161039f5761074a9036906004016106e9565b506107536123ea565b306001600160a01b039091160361077657604051630a85bd0160e11b8152602090f35b637485328f60e11b5f5260045ffd5b6001600160401b0381116106825760051b60200190565b9080601f8301121561039f5781356107b381610785565b926107c1604051948561065f565b81845260208085019260051b82010192831161039f57602001905b8282106107e95750505090565b6020809183356107f88161063a565b8152019101906107dc565b9080601f8301121561039f57813561081a81610785565b92610828604051948561065f565b81845260208085019260051b82010192831161039f57602001905b8282106108505750505090565b8135815260209182019101610843565b9080601f8301121561039f57813561087781610785565b92610885604051948561065f565b81845260208085019260051b8201019183831161039f5760208201905b8382106108b157505050505090565b81356001600160401b03811161039f576020916108d3878480948801016106e9565b8152019101906108a2565b608060031982011261039f576004356001600160401b03811161039f57816109089160040161079c565b916024356001600160401b03811161039f578261092791600401610803565b91604435906001600160401b03821161039f5761094691600401610860565b9060643590565b3461039f5761095b366108de565b909261096982858584612383565b93610973856124c1565b50610987610982600b546105eb565b6105eb565b936040519363793d064960e11b8552602085600481895afa948515610b21575f95610b55575b506109da6109cd6109bd306105eb565b60601b6001600160601b03191690565b6001600160601b03191690565b18946020604051809263b1c5f42760e01b825281806109ff8b89898c60048601612e19565b03915afa908115610b21575f91610b26575b50610a1b87611d13565b55610a2a610982600b546105eb565b90813b1561039f575f8094610a5687604051998a97889687956308f2a0bb60e41b875260048701612e5e565b03925af1908115610b2157610a7a92610a7592610b07575b5042612a55565b612a18565b9065ffffffffffff821615610af8577f9a2e42fd6722813d69113e7d0079d3d940171428df7373df9c7f7617cfda2892610ae583610ac6610565956001610ac087611d21565b01611d2f565b6040805185815265ffffffffffff909216602083015290918291820190565b0390a16040519081529081906020820190565b634844252360e11b5f5260045ffd5b80610b155f610b1b9361065f565b806103a3565b5f610a6e565b611d8a565b610b48915060203d602011610b4e575b610b40818361065f565b810190612d37565b5f610a11565b503d610b36565b610b6f91955060203d602011610b4e57610b40818361065f565b935f6109ad565b610b7f366108de565b91610b8c83838387612383565b936020610b9a603087612581565b50610bba610ba787611d21565b805460ff60f01b1916600160f01b179055565b610bc26123ea565b306001600160a01b0390911603610c59575b5091849391610be69361056596612eab565b30610bf26109826123ea565b141580610c3a575b610c31575b6040518181527f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f908060208101610ae5565b5f600555610bff565b506005546001600160801b03811660809190911c1415610bfa565b1590565b949091935f5b8351811015610cb35760019030610c89610982610c7c8489611d5c565b516001600160a01b031690565b14610c95575b01610c5f565b610cae610ca28288611d5c565b518981519101206125bf565b610c8f565b509094509290610565610bd4565b3461039f57602036600319011261039f576004355f526004602052602065ffffffffffff60405f205460a01c16604051908152f35b3461039f575f36600319011261039f5760206040515f805160206139998339815191528152f35b3461039f575f36600319011261039f57602065ffffffffffff60085416604051908152f35b634e487b7160e01b5f52602160045260245ffd5b60081115610d6057565b610d42565b6008811015610d6057602452565b3461039f57602036600319011261039f57610d8f60043561263a565b6040516008821015610d60576020918152f35b3461039f57604036600319011261039f57602060ff610ddb602435600435610dc98261063a565b5f5260098452600360405f2001611d75565b54166040519015158152f35b3461039f57610df5366108de565b91610e0283838387612383565b610e0b81612501565b505f908152600460205260409020546001600160a01b03163303610f1357610e3293612383565b610e3d603b82612581565b50610e5f610e4a82611d21565b80546001600160f81b0316600160f81b179055565b6040518181527f789cf55be980739dad1d0699b93b58e806b51c9d96619bfa8fe0a28abaa7b30c90602090a1610e9481611d13565b549081610ea7575b604051908152602090f35b610eb5610982600b546105eb565b803b1561039f5760405163c4d252f560e01b815260048101939093525f908390602490829084905af1918215610b215761056592610eff575b505f610ef982611d13565b55610e9c565b80610b155f610f0d9361065f565b5f610eee565b63233d98e360e01b5f523360045260245ffd5b3461039f575f36600319011261039f57610565610f41611de4565b6040519182916020835260208301906104d9565b3461039f57602036600319011261039f576004355f526009602052606060405f20805490600260018201549101549060405192835260208301526040820152f35b3461039f575f36600319011261039f57610565604051610fb760408261065f565b60018152603160f81b60208201526040519182916020835260208301906104d9565b6024359060ff8216820361039f57565b3461039f57604036600319011261039f57602061102260043561100a610fd9565b60405191611018858461065f565b5f83523390612737565b604051908152f35b9181601f8401121561039f578235916001600160401b03831161039f576020838186019501011161039f57565b3461039f5760c036600319011261039f57600435611073610fd9565b90604435906110818261063a565b6064356001600160401b03811161039f576110a090369060040161102a565b6084356001600160401b03811161039f576110bf9036906004016106e9565b60a435949092906001600160401b03861161039f57610565966110e96110ef9736906004016106e9565b95611eb3565b6040519081529081906020820190565b3461039f57608036600319011261039f5760043561111b610fd9565b906044356001600160401b03811161039f5761113b90369060040161102a565b90929091906064356001600160401b03811161039f57610e9c9461116661116e9236906004016106e9565b9436916106b3565b9133906128d9565b3461039f57602036600319011261039f576020611022600435611fa0565b65ffffffffffff81160361039f57565b3461039f57602036600319011261039f576004356111c181611194565b6111c961240f565b6008547fc565b045403dc03c2eea82b81a0465edad9e2e7fc4d97e11421c209da93d7a93604065ffffffffffff81519481851686521693846020820152a165ffffffffffff191617600855005b3461039f57606036600319011261039f57600435611232610fd9565b90604435906001600160401b03821161039f5760209261126361125c61102294369060040161102a565b36916106b3565b913390612737565b3461039f57608036600319011261039f576004356001600160401b03811161039f5761129b90369060040161079c565b6024356001600160401b03811161039f576112ba903690600401610803565b906044356001600160401b03811161039f576112da903690600401610860565b60643591906001600160401b03831161039f573660238401121561039f57610565936113136110ef9436906024816004013591016106b3565b9261209d565b3461039f57602036600319011261039f576004356113368161063a565b60018060a01b03165f526002602052602060405f2054604051908152f35b90602080835192838152019201905f5b8181106113715750505090565b8251845260209384019390920191600101611364565b3461039f575f36600319011261039f576114296113c37f000000000000000000000000000000000000000000000000000000000000000061357a565b6105656113ef7f00000000000000000000000000000000000000000000000000000000000000006135d9565b6114376040519161140160208461065f565b5f808452366020850137604051958695600f60f81b875260e0602088015260e08701906104d9565b9085820360408701526104d9565b904660608501523060808501525f60a085015283820360c0850152611354565b3461039f57608036600319011261039f57600435611473610fd9565b90604435916114818361063a565b6064356001600160401b03811161039f57610c556114a66115099236906004016106e9565b6115036114b287612754565b60405160208101915f80516020613979833981519152835288604083015260ff8816606083015260018060a01b038a16608083015260a082015260a081526114fb60c08261065f565b519020612776565b8661279c565b61152457906110ef916105659361151e611d95565b92612737565b6394ab6c0760e01b5f52611537836105f7565b5ffd5b3461039f575f36600319011261039f5760206115546121ad565b65ffffffffffff60405191168152f35b3461039f575f36600319011261039f57602060405160648152f35b3461039f57606036600319011261039f5760043561159c8161063a565b6024356044356001600160401b03811161039f576115be9036906004016106e9565b50604051630748d63560e31b81526001600160a01b039283166004820152602481019190915290602090829060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa8015610b2157610565915f91611635575b506040519081529081906020820190565b61164e915060203d602011610b4e57610b40818361065f565b5f611624565b3461039f575f36600319011261039f5760206001600160d01b03611676612d46565b16604051908152f35b3461039f57602036600319011261039f5760043561169c8161063a565b6116a461240f565b600b54604080516001600160a01b03808416825290931660208401819052927f08f74ea46ef7894f65eabfb5e6e695de773a000b47c529ab559178069b2264019190a16001600160a01b03191617600b55005b3461039f57602036600319011261039f57602060405160018152f35b3461039f57602036600319011261039f576020611022600435612240565b3461039f575f36600319011261039f576020600754604051908152f35b3461039f5760a036600319011261039f5761176a60043561063a565b61177560243561063a565b6044356001600160401b03811161039f57611794903690600401610803565b506064356001600160401b03811161039f576117b4903690600401610803565b506084356001600160401b03811161039f576117d49036906004016106e9565b506105656117e061225a565b6040516001600160e01b031990911681529081906020820190565b3461039f57602036600319011261039f576020611022600435612279565b606036600319011261039f576004356118318161063a565b6024356044356001600160401b03811161039f57610020925f9261185a8493369060040161102a565b919061186461240f565b826040519384928337810185815203925af161187e6122c0565b90612d77565b3461039f576020611022611897366108de565b92919091612383565b3461039f575f36600319011261039f57600b546040516001600160a01b039091168152602090f35b3461039f575f36600319011261039f576105656040516118e960408261065f565b602081527f737570706f72743d627261766f2671756f72756d3d666f722c6162737461696e60208201526040519182916020835260208301906104d9565b3461039f575f36600319011261039f5760206040515f805160206139798339815191528152f35b3461039f57602036600319011261039f5760043563ffffffff81169081810361039f5761197961240f565b81156119dc577f7e3f7f0708a84de9203036abaa450dccc85ad5ff52f78c170f3edb55cf5e882860406008549381519063ffffffff8660301c1682526020820152a163ffffffff60301b1990911660309190911b63ffffffff60301b1617600855005b63f1cfbf0560e01b5f525f60045260245ffd5b3461039f57604036600319011261039f57600435611a0c8161063a565b6024355f604051611a1e60208261065f565b52604051630748d63560e31b81526001600160a01b039283166004820152602481019190915290602090829060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa8015610b2157610565915f9161163557506040519081529081906020820190565b3461039f57602036600319011261039f57600435611ab061240f565b60075460408051918252602082018390527fccb45da8d5717e6c4544694297c4ba5cf151d455c9bb0ed4fc7a38411bc0546191a1600755005b3461039f5760a036600319011261039f57611b0560043561063a565b611b1060243561063a565b6084356001600160401b03811161039f57611b2f9036906004016106e9565b50611b386123ea565b306001600160a01b03909116036107765760405163f23a6e6160e01b8152602090f35b3461039f57602036600319011261039f57600435604051632394e7a360e21b815260048101829052906020826024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215610b21575f92611bf1575b50611bce90611fa0565b90818102918183041490151715611bec5761056590606490046110ef565b611f6f565b611bce919250611c0f9060203d602011610b4e57610b40818361065f565b9190611bc4565b3461039f575f36600319011261039f576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b90600182811c92168015611c88575b6020831014611c7457565b634e487b7160e01b5f52602260045260245ffd5b91607f1691611c69565b5f9291815491611ca183611c5a565b8083529260018116908115611cf65750600114611cbd57505050565b5f9081526020812093945091925b838310611cdc575060209250010190565b600181602092949394548385870101520191019190611ccb565b915050602093945060ff929192191683830152151560051b010190565b5f52600c60205260405f2090565b5f52600460205260405f2090565b9065ffffffffffff1665ffffffffffff19825416179055565b634e487b7160e01b5f52603260045260245ffd5b8051821015611d705760209160051b010190565b611d48565b9060018060a01b03165f5260205260405f2090565b6040513d5f823e3d90fd5b60405190611da460208361065f565b5f8252565b60405190611db860408361065f565b601d82527f6d6f64653d626c6f636b6e756d6265722666726f6d3d64656661756c740000006020830152565b604051634bf5d7e960e01b81525f816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa5f9181611e38575b5061050e575061050e611da9565b9091503d805f833e611e4a818361065f565b81019060208183031261039f578051906001600160401b03821161039f570181601f8201121561039f57805190611e8082610698565b92611e8e604051948561065f565b8284526020838301011161039f57815f9260208093018386015e83010152905f611e2a565b939092919695610c55611f4191611f3b8a611ecd81612754565b611ed836888a6106b3565b602081519101208b5160208d0120906040519260208401945f8051602061399983398151915286528d604086015260ff8d16606086015260018060a01b0316608085015260a084015260c083015260e082015260e081526114fb6101008261065f565b8a61279c565b611f5c5761050e959691611f569136916106b3565b926128d9565b6394ab6c0760e01b5f52611537876105f7565b634e487b7160e01b5f52601160045260245ffd5b5f19810191908211611bec57565b602719810191908211611bec57565b600a54905f198201828111611bec57821115611d7057600a5f525f8051602061393983398151915282015465ffffffffffff81168210156120945750611fe590612a18565b5f829160058411612040575b611ffb9350613382565b8061200557505f90565b61203461202d61201761050e93611f83565b600a5f525f805160206139598339815191520190565b5460301c90565b6001600160d01b031690565b919261204b8161320f565b8103908111611bec57611ffb93600a5f5265ffffffffffff8260205f2001541665ffffffffffff8516105f14612082575091611ff1565b92915061208e90612a47565b90611ff1565b91505060301c90565b91939290936120ac8233612a73565b1561219a575f1965ffffffffffff6120c26121ad565b16019465ffffffffffff8611611bec575f6040516120e160208261065f565b52604051630748d63560e31b815233600482015265ffffffffffff9690961660248701526020866044817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa958615610b21575f96612179575b5060075480871061215e575061050e9495503393612b2a565b636121770b60e11b5f5233600452602487905260445260645ffd5b61219391965060203d602011610b4e57610b40818361065f565b945f612145565b63d9b3955760e01b5f523360045260245ffd5b6040516324776b7d60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa5f9181612203575b5061050e575061050e43612a18565b9091506020813d602011612238575b8161221f6020938361065f565b8101031261039f575161223181611194565b905f6121f4565b3d9150612212565b5f52600460205265ffffffffffff600160405f2001541690565b600b54306001600160a01b03909116036107765763bc197c8160e01b90565b805f52600460205265ffffffffffff60405f205460a01c16905f52600460205263ffffffff60405f205460d01c160165ffffffffffff8111611bec5765ffffffffffff1690565b3d156122ea573d906122d182610698565b916122df604051938461065f565b82523d5f602084013e565b606090565b90602080835192838152019201905f5b81811061230c5750505090565b82516001600160a01b03168452602093840193909201916001016122ff565b9080602083519182815201916020808360051b8301019401925f915b83831061235657505050505090565b9091929394602080612374600193601f1986820301875289516104d9565b97019301930191939290612347565b92906123e4916123d06123be946040519586946123ac602087019960808b5260a08801906122ef565b868103601f1901604088015290611354565b848103601f190160608601529061232b565b90608083015203601f19810183528261065f565b51902090565b600b546001600160a01b031690565b600b54306001600160a01b039091160361077657565b6124176123ea565b336001600160a01b0390911603612482576124306123ea565b306001600160a01b039091160361244357565b61244c36610698565b612459604051918261065f565b3681526020810190365f83375f602036830101525190205b8061247a612dbb565b036124715750565b6347096e4760e01b5f523360045260245ffd5b6008811015610d605760ff600191161b90565b600452606491906008811015610d60576024525f604452565b6124ca8161263a565b9060106124d683612495565b16156124e0575090565b6331b75e4d60e01b5f526004526124f79150610d65565b601060445260645ffd5b61250a8161263a565b90600161251683612495565b1615612520575090565b6331b75e4d60e01b5f526004526125379150610d65565b600160445260645ffd5b61254a8161263a565b90600261255683612495565b1615612560575090565b6331b75e4d60e01b5f526004526125779150610d65565b600260445260645ffd5b9061258b8261263a565b918161259684612495565b16156125a157505090565b6331b75e4d60e01b5f526004526125b782610d65565b60445260645ffd5b6005546001608082901c90810192916001600160801b03808516911614612613575f90815260066020526040902055600580546001600160801b031660809290921b6001600160801b031916919091179055565b638acb5f2760e01b5f5260045ffd5b9081602091031261039f5751801515810361039f5790565b61264381612f30565b9061264d82610d56565b600582036127335761265f9150611d13565b5461266e610982600b546105eb565b604051632c258a9f60e11b815260048101839052602081602481855afa908115610b21575f91612714575b50156126a6575050600590565b604051632ab0f52960e01b81526004810192909252602090829060249082905afa908115610b21575f916126e5575b50156126e057600790565b600290565b612707915060203d60201161270d575b6126ff818361065f565b810190612622565b5f6126d5565b503d6126f5565b61272d915060203d60201161270d576126ff818361065f565b5f612699565b5090565b9161050e93916040519361274c60208661065f565b5f85526128d9565b6001600160a01b03165f90815260026020526040902080546001810190915590565b604290612781613009565b906040519161190160f01b8352600283015260228201522090565b906127a7838261311f565b506004819592951015610d6057159384612863575b5083156127ca575b50505090565b5f9350906128026128108594936040519283916020830195630b135d3f60e11b875260248401526040604484015260648301906104d9565b03601f19810183528261065f565b51915afa61281c6122c0565b81612855575b81612831575b505f80806127c4565b905061284e630b135d3f60e11b9160208082518301019101612d37565b145f612828565b905060208151101590612822565b6001600160a01b0384811691161493505f6127bc565b93909260ff6128a59361050e97958752166020860152604085015260a0606085015260a08401906104d9565b9160808184039101526104d9565b909260ff60809361050e96958452166020830152604082015281606082015201906104d9565b93929190936128e781612541565b50805f52600460205265ffffffffffff61290e60405f2065ffffffffffff905460a01c1690565b169360405195630748d63560e31b875260018060a01b03811695866004890152602488015260208760448160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa968715610b21575f976129f1575b50868461297f9285613159565b80516129be57506129b87fb8e138887d0aa13bab447e82de9d5c1777041ecd21ca36ba824ff1e6c07ddda49386604051948594856128b3565b0390a290565b6129b8907fe2babfbac5889a709b63bb7f598b324e08bc5a4fb9ec647fb3cbc9ec07eb8712948760405195869586612879565b84975090612a1061297f9260203d602011610b4e57610b40818361065f565b975090612972565b65ffffffffffff8111612a305765ffffffffffff1690565b6306dfcc6560e41b5f52603060045260245260445ffd5b9060018201809211611bec57565b91908201809211611bec57565b908151811015611d70570160200190565b815160348110612b225760131981840101516001600160a01b0319166b1b91f1b211f2119351b859f160a31b01612b2257915f92612ab081611f91565b915b818310612acd575050506001600160a01b0391821691161490565b909193612af3612aee612ae08785612a62565b516001600160f81b03191690565b6133e8565b9015612b175760019160ff9060041b6010600160a01b031691161794019190612ab2565b505050505050600190565b505050600190565b929093919363ffffffff7f0000000000000000000000000000000000000000000000000000000000000000164210612d2857612b6e82516020840120868387612383565b948451825190818114801590612d1d575b8015612d15575b612cf657505065ffffffffffff612bae612b9f88611d21565b5460a01c65ffffffffffff1690565b16612cd95791612cd3917f7d84a6263ae0d98d3329bd7b46bb4e8d6f98cd35a7adb45c274c8b7fd5ebd5e0959493612c14612be76121ad565b65ffffffffffff612c0d612c0265ffffffffffff6008541690565b65ffffffffffff1690565b9116612a55565b90612c33612c2a63ffffffff60085460301c1690565b63ffffffff1690565b612cb1612c3f8b611d21565b80546001600160a01b0319166001600160a01b038a16178155612c88612c6486612a18565b825465ffffffffffff60a01b191660a09190911b65ffffffffffff60a01b16178255565b612c918361390d565b815463ffffffff60d01b191660d09190911b63ffffffff60d01b16179055565b612cc5612cbe8951613465565b9184612a55565b936040519889988c8a6134ae565b0390a190565b61153786612ce68161263a565b6331b75e4d60e01b5f52906124a8565b9151630447b05d60e41b5f908152600493909352602452604452606490fd5b508015612b86565b508251811415612b7f565b635fd36d9960e11b5f5260045ffd5b9081602091031261039f575190565b600a5480612d5357505f90565b805f19810111611bec57600a5f525f80516020613939833981519152015460301c90565b9091906106965750805115612d8e57805190602001fd5b630a12f52160e11b5f5260045ffd5b8115612da7570490565b634e487b7160e01b5f52601260045260245ffd5b6005546001600160801b038116919060801c8214612e0a575f8281526006602052604081208054919055600580546001600160801b03191660019094016001600160801b031693909317909255565b6375e52f4f60e01b5f5260045ffd5b949392612e45608093612e37612e539460a08a5260a08a01906122ef565b9088820360208a0152611354565b90868203604088015261232b565b935f60608201520152565b9192612e8d60a094612e7f612e9b949998979960c0875260c08701906122ef565b908582036020870152611354565b90838203604085015261232b565b945f606083015260808201520152565b600b5490949192916001600160a01b03909116906001600160601b03193060601b16823b1561039f57612ef85f956040519788968795869563e38335e560e01b8752189260048601612e19565b039134905af18015610b2157612f17575b50612f145f91611d13565b55565b80612f235f809361065f565b80031261039f575f612f09565b612f3981611d21565b5460f881901c9060f01c60ff1661300257612ffc57612f5d612c02612b9f83611d21565b8015612fe857612f6e612c026121ad565b80911015612fe257612f7f82612279565b10612f8a5750600190565b612f96610c55826137ae565b8015612fbf575b15612fa85750600390565b612fb190612240565b612fba57600490565b600590565b50612fdd610c55825f52600960205260405f20600181015490541090565b612f9d565b50505f90565b636ad0607560e01b5f52600482905260245ffd5b50600290565b5050600790565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614806130f6575b15613064577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a081526123e460c08261065f565b507f0000000000000000000000000000000000000000000000000000000000000000461461303b565b815191906041830361314f576131489250602082015190606060408401519301515f1a90613883565b9192909190565b50505f9160029190565b61316e909291925f52600960205260405f2090565b91600383016131876131808383611d75565b5460ff1690565b6131fc5761319b60ff93926131a892611d75565b805460ff19166001179055565b16806131bf5750906131bb908254612a55565b9055565b600181036131d7575060016131bb9101918254612a55565b6002036131ed5760026131bb9101918254612a55565b6303599be160e11b5f5260045ffd5b6371c6af4960e01b5f52611537826105f7565b801561337d5761050e9061331361330c6133026132f86132ee6132e46132da6132d060016132be5f8b608081901c8061336f575b50806132526132b49260401c90565b80613362575b506132638160201c90565b80613355575b506132748160101c90565b80613348575b506132858160081c90565b8061333b575b506132968160041c90565b8061332e575b506132a78160021c90565b80613321575b5060011c90565b6133195760011c90565b1b6132c9818b612d9d565b0160011c90565b6132c9818a612d9d565b6132c98189612d9d565b6132c98188612d9d565b6132c98187612d9d565b6132c98186612d9d565b6132c98185612d9d565b8092612d9d565b906138fb565b820160011c90565b600291509201915f6132ad565b600491509201915f61329c565b600891509201915f61328b565b601091509201915f61327a565b602091509201915f613269565b604091509201915f613258565b6080925090506132b4613243565b505f90565b905b82811061339057505090565b90918082169080831860011c8201809211611bec57600a5f525f8051602061395983398151915282015465ffffffffffff90811690851610156133d65750915b90613384565b9291506133e290612a47565b906133d0565b60f81c9081602f108061345b575b1561340857600191602f190160ff1690565b8160401080613451575b15613424576001916036190160ff1690565b8160601080613447575b15613440576001916056190160ff1690565b5f91508190565b506067821061342e565b5060478210613412565b50603a82106133f6565b9061346f82610785565b61347c604051918261065f565b828152809261348d601f1991610785565b01905f5b82811061349d57505050565b806060602080938501015201613491565b9599989697949391926134ef936134e192885260018060a01b0316602088015261012060408801526101208701906122ef565b908582036060870152611354565b968388036080850152815180895260208901906020808260051b8c01019401915f905b82821061354e575050505061050e969750906135359184820360a086015261232b565b9360c083015260e08201526101008184039101526104d9565b9091929460208061356c6001938f601f1990820301865289516104d9565b970192019201909291613512565b60ff81146135c05760ff811690601f82116135b1576040519161359e60408461065f565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b5060405161050e816135d2815f611c92565b038261065f565b60ff81146135fd5760ff811690601f82116135b1576040519161359e60408461065f565b5060405161050e816135d2816001611c92565b9065ffffffffffff82549181199060301b169116179055565b908154600160401b8110156106825760018101808455811015611d7057610696925f5260205f20019061366565ffffffffffff82511683611d2f565b602001516001600160d01b031690613610565b604080519192919081016001600160401b0381118282101761068257604052915465ffffffffffff8116835260301c6020830152565b600a5491929190811561378557816136d76136d261201765ffffffffffff95611f83565b613678565b906136e8825165ffffffffffff1690565b848416948591161161377657856020936137379561370f612c02865165ffffffffffff1690565b0361373b575061372461201761372993611f83565b613610565b01516001600160d01b031690565b9190565b9050613771915061375b61374d610687565b65ffffffffffff9092168252565b6001600160d01b038716818501525b600a613629565b613729565b632520601d60e01b5f5260045ffd5b6137a9915061379561374d610687565b6001600160d01b038416602082015261376a565b5f9190565b805f52600960205260405f20905f52600460205265ffffffffffff60405f205460a01c1660405190632394e7a360e21b825280600483015260208260248160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa918215610b21575f9261385e575b5061382f90611fa0565b90818102918183041490151715611bec576138599060649004916002600182015491015490612a55565b101590565b61382f91925061387c9060203d602011610b4e57610b40818361065f565b9190613825565b91906fa2a8918ca85bafe22016d0b997e4df60600160ff1b0384116138f0579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610b21575f516001600160a01b038116156138e657905f905f90565b505f906001905f90565b5050505f9160039190565b9080821015613908575090565b905090565b63ffffffff81116139215763ffffffff1690565b6306dfcc6560e41b5f52602060045260245260445ffdfec65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a7c65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8f2aad550cf55f045cb27e9c559f9889fdfb6e6cdaa032301d6ea397784ae51d73e83946653575f9a39005e1545185629e92736b7528ab20ca3816f315424a811a164736f6c634300081a000aa164736f6c634300081a000a60808060405234601557611b42908161001a8239f35b5f80fdfe60806040526004361015610011575f80fd5b5f3560e01c63efc81a8c14610024575f80fd5b346100db575f3660031901126100db5761003c6100df565b6100446100df565b604051916119f19182840191906001600160401b038311858410176100c7576100886100969286956101458739620151808552608060208601526080850190610108565b908382036040850152610108565b9060603391015203905ff080156100bc576040516001600160a01b039091168152602090f35b6040513d5f823e3d90fd5b634e487b7160e01b5f52604160045260245ffd5b5f80fd5b60405190602082016001600160401b038111838210176100c7576040525f808352366020840137565b90602080835192838152019201905f5b8181106101255750505090565b82516001600160a01b031684526020938401939092019160010161011856fe608060405234610166576119f1803803806100198161016a565b92833981019060808183031261016657805160208201519091906001600160401b038111610166578361004d9183016101b7565b604082015190936001600160401b0382116101665761007360609161007a9385016101b7565b92016101a3565b61008330610249565b506001600160a01b038116610156575b505f5b83518110156100e0576001906100be6001600160a01b036100b78388610221565b51166102bf565b506100d9828060a01b036100d28388610221565b5116610352565b5001610096565b50905f5b82518110156101135760019061010c6001600160a01b036101058387610221565b51166103e5565b50016100e4565b7f11c24f4ead16507c69ac467fbd5e4eed5fb5c699626d2cc6d66421df253886d5604083806002558151905f82526020820152a16040516114d890816104798239f35b61015f90610249565b505f610093565b5f80fd5b6040519190601f01601f191682016001600160401b0381118382101761018f57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b038216820361016657565b9080601f83011215610166578151916001600160401b03831161018f578260051b906020806101e781850161016a565b80968152019282010192831161016657602001905b8282106102095750505090565b60208091610216846101a3565b8152019101906101fc565b80518210156102355760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b6001600160a01b0381165f9081525f805160206119d1833981519152602052604090205460ff166102ba576001600160a01b03165f8181525f805160206119d183398151915260205260408120805460ff191660011790553391905f805160206119518339815191528180a4600190565b505f90565b6001600160a01b0381165f9081525f80516020611971833981519152602052604090205460ff166102ba576001600160a01b03165f8181525f8051602061197183398151915260205260408120805460ff191660011790553391907fb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1905f805160206119518339815191529080a4600190565b6001600160a01b0381165f9081525f805160206119b1833981519152602052604090205460ff166102ba576001600160a01b03165f8181525f805160206119b183398151915260205260408120805460ff191660011790553391907ffd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f783905f805160206119518339815191529080a4600190565b6001600160a01b0381165f9081525f80516020611991833981519152602052604090205460ff166102ba576001600160a01b03165f8181525f8051602061199183398151915260205260408120805460ff191660011790553391907fd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63905f805160206119518339815191529080a460019056fe6080604052600436101561001a575b3615610018575f80fd5b005b5f3560e01c806301d5062a14610a5157806301ffc9a7146109e157806307bd0265146109ba578063134008d31461092d57806313bc9f201461090f578063150b7a02146108ba578063248a9ca31461089c5780632ab0f5291461087e5780632f2ff15d1461084d57806331d507501461082f57806336568abe146107eb578063584b153e146107c357806364d623531461075e5780637958004c1461071b5780638065657f146106fc5780638f2a0bb01461058a5780638f61f4f51461056357806391d148541461051b578063a217fddf14610501578063b08e51c0146104da578063b1c5f427146104b0578063bc197c811461041b578063c4d252f514610350578063d45c443514610326578063d547741f146102ee578063e38335e5146101c8578063f23a6e61146101735763f27a0c920361000e573461016f575f36600319011261016f576020600254604051908152f35b5f80fd5b3461016f5760a036600319011261016f5761018c610ae9565b50610195610aff565b506084356001600160401b03811161016f576101b5903690600401610be2565b5060405163f23a6e6160e01b8152602090f35b6101d136610c58565b5f80525f8051602061140c8339815191526020527f5ba6852781629bcdcd4bdaa6de76d786f1c64b16acdac474e55bebc0ea1579515492979196919593949260ff16156102e0575b8282148015906102d6575b6102bb5761023b61024291888a888789888d610f33565b9687611212565b5f5b81811061025457610018876112bd565b8080885f8051602061142c83398151915288886102b26102998f986001998f828e61028c8f836102879161029296610eba565b610ede565b97610eba565b3595610ef2565b906102a68282878761126a565b60405194859485610d85565b0390a301610244565b50869063ffb0321160e01b5f5260045260245260445260645ffd5b5087821415610224565b6102e93361116a565b610219565b3461016f57604036600319011261016f5761001860043561030d610aff565b9061032161031a82610dc4565b33906111ca565b611363565b3461016f57602036600319011261016f576004355f526001602052602060405f2054604051908152f35b3461016f57602036600319011261016f57335f9081527fc3ad33e20b0c56a223ad5104fff154aa010f8715b9c981fd38fdc60a4d1a52fb60205260409020546004359060ff16156103f7576103a481610e04565b156103dd57805f5260016020525f60408120557fbaa1eb22f2a492ba1a5fea61b8df4d27c6c8b5f3971e63bb58fa14ff72eedb705f80a2005b635ead8eb560e01b5f52600452600460021760245260445ffd5b63e2517d3f60e01b5f52336004525f805160206114ac83398151915260245260445ffd5b3461016f5760a036600319011261016f57610434610ae9565b5061043d610aff565b506044356001600160401b03811161016f5761045d903690600401610cc6565b506064356001600160401b03811161016f5761047d903690600401610cc6565b506084356001600160401b03811161016f5761049d903690600401610be2565b5060405163bc197c8160e01b8152602090f35b3461016f5760206104d26104c336610c58565b96959095949194939293610f33565b604051908152f35b3461016f575f36600319011261016f5760206040515f805160206114ac8339815191528152f35b3461016f575f36600319011261016f5760206040515f8152f35b3461016f57604036600319011261016f57610534610aff565b6004355f525f60205260405f209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b3461016f575f36600319011261016f5760206040515f8051602061144c8339815191528152f35b3461016f5760c036600319011261016f576004356001600160401b03811161016f576105ba903690600401610c28565b906024356001600160401b03811161016f576105da903690600401610c28565b9091906044356001600160401b03811161016f576105fc903690600401610c28565b9390916064356084359560a43592610613336110f7565b8089148015906106f2575b6106d85761063288848489858a8f8e610f33565b9861063d858b611084565b895f5b82811061067d5750898061065057005b60207f20fda5fd27a1ea7bf5b9567f143ac5470bb059374a27e8f67cb44f946f6d038791604051908152a2005b806001925f8051602061148c8339815191528b8b6106cd8f8c6106c08f928e6106b98f8f906106b36102878f8097948195610eba565b99610eba565b3597610ef2565b9060405196879687610d4d565b0390a3018a90610640565b908863ffb0321160e01b5f5260045260245260445260645ffd5b508189141561061e565b3461016f5760206104d261070f36610b42565b94939093929192610e65565b3461016f57602036600319011261016f57610737600435610e2d565b604051600482101561074a576020918152f35b634e487b7160e01b5f52602160045260245ffd5b3461016f57602036600319011261016f576004353033036107b0577f11c24f4ead16507c69ac467fbd5e4eed5fb5c699626d2cc6d66421df253886d560406002548151908152836020820152a1600255005b63e2850c5960e01b5f523360045260245ffd5b3461016f57602036600319011261016f5760206107e1600435610e04565b6040519015158152f35b3461016f57604036600319011261016f57610804610aff565b336001600160a01b038216036108205761001890600435611363565b63334bd91960e11b5f5260045ffd5b3461016f57602036600319011261016f5760206107e1600435610ded565b3461016f57604036600319011261016f5761001860043561086c610aff565b9061087961031a82610dc4565b6112db565b3461016f57602036600319011261016f5760206107e1600435610dd5565b3461016f57602036600319011261016f5760206104d2600435610dc4565b3461016f57608036600319011261016f576108d3610ae9565b506108dc610aff565b506064356001600160401b03811161016f576108fc903690600401610be2565b50604051630a85bd0160e11b8152602090f35b3461016f57602036600319011261016f5760206107e1600435610dac565b6100186109985f6109a45f8051602061142c83398151915261098f61095136610b42565b5f8051602061146c8339815191528a9995979299949394528960205260408a208a805260205260ff60408b205416156109ac575b8884848989610e65565b98899788611212565b6102a68282878761126a565b0390a36112bd565b6109b53361116a565b610985565b3461016f575f36600319011261016f5760206040515f8051602061146c8339815191528152f35b3461016f57602036600319011261016f5760043563ffffffff60e01b811680910361016f57602090630271189760e51b8114908115610a26575b506040519015158152f35b637965db0b60e01b811491508115610a40575b5082610a1b565b6301ffc9a760e01b14905082610a39565b3461016f5760c036600319011261016f57610a6a610ae9565b602435906044356001600160401b03811161016f575f8051602061148c83398151915292610a9d5f923690600401610b15565b94909160643594610adf6084359660a43590610ab8336110f7565b610ac689828c8a8989610e65565b998a97610ad3848a611084565b60405196879687610d4d565b0390a38061065057005b600435906001600160a01b038216820361016f57565b602435906001600160a01b038216820361016f57565b9181601f8401121561016f578235916001600160401b03831161016f576020838186019501011161016f57565b60a060031982011261016f576004356001600160a01b038116810361016f579160243591604435906001600160401b03821161016f57610b8491600401610b15565b90916064359060843590565b601f909101601f19168101906001600160401b03821190821017610bb357604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b038111610bb357601f01601f191660200190565b81601f8201121561016f57803590610bf982610bc7565b92610c076040519485610b90565b8284526020838301011161016f57815f926020809301838601378301015290565b9181601f8401121561016f578235916001600160401b03831161016f576020808501948460051b01011161016f57565b60a060031982011261016f576004356001600160401b03811161016f5781610c8291600401610c28565b909290916024356001600160401b03811161016f5781610ca491600401610c28565b90929091604435906001600160401b03821161016f57610b8491600401610c28565b9080601f8301121561016f578135916001600160401b038311610bb3578260051b9060405193610cf96020840186610b90565b845260208085019282010192831161016f57602001905b828210610d1d5750505090565b8135815260209182019101610d10565b908060209392818452848401375f828201840152601f01601f1916010190565b929093610d7b926080959897969860018060a01b03168552602085015260a0604085015260a0840191610d2d565b9460608201520152565b610da9949260609260018060a01b0316825260208201528160408201520191610d2d565b90565b610db590610e2d565b600481101561074a5760021490565b5f525f602052600160405f20015490565b610dde90610e2d565b600481101561074a5760031490565b610df690610e2d565b600481101561074a57151590565b610e0d90610e2d565b600481101561074a5760018114908115610e25575090565b600291501490565b5f52600160205260405f205480155f14610e4657505f90565b60018103610e545750600390565b421015610e6057600190565b600290565b94610e9b610eb494959293604051968795602087019960018060a01b03168a52604087015260a0606087015260c0860191610d2d565b91608084015260a083015203601f198101835282610b90565b51902090565b9190811015610eca5760051b0190565b634e487b7160e01b5f52603260045260245ffd5b356001600160a01b038116810361016f5790565b9190811015610eca5760051b81013590601e198136030182121561016f5701803591906001600160401b03831161016f57602001823603811361016f579190565b9693949190969592956040519660208801988060c08a0160a08c525260e0890192905f905b80821061104e57505050878203601f190160408901528082526001600160fb1b03811161016f579087959394929160051b8092602083013701848103606086015260208101849052600584901b8101604090810194908201915f90889036829003601e1901905b848410610fe957505050505050610eb49450608084015260a083015203601f198101835282610b90565b91939597909294969850601f19601f198383030101875289358381121561016f578401602081019190356001600160401b03811161016f57803603831361016f5761103a6020928392600195610d2d565b9b0197019401918a98969997959391610fbf565b91939091908435906001600160a01b038216820361016f576001600160a01b039091168152602090810194019160010190610f58565b9061108e82610ded565b6110df576002548082106110c957504201908142116110b5575f52600160205260405f2055565b634e487b7160e01b5f52601160045260245ffd5b90635433660960e01b5f5260045260245260445ffd5b50635ead8eb560e01b5f52600452600160245260445ffd5b6001600160a01b0381165f9081527f3412d5605ac6cd444957cedb533e5dacad6378b4bc819ebe3652188a665066d5602052604090205460ff16156111395750565b63e2517d3f60e01b5f9081526001600160a01b03919091166004525f8051602061144c833981519152602452604490fd5b6001600160a01b0381165f9081525f8051602061140c833981519152602052604090205460ff16156111995750565b63e2517d3f60e01b5f9081526001600160a01b03919091166004525f8051602061146c833981519152602452604490fd5b90815f525f60205260405f2060018060a01b0382165f5260205260ff60405f205416156111f5575050565b63e2517d3f60e01b5f5260018060a01b031660045260245260445ffd5b61121b81610dac565b15611253575080151580611243575b6112315750565b63121534c360e31b5f5260045260245ffd5b5061124d81610dd5565b1561122a565b635ead8eb560e01b5f52600452600460245260445ffd5b6112b2935f93928493826040519384928337810185815203925af13d156112b5573d9061129682610bc7565b916112a46040519384610b90565b82523d5f602084013e6113e3565b50565b6060906113e3565b6112c681610dac565b15611253575f526001602052600160405f2055565b5f818152602081815260408083206001600160a01b038616845290915290205460ff1661135d575f818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b50505f90565b5f818152602081815260408083206001600160a01b038616845290915290205460ff161561135d575f818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b90919061140957508051156113fa57805190602001fd5b630a12f52160e11b5f5260045ffd5b56fedae2aa361dfd1ca020a396615627d436107c35eff9fe7738a3512819782d7069c2617efa69bab66782fa219543714338489c4e9e178271560a91b82c3f612b58b09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1d8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e634cf4410cc57040e44862ef0f45f3dd5a5e02db8eb8add648d4b0e236f1d07dcafd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f783a164736f6c634300081a000a2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d3412d5605ac6cd444957cedb533e5dacad6378b4bc819ebe3652188a665066d5dae2aa361dfd1ca020a396615627d436107c35eff9fe7738a3512819782d7069c3ad33e20b0c56a223ad5104fff154aa010f8715b9c981fd38fdc60a4d1a52fbad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5a164736f6c634300081a000a000000000000000000000000660eaaedebc968f8f3694354fa8ec0b4c5ba8d12
Deployed Bytecode
0x6080806040526004361015610012575f80fd5b5f905f3560e01c908163601846df146104fc57508063a3f697ba146100865763f78a8a3e1461003f575f80fd5b346100835780600319360112610083576040517f000000000000000000000000660eaaedebc968f8f3694354fa8ec0b4c5ba8d126001600160a01b03168152602090f35b80fd5b5034610491576040366003190112610491576004356001600160a01b03811690819003610491576024356001600160401b03811161049157366023820112156104915760048101356001600160401b038111610491578101916024830192368411610491577f000000000000000000000000660eaaedebc968f8f3694354fa8ec0b4c5ba8d126001600160a01b031633036104ed57608090839003126104915760248201356001600160401b03811161049157820192806043850112156104915760248401356001600160401b0381116104955760405194610172601f8301601f19166020018761053d565b81865260208601926044828401011161049157815f9260446020930185378601015260448301359365ffffffffffff85168095036104915760648401359063ffffffff821680920361049157604051633bf206a360e21b8152916020836004815f7f00000000000000000000000044610355465c1f5914c8b8ea0e7c887cc67459b26001600160a01b03165af1928315610486575f936104a9575b50610248600b6020604051809782820196518091885e81016a20476f7665726e616e636560a81b83820152030160141981018752018561053d565b60405195614552808801949092906001600160401b038611898710176104955760e09789976084956105618a3960c088525180968160c08a01528a89015e5f898789010152602087015260018060a01b03169889604087015260608601526080850152013560a0830152601f8019910116010301905ff08015610486576001600160a01b031690803b1561049157604051632f2ff15d60e01b81527fb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc16004820152602481018390525f8160448183865af1801561048657610471575b50803b1561042d5782604051632f2ff15d60e01b81527ffd643c72710c63c0180259aba6b2d05451e3591a24e58b62239378085726f7836004820152836024820152818160448183875af180156104515761045c575b5050803b1561042d5782604051632f2ff15d60e01b81527fd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e636004820152816024820152818160448183875af180156104515761043c575b5050803b1561042d57604051631b2b455f60e11b815260048101849052306024820152838160448183865af1801561043157610418575b6040838382519182526020820152f35b61042384809261053d565b61042d5782610408565b8280fd5b6040513d86823e3d90fd5b816104469161053d565b61042d57825f6103d1565b6040513d84823e3d90fd5b816104669161053d565b61042d57825f61037a565b61047e9193505f9061053d565b5f915f610324565b6040513d5f823e3d90fd5b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b9092506020813d6020116104e5575b816104c56020938361053d565b8101031261049157516001600160a01b038116810361049157915f61020d565b3d91506104b8565b633617fe5360e11b5f5260045ffd5b34610491575f366003190112610491577f00000000000000000000000044610355465c1f5914c8b8ea0e7c887cc67459b26001600160a01b03168152602090f35b601f909101601f19168101906001600160401b038211908210176104955760405256fe6101a0604052346100c557610021610015610169565b9493909392919261024d565b6040516139c59081610b8d823960805181613042015260a051816130f9015260c0518161300c015260e05181613091015261010051816130b70152610120518161139f015261014051816113cb0152610160518181816115f101528181611a5101528181611b8c01528181611c2b01528181611df80152818161210d015281816121c20152818161294201526137f50152610180518181816103ef0152612b360152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761010057604052565b6100c9565b604051906101146040836100dd565b565b6001600160401b03811161010057601f01601f191660200190565b51906001600160a01b03821682036100c557565b519065ffffffffffff821682036100c557565b519063ffffffff821682036100c557565b61455290813803806040519361017f82866100dd565b843982019060c0838303126100c55782516001600160401b0381116100c557830182601f820112156100c5578051906101b782610116565b936101c560405195866100dd565b828552602083830101116100c557815f9260208093018387015e840101526101ef60208401610131565b926101fc60408201610131565b9261020960608301610145565b9260a061021860808501610158565b93015191959493929190565b634e487b7160e01b5f52601160045260245ffd5b906276a700820180921161024857565b610224565b610320929461031661033a97939561031161031b946040516102706040826100dd565b6001815260208101603160f81b8152610288836106b9565b610120526102958261079c565b6101405282516020840120918260e05251902080610100524660a0526040519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604083015260608201524660808201523060a082015260a0815261030260c0826100dd565b5190206080523060c0526103ee565b6105b2565b6105ff565b610680565b6001600160a01b031661016052610335610519565b6104c6565b61034f61034642610238565b63ffffffff1690565b61018052565b90600182811c92168015610383575b602083101461036f57565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610364565b601f821161039a57505050565b5f5260205f20906020601f840160051c830193106103d2575b601f0160051c01905b8181106103c7575050565b5f81556001016103bc565b90915081906103b3565b8160011b915f199060031b1c19161790565b80519091906001600160401b0381116101005761041781610410600354610355565b600361038d565b602092601f821160011461044a5761043a929382915f9261043f575b50506103dc565b600355565b015190505f80610433565b60035f52601f198216937fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b915f5b8681106104ae5750836001959610610496575b505050811b01600355565b01515f1960f88460031b161c191690555f808061048b565b91926020600181928685015181550194019201610478565b600b54604080516001600160a01b03808416825290931660208401819052927f08f74ea46ef7894f65eabfb5e6e695de773a000b47c529ab559178069b2264019190a16001600160a01b03191617600b55565b600a548061057957505f5b6001600160d01b0316610535610881565b7f0553476bf02ef2726e8ce5ced78d63e26e602e4a2257b1f559418e24b463399791600891610565908390610a58565b5050604080519182526020820192909252a1565b805f1981011161024857600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a7015460301c610524565b6008547fc565b045403dc03c2eea82b81a0465edad9e2e7fc4d97e11421c209da93d7a93604065ffffffffffff81519481851686521693846020820152a165ffffffffffff191617600855565b63ffffffff811690811561066d5769ffffffff000000000000907f7e3f7f0708a84de9203036abaa450dccc85ad5ff52f78c170f3edb55cf5e882860406008549481519063ffffffff8760301c1682526020820152a160301b169069ffffffff000000000000191617600855565b63f1cfbf0560e01b5f525f60045260245ffd5b60075460408051918252602082018390527fccb45da8d5717e6c4544694297c4ba5cf151d455c9bb0ed4fc7a38411bc0546191a1600755565b908151602081105f146106d45750906106d190610923565b90565b6001600160401b038111610100576106f6816106f05f54610355565b5f61038d565b602092601f821160011461071f57610718929382915f9261043f5750506103dc565b5f5560ff90565b5f8052601f198216937f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563915f5b868110610784575083600195961061076c575b505050811b015f5560ff90565b01515f1960f88460031b161c191690555f808061075f565b9192602060018192868501518155019401920161074c565b908151602081105f146107b45750906106d190610923565b6001600160401b038111610100576107d8816107d1600154610355565b600161038d565b602092601f8211600114610802576107fa929382915f9261043f5750506103dc565b60015560ff90565b60015f52601f198216937fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6915f5b8681106108695750836001959610610851575b505050811b0160015560ff90565b01515f1960f88460031b161c191690555f8080610843565b91926020600181928685015181550194019201610830565b610160516040516324776b7d60e21b815290602090829060049082906001600160a01b03165afa5f91816108e7575b506106d1575065ffffffffffff43116108cf5765ffffffffffff431690565b6306dfcc6560e41b5f5260306004524360245260445ffd5b9091506020813d60201161091b575b81610903602093836100dd565b810103126100c55761091490610145565b905f6108b0565b3d91506108f6565b601f81511161094e57602081519101516020821061093f571790565b5f198260200360031b1b161790565b604460209160405192839163305a27a960e01b83528160048401528051918291826024860152018484015e5f828201840152601f01601f19168101030190fd5b5f1981019190821161024857565b9065ffffffffffff82549181199060301b169116179055565b908154680100000000000000008110156101005760018101808455811015610a0e57610114925f5260205f20019065ffffffffffff81511665ffffffffffff19835416178255602060018060d01b03910151169061099c565b634e487b7160e01b5f52603260045260245ffd5b604080519192919081016001600160401b0381118282101761010057604052915465ffffffffffff8116835260301c6020830152565b600a54919291908115610b635781610aaa610aa5610a7c65ffffffffffff9561098e565b600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80190565b610a22565b90610abb825165ffffffffffff1690565b8484169485911611610b545785602093610b1595610aed610ae2865165ffffffffffff1690565b65ffffffffffff1690565b03610b195750610b02610a7c610b079361098e565b61099c565b01516001600160d01b031690565b9190565b9050610b4f9150610b39610b2b610105565b65ffffffffffff9092168252565b6001600160d01b038716818501525b600a6109b5565b610b07565b632520601d60e01b5f5260045ffd5b610b879150610b73610b2b610105565b6001600160d01b0384166020820152610b48565b5f919056fe60806040526004361015610022575b3615610018575f80fd5b6100206123f9565b005b5f3560e01c806301ffc9a71461033157806302a251a31461032c57806305c44b9a1461032757806306f3f9e61461032257806306fdde031461031d578063143489d014610318578063150b7a0214610313578063160cbed71461030e5780632656227d146103095780632d63f693146103045780632fe3e261146102ff5780633932abb1146102fa5780633e4f49e6146102f557806343859632146102f0578063452115d6146102eb5780634bf5d7e9146102e6578063544ffc9c146102e157806354fd4d50146102dc57806356781388146102d75780635b8d0e0d146102d25780635f398a14146102cd57806360c4247f146102c857806379051887146102c35780637b3c71d3146102be5780637d5e81e2146102b95780637ecebe00146102b457806384b0196e146102af5780638ff262e3146102aa57806391ddadf4146102a557806397c3d334146102a05780639a802a6d1461029b578063a7713a7014610296578063a890c91014610291578063a9a952941461028c578063ab58fb8e14610287578063b58131b014610282578063bc197c811461027d578063c01f9e3714610278578063c28bc2fa14610273578063c59057e41461026e578063d33219b414610269578063dd4e2ba514610264578063deaaa7cc1461025f578063e540d01d1461025a578063eb9019d414610255578063ece40cc114610250578063f23a6e611461024b578063f8ce560a146102465763fc0c546a0361000e57611c16565b611b5b565b611ae9565b611a94565b6119ef565b61194e565b611927565b6118c8565b6118a0565b611884565b611819565b6117fb565b61174e565b611731565b611713565b6116f7565b61167f565b611654565b61157f565b611564565b61153a565b611457565b611387565b611319565b61126b565b611216565b6111a4565b611176565b6110ff565b611057565b610fe9565b610f96565b610f55565b610f26565b610de7565b610da2565b610d73565b610d1d565b610cf6565b610cc1565b610b76565b61094d565b610704565b610608565b610511565b610413565b6103d3565b6103ad565b3461039f57602036600319011261039f5760043563ffffffff60e01b811680910361039f576020906332a2ad4360e11b811490811561038e575b811561037d575b506040519015158152f35b6301ffc9a760e01b1490505f610372565b630271189760e51b8114915061036b565b5f80fd5b5f91031261039f57565b3461039f575f36600319011261039f57602063ffffffff60085460301c16604051908152f35b3461039f575f36600319011261039f57602060405163ffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b3461039f57602036600319011261039f5760043561042f61240f565b606481116104c2576001600160d01b03610447612d46565b16906104516121ad565b916001600160d01b0382116104aa577f0553476bf02ef2726e8ce5ced78d63e26e602e4a2257b1f559418e24b463399792610496906001600160d01b038416906136ae565b5050604080519182526020820192909252a1005b506306dfcc6560e41b5f5260d060045260245260445ffd5b63243e544560e01b5f52600452606460245260445ffd5b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602061050e9281815201906104d9565b90565b3461039f575f36600319011261039f576040515f60035461053181611c5a565b80845290600181169081156105c75750600114610569575b610565836105598185038261065f565b604051918291826104fd565b0390f35b60035f9081527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b939250905b8082106105ad57509091508101602001610559610549565b919260018160209254838588010152019101909291610595565b60ff191660208086019190915291151560051b840190910191506105599050610549565b6001600160a01b031690565b6001600160a01b0316600452602490565b3461039f57602036600319011261039f576004355f526004602052602060018060a01b0360405f205416604051908152f35b6001600160a01b0381160361039f57565b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761068257604052565b61064b565b6040519061069660408361065f565b565b6001600160401b03811161068257601f01601f191660200190565b9291926106bf82610698565b916106cd604051938461065f565b82948184528183011161039f578281602093845f960137010152565b9080601f8301121561039f5781602061050e933591016106b3565b3461039f57608036600319011261039f5761072060043561063a565b61072b60243561063a565b6064356001600160401b03811161039f5761074a9036906004016106e9565b506107536123ea565b306001600160a01b039091160361077657604051630a85bd0160e11b8152602090f35b637485328f60e11b5f5260045ffd5b6001600160401b0381116106825760051b60200190565b9080601f8301121561039f5781356107b381610785565b926107c1604051948561065f565b81845260208085019260051b82010192831161039f57602001905b8282106107e95750505090565b6020809183356107f88161063a565b8152019101906107dc565b9080601f8301121561039f57813561081a81610785565b92610828604051948561065f565b81845260208085019260051b82010192831161039f57602001905b8282106108505750505090565b8135815260209182019101610843565b9080601f8301121561039f57813561087781610785565b92610885604051948561065f565b81845260208085019260051b8201019183831161039f5760208201905b8382106108b157505050505090565b81356001600160401b03811161039f576020916108d3878480948801016106e9565b8152019101906108a2565b608060031982011261039f576004356001600160401b03811161039f57816109089160040161079c565b916024356001600160401b03811161039f578261092791600401610803565b91604435906001600160401b03821161039f5761094691600401610860565b9060643590565b3461039f5761095b366108de565b909261096982858584612383565b93610973856124c1565b50610987610982600b546105eb565b6105eb565b936040519363793d064960e11b8552602085600481895afa948515610b21575f95610b55575b506109da6109cd6109bd306105eb565b60601b6001600160601b03191690565b6001600160601b03191690565b18946020604051809263b1c5f42760e01b825281806109ff8b89898c60048601612e19565b03915afa908115610b21575f91610b26575b50610a1b87611d13565b55610a2a610982600b546105eb565b90813b1561039f575f8094610a5687604051998a97889687956308f2a0bb60e41b875260048701612e5e565b03925af1908115610b2157610a7a92610a7592610b07575b5042612a55565b612a18565b9065ffffffffffff821615610af8577f9a2e42fd6722813d69113e7d0079d3d940171428df7373df9c7f7617cfda2892610ae583610ac6610565956001610ac087611d21565b01611d2f565b6040805185815265ffffffffffff909216602083015290918291820190565b0390a16040519081529081906020820190565b634844252360e11b5f5260045ffd5b80610b155f610b1b9361065f565b806103a3565b5f610a6e565b611d8a565b610b48915060203d602011610b4e575b610b40818361065f565b810190612d37565b5f610a11565b503d610b36565b610b6f91955060203d602011610b4e57610b40818361065f565b935f6109ad565b610b7f366108de565b91610b8c83838387612383565b936020610b9a603087612581565b50610bba610ba787611d21565b805460ff60f01b1916600160f01b179055565b610bc26123ea565b306001600160a01b0390911603610c59575b5091849391610be69361056596612eab565b30610bf26109826123ea565b141580610c3a575b610c31575b6040518181527f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f908060208101610ae5565b5f600555610bff565b506005546001600160801b03811660809190911c1415610bfa565b1590565b949091935f5b8351811015610cb35760019030610c89610982610c7c8489611d5c565b516001600160a01b031690565b14610c95575b01610c5f565b610cae610ca28288611d5c565b518981519101206125bf565b610c8f565b509094509290610565610bd4565b3461039f57602036600319011261039f576004355f526004602052602065ffffffffffff60405f205460a01c16604051908152f35b3461039f575f36600319011261039f5760206040515f805160206139998339815191528152f35b3461039f575f36600319011261039f57602065ffffffffffff60085416604051908152f35b634e487b7160e01b5f52602160045260245ffd5b60081115610d6057565b610d42565b6008811015610d6057602452565b3461039f57602036600319011261039f57610d8f60043561263a565b6040516008821015610d60576020918152f35b3461039f57604036600319011261039f57602060ff610ddb602435600435610dc98261063a565b5f5260098452600360405f2001611d75565b54166040519015158152f35b3461039f57610df5366108de565b91610e0283838387612383565b610e0b81612501565b505f908152600460205260409020546001600160a01b03163303610f1357610e3293612383565b610e3d603b82612581565b50610e5f610e4a82611d21565b80546001600160f81b0316600160f81b179055565b6040518181527f789cf55be980739dad1d0699b93b58e806b51c9d96619bfa8fe0a28abaa7b30c90602090a1610e9481611d13565b549081610ea7575b604051908152602090f35b610eb5610982600b546105eb565b803b1561039f5760405163c4d252f560e01b815260048101939093525f908390602490829084905af1918215610b215761056592610eff575b505f610ef982611d13565b55610e9c565b80610b155f610f0d9361065f565b5f610eee565b63233d98e360e01b5f523360045260245ffd5b3461039f575f36600319011261039f57610565610f41611de4565b6040519182916020835260208301906104d9565b3461039f57602036600319011261039f576004355f526009602052606060405f20805490600260018201549101549060405192835260208301526040820152f35b3461039f575f36600319011261039f57610565604051610fb760408261065f565b60018152603160f81b60208201526040519182916020835260208301906104d9565b6024359060ff8216820361039f57565b3461039f57604036600319011261039f57602061102260043561100a610fd9565b60405191611018858461065f565b5f83523390612737565b604051908152f35b9181601f8401121561039f578235916001600160401b03831161039f576020838186019501011161039f57565b3461039f5760c036600319011261039f57600435611073610fd9565b90604435906110818261063a565b6064356001600160401b03811161039f576110a090369060040161102a565b6084356001600160401b03811161039f576110bf9036906004016106e9565b60a435949092906001600160401b03861161039f57610565966110e96110ef9736906004016106e9565b95611eb3565b6040519081529081906020820190565b3461039f57608036600319011261039f5760043561111b610fd9565b906044356001600160401b03811161039f5761113b90369060040161102a565b90929091906064356001600160401b03811161039f57610e9c9461116661116e9236906004016106e9565b9436916106b3565b9133906128d9565b3461039f57602036600319011261039f576020611022600435611fa0565b65ffffffffffff81160361039f57565b3461039f57602036600319011261039f576004356111c181611194565b6111c961240f565b6008547fc565b045403dc03c2eea82b81a0465edad9e2e7fc4d97e11421c209da93d7a93604065ffffffffffff81519481851686521693846020820152a165ffffffffffff191617600855005b3461039f57606036600319011261039f57600435611232610fd9565b90604435906001600160401b03821161039f5760209261126361125c61102294369060040161102a565b36916106b3565b913390612737565b3461039f57608036600319011261039f576004356001600160401b03811161039f5761129b90369060040161079c565b6024356001600160401b03811161039f576112ba903690600401610803565b906044356001600160401b03811161039f576112da903690600401610860565b60643591906001600160401b03831161039f573660238401121561039f57610565936113136110ef9436906024816004013591016106b3565b9261209d565b3461039f57602036600319011261039f576004356113368161063a565b60018060a01b03165f526002602052602060405f2054604051908152f35b90602080835192838152019201905f5b8181106113715750505090565b8251845260209384019390920191600101611364565b3461039f575f36600319011261039f576114296113c37f000000000000000000000000000000000000000000000000000000000000000061357a565b6105656113ef7f00000000000000000000000000000000000000000000000000000000000000006135d9565b6114376040519161140160208461065f565b5f808452366020850137604051958695600f60f81b875260e0602088015260e08701906104d9565b9085820360408701526104d9565b904660608501523060808501525f60a085015283820360c0850152611354565b3461039f57608036600319011261039f57600435611473610fd9565b90604435916114818361063a565b6064356001600160401b03811161039f57610c556114a66115099236906004016106e9565b6115036114b287612754565b60405160208101915f80516020613979833981519152835288604083015260ff8816606083015260018060a01b038a16608083015260a082015260a081526114fb60c08261065f565b519020612776565b8661279c565b61152457906110ef916105659361151e611d95565b92612737565b6394ab6c0760e01b5f52611537836105f7565b5ffd5b3461039f575f36600319011261039f5760206115546121ad565b65ffffffffffff60405191168152f35b3461039f575f36600319011261039f57602060405160648152f35b3461039f57606036600319011261039f5760043561159c8161063a565b6024356044356001600160401b03811161039f576115be9036906004016106e9565b50604051630748d63560e31b81526001600160a01b039283166004820152602481019190915290602090829060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa8015610b2157610565915f91611635575b506040519081529081906020820190565b61164e915060203d602011610b4e57610b40818361065f565b5f611624565b3461039f575f36600319011261039f5760206001600160d01b03611676612d46565b16604051908152f35b3461039f57602036600319011261039f5760043561169c8161063a565b6116a461240f565b600b54604080516001600160a01b03808416825290931660208401819052927f08f74ea46ef7894f65eabfb5e6e695de773a000b47c529ab559178069b2264019190a16001600160a01b03191617600b55005b3461039f57602036600319011261039f57602060405160018152f35b3461039f57602036600319011261039f576020611022600435612240565b3461039f575f36600319011261039f576020600754604051908152f35b3461039f5760a036600319011261039f5761176a60043561063a565b61177560243561063a565b6044356001600160401b03811161039f57611794903690600401610803565b506064356001600160401b03811161039f576117b4903690600401610803565b506084356001600160401b03811161039f576117d49036906004016106e9565b506105656117e061225a565b6040516001600160e01b031990911681529081906020820190565b3461039f57602036600319011261039f576020611022600435612279565b606036600319011261039f576004356118318161063a565b6024356044356001600160401b03811161039f57610020925f9261185a8493369060040161102a565b919061186461240f565b826040519384928337810185815203925af161187e6122c0565b90612d77565b3461039f576020611022611897366108de565b92919091612383565b3461039f575f36600319011261039f57600b546040516001600160a01b039091168152602090f35b3461039f575f36600319011261039f576105656040516118e960408261065f565b602081527f737570706f72743d627261766f2671756f72756d3d666f722c6162737461696e60208201526040519182916020835260208301906104d9565b3461039f575f36600319011261039f5760206040515f805160206139798339815191528152f35b3461039f57602036600319011261039f5760043563ffffffff81169081810361039f5761197961240f565b81156119dc577f7e3f7f0708a84de9203036abaa450dccc85ad5ff52f78c170f3edb55cf5e882860406008549381519063ffffffff8660301c1682526020820152a163ffffffff60301b1990911660309190911b63ffffffff60301b1617600855005b63f1cfbf0560e01b5f525f60045260245ffd5b3461039f57604036600319011261039f57600435611a0c8161063a565b6024355f604051611a1e60208261065f565b52604051630748d63560e31b81526001600160a01b039283166004820152602481019190915290602090829060449082907f0000000000000000000000000000000000000000000000000000000000000000165afa8015610b2157610565915f9161163557506040519081529081906020820190565b3461039f57602036600319011261039f57600435611ab061240f565b60075460408051918252602082018390527fccb45da8d5717e6c4544694297c4ba5cf151d455c9bb0ed4fc7a38411bc0546191a1600755005b3461039f5760a036600319011261039f57611b0560043561063a565b611b1060243561063a565b6084356001600160401b03811161039f57611b2f9036906004016106e9565b50611b386123ea565b306001600160a01b03909116036107765760405163f23a6e6160e01b8152602090f35b3461039f57602036600319011261039f57600435604051632394e7a360e21b815260048101829052906020826024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215610b21575f92611bf1575b50611bce90611fa0565b90818102918183041490151715611bec5761056590606490046110ef565b611f6f565b611bce919250611c0f9060203d602011610b4e57610b40818361065f565b9190611bc4565b3461039f575f36600319011261039f576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b90600182811c92168015611c88575b6020831014611c7457565b634e487b7160e01b5f52602260045260245ffd5b91607f1691611c69565b5f9291815491611ca183611c5a565b8083529260018116908115611cf65750600114611cbd57505050565b5f9081526020812093945091925b838310611cdc575060209250010190565b600181602092949394548385870101520191019190611ccb565b915050602093945060ff929192191683830152151560051b010190565b5f52600c60205260405f2090565b5f52600460205260405f2090565b9065ffffffffffff1665ffffffffffff19825416179055565b634e487b7160e01b5f52603260045260245ffd5b8051821015611d705760209160051b010190565b611d48565b9060018060a01b03165f5260205260405f2090565b6040513d5f823e3d90fd5b60405190611da460208361065f565b5f8252565b60405190611db860408361065f565b601d82527f6d6f64653d626c6f636b6e756d6265722666726f6d3d64656661756c740000006020830152565b604051634bf5d7e960e01b81525f816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa5f9181611e38575b5061050e575061050e611da9565b9091503d805f833e611e4a818361065f565b81019060208183031261039f578051906001600160401b03821161039f570181601f8201121561039f57805190611e8082610698565b92611e8e604051948561065f565b8284526020838301011161039f57815f9260208093018386015e83010152905f611e2a565b939092919695610c55611f4191611f3b8a611ecd81612754565b611ed836888a6106b3565b602081519101208b5160208d0120906040519260208401945f8051602061399983398151915286528d604086015260ff8d16606086015260018060a01b0316608085015260a084015260c083015260e082015260e081526114fb6101008261065f565b8a61279c565b611f5c5761050e959691611f569136916106b3565b926128d9565b6394ab6c0760e01b5f52611537876105f7565b634e487b7160e01b5f52601160045260245ffd5b5f19810191908211611bec57565b602719810191908211611bec57565b600a54905f198201828111611bec57821115611d7057600a5f525f8051602061393983398151915282015465ffffffffffff81168210156120945750611fe590612a18565b5f829160058411612040575b611ffb9350613382565b8061200557505f90565b61203461202d61201761050e93611f83565b600a5f525f805160206139598339815191520190565b5460301c90565b6001600160d01b031690565b919261204b8161320f565b8103908111611bec57611ffb93600a5f5265ffffffffffff8260205f2001541665ffffffffffff8516105f14612082575091611ff1565b92915061208e90612a47565b90611ff1565b91505060301c90565b91939290936120ac8233612a73565b1561219a575f1965ffffffffffff6120c26121ad565b16019465ffffffffffff8611611bec575f6040516120e160208261065f565b52604051630748d63560e31b815233600482015265ffffffffffff9690961660248701526020866044817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa958615610b21575f96612179575b5060075480871061215e575061050e9495503393612b2a565b636121770b60e11b5f5233600452602487905260445260645ffd5b61219391965060203d602011610b4e57610b40818361065f565b945f612145565b63d9b3955760e01b5f523360045260245ffd5b6040516324776b7d60e21b81526020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa5f9181612203575b5061050e575061050e43612a18565b9091506020813d602011612238575b8161221f6020938361065f565b8101031261039f575161223181611194565b905f6121f4565b3d9150612212565b5f52600460205265ffffffffffff600160405f2001541690565b600b54306001600160a01b03909116036107765763bc197c8160e01b90565b805f52600460205265ffffffffffff60405f205460a01c16905f52600460205263ffffffff60405f205460d01c160165ffffffffffff8111611bec5765ffffffffffff1690565b3d156122ea573d906122d182610698565b916122df604051938461065f565b82523d5f602084013e565b606090565b90602080835192838152019201905f5b81811061230c5750505090565b82516001600160a01b03168452602093840193909201916001016122ff565b9080602083519182815201916020808360051b8301019401925f915b83831061235657505050505090565b9091929394602080612374600193601f1986820301875289516104d9565b97019301930191939290612347565b92906123e4916123d06123be946040519586946123ac602087019960808b5260a08801906122ef565b868103601f1901604088015290611354565b848103601f190160608601529061232b565b90608083015203601f19810183528261065f565b51902090565b600b546001600160a01b031690565b600b54306001600160a01b039091160361077657565b6124176123ea565b336001600160a01b0390911603612482576124306123ea565b306001600160a01b039091160361244357565b61244c36610698565b612459604051918261065f565b3681526020810190365f83375f602036830101525190205b8061247a612dbb565b036124715750565b6347096e4760e01b5f523360045260245ffd5b6008811015610d605760ff600191161b90565b600452606491906008811015610d60576024525f604452565b6124ca8161263a565b9060106124d683612495565b16156124e0575090565b6331b75e4d60e01b5f526004526124f79150610d65565b601060445260645ffd5b61250a8161263a565b90600161251683612495565b1615612520575090565b6331b75e4d60e01b5f526004526125379150610d65565b600160445260645ffd5b61254a8161263a565b90600261255683612495565b1615612560575090565b6331b75e4d60e01b5f526004526125779150610d65565b600260445260645ffd5b9061258b8261263a565b918161259684612495565b16156125a157505090565b6331b75e4d60e01b5f526004526125b782610d65565b60445260645ffd5b6005546001608082901c90810192916001600160801b03808516911614612613575f90815260066020526040902055600580546001600160801b031660809290921b6001600160801b031916919091179055565b638acb5f2760e01b5f5260045ffd5b9081602091031261039f5751801515810361039f5790565b61264381612f30565b9061264d82610d56565b600582036127335761265f9150611d13565b5461266e610982600b546105eb565b604051632c258a9f60e11b815260048101839052602081602481855afa908115610b21575f91612714575b50156126a6575050600590565b604051632ab0f52960e01b81526004810192909252602090829060249082905afa908115610b21575f916126e5575b50156126e057600790565b600290565b612707915060203d60201161270d575b6126ff818361065f565b810190612622565b5f6126d5565b503d6126f5565b61272d915060203d60201161270d576126ff818361065f565b5f612699565b5090565b9161050e93916040519361274c60208661065f565b5f85526128d9565b6001600160a01b03165f90815260026020526040902080546001810190915590565b604290612781613009565b906040519161190160f01b8352600283015260228201522090565b906127a7838261311f565b506004819592951015610d6057159384612863575b5083156127ca575b50505090565b5f9350906128026128108594936040519283916020830195630b135d3f60e11b875260248401526040604484015260648301906104d9565b03601f19810183528261065f565b51915afa61281c6122c0565b81612855575b81612831575b505f80806127c4565b905061284e630b135d3f60e11b9160208082518301019101612d37565b145f612828565b905060208151101590612822565b6001600160a01b0384811691161493505f6127bc565b93909260ff6128a59361050e97958752166020860152604085015260a0606085015260a08401906104d9565b9160808184039101526104d9565b909260ff60809361050e96958452166020830152604082015281606082015201906104d9565b93929190936128e781612541565b50805f52600460205265ffffffffffff61290e60405f2065ffffffffffff905460a01c1690565b169360405195630748d63560e31b875260018060a01b03811695866004890152602488015260208760448160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa968715610b21575f976129f1575b50868461297f9285613159565b80516129be57506129b87fb8e138887d0aa13bab447e82de9d5c1777041ecd21ca36ba824ff1e6c07ddda49386604051948594856128b3565b0390a290565b6129b8907fe2babfbac5889a709b63bb7f598b324e08bc5a4fb9ec647fb3cbc9ec07eb8712948760405195869586612879565b84975090612a1061297f9260203d602011610b4e57610b40818361065f565b975090612972565b65ffffffffffff8111612a305765ffffffffffff1690565b6306dfcc6560e41b5f52603060045260245260445ffd5b9060018201809211611bec57565b91908201809211611bec57565b908151811015611d70570160200190565b815160348110612b225760131981840101516001600160a01b0319166b1b91f1b211f2119351b859f160a31b01612b2257915f92612ab081611f91565b915b818310612acd575050506001600160a01b0391821691161490565b909193612af3612aee612ae08785612a62565b516001600160f81b03191690565b6133e8565b9015612b175760019160ff9060041b6010600160a01b031691161794019190612ab2565b505050505050600190565b505050600190565b929093919363ffffffff7f0000000000000000000000000000000000000000000000000000000000000000164210612d2857612b6e82516020840120868387612383565b948451825190818114801590612d1d575b8015612d15575b612cf657505065ffffffffffff612bae612b9f88611d21565b5460a01c65ffffffffffff1690565b16612cd95791612cd3917f7d84a6263ae0d98d3329bd7b46bb4e8d6f98cd35a7adb45c274c8b7fd5ebd5e0959493612c14612be76121ad565b65ffffffffffff612c0d612c0265ffffffffffff6008541690565b65ffffffffffff1690565b9116612a55565b90612c33612c2a63ffffffff60085460301c1690565b63ffffffff1690565b612cb1612c3f8b611d21565b80546001600160a01b0319166001600160a01b038a16178155612c88612c6486612a18565b825465ffffffffffff60a01b191660a09190911b65ffffffffffff60a01b16178255565b612c918361390d565b815463ffffffff60d01b191660d09190911b63ffffffff60d01b16179055565b612cc5612cbe8951613465565b9184612a55565b936040519889988c8a6134ae565b0390a190565b61153786612ce68161263a565b6331b75e4d60e01b5f52906124a8565b9151630447b05d60e41b5f908152600493909352602452604452606490fd5b508015612b86565b508251811415612b7f565b635fd36d9960e11b5f5260045ffd5b9081602091031261039f575190565b600a5480612d5357505f90565b805f19810111611bec57600a5f525f80516020613939833981519152015460301c90565b9091906106965750805115612d8e57805190602001fd5b630a12f52160e11b5f5260045ffd5b8115612da7570490565b634e487b7160e01b5f52601260045260245ffd5b6005546001600160801b038116919060801c8214612e0a575f8281526006602052604081208054919055600580546001600160801b03191660019094016001600160801b031693909317909255565b6375e52f4f60e01b5f5260045ffd5b949392612e45608093612e37612e539460a08a5260a08a01906122ef565b9088820360208a0152611354565b90868203604088015261232b565b935f60608201520152565b9192612e8d60a094612e7f612e9b949998979960c0875260c08701906122ef565b908582036020870152611354565b90838203604085015261232b565b945f606083015260808201520152565b600b5490949192916001600160a01b03909116906001600160601b03193060601b16823b1561039f57612ef85f956040519788968795869563e38335e560e01b8752189260048601612e19565b039134905af18015610b2157612f17575b50612f145f91611d13565b55565b80612f235f809361065f565b80031261039f575f612f09565b612f3981611d21565b5460f881901c9060f01c60ff1661300257612ffc57612f5d612c02612b9f83611d21565b8015612fe857612f6e612c026121ad565b80911015612fe257612f7f82612279565b10612f8a5750600190565b612f96610c55826137ae565b8015612fbf575b15612fa85750600390565b612fb190612240565b612fba57600490565b600590565b50612fdd610c55825f52600960205260405f20600181015490541090565b612f9d565b50505f90565b636ad0607560e01b5f52600482905260245ffd5b50600290565b5050600790565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031614806130f6575b15613064577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a081526123e460c08261065f565b507f0000000000000000000000000000000000000000000000000000000000000000461461303b565b815191906041830361314f576131489250602082015190606060408401519301515f1a90613883565b9192909190565b50505f9160029190565b61316e909291925f52600960205260405f2090565b91600383016131876131808383611d75565b5460ff1690565b6131fc5761319b60ff93926131a892611d75565b805460ff19166001179055565b16806131bf5750906131bb908254612a55565b9055565b600181036131d7575060016131bb9101918254612a55565b6002036131ed5760026131bb9101918254612a55565b6303599be160e11b5f5260045ffd5b6371c6af4960e01b5f52611537826105f7565b801561337d5761050e9061331361330c6133026132f86132ee6132e46132da6132d060016132be5f8b608081901c8061336f575b50806132526132b49260401c90565b80613362575b506132638160201c90565b80613355575b506132748160101c90565b80613348575b506132858160081c90565b8061333b575b506132968160041c90565b8061332e575b506132a78160021c90565b80613321575b5060011c90565b6133195760011c90565b1b6132c9818b612d9d565b0160011c90565b6132c9818a612d9d565b6132c98189612d9d565b6132c98188612d9d565b6132c98187612d9d565b6132c98186612d9d565b6132c98185612d9d565b8092612d9d565b906138fb565b820160011c90565b600291509201915f6132ad565b600491509201915f61329c565b600891509201915f61328b565b601091509201915f61327a565b602091509201915f613269565b604091509201915f613258565b6080925090506132b4613243565b505f90565b905b82811061339057505090565b90918082169080831860011c8201809211611bec57600a5f525f8051602061395983398151915282015465ffffffffffff90811690851610156133d65750915b90613384565b9291506133e290612a47565b906133d0565b60f81c9081602f108061345b575b1561340857600191602f190160ff1690565b8160401080613451575b15613424576001916036190160ff1690565b8160601080613447575b15613440576001916056190160ff1690565b5f91508190565b506067821061342e565b5060478210613412565b50603a82106133f6565b9061346f82610785565b61347c604051918261065f565b828152809261348d601f1991610785565b01905f5b82811061349d57505050565b806060602080938501015201613491565b9599989697949391926134ef936134e192885260018060a01b0316602088015261012060408801526101208701906122ef565b908582036060870152611354565b968388036080850152815180895260208901906020808260051b8c01019401915f905b82821061354e575050505061050e969750906135359184820360a086015261232b565b9360c083015260e08201526101008184039101526104d9565b9091929460208061356c6001938f601f1990820301865289516104d9565b970192019201909291613512565b60ff81146135c05760ff811690601f82116135b1576040519161359e60408461065f565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b5060405161050e816135d2815f611c92565b038261065f565b60ff81146135fd5760ff811690601f82116135b1576040519161359e60408461065f565b5060405161050e816135d2816001611c92565b9065ffffffffffff82549181199060301b169116179055565b908154600160401b8110156106825760018101808455811015611d7057610696925f5260205f20019061366565ffffffffffff82511683611d2f565b602001516001600160d01b031690613610565b604080519192919081016001600160401b0381118282101761068257604052915465ffffffffffff8116835260301c6020830152565b600a5491929190811561378557816136d76136d261201765ffffffffffff95611f83565b613678565b906136e8825165ffffffffffff1690565b848416948591161161377657856020936137379561370f612c02865165ffffffffffff1690565b0361373b575061372461201761372993611f83565b613610565b01516001600160d01b031690565b9190565b9050613771915061375b61374d610687565b65ffffffffffff9092168252565b6001600160d01b038716818501525b600a613629565b613729565b632520601d60e01b5f5260045ffd5b6137a9915061379561374d610687565b6001600160d01b038416602082015261376a565b5f9190565b805f52600960205260405f20905f52600460205265ffffffffffff60405f205460a01c1660405190632394e7a360e21b825280600483015260208260248160018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa918215610b21575f9261385e575b5061382f90611fa0565b90818102918183041490151715611bec576138599060649004916002600182015491015490612a55565b101590565b61382f91925061387c9060203d602011610b4e57610b40818361065f565b9190613825565b91906fa2a8918ca85bafe22016d0b997e4df60600160ff1b0384116138f0579160209360809260ff5f9560405194855216868401526040830152606082015282805260015afa15610b21575f516001600160a01b038116156138e657905f905f90565b505f906001905f90565b5050505f9160039190565b9080821015613908575090565b905090565b63ffffffff81116139215763ffffffff1690565b6306dfcc6560e41b5f52602060045260245260445ffdfec65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a7c65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8f2aad550cf55f045cb27e9c559f9889fdfb6e6cdaa032301d6ea397784ae51d73e83946653575f9a39005e1545185629e92736b7528ab20ca3816f315424a811a164736f6c634300081a000aa164736f6c634300081a000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000660eaaedebc968f8f3694354fa8ec0b4c5ba8d12
-----Decoded View---------------
Arg [0] : airlock_ (address): 0x660eAaEdEBc968f8f3694354FA8EC0b4c5Ba8D12
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000660eaaedebc968f8f3694354fa8ec0b4c5ba8d12
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.