Skip to content
Verified contractExactMIT

YoCcipAdapter

Address0x41e2ae2271fd724db474fd8f25012deadf2ad39f
Balance

0.010333 ETH

 

Transactions

0

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 10,000 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,588,120
Creation transaction
0x8dd061e909…d49592a7ba

src/adapters/ccip/YoCcipAdapter.sol

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

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

import { CcipClient } from "../../interfaces/external/CcipClient.sol";
import { ICcipRouterClient } from "../../interfaces/external/ICcipRouterClient.sol";
import { IYoBridgeRouteRegistry } from "../../interfaces/IYoBridgeRouteRegistry.sol";
import { IYoCcipAdapter } from "../../interfaces/IYoCcipAdapter.sol";
import { IYoRegistry } from "../../interfaces/IYoRegistry.sol";
import { YoAdapterBase } from "../base/YoAdapterBase.sol";

/// @title  YoCcipAdapter
/// @notice Immutable adapter for Chainlink CCIP token transfers. See `IYoCcipAdapter` for the
///         approval / route contract.
/// @dev    INVARIANTS:
///           - `msg.sender` is the vault when invoked via `YoVault.manage(...)`.
///           - The CCIP message payload (`data`) is always empty — token transfers only, never an
///             arbitrary cross-chain call.
///           - Funds may only leave to a route allowlisted in `routeRegistry`.
///           - The CCIP fee is paid ONLY in the native gas asset, from `msg.value`; an ERC-20/LINK
///             fee is not supported, so the fee never touches the bridged token's allowance.
///           - Each call leaks zero new balance / zero allowance to the router; the adapter forwards
///             exactly the quoted `fee`, and any native overpayment is recoverable by registered YO
///             vaults (which are payable via {Compatible}) through `rescue` / `rescueETH` (see
///             {YoAdapterBase}).
contract YoCcipAdapter is YoAdapterBase, IYoCcipAdapter {
    using SafeERC20 for IERC20;

    /// @notice The CCIP `Router` this adapter dispatches through.
    ICcipRouterClient public immutable router;

    /// @notice Allowlist of permitted `(vault, adapter, token, destChainSelector, recipient)` routes.
    IYoBridgeRouteRegistry public immutable routeRegistry;

    constructor(
        ICcipRouterClient _router,
        IYoBridgeRouteRegistry _routeRegistry,
        IYoRegistry _yoRegistry
    )
        YoAdapterBase(_yoRegistry)
    {
        router = _router;
        routeRegistry = _routeRegistry;
    }

    /// @inheritdoc IYoCcipAdapter
    function send(
        uint64 destinationChainSelector,
        bytes32 recipient,
        address token,
        uint256 amount,
        uint256 maxFee,
        bytes calldata extraArgs
    )
        external
        payable
        nonReentrant
        returns (bytes32 messageId)
    {
        if (amount == 0) {
            revert InvalidAmount();
        }
        address vault = msg.sender;
        // CCIP delivers the same token it transfers, so no output token is pinned (`bytes32(0)`).
        if (!routeRegistry.isRouteAllowed(vault, address(this), token, destinationChainSelector, recipient, bytes32(0)))
        {
            revert RouteNotAllowed(token, destinationChainSelector, recipient);
        }
        // Delivery truncates `recipient` to an EVM address; reject dirty high bits so the route check
        // cannot pass for a recipient that differs from where funds actually land.
        if (uint256(recipient) >> 160 != 0) {
            revert RecipientNotEvmAddress(recipient);
        }

        CcipClient.EVM2AnyMessage memory message = _buildMessage(recipient, token, amount, extraArgs);

        uint256 fee = router.getFee(destinationChainSelector, message);
        if (fee > maxFee) {
            revert FeeExceedsMax(fee, maxFee);
        }
        // Native-only fee, forwarded from `msg.value`; overpayment stays recoverable via `rescueETH`.
        if (msg.value < fee) {
            revert IncorrectNativeFee(msg.value, fee);
        }

        IERC20(token).safeTransferFrom(vault, address(this), amount);
        IERC20(token).forceApprove(address(router), amount);

        messageId = router.ccipSend{ value: fee }(destinationChainSelector, message);

        IERC20(token).forceApprove(address(router), 0);

        _emitAction(address(router), token, AdapterDirection.Bridge, amount);
    }

    /// @dev Assemble the token-only CCIP message: empty payload, single token leg, EVM recipient,
    ///      native fee (`feeToken == address(0)`).
    function _buildMessage(
        bytes32 recipient,
        address token,
        uint256 amount,
        bytes calldata extraArgs
    )
        private
        pure
        returns (CcipClient.EVM2AnyMessage memory message)
    {
        CcipClient.EVMTokenAmount[] memory tokenAmounts = new CcipClient.EVMTokenAmount[](1);
        tokenAmounts[0] = CcipClient.EVMTokenAmount({ token: token, amount: amount });

        message = CcipClient.EVM2AnyMessage({
            receiver: abi.encode(address(uint160(uint256(recipient)))),
            data: "",
            tokenAmounts: tokenAmounts,
            feeToken: address(0),
            extraArgs: extraArgs
        });
    }
}

node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

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);
}

node_modules/@openzeppelin/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

node_modules/@openzeppelin/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";

node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.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);
}

node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.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 {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @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 {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 relies 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 relies 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}.
     * Oppositely, 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 `token.transfer(to, value)` call, 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 to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}

node_modules/@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuardTransient.sol)

pragma solidity ^0.8.24;

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

/**
 * @dev Variant of {ReentrancyGuard} that uses transient storage.
 *
 * NOTE: This variant only works on networks where EIP-1153 is available.
 *
 * _Available since v5.1._
 *
 * @custom:stateless
 */
abstract contract ReentrancyGuardTransient {
    using TransientSlot for *;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    /**
     * @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();
    }

    /**
     * @dev A `view` only version of {nonReentrant}. Use to block view functions
     * from being called, preventing reading from inconsistent contract state.
     *
     * CAUTION: This is a "view" modifier and does not change the reentrancy
     * status. Use it only on view functions. For payable or non-payable functions,
     * use the standard {nonReentrant} modifier instead.
     */
    modifier nonReentrantView() {
        _nonReentrantBeforeView();
        _;
    }

    function _nonReentrantBeforeView() private view {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, REENTRANCY_GUARD_STORAGE.asBoolean().tload() will be false
        _nonReentrantBeforeView();

        // Any calls to nonReentrant after this point will fail
        _reentrancyGuardStorageSlot().asBoolean().tstore(true);
    }

    function _nonReentrantAfter() private {
        _reentrancyGuardStorageSlot().asBoolean().tstore(false);
    }

    /**
     * @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 _reentrancyGuardStorageSlot().asBoolean().tload();
    }

    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
        return REENTRANCY_GUARD_STORAGE;
    }
}

node_modules/@openzeppelin/contracts/utils/TransientSlot.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.

pragma solidity ^0.8.24;

/**
 * @dev Library for reading and writing value-types to specific transient storage slots.
 *
 * Transient slots are often used to store temporary values that are removed after the current transaction.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 *  * Example reading and writing values using transient storage:
 * ```solidity
 * contract Lock {
 *     using TransientSlot for *;
 *
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
 *
 *     modifier locked() {
 *         require(!_LOCK_SLOT.asBoolean().tload());
 *
 *         _LOCK_SLOT.asBoolean().tstore(true);
 *         _;
 *         _LOCK_SLOT.asBoolean().tstore(false);
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library TransientSlot {
    /**
     * @dev UDVT that represents a slot holding an address.
     */
    type AddressSlot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a AddressSlot.
     */
    function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
        return AddressSlot.wrap(slot);
    }

    /**
     * @dev UDVT that represents a slot holding a bool.
     */
    type BooleanSlot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a BooleanSlot.
     */
    function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
        return BooleanSlot.wrap(slot);
    }

    /**
     * @dev UDVT that represents a slot holding a bytes32.
     */
    type Bytes32Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Bytes32Slot.
     */
    function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
        return Bytes32Slot.wrap(slot);
    }

    /**
     * @dev UDVT that represents a slot holding a uint256.
     */
    type Uint256Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Uint256Slot.
     */
    function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
        return Uint256Slot.wrap(slot);
    }

    /**
     * @dev UDVT that represents a slot holding a int256.
     */
    type Int256Slot is bytes32;

    /**
     * @dev Cast an arbitrary slot to a Int256Slot.
     */
    function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
        return Int256Slot.wrap(slot);
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(AddressSlot slot) internal view returns (address value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(AddressSlot slot, address value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(BooleanSlot slot) internal view returns (bool value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(BooleanSlot slot, bool value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Bytes32Slot slot, bytes32 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Uint256Slot slot) internal view returns (uint256 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Uint256Slot slot, uint256 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }

    /**
     * @dev Load the value held at location `slot` in transient storage.
     */
    function tload(Int256Slot slot) internal view returns (int256 value) {
        assembly ("memory-safe") {
            value := tload(slot)
        }
    }

    /**
     * @dev Store `value` at location `slot` in transient storage.
     */
    function tstore(Int256Slot slot, int256 value) internal {
        assembly ("memory-safe") {
            tstore(slot, value)
        }
    }
}

node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @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);
}

src/adapters/base/YoAdapterBase.sol

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

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";

import { IYoRegistry } from "../../interfaces/IYoRegistry.sol";

/// @title  YoAdapterBase
/// @notice Shared base for every YO adapter: the `rescue` / `rescueETH` recovery surface and the
///         canonical `nonReentrant` guard.
/// @dev    INVARIANTS:
///           - No admin keys, no upgrade path.
///           - `rescue` / `rescueETH` are callable only by a *currently*-registered YO vault (per the
///             immutable `YoRegistry.isYoVault`) and always send to `msg.sender` — no caller-controlled
///             destination, so a removed vault loses rescue rights and the path cannot be redirected.
///           - Rescue shares the adapters' reentrancy guard, so no cross-method reentry is possible.
abstract contract YoAdapterBase is ReentrancyGuardTransient {
    using SafeERC20 for IERC20;

    /// @notice Registry consulted to validate rescue callers. Immutable for the lifetime of the
    ///         adapter; if a new registry is ever needed, redeploy.
    IYoRegistry public immutable yoRegistry;

    /// @notice Basis-points denominator (100% == 10_000). Shared by adapters that cap fees or floor
    ///         slippage against a bps bound.
    uint256 internal constant BPS_DENOMINATOR = 10_000;

    error CallerNotYoVault(address caller);
    error ZeroRegistry();
    error EthTransferFailed();

    /// @notice Emitted on every successful `rescue(IERC20)`. `amount == 0` is permitted and emits.
    event Rescued(address indexed token, address indexed to, uint256 amount);
    /// @notice Emitted on every successful `rescueETH()`. `amount == 0` is permitted and emits.
    event RescuedETH(address indexed to, uint256 amount);

    /// @notice Direction of value flow relative to the calling vault.
    /// @dev    `Deposit` = vault → external protocol; `Withdraw` = external protocol → vault;
    ///         `Bridge` = vault → another chain (funds leave this chain and do not return to the
    ///         vault here). New variants are appended so existing ordinals stay stable for off-chain
    ///         decoders. `YoSwapAdapter` does not emit `AdapterAction`; it has its own `SwapAction`
    ///         event that captures both legs of an exchange in a single log.
    enum AdapterDirection {
        Deposit,
        Withdraw,
        Bridge
    }

    /// @notice Vault-level audit signal emitted by every adapter operation. Lets off-chain
    ///         monitoring reconstruct strategy actions without parsing each external protocol's logs.
    /// @param  vault     The calling YO vault (always `msg.sender` for adapter entrypoints).
    /// @param  target    The external protocol contract the adapter interacted with.
    /// @param  asset     The ERC-20 token whose movement defines this leg of the action.
    /// @param  direction Inflow or outflow relative to the vault.
    /// @param  amount    Quantity of `asset` in its native decimals.
    event AdapterAction(
        address indexed vault,
        address indexed target,
        address indexed asset,
        AdapterDirection direction,
        uint256 amount
    );

    constructor(IYoRegistry _yoRegistry) {
        if (address(_yoRegistry) == address(0)) {
            revert ZeroRegistry();
        }
        yoRegistry = _yoRegistry;
    }

    /// @dev Restricts the caller to a currently-registered YO vault. Applied to `rescue` /
    ///      `rescueETH`; child adapters' per-protocol methods are gated by their own allowlists
    ///      and do not use this modifier.
    modifier onlyYoVault() {
        if (!yoRegistry.isYoVault(msg.sender)) {
            revert CallerNotYoVault(msg.sender);
        }
        _;
    }

    /// @notice Sweep this adapter's full balance of `token` to the calling vault. Callable only by
    ///         a currently-registered YO vault.
    /// @return amount The token balance transferred.
    function rescue(IERC20 token) external nonReentrant onlyYoVault returns (uint256 amount) {
        amount = token.balanceOf(address(this));
        if (amount != 0) {
            token.safeTransfer(msg.sender, amount);
        }
        emit Rescued(address(token), msg.sender, amount);
    }

    /// @dev Emit an `AdapterAction` log keyed on `msg.sender` (the calling vault). Used by every
    ///      adapter at the point a deposit / withdraw / swap leg completes.
    function _emitAction(address target, address asset, AdapterDirection direction, uint256 amount) internal {
        emit AdapterAction(msg.sender, target, asset, direction, amount);
    }

    /// @dev `amount * bps / BPS_DENOMINATOR`. Shared by adapter fee caps and slippage floors (pass
    ///      `BPS_DENOMINATOR - slippageBps` for a floor).
    function _applyBps(uint256 amount, uint256 bps) internal pure returns (uint256) {
        return (amount * bps) / BPS_DENOMINATOR;
    }

    /// @notice Sweep this adapter's full ETH balance to the calling vault. Callable only by a
    ///         currently-registered YO vault.
    /// @return amount The ETH amount transferred.
    function rescueETH() external nonReentrant onlyYoVault returns (uint256 amount) {
        amount = address(this).balance;
        if (amount != 0) {
            (bool ok,) = payable(msg.sender).call{ value: amount }("");
            if (!ok) {
                revert EthTransferFailed();
            }
        }
        emit RescuedETH(msg.sender, amount);
    }
}

src/interfaces/IYoBridgeRouteRegistry.sol

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

/// @notice Per-vault allowlist of cross-chain destinations reachable through the YO bridge adapters
///         (`YoAcrossAdapter`, `YoCcipAdapter`, `YoCctpAdapter`).
/// @dev    Bridges are the only adapters that move value OFF the current chain to a recipient
///         elsewhere, so the usual "funds return to the vault" invariant does not apply. This
///         registry is the on-chain destination floor: an adapter may only let `vault` send `token`
///         to `(destinationId, recipient)` if the multisig has explicitly allowlisted that route.
///
///         A route is keyed on six fields:
///           - `vault`         — the calling YO vault.
///           - `adapter`       — the bridge adapter (`address(this)` inside the adapter). Namespaces
///                               routes per bridge so an Across route for chainId 8453 can never be
///                               reused as a CCTP route for domain 8453.
///           - `token`         — the asset leaving the chain (e.g. USDC).
///           - `destinationId` — the bridge's native destination identifier, widened to `uint256`
///                               (Across chainId, CCIP chain selector, CCTP domain).
///           - `recipient`     — the destination recipient, widened to `bytes32` (an EVM address is
///                               left-padded to 32 bytes).
///           - `outputToken`   — the destination-chain token the adapter presents, widened to
///                               `bytes32`. Adapters where the operator names the delivered token
///                               (Across `outputToken`, Mayan order `tokenOut`) pass it here so the
///                               multisig pins the destination asset's identity; adapters where the
///                               protocol fixes the output (CCIP, CCTP) pass `bytes32(0)`.
interface IYoBridgeRouteRegistry {
    event RouteSet(
        address indexed vault,
        address indexed adapter,
        address indexed token,
        uint256 destinationId,
        bytes32 recipient,
        bytes32 outputToken,
        bool allowed
    );

    error ZeroAddress();
    error RenounceDisabled();

    /// @notice Allow or disallow a single bridge route. Owner-only.
    /// @param vault         The YO vault the route applies to.
    /// @param adapter       The bridge adapter that will consult this route.
    /// @param token         The asset being bridged.
    /// @param destinationId The bridge's destination identifier, widened to `uint256`.
    /// @param recipient     The destination recipient, widened to `bytes32`.
    /// @param outputToken   The pinned destination token, widened to `bytes32` (`0` when unpinned).
    /// @param allowed       `true` to allow the route, `false` to revoke it.
    function setRoute(
        address vault,
        address adapter,
        address token,
        uint256 destinationId,
        bytes32 recipient,
        bytes32 outputToken,
        bool allowed
    )
        external;

    /// @notice Whether `vault` may bridge `token` to `(destinationId, recipient)` delivering
    ///         `outputToken` via `adapter`.
    /// @dev    Defaults to `false` for every unset route.
    function isRouteAllowed(
        address vault,
        address adapter,
        address token,
        uint256 destinationId,
        bytes32 recipient,
        bytes32 outputToken
    )
        external
        view
        returns (bool);
}

src/interfaces/IYoCcipAdapter.sol

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

/// @notice Immutable adapter that brokers Chainlink CCIP token transfers on behalf of a vault.
/// @dev    Functions are intended to be invoked exclusively via `YoVault.manage(...)` so that
///         `msg.sender == vault` inside the adapter. Token transfers only — the CCIP message
///         payload is forced empty, so vault funds can never trigger an arbitrary cross-chain call.
///
///         SAFETY: a send moves funds off-chain, so the destination is constrained by
///         `YoBridgeRouteRegistry` — `(vault, adapter, token, destinationChainSelector, recipient)`
///         must be allowlisted by the multisig. `destinationChainSelector` is the CCIP-specific
///         chain id. The quoted fee is capped at the operator's `maxFee`.
///
///         FEES: paid ONLY in the native gas asset, forwarded as `msg.value` from `YoVault.manage`.
///         An ERC-20/LINK fee is not supported — this keeps the fee off the bridged token's allowance
///         and out of the vault's ERC-20 approvals.
///
///         APPROVAL FLOW: the vault approves the adapter on the bridged `token`
///         (`vault.approveToken(token, adapter, cap)`); the native fee is sent as `msg.value`.
interface IYoCcipAdapter {
    error InvalidAmount();
    error RouteNotAllowed(address token, uint64 destinationChainSelector, bytes32 recipient);
    error FeeExceedsMax(uint256 fee, uint256 maxFee);
    error IncorrectNativeFee(uint256 sent, uint256 required);
    /// @dev `recipient` has non-zero bits above 160 — it is not a left-padded EVM address, but the
    ///      CCIP message delivers to the truncated `address(uint160(...))`. Reject to fail closed.
    error RecipientNotEvmAddress(bytes32 recipient);

    /// @notice Send `amount` of `token` to `recipient` on `destinationChainSelector` via CCIP, paying
    ///         the CCIP fee in the native gas asset from `msg.value`.
    /// @dev    Reverts unless the `(token, destinationChainSelector, recipient)` route is allowlisted
    ///         for the calling vault, or if the quoted fee exceeds `maxFee`.
    /// @param destinationChainSelector CCIP chain selector of the destination chain.
    /// @param recipient                Destination recipient (allowlisted route), as `bytes32`.
    /// @param token                    Token to bridge.
    /// @param amount                   Amount of `token` to bridge.
    /// @param maxFee                   Maximum acceptable CCIP fee (in the native asset).
    /// @param extraArgs                Operator-supplied CCIP `extraArgs` (e.g. `GenericExtraArgsV2`).
    /// @return messageId The CCIP message id.
    function send(
        uint64 destinationChainSelector,
        bytes32 recipient,
        address token,
        uint256 amount,
        uint256 maxFee,
        bytes calldata extraArgs
    )
        external
        payable
        returns (bytes32 messageId);
}

src/interfaces/IYoRegistry.sol

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

interface IYoRegistry {
    event YoVaultAdded(address indexed asset, address indexed vault);
    event YoVaultRemoved(address indexed asset, address indexed vault);

    /// @notice Checks if an address is a valid YO vault
    /// @param vaultAddress Vault address to be added
    function isYoVault(address vaultAddress) external view returns (bool);

    /// @notice Registers a YO vault
    /// @param vaultAddress YO vault address to be added
    function addYoVault(address vaultAddress) external;

    /// @notice Removes YO vault registration
    /// @param vaultAddress YO vault address to be removed
    function removeYoVault(address vaultAddress) external;

    /// @notice Returns a list of all registered YO vaults
    function listYoVaults() external view returns (address[] memory);
}

src/interfaces/external/CcipClient.sol

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

/// @notice Minimal vendored subset of Chainlink CCIP's `Client` library — only the message types
///         and the latest `GenericExtraArgsV2` encoding the YO CCIP adapter needs.
/// @dev    Renamed from Chainlink's `Client` to `CcipClient` to avoid a generic name collision.
///         `extraArgs` is built off-chain by the operator and passed through verbatim, so callers
///         that want a typed builder can use `_argsToBytes`; the adapter never decodes it.
library CcipClient {
    /// @notice A token + amount leg of a CCIP message.
    struct EVMTokenAmount {
        address token;
        uint256 amount;
    }

    /// @notice CCIP message dispatched from an EVM source chain to any destination chain.
    /// @param receiver     Destination recipient, abi-encoded (an EVM address is `abi.encode`d).
    /// @param data         Arbitrary payload for a destination contract. YO sends none.
    /// @param tokenAmounts Tokens transferred with the message.
    /// @param feeToken     Fee token; `address(0)` pays the fee in the native gas token.
    /// @param extraArgs    Versioned extra arguments (see `GenericExtraArgsV2`).
    struct EVM2AnyMessage {
        bytes receiver;
        bytes data;
        EVMTokenAmount[] tokenAmounts;
        address feeToken;
        bytes extraArgs;
    }

    /// @dev Selector tag prefixing `GenericExtraArgsV2`-encoded `extraArgs`.
    bytes4 public constant GENERIC_EXTRA_ARGS_V2_TAG = 0x181dcf10;

    /// @notice Latest extra-args shape for CCIP messages.
    /// @param gasLimit                 Gas for the destination `ccipReceive`; `0` for EOA transfers.
    /// @param allowOutOfOrderExecution Whether the message may execute out of order.
    struct GenericExtraArgsV2 {
        uint256 gasLimit;
        bool allowOutOfOrderExecution;
    }

    /// @notice Encode `GenericExtraArgsV2` into the tagged `extraArgs` bytes CCIP expects.
    function _argsToBytes(GenericExtraArgsV2 memory extraArgs) internal pure returns (bytes memory) {
        return abi.encodeWithSelector(GENERIC_EXTRA_ARGS_V2_TAG, extraArgs);
    }
}

src/interfaces/external/ICcipRouterClient.sol

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

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

/// @notice Minimal interface for the Chainlink CCIP `Router`, the source-chain entrypoint for
///         cross-chain token transfers and messages.
/// @dev    Quote the fee with `getFee`, approve the router for the token leg (and the fee token if
///         not native), then dispatch with `ccipSend`. A native fee is sent as `msg.value`.
interface ICcipRouterClient {
    /// @notice Quote the fee (in `message.feeToken`, or the native token if `feeToken == address(0)`)
    ///         for sending `message` to `destinationChainSelector`.
    function getFee(
        uint64 destinationChainSelector,
        CcipClient.EVM2AnyMessage memory message
    )
        external
        view
        returns (uint256 fee);

    /// @notice Dispatch `message` to `destinationChainSelector`, returning the CCIP message id.
    /// @dev    Payable: when `message.feeToken == address(0)` the fee is paid from `msg.value`.
    function ccipSend(
        uint64 destinationChainSelector,
        CcipClient.EVM2AnyMessage calldata message
    )
        external
        payable
        returns (bytes32 messageId);
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 10000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
    "forge-std/=node_modules/forge-std/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.