Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/AgoraGovernor.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {TimersUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/utils/TimersUpgradeable.sol";
import {SafeCastUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/utils/math/SafeCastUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable-v4/proxy/utils/Initializable.sol";
import {TimelockControllerUpgradeable} from
"@openzeppelin/contracts-upgradeable-v4/governance/TimelockControllerUpgradeable.sol";
import {AddressUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/utils/AddressUpgradeable.sol";
import {GovernorCountingSimpleUpgradeableV2} from "src/lib/openzeppelin/v2/GovernorCountingSimpleUpgradeableV2.sol";
import {IGovernorUpgradeable} from "src/lib/openzeppelin/v2/GovernorUpgradeableV2.sol";
import {GovernorUpgradeableV2} from "src/lib/openzeppelin/v2/GovernorUpgradeableV2.sol";
import {GovernorVotesUpgradeableV2} from "src/lib/openzeppelin/v2/GovernorVotesUpgradeableV2.sol";
import {GovernorSettingsUpgradeableV2} from "src/lib/openzeppelin/v2/GovernorSettingsUpgradeableV2.sol";
import {GovernorTimelockControlUpgradeableV2} from "src/lib/openzeppelin/v2/GovernorTimelockControlUpgradeableV2.sol";
import {IProposalTypesConfigurator} from "src/interfaces/IProposalTypesConfigurator.sol";
import {VotingModule} from "src/modules/VotingModule.sol";
import {IVotingToken} from "src/interfaces/IVotingToken.sol";
/// @custom:security-contact security@voteagora.com
contract AgoraGovernor is
Initializable,
GovernorUpgradeableV2,
GovernorCountingSimpleUpgradeableV2,
GovernorVotesUpgradeableV2,
GovernorSettingsUpgradeableV2,
GovernorTimelockControlUpgradeableV2
{
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event ProposalCreated(
uint256 indexed proposalId,
address indexed proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 startBlock,
uint256 endBlock,
string description,
uint8 proposalTypeId
);
event ProposalCreated(
uint256 indexed proposalId,
address indexed proposer,
address indexed votingModule,
bytes proposalData,
uint256 startBlock,
uint256 endBlock,
string description,
uint8 proposalTypeId
);
event ProposalTypeUpdated(uint256 indexed proposalId, uint8 proposalTypeId);
event ProposalDeadlineUpdated(uint256 proposalId, uint64 deadline);
event AdminSet(address indexed oldAdmin, address indexed newAdmin);
event ManagerSet(address indexed oldManager, address indexed newManager);
enum SupplyType {
Total,
Votable
}
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
error InvalidProposalType(uint8 proposalTypeId);
error InvalidProposalId();
error InvalidProposalLength();
error InvalidEmptyProposal();
error InvalidVotesBelowThreshold();
error InvalidProposalExists();
error InvalidRelayTarget(address target);
error NotAdminOrTimelock();
/*//////////////////////////////////////////////////////////////
LIBRARIES
//////////////////////////////////////////////////////////////*/
using SafeCastUpgradeable for uint256;
using TimersUpgradeable for TimersUpgradeable.BlockNumber;
/*//////////////////////////////////////////////////////////////
IMMUTABLE STORAGE
//////////////////////////////////////////////////////////////*/
uint256 private constant GOVERNOR_VERSION = 1;
/// @notice Max value of `quorum` and `approvalThreshold` in `ProposalType`
uint16 public constant PERCENT_DIVISOR = 10_000;
IProposalTypesConfigurator public PROPOSAL_TYPES_CONFIGURATOR;
SupplyType public SUPPLY_TYPE;
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
address public admin;
address public manager;
mapping(address module => bool approved) public approvedModules;
modifier onlyAdminOrTimelock() {
address sender = _msgSender();
if (sender != admin && sender != timelock()) revert NotAdminOrTimelock();
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor() {
_disableInitializers();
}
/**
* @notice Initialize the governor with the given parameters.
* @param _votingToken The governance token used for voting.
* @param _supplyType The type of supply to use for voting calculations.
* @param _admin Admin address for the governor.
* @param _manager Manager address.
* @param _timelock The governance timelock.
* @param _proposalTypesConfigurator Proposal types configurator contract.
*/
function initialize(
IVotingToken _votingToken,
SupplyType _supplyType,
address _admin,
address _manager,
TimelockControllerUpgradeable _timelock,
IProposalTypesConfigurator _proposalTypesConfigurator
) public initializer {
PROPOSAL_TYPES_CONFIGURATOR = _proposalTypesConfigurator;
SUPPLY_TYPE = _supplyType;
__Governor_init("Agora");
__GovernorCountingSimple_init();
__GovernorVotes_init(_votingToken);
__GovernorSettings_init({initialVotingDelay: 6575, initialVotingPeriod: 46027, initialProposalThreshold: 0});
__GovernorTimelockControl_init(_timelock);
admin = _admin;
manager = _manager;
}
/*//////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Returns the quorum for a `proposalId`, in terms of number of votes: `supply * numerator / denominator`.
* @dev Supply is calculated at the proposal snapshot timepoint.
* @dev Quorum value is derived from `PROPOSAL_TYPES_CONFIGURATOR`.
*/
function quorum(uint256 proposalId) public view virtual override returns (uint256) {
uint256 snapshotBlock = proposalSnapshot(proposalId);
uint256 supply;
if (SUPPLY_TYPE == SupplyType.Total) {
supply = token.getPastTotalSupply(snapshotBlock);
} else {
supply = token.getPastVotableSupply(snapshotBlock);
}
uint8 proposalTypeId = _proposals[proposalId].proposalType;
return (supply * PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).quorum) / PERCENT_DIVISOR;
}
/**
* @dev Updated version in which quorum is based on `proposalId` instead of snapshot block.
*/
function _quorumReached(uint256 proposalId)
internal
view
virtual
override(GovernorCountingSimpleUpgradeableV2, GovernorUpgradeableV2)
returns (bool)
{
(uint256 againstVotes, uint256 forVotes, uint256 abstainVotes) = proposalVotes(proposalId);
return quorum(proposalId) <= againstVotes + forVotes + abstainVotes;
}
/**
* @dev Added logic based on approval voting threshold to determine if vote has succeeded.
*/
function _voteSucceeded(uint256 proposalId)
internal
view
virtual
override(GovernorCountingSimpleUpgradeableV2, GovernorUpgradeableV2)
returns (bool voteSucceeded)
{
ProposalCore storage proposal = _proposals[proposalId];
address votingModule = proposal.votingModule;
if (votingModule != address(0)) {
if (!VotingModule(votingModule)._voteSucceeded(proposalId)) {
return false;
}
}
uint256 approvalThreshold = PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposal.proposalType).approvalThreshold;
if (approvalThreshold == 0) return true;
ProposalVote storage proposalVote = _proposalVotes[proposalId];
uint256 forVotes = proposalVote.forVotes;
uint256 totalVotes = forVotes + proposalVote.againstVotes;
if (totalVotes != 0) {
voteSucceeded = (forVotes * PERCENT_DIVISOR) / totalVotes >= approvalThreshold;
}
}
/**
* @notice Returns the proposal type of a proposal.
* @param proposalId The id of the proposal.
*/
function getProposalType(uint256 proposalId) external view returns (uint8) {
return _proposals[proposalId].proposalType;
}
/**
* @dev See {IGovernor-COUNTING_MODE}.
* Params encoding:
* - modules = custom external params depending on module used
*/
function COUNTING_MODE()
public
pure
virtual
override(GovernorCountingSimpleUpgradeableV2, IGovernorUpgradeable)
returns (string memory)
{
return "support=bravo&quorum=against,for,abstain¶ms=modules";
}
/**
* @dev Returns the current version of the governor.
*/
function VERSION() public pure virtual returns (uint256) {
return GOVERNOR_VERSION;
}
/**
* @notice Calculate `proposalId` hashing similarly to `hashProposal` but based on `module` and `proposalData`.
* See {IGovernor-hashProposal}.
* @param module The address of the voting module to use for this proposal.
* @param proposalData The proposal data to pass to the voting module.
* @param descriptionHash The hash of the proposal description.
* @return The id of the proposal.
*/
function hashProposalWithModule(address module, bytes memory proposalData, bytes32 descriptionHash)
public
view
virtual
returns (uint256)
{
return uint256(keccak256(abi.encode(address(this), module, proposalData, descriptionHash)));
}
/**
* @inheritdoc GovernorSettingsUpgradeableV2
*/
function proposalThreshold()
public
view
override(GovernorSettingsUpgradeableV2, GovernorUpgradeableV2)
returns (uint256)
{
return GovernorSettingsUpgradeableV2.proposalThreshold();
}
function _executor()
internal
view
override(GovernorUpgradeableV2, GovernorTimelockControlUpgradeableV2)
returns (address)
{
return GovernorTimelockControlUpgradeableV2._executor();
}
/**
* @inheritdoc GovernorTimelockControlUpgradeableV2
*/
function state(uint256 proposalId)
public
view
virtual
override(GovernorUpgradeableV2, GovernorTimelockControlUpgradeableV2)
returns (ProposalState)
{
return GovernorTimelockControlUpgradeableV2.state(proposalId);
}
/**
* @inheritdoc GovernorTimelockControlUpgradeableV2
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(GovernorUpgradeableV2, GovernorTimelockControlUpgradeableV2)
returns (bool)
{
return GovernorTimelockControlUpgradeableV2.supportsInterface(interfaceId);
}
/*//////////////////////////////////////////////////////////////
WRITE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @notice Approve or reject a voting module. Only the admin or timelock can call this function.
* @param module The address of the voting module to approve or reject.
* @param approved Whether to approve or reject the voting module.
*/
function setModuleApproval(address module, bool approved) external onlyAdminOrTimelock {
approvedModules[module] = approved;
}
/**
* @notice Set the deadline for a proposal. Only the admin or timelock can call this function.
* @param proposalId The id of the proposal.
* @param deadline The new deadline for the proposal.
*/
function setProposalDeadline(uint256 proposalId, uint64 deadline) external onlyAdminOrTimelock {
_proposals[proposalId].voteEnd.setDeadline(deadline);
emit ProposalDeadlineUpdated(proposalId, deadline);
}
/**
* @inheritdoc GovernorSettingsUpgradeableV2
*/
function setVotingDelay(uint256 newVotingDelay) public override onlyAdminOrTimelock {
_setVotingDelay(newVotingDelay);
}
/**
* @inheritdoc GovernorSettingsUpgradeableV2
*/
function setVotingPeriod(uint256 newVotingPeriod) public override onlyAdminOrTimelock {
_setVotingPeriod(newVotingPeriod);
}
/**
* @inheritdoc GovernorSettingsUpgradeableV2
*/
function setProposalThreshold(uint256 newProposalThreshold) public override onlyAdminOrTimelock {
_setProposalThreshold(newProposalThreshold);
}
/**
* @notice Set the admin address. Only the admin or timelock can call this function.
* @param _newAdmin The new admin address.
*/
function setAdmin(address _newAdmin) external onlyAdminOrTimelock {
emit AdminSet(admin, _newAdmin);
admin = _newAdmin;
}
/**
* @notice Set the manager address. Only the admin or timelock can call this function.
* @param _newManager The new manager address.
*/
function setManager(address _newManager) external onlyAdminOrTimelock {
emit ManagerSet(manager, _newManager);
manager = _newManager;
}
/**
* @dev Updated internal vote casting mechanism which delegates counting logic to voting module,
* in addition to executing standard `_countVote`. See {IGovernor-_castVote}.
*/
function _castVote(uint256 proposalId, address account, uint8 support, string memory reason, bytes memory params)
internal
virtual
override
returns (uint256 weight)
{
require(state(proposalId) == ProposalState.Active, "Governor: vote not currently active");
weight = _getVotes(account, _proposals[proposalId].voteStart.getDeadline(), "");
_countVote(proposalId, account, support, weight, params);
address votingModule = _proposals[proposalId].votingModule;
if (votingModule != address(0)) {
VotingModule(votingModule)._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);
}
}
/**
* @inheritdoc GovernorUpgradeableV2
*/
function relay(address target, uint256 value, bytes calldata data)
external
payable
virtual
override(GovernorUpgradeableV2)
onlyGovernance
{
if (approvedModules[target]) revert InvalidRelayTarget(target);
(bool success, bytes memory returndata) = target.call{value: value}(data);
AddressUpgradeable.verifyCallResult(success, returndata, "Governor: relay reverted without message");
}
/**
* @inheritdoc GovernorUpgradeableV2
* @dev Updated version in which default `proposalType` is set to 0.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override(IGovernorUpgradeable, GovernorUpgradeableV2) returns (uint256) {
return propose(targets, values, calldatas, description, 0);
}
/**
* @notice Propose a new proposal. Only the manager or an address with votes above the proposal threshold can propose.
* See {IGovernor-propose}.
* @dev Updated version of `propose` in which `proposalType` is set and checked.
*/
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description,
uint8 proposalTypeId
) public virtual returns (uint256 proposalId) {
address proposer = _msgSender();
if (proposer != manager && getVotes(proposer, block.number - 1) < proposalThreshold()) {
revert InvalidVotesBelowThreshold();
}
if (targets.length != values.length) revert InvalidProposalLength();
if (targets.length != calldatas.length) revert InvalidProposalLength();
if (targets.length == 0) revert InvalidEmptyProposal();
// Revert if `proposalType` is unset or requires module
if (
bytes(PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).name).length == 0
|| PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).module != address(0)
) {
revert InvalidProposalType(proposalTypeId);
}
PROPOSAL_TYPES_CONFIGURATOR.validateProposalData(targets, calldatas, proposalTypeId);
proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
ProposalCore storage proposal = _proposals[proposalId];
if (!proposal.voteStart.isUnset()) revert InvalidProposalExists();
uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();
uint64 deadline = snapshot + votingPeriod().toUint64();
proposal.voteStart.setDeadline(snapshot);
proposal.voteEnd.setDeadline(deadline);
proposal.proposalType = proposalTypeId;
proposal.proposer = proposer;
emit ProposalCreated(
proposalId,
_msgSender(),
targets,
values,
new string[](targets.length),
calldatas,
snapshot,
deadline,
description,
proposalTypeId
);
}
/**
* @notice Propose a new proposal using a custom voting module. Only the manager or an address with votes above the
* proposal threshold can propose. Uses the default proposal type.
* @param module The address of the voting module to use for this proposal.
* @param proposalData The proposal data to pass to the voting module.
* @param description The description of the proposal.
* @return The id of the proposal.
*/
function proposeWithModule(VotingModule module, bytes memory proposalData, string memory description)
public
virtual
returns (uint256)
{
return proposeWithModule(module, proposalData, description, 0);
}
/**
* @notice Propose a new proposal using a custom voting module. Only the manager or an address with votes above the
* proposal threshold can propose.
* @param module The address of the voting module to use for this proposal.
* @param proposalData The proposal data to pass to the voting module.
* @param description The description of the proposal.
* @param proposalTypeId The type of the proposal.
* @dev Updated version in which `proposalTypeId` is set and checked.
* @return proposalId The id of the proposal.
*/
function proposeWithModule(
VotingModule module,
bytes memory proposalData,
string memory description,
uint8 proposalTypeId
) public virtual returns (uint256 proposalId) {
address proposer = _msgSender();
if (proposer != manager) {
if (getVotes(proposer, block.number - 1) < proposalThreshold()) revert InvalidVotesBelowThreshold();
}
require(approvedModules[address(module)], "Governor: module not approved");
// Revert if `proposalTypeId` is unset or doesn't match module
if (
bytes(PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).name).length == 0
|| PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).module != address(module)
) {
revert InvalidProposalType(proposalTypeId);
}
bytes32 descriptionHash = keccak256(bytes(description));
proposalId = hashProposalWithModule(address(module), proposalData, descriptionHash);
ProposalCore storage proposal = _proposals[proposalId];
if (!proposal.voteStart.isUnset()) revert InvalidProposalExists();
uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();
uint64 deadline = snapshot + votingPeriod().toUint64();
proposal.voteStart.setDeadline(snapshot);
proposal.voteEnd.setDeadline(deadline);
proposal.votingModule = address(module);
proposal.proposalType = proposalTypeId;
proposal.proposer = proposer;
module.propose(proposalId, proposalData, descriptionHash);
emit ProposalCreated(
proposalId, proposer, address(module), proposalData, snapshot, deadline, description, proposalTypeId
);
}
/**
* @notice Allows admin or timelock to modify the `proposalTypeId` of a proposal, in case it was set incorrectly.
* @param proposalId The id of the proposal.
* @param proposalTypeId The new proposal type.
*/
function editProposalType(uint256 proposalId, uint8 proposalTypeId) external onlyAdminOrTimelock {
if (proposalSnapshot(proposalId) == 0) revert InvalidProposalId();
// Revert if `proposalTypeId` is unset or the proposal has a different voting module
if (
bytes(PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).name).length == 0
|| PROPOSAL_TYPES_CONFIGURATOR.proposalTypes(proposalTypeId).module != _proposals[proposalId].votingModule
) {
revert InvalidProposalType(proposalTypeId);
}
_proposals[proposalId].proposalType = proposalTypeId;
emit ProposalTypeUpdated(proposalId, proposalTypeId);
}
/**
* @notice Cancel a proposal. Only the admin, timelock, or proposer can call this function.
* See {GovernorUpgradeableV2-_cancel}.
*/
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
address sender = _msgSender();
require(
sender == admin || sender == timelock() || sender == _proposals[proposalId].proposer,
"Governor: only admin, governor timelock, or proposer can cancel"
);
return _cancel(targets, values, calldatas, descriptionHash);
}
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(GovernorUpgradeableV2, GovernorTimelockControlUpgradeableV2) returns (uint256) {
return GovernorTimelockControlUpgradeableV2._cancel(targets, values, calldatas, descriptionHash);
}
/**
* @notice Cancel a proposal with a custom voting module. See {GovernorUpgradeableV2-_cancel}.
* @param module The address of the voting module to use for this proposal.
* @param proposalData The proposal data to pass to the voting module.
* @param descriptionHash The hash of the proposal description.
* @return The id of the proposal.
*/
function cancelWithModule(VotingModule module, bytes memory proposalData, bytes32 descriptionHash)
public
virtual
returns (uint256)
{
uint256 proposalId = hashProposalWithModule(address(module), proposalData, descriptionHash);
address sender = _msgSender();
require(
sender == admin || sender == timelock() || sender == _proposals[proposalId].proposer,
"Governor: only admin, governor timelock, or proposer can cancel"
);
ProposalState status = state(proposalId);
require(
status != ProposalState.Canceled && status != ProposalState.Expired && status != ProposalState.Executed,
"Governor: proposal not active"
);
_proposals[proposalId].canceled = true;
emit ProposalCanceled(proposalId);
// Code from GovernorTimelockControlUpgradeableV2._cancel
if (_timelockIds[proposalId] != 0) {
_timelock.cancel(_timelockIds[proposalId]);
delete _timelockIds[proposalId];
}
return proposalId;
}
/**
* @inheritdoc GovernorTimelockControlUpgradeableV2
*/
function queue(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
public
override
returns (uint256)
{
return super.queue(targets, values, calldatas, descriptionHash);
}
/**
* @notice Queue a proposal with a custom voting module. See {GovernorTimelockControlUpgradeableV2-queue}.
*/
function queueWithModule(VotingModule module, bytes memory proposalData, bytes32 descriptionHash)
public
returns (uint256)
{
uint256 proposalId = hashProposalWithModule(address(module), proposalData, descriptionHash);
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) =
module._formatExecuteParams(proposalId, proposalData);
require(state(proposalId) == ProposalState.Succeeded, "Governor: proposal not successful");
uint256 delay = _timelock.getMinDelay();
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);
_timelock.scheduleBatch(targets, values, calldatas, 0, descriptionHash, delay);
emit ProposalQueued(proposalId, block.timestamp + delay);
return proposalId;
}
/**
* @inheritdoc GovernorUpgradeableV2
*/
function execute(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public payable override(IGovernorUpgradeable, GovernorUpgradeableV2) returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
ProposalState status = state(proposalId);
require(status == ProposalState.Queued, "Governor: proposal not queued");
_proposals[proposalId].executed = true;
emit ProposalExecuted(proposalId);
_beforeExecute(proposalId, targets, values, calldatas, descriptionHash);
_execute(proposalId, targets, values, calldatas, descriptionHash);
_afterExecute(proposalId, targets, values, calldatas, descriptionHash);
return proposalId;
}
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(GovernorUpgradeableV2, GovernorTimelockControlUpgradeableV2) {
return GovernorTimelockControlUpgradeableV2._execute(proposalId, targets, values, calldatas, descriptionHash);
}
/**
* Executes a proposal via a custom voting module. See {IGovernor-execute}.
*
* @param module The address of the voting module to use for this proposal.
* @param proposalData The proposal data to pass to the voting module.
* @param descriptionHash The hash of the proposal description.
*/
function executeWithModule(VotingModule module, bytes memory proposalData, bytes32 descriptionHash)
public
payable
virtual
returns (uint256)
{
uint256 proposalId = hashProposalWithModule(address(module), proposalData, descriptionHash);
ProposalState status = state(proposalId);
require(status == ProposalState.Queued, "Governor: proposal not queued");
_proposals[proposalId].executed = true;
emit ProposalExecuted(proposalId);
(address[] memory targets, uint256[] memory values, bytes[] memory calldatas) =
module._formatExecuteParams(proposalId, proposalData);
_beforeExecute(proposalId, targets, values, calldatas, descriptionHash);
_execute(proposalId, targets, values, calldatas, descriptionHash);
_afterExecute(proposalId, targets, values, calldatas, descriptionHash);
return proposalId;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable-v4/contracts/utils/TimersUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Timers.sol)
pragma solidity ^0.8.0;
/**
* @dev Tooling for timepoints, timers and delays
*/
library TimersUpgradeable {
struct Timestamp {
uint64 _deadline;
}
function getDeadline(Timestamp memory timer) internal pure returns (uint64) {
return timer._deadline;
}
function setDeadline(Timestamp storage timer, uint64 timestamp) internal {
timer._deadline = timestamp;
}
function reset(Timestamp storage timer) internal {
timer._deadline = 0;
}
function isUnset(Timestamp memory timer) internal pure returns (bool) {
return timer._deadline == 0;
}
function isStarted(Timestamp memory timer) internal pure returns (bool) {
return timer._deadline > 0;
}
function isPending(Timestamp memory timer) internal view returns (bool) {
return timer._deadline > block.timestamp;
}
function isExpired(Timestamp memory timer) internal view returns (bool) {
return isStarted(timer) && timer._deadline <= block.timestamp;
}
struct BlockNumber {
uint64 _deadline;
}
function getDeadline(BlockNumber memory timer) internal pure returns (uint64) {
return timer._deadline;
}
function setDeadline(BlockNumber storage timer, uint64 timestamp) internal {
timer._deadline = timestamp;
}
function reset(BlockNumber storage timer) internal {
timer._deadline = 0;
}
function isUnset(BlockNumber memory timer) internal pure returns (bool) {
return timer._deadline == 0;
}
function isStarted(BlockNumber memory timer) internal pure returns (bool) {
return timer._deadline > 0;
}
function isPending(BlockNumber memory timer) internal view returns (bool) {
return timer._deadline > block.number;
}
function isExpired(BlockNumber memory timer) internal view returns (bool) {
return isStarted(timer) && timer._deadline <= block.number;
}
}
"
},
"lib/openzeppelin-contracts-upgradeable-v4/contracts/utils/math/SafeCastUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCastUpgradeable {
/**
* @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
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
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
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
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
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
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
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
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
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
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
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
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
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
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
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
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
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
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
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
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
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
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
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
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
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
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
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
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
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
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
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
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
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
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
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
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
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
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
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
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
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
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
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
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
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
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
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
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
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
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
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
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
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
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
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
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
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
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
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
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
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
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
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest in
Submitted on: 2025-09-30 20:29:05
Comments
Log in to comment.
No comments yet.