Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x686FdecC0572e30768331D4e1a44E5077B2f6083
Balance 0 ETH
Nonce 1
Code Size 2619 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

2619 bytes
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c8063bb53d33611610097578063db8ea62e11610066578063db8ea62e14610213578063ebd090541461021b578063f011a7af14610242578063fe417fa51461024a57600080fd5b8063bb53d336146101b5578063bd814b6f146101c8578063bf7e214f146101db578063d7062005146101ec57600080fd5b80636c63c2da116100d35780636c63c2da146101725780638287ccb41461017b57806397bc1e1b14610190578063ad7a672f146101ad57600080fd5b80630a28a477146100fa578063409cfe01146101205780634b6d39f51461015f575b600080fd5b61010d610108366004610912565b61025d565b6040519081526020015b60405180910390f35b6101477f000000000000000000000000828787a14fd4470ef925eefa8a56c88d85d4a06a81565b6040516001600160a01b039091168152602001610117565b61010d61016d366004610912565b610267565b61010d60015481565b61018e610189366004610912565b6102c0565b005b600054600160a01b900460ff166040519015158152602001610117565b61010d610315565b61018e6101c3366004610912565b610324565b61018e6101d6366004610942565b610372565b6000546001600160a01b0316610147565b6101477f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf81565b61010d610487565b6101477f0000000000000000000000002ceb95d4a67bf771f1165659df3d11d8871e906f81565b61018e6104b0565b61018e610258366004610964565b610516565b6000815b92915050565b6000336001600160a01b037f000000000000000000000000828787a14fd4470ef925eefa8a56c88d85d4a06a16146102b25760405163606cb83f60e01b815260040160405180910390fd5b6102618261057b565b919050565b336001600160a01b037f000000000000000000000000828787a14fd4470ef925eefa8a56c88d85d4a06a16146103095760405163606cb83f60e01b815260040160405180910390fd5b6103128161059a565b50565b600061031f6105b4565b905090565b336001600160a01b037f000000000000000000000000828787a14fd4470ef925eefa8a56c88d85d4a06a161461036d5760405163606cb83f60e01b815260040160405180910390fd5b600155565b336001600160a01b037f000000000000000000000000828787a14fd4470ef925eefa8a56c88d85d4a06a16146103bb5760405163606cb83f60e01b815260040160405180910390fd5b6103c361063f565b60006001556040516370a0823160e01b81523060048201526103129082906001600160a01b037f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf16906370a0823190602401602060405180830381865afa158015610432573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610456919061098e565b6001600160a01b037f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf1691906106bf565b6000806104926105b4565b90506001548111156104a8576001549003919050565b600091505090565b6104c6336000356001600160e01b031916610716565b61050c5760405162461bcd60e51b8152602060048201526012602482015271105d5d1a0e8815539055551213d49256915160721b60448201526064015b60405180910390fd5b61051461063f565b565b61052c336000356001600160e01b031916610716565b61056d5760405162461bcd60e51b8152602060048201526012602482015271105d5d1a0e8815539055551213d49256915160721b6044820152606401610503565b61057782826107b5565b5050565b6000816001600082825461058f91906109bd565b909155509192915050565b80600160008282546105ac91906109d0565b909155505050565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf6001600160a01b0316906370a0823190602401602060405180830381865afa15801561061b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061031f919061098e565b6000610649610487565b9050801561031257600061065c82610841565b90506001546106696105b4565b10156106885760405163764f2ec560e11b815260040160405180910390fd5b6040518181527ffdf9b46a645f9f6f4ca3354fd63e9f78c4780b786db68976e485cb41ffc0bb129060200160405180910390a15050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b17905261071190849061089b565b505050565b600080546001600160a01b031680158015906107ad575060405163b700961360e01b81526001600160a01b0385811660048301523060248301526001600160e01b03198516604483015282169063b700961390606401602060405180830381865afa158015610789573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ad91906109e3565b949350505050565b7f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf6001600160a01b0316826001600160a01b0316036108075760405163c1ab6dc160e01b815260040160405180910390fd5b8015610577576105776001600160a01b0383167f0000000000000000000000002ceb95d4a67bf771f1165659df3d11d8871e906f836106bf565b60006108976001600160a01b037f000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf167f0000000000000000000000002ceb95d4a67bf771f1165659df3d11d8871e906f846106bf565b5090565b600080602060008451602086016000885af1806108be576040513d6000823e3d81fd5b50506000513d915081156108d65780600114156108e3565b6001600160a01b0384163b155b1561090c57604051635274afe760e01b81526001600160a01b0385166004820152602401610503565b50505050565b60006020828403121561092457600080fd5b5035919050565b80356001600160a01b03811681146102bb57600080fd5b60006020828403121561095457600080fd5b61095d8261092b565b9392505050565b6000806040838503121561097757600080fd5b6109808361092b565b946020939093013593505050565b6000602082840312156109a057600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610261576102616109a7565b80820180821115610261576102616109a7565b6000602082840312156109f557600080fd5b8151801515811461095d57600080fdfea264697066735822122060258778f4ca88348b5b283aed8c37ba529e0dfc40c2766e24c17ce08fdfe4cd64736f6c634300081d0033

Verified Source Code Full Match

Compiler: v0.8.29+commit.ab55807c EVM: paris Optimization: Yes (200 runs)
BaseEscrow.sol 176 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.29;

import { AuthNoOwner } from "./Dependencies/AuthNoOwner.sol";
import { IEscrow } from "./Dependencies/IEscrow.sol";
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title BaseEscrow
/// @notice Handles assets custody on deposits and withdrawals.
contract BaseEscrow is AuthNoOwner, IEscrow {
    using SafeERC20 for IERC20;

    IERC20 public immutable ASSET_TOKEN;
    address public immutable BSM;
    address public immutable FEE_RECIPIENT;

    /// @notice total user deposit amount
    uint256 public totalAssetsDeposited;

    error CallerNotBSM();
    error InvalidToken();
    error LossCheck();

    /// @notice Modifier to restrict function calls to the BSM
    modifier onlyBSM() {
        if (msg.sender != BSM) {
            revert CallerNotBSM();
        }
        _;
    }

    /// @notice Contract constructor
    /// @param _assetToken The ERC20 token address used for deposits and withdrawals
    /// @param _bsm The address of the eBTC Stability Module (BSM)
    /// @param _governance The governance address used for AuthNoOwner
    /// @param _feeRecipient The address where collected fees are sent
    constructor(address _assetToken, address _bsm, address _governance, address _feeRecipient) {
        ASSET_TOKEN = IERC20(_assetToken);
        BSM = _bsm;
        FEE_RECIPIENT = _feeRecipient;
        _initializeAuthority(_governance);

        // allow the BSM to transfer asset tokens
        ASSET_TOKEN.forceApprove(BSM, type(uint256).max); /// safe approve
    }

    /// @dev Internal function that checks the total balance of assets held by the contract
    function _totalBalance() internal virtual view returns (uint256) {
        return ASSET_TOKEN.balanceOf(address(this));
    }

    /// @notice Internal function to handle asset deposits
    /// @param _assetAmount The amount of assets to deposit
    function _onDeposit(uint256 _assetAmount) internal virtual {
        totalAssetsDeposited += _assetAmount;
    }

    /// @notice Internal function to handle asset withdrawals
    /// @param _assetAmount The amount of assets to withdraw
    /// @return The amount of assets actually withdrawn
    function _onWithdraw(uint256 _assetAmount) internal virtual returns (uint256) {
        totalAssetsDeposited -= _assetAmount;
        /// @dev returning the amount requested since this is the base contract
        /// it's possible for other implementations to return lower amounts
        return _assetAmount;
    }

    /// @notice Internal function to preview the withdrawable amount without making any state changes
    /// @param _assetAmount The amount of assets queried for withdrawal
    /// @return The amount that can be withdrawn
    function _previewWithdraw(uint256 _assetAmount) internal virtual view returns (uint256) {
        return _assetAmount;
    }

    /// @notice withdraw profit to FEE_RECIPIENT
    /// @param _profitAmount The amount of profit to withdraw
    function _withdrawProfit(uint256 _profitAmount) internal virtual returns (uint256){
        ASSET_TOKEN.safeTransfer(FEE_RECIPIENT, _profitAmount);
        return _profitAmount;
    }

    /// @notice Prepares the escrow for migration
    function _beforeMigration() internal virtual {
        // Do nothing
    }

    /// @notice Internal function to claim profits generated from fees and external lending
    function _claimProfit() internal {
        uint256 profit = feeProfit();
        if (profit > 0) {
            uint256 profitWithdrawn = _withdrawProfit(profit);
            // INVARIANT: total balance must be >= deposit amount
            require(_totalBalance() >= totalAssetsDeposited, LossCheck());
            emit ProfitClaimed(profitWithdrawn);
        }        
    }

    /// @notice Returns the total balance of assets in the escrow
    function totalBalance() external view returns (uint256) {
        return _totalBalance();
    }

    /// @notice Deposits assets into the escrow
    /// @dev Can only be called by the bsm contract
    /// @param _assetAmount The amount of assets to deposit
    function onDeposit(uint256 _assetAmount) external onlyBSM {
        _onDeposit(_assetAmount);
    }

    /// @notice Withdraws assets from the escrow
    /// @dev Can only be called by the bsm contract
    /// @param _assetAmount The amount of assets to withdraw
    /// @return The amount of assets withdrawn
    function onWithdraw(uint256 _assetAmount) external onlyBSM returns (uint256) {
        return _onWithdraw(_assetAmount);
    }

    function previewWithdraw(uint256 _assetAmount) external view returns (uint256) {
        /// @dev derived contracts can override _previewWithdraw to report potential losses
        return _previewWithdraw(_assetAmount);
    }

    /// @notice Called on the source escrow during a migration by the BSM to transfer liquidity
    /// @dev Can only be called by the bsm contract
    /// @param _newEscrow new escrow address
    function onMigrateSource(address _newEscrow) external onlyBSM {
        /// @dev take profit first (totalBalance == depositAmount after)
        _claimProfit();

        /// @dev clear depositAmount in old vault (address(this))
        totalAssetsDeposited = 0;

        /// @dev perform pre-migration tasks (potentially used by derived contracts)
        _beforeMigration();

        /// @dev transfer all liquidity to new vault
        ASSET_TOKEN.safeTransfer(_newEscrow, ASSET_TOKEN.balanceOf(address(this)));
    }

    /// @notice Called on the target escrow during a migration by the BSM to set the user deposit amount
    /// @dev Can only be called by the bsm contract
    function onMigrateTarget(uint256 _amount) external onlyBSM {
        totalAssetsDeposited = _amount;
    }

    /// @notice Calculates the profit generated from asset management
    /// @return The amount of profit generated
    function feeProfit() public view returns (uint256) {
        uint256 tb = _totalBalance();
        if(tb > totalAssetsDeposited) {
            unchecked {
                return tb - totalAssetsDeposited;
            }
        }

        return 0;
    }

    /// @notice Claim profit (fees + external lending profit)
    /// @dev can only be called by authorized users
    function claimProfit() external requiresAuth {
        _claimProfit();
    }

    function _claimTokens(address token, uint256 amount) internal virtual {
        require(token != address(ASSET_TOKEN), InvalidToken());
        if (amount > 0) {
            IERC20(token).safeTransfer(FEE_RECIPIENT, amount);
        }
    }

    /// @notice Claim reward tokens and/or other tokens sent to this contract
    function claimTokens(address token, uint256 amount) external requiresAuth {
        _claimTokens(token, amount);
    }
}
AuthNoOwner.sol 49 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.29;

import {Authority} from "./Authority.sol";

/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Modified by BadgerDAO to remove owner
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
contract AuthNoOwner {
    event AuthorityUpdated(address indexed user, Authority indexed newAuthority);

    Authority private _authority;
    bool private _authorityInitialized;

    modifier requiresAuth() virtual {
        require(isAuthorized(msg.sender, msg.sig), "Auth: UNAUTHORIZED");

        _;
    }

    function authority() public view returns (Authority) {
        return _authority;
    }

    function authorityInitialized() public view returns (bool) {
        return _authorityInitialized;
    }

    function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
        Authority auth = _authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.

        // Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
        // aware that this makes protected functions uncallable even to the owner if the authority is out of order.
        return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig));
    }

    /// @notice Changed constructor to initialize to allow flexibility of constructor vs initializer use
    /// @notice sets authorityInitialized flag to ensure only one use of
    function _initializeAuthority(address newAuthority) internal {
        require(address(_authority) == address(0), "Auth: authority is non-zero");
        require(!_authorityInitialized, "Auth: authority already initialized");

        _authority = Authority(newAuthority);
        _authorityInitialized = true;

        emit AuthorityUpdated(address(this), Authority(newAuthority));
    }
}
IEscrow.sol 15 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.29;

interface IEscrow {
    event ProfitClaimed(uint256 profitAmount);

    function totalAssetsDeposited() external view returns (uint256);
    function totalBalance() external view returns (uint256);
    function onDeposit(uint256 assetAmount) external;
    function onWithdraw(uint256 assetAmount) external returns (uint256);
    function previewWithdraw(uint256 assetAmount) external view returns (uint256);
    function claimProfit() external;
    function onMigrateSource(address newEscrow) external;
    function onMigrateTarget(uint256 amount) external;
}
SafeERC20.sol 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 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 {
    /**
     * @dev An operation with an ERC-20 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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    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 Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 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).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
Authority.sol 9 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.29;

/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
    function canCall(address user, address target, bytes4 functionSig) external view returns (bool);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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);
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)

pragma solidity ^0.8.20;

import {Errors} from "./Errors.sol";

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @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 Errors.InsufficientBalance(address(this).balance, amount);
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert Errors.FailedCall();
        }
    }

    /**
     * @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
     * {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
        }
        (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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
     */
    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
            assembly ("memory-safe") {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert Errors.FailedCall();
        }
    }
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 *
 * _Available since v5.1._
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedCall();

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();

    /**
     * @dev A necessary precompile is missing.
     */
    error MissingPrecompile(address);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Read Contract

ASSET_TOKEN 0xd7062005 → address
BSM 0x409cfe01 → address
FEE_RECIPIENT 0xebd09054 → address
authority 0xbf7e214f → address
authorityInitialized 0x97bc1e1b → bool
feeProfit 0xdb8ea62e → uint256
previewWithdraw 0x0a28a477 → uint256
totalAssetsDeposited 0x6c63c2da → uint256
totalBalance 0xad7a672f → uint256

Write Contract 6 functions

These functions modify contract state and require a wallet transaction to execute.

claimProfit 0xf011a7af
No parameters
claimTokens 0xfe417fa5
address token
uint256 amount
onDeposit 0x8287ccb4
uint256 _assetAmount
onMigrateSource 0xbd814b6f
address _newEscrow
onMigrateTarget 0xbb53d336
uint256 _amount
onWithdraw 0x4b6d39f5
uint256 _assetAmount
returns: uint256

Recent Transactions

No transactions found for this address