Skip to content
Verified contractExactMIT

SKChainflipVault4626_V4

Address0x96d9f81eff91e6101eeeaee53a270ca28f97ad1b
Balance

0 ETH

 

Transactions

7

 

Compiler

solc 0.8.22

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.22+commit.4fc1097e
Language
solidity
Optimization
Yes, 200 runs
EVM version
shanghai
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,293,882
Creation transaction
0x52b831a460…be4940b8fb

project/src/contracts/aggregators/chainflip/SKChainflipVault4626_V4.sol

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

import {Owners} from "../../../lib/Owners.sol";
import {SafeTransferLib} from "../../../lib/SafeTransferLib.sol";
import {IChainflipReceiver} from "../../../interfaces/IChainflipReceiver.sol";
import {IERC4626} from "../../../interfaces/IERC4626.sol";
import {IBlockList, IBlockListedVault} from "../../../interfaces/IBlockList.sol";
import {IERC20} from "../../../interfaces/IERC20.sol";
import {SKAggregator_V1} from "../../abstract/SKAggregator_V1.sol";
import {SKChainflipAggregator_V1} from "../../abstract/SKChainflipAggregator_V1.sol";

/// @title SKChainflipVault4626_V4
/// @notice Chainflip CCM <-> Kiln ERC-4626 vault aggregator (Ledger "Swap to Earn").
/// @dev DEPOSIT (earn): Chainflip swaps any asset -> USDC/USDT and delivers it to this
///      contract with a CCM `message`; `cfReceive` decodes {vault, recipient, minShares}
///      and deposits into the ERC-4626 vault, minting shares directly to the recipient.
/// @dev The `cfReceive` path is deliberately NON-REVERTING: a revert on the Chainflip
///      callback would strand user funds, so on any failure funds are swept to the
///      recipient (or `lostFundsCollector` when the payload can't be decoded). This
///      mirrors the professional-engineer-authored `cf-evm-agg/Receiver.sol` reference.
/// @dev DEPOSIT-ONLY. V3 removed the entire withdraw leg at Kiln's request:
///      there is no `redeemAndSwapOut`, no `redeemAndSwapOutWithPermit2`, and no code path
///      that pulls vault shares (or any other token) from a user. Users exit by calling
///      `redeem`/`withdraw` on the Kiln vault directly. The only token movement this
///      contract performs is on assets Chainflip has already delivered to it.
/// @dev NEW IN V4: the share recipient is checked against the vault's own blocklist before
///      any deposit is attempted. Kiln's `deposit` does not check its `receiver` against
///      `blockList()`, so without this a blocked address could still be minted shares
///      through this aggregator. When the recipient is blocked the deposit does not happen,
///      the vault is never called, and the delivered stablecoin is forwarded to the
///      recipient as it is on every other failure path - the asset is not Kiln's to
///      withhold and `cfReceive` must not revert. See `_isRecipientBlocked` for the policy
///      when the registry cannot be read.
/// @dev Inherited from V2: the spending allowance granted to the vault is cleared after the
///      deposit, so a vault that pulls less than it was approved for leaves no standing
///      allowance behind (PeckShield PVE-001). V1, V2 and V3 are unchanged and stay deployed;
///      see audits/PeckShield-Audit-Report-Swapkit-ChainflipVault-v1.0rc.pdf.
/// @dev `tokenTransferProxy` / `permit2` are inherited from SKAggregator_V1 and are left
///      UNSET on this contract: nothing in V4 reads them, and it is deliberately not
///      registered as a TokenTransferProxy executor.
contract SKChainflipVault4626_V4 is
    Owners,
    IChainflipReceiver,
    SKAggregator_V1,
    SKChainflipAggregator_V1
{
    using SafeTransferLib for address;

    /// @dev Address Chainflip uses to signal the native asset.
    address private constant _CF_NATIVE_ADDR =
        0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    /// @notice CCM payload delivered on the source chain and decoded on arrival.
    /// @param vault The ERC-4626 vault to deposit the delivered asset into.
    /// @param recipient Address that receives the minted vault shares.
    /// @param minShares Slippage guard: minimum shares that must be minted.
    struct CCMVaultDeposit {
        address vault;
        address recipient;
        uint256 minShares;
    }

    /// @notice Catch-all recipient when there is no valid user address (undecodable payload).
    address public lostFundsCollector;

    /// @notice Owner-managed vault allowlist (defense-in-depth on top of the asset() check).
    mapping(address => bool) public allowedVaults;

    /// @notice When true, deposits only succeed into allowlisted vaults.
    bool public enforceVaultAllowlist;

    event VaultDeposit(
        uint32 srcChain,
        bytes srcAddress,
        address indexed vault,
        address indexed recipient,
        address token,
        uint256 amount,
        uint256 sharesMinted
    );
    event VaultDepositFallback(
        address indexed recipient,
        address token,
        uint256 amount,
        string reason
    );
    event SweptFunds(address indexed to, address token, uint256 amount);
    event VaultAllowed(address indexed vault, bool allowed);
    event EnforceVaultAllowlistSet(bool enforced);
    event LostFundsCollectorSet(address indexed collector);

    /// @notice CREATE2-compatible constructor.
    /// @dev TTP / Permit2 are set post-deployment via setters (chain-specific).
    /// @param _feeRecipient Address to receive protocol fees (cross-chain constant).
    /// @param _cfVault Chainflip Vault address (can be updated via `updateCfVault`).
    /// @param _lostFundsCollector Catch-all for undecodable-payload funds.
    constructor(
        address _feeRecipient,
        address _cfVault,
        address _lostFundsCollector
    )
        SKAggregator_V1(address(0), _feeRecipient)
        SKChainflipAggregator_V1(_cfVault)
    {
        _setOwner(tx.origin, true);
        require(_lostFundsCollector != address(0), "invalid collector");
        lostFundsCollector = _lostFundsCollector;
        enforceVaultAllowlist = true;
    }

    //////////////////////////////////////////////////////////////
    //                    Chainflip receiver                    //
    //////////////////////////////////////////////////////////////

    /// @notice Chainflip CCM entry point. Only callable by the Chainflip Vault.
    /// @dev For ERC-20, Chainflip transfers `amount` of `token` to this contract before the call.
    /// @param srcChain Source chain id (provenance only).
    /// @param srcAddress Source address (provenance only).
    /// @param message ABI-encoded `CCMVaultDeposit`.
    /// @param token The delivered token (USDC/USDT), or the native sentinel.
    /// @param amount The delivered amount.
    function cfReceive(
        uint32 srcChain,
        bytes calldata srcAddress,
        bytes calldata message,
        address token,
        uint256 amount
    ) external payable onlyCfVault nonReentrant {
        token = token == _CF_NATIVE_ADDR ? address(0) : token;

        // The asset is already in the contract; snapshot the pre-delivery balance.
        uint256 initialBalance = _getAssetBalance(token) - amount;

        // Non-reverting decode: bad payloads route funds to the lostFundsCollector.
        CCMVaultDeposit memory dep;
        try this.decodeMessage(message) returns (CCMVaultDeposit memory _dep) {
            dep = _dep;
        } catch {
            _sweepFunds(token, lostFundsCollector, amount);
            emit VaultDepositFallback(lostFundsCollector, token, amount, "decode");
            return;
        }

        address dest = dep.recipient == address(0) ? lostFundsCollector : dep.recipient;

        // Blocklist gate (V4). The vault's `deposit` does not screen its `receiver`, so the
        // check belongs here. A blocked recipient means the vault is never called at all;
        // the delivered stablecoin is forwarded on to them unchanged.
        if (_isRecipientBlocked(dep.vault, dest)) {
            _sweepFunds(token, dest, amount);
            emit VaultDepositFallback(dest, token, amount, "blocked");
            return;
        }

        // Attempt the vault deposit in a try/catch so a failure never reverts the callback.
        try this._depositToVault(dep.vault, token, amount, dest, dep.minShares) returns (
            uint256 sharesMinted
        ) {
            emit VaultDeposit(srcChain, srcAddress, dep.vault, dest, token, amount, sharesMinted);
        } catch {
            // The deposit (incl. fee transfer) rolled back; refund the full delivered amount.
            _sweepFunds(token, dest, amount);
            emit VaultDepositFallback(dest, token, amount, "deposit");
        }

        // Safety net: sweep any residual delivered asset back to the recipient.
        uint256 finalBalance = _getAssetBalance(token);
        if (finalBalance > initialBalance) {
            _sweepFunds(token, dest, finalBalance - initialBalance);
        }
    }

    /// @notice Fee + approve + ERC-4626 deposit. External so `cfReceive` can try/catch it.
    /// @dev Self-only: pulling from the contract balance for an arbitrary receiver would
    ///      otherwise be an open drain of any stuck funds.
    function _depositToVault(
        address vault,
        address token,
        uint256 amount,
        address recipient,
        uint256 minShares
    ) external returns (uint256 sharesMinted) {
        require(msg.sender == address(this), "only self");
        require(IERC4626(vault).asset() == token, "vault asset mismatch");
        if (enforceVaultAllowlist) {
            require(allowedVaults[vault], "vault not allowed");
        }

        uint256 depositAmount = takeFee(token, amount);

        // zero-first approval for USDT-like tokens
        token.safeApprove(vault, 0);
        token.safeApprove(vault, depositAmount);
        sharesMinted = IERC4626(vault).deposit(depositAmount, recipient);
        _clearAllowance(token, vault);

        require(sharesMinted >= minShares, "insufficient shares");
    }

    /// @notice Decode the CCM message. External + pure so `cfReceive` can try/catch it.
    function decodeMessage(
        bytes calldata message
    ) public pure returns (CCMVaultDeposit memory) {
        return abi.decode(message, (CCMVaultDeposit));
    }

    //////////////////////////////////////////////////////////////
    //                    Governance & Getters                  //
    //////////////////////////////////////////////////////////////

    function setVaultAllowed(address vault, bool allowed) external isOwner {
        allowedVaults[vault] = allowed;
        emit VaultAllowed(vault, allowed);
    }

    function setEnforceVaultAllowlist(bool enforced) external isOwner {
        enforceVaultAllowlist = enforced;
        emit EnforceVaultAllowlistSet(enforced);
    }

    function setLostFundsCollector(address _lostFundsCollector) external isOwner {
        require(_lostFundsCollector != address(0), "invalid collector");
        lostFundsCollector = _lostFundsCollector;
        emit LostFundsCollectorSet(_lostFundsCollector);
    }

    //////////////////////////////////////////////////////////////
    //                        Utilities                         //
    //////////////////////////////////////////////////////////////

    /// @notice Whether `recipient` is blocked by the registry that `vault` points at.
    /// @dev Deliberately built out of raw staticcalls rather than `try`/`catch`: `cfReceive`
    ///      must never revert, and a `try` on a typed call still reverts in THIS contract
    ///      when the callee's return data fails to decode. Nothing below can revert.
    /// @dev Policy when the registry cannot be read:
    ///      - the vault exposes no `blockList()`, or it returns the zero address -> there is
    ///        no blocklist to enforce and the deposit proceeds (fail OPEN on absence);
    ///      - a registry IS configured but will not give a clean answer -> the recipient is
    ///        treated as blocked (fail CLOSED on an unreadable answer). Being wrong that way
    ///        costs the user nothing but the yield: they keep the delivered stablecoin.
    function _isRecipientBlocked(
        address vault,
        address recipient
    ) internal view returns (bool) {
        (bool ok, bytes memory ret) = vault.staticcall(
            abi.encodeWithSelector(IBlockListedVault.blockList.selector)
        );
        if (!ok || ret.length < 32) return false;

        address registry = address(uint160(uint256(_firstWord(ret))));
        if (registry == address(0)) return false;

        (ok, ret) = registry.staticcall(
            abi.encodeWithSelector(IBlockList.isBlocked.selector, recipient)
        );
        if (!ok || ret.length < 32) return true;

        return _firstWord(ret) != bytes32(0);
    }

    /// @dev First 32-byte word of `data`, or zero when it is shorter than a word. Used in
    ///      place of `abi.decode`, which reverts on a malformed encoding (a dirty address,
    ///      a non-canonical bool) - and the blocklist read must not be able to revert.
    function _firstWord(bytes memory data) private pure returns (bytes32 word) {
        if (data.length < 32) return bytes32(0);
        assembly {
            word := mload(add(data, 32))
        }
    }

    /// @dev Reset a spender's allowance to zero when it did not consume all of it.
    /// @dev An ERC-4626 vault or the Chainflip Vault normally pulls the exact amount it was
    ///      approved for, leaving nothing behind; one that pulls less (a deposit cap, a
    ///      fee-on-transfer underlying) would otherwise leave a standing allowance. The
    ///      read is a warm SLOAD on the slot just written, so the common zero case costs far
    ///      less than an unconditional `approve(0)`.
    function _clearAllowance(address token, address spender) internal {
        if (IERC20(token).allowance(address(this), spender) != 0) {
            token.safeApprove(spender, 0);
        }
    }

    function _getAssetBalance(address token) internal view returns (uint256) {
        return token == address(0) ? address(this).balance : IERC20(token).balanceOf(address(this));
    }

    function _sweepFunds(address token, address to, uint256 amount) internal {
        if (amount == 0) return;
        if (token == address(0)) {
            to.safeTransferETH(amount);
        } else {
            token.safeTransfer(to, amount);
        }
        emit SweptFunds(to, token, amount);
    }
}

project/src/contracts/abstract/SKAggregator_V1.sol

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

import {SafeTransferLib} from "../../lib/SafeTransferLib.sol";
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
import {Owners} from "../../lib/Owners.sol";
import {SKTokenTransferProxy} from "../misc/SKTokenTransferProxy.sol";
import {IERC20} from "../../interfaces/IERC20.sol";
import {IPermit2} from "../../interfaces/IPermit2.sol";

abstract contract SKAggregator_V1 is Owners, ReentrancyGuard {
    using SafeTransferLib for address;

    event FeeSet(uint256 fee, address feeRecipient);

    uint256 public fee;
    address public feeRecipient;
    SKTokenTransferProxy public tokenTransferProxy;
    address public permit2;

    constructor(address _tokenTransferProxy, address _feeRecipient) {
        _setOwner(tx.origin, true);
        tokenTransferProxy = SKTokenTransferProxy(_tokenTransferProxy);
        feeRecipient = _feeRecipient;
    }

    // Needed for the swap router to be able to send back ETH
    receive() external payable {}

    function setFee(uint256 _fee, address _feeRecipient) external isOwner {
        require(_fee <= 1000, "fee can not be more than 10%");
        fee = _fee;
        feeRecipient = _feeRecipient;
        emit FeeSet(_fee, _feeRecipient);
    }

    /// @dev Take fee from amount, handles both gas (asset = address(0)) and tokens
    /// @param asset The asset address (address(0) for native gas asset)
    /// @param amount The amount to take fee from
    /// @return Amount after fee deduction
    function takeFee(address asset, uint256 amount) internal returns (uint256) {
        uint256 amountFee = getFee(amount);
        if (amountFee > 0) {
            if (asset == address(0)) {
                feeRecipient.safeTransferETH(amountFee);
            } else {
                asset.safeTransfer(feeRecipient, amountFee);
            }
            amount -= amountFee;
        }
        return amount;
    }

    /// @dev Take fee with custom fee basis points and recipient
    /// @param asset The asset address (address(0) for native gas asset)
    /// @param amount The amount to take fee from
    /// @param feeBps Fee in basis points (1 = 0.01%, 100 = 1%)
    /// @param recipient Address to receive the fee
    /// @return Amount after fee deduction
    function takeFee(
        address asset,
        uint256 amount,
        uint256 feeBps,
        address recipient
    ) internal returns (uint256) {
        if (feeBps == 0 || recipient == address(0)) {
            return amount;
        }
        uint256 feeAmount = (amount * feeBps) / 10000;
        if (feeAmount > 0) {
            if (asset == address(0)) {
                recipient.safeTransferETH(feeAmount);
            } else {
                asset.safeTransfer(recipient, feeAmount);
            }
            amount -= feeAmount;
        }
        return amount;
    }

    function getFee(uint256 amount) internal view returns (uint256) {
        if (fee != 0) {
            return (amount * fee) / 10000;
        }
        return 0;
    }

    /// @notice Set TokenTransferProxy address (one-time, for CREATE2 compatibility)
    /// @dev Can only be called if TTP was not set in constructor (address(0))
    function setTokenTransferProxy(address _ttp) external isOwner {
        require(address(tokenTransferProxy) == address(0), "TTP already set");
        require(_ttp != address(0), "Invalid TTP");
        tokenTransferProxy = SKTokenTransferProxy(_ttp);
    }

    /// @notice Set Permit2 address (one-time, for CREATE2 compatibility)
    /// @dev Permit2 canonical address: 0x000000000022D473030F116dDEE9F6B43aC78BA3
    function setPermit2(address _permit2) external isOwner {
        require(permit2 == address(0), "Permit2 already set");
        require(_permit2 != address(0), "Invalid Permit2");
        permit2 = _permit2;
    }

    /// @dev Pull tokens from user via TTP, returns actual amount received
    /// @dev Handles fee-on-transfer tokens by checking balance difference
    function _pullTokens(
        address token,
        address from,
        uint256 amount
    ) internal returns (uint256 received) {
        uint256 balanceBefore = IERC20(token).balanceOf(address(this));
        tokenTransferProxy.transferTokens(token, from, address(this), amount);
        received = IERC20(token).balanceOf(address(this)) - balanceBefore;
    }

    /// @dev Pull tokens from user via Permit2, returns actual amount received
    /// @dev Handles fee-on-transfer tokens by checking balance difference
    function _pullTokensWithPermit2(
        address token,
        address from,
        uint256 amount,
        uint256 nonce,
        uint256 deadline,
        bytes calldata signature
    ) internal returns (uint256 received) {
        uint256 balanceBefore = IERC20(token).balanceOf(address(this));
        IPermit2(permit2).permitTransferFrom(
            IPermit2.PermitTransferFrom({
                permitted: IPermit2.TokenPermissions({
                    token: token,
                    amount: amount
                }),
                nonce: nonce,
                deadline: deadline
            }),
            IPermit2.SignatureTransferDetails({
                to: address(this),
                requestedAmount: amount
            }),
            from,
            signature
        );
        received = IERC20(token).balanceOf(address(this)) - balanceBefore;
    }

    // Aggregator contracts are not meant to hold any funds
    // This is just in case assets get stuck in the contract
    function rescueFunds(
        address asset,
        uint256 amount,
        address destination
    ) public isOwner {
        if (asset == address(0)) {
            payable(destination).transfer(amount);
        } else {
            asset.safeTransfer(destination, amount);
        }
    }
}

project/src/contracts/abstract/SKChainflipAggregator_V1.sol

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

import {SafeTransferLib} from "../../lib/SafeTransferLib.sol";
import {Owners} from "../../lib/Owners.sol";
import {TSAggregatorTokenTransferProxy} from "../misc/TSAggregatorTokenTransferProxy.sol";

abstract contract SKChainflipAggregator_V1 is Owners {
    using SafeTransferLib for address;

    address public cfVault;

    constructor(address _cfVault) {
        cfVault = _cfVault;
    }

    function updateCfVault(address _cfVault) external isOwner {
        cfVault = _cfVault;
    }

   /// @dev Check that the sender is the Chainflip's Vault.
    modifier onlyCfVault() {
        require(msg.sender == cfVault, "CFReceiver: caller not Chainflip sender");
        _;
    }
}

project/src/contracts/misc/SKTokenTransferProxy.sol

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

import {SafeTransferLib} from "../../lib/SafeTransferLib.sol";
import {Executors} from "../../lib/Executors.sol";
import {IERC20} from "../../interfaces/IERC20.sol";

/// @title SKTokenTransferProxy
/// @notice Token transfer proxy for SwapKit aggregators
/// @dev Aggregators register as executors and call transferTokens to pull tokens from users.
///      Owners can add/remove executors and pause/unpause the contract.
///      Always returns actual received amount to handle fee-on-transfer tokens.
contract SKTokenTransferProxy is Executors {
    using SafeTransferLib for address;

    event Paused(address indexed by);
    event Unpaused(address indexed by);

    bool public paused;

    modifier whenNotPaused() {
        require(!paused, "Paused");
        _;
    }

    constructor() {
        _setOwner(tx.origin, true);
    }

    /// @notice Transfer tokens from user to destination, returning actual amount received
    /// @param token Token address to transfer
    /// @param from Source address (must have approved this contract)
    /// @param to Destination address
    /// @param amount Amount to transfer
    /// @return received Actual amount received (may differ for fee-on-transfer tokens)
    function transferTokens(
        address token,
        address from,
        address to,
        uint256 amount
    ) external isExecutor whenNotPaused returns (uint256 received) {
        require(from == tx.origin, "Invalid from");

        uint256 balanceBefore = IERC20(token).balanceOf(to);
        token.safeTransferFrom(from, to, amount);
        received = IERC20(token).balanceOf(to) - balanceBefore;
    }

    /// @notice Pause all transfers (emergency stop)
    function pause() external isOwner {
        paused = true;
        emit Paused(msg.sender);
    }

    /// @notice Resume transfers
    function unpause() external isOwner {
        paused = false;
        emit Unpaused(msg.sender);
    }
}

project/src/contracts/misc/TSAggregatorTokenTransferProxy.sol

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

import {SafeTransferLib} from "../../lib/SafeTransferLib.sol";
import {Owners} from "../../lib/Owners.sol";

/// @title TSAggregatorTokenTransferProxy
/// @notice Token transfer proxy for THORSwap aggregators (legacy TS prefix)
/// @dev Aggregators register as owners and call transferTokens to pull tokens from users
contract TSAggregatorTokenTransferProxy is Owners {
    using SafeTransferLib for address;

    constructor() {
        _setOwner(msg.sender, true);
    }

    function transferTokens(
        address token,
        address from,
        address to,
        uint256 amount
    ) external isOwner {
        require(from == tx.origin || _isContract(from), "Invalid from address");
        token.safeTransferFrom(from, to, amount);
    }

    function _isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }
}

project/src/interfaces/IBlockList.sol

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

/// @notice An ERC-4626 vault that points at a blocklist registry.
/// @dev Verified live on every Kiln vault we route to: each returns a single per-chain
///      registry - 0x8cE05D6381924192206350d67fB815B01ED4A095 on Ethereum and
///      0x5cb3c7dEFffD95564423733801DD5226637FF66f on Arbitrum. Reading the address from
///      the vault rather than storing it here means a registry rotation on Kiln's side is
///      picked up automatically.
interface IBlockListedVault {
    function blockList() external view returns (address);
}

/// @notice Kiln's blocklist registry.
interface IBlockList {
    function isBlocked(address account) external view returns (bool);
}

project/src/interfaces/IChainflipReceiver.sol

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

/**
 * @dev Minimal interface for Chainflip vault or router to call cfReceive
 *      In practice, Chainflip's official interface will call this function
 *      on your contract, delivering the swapped tokens.
 */
interface IChainflipReceiver {
    function cfReceive(
        uint32 srcChain,
        bytes calldata srcAddress,
        bytes calldata message,
        address token,
        uint256 amount
    ) external payable;
}

project/src/interfaces/IERC20.sol

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

interface IERC20 {
    function decimals() external view returns (uint8);

    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(
        address recipient,
        uint256 amount
    ) external returns (bool);

    function allowance(
        address owner,
        address spender
    ) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);
}

project/src/interfaces/IERC4626.sol

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

interface IERC4626 {
    function asset() external view returns (address assetTokenAddress);

    function totalAssets() external view returns (uint256 totalManagedAssets);

    function convertToShares(
        uint256 assets
    ) external view returns (uint256 shares);

    function convertToAssets(
        uint256 shares
    ) external view returns (uint256 assets);

    function maxDeposit(
        address receiver
    ) external view returns (uint256 maxAssets);

    function previewDeposit(
        uint256 assets
    ) external view returns (uint256 shares);

    function deposit(
        uint256 assets,
        address receiver
    ) external returns (uint256 shares);

    function maxMint(
        address receiver
    ) external view returns (uint256 maxShares);

    function previewMint(uint256 shares) external view returns (uint256 assets);

    function mint(
        uint256 shares,
        address receiver
    ) external returns (uint256 assets);

    function maxWithdraw(
        address owner
    ) external view returns (uint256 maxAssets);

    function previewWithdraw(
        uint256 assets
    ) external view returns (uint256 shares);

    function withdraw(
        uint256 assets,
        address receiver,
        address owner
    ) external returns (uint256 shares);

    function maxRedeem(address owner) external view returns (uint256 maxShares);

    function previewRedeem(
        uint256 shares
    ) external view returns (uint256 assets);

    function redeem(
        uint256 shares,
        address receiver,
        address owner
    ) external returns (uint256 assets);

    event Deposit(
        address indexed caller,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );
    event Withdraw(
        address indexed caller,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );
}

project/src/interfaces/IPermit2.sol

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

/// @title IPermit2
/// @notice Minimal interface for Uniswap's Permit2 SignatureTransfer
/// @dev Permit2 canonical address: 0x000000000022D473030F116dDEE9F6B43aC78BA3
interface IPermit2 {
    /// @notice Token and amount for a permit
    struct TokenPermissions {
        address token;
        uint256 amount;
    }

    /// @notice The permit data for a single token transfer
    struct PermitTransferFrom {
        TokenPermissions permitted;
        uint256 nonce;
        uint256 deadline;
    }

    /// @notice Details for the transfer recipient
    struct SignatureTransferDetails {
        address to;
        uint256 requestedAmount;
    }

    /// @notice Transfer tokens using a signed permit
    /// @param permit The permit data signed by the owner
    /// @param transferDetails The recipient and amount to transfer
    /// @param owner The owner of the tokens
    /// @param signature The signature over the permit data
    function permitTransferFrom(
        PermitTransferFrom calldata permit,
        SignatureTransferDetails calldata transferDetails,
        address owner,
        bytes calldata signature
    ) external;
}

project/src/lib/Executors.sol

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

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

abstract contract Executors is Owners {
    event ExecutorSet(address indexed executor, bool active);

    mapping(address => bool) public executors;

    modifier isExecutor() {
        require(executors[msg.sender], "Unauthorized");
        _;
    }

    function _setExecutor(address executor, bool active) internal virtual {
        executors[executor] = active;
        emit ExecutorSet(executor, active);
    }

    function setExecutor(address owner, bool active) external virtual isOwner {
        _setExecutor(owner, active);
    }
}

project/src/lib/Owners.sol

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

abstract contract Owners {
    event OwnerSet(address indexed owner, bool active);

    mapping(address => bool) public owners;

    modifier isOwner() {
        require(owners[msg.sender], "Unauthorized");
        _;
    }

    function _setOwner(address owner, bool active) internal virtual {
        owners[owner] = active;
        emit OwnerSet(owner, active);
    }

    function setOwner(address owner, bool active) external virtual isOwner {
        _setOwner(owner, active);
    }
}

project/src/lib/ReentrancyGuard.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    uint256 private locked = 1;

    modifier nonReentrant() {
        require(locked == 1, "REENTRANCY");

        locked = 2;

        _;

        locked = 1;
    }
}

project/src/lib/SafeTransferLib.sol

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Gnosis (https://github.com/gnosis/gp-v2-contracts/blob/main/src/contracts/libraries/GPv2SafeERC20.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
library SafeTransferLib {
    /*///////////////////////////////////////////////////////////////
                            ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool callStatus;

        assembly {
            // Transfer the ETH and store if it succeeded or not.
            callStatus := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(callStatus, "ETH_TRANSFER_FAILED");
    }

    /*///////////////////////////////////////////////////////////////
                           ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool callStatus;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata to memory piece by piece:
            mstore(
                freeMemoryPointer,
                0x23b872dd00000000000000000000000000000000000000000000000000000000
            ) // Begin with the function selector.
            mstore(
                add(freeMemoryPointer, 4),
                and(from, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Mask and append the "from" argument.
            mstore(
                add(freeMemoryPointer, 36),
                and(to, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Mask and append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.

            // Call the token and store if it succeeded or not.
            // We use 100 because the calldata length is 4 + 32 * 3.
            callStatus := call(gas(), token, 0, freeMemoryPointer, 100, 0, 0)
        }

        require(
            didLastOptionalReturnCallSucceed(callStatus),
            "TRANSFER_FROM_FAILED"
        );
    }

    function safeTransfer(address token, address to, uint256 amount) internal {
        bool callStatus;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata to memory piece by piece:
            mstore(
                freeMemoryPointer,
                0xa9059cbb00000000000000000000000000000000000000000000000000000000
            ) // Begin with the function selector.
            mstore(
                add(freeMemoryPointer, 4),
                and(to, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Mask and append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.

            // Call the token and store if it succeeded or not.
            // We use 68 because the calldata length is 4 + 32 * 2.
            callStatus := call(gas(), token, 0, freeMemoryPointer, 68, 0, 0)
        }

        require(
            didLastOptionalReturnCallSucceed(callStatus),
            "TRANSFER_FAILED"
        );
    }

    function safeApprove(address token, address to, uint256 amount) internal {
        bool callStatus;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata to memory piece by piece:
            mstore(
                freeMemoryPointer,
                0x095ea7b300000000000000000000000000000000000000000000000000000000
            ) // Begin with the function selector.
            mstore(
                add(freeMemoryPointer, 4),
                and(to, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Mask and append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Finally append the "amount" argument. No mask as it's a full 32 byte value.

            // Call the token and store if it succeeded or not.
            // We use 68 because the calldata length is 4 + 32 * 2.
            callStatus := call(gas(), token, 0, freeMemoryPointer, 68, 0, 0)
        }

        require(didLastOptionalReturnCallSucceed(callStatus), "APPROVE_FAILED");
    }

    /*///////////////////////////////////////////////////////////////
                         INTERNAL HELPER LOGIC
    //////////////////////////////////////////////////////////////*/

    function didLastOptionalReturnCallSucceed(
        bool callStatus
    ) private pure returns (bool success) {
        assembly {
            // Get how many bytes the call returned.
            let returnDataSize := returndatasize()

            // If the call reverted:
            if iszero(callStatus) {
                // Copy the revert message into memory.
                returndatacopy(0, 0, returnDataSize)

                // Revert with the same message.
                revert(0, returnDataSize)
            }

            switch returnDataSize
            case 32 {
                // Copy the return data into memory.
                returndatacopy(0, 0, returnDataSize)

                // Set success to whether it returned true.
                success := iszero(iszero(mload(0)))
            }
            case 0 {
                // There was no return data.
                success := 1
            }
            default {
                // It returned some malformed input.
                success := 0
            }
        }
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.