// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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 v4.9.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 v4.9.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.
*/
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].
*/
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
pragma solidity ^0.8.19;
interface IVetoCouncil {
/* -------------------------------------------------------------------------- */
/* errors */
/* -------------------------------------------------------------------------- */
error CallerNotGovernance();
error NoRewards();
error ZeroAddressInConstructor();
error MaxCouncilMembersExceeded();
/* -------------------------------------------------------------------------- */
/* events */
/* -------------------------------------------------------------------------- */
/**
* @param oldMember The address of the member to be slashed or removed
* @param newMember The address of the new member (0 = no new member)
* @param slashOldMember Whether to slash the member or not
*/
event VetoCouncilSeatsEdited(address indexed oldMember, address indexed newMember, bool slashOldMember);
/**
* @dev emitted when a council member is paid out
* @param account The address of the council member
* @param amountNow The amount paid out now
* @param amountToBeVested The amount to be vested
*/
event CouncilMemberPayout(address indexed account, uint256 amountNow, uint256 amountToBeVested);
/* -------------------------------------------------------------------------- */
/* state-changing */
/* -------------------------------------------------------------------------- */
/**
* @notice Add or remove a council member
* @param oldMember The address of the member to be slashed or removed
* @param newMember The address of the new member (0 = no new member)
* @param slashOldMember Whether to slash the member or not
* @return - true if the council member was added or removed, false if nothing was done
* - the function should return false if the new member is already a council member
* - if the old member is not a council member, the function should return false
* - if the old member is a council member and the new member is the same as the old member, the function should return false
* - by adding a new member there would be more than 7 council members, the function should return false
*/
function addAndRemoveCouncilMember(address oldMember, address newMember, bool slashOldMember)
external
returns (bool);
/**
* @notice Payout the council member
* @param member The address of the council member
* @param nonce The payout nonce to claim from
* @param sync Whether to sync the vesting schedule or not
* @param members The addresses of the council members that were active at `nonce`
*/
function claimPayout(address member, uint256 nonce, bool sync, address[] memory members) external;
/* -------------------------------------------------------------------------- */
/* view */
/* -------------------------------------------------------------------------- */
/**
* @notice returns true if the member is a council member
* @param member The address of the member to be checked
* @return - true if the member is a council member
*/
function isCouncilMember(address member) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
if (nonceAfter != nonceBefore + 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {IVetoCouncil} from "@/interfaces/IVetoCouncil.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @dev Struct representing a holding of tokens in the HoldingContract.
* @param amount The amount of tokens being held.
* @param expirationTimestamp The timestamp at which the holding expires and can be withdrawn.
*/
struct Holding {
uint192 amount;
uint64 expirationTimestamp;
}
/**
* @dev a helper type to organize claim holdings arguments
* @param user the address of the user
* @param token the address of the USDC token to withdraw
*/
struct ClaimHoldingArgs {
address user;
address token;
}
interface ISafetyDelay {
function addHolding(address user, address token, uint192 amount) external;
function holdings(address user, address token) external view returns (Holding memory);
function claimHoldings(ClaimHoldingArgs[] memory args) external;
}
/**
* @title SafetyDelay
* @notice This contract is used to hold tokens for users
* - This contract holds all USDC tokens that are part of the protocol
* - Once farms withdraw, there is a 1 week delay before they can claim their tokens
* - The Miner Pool Contract assigns these holdings as part of the withdraw process
* - Veto Agents can delay all withdrawals by 13 weeks
* - A holding can be max delayed for 97 days
*/
contract SafetyDelay is ISafetyDelay {
/* -------------------------------------------------------------------------- */
/* errors */
/* -------------------------------------------------------------------------- */
error OnlyMinerPoolCanAddHoldings();
error WithdrawalNotReady();
error CallerMustBeVetoCouncilMember();
error DelayStillOnCooldown();
error NetworkIsFrozen();
error AlreadyWithdrawnFromHolding();
error MinerPoolAlreadySet();
/* -------------------------------------------------------------------------- */
/* constants */
/* -------------------------------------------------------------------------- */
/**
* @notice the default delay for withdrawals
* @dev the default delay is 7 days
* Whenever a user withdraws from the miner pool,
* their funds are locked for 7 days
*/
uint256 public constant DEFAULT_DELAY = uint256(7 days);
/**
* @dev 90 days in seconds
*/
uint256 public constant NINETY_DAYS = uint256(90 days);
/**
* @notice the delay for withdrawals after the network is delayed
* @dev the delay is 13 weeks
* all withdrawals will be delayed for 13 weeks
*/
uint256 public constant VETO_HOLDING_DELAY = uint256(13 weeks);
/**
* @dev a cached version of five weeks in seconds
* @dev used in delayNetwork to ensure that the network can only be delayed every 5 weeks
* @dev This helps prevent bad veto agents from spamming the delay network function
* - by giving governance enough time to kick out the veto agent
*/
uint256 public constant FIVE_WEEKS = uint256(5 weeks);
/* -------------------------------------------------------------e------------- */
/* immutables */
/* -------------------------------------------------------------------------- */
/**
* @notice the address of the veto council
* @dev veto council members can delay the network
*/
IVetoCouncil public immutable VETO_COUNCIL;
/**
* @notice the address of the miner pool
* @dev this is the address that can add holdings to the contract
*/
address public immutable MINER_POOL;
/* -------------------------------------------------------------------------- */
/* state vars */
/* -------------------------------------------------------------------------- */
/**
* @notice the minimum timestamp for withdrawals
* @dev any claims below this timestamp will revert
*/
uint256 public minimumWithdrawTimestamp;
/* -------------------------------------------------------------------------- */
/* mappings */
/* -------------------------------------------------------------------------- */
/**
* @notice the holdings for each user
* Note: We could have chosen an array of holdings
* such that each withdraw truly is a FIFO queue with 1 week delay
* However, we chose to store all holdings in a single slot
* to avoid cold sstores and sloads
* The downside of this approach is that we can't have a FIFO queue
* and that any time a withdraw is made from the miner pool contract
* the user's holdings are locked for 7 days
*/
mapping(address => mapping(address => Holding)) private _holdings;
/* -------------------------------------------------------------------------- */
/* events */
/* -------------------------------------------------------------------------- */
/**
* @dev emitted when there is a network delay
* @param vetoAgent the address of the veto agent that delayed the network
* @param timestamp the timestamp at which the network was delayed
*/
event NetworkDelay(address vetoAgent, uint256 timestamp);
/**
* @dev emitted whenever a holding is added to a user
* @param user the address of the user
* @param token the address of the USDC token
* @param amount the amount of tokens added to the holding
* @dev we dont emit a {HoldingClaimed} event since there may be a tax
* - on the token that will mess up the data.
* - we rely on catching transfer events
*/
event HoldingAdded(address indexed user, address indexed token, uint192 amount);
/*
* @notice emitted when a user claims their holding
* @param user the address of the user
* @param token the address of the USDC token
* @param amount the amount of tokens claimed
*/
event HoldingClaimed(address indexed user, address indexed token, uint192 amount);
/* -------------------------------------------------------------------------- */
/* constructor */
/* -------------------------------------------------------------------------- */
/**
* @param _vetoCouncil the address of the veto council
* @param _minerPool the address of the miner pool
*/
constructor(address _vetoCouncil, address _minerPool) payable {
VETO_COUNCIL = IVetoCouncil(_vetoCouncil);
MINER_POOL = _minerPool;
}
/* -------------------------------------------------------------------------- */
/* delay */
/* -------------------------------------------------------------------------- */
/**
* @notice allows veto council members to delay the network by 13 weeks
*/
function delayNetwork() external {
if (!VETO_COUNCIL.isCouncilMember(msg.sender)) {
_revert(CallerMustBeVetoCouncilMember.selector);
}
uint256 _minimumWithdrawTimestamp = minimumWithdrawTimestamp;
if (_minimumWithdrawTimestamp == 0) {
minimumWithdrawTimestamp = block.timestamp + VETO_HOLDING_DELAY;
emit NetworkDelay(msg.sender, block.timestamp);
return;
}
if (block.timestamp < _minimumWithdrawTimestamp) {
//The block.timestamp needs to be within 5 weeks of
//minimumWithdrawTimestamp
uint256 timeLeftInDelay = _minimumWithdrawTimestamp - block.timestamp;
if (timeLeftInDelay > FIVE_WEEKS) {
_revert(DelayStillOnCooldown.selector);
}
}
minimumWithdrawTimestamp = block.timestamp + VETO_HOLDING_DELAY;
emit NetworkDelay(msg.sender, block.timestamp);
}
/* -------------------------------------------------------------------------- */
/* claim */
/* -------------------------------------------------------------------------- */
/**
* @notice entrypoint to claim holdings
* @param args - an array of {ClaimHoldingArgs}
* @dev this is a batch method to claim holdings
* - this is more gas efficient than calling claimHolding for each holding
* - the protocol may use a relayer to bundle claims
*/
function claimHoldings(ClaimHoldingArgs[] memory args) external {
//If the network is frozen, don't allow withdrawals
bool networkIsFrozen = isNetworkFrozen();
//Loop over all the arguments
uint256 len = args.length;
for (uint256 i; i < len;) {
ClaimHoldingArgs memory arg = args[i];
_claimHolding(arg.user, arg.token, networkIsFrozen);
unchecked {
++i;
}
}
}
/**
* @notice entrypoint to claim a single holding
* @param user the address of the user
* @param token the address of the USDC token to withdraw
* @dev should be used if the user only wants to claim their holding
*/
function claimHoldingSingleton(address user, address token) external {
// If the network is frozen and timestamp since expiration is not more than 90 days, don't allow withdrawals
bool networkIsFrozen = isNetworkFrozen();
_claimHolding(user, token, networkIsFrozen);
}
/* -------------------------------------------------------------------------- */
/* add holdings */
/* -------------------------------------------------------------------------- */
/**
* @notice an internal method to increment the amount in a holding
* @param user the address of the user
* @param token the address of the USDC token to withdraw
* @param amount the amount of tokens to add to the holding
*/
function addHolding(address user, address token, uint192 amount) external {
if (msg.sender != MINER_POOL) {
_revert(OnlyMinerPoolCanAddHoldings.selector);
}
_holdings[user][token].amount += amount;
_holdings[user][token].expirationTimestamp = uint64(block.timestamp + DEFAULT_DELAY);
emit HoldingAdded(user, token, amount);
}
/* -------------------------------------------------------------------------- */
/* view functions */
/* -------------------------------------------------------------------------- */
/**
* @notice returns the Holding struct for a user and token pair
* @param user the address of the user
* @param token the address of the USDC token to withdraw
* @return holding - the Holding struct
*/
function holdings(address user, address token) external view returns (Holding memory) {
return _holdings[user][token];
}
/**
* @notice returns true if the network is frozen
* @dev the network is frozen if the minimumWithdrawTimestamp is greater than the current block timestamp
* @return isNetworkFrozen - true if the network is frozen
*/
function isNetworkFrozen() public view returns (bool) {
return block.timestamp < minimumWithdrawTimestamp;
}
/**
* @dev checks if the holding is available to be withdrawn
* @param holdingExpirationTimestamp the timestamp at which the holding expires
* @param isNetworkFrozen whether or not the network is currently frozen
* @dev - if the network is frozen, the holding can be withdrawn only if it's been more than 90 days past the expiration of the holding
* - if the network is not frozen, the holding can be withdrawn only if it's past the expiration date of the holding
*/
function checkHoldingAvailable(uint64 holdingExpirationTimestamp, bool isNetworkFrozen) internal view {
if (block.timestamp < holdingExpirationTimestamp) {
_revert(WithdrawalNotReady.selector);
}
//Can't underflow because of the check above
//No claim should be able to be held for more than 97 days
//If it's been less than than 97 days since the proposal has expired,
//(expiration timestamp is always claim timestamp + 1 week, so )
//in order for proposal to be held maximum 97 days,
//We need to check if the diff is 90 days
if (block.timestamp - holdingExpirationTimestamp < NINETY_DAYS) {
if (isNetworkFrozen) {
_revert(NetworkIsFrozen.selector);
}
}
}
/* -------------------------------------------------------------------------- */
/* utils */
/* -------------------------------------------------------------------------- */
/**
* @dev an internal method to claim a holding
* @param user the address of the user
* @param token the address of the USDC token to withdraw
* @param networkIsFrozen whether or not the network is currently frozen
*/
function _claimHolding(address user, address token, bool networkIsFrozen) internal {
Holding memory holding = _holdings[user][token];
checkHoldingAvailable(holding.expirationTimestamp, networkIsFrozen);
//Delete the holding args.
//Should set all the data to zero.
delete _holdings[user][token];
//Add the amount to the amount to transfer
SafeERC20.safeTransfer(IERC20(token), user, holding.amount);
emit HoldingClaimed(user, token, holding.amount);
}
/**
* @dev more efficient reverts
* @param selector the selector of the error
*/
function _revert(bytes4 selector) internal pure {
// solhint-disable-next-line no-inline-assembly
assembly {
mstore(0, selector)
revert(0, 4)
}
}
}
{
"compilationTarget": {
"src/SafetyDelay.sol": "SafetyDelay"
},
"evmVersion": "paris",
"libraries": {
"src/libraries/HalfLife.sol:HalfLife": "0xcf4d7552ca9f07c474d69e89a88943fabb60b199",
"src/libraries/HalfLifeCarbonCreditAuction.sol:HalfLifeCarbonCreditAuction": "0xd178525026bafc51d045a2e98b0c79a526d446de"
},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000000
},
"remappings": [
":@/=src/",
":@clones/=lib/unifap-v2/lib/clones-with-immutable-args/src/",
":@ds/=lib/unifap-v2/lib/ds-test/src/",
":@openzeppelin/=lib/openzeppelin-contracts/contracts/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@solady/=lib/solady/src/",
":@solmate/=lib/unifap-v2/lib/solmate/src/",
":@std/=lib/unifap-v2/lib/forge-std/src/",
":@unifapv2/=src/UnifapV2/",
":abdk-libraries-solidity/=lib/abdk-libraries-solidity/",
":clones-with-immutable-args/=lib/clones-with-immutable-args/src/",
":clones/=lib/clones-with-immutable-args/src/",
":clones/=lib/unifap-v2/lib/clones-with-immutable-args/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":solady/=lib/solady/",
":solmate/=lib/solmate/src/",
":unifap-v2/=lib/unifap-v2/src/"
]
}
[{"inputs":[{"internalType":"address","name":"_vetoCouncil","type":"address"},{"internalType":"address","name":"_minerPool","type":"address"}],"stateMutability":"payable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"AlreadyWithdrawnFromHolding","type":"error"},{"inputs":[],"name":"CallerMustBeVetoCouncilMember","type":"error"},{"inputs":[],"name":"DelayStillOnCooldown","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"MinerPoolAlreadySet","type":"error"},{"inputs":[],"name":"NetworkIsFrozen","type":"error"},{"inputs":[],"name":"OnlyMinerPoolCanAddHoldings","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"WithdrawalNotReady","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint192","name":"amount","type":"uint192"}],"name":"HoldingAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint192","name":"amount","type":"uint192"}],"name":"HoldingClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"vetoAgent","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"NetworkDelay","type":"event"},{"inputs":[],"name":"DEFAULT_DELAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FIVE_WEEKS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINER_POOL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NINETY_DAYS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VETO_COUNCIL","outputs":[{"internalType":"contract IVetoCouncil","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VETO_HOLDING_DELAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint192","name":"amount","type":"uint192"}],"name":"addHolding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"claimHoldingSingleton","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"internalType":"struct ClaimHoldingArgs[]","name":"args","type":"tuple[]"}],"name":"claimHoldings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delayNetwork","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"holdings","outputs":[{"components":[{"internalType":"uint192","name":"amount","type":"uint192"},{"internalType":"uint64","name":"expirationTimestamp","type":"uint64"}],"internalType":"struct Holding","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isNetworkFrozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumWithdrawTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]