Skip to content
Verified contractExactMIT

HardOwnerPair

Address0x2a28a276d64860a49aa545ebe7493dd063d28830
Balance

0 ETH

 

Transactions

14

 

Compiler

solc 0.8.38

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.38+commit.1835d247
Language
solidity
Optimization
Yes, 50 runs
EVM version
prague
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,399,084
Creation transaction
0x11e277f727…a3cedccbc4

src/HardOwnerPair.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

import {ReentrancyGuard} from "solady/utils/ReentrancyGuard.sol";
import {LibCall} from "solady/utils/LibCall.sol";
import {HardCore} from "./HardCore.sol";
import {NoProposal, ProposalMismatch, Unauthorized, ZeroAddress} from "./HardErrors.sol";

/// @notice Two-signer owner for the vault and the company-fee contract.
/// @dev One signer stores a call. The other signer sends it. Neither signer is `owner`.
contract HardOwnerPair is ReentrancyGuard {
    /// @dev A stored call dies after this. Confirming can still happen in the proposal block.
    uint64 internal constant PROPOSAL_TTL = 48 hours;

    address public signerA;
    address public signerB;
    address public vault;
    address public companyFee;

    /// @notice Monotonic id. A cleared proposal does not reuse it.
    uint256 public actionNonce;
    /// @notice Non-zero while a call is waiting for the other signer.
    uint256 public pendingNonce;
    address public pendingProposer;
    address public pendingTarget;
    uint64 public pendingExpiresAt;
    bytes public pendingData;

    event Proposed(
        address indexed proposer, uint256 indexed nonce, address indexed target, bytes data, uint64 expiresAt
    );
    event Confirmed(uint256 indexed nonce);
    event Cancelled(uint256 indexed nonce);
    event TargetsSet(address vault, address companyFee);
    event SignersSet(address signerA, address signerB);

    error SameSigner();
    error ProposalExpired();
    error BadTarget();

    constructor(address signerA_, address signerB_) {
        _setSigners(signerA_, signerB_);
    }

    /// @notice Store `data` for `target`. Replaces a call that is already waiting.
    function propose(address target, bytes calldata data) external nonReentrant {
        if (!_isSigner(msg.sender)) revert Unauthorized();
        _checkTarget(target, data);
        if (pendingNonce != 0) emit Cancelled(pendingNonce);
        uint256 nonce = actionNonce + 1;
        uint64 expiresAt = HardCore.readyAt(PROPOSAL_TTL);
        actionNonce = nonce;
        pendingNonce = nonce;
        pendingProposer = msg.sender;
        pendingTarget = target;
        pendingExpiresAt = expiresAt;
        pendingData = data;
        emit Proposed(msg.sender, nonce, target, data, expiresAt);
    }

    /// @notice Send the stored call. `callHash` is `keccak256(abi.encode(target, data))`
    /// of the call the signer reviewed. A replacement changes the nonce and the hash.
    function confirm(uint256 nonce, bytes32 callHash) external nonReentrant {
        if (pendingNonce == 0) revert NoProposal();
        address target = pendingTarget;
        bytes memory data = pendingData;
        if (nonce != pendingNonce || keccak256(abi.encode(target, data)) != callHash) revert ProposalMismatch();
        if (msg.sender == pendingProposer || !_isSigner(msg.sender)) revert Unauthorized();
        if (block.timestamp > pendingExpiresAt) revert ProposalExpired();
        _clearPending();
        if (target == address(this)) _applySelf(data);
        else LibCall.callContract(target, data);
        emit Confirmed(nonce);
    }

    /// @notice Drop the stored call. Either signer may drop it, including after it expires.
    function cancel() external nonReentrant {
        if (!_isSigner(msg.sender)) revert Unauthorized();
        uint256 nonce = pendingNonce;
        if (nonce == 0) revert NoProposal();
        _clearPending();
        emit Cancelled(nonce);
    }

    /// @notice Bind the vault and the company-fee contract. Both must already name this pair as owner.
    function setTargets(address vault_, address companyFee_) external {
        if (msg.sender != address(this)) revert Unauthorized();
        _setTargets(vault_, companyFee_);
    }

    /// @notice Replace the two signers. A later owner call still needs both of the new signers.
    function setSigners(address nextA, address nextB) external {
        if (msg.sender != address(this)) revert Unauthorized();
        _setSigners(nextA, nextB);
    }

    function _setTargets(address vault_, address companyFee_) internal {
        if (vault_ == address(0) || companyFee_ == address(0)) revert ZeroAddress();
        if (vault_ == companyFee_ || vault_ == address(this) || companyFee_ == address(this)) revert BadTarget();
        if (!_ownedByThis(vault_) || !_ownedByThis(companyFee_)) revert BadTarget();
        // Cross-check the wiring: the vault must actually pay this company-fee contract, and both must share
        // one stablecoin. A mismatched pair is a deploy error and is refused here, not bound. See P2-9.
        if (_readAddress(vault_, "companyFee()") != companyFee_) revert BadTarget();
        if (_readAddress(vault_, "stable()") != _readAddress(companyFee_, "stable()")) revert BadTarget();
        vault = vault_;
        companyFee = companyFee_;
        emit TargetsSet(vault_, companyFee_);
    }

    function _setSigners(address nextA, address nextB) internal {
        if (nextA == address(0) || nextB == address(0)) revert ZeroAddress();
        if (nextA == nextB || nextA == address(this) || nextB == address(this)) revert SameSigner();
        signerA = nextA;
        signerB = nextB;
        emit SignersSet(nextA, nextB);
    }

    function _clearPending() internal {
        pendingNonce = 0;
        pendingProposer = address(0);
        pendingTarget = address(0);
        pendingExpiresAt = 0;
        delete pendingData;
    }

    function _isSigner(address account) internal view returns (bool) {
        return account == signerA || account == signerB;
    }

    function _checkTarget(address target, bytes calldata data) internal view {
        if (data.length < 4) revert BadTarget();
        if (target == address(this)) {
            bytes4 selector = bytes4(data);
            if (selector != this.setTargets.selector && selector != this.setSigners.selector) revert BadTarget();
            if (data.length != 68) revert BadTarget();
            return;
        }
        if (vault == address(0) || companyFee == address(0) || (target != vault && target != companyFee)) {
            revert BadTarget();
        }
        // The pair owns both targets and must keep owning both. It may not renounce ownership, complete a
        // handover to an outside requester, or transfer ownership of one target alone: each would strand the
        // vault or the company-fee contract, or split the single owner. Signers change through `setSigners`.
        // See the P2-5 remediation and audit v2 MEDIUM-4.
        bytes4 selector = bytes4(data);
        if (selector == 0x715018a6 || selector == 0xf04e283e || selector == 0xf2fde38b) revert BadTarget();
    }

    /// @dev `confirm` applies a self call in this frame. An external call back into `confirm`
    /// would trip the reentrancy guard, so the pair does not call itself.
    function _applySelf(bytes memory data) internal {
        if (data.length != 68) revert BadTarget();
        bytes4 selector;
        address first;
        address second;
        assembly ("memory-safe") {
            selector := mload(add(data, 0x20))
            first := and(mload(add(data, 0x24)), 0xffffffffffffffffffffffffffffffffffffffff)
            second := and(mload(add(data, 0x44)), 0xffffffffffffffffffffffffffffffffffffffff)
        }
        if (selector == this.setTargets.selector) _setTargets(first, second);
        else if (selector == this.setSigners.selector) _setSigners(first, second);
        else revert BadTarget();
    }

    function _ownedByThis(address target) internal view returns (bool) {
        return _readAddress(target, "owner()") == address(this);
    }

    /// @dev Read one `address`-returning getter by a zero-argument signature, reverting `BadTarget` if the
    /// call fails or returns too little data. Used to verify target ownership and cross-wiring.
    function _readAddress(address target, string memory signature) internal view returns (address) {
        (bool ok, bytes memory data) = target.staticcall(abi.encodeWithSignature(signature));
        if (!ok || data.length < 32) revert BadTarget();
        return abi.decode(data, (address));
    }
}

lib/solady/src/utils/LibCall.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Library for making calls.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibCall.sol)
/// @author Modified from ExcessivelySafeCall (https://github.com/nomad-xyz/ExcessivelySafeCall)
///
/// @dev Note:
/// - The arguments of the functions may differ from the libraries.
///   Please read the functions carefully before use.
library LibCall {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The target of the call is not a contract.
    error TargetIsNotContract();

    /// @dev The data is too short to contain a function selector.
    error DataTooShort();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  CONTRACT CALL OPERATIONS                  */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // These functions will revert if called on a non-contract
    // (i.e. address without code).
    // They will bubble up the revert if the call fails.

    /// @dev Makes a call to `target`, with `data` and `value`.
    function callContract(address target, uint256 value, bytes memory data)
        internal
        returns (bytes memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            if iszero(call(gas(), target, value, add(data, 0x20), mload(data), codesize(), 0x00)) {
                // Bubble up the revert if the call reverts.
                returndatacopy(result, 0x00, returndatasize())
                revert(result, returndatasize())
            }
            if iszero(returndatasize()) {
                if iszero(extcodesize(target)) {
                    mstore(0x00, 0x5a836a5f) // `TargetIsNotContract()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(result, returndatasize()) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, returndatasize()) // Copy the returndata.
            mstore(0x40, add(o, returndatasize())) // Allocate the memory.
        }
    }

    /// @dev Makes a call to `target`, with `data`.
    function callContract(address target, bytes memory data)
        internal
        returns (bytes memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            if iszero(call(gas(), target, 0, add(data, 0x20), mload(data), codesize(), 0x00)) {
                // Bubble up the revert if the call reverts.
                returndatacopy(result, 0x00, returndatasize())
                revert(result, returndatasize())
            }
            if iszero(returndatasize()) {
                if iszero(extcodesize(target)) {
                    mstore(0x00, 0x5a836a5f) // `TargetIsNotContract()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(result, returndatasize()) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, returndatasize()) // Copy the returndata.
            mstore(0x40, add(o, returndatasize())) // Allocate the memory.
        }
    }

    /// @dev Makes a static call to `target`, with `data`.
    function staticCallContract(address target, bytes memory data)
        internal
        view
        returns (bytes memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            if iszero(staticcall(gas(), target, add(data, 0x20), mload(data), codesize(), 0x00)) {
                // Bubble up the revert if the call reverts.
                returndatacopy(result, 0x00, returndatasize())
                revert(result, returndatasize())
            }
            if iszero(returndatasize()) {
                if iszero(extcodesize(target)) {
                    mstore(0x00, 0x5a836a5f) // `TargetIsNotContract()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(result, returndatasize()) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, returndatasize()) // Copy the returndata.
            mstore(0x40, add(o, returndatasize())) // Allocate the memory.
        }
    }

    /// @dev Makes a delegate call to `target`, with `data`.
    function delegateCallContract(address target, bytes memory data)
        internal
        returns (bytes memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            if iszero(delegatecall(gas(), target, add(data, 0x20), mload(data), codesize(), 0x00)) {
                // Bubble up the revert if the call reverts.
                returndatacopy(result, 0x00, returndatasize())
                revert(result, returndatasize())
            }
            if iszero(returndatasize()) {
                if iszero(extcodesize(target)) {
                    mstore(0x00, 0x5a836a5f) // `TargetIsNotContract()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(result, returndatasize()) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, returndatasize()) // Copy the returndata.
            mstore(0x40, add(o, returndatasize())) // Allocate the memory.
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                    TRY CALL OPERATIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // These functions enable gas limited calls to be performed,
    // with a cap on the number of return data bytes to be copied.
    // The can be used to ensure that the calling contract will not
    // run out-of-gas.

    /// @dev Makes a call to `target`, with `data` and `value`.
    /// The call is given a gas limit of `gasStipend`,
    /// and up to `maxCopy` bytes of return data can be copied.
    function tryCall(
        address target,
        uint256 value,
        uint256 gasStipend,
        uint16 maxCopy,
        bytes memory data
    ) internal returns (bool success, bool exceededMaxCopy, bytes memory result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            success := call(
                gasStipend,
                target,
                value,
                add(data, 0x20),
                mload(data),
                codesize(),
                0x00
            )
            let n := returndatasize()
            if gt(returndatasize(), and(0xffff, maxCopy)) {
                n := and(0xffff, maxCopy)
                exceededMaxCopy := 1
            }
            mstore(result, n) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, n) // Copy the returndata.
            mstore(0x40, add(o, n)) // Allocate the memory.
        }
    }

    /// @dev Makes a call to `target`, with `data`.
    /// The call is given a gas limit of `gasStipend`,
    /// and up to `maxCopy` bytes of return data can be copied.
    function tryStaticCall(address target, uint256 gasStipend, uint16 maxCopy, bytes memory data)
        internal
        view
        returns (bool success, bool exceededMaxCopy, bytes memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            success := staticcall(
                gasStipend,
                target,
                add(data, 0x20),
                mload(data),
                codesize(),
                0x00
            )
            let n := returndatasize()
            if gt(returndatasize(), and(0xffff, maxCopy)) {
                n := and(0xffff, maxCopy)
                exceededMaxCopy := 1
            }
            mstore(result, n) // Store the length.
            let o := add(result, 0x20)
            returndatacopy(o, 0x00, n) // Copy the returndata.
            mstore(0x40, add(o, n)) // Allocate the memory.
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      OTHER OPERATIONS                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Bubbles up the revert.
    function bubbleUpRevert(bytes memory revertReturnData) internal pure {
        /// @solidity memory-safe-assembly
        assembly {
            revert(add(0x20, revertReturnData), mload(revertReturnData))
        }
    }

    /// @dev In-place replaces the function selector of encoded contract call data.
    function setSelector(bytes4 newSelector, bytes memory data) internal pure {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(gt(mload(data), 0x03)) {
                mstore(0x00, 0x0acec8bd) // `DataTooShort()`.
                revert(0x1c, 0x04)
            }
            let o := add(data, 0x20)
            mstore(o, or(shr(32, shl(32, mload(o))), newSelector))
        }
    }
}

lib/solady/src/utils/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Reentrancy guard mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Unauthorized reentrant call.
    error Reentrancy();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`.
    /// 9 bytes is large enough to avoid collisions with lower slots,
    /// but not too large to result in excessive bytecode bloat.
    uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      REENTRANCY GUARD                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Guards a function from reentrancy.
    modifier nonReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
            sstore(_REENTRANCY_GUARD_SLOT, address())
        }
        _;
        /// @solidity memory-safe-assembly
        assembly {
            sstore(_REENTRANCY_GUARD_SLOT, codesize())
        }
    }

    /// @dev Guards a view function from read-only reentrancy.
    modifier nonReadReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
        }
        _;
    }
}

src/HardCore.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

import {BadTerms} from "./HardErrors.sol";

/// @notice The weekly profit-fee steps and the bounds a deploy may set.
/// @dev `BPS` is the basis-point unit. `SET_SESSION_KEY` is the Derive action id, passed as `uint64`.
/// Neither is a deploy input. Before `FEE_RISE_AT` the rate is `FEE_BASE`.
/// That instant is Monday 2026-11-23 00:00:00 UTC, the first Monday after
/// 2026-11-22. Each `FEE_PERIOD` from then adds `FEE_STEP`, and the rate stops at `FEE_CAP`.
library HardCore {
    /// @dev 2026-11-23 00:00:00 UTC. The first Monday after 2026-11-22.
    uint64 internal constant FEE_RISE_AT = 1_795_392_000;
    uint64 internal constant FEE_PERIOD = 7 days;
    uint16 internal constant FEE_BASE = 2_000;
    uint16 internal constant FEE_STEP = 100;
    uint16 internal constant FEE_CAP = 5_000;
    uint256 internal constant BPS = 10_000;
    uint64 internal constant TIMELOCK = 48 hours;
    uint64 internal constant MIN_HUMAN = 1;
    uint64 internal constant MAX_HUMAN = 1_000_000;
    uint64 internal constant START_HUMAN = 1_000;
    uint64 internal constant MIN_PERIOD = 86_400;
    uint64 internal constant MAX_PERIOD = 7_776_000;
    /// @dev Production length of the first deposit window, measured from the deploy block.
    uint64 internal constant START_PERIOD = 432_000;
    /// @dev Production trading epoch. The open epoch end does not move when the next one changes.
    uint64 internal constant START_TRADING_PERIOD = 604_800;
    /// @dev Largest Derive withdrawal fee `redeem` absorbs without an owner shortfall proposal, in
    /// human units. `private/withdraw` caps the fee by the signed `max_fee_usd`; the docs sample signs 1.5.
    uint64 internal constant WITHDRAW_FEE_HUMAN = 2;
    /// @dev Longest owner-change timelock a deploy may fix. A larger value would make every proposal wait
    /// too long to ever apply. Audit v2 LOW-3.
    uint64 internal constant MAX_TIMELOCK = 30 days;
    /// @dev Derive `OnchainActionManager` action. Documented, not a scope code.
    uint64 internal constant SET_SESSION_KEY = 51;
    /// @dev SDK 3.0.25 `ProtocolScopeCode.Admin`. The vault refuses this code on a session key.
    uint256 internal constant ADMIN_SCOPE = 0;

    /// @notice Values fixed in the vault constructor. Later owner changes stay inside these bounds.
    struct Terms {
        uint64 feeRiseAt;
        uint64 feePeriod;
        uint16 feeBase;
        uint16 feeStep;
        uint16 feeCap;
        uint64 timelock;
        uint64 minHuman;
        uint64 maxHuman;
        uint64 startHuman;
        uint64 minPeriod;
        uint64 maxPeriod;
        uint64 startPeriod;
        uint64 startTradingPeriod;
        uint64 withdrawFeeHuman;
    }

    function defaultTerms() internal pure returns (Terms memory terms) {
        terms = Terms({
            feeRiseAt: FEE_RISE_AT,
            feePeriod: FEE_PERIOD,
            feeBase: FEE_BASE,
            feeStep: FEE_STEP,
            feeCap: FEE_CAP,
            timelock: TIMELOCK,
            minHuman: MIN_HUMAN,
            maxHuman: MAX_HUMAN,
            startHuman: START_HUMAN,
            minPeriod: MIN_PERIOD,
            maxPeriod: MAX_PERIOD,
            startPeriod: START_PERIOD,
            startTradingPeriod: START_TRADING_PERIOD,
            withdrawFeeHuman: WITHDRAW_FEE_HUMAN
        });
    }

    /// @dev A zero timelock is valid: the proposal is ready in the same block.
    /// A zero period is not, because the window or the epoch would have no duration.
    function validate(Terms memory terms) internal pure {
        if (terms.feePeriod == 0 || terms.feeBase > terms.feeCap) revert BadTerms();
        if (uint256(terms.feeBase) > BPS || uint256(terms.feeStep) > BPS || uint256(terms.feeCap) > BPS) {
            revert BadTerms();
        }
        if (terms.minHuman == 0 || terms.minHuman > terms.maxHuman) revert BadTerms();
        if (terms.startHuman < terms.minHuman || terms.startHuman > terms.maxHuman) revert BadTerms();
        if (terms.minPeriod == 0 || terms.minPeriod > terms.maxPeriod) revert BadTerms();
        if (terms.startTradingPeriod < terms.minPeriod || terms.startTradingPeriod > terms.maxPeriod) {
            revert BadTerms();
        }
        if (terms.startPeriod == 0 || terms.timelock > MAX_TIMELOCK) revert BadTerms();
        if (terms.withdrawFeeHuman > terms.maxHuman) revert BadTerms();
    }

    /// @dev `block.timestamp + delay` must fit the `uint64` clocks the vault stores.
    function readyAt(uint64 delay) internal view returns (uint64) {
        uint256 ready = block.timestamp + uint256(delay);
        if (ready > type(uint64).max) revert BadTerms();
        // forge-lint: disable-next-line(unsafe-typecast)
        return uint64(ready);
    }

    /// @dev Before `riseAt` the rate is `base`. At `riseAt`, and every `period` after it, the rate
    /// gains one `step`. It never passes `cap`. A zero `step` stays at `base`.
    function feeAt(uint256 timestamp, uint64 riseAt, uint64 period, uint16 base, uint16 step, uint16 cap)
        internal
        pure
        returns (uint16)
    {
        if (step == 0 || timestamp < riseAt) return base;
        uint256 steps = (timestamp - riseAt) / period;
        uint256 raised = uint256(base) + uint256(step) * (steps + 1);
        if (raised > cap) return cap;
        // forge-lint: disable-next-line(unsafe-typecast)
        return uint16(raised);
    }

    /// @dev The whole positive profit is taxable. Losses from earlier periods are not
    /// recovered: `applyLoss` marks the capital down and the next positive profit pays the
    /// wallet fee on that reduced capital. See ADR-0126 and invariant I27.
    function splitProfit(uint256 gross, uint16 feeBps_) internal pure returns (uint256 net, uint256 fee) {
        if (gross == 0) return (0, 0);
        fee = gross * feeBps_ / BPS;
        net = gross - fee;
    }
}

src/HardErrors.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.38;

error ZeroAddress();
error AdminScope();
error ZeroAmount();
error BadTerms();
error BadMinimum();
error BadPeriod();
error Unauthorized();
error Paused();
error BelowMinimum();
error InsufficientPending();
error SweepRequired();
error WindowOpen();
error AlreadySwept();
error UnknownWindow();
error NothingToClaim();
error NoActiveSupply();
error NothingToDistribute();
error ProfitEpochOpen();
error ProfitEpochSettled();
error ProfitOutstanding();
error AlreadyRedeemed();
error RedemptionAlreadyPending();
error NoRedemptionPending();
error RedemptionMismatch();
error ReturnAlreadyReceived();
error InsufficientSurplus();
error TimelockPending();
error NoProposal();
error ProposalMismatch();
error InvalidPayees();
error InvalidShares();
error ThirdPayeeTooLarge();
error TokenNotRecoverable();
error NotPending();
error EpochNotEnded();
error LossTooLarge();
error UnpaidWipe();
error DepositFeeUncharged();
error DepositFeeAlreadyCharged();
error SettlementTooLarge();
error LateReturnPending();
error AmountTooLarge();
error MarkdownRoundsToZero();
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 50,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.