Verified contractPartialUNLICENSED
YieldDeliveryModule
Address0xbe41bae9b4f79a5e044516af2f16f0a37c28c331
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 1 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,406,615
- Creation transaction
- 0x8391906c1f…3138b07bd3
7 files
- contracts/module/YieldDeliveryModule.solmain2.61 KB
- contracts/module/BytesUtils.sol6.87 KB
- contracts/module/base/SafeModuleBase.sol24.9 KB
- contracts/module/interfaces/ISafe.sol2.74 KB
- contracts/module/interfaces/IYieldDeliveryModule.sol740 B
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol3.38 KB
contracts/module/YieldDeliveryModule.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import {BytesUtils} from "./BytesUtils.sol";
import {ISafe} from "./interfaces/ISafe.sol";
import {IYieldDeliveryModule} from "./interfaces/IYieldDeliveryModule.sol";
import {SafeModuleBase} from "./base/SafeModuleBase.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title YieldDeliveryModule
* @author Manifest Finance
* @notice Safe module that sends USDe held by one Safe to one fixed destination, the treasury. The
* bot decides when to deliver and how much. It cannot decide where the USDe goes.
* @dev The Safe, the token and the treasury are set at deployment and never change. A different
* destination needs a new module, enabled by the Safe's own signers. The Safe needs no
* standing allowance: the Safe itself makes the transfer.
*/
contract YieldDeliveryModule is IYieldDeliveryModule, SafeModuleBase {
using BytesUtils for bytes;
/// @notice The Safe whose USDe is delivered
address public immutable SAFE;
/// @notice The token that is delivered
address public immutable USDE;
/// @notice The address that receives every delivery
address public immutable TREASURY;
constructor(
address _safe,
address _usde,
address _treasury,
address _authorizedBot,
address _owner,
uint256 _timelockDelay
) SafeModuleBase(_authorizedBot, _owner, _timelockDelay) {
if (_safe == address(0) || _usde == address(0) || _treasury == address(0)) {
revert InvalidAddress();
}
if (_treasury == _safe) revert TreasuryIsSafe();
SAFE = _safe;
USDE = _usde;
TREASURY = _treasury;
}
/// @notice Sends `amount` USDe from the Safe to the treasury
function deliver(uint256 amount) external onlyAuthorizedBot notPaused nonReentrant {
if (amount == 0) revert ZeroAmount();
if (!ISafe(SAFE).isModuleEnabled(address(this))) revert ModuleNotEnabled();
(bool success, bytes memory returnData) = ISafe(SAFE)
.execTransactionFromModuleReturnData(
USDE, 0, abi.encodeCall(IERC20.transfer, (TREASURY, amount)), ISafe.Operation.Call
);
if (!success || (returnData.length == 32 && abi.decode(returnData, (uint256)) == 0)) {
returnData.revertWithError("YieldDeliveryModule: deliver failed: ");
}
emit YieldDelivered(amount);
}
function getVersion() external pure returns (string memory) {
return "YieldDeliveryModule v1.0.0";
}
}
contracts/module/BytesUtils.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
library BytesUtils {
function calldataSliceSelector(bytes calldata _bytes) internal pure returns (bytes4 selector) {
selector = _bytes[0] | (bytes4(_bytes[1]) >> 8) | (bytes4(_bytes[2]) >> 16) | (bytes4(_bytes[3]) >> 24);
}
function memorySliceSelector(bytes memory _bytes) internal pure returns (bytes4 selector) {
selector = _bytes[0] | (bytes4(_bytes[1]) >> 8) | (bytes4(_bytes[2]) >> 16) | (bytes4(_bytes[3]) >> 24);
}
/**
* @notice Parse and revert with a descriptive error message based on return data format
* @dev Handles: empty data, bool, Error(string), Panic(uint256), custom errors, and unknown formats
* @param _bytes The return data to parse
* @param _tracingInfo Prefix to add to the error message for context
*/
function revertWithError(bytes memory _bytes, string memory _tracingInfo) internal pure {
// Handle empty return data (some functions don't return anything)
if (_bytes.length == 0) {
revert(string(abi.encodePacked(_tracingInfo, "transaction failed with no return data")));
}
// Handle boolean/uint256 return (32 bytes) - common for ERC20 transfers
if (_bytes.length == 32) {
bool success;
assembly {
success := mload(add(_bytes, 0x20))
}
if (!success) {
revert(string(abi.encodePacked(_tracingInfo, "transaction returned false")));
} else {
revert(
string(abi.encodePacked(_tracingInfo, "transaction marked failed but returned true (unexpected)"))
);
}
}
// Need at least 4 bytes for a selector
if (_bytes.length >= 4) {
bytes4 selector;
assembly {
selector := mload(add(_bytes, 0x20))
}
// Handle Error(string) format: selector 0x08c379a0
if (selector == 0x08c379a0 && _bytes.length >= 68) {
assembly {
_bytes := add(_bytes, 68)
}
revert(string(abi.encodePacked(_tracingInfo, string(_bytes))));
}
// Handle Panic(uint256) format: selector 0x4e487b71
if (selector == 0x4e487b71 && _bytes.length >= 36) {
uint256 panicCode;
assembly {
panicCode := mload(add(_bytes, 0x24))
}
string memory panicMsg = _getPanicMessage(panicCode);
revert(string(abi.encodePacked(_tracingInfo, "panic: ", panicMsg)));
}
// Handle custom errors - just show the selector
revert(string(abi.encodePacked(_tracingInfo, "custom error 0x", _toHexString(selector))));
}
// Fallback for truly unexpected formats
revert(string(abi.encodePacked(_tracingInfo, "unexpected return data format")));
}
/**
* @notice Parse and return a descriptive error message based on return data format
* @dev Same logic as revertWithError but returns string instead of reverting
* @param _bytes The return data to parse
* @param _tracingInfo Prefix to add to the error message for context
* @return string The parsed error message
*/
function returnError(bytes memory _bytes, string memory _tracingInfo) internal pure returns (string memory) {
// Handle empty return data
if (_bytes.length == 0) {
return string(abi.encodePacked(_tracingInfo, "transaction failed with no return data"));
}
// Handle boolean/uint256 return (32 bytes)
if (_bytes.length == 32) {
bool success;
assembly {
success := mload(add(_bytes, 0x20))
}
if (!success) {
return string(abi.encodePacked(_tracingInfo, "transaction returned false"));
} else {
return
string(abi.encodePacked(_tracingInfo, "transaction marked failed but returned true (unexpected)"));
}
}
// Need at least 4 bytes for a selector
if (_bytes.length >= 4) {
bytes4 selector;
assembly {
selector := mload(add(_bytes, 0x20))
}
// Handle Error(string) format
if (selector == 0x08c379a0 && _bytes.length >= 68) {
assembly {
_bytes := add(_bytes, 68)
}
return string(abi.encodePacked(_tracingInfo, string(_bytes)));
}
// Handle Panic(uint256) format
if (selector == 0x4e487b71 && _bytes.length >= 36) {
uint256 panicCode;
assembly {
panicCode := mload(add(_bytes, 0x24))
}
string memory panicMsg = _getPanicMessage(panicCode);
return string(abi.encodePacked(_tracingInfo, "panic: ", panicMsg));
}
// Handle custom errors
return string(abi.encodePacked(_tracingInfo, "custom error 0x", _toHexString(selector)));
}
// Fallback
return string(abi.encodePacked(_tracingInfo, "unexpected return data format"));
}
/**
* @notice Get human-readable message for Solidity panic codes
* @param code The panic error code
* @return string Description of the panic error
*/
function _getPanicMessage(uint256 code) private pure returns (string memory) {
if (code == 0x00) return "generic/unspecified error";
if (code == 0x01) return "assertion failed";
if (code == 0x11) return "arithmetic underflow or overflow";
if (code == 0x12) return "division or modulo by zero";
if (code == 0x21) return "invalid enum conversion";
if (code == 0x22) return "invalid storage byte array encoding";
if (code == 0x31) return "pop() on empty array";
if (code == 0x32) return "array out of bounds access";
if (code == 0x41) return "out of memory error";
if (code == 0x51) return "invalid internal function call";
return "unknown panic code";
}
/**
* @notice Convert bytes4 to hex string for error reporting
* @param _bytes The bytes4 to convert
* @return string The hex string representation (8 characters, no 0x prefix)
*/
function _toHexString(bytes4 _bytes) private pure returns (string memory) {
bytes memory hexChars = "0123456789abcdef";
bytes memory result = new bytes(8);
for (uint256 i = 0; i < 4; i++) {
result[i * 2] = hexChars[uint8(_bytes[i]) >> 4];
result[i * 2 + 1] = hexChars[uint8(_bytes[i]) & 0x0f];
}
return string(result);
}
}
contracts/module/base/SafeModuleBase.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/**
* @title SafeModuleBase
* @author Manifest Finance
* @notice Shared auth, pause, two-step ownership and timelock primitives for Manifest Safe modules.
* PositionFeeModule, RewardDistributionModule and YieldDeliveryModule inherit it.
* LiquidityModule and GuardedMintModule keep their own copies of these primitives on
* purpose: both are live and audited, so migrating them would add a fourth copy during the
* change rather than remove two. Their copies are no longer equivalent to this one: they
* raise a string require where this base reverts TimelockDelayExceedsExpiry, they enforce
* no uniqueness over (opType, payloadHash), and their queueSetAuthorizedBot accepts the bot
* that is already authorized. The allowlist half of the sequence UNIQUENESS describes below is
* therefore still reachable in both of them, through their own immediate removers; the bot
* half is not, because neither exposes an immediate clearAuthorizedBot. A new module should
* inherit this rather than copy them again.
* @dev TIMELOCK MODEL: the base stores only the operation's opType and a payload HASH, never the
* payload. The caller re-supplies the payload at execution and _consume rebinds it, so a queued
* operation cannot be executed with substituted arguments and cannot be replayed.
*
* UNIQUENESS: at most one live (unexecuted, uncancelled, unexpired) operation may exist for
* a given (opType, payloadHash). A second queue of the same action is rejected so a leftover
* operation cannot apply the same change later without a newly announced delay. Cancel or
* execute the live one before queueing it again. An expired leftover cannot execute, so it
* does not occupy the slot: the same payload may be announced again and starts a fresh delay.
* Different payloads of the same opType may be pending together.
*
* TIMELOCK SCOPE: the timelock gates the bot's identity and the set of things it may act on.
* It does not gate everything an owner can do, and that is deliberate. Clearing the bot is
* immediate, because a compromised key must be cuttable at once. setPaused is immediate in
* both directions, because a kill switch that takes hours to release is not usable. Ownership
* transfer is not timelocked because it is two-step: acceptOwnership requires the incoming
* owner to act, so a hijacked transferOwnership cannot complete on its own.
*/
abstract contract SafeModuleBase is ReentrancyGuard {
// ========================================
// CONSTANTS
// ========================================
/// @notice Default timelock delay applied when the constructor is passed 0
uint256 public constant DEFAULT_TIMELOCK_DELAY = 6 hours;
/// @notice How long after `executeAfter` a queued operation can still be executed. Execution is
/// allowed from `executeAfter` up to and including `executeAfter + TIMELOCK_EXPIRY`;
/// from the next second on, an attempt to execute reverts TimelockExpired
uint256 public constant TIMELOCK_EXPIRY = 7 days;
/// @notice opType reserved by the base. Children MUST use values >= 2.
uint8 public constant OP_SET_AUTHORIZED_BOT = 1;
/// @notice Timelock delay, fixed at construction. 0 selects DEFAULT_TIMELOCK_DELAY.
uint256 public immutable TIMELOCK_DELAY;
// ========================================
// STATE
// ========================================
/// @notice A queued timelock operation, as returned by getPendingOperation.
/// @param opType What kind of operation this is. 1 is the base's bot change; a child defines its
/// own values from 2 up
/// @param executed True once consumed. A consumed operation is never reusable
/// @param cancelled True once the owner cancelled it. Cancelling does not free the id for reuse
/// @param payloadHash keccak256 of the abi-encoded arguments the executor must re-supply
/// @param executeAfter Timestamp from which it may be executed. Zero means no such operation
/// exists, which is how getPendingOperation reports an unknown id
struct PendingOperation {
uint8 opType;
bool executed;
bool cancelled;
bytes32 payloadHash;
uint256 executeAfter;
}
/// @notice The single address allowed to call the child's bot-gated entry points. Zero after
/// clearAuthorizedBot, which leaves no address able to pass onlyAuthorizedBot
address public authorizedBot;
/// @notice The administrator: manages the bot, the pause and every timelocked operation
address public owner;
/// @notice Owner nominated by transferOwnership, pending its own acceptOwnership call
address public pendingOwner;
/// @notice While true, every function carrying notPaused reverts ModulePaused
bool public paused;
mapping(bytes32 => PendingOperation) private pendingOperations;
uint256 private _operationNonce;
/// @dev keccak256(opType, payloadHash) => the id of the last operation queued under that key.
/// A later queue of the same key overwrites it once that operation is executed, cancelled
/// or expired. Nothing ever clears the entry: _queueReserved decides whether the slot is
/// taken from the stored record's flags and its expiry, not from the entry's presence.
mapping(bytes32 => bytes32) private pendingByPayload;
// ========================================
// ERRORS
// ========================================
/// @notice The caller is not the authorized bot. Also raised when the bot has been cleared,
/// since no caller can then match the zero address
error OnlyAuthorizedBot();
/// @notice The caller is not the owner
error OnlyOwner();
/// @notice The caller is not the pending owner nominated by transferOwnership
error OnlyPendingOwner();
/// @notice The module is paused. Only functions carrying notPaused are affected; owner
/// administration, including unpausing, stays available
error ModulePaused();
/// @notice A zero address was supplied where one is not allowed: this constructor's bot or
/// owner, a new bot, or a new owner. Children raise the same error for their own
/// constructor arguments, since they do not redeclare it; PositionFeeModule does so for
/// its PositionManager and its Safe. Clearing the bot has its own function and is
/// unaffected
error InvalidAddress();
/// @notice queueSetAuthorizedBot was called with the address that is already authorized. A
/// no-op queue would mature while the bot is live and could re-authorize it after
/// clearAuthorizedBot with no newly announced delay.
error BotAlreadyAuthorized();
/// @notice cancelOwnershipTransfer was called with no transfer pending
error NoPendingOwnership();
/// @notice The timelock delay passed to the constructor is longer than TIMELOCK_EXPIRY
error TimelockDelayExceedsExpiry();
/// @notice No operation has ever been queued under this id. Records are never deleted, so an
/// executed or cancelled operation raises TimelockAlreadyExecuted or
/// TimelockAlreadyCancelled instead of this
/// @param operationId The id that resolved to no stored operation
error TimelockNotFound(bytes32 operationId);
/// @notice The operation exists but its delay has not elapsed yet
/// @param operationId The id that is not yet executable
error TimelockNotReady(bytes32 operationId);
/// @notice The operation's execution window has closed. It can never be executed and must be
/// queued again
/// @param operationId The id whose window has passed
error TimelockExpired(bytes32 operationId);
/// @notice The operation was already consumed. Execution is single-use
/// @param operationId The id that was already executed
error TimelockAlreadyExecuted(bytes32 operationId);
/// @notice The operation was cancelled by the owner and can never be executed
/// @param operationId The id that was cancelled
error TimelockAlreadyCancelled(bytes32 operationId);
/// @notice A live (unexecuted, uncancelled, unexpired) operation with the same type and payload
/// is already queued. Cancel it, or wait for it to execute, before announcing the same
/// change again. An expired leftover does not occupy the slot.
/// @param operationId The live operation occupying this (opType, payloadHash) slot
error TimelockAlreadyPending(bytes32 operationId);
/// @notice What the executor supplied does not rebind to what was queued. Raised for BOTH a
/// mismatched opType and a mismatched payload, so this error alone does not say which:
/// compare the arguments and the operation type against getPendingOperation
/// @param operationId The id whose stored type or payload hash did not match
error TimelockPayloadMismatch(bytes32 operationId);
/// @notice A child tried to queue or consume an opType outside the child range: either the
/// value the base reserves (OP_SET_AUTHORIZED_BOT) or zero. Children must use values
/// strictly greater than OP_SET_AUTHORIZED_BOT
error ReservedOpType();
// ========================================
// EVENTS
// ========================================
/// @notice The authorized bot was replaced through the timelock
/// @param previousBot The bot that was authorized until this call
/// @param newBot The bot authorized from now on
event AuthorizedBotChanged(address indexed previousBot, address indexed newBot);
/// @notice clearAuthorizedBot was called. No address can pass onlyAuthorizedBot until a new bot
/// is set. Like setPaused, the call has no equality guard, so a repeat emits again with
/// previousBot already zero and revokes nothing
/// @param previousBot The bot authorized until this call, or zero if there was none
event AuthorizedBotCleared(address indexed previousBot);
/// @notice The pause flag was written. Emitted on every setPaused call, including one that
/// writes the value it already held, so this event does not imply a change
/// @param paused The value now stored
event Paused(bool paused);
/// @notice An ownership transfer was nominated. Ownership has NOT moved yet: the nominee must
/// call acceptOwnership
/// @param currentOwner The owner at nomination time, still the owner after this event
/// @param pendingOwner The nominee
event OwnershipTransferStarted(address indexed currentOwner, address indexed pendingOwner);
/// @notice Ownership moved. This is the event that marks the actual handover
/// @param previousOwner The owner before the handover
/// @param newOwner The owner from now on
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/// @notice A pending ownership transfer was withdrawn before the nominee accepted it
/// @param owner The owner who withdrew it, unchanged by this call
/// @param cancelledPendingOwner The nominee whose nomination was withdrawn
event OwnershipTransferCancelled(address indexed owner, address indexed cancelledPendingOwner);
/// @notice An operation was queued. This is the announcement a third-party watcher reacts to:
/// it names the operation type and the moment it becomes executable, ahead of the change
/// @param operationId Handle needed to execute or cancel. Derived from an internal nonce and the
/// queueing context, so it cannot be recomputed from the payload alone
/// @param opType 1 for the base's bot change, or a child-defined value from 2 up
/// @param executeAfter Timestamp from which execution is allowed. The last timestamp inside
/// the window is executeAfter + TIMELOCK_EXPIRY
event TimelockQueued(bytes32 indexed operationId, uint8 indexed opType, uint256 executeAfter);
/// @notice A queued operation was consumed. Emitted while the timelock is being rebound, before
/// the operation's own effect, so an indexer sees this ahead of the effect's own event
/// @param operationId The id consumed
/// @param opType The type it was queued and consumed as
event TimelockExecuted(bytes32 indexed operationId, uint8 indexed opType);
/// @notice A queued operation was cancelled and can never be executed
/// @param operationId The id cancelled
event TimelockCancelled(bytes32 indexed operationId);
// ========================================
// MODIFIERS
// ========================================
modifier onlyAuthorizedBot() {
if (msg.sender != authorizedBot) revert OnlyAuthorizedBot();
_;
}
modifier onlyOwner() {
if (msg.sender != owner) revert OnlyOwner();
_;
}
modifier onlyPendingOwner() {
if (msg.sender != pendingOwner) revert OnlyPendingOwner();
_;
}
modifier notPaused() {
if (paused) revert ModulePaused();
_;
}
// ========================================
// CONSTRUCTOR
// ========================================
constructor(address _authorizedBot, address _owner, uint256 _timelockDelay) {
if (_authorizedBot == address(0)) revert InvalidAddress();
if (_owner == address(0)) revert InvalidAddress();
uint256 delay = _timelockDelay == 0 ? DEFAULT_TIMELOCK_DELAY : _timelockDelay;
// The delay is capped at TIMELOCK_EXPIRY, so a queued operation never waits longer than
// that before it can be executed.
if (delay > TIMELOCK_EXPIRY) revert TimelockDelayExceedsExpiry();
TIMELOCK_DELAY = delay;
authorizedBot = _authorizedBot;
owner = _owner;
}
// ========================================
// TIMELOCK PRIMITIVES (for children)
// ========================================
/// @dev Owner-gated queue used by the base's reserved opTypes and, through _queue, by every
/// child opType. The owner check is repeated here rather than relied on at the external
/// wrappers, so no future caller can reach the queue without it. Rejects a second live
/// (unexecuted, uncancelled, unexpired) operation of the same (opType, payloadHash) so a
/// leftover queue cannot re-apply a reversed change inside its original window. An expired
/// leftover does not occupy the slot.
function _queueReserved(uint8 opType, bytes32 payloadHash) private returns (bytes32 operationId) {
if (msg.sender != owner) revert OnlyOwner();
bytes32 key = keccak256(abi.encode(opType, payloadHash));
bytes32 existing = pendingByPayload[key];
if (existing != bytes32(0)) {
PendingOperation storage existingOp = pendingOperations[existing];
if (
!existingOp.executed && !existingOp.cancelled
&& block.timestamp <= existingOp.executeAfter + TIMELOCK_EXPIRY
) {
revert TimelockAlreadyPending(existing);
}
}
operationId = keccak256(abi.encodePacked(_operationNonce, address(this), msg.sender, block.timestamp));
unchecked {
++_operationNonce;
}
uint256 executeAfter = block.timestamp + TIMELOCK_DELAY;
pendingOperations[operationId] = PendingOperation({
opType: opType, executed: false, cancelled: false, payloadHash: payloadHash, executeAfter: executeAfter
});
pendingByPayload[key] = operationId;
emit TimelockQueued(operationId, opType, executeAfter);
}
/// @dev Owner-gated consume counterpart to _queueReserved. Reverts unless the operation exists,
/// is of the expected type, matches the supplied payload, is ready, unexpired, unexecuted
/// and uncancelled. Marks it executed before returning.
function _consumeReserved(bytes32 operationId, uint8 opType, bytes32 payloadHash) private {
if (msg.sender != owner) revert OnlyOwner();
PendingOperation storage op = pendingOperations[operationId];
if (op.executeAfter == 0) revert TimelockNotFound(operationId);
if (op.executed) revert TimelockAlreadyExecuted(operationId);
if (op.cancelled) revert TimelockAlreadyCancelled(operationId);
if (op.opType != opType) revert TimelockPayloadMismatch(operationId);
if (op.payloadHash != payloadHash) revert TimelockPayloadMismatch(operationId);
if (block.timestamp < op.executeAfter) revert TimelockNotReady(operationId);
if (block.timestamp > op.executeAfter + TIMELOCK_EXPIRY) revert TimelockExpired(operationId);
op.executed = true;
emit TimelockExecuted(operationId, opType);
}
/// @dev Owner-gating is enforced by _queueReserved itself, not left to caller discipline.
/// Children must use an opType strictly greater than OP_SET_AUTHORIZED_BOT; a reserved
/// opType is rejected here before it ever reaches storage. Hash the payload with
/// abi.encode rather than abi.encodePacked: UNIQUENESS treats one hash as one operation,
/// so a packed encoding that collapses two distinct payloads into one hash would have this
/// base reject a legitimate queue as a duplicate.
function _queue(uint8 opType, bytes32 payloadHash) internal returns (bytes32 operationId) {
if (opType <= OP_SET_AUTHORIZED_BOT) revert ReservedOpType();
operationId = _queueReserved(opType, payloadHash);
}
/// @dev Owner-gating is enforced by _consumeReserved itself, not left to caller discipline.
/// Children must use an opType strictly greater than OP_SET_AUTHORIZED_BOT; a reserved
/// opType is rejected here before it is ever consumed. See _consumeReserved for the full
/// revert contract.
function _consume(bytes32 operationId, uint8 opType, bytes32 payloadHash) internal {
if (opType <= OP_SET_AUTHORIZED_BOT) revert ReservedOpType();
_consumeReserved(operationId, opType, payloadHash);
}
// ========================================
// TIMELOCK ADMIN
// ========================================
/// @notice Cancels a queued operation permanently. The id is not freed for reuse.
/// @dev Reverts if the operation does not exist, was already executed, or was already cancelled.
/// @param operationId The queued operation to cancel
function cancelTimelock(bytes32 operationId) external onlyOwner {
PendingOperation storage op = pendingOperations[operationId];
if (op.executeAfter == 0) revert TimelockNotFound(operationId);
if (op.executed) revert TimelockAlreadyExecuted(operationId);
if (op.cancelled) revert TimelockAlreadyCancelled(operationId);
op.cancelled = true;
emit TimelockCancelled(operationId);
}
/// @notice Reads a queued operation. Never reverts.
/// @param operationId The operation to read
/// @return The stored record. An all-zero struct, recognisable by executeAfter == 0, means no
/// operation was ever queued under this id. Executed and cancelled operations are
/// retained with their flags set, not deleted
function getPendingOperation(bytes32 operationId) external view returns (PendingOperation memory) {
return pendingOperations[operationId];
}
// ========================================
// BOT MANAGEMENT
// ========================================
/// @notice Queues a bot replacement. The bot does not change until executeSetAuthorizedBot runs.
/// @dev To revoke rather than replace, use clearAuthorizedBot, which is immediate. A queue of
/// the already-authorized bot is rejected so a leftover cannot re-authorize it after a
/// clear without a newly announced delay.
/// @param newBot The bot to authorize once the timelock elapses. Must not be the zero address
/// or the currently authorized bot.
/// @return operationId Handle for executeSetAuthorizedBot or cancelTimelock. Retain it: it is
/// derived from an internal nonce and the queueing context, so it cannot be recomputed
/// from newBot
function queueSetAuthorizedBot(address newBot) external onlyOwner returns (bytes32 operationId) {
if (newBot == address(0)) revert InvalidAddress();
if (newBot == authorizedBot) revert BotAlreadyAuthorized();
operationId = _queueReserved(OP_SET_AUTHORIZED_BOT, keccak256(abi.encode(newBot)));
}
/// @notice Applies a queued bot replacement once its delay has elapsed.
/// @dev newBot must be identical to the one queued: it is rebound against the stored payload
/// hash. A mismatch reverts TimelockPayloadMismatch, as does an operationId that was
/// queued under a different operation type, such as a child's allowlist handle.
/// @param operationId The handle returned by queueSetAuthorizedBot
/// @param newBot The same address that was queued
function executeSetAuthorizedBot(bytes32 operationId, address newBot) external onlyOwner {
_consumeReserved(operationId, OP_SET_AUTHORIZED_BOT, keccak256(abi.encode(newBot)));
address previous = authorizedBot;
authorizedBot = newBot;
emit AuthorizedBotChanged(previous, newBot);
}
/// @notice Revokes the authorized bot immediately, leaving no bot until one is set again.
/// @dev Deliberately outside the timelock: a compromised bot key must be cuttable in the same
/// transaction, whatever TIMELOCK_DELAY is set to.
function clearAuthorizedBot() external onlyOwner {
address previous = authorizedBot;
authorizedBot = address(0);
emit AuthorizedBotCleared(previous);
}
// ========================================
// PAUSE
// ========================================
/// @notice The kill switch. Blocks every function carrying notPaused while true.
/// @dev Immediate in BOTH directions and deliberately outside the timelock: a switch that takes
/// hours to throw is not a kill switch, and one that takes hours to release is not usable.
/// Owner administration, including unpausing, keeps working while paused.
/// @param _paused True to block the gated entry points, false to release them
function setPaused(bool _paused) external onlyOwner {
paused = _paused;
emit Paused(_paused);
}
// ========================================
// OWNERSHIP (two-step)
// ========================================
/// @notice Nominates a new owner. This does NOT transfer ownership: the nominee must call
/// acceptOwnership, and the current owner keeps every power until they do.
/// @dev Two-step by design and therefore not timelocked: acceptOwnership must come from the
/// nominee, so a mistyped or uncontrolled address can never take ownership, and
/// cancelOwnershipTransfer withdraws a nomination before it is accepted. This does NOT
/// defend against a compromised owner key, which can nominate an address it controls and
/// accept from it in the same transaction. Nominating again overwrites the previous
/// nominee.
/// @param newOwner The address to nominate. Must not be the zero address
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert InvalidAddress();
pendingOwner = newOwner;
emit OwnershipTransferStarted(owner, newOwner);
}
/// @notice Completes a nominated ownership transfer. Callable only by the nominee, and this is
/// the call that actually moves ownership.
function acceptOwnership() external onlyPendingOwner {
address previous = owner;
owner = pendingOwner;
pendingOwner = address(0);
emit OwnershipTransferred(previous, owner);
}
/// @notice Withdraws a pending nomination before the nominee accepts it.
/// @dev Reverts NoPendingOwnership when no transfer is pending.
function cancelOwnershipTransfer() external onlyOwner {
if (pendingOwner == address(0)) revert NoPendingOwnership();
address cancelled = pendingOwner;
pendingOwner = address(0);
emit OwnershipTransferCancelled(owner, cancelled);
}
}
contracts/module/interfaces/ISafe.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
interface ISafe {
enum Operation {
Call,
DelegateCall
}
/// @dev Allows a Module to execute a Safe transaction without any further confirmations.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction.
function execTransactionFromModule(address to, uint256 value, bytes calldata data, Operation operation)
external
returns (bool success);
/// @dev Allows a Module to execute a Safe transaction without any further confirmations and return data
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction.
function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, Operation operation)
external
returns (bool success, bytes memory returnData);
/// @dev Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction.
/// Note: The fees are always transferred, even if the user transaction fails.
/// @param to Destination address of Safe transaction.
/// @param value Ether value of Safe transaction.
/// @param data Data payload of Safe transaction.
/// @param operation Operation type of Safe transaction.
/// @param safeTxGas Gas that should be used for the Safe transaction.
/// @param baseGas Gas costs that are independent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund)
/// @param gasPrice Gas price that should be used for the payment calculation.
/// @param gasToken Token address (or 0 if ETH) that is used for the payment.
/// @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).
/// @param signatures Packed signature data ({bytes32 r}{bytes32 s}{uint8 v})
function execTransaction(
address to,
uint256 value,
bytes calldata data,
Operation operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address payable refundReceiver,
bytes memory signatures
) external payable returns (bool success);
function enableModule(address module) external;
function isModuleEnabled(address module) external view returns (bool);
function approveHash(bytes32 hashToApprove) external;
}
contracts/module/interfaces/IYieldDeliveryModule.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;
/**
* @title IYieldDeliveryModule
* @notice Interface for the YieldDeliveryModule
*/
interface IYieldDeliveryModule {
/// @notice The amount was zero, so there was nothing to deliver
error ZeroAmount();
/// @notice The module is not enabled on the Safe
error ModuleNotEnabled();
/// @notice The treasury is the Safe itself, so a delivery would move nothing
error TreasuryIsSafe();
/// @notice USDe left the Safe for the treasury
/// @param amount USDe transferred to the treasury
event YieldDelivered(uint256 amount);
function deliver(uint256 amount) external;
function getVersion() external pure returns (string memory);
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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);
}
lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@uniswap/v4-core/=lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/messagelib/",
"@layerzerolabs/oapp-evm/=lib/LayerZero-v2/packages/layerzero-v2/evm/oapp/",
"@layerzerolabs/oapp-evm-devtools/=lib/devtools/packages/oapp-evm/",
"@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/",
"@layerzerolabs/ovault-evm/=lib/devtools/packages/ovault-evm/",
"@layerzerolabs/test-devtools-evm-foundry/=lib/devtools/packages/test-devtools-evm-foundry/",
"solidity-bytes-utils/=lib/solidity-bytes-utils/",
"solady/=lib/solady/src/",
"@perimetersec/fuzzlib/=lib/fuzzlib/",
"solmate/=lib/solmate/",
"@safe-global/safe-smart-account/=lib/safe-smart-account/",
"@chainlink/contracts/=node_modules/@chainlink/contracts/",
"@SKYBITDev3/=node_modules/@SKYBITDev3/",
"@Vectorized/=node_modules/@Vectorized/",
"@arbitrum/=node_modules/@arbitrum/",
"@axelar-network/=node_modules/@axelar-network/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@eth-optimism/=node_modules/@eth-optimism/",
"@offchainlabs/=node_modules/@offchainlabs/",
"@scroll-tech/=node_modules/@scroll-tech/",
"@transmissions11/=node_modules/@transmissions11/",
"@zksync/=node_modules/@zksync/",
"LayerZero-v2/=lib/LayerZero-v2/",
"devtools/=lib/devtools/packages/toolbox-foundry/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"fuzzlib/=lib/fuzzlib/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"safe-smart-account/=lib/safe-smart-account/",
"v4-core/=lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.