Skip to content
Verified contractExactMIT

SolvBTCRouterV2

Address0x1d8595e194eaaff37496a9a5f3f509f5eea9c70b
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 1 runs
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,079,724
Creation transaction
0x953a450277…dbe4658e5a

contracts/SolvBTCRouterV2.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {IOpenFundMarket, IOFMWhitelistStrategyManager, PoolInfo} from "./external/IOpenFundMarket.sol";
import {
    IOpenFundRedemptionDelegate, IOpenFundRedemptionConcrete, RedeemInfo
} from "./external/IOpenFundRedemption.sol";
import {IERC721} from "./external/IERC721.sol";
import {IERC3525} from "./external/IERC3525.sol";
import {ERC20TransferHelper} from "./utils/ERC20TransferHelper.sol";
import {ERC3525TransferHelper} from "./utils/ERC3525TransferHelper.sol";
import {ISolvBTCMultiAssetPool} from "./ISolvBTCMultiAssetPool.sol";
import {IxSolvBTCPool} from "./IxSolvBTCPool.sol";
import {FeeManager} from "./FeeManager.sol";

contract SolvBTCRouterV2 is ReentrancyGuardUpgradeable, Ownable2StepUpgradeable {
    event Deposit(
        address indexed targetToken,
        address indexed currency,
        address indexed depositor,
        uint256 targetTokenAmount,
        uint256 currencyAmount,
        address[] path,
        bytes32[] poolIds
    );
    event CollectDepositFee(
        address indexed payer, address indexed currency, address indexed feeReceiver, uint256 feeAmount
    );
    event WithdrawRequest(
        address indexed targetToken,
        address indexed currency,
        address indexed requester,
        bytes32 poolId,
        uint256 withdrawAmount,
        uint256 redemptionId
    );
    event CancelWithdrawRequest(
        address indexed targetToken,
        address indexed redemption,
        address indexed requester,
        bytes32 poolId,
        uint256 redemptionId,
        uint256 targetTokenAmount
    );
    event SetOpenFundMarket(address indexed openFundMarket);
    event AddKycSBTVerifier(address indexed verifier);
    event RemoveKycSBTVerifier(address indexed verifier);
    event SetPath(address indexed currency, address indexed targetToken, address[] path);
    event SetPoolId(address indexed targetToken, address indexed currency, bytes32 indexed poolId);
    event SetMultiAssetPool(address indexed token, address indexed multiAssetPool);
    event SetFeeManager(address feeManager);

    // the address of openFundMarket
    address public openFundMarket;

    // the addresses of SBTs that will be used to verify the KYC status
    address[] public kycSBTVerifiers;

    // currency => target ERC20 => path(ERC20[])
    mapping(address => mapping(address => address[])) public paths;

    // target ERC20 (SolvBTC or LSTs) => currency => poolId
    mapping(address => mapping(address => bytes32)) public poolIds;

    // ERC20 => multiAssetPool
    mapping(address => address) public multiAssetPools;

    address public feeManager;

    // use a special poolId to represent the xSolvBTC pool
    bytes32 public constant X_SOLV_BTC_POOL_ID =
        bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    /**
     * @notice RouterV2 initialization
     * @param owner_ The owner of this router
     * @param openFundMarket_ The address of openFundMarket
     */
    function initialize(address owner_, address openFundMarket_) external initializer {
        require(owner_ != address(0), "SolvBTCRouterV2: invalid admin");
        __Ownable_init_unchained(owner_);
        __ReentrancyGuard_init();
        _setOpenFundMarket(openFundMarket_);
    }

    /**
     * @notice Deposit currency and get targetToken
     * @param targetToken_ The target ERC20 token address to receive
     * @param currency_ The currency address to deposit
     * @param currencyAmount_ The amount of currency to deposit
     * @param minimumTargetTokenAmount_ The minimum acceptable return amount of target token
     * @param expireTime_ The expire time
     * @return targetTokenAmount_ The targetToken amount to receive
     */
    function deposit(
        address targetToken_,
        address currency_,
        uint256 currencyAmount_,
        uint256 minimumTargetTokenAmount_,
        uint64 expireTime_
    ) external virtual nonReentrant returns (uint256 targetTokenAmount_) {
        require(currencyAmount_ > 0, "SolvBTCRouterV2: invalid currency amount");
        ERC20TransferHelper.doTransferIn(currency_, msg.sender, currencyAmount_);

        // collect deposit fee
        (uint256 feeAmount, address feeReceiver) =
            FeeManager(feeManager).getDepositFee(targetToken_, currency_, currencyAmount_);
        require(feeAmount <= currencyAmount_, "SolvBTCRouterV2: fee amount exceeds currency amount");
        if (feeAmount > 0) {
            ERC20TransferHelper.doTransferOut(currency_, payable(feeReceiver), feeAmount);
            emit CollectDepositFee(msg.sender, currency_, feeReceiver, feeAmount);
        }

        address[] memory path = paths[currency_][targetToken_];
        bytes32[] memory pathPoolIds = new bytes32[](path.length + 1);
        targetTokenAmount_ = currencyAmount_ - feeAmount;
        for (uint256 i = 0; i <= path.length; i++) {
            address paidToken = i == 0 ? currency_ : path[i - 1];
            address receivedToken = i == path.length ? targetToken_ : path[i];
            bytes32 targetPoolId = poolIds[receivedToken][paidToken];
            pathPoolIds[i] = targetPoolId;
            // if the targetPoolId is the xSolvBTC pool, deposit to xSolvBTC pool
            if (targetPoolId == bytes32(X_SOLV_BTC_POOL_ID)) {
                targetTokenAmount_ = _depositToXSolvBTC(receivedToken, targetTokenAmount_);
            } else {
                targetTokenAmount_ = _deposit(receivedToken, paidToken, targetTokenAmount_, expireTime_);
            }
        }
        require(targetTokenAmount_ >= minimumTargetTokenAmount_, "SolvBTCRouterV2: target token amount not enough");
        ERC20TransferHelper.doTransferOut(targetToken_, payable(msg.sender), targetTokenAmount_);

        emit Deposit(targetToken_, currency_, msg.sender, targetTokenAmount_, currencyAmount_, path, pathPoolIds);
    }

    function _depositToXSolvBTC(address targetToken_, uint256 currencyAmount_)
        internal
        returns (uint256 targetTokenAmount_)
    {
        address xSolvBTCPool = multiAssetPools[targetToken_];
        return IxSolvBTCPool(xSolvBTCPool).deposit(currencyAmount_);
    }

    function _deposit(address targetToken_, address currency_, uint256 currencyAmount_, uint64 expireTime_)
        internal
        returns (uint256 targetTokenAmount_)
    {
        bytes32 targetPoolId = poolIds[targetToken_][currency_];
        require(targetPoolId > 0, "SolvBTCRouterV2: poolId not found");
        require(checkPoolPermission(targetPoolId), "SolvBTCRouterV2: pool permission denied");

        address _openFundMarket = openFundMarket;
        PoolInfo memory poolInfo = IOpenFundMarket(_openFundMarket).poolInfos(targetPoolId);
        require(currency_ == poolInfo.currency, "SolvBTCRouterV2: currency not match");
        IERC3525 share = IERC3525(poolInfo.poolSFTInfo.openFundShare);
        uint256 shareSlot = poolInfo.poolSFTInfo.openFundShareSlot;

        address multiAssetPool = multiAssetPools[targetToken_];
        require(
            targetToken_ == ISolvBTCMultiAssetPool(multiAssetPool).getERC20(address(share), shareSlot),
            "SolvBTCRouterV2: target token not match"
        );

        ERC20TransferHelper.doApprove(currency_, _openFundMarket, currencyAmount_);
        targetTokenAmount_ = IOpenFundMarket(_openFundMarket).subscribe(targetPoolId, currencyAmount_, 0, expireTime_);

        uint256 shareCount = share.balanceOf(address(this));
        uint256 shareId = share.tokenOfOwnerByIndex(address(this), shareCount - 1);
        require(shareSlot == share.slotOf(shareId), "SolvBTCRouterV2: share slot not match");
        require(targetTokenAmount_ == share.balanceOf(shareId), "SolvBTCRouterV2: share value not match");

        share.approve(multiAssetPool, shareId);
        ISolvBTCMultiAssetPool(multiAssetPool).deposit(address(share), shareId, targetTokenAmount_);
    }

    /**
     * @notice Withdraw currency with target token from the pool
     * @param targetToken_ The target ERC20 token address to withdraw
     * @param currency_ The currency address to receive after claiming
     * @param withdrawAmount_ The amount of targetToken to withdraw
     * @return The address and ID of the redemption sft token to receive
     */
    function withdrawRequest(address targetToken_, address currency_, uint256 withdrawAmount_)
        external
        virtual
        nonReentrant
        returns (address, uint256)
    {
        bytes32 targetPoolId = poolIds[targetToken_][currency_];
        require(targetPoolId > 0, "SolvBTCRouterV2: poolId not found");

        address _openFundMarket = openFundMarket;
        PoolInfo memory poolInfo = IOpenFundMarket(_openFundMarket).poolInfos(targetPoolId);
        require(currency_ == poolInfo.currency, "SolvBTCRouterV2: currency not match");
        IERC3525 share = IERC3525(poolInfo.poolSFTInfo.openFundShare);
        IERC3525 redemption = IERC3525(poolInfo.poolSFTInfo.openFundRedemption);
        uint256 shareSlot = poolInfo.poolSFTInfo.openFundShareSlot;

        {
            address multiAssetPool = multiAssetPools[targetToken_];
            require(
                targetToken_ == ISolvBTCMultiAssetPool(multiAssetPool).getERC20(address(share), shareSlot),
                "SolvBTCRouterV2: target token not match"
            );

            ERC20TransferHelper.doTransferIn(targetToken_, msg.sender, withdrawAmount_);
            uint256 shareId =
                ISolvBTCMultiAssetPool(multiAssetPool).withdraw(address(share), shareSlot, 0, withdrawAmount_);
            require(withdrawAmount_ == share.balanceOf(shareId), "SolvBTCRouterV2: share value not match");

            ERC3525TransferHelper.doApproveId(address(share), _openFundMarket, shareId);
            IOpenFundMarket(_openFundMarket).requestRedeem(targetPoolId, shareId, 0, withdrawAmount_);
        }

        uint256 redemptionCount = redemption.balanceOf(address(this));
        uint256 redemptionId_ = redemption.tokenOfOwnerByIndex(address(this), redemptionCount - 1);
        require(withdrawAmount_ == redemption.balanceOf(redemptionId_), "SolvBTCRouterV2: redemption value not match");
        ERC3525TransferHelper.doTransferOut(address(redemption), payable(msg.sender), redemptionId_);

        emit WithdrawRequest(targetToken_, currency_, msg.sender, targetPoolId, withdrawAmount_, redemptionId_);
        return (address(redemption), redemptionId_);
    }

    /**
     * @notice Cancel the withdraw request
     * @param targetToken_ The target ERC20 token address to receive after canceling
     * @param redemption_ The redemption sft token address
     * @param redemptionId_ The redemption sft token ID
     * @return targetTokenAmount_ The targetToken amount to receive
     */
    function cancelWithdrawRequest(address targetToken_, address redemption_, uint256 redemptionId_)
        external
        virtual
        nonReentrant
        returns (uint256 targetTokenAmount_)
    {
        bytes32 targetPoolId = _getPoolIdByRedemptionId(redemption_, redemptionId_);
        address _openFundMarket = openFundMarket;
        PoolInfo memory poolInfo = IOpenFundMarket(_openFundMarket).poolInfos(targetPoolId);
        IERC3525 share = IERC3525(poolInfo.poolSFTInfo.openFundShare);
        uint256 shareSlot = poolInfo.poolSFTInfo.openFundShareSlot;

        address multiAssetPool = multiAssetPools[targetToken_];
        require(
            targetToken_ == ISolvBTCMultiAssetPool(multiAssetPool).getERC20(address(share), shareSlot),
            "SolvBTCRouterV2: target token not match"
        );

        targetTokenAmount_ = IERC3525(redemption_).balanceOf(redemptionId_);
        ERC3525TransferHelper.doTransferIn(redemption_, msg.sender, redemptionId_);
        ERC3525TransferHelper.doApproveId(redemption_, _openFundMarket, redemptionId_);
        IOpenFundMarket(_openFundMarket).revokeRedeem(targetPoolId, redemptionId_);
        uint256 shareCount = share.balanceOf(address(this));
        uint256 shareId = share.tokenOfOwnerByIndex(address(this), shareCount - 1);
        require(targetTokenAmount_ == share.balanceOf(shareId), "SolvBTCRouterV2: cancel amount not match");

        ERC3525TransferHelper.doApproveId(address(share), multiAssetPool, shareId);
        ISolvBTCMultiAssetPool(multiAssetPool).deposit(address(share), shareId, targetTokenAmount_);
        ERC20TransferHelper.doTransferOut(targetToken_, payable(msg.sender), targetTokenAmount_);

        emit CancelWithdrawRequest(
            targetToken_, redemption_, msg.sender, targetPoolId, redemptionId_, targetTokenAmount_
        );
    }

    /**
     * @notice Check if msg.sender is allowed to deposit to the pool
     * @param poolId_ The poolId of the pool to deposit
     */
    function checkPoolPermission(bytes32 poolId_) public view virtual returns (bool) {
        address _openFundMarket = openFundMarket;
        PoolInfo memory poolInfo = IOpenFundMarket(_openFundMarket).poolInfos(poolId_);
        if (poolInfo.permissionless) {
            return true;
        }
        address whiteListManager = IOpenFundMarket(_openFundMarket).getAddress("OFMWhitelistStrategyManager");
        return IOFMWhitelistStrategyManager(whiteListManager).isWhitelisted(poolId_, msg.sender) || checkKycSBT();
    }

    /**
     * @notice Verify the KYC status of msg.sender
     */
    function checkKycSBT() public view virtual returns (bool) {
        for (uint256 i = 0; i < kycSBTVerifiers.length; i++) {
            if (IERC721(kycSBTVerifiers[i]).balanceOf(msg.sender) > 0) {
                return true;
            }
        }
        return false;
    }

    /**
     * @notice Add KYC SBT verifier
     * @param kycSBTVerifier_ The KYC SBT verifier address
     */
    function addKycSBTVerifier(address kycSBTVerifier_) external onlyOwner {
        require(kycSBTVerifier_ != address(0), "SolvBTCRouterV2: invalid verifier");
        kycSBTVerifiers.push(kycSBTVerifier_);
        emit AddKycSBTVerifier(kycSBTVerifier_);
    }

    /**
     * @notice Remove KYC SBT verifier
     * @param kycSBTVerifier_ The KYC SBT verifier address
     */
    function removeKycSBTVerifier(address kycSBTVerifier_) external onlyOwner {
        for (uint256 i = 0; i < kycSBTVerifiers.length; i++) {
            if (kycSBTVerifiers[i] == kycSBTVerifier_) {
                kycSBTVerifiers[i] = kycSBTVerifiers[kycSBTVerifiers.length - 1];
                kycSBTVerifiers.pop();
                emit RemoveKycSBTVerifier(kycSBTVerifier_);
                break;
            }
        }
    }

    function _getPoolIdByRedemptionId(address redemption_, uint256 redemptionId_) internal virtual returns (bytes32) {
        address redemptionConcrete = IOpenFundRedemptionDelegate(redemption_).concrete();
        uint256 redemptionSlot = IERC3525(redemption_).slotOf(redemptionId_);
        RedeemInfo memory redeemInfo = IOpenFundRedemptionConcrete(redemptionConcrete).getRedeemInfo(redemptionSlot);
        return redeemInfo.poolId;
    }

    function _setOpenFundMarket(address openFundMarket_) private {
        require(openFundMarket_ != address(0), "SolvBTCRouterV2: invalid openFundMarket");
        openFundMarket = openFundMarket_;
        emit SetOpenFundMarket(openFundMarket_);
    }

    /**
     * @notice Set the poolId for a target token and currency
     * @param targetToken_ The target ERC20 token address to receive
     * @param currency_ The currency address to deposit
     * @param poolId_ The poolId of the pool to deposit
     */
    function setPoolId(address targetToken_, address currency_, bytes32 poolId_) external onlyOwner {
        require(targetToken_ != address(0), "SolvBTCRouterV2: invalid targetToken");
        require(currency_ != address(0), "SolvBTCRouterV2: invalid currency");
        require(poolId_ > 0, "SolvBTCRouterV2: invalid poolId");

        poolIds[targetToken_][currency_] = poolId_;
        emit SetPoolId(targetToken_, currency_, poolId_);
    }

    /**
     * @notice Set the path for a target token and currency
     * @param currency_ The currency address to deposit
     * @param targetToken_ The target ERC20 token address to receive
     * @param path_ The addresses of the path tokens that indicate how to convert currency to targetToken
     */
    function setPath(address currency_, address targetToken_, address[] memory path_) external onlyOwner {
        require(currency_ != address(0), "SolvBTCRouterV2: invalid currency");
        require(targetToken_ != address(0), "SolvBTCRouterV2: invalid targetToken");
        for (uint256 i = 0; i < path_.length; i++) {
            require(path_[i] != address(0), "SolvBTCRouterV2: invalid path token");
        }

        paths[currency_][targetToken_] = path_;
        emit SetPath(currency_, targetToken_, path_);
    }

    /**
     * @notice Set the multiAssetPool/xSolvBTCPool address for a target token
     * @param token_ The target ERC20 token address
     * @param multiAssetPool_ The multiAssetPool/xSolvBTCPool address
     */
    function setMultiAssetPool(address token_, address multiAssetPool_) external onlyOwner {
        require(token_ != address(0), "SolvBTCRouterV2: invalid token");
        require(multiAssetPool_ != address(0), "SolvBTCRouterV2: invalid multiAssetPool");
        multiAssetPools[token_] = multiAssetPool_;
        emit SetMultiAssetPool(token_, multiAssetPool_);
    }

    /**
     * @notice Set the subscriptionFeeOracle address
     * @param feeManager_ The feeManager address
     */
    function setFeeManager(address feeManager_) external onlyOwner {
        require(feeManager_ != address(0), "SolvBTCRouterV2: invalid fee manager");
        feeManager = feeManager_;
        emit SetFeeManager(feeManager_);
    }

    uint256[44] private __gap;
}

@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
    struct Ownable2StepStorage {
        address _pendingOwner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;

    function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
        assembly {
            $.slot := Ownable2StepStorageLocation
        }
    }

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    function __Ownable2Step_init() internal onlyInitializing {
    }

    function __Ownable2Step_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        return $._pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        $._pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        Ownable2StepStorage storage $ = _getOwnable2StepStorage();
        delete $._pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        OwnableStorage storage $ = _getOwnableStorage();
        return $._owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        OwnableStorage storage $ = _getOwnableStorage();
        address oldOwner = $._owner;
        $._owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

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

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol

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

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

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

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

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

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

contracts/FeeManager.sol

// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

pragma solidity 0.8.20;

contract FeeManager is Ownable2StepUpgradeable {

    // DepositFee
    event SetDepositFee(
        address indexed targetToken,
        address indexed currency,
        uint64 feeRate,
        address feeReceiver
    );

    struct DepositFee {
        uint64 feeRate;   // decimal = 8, 1e8 = 100%
        address feeReceiver;
    }

    struct DepositFeeParam {
        address targetToken;
        address currency;
        uint64 feeRate;
        address feeReceiver;
    }

    struct FeeManagerStorage {
        // targetToken => currency => DepositFee
        mapping(address => mapping(address => DepositFee)) _depositFees;
    }

    // keccak256(abi.encode(uint256(keccak256("solv.storage.FeeManager")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant FeeManagerStorageLocation =
        0xd54c6203b7ea9f2a1f1717acf254621134b6951cfc66daad7b3aa9cad9627c00;

    function _getFeeManagerStorage() private pure returns (FeeManagerStorage storage $) {
        assembly {
            $.slot := FeeManagerStorageLocation
        }
    }

    function initialize() external initializer {
        __Ownable_init(msg.sender);
    }

    function setDepositFees(DepositFeeParam[] calldata params) external onlyOwner {
        for (uint256 i = 0; i < params.length; i++) {
            address targetToken = params[i].targetToken;
            address currency = params[i].currency;
            uint64 feeRate = params[i].feeRate;
            address feeReceiver = params[i].feeReceiver;

            require(targetToken != address(0), "FeeManager: targetToken is zero address");
            require(currency != address(0), "FeeManager: currency is zero address");
            require(feeRate <= 1e8, "FeeManager: feeRate exceeds 100%");
            require(feeRate == 0 || feeReceiver != address(0), "FeeManager: feeReceiver is zero address");

            FeeManagerStorage storage $ = _getFeeManagerStorage();
            $._depositFees[targetToken][currency] = DepositFee(feeRate, feeReceiver);
            emit SetDepositFee(targetToken, currency, feeRate, feeReceiver);
        }
    }

    function getDepositFee(address targetToken_, address currency_, uint256 amount_) 
        external 
        view 
        virtual
        returns (uint256 feeAmount_, address feeReceiver_) 
    {
        DepositFee memory depositFee = _getFeeManagerStorage()._depositFees[targetToken_][currency_];
        feeAmount_ = (amount_ * depositFee.feeRate) / 1e8;
        feeReceiver_ = depositFee.feeReceiver;
    }

}

contracts/ISolvBTCMultiAssetPool.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

interface ISolvBTCMultiAssetPool {
    function deposit(address sft_, uint256 sftId_, uint256 value_) external;
    function withdraw(address sft, uint256 slot, uint256 sftId, uint256 value) external returns (uint256 toSftId_);

    function isSftSlotDepositAllowed(address sft_, uint256 slot_) external view returns (bool);
    function isSftSlotWithdrawAllowed(address sft_, uint256 slot_) external view returns (bool);
    function getERC20(address sft_, uint256 slot_) external view returns (address);
    function getHoldingValueSftId(address sft_, uint256 slot_) external view returns (uint256);
    function getSftSlotBalance(address sft_, uint256 slot_) external view returns (uint256);
}

contracts/IxSolvBTCPool.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

interface IxSolvBTCPool {
    function deposit(uint256 solvBtcAmount_) external returns (uint256 xSolvBtcAmount);
    function withdraw(uint256 xSolvBtcAmount_) external returns (uint256 solvBtcAmount);
}

contracts/external/IERC3525.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

import "./IERC721.sol";

interface IERC3525 is IERC721 {
    function valueDecimals() external view returns (uint8);
    function balanceOf(uint256 tokenId) external view returns (uint256);
    function slotOf(uint256 tokenId) external view returns (uint256);
    function allowance(uint256 tokenId, address operator) external view returns (uint256);
    
    function approve(address operator, uint256 tokenId) external payable;
    function approve(uint256 tokenId, address operator, uint256 value) external payable;
    function transferFrom(uint256 fromTokenId, uint256 toTokenId, uint256 value) external payable;
    function transferFrom(uint256 fromTokenId, address to, uint256 value) external payable returns (uint256);
}

contracts/external/IERC721.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

interface IERC721 {
    function balanceOf(address owner) external view returns (uint256);
    function ownerOf(uint256 tokenId) external view returns (address);
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
    function getApproved(uint256 tokenId) external view returns (address);
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    function approve(address approved, uint256 tokenId) external payable;
    function setApprovalForAll(address operator, bool approved) external;
    function transferFrom(address from, address to, uint256 tokenId) external payable;
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external payable;
    function safeTransferFrom(address from, address to, uint256 tokenId) external payable;
}

contracts/external/IOpenFundMarket.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

struct SubscribeLimitInfo {
    uint256 hardCap;
    uint256 subscribeMin;
    uint256 subscribeMax;
    uint64 fundraisingStartTime;
    uint64 fundraisingEndTime;
}

struct PoolSFTInfo {
    address openFundShare;
    address openFundRedemption;
    uint256 openFundShareSlot;
    uint256 latestRedeemSlot;
}

struct PoolFeeInfo {
    uint16 carryRate;
    address carryCollector;
    uint64 latestProtocolFeeSettleTime;
}

struct ManagerInfo {
    address poolManager;
    address subscribeNavManager;
    address redeemNavManager;
}

struct PoolInfo {
    PoolSFTInfo poolSFTInfo;
    PoolFeeInfo poolFeeInfo;
    ManagerInfo managerInfo;
    SubscribeLimitInfo subscribeLimitInfo;
    address vault;
    address currency;
    address navOracle;
    uint64 valueDate;
    bool permissionless;
    uint256 fundraisingAmount;
}

interface IOpenFundMarket {
    function subscribe(bytes32 poolId, uint256 currencyAmount, uint256 openFundShareId, uint64 expireTime)
        external
        returns (uint256 value_);
    function requestRedeem(bytes32 poolId, uint256 openFundShareId, uint256 openFundRedemptionId, uint256 redeemValue)
        external;
    function revokeRedeem(bytes32 poolId, uint256 openFundRedemptionId) external;

    function poolInfos(bytes32 poolId) external view returns (PoolInfo memory);
    function getAddress(bytes32 name) external view returns (address);
    function purchasedRecords(bytes32 poolId, address buyer) external view returns (uint256);
}

interface IOFMWhitelistStrategyManager {
    function isWhitelisted(bytes32 poolId_, address buyer_) external view returns (bool);
}

contracts/external/IOpenFundRedemption.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

struct RedeemInfo {
    bytes32 poolId;
    address currency;
    uint256 createTime;
    uint256 nav;
}

interface IOpenFundRedemptionDelegate {
    function concrete() external view returns (address);
}

interface IOpenFundRedemptionConcrete {
    function getRedeemInfo(uint256 slot) external view returns (RedeemInfo memory);
}

contracts/utils/ERC20TransferHelper.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

interface ERC20Interface {
    function balanceOf(address account) external view returns (uint256);

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

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

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

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library ERC20TransferHelper {

    address internal constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    function doApprove(address underlying, address spender, uint256 amount) internal {
        require(underlying.code.length > 0, "invalid underlying");
        (bool success, bytes memory data) = underlying.call(
            abi.encodeWithSelector(
                ERC20Interface.approve.selector,
                spender,
                amount
            )
        );
        require(success && (data.length == 0 || abi.decode(data, (bool))), "SAF");
    }

    function doTransferIn(address underlying, address from, uint256 amount) internal {
        if (underlying == ETH_ADDRESS) {
            // Sanity checks
            require(tx.origin == from || msg.sender == from, "sender mismatch");
            require(msg.value >= amount, "value mismatch");
        } else {
            require(underlying.code.length > 0, "invalid underlying");
            (bool success, bytes memory data) = underlying.call(
                abi.encodeWithSelector(
                    ERC20Interface.transferFrom.selector,
                    from,
                    address(this),
                    amount
                )
            );
            require(success && (data.length == 0 || abi.decode(data, (bool))), "STF");
        }
    }

    function doTransferOut(address underlying, address payable to, uint256 amount) internal {
        if (underlying == ETH_ADDRESS) {
            (bool success, ) = to.call{value: amount}(new bytes(0));
            require(success, "STE");
        } else {
            require(underlying.code.length > 0, "invalid underlying");
            (bool success, bytes memory data) = underlying.call(
                abi.encodeWithSelector(
                    ERC20Interface.transfer.selector,
                    to,
                    amount
                )
            );
            require(success && (data.length == 0 || abi.decode(data, (bool))), "ST");
        }
    }
}

contracts/utils/ERC3525TransferHelper.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;

interface ERC721Interface {
    function approve(address to, uint256 tokenId) external;
    function transferFrom(address from, address to, uint256 tokenId) external;
    function safeTransferFrom(address from, address to, uint256 tokenId) external;
}

interface ERC3525Interface {
    function approve(uint256 tokenId, address to, uint256 allowance) external payable;
    function transferFrom(uint256 fromTokenId, uint256 toTokenId, uint256 value) external payable;
    function transferFrom(uint256 fromTokenId, address to, uint256 value) external payable returns (uint256); 
}

library ERC3525TransferHelper {
    function doApproveId(address underlying, address to, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.approve(to, tokenId);
    }

    function doApproveValue(address underlying, uint256 tokenId, address to, uint256 allowance) internal {
        ERC3525Interface token = ERC3525Interface(underlying);
        token.approve(tokenId, to, allowance);
    }

    function doTransferIn(address underlying, address from, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.transferFrom(from, address(this), tokenId);
    }
    
    function doSafeTransferIn(address underlying, address from, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.safeTransferFrom(from, address(this), tokenId);
    }

    function doSafeTransferOut(address underlying, address to, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.safeTransferFrom(address(this), to, tokenId);
    }

    function doTransferOut(address underlying, address to, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.transferFrom(address(this), to, tokenId);
    }

    function doTransferIn(address underlying, uint256 fromTokenId, uint256 value) internal returns (uint256 newTokenId) {
        ERC3525Interface token = ERC3525Interface(underlying);
        return token.transferFrom(fromTokenId, address(this), value);
    }

    function doTransferOut(address underlying, uint256 fromTokenId, address to, uint256 value) internal returns (uint256 newTokenId) {
        ERC3525Interface token = ERC3525Interface(underlying);
        newTokenId = token.transferFrom(fromTokenId, to, value);
    }

    function doTransfer(address underlying, address from, address to, uint256 tokenId) internal {
        ERC721Interface token = ERC721Interface(underlying);
        token.transferFrom(from, to, tokenId);
    }

    function doTransfer(address underlying, uint256 fromTokenId, uint256 toTokenId, uint256 value) internal {
        ERC3525Interface token = ERC3525Interface(underlying);
        token.transferFrom(fromTokenId, toTokenId, value);
    }

}
Compiler settingsShow
{
  "metadata": {
    "useLiteralContent": true
  },
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.