FRAX Price: $0.83 (-17.84%)

Contract

0xEfc15efb330112a2c313d5da8f1b29893AD4Cd99

Overview

FRAX Balance | FXTL Balance

0 FRAX | 1,126 FXTL

FRAX Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Age:7D
Reset Filter

Transaction Hash
Block
From
To

There are no matching entries

> 10 Token Transfers found.

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
DStakeRouterDLend

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion, MIT license
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts-5/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts-5/token/ERC20/utils/SafeERC20.sol";
import {AccessControl} from "@openzeppelin/contracts-5/access/AccessControl.sol";
import {IDStakeRouter} from "./interfaces/IDStakeRouter.sol";
import {IDStableConversionAdapter} from "./interfaces/IDStableConversionAdapter.sol";
import {IDStakeCollateralVault} from "./DStakeCollateralVault.sol";
import {IERC4626} from "@openzeppelin/contracts-5/interfaces/IERC4626.sol";

/**
 * @title DStakeRouterDLend
 * @notice Orchestrates deposits, withdrawals, and asset exchanges for a DStakeToken vault.
 * @dev Interacts with the DStakeToken, DStakeCollateralVault, and various IDStableConversionAdapters.
 *      This contract is non-upgradeable but replaceable via DStakeToken governance.
 *      Relies on the associated DStakeToken for role management.
 */
contract DStakeRouterDLend is IDStakeRouter, AccessControl {
    using SafeERC20 for IERC20;

    // --- Errors ---
    error ZeroAddress();
    error AdapterNotFound(address vaultAsset);
    error ZeroPreviewWithdrawAmount(address vaultAsset);
    error InsufficientDStableFromAdapter(
        address vaultAsset,
        uint256 expected,
        uint256 actual
    );
    error VaultAssetManagedByDifferentAdapter(
        address vaultAsset,
        address existingAdapter
    );
    error ZeroInputDStableValue(address fromAsset, uint256 fromAmount);
    error AdapterAssetMismatch(
        address adapter,
        address expectedAsset,
        address actualAsset
    );
    error SlippageCheckFailed(
        address toAsset,
        uint256 calculatedAmount,
        uint256 minAmount
    );
    error InconsistentState(string message);

    // --- Roles ---
    bytes32 public constant DSTAKE_TOKEN_ROLE = keccak256("DSTAKE_TOKEN_ROLE");
    bytes32 public constant COLLATERAL_EXCHANGER_ROLE =
        keccak256("COLLATERAL_EXCHANGER_ROLE");

    // --- State ---
    address public immutable dStakeToken; // The DStakeToken this router serves
    IDStakeCollateralVault public immutable collateralVault; // The DStakeCollateralVault this router serves
    address public immutable dStable; // The underlying dSTABLE asset address

    // Governance-configurable risk parameters
    uint256 public dustTolerance = 1; // 1 wei default tolerance

    mapping(address => address) public vaultAssetToAdapter; // vaultAsset => adapterAddress
    address public defaultDepositVaultAsset; // Default strategy for deposits

    // Struct used to pack local variables in functions prone to "stack too deep" compiler errors
    struct ExchangeLocals {
        address fromAdapterAddress;
        address toAdapterAddress;
        IDStableConversionAdapter fromAdapter;
        IDStableConversionAdapter toAdapter;
        uint256 dStableValueIn;
        uint256 calculatedToVaultAssetAmount;
    }

    // --- Constructor ---
    constructor(address _dStakeToken, address _collateralVault) {
        if (_dStakeToken == address(0) || _collateralVault == address(0)) {
            revert ZeroAddress();
        }
        dStakeToken = _dStakeToken;
        collateralVault = IDStakeCollateralVault(_collateralVault);
        dStable = collateralVault.dStable(); // Fetch dStable address from vault
        if (dStable == address(0)) {
            revert ZeroAddress();
        }

        // Setup roles
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(DSTAKE_TOKEN_ROLE, _dStakeToken);
    }

    // --- External Functions (IDStakeRouter Interface) ---

    /**
     * @inheritdoc IDStakeRouter
     */
    function deposit(
        uint256 dStableAmount
    ) external override onlyRole(DSTAKE_TOKEN_ROLE) {
        address adapterAddress = vaultAssetToAdapter[defaultDepositVaultAsset];
        if (adapterAddress == address(0)) {
            revert AdapterNotFound(defaultDepositVaultAsset);
        }

        (
            address vaultAssetExpected,
            uint256 expectedShares
        ) = IDStableConversionAdapter(adapterAddress)
                .previewConvertToVaultAsset(dStableAmount);

        uint256 mintedShares = _executeDeposit(
            adapterAddress,
            vaultAssetExpected,
            dStableAmount
        );

        if (mintedShares < expectedShares) {
            revert SlippageCheckFailed(
                vaultAssetExpected,
                mintedShares,
                expectedShares
            );
        }

        emit RouterDeposit(
            adapterAddress,
            vaultAssetExpected,
            msg.sender,
            mintedShares,
            dStableAmount
        );
    }

    /**
     * @dev Performs the actual pull-approve-convert sequence and returns the number of shares
     *      minted to the collateral vault.
     * @param adapterAddress The adapter to use for conversion.
     * @param vaultAssetExpected The vault asset that the adapter should mint.
     * @param dStableAmount The amount of dStable being deposited.
     * @return mintedShares The number of vault asset shares minted.
     */
    function _executeDeposit(
        address adapterAddress,
        address vaultAssetExpected,
        uint256 dStableAmount
    ) private returns (uint256 mintedShares) {
        uint256 beforeBal = IERC20(vaultAssetExpected).balanceOf(
            address(collateralVault)
        );

        // Pull dStable from caller (DStakeToken)
        IERC20(dStable).safeTransferFrom(
            msg.sender,
            address(this),
            dStableAmount
        );

        // Approve adapter to spend dStable
        // Use standard approve for trusted protocol token (dStable)
        IERC20(dStable).approve(adapterAddress, dStableAmount);

        // Convert dStable to vault asset (minted directly to collateral vault)
        (
            address vaultAssetActual,
            uint256 reportedShares
        ) = IDStableConversionAdapter(adapterAddress).convertToVaultAsset(
                dStableAmount
            );

        if (vaultAssetActual != vaultAssetExpected) {
            revert AdapterAssetMismatch(
                adapterAddress,
                vaultAssetExpected,
                vaultAssetActual
            );
        }

        mintedShares =
            IERC20(vaultAssetExpected).balanceOf(address(collateralVault)) -
            beforeBal;

        if (mintedShares != reportedShares) {
            revert InconsistentState("Adapter mis-reported shares");
        }
    }

    /**
     * @inheritdoc IDStakeRouter
     */
    function withdraw(
        uint256 dStableAmount,
        address receiver,
        address owner
    ) external override onlyRole(DSTAKE_TOKEN_ROLE) {
        address adapterAddress = vaultAssetToAdapter[defaultDepositVaultAsset];
        if (adapterAddress == address(0)) {
            revert AdapterNotFound(defaultDepositVaultAsset);
        }
        IDStableConversionAdapter adapter = IDStableConversionAdapter(
            adapterAddress
        );

        // 1. Determine vault asset and required amount
        address vaultAsset = adapter.vaultAsset();
        // Use previewConvertFromVaultAsset to get the required vaultAssetAmount for the target dStableAmount
        uint256 vaultAssetAmount = IERC4626(vaultAsset).previewWithdraw(
            dStableAmount
        );
        if (vaultAssetAmount == 0) revert ZeroPreviewWithdrawAmount(vaultAsset);

        // 2. Pull vaultAsset from collateral vault
        collateralVault.sendAsset(vaultAsset, vaultAssetAmount, address(this));

        // 3. Approve adapter (use forceApprove for external vault assets)
        IERC20(vaultAsset).forceApprove(adapterAddress, vaultAssetAmount);

        // 4. Call adapter to convert and send dStable to receiver
        // Temporarily transfer to this contract, then forward to receiver if needed
        uint256 receivedDStable = adapter.convertFromVaultAsset(
            vaultAssetAmount
        );

        // Sanity check: Ensure adapter returned at least the requested amount
        if (receivedDStable < dStableAmount) {
            revert InsufficientDStableFromAdapter(
                vaultAsset,
                dStableAmount,
                receivedDStable
            );
        }

        // 5. Transfer ONLY the requested amount to the user
        IERC20(dStable).safeTransfer(receiver, dStableAmount);

        // 6. If adapter over-delivered, immediately convert the surplus dStable
        //    back into vault-asset shares so the value is reflected in
        //    totalAssets() for all shareholders.
        uint256 surplus = receivedDStable - dStableAmount;
        if (surplus > 0) {
            // Give the adapter allowance to pull the surplus (standard approve for trusted dStable)
            IERC20(dStable).approve(adapterAddress, surplus);

            // Attempt to recycle surplus; on failure hold it in the router
            try adapter.convertToVaultAsset(surplus) returns (
                address mintedAsset,
                uint256 /* mintedAmount */
            ) {
                // Sanity: adapter must mint the same asset we just redeemed from
                if (mintedAsset != vaultAsset) {
                    revert AdapterAssetMismatch(
                        adapterAddress,
                        vaultAsset,
                        mintedAsset
                    );
                }
            } catch {
                // Clear approval in case of revert and keep surplus inside router
                IERC20(dStable).approve(adapterAddress, 0);
                emit SurplusHeld(surplus);
            }
            // If success: shares minted directly to collateralVault; surplus value captured
        }

        emit Withdrawn(
            vaultAsset,
            vaultAssetAmount,
            dStableAmount,
            owner,
            receiver
        );
    }

    // --- External Functions (Exchange/Rebalance) ---

    /**
     * @notice Exchanges `fromVaultAssetAmount` of one vault asset for another via their adapters.
     * @dev Uses dSTABLE as the intermediary asset. Requires COLLATERAL_EXCHANGER_ROLE.
     * @param fromVaultAsset The address of the asset to sell.
     * @param toVaultAsset The address of the asset to buy.
     * @param fromVaultAssetAmount The amount of the `fromVaultAsset` to exchange.
     * @param minToVaultAssetAmount The minimum amount of `toVaultAsset` the solver is willing to accept.
     */
    function exchangeAssetsUsingAdapters(
        address fromVaultAsset,
        address toVaultAsset,
        uint256 fromVaultAssetAmount,
        uint256 minToVaultAssetAmount
    ) external onlyRole(COLLATERAL_EXCHANGER_ROLE) {
        address fromAdapterAddress = vaultAssetToAdapter[fromVaultAsset];
        address toAdapterAddress = vaultAssetToAdapter[toVaultAsset];
        if (fromAdapterAddress == address(0))
            revert AdapterNotFound(fromVaultAsset);
        if (toAdapterAddress == address(0))
            revert AdapterNotFound(toVaultAsset);

        IDStableConversionAdapter fromAdapter = IDStableConversionAdapter(
            fromAdapterAddress
        );
        IDStableConversionAdapter toAdapter = IDStableConversionAdapter(
            toAdapterAddress
        );

        // 1. Get assets and calculate equivalent dStable amount
        uint256 dStableAmountEquivalent = fromAdapter
            .previewConvertFromVaultAsset(fromVaultAssetAmount);

        // 2. Pull fromVaultAsset from collateral vault
        collateralVault.sendAsset(
            fromVaultAsset,
            fromVaultAssetAmount,
            address(this)
        );

        // 3. Approve fromAdapter (use forceApprove for external vault assets) & Convert fromVaultAsset -> dStable (sent to this router)
        IERC20(fromVaultAsset).forceApprove(
            fromAdapterAddress,
            fromVaultAssetAmount
        );
        uint256 receivedDStable = fromAdapter.convertFromVaultAsset(
            fromVaultAssetAmount
        );

        // 4. Approve toAdapter (standard approve for trusted dStable) & Convert dStable -> toVaultAsset (sent to collateralVault)
        IERC20(dStable).approve(toAdapterAddress, receivedDStable);
        (
            address actualToVaultAsset,
            uint256 resultingToVaultAssetAmount
        ) = toAdapter.convertToVaultAsset(receivedDStable);
        if (actualToVaultAsset != toVaultAsset) {
            revert AdapterAssetMismatch(
                toAdapterAddress,
                toVaultAsset,
                actualToVaultAsset
            );
        }
        // Slippage control: ensure output meets minimum requirement
        if (resultingToVaultAssetAmount < minToVaultAssetAmount) {
            revert SlippageCheckFailed(
                toVaultAsset,
                resultingToVaultAssetAmount,
                minToVaultAssetAmount
            );
        }

        // --- Underlying value parity check ---
        uint256 resultingDStableEquivalent = toAdapter
            .previewConvertFromVaultAsset(resultingToVaultAssetAmount);

        // Rely on Solidity 0.8 checked arithmetic: if `dustTolerance` is greater than
        // `dStableAmountEquivalent`, the subtraction will underflow and the transaction
        // will revert automatically. This saves gas compared to a ternary guard.
        uint256 minRequiredDStable = dStableAmountEquivalent - dustTolerance;

        if (resultingDStableEquivalent < minRequiredDStable) {
            revert SlippageCheckFailed(
                dStable,
                resultingDStableEquivalent,
                minRequiredDStable
            );
        }

        emit Exchanged(
            fromVaultAsset,
            toVaultAsset,
            fromVaultAssetAmount,
            resultingToVaultAssetAmount,
            dStableAmountEquivalent,
            msg.sender
        );
    }

    /**
     * @notice Exchanges assets between the collateral vault and an external solver.
     * @dev Pulls `fromVaultAsset` from the solver (`msg.sender`) and sends `toVaultAsset` from the vault to the solver.
     *      Requires COLLATERAL_EXCHANGER_ROLE.
     * @param fromVaultAsset The address of the asset the solver is providing.
     * @param toVaultAsset The address of the asset the solver will receive from the vault.
     * @param fromVaultAssetAmount The amount of `fromVaultAsset` provided by the solver.
     * @param minToVaultAssetAmount The minimum amount of `toVaultAsset` the solver is willing to accept.
     */
    function exchangeAssets(
        address fromVaultAsset,
        address toVaultAsset,
        uint256 fromVaultAssetAmount,
        uint256 minToVaultAssetAmount
    ) external onlyRole(COLLATERAL_EXCHANGER_ROLE) {
        if (fromVaultAssetAmount == 0) {
            revert InconsistentState("Input amount cannot be zero");
        }
        if (fromVaultAsset == address(0) || toVaultAsset == address(0)) {
            revert ZeroAddress();
        }

        ExchangeLocals memory locals;

        // Resolve adapters
        locals.fromAdapterAddress = vaultAssetToAdapter[fromVaultAsset];
        locals.toAdapterAddress = vaultAssetToAdapter[toVaultAsset];

        if (locals.fromAdapterAddress == address(0))
            revert AdapterNotFound(fromVaultAsset);
        if (locals.toAdapterAddress == address(0))
            revert AdapterNotFound(toVaultAsset);

        locals.fromAdapter = IDStableConversionAdapter(
            locals.fromAdapterAddress
        );
        locals.toAdapter = IDStableConversionAdapter(locals.toAdapterAddress);

        // Calculate dStable received for the input asset
        locals.dStableValueIn = locals.fromAdapter.previewConvertFromVaultAsset(
            fromVaultAssetAmount
        );
        if (locals.dStableValueIn == 0) {
            revert ZeroInputDStableValue(fromVaultAsset, fromVaultAssetAmount);
        }

        // Calculate expected output vault asset amount
        (address expectedToAsset, uint256 tmpToAmount) = locals
            .toAdapter
            .previewConvertToVaultAsset(locals.dStableValueIn);

        if (expectedToAsset != toVaultAsset) {
            revert AdapterAssetMismatch(
                locals.toAdapterAddress,
                toVaultAsset,
                expectedToAsset
            );
        }

        locals.calculatedToVaultAssetAmount = tmpToAmount;

        // Slippage check
        if (locals.calculatedToVaultAssetAmount < minToVaultAssetAmount) {
            revert SlippageCheckFailed(
                toVaultAsset,
                locals.calculatedToVaultAssetAmount,
                minToVaultAssetAmount
            );
        }

        // --- Asset movements ---

        // 1. Pull `fromVaultAsset` from solver to this contract
        IERC20(fromVaultAsset).safeTransferFrom(
            msg.sender,
            address(this),
            fromVaultAssetAmount
        );

        // 2. Transfer the asset into the collateral vault
        IERC20(fromVaultAsset).safeTransfer(
            address(collateralVault),
            fromVaultAssetAmount
        );

        // 3. Send the calculated amount of `toVaultAsset` to the solver
        collateralVault.sendAsset(
            toVaultAsset,
            locals.calculatedToVaultAssetAmount,
            msg.sender
        );

        emit Exchanged(
            fromVaultAsset,
            toVaultAsset,
            fromVaultAssetAmount,
            locals.calculatedToVaultAssetAmount,
            locals.dStableValueIn,
            msg.sender
        );
    }

    // --- External Functions (Governance - Managed by Admin) ---

    /**
     * @notice Adds or updates a conversion adapter for a given vault asset.
     * @dev Only callable by an address with DEFAULT_ADMIN_ROLE.
     * @param vaultAsset The address of the vault asset.
     * @param adapterAddress The address of the new adapter contract.
     */
    function addAdapter(
        address vaultAsset,
        address adapterAddress
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (adapterAddress == address(0) || vaultAsset == address(0)) {
            revert ZeroAddress();
        }
        address adapterVaultAsset = IDStableConversionAdapter(adapterAddress)
            .vaultAsset();
        if (adapterVaultAsset != vaultAsset)
            revert AdapterAssetMismatch(
                adapterAddress,
                vaultAsset,
                adapterVaultAsset
            );
        if (
            vaultAssetToAdapter[vaultAsset] != address(0) &&
            vaultAssetToAdapter[vaultAsset] != adapterAddress
        ) {
            revert VaultAssetManagedByDifferentAdapter(
                vaultAsset,
                vaultAssetToAdapter[vaultAsset]
            );
        }
        vaultAssetToAdapter[vaultAsset] = adapterAddress;

        // Inform the collateral vault of the new supported asset list (no-op if already added)
        try collateralVault.addSupportedAsset(vaultAsset) {} catch {}

        emit AdapterSet(vaultAsset, adapterAddress);
    }

    /**
     * @notice Removes a conversion adapter for a given vault asset.
     * @dev Only callable by an address with DEFAULT_ADMIN_ROLE.
     * @dev Does not automatically migrate funds. Ensure assets managed by this adapter are zero
     *      in the collateral vault or migrated via exchangeAssets before calling.
     * @param vaultAsset The address of the vault asset to remove.
     */
    function removeAdapter(
        address vaultAsset
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        address adapterAddress = vaultAssetToAdapter[vaultAsset];
        if (adapterAddress == address(0)) {
            revert AdapterNotFound(vaultAsset);
        }
        delete vaultAssetToAdapter[vaultAsset];

        // Inform the collateral vault to remove supported asset.
        collateralVault.removeSupportedAsset(vaultAsset);

        emit AdapterRemoved(vaultAsset, adapterAddress);
    }

    /**
     * @notice Sets the default vault asset to use for new deposits.
     * @dev Only callable by an address with DEFAULT_ADMIN_ROLE.
     * @param vaultAsset The address of the vault asset to set as default.
     */
    function setDefaultDepositVaultAsset(
        address vaultAsset
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (vaultAssetToAdapter[vaultAsset] == address(0)) {
            revert AdapterNotFound(vaultAsset);
        }
        defaultDepositVaultAsset = vaultAsset;
        emit DefaultDepositVaultAssetSet(vaultAsset);
    }

    // --- Events ---
    event RouterDeposit(
        address indexed adapter,
        address indexed vaultAsset,
        address indexed dStakeToken,
        uint256 vaultAssetAmount,
        uint256 dStableAmount
    );
    event Withdrawn(
        address indexed vaultAsset,
        uint256 vaultAssetAmount,
        uint256 dStableAmount,
        address owner,
        address receiver
    );
    event Exchanged(
        address indexed fromAsset,
        address indexed toAsset,
        uint256 fromAssetAmount,
        uint256 toAssetAmount,
        uint256 dStableAmountEquivalent,
        address indexed exchanger
    );
    event AdapterSet(address indexed vaultAsset, address adapterAddress);
    event AdapterRemoved(address indexed vaultAsset, address adapterAddress);
    event DefaultDepositVaultAssetSet(address indexed vaultAsset);
    event DustToleranceSet(uint256 newDustTolerance);
    event SurplusHeld(uint256 amount);
    event SurplusSwept(uint256 amount, address vaultAsset);

    // --- Governance setters ---

    /**
     * @notice Updates the `dustTolerance` used for value-parity checks.
     * @dev Only callable by DEFAULT_ADMIN_ROLE.
     * @param _dustTolerance The new tolerance value in wei of dStable.
     */
    function setDustTolerance(
        uint256 _dustTolerance
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        dustTolerance = _dustTolerance;
        emit DustToleranceSet(_dustTolerance);
    }

    /**
     * @notice Sweeps any dSTABLE surplus held by the router back into the default vault asset.
     * @param maxAmount Maximum amount of dSTABLE to sweep (use 0 to sweep full balance).
     */
    function sweepSurplus(
        uint256 maxAmount
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        uint256 balance = IERC20(dStable).balanceOf(address(this));
        if (balance == 0) revert ZeroInputDStableValue(dStable, 0);

        uint256 amountToSweep = (maxAmount == 0 || maxAmount > balance)
            ? balance
            : maxAmount;

        address adapterAddress = vaultAssetToAdapter[defaultDepositVaultAsset];
        if (adapterAddress == address(0))
            revert AdapterNotFound(defaultDepositVaultAsset);

        IDStableConversionAdapter adapter = IDStableConversionAdapter(
            adapterAddress
        );
        address vaultAsset = adapter.vaultAsset();

        IERC20(dStable).approve(adapterAddress, amountToSweep);
        (address mintedAsset, ) = adapter.convertToVaultAsset(amountToSweep);

        if (mintedAsset != vaultAsset) {
            revert AdapterAssetMismatch(
                adapterAddress,
                vaultAsset,
                mintedAsset
            );
        }

        emit SurplusSwept(amountToSweep, mintedAsset);
    }
}

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

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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.
     */
    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.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

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

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

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

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

pragma solidity ^0.8.20;

/**
 * @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 ReentrancyGuard {
    // 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;

    uint256 private _status;

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

    constructor() {
        _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 {
        // 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 {
        // 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) {
        return _status == ENTERED;
    }
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * 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[EIP 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);
}

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

pragma solidity ^0.8.20;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes32 value => uint256) _positions;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

            if (valueIndex != lastIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

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

import {IERC20} from "@openzeppelin/contracts-5/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts-5/token/ERC20/utils/SafeERC20.sol";
import {IDStakeCollateralVault} from "./interfaces/IDStakeCollateralVault.sol";
import {IDStableConversionAdapter} from "./interfaces/IDStableConversionAdapter.sol";
import {AccessControl} from "@openzeppelin/contracts-5/access/AccessControl.sol";
import {EnumerableSet} from "@openzeppelin/contracts-5/utils/structs/EnumerableSet.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts-5/utils/ReentrancyGuard.sol";

// ---------------------------------------------------------------------------
// Internal interface to query the router's public mapping without importing the
// full router contract (avoids circular dependencies).
// ---------------------------------------------------------------------------
interface IAdapterProvider {
    function vaultAssetToAdapter(address) external view returns (address);
}

/**
 * @title DStakeCollateralVault
 * @notice Holds various yield-bearing/convertible ERC20 tokens (`vault assets`) managed by dSTAKE.
 * @dev Calculates the total value of these assets in terms of the underlying dStable asset
 *      using registered adapters. This contract is non-upgradeable but replaceable via
 *      DStakeToken governance.
 *      Uses AccessControl for role-based access control.
 */
contract DStakeCollateralVault is
    IDStakeCollateralVault,
    AccessControl,
    ReentrancyGuard
{
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    // --- Roles ---
    bytes32 public constant ROUTER_ROLE = keccak256("ROUTER_ROLE");

    // --- Errors ---
    error ZeroAddress();
    error AssetNotSupported(address asset);
    error AssetAlreadySupported(address asset);
    error NonZeroBalance(address asset);
    error CannotRescueRestrictedToken(address token);
    error ETHTransferFailed(address receiver, uint256 amount);

    // --- Events ---
    event TokenRescued(
        address indexed token,
        address indexed receiver,
        uint256 amount
    );
    event ETHRescued(address indexed receiver, uint256 amount);

    // --- State ---
    address public immutable dStakeToken; // The DStakeToken this vault serves
    address public immutable dStable; // The underlying dStable asset address

    address public router; // The DStakeRouter allowed to interact

    EnumerableSet.AddressSet private _supportedAssets; // Set of supported vault assets

    // --- Constructor ---
    constructor(address _dStakeVaultShare, address _dStableAsset) {
        if (_dStakeVaultShare == address(0) || _dStableAsset == address(0)) {
            revert ZeroAddress();
        }
        dStakeToken = _dStakeVaultShare;
        dStable = _dStableAsset;

        // Set up the DEFAULT_ADMIN_ROLE initially to the contract deployer
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    // --- External Views (IDStakeCollateralVault Interface) ---

    /**
     * @inheritdoc IDStakeCollateralVault
     */
    function totalValueInDStable()
        external
        view
        override
        returns (uint256 dStableValue)
    {
        uint256 totalValue = 0;
        uint256 len = _supportedAssets.length();
        for (uint256 i = 0; i < len; i++) {
            address vaultAsset = _supportedAssets.at(i);
            address adapterAddress = IAdapterProvider(router)
                .vaultAssetToAdapter(vaultAsset);

            if (adapterAddress == address(0)) {
                // If there is no adapter configured, simply skip this asset to
                // preserve liveness. Anyone can dust this vault and we cannot
                // enforce that all assets have adapters before removal
                continue;
            }

            uint256 balance = IERC20(vaultAsset).balanceOf(address(this));
            if (balance > 0) {
                totalValue += IDStableConversionAdapter(adapterAddress)
                    .assetValueInDStable(vaultAsset, balance);
            }
        }
        return totalValue;
    }

    // --- External Functions (Router Interactions) ---

    /**
     * @notice Transfers `amount` of `vaultAsset` from this vault to `recipient`.
     * @dev Only callable by the registered router (ROUTER_ROLE).
     */
    function sendAsset(
        address vaultAsset,
        uint256 amount,
        address recipient
    ) external onlyRole(ROUTER_ROLE) {
        if (!_isSupported(vaultAsset)) revert AssetNotSupported(vaultAsset);
        IERC20(vaultAsset).safeTransfer(recipient, amount);
    }

    /**
     * @notice Adds a new supported vault asset. Can only be invoked by the router.
     */
    function addSupportedAsset(
        address vaultAsset
    ) external onlyRole(ROUTER_ROLE) {
        if (vaultAsset == address(0)) revert ZeroAddress();
        if (_isSupported(vaultAsset)) revert AssetAlreadySupported(vaultAsset);

        _supportedAssets.add(vaultAsset);
        emit SupportedAssetAdded(vaultAsset);
    }

    /**
     * @notice Removes a supported vault asset. Can only be invoked by the router.
     */
    function removeSupportedAsset(
        address vaultAsset
    ) external onlyRole(ROUTER_ROLE) {
        if (!_isSupported(vaultAsset)) revert AssetNotSupported(vaultAsset);
        // NOTE: Previously this function reverted if the vault still held a
        // non-zero balance of the asset, causing a griefing / DoS vector:
        // anyone could deposit 1 wei of the token to block removal. The
        // check has been removed so governance can always delist an asset.

        _supportedAssets.remove(vaultAsset);
        emit SupportedAssetRemoved(vaultAsset);
    }

    // --- Governance Functions ---

    /**
     * @notice Sets the router address. Grants ROUTER_ROLE to new router and
     *         revokes it from the previous router.
     */
    function setRouter(
        address _newRouter
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_newRouter == address(0)) revert ZeroAddress();

        // Revoke role from old router
        if (router != address(0)) {
            _revokeRole(ROUTER_ROLE, router);
        }

        _grantRole(ROUTER_ROLE, _newRouter);
        router = _newRouter;
        emit RouterSet(_newRouter);
    }

    // --- Internal Utilities ---

    function _isSupported(address asset) private view returns (bool) {
        return _supportedAssets.contains(asset);
    }

    // --- External Views ---

    /**
     * @notice Returns the vault asset at `index` from the internal supported set.
     *         Kept for backwards-compatibility with the previous public array getter.
     */
    function supportedAssets(
        uint256 index
    ) external view override returns (address) {
        return _supportedAssets.at(index);
    }

    /**
     * @notice Returns the entire list of supported vault assets. Useful for UIs & off-chain tooling.
     */
    function getSupportedAssets() external view returns (address[] memory) {
        return _supportedAssets.values();
    }

    // --- Recovery Functions ---

    /**
     * @notice Rescues tokens accidentally sent to the contract
     * @dev Cannot rescue supported vault assets or the dStable token
     * @param token Address of the token to rescue
     * @param receiver Address to receive the rescued tokens
     * @param amount Amount of tokens to rescue
     */
    function rescueToken(
        address token,
        address receiver,
        uint256 amount
    ) external onlyRole(DEFAULT_ADMIN_ROLE) nonReentrant {
        if (receiver == address(0)) revert ZeroAddress();

        // Check if token is a supported asset
        if (_isSupported(token)) {
            revert CannotRescueRestrictedToken(token);
        }

        // Check if token is the dStable token
        if (token == dStable) {
            revert CannotRescueRestrictedToken(token);
        }

        // Rescue the token
        IERC20(token).safeTransfer(receiver, amount);
        emit TokenRescued(token, receiver, amount);
    }

    /**
     * @notice Rescues ETH accidentally sent to the contract
     * @param receiver Address to receive the rescued ETH
     * @param amount Amount of ETH to rescue
     */
    function rescueETH(
        address receiver,
        uint256 amount
    ) external onlyRole(DEFAULT_ADMIN_ROLE) nonReentrant {
        if (receiver == address(0)) revert ZeroAddress();

        (bool success, ) = receiver.call{value: amount}("");
        if (!success) revert ETHTransferFailed(receiver, amount);

        emit ETHRescued(receiver, amount);
    }

    /**
     * @notice Returns the list of tokens that cannot be rescued
     * @return restrictedTokens Array of restricted token addresses
     */
    function getRestrictedRescueTokens()
        external
        view
        returns (address[] memory)
    {
        address[] memory assets = _supportedAssets.values();
        address[] memory restrictedTokens = new address[](assets.length + 1);

        // Add all supported assets
        for (uint256 i = 0; i < assets.length; i++) {
            restrictedTokens[i] = assets[i];
        }

        // Add dStable token
        restrictedTokens[assets.length] = dStable;

        return restrictedTokens;
    }

    /**
     * @notice Allows the contract to receive ETH
     */
    receive() external payable {}
}

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

/**
 * @title IDStableConversionAdapter Interface
 * @notice Interface for contracts that handle the conversion between the core dStable asset
 *         and a specific yield-bearing or convertible ERC20 token (`vault asset`), as well as
 *         valuing that `vault asset` in terms of the dStable asset.
 * @dev Implementations interact with specific protocols (lending pools, DEX LPs, wrappers, etc.).
 */
interface IDStableConversionAdapter {
    /**
     * @notice Converts a specified amount of the dStable asset into the specific `vaultAsset`
     *         managed by this adapter.
     * @dev The adapter MUST pull `dStableAmount` of the dStable asset from the caller (expected to be the Router).
     * @dev The resulting `vaultAsset` MUST be sent/deposited/minted directly to the `collateralVault` address provided during adapter setup or retrieved.
     * @param dStableAmount The amount of dStable asset to convert.
     * @return vaultAsset The address of the specific `vault asset` token managed by this adapter.
     * @return vaultAssetAmount The amount of `vaultAsset` generated from the conversion.
     */
    function convertToVaultAsset(
        uint256 dStableAmount
    ) external returns (address vaultAsset, uint256 vaultAssetAmount);

    /**
     * @notice Converts a specific amount of `vaultAsset` back into the dStable asset.
     * @dev The adapter MUST pull the required amount of `vaultAsset` from the caller (expected to be the Router).
     * @dev The resulting dStable asset MUST be sent to the caller.
     * @param vaultAssetAmount The amount of `vaultAsset` to convert.
     * @return dStableAmount The amount of dStable asset sent to the caller.
     */
    function convertFromVaultAsset(
        uint256 vaultAssetAmount
    ) external returns (uint256 dStableAmount);

    /**
     * @notice Preview the result of converting a given dStable amount to vaultAsset (without state change).
     * @param dStableAmount The amount of dStable asset to preview conversion for.
     * @return vaultAsset The address of the specific `vault asset` token managed by this adapter.
     * @return vaultAssetAmount The amount of `vaultAsset` that would be received.
     */
    function previewConvertToVaultAsset(
        uint256 dStableAmount
    ) external view returns (address vaultAsset, uint256 vaultAssetAmount);

    /**
     * @notice Preview the result of converting a given vaultAsset amount to dStable (without state change).
     * @param vaultAssetAmount The amount of `vaultAsset` to preview conversion for.
     * @return dStableAmount The amount of dStable asset that would be received.
     */
    function previewConvertFromVaultAsset(
        uint256 vaultAssetAmount
    ) external view returns (uint256 dStableAmount);

    /**
     * @notice Calculates the value of a given amount of the specific `vaultAsset` managed by this adapter
     *         in terms of the dStable asset.
     * @param vaultAsset The address of the vault asset token (should match getVaultAsset()). Included for explicitness.
     * @param vaultAssetAmount The amount of the `vaultAsset` to value.
     * @return dStableValue The equivalent value in the dStable asset.
     */
    function assetValueInDStable(
        address vaultAsset,
        uint256 vaultAssetAmount
    ) external view returns (uint256 dStableValue);

    /**
     * @notice Returns the address of the specific `vault asset` token managed by this adapter.
     * @return The address of the `vault asset`.
     */
    function vaultAsset() external view returns (address);
}

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

/**
 * @title IDStakeCollateralVault Interface
 * @notice Defines the external functions of the DStakeCollateralVault required by other
 *         contracts in the dSTAKE system, primarily the DStakeToken.
 */
interface IDStakeCollateralVault {
    /**
     * @notice Calculates the total value of all managed `vault assets` held by the vault,
     *         denominated in the underlying dStable asset.
     * @dev This is typically called by the DStakeToken's `totalAssets()` function.
     * @return dStableValue The total value of managed assets in terms of the dStable asset.
     */
    function totalValueInDStable() external view returns (uint256 dStableValue);

    /**
     * @notice Returns the address of the underlying dStable asset the vault operates with.
     * @return The address of the dStable asset.
     */
    function dStable() external view returns (address);

    /**
     * @notice The DStakeToken contract address this vault serves.
     */
    function dStakeToken() external view returns (address);

    /**
     * @notice The DStakeRouter contract address allowed to interact.
     */
    function router() external view returns (address);

    /**
     * @notice Returns the vault asset at `index` from the internal supported list.
     */
    function supportedAssets(uint256 index) external view returns (address);

    /**
     * @notice Returns the entire list of supported vault assets. Convenient for UIs & off-chain analytics.
     */
    function getSupportedAssets() external view returns (address[] memory);

    /**
     * @notice Transfers `amount` of `vaultAsset` from this vault to the `recipient`.
     * @dev Only callable by the registered router.
     * @param vaultAsset The address of the vault asset to send.
     * @param amount The amount to send.
     * @param recipient The address to receive the asset.
     */
    function sendAsset(
        address vaultAsset,
        uint256 amount,
        address recipient
    ) external;

    /**
     * @notice Sets the address of the DStakeRouter contract.
     * @dev Only callable by an address with the DEFAULT_ADMIN_ROLE.
     * @param _newRouter The address of the new router contract.
     */
    function setRouter(address _newRouter) external;

    /**
     * @notice Adds a vault asset to the supported list. Callable only by the router.
     */
    function addSupportedAsset(address vaultAsset) external;

    /**
     * @notice Removes a vault asset from the supported list. Callable only by the router.
     */
    function removeSupportedAsset(address vaultAsset) external;

    /**
     * @notice Emitted when the router address is set.
     * @param router The address of the new router.
     */
    event RouterSet(address indexed router);

    /**
     * @notice Emitted when a new vault asset is added to the supported list.
     */
    event SupportedAssetAdded(address indexed vaultAsset);

    /**
     * @notice Emitted when a vault asset is removed from the supported list.
     */
    event SupportedAssetRemoved(address indexed vaultAsset);
}

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

/**
 * @title IDStakeRouter Interface
 * @notice Defines the external functions of the DStakeRouter required by the DStakeToken
 *         for handling deposits and withdrawals.
 */
interface IDStakeRouter {
    /**
     * @notice Handles the conversion of deposited dStable asset into a chosen `vaultAsset`
     *         and informs the collateral vault.
     * @dev Called by `DStakeToken._deposit()` after the token has received the dStable asset.
     * @dev The router MUST pull `dStableAmount` from the caller (`DStakeToken`).
     * @param dStableAmount The amount of dStable asset deposited by the user into the DStakeToken.
     */
    function deposit(uint256 dStableAmount) external;

    /**
     * @notice Handles the conversion of a `vaultAsset` back into the dStable asset for withdrawal.
     * @dev Called by `DStakeToken._withdraw()`.
     * @dev The router coordinates pulling the required `vaultAsset` from the collateral vault
     *      and ensuring the converted dStable asset is sent to the `receiver`.
     * @param dStableAmount The amount of dStable asset to be withdrawn to the `receiver` (after vault fees).
     * @param receiver The address that will receive the withdrawn dStable asset.
     * @param owner The original owner initiating the withdrawal (typically the user burning shares).
     */
    function withdraw(
        uint256 dStableAmount,
        address receiver,
        address owner
    ) external;
}

Settings
{
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "viaIR": true,
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_dStakeToken","type":"address"},{"internalType":"address","name":"_collateralVault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"address","name":"expectedAsset","type":"address"},{"internalType":"address","name":"actualAsset","type":"address"}],"name":"AdapterAssetMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"}],"name":"AdapterNotFound","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"InconsistentState","type":"error"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"},{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"InsufficientDStableFromAdapter","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"address","name":"toAsset","type":"address"},{"internalType":"uint256","name":"calculatedAmount","type":"uint256"},{"internalType":"uint256","name":"minAmount","type":"uint256"}],"name":"SlippageCheckFailed","type":"error"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"},{"internalType":"address","name":"existingAdapter","type":"address"}],"name":"VaultAssetManagedByDifferentAdapter","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[{"internalType":"address","name":"fromAsset","type":"address"},{"internalType":"uint256","name":"fromAmount","type":"uint256"}],"name":"ZeroInputDStableValue","type":"error"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"}],"name":"ZeroPreviewWithdrawAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vaultAsset","type":"address"},{"indexed":false,"internalType":"address","name":"adapterAddress","type":"address"}],"name":"AdapterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vaultAsset","type":"address"},{"indexed":false,"internalType":"address","name":"adapterAddress","type":"address"}],"name":"AdapterSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vaultAsset","type":"address"}],"name":"DefaultDepositVaultAssetSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newDustTolerance","type":"uint256"}],"name":"DustToleranceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fromAsset","type":"address"},{"indexed":true,"internalType":"address","name":"toAsset","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromAssetAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toAssetAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dStableAmountEquivalent","type":"uint256"},{"indexed":true,"internalType":"address","name":"exchanger","type":"address"}],"name":"Exchanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"},{"indexed":true,"internalType":"address","name":"vaultAsset","type":"address"},{"indexed":true,"internalType":"address","name":"dStakeToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"vaultAssetAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dStableAmount","type":"uint256"}],"name":"RouterDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SurplusHeld","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"vaultAsset","type":"address"}],"name":"SurplusSwept","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vaultAsset","type":"address"},{"indexed":false,"internalType":"uint256","name":"vaultAssetAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dStableAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"COLLATERAL_EXCHANGER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DSTAKE_TOKEN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"},{"internalType":"address","name":"adapterAddress","type":"address"}],"name":"addAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateralVault","outputs":[{"internalType":"contract IDStakeCollateralVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dStable","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dStakeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultDepositVaultAsset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"dStableAmount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dustTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"fromVaultAsset","type":"address"},{"internalType":"address","name":"toVaultAsset","type":"address"},{"internalType":"uint256","name":"fromVaultAssetAmount","type":"uint256"},{"internalType":"uint256","name":"minToVaultAssetAmount","type":"uint256"}],"name":"exchangeAssets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"fromVaultAsset","type":"address"},{"internalType":"address","name":"toVaultAsset","type":"address"},{"internalType":"uint256","name":"fromVaultAssetAmount","type":"uint256"},{"internalType":"uint256","name":"minToVaultAssetAmount","type":"uint256"}],"name":"exchangeAssetsUsingAdapters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"}],"name":"removeAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vaultAsset","type":"address"}],"name":"setDefaultDepositVaultAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_dustTolerance","type":"uint256"}],"name":"setDustTolerance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"name":"sweepSurplus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaultAssetToAdapter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"dStableAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e06040908082523462000175578181620024f78038038091620000248285620001aa565b83398101031262000175576200004860206200004083620001e4565b9201620001e4565b600180556001600160a01b03908282161580156200019f575b6200018e5760208260049285608052168060a0528551928380926306617c6960e11b82525afa90811562000183576000916200013c575b508060c05216156200012b57620000bb90620000b433620001f9565b5062000279565b50516121bb90816200031c8239608051816113c9015260a05181818161031a0152818161076f01528181610b1c015281816112a80152818161145c015281816117d80152611aed015260c0518181816103e5015281816107c901528181610bce01528181610f950152611aa80152f35b815163d92e233d60e01b8152600490fd5b90506020813d6020116200017a575b816200015a60209383620001aa565b8101031262000175576200016e90620001e4565b3862000098565b600080fd5b3d91506200014b565b84513d6000823e3d90fd5b835163d92e233d60e01b8152600490fd5b508181161562000061565b601f909101601f19168101906001600160401b03821190821017620001ce57604052565b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b03821682036200017557565b6001600160a01b031660008181527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205490919060ff166200027557818052816020526040822081835260205260408220600160ff198254161790553391600080516020620024d78339815191528180a4600190565b5090565b6001600160a01b031660008181527fee6598bb9d8813ec5dcf0988fbc9935f3bd23c22de3e37b2654f2216372e6c0860205260408120549091907f7fee0d6ae731e4c26a7bffbf1bb702cb3aaa110506f5b2a78cc9372669d439ae9060ff166200031657808352826020526040832082845260205260408320600160ff19825416179055600080516020620024d7833981519152339380a4600190565b50509056fe608080604052600436101561001357600080fd5b600090813560e01c90816301ffc9a714611b1c575080630bece79c14611ad75780630cc2f8d214611a925780631e99981414611a745780632379e45214611639578063248a9ca31461160d5780632f2ff15d146115d057806336568abe146115885780633a5d64c51461150d578063585cd34b146113f85780635c47df42146113b35780636dacd3d7146111f157806391d14854146111a65780639bb9461f14610f59578063a217fddf14610f3d578063b460af9414610a61578063b6b55f25146106f3578063b9c7e7a514610295578063bc6d5a101461025a578063c8232bd71461021e578063d547741f146101dd578063dc369c651461018f578063e1e6548d146101665763ee1f70441461012957600080fd5b3461016357806003193601126101635760206040517f3a4b3a1f03347d0616bb4d34491485029b5c8f56cd6dc1f9e9b1524cad0936f78152f35b80fd5b50346101635780600319360112610163576003546040516001600160a01b039091168152602090f35b5034610163576020366003190112610163577fbd575a5650fa5dbcfe03ab798aec3c80a935c6d293729c1ede529f46efbfbd4760206004356101cf611d08565b80600155604051908152a180f35b50346101635760403660031901126101635761021a6004356101fd611b71565b90808452836020526102156001604086200154611d9e565b611ede565b5080f35b5034610163576020366003190112610163576020906001600160a01b039060409082610248611b87565b16815260028452205416604051908152f35b503461016357806003193601126101635760206040517f7fee0d6ae731e4c26a7bffbf1bb702cb3aaa110506f5b2a78cc9372669d439ae8152f35b5034610163576102a436611b9d565b90926102ae611c8e565b60018060a01b0380821692838752602090600282528260408920541683871696878a528460408b2054169282156106da5783156106c157908a9392916040519763e0e5c1ab60e01b93848a528c60048b0152878a602481845afa998a1561067f57879a61068e575b50887f000000000000000000000000000000000000000000000000000000000000000016803b1561068a57604051631c7fc97360e11b81526001600160a01b03939093166004840152602483018e905230604484015287908390606490829084905af1801561067f5788928891610662575b50506103958d828d611f53565b60248d604051988993849263508fef7760e11b845260048401525af1948515610657578c95610628575b5060405163095ea7b360e01b81526001600160a01b0385166004820152602481018690527f0000000000000000000000000000000000000000000000000000000000000000958d918881604481868e8d165af1801561061d576105f0575b50604051906254772560e21b82526004820152604081602481858a5af19889156105e5578c91839a6105ae575b5082160361057b575080871061054c575050839060246040518094819382528860048301525afa92831561054157899361050c575b505061048d60015485611c6b565b8083106104d95750506040805196875260208701929092525084015233927f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539080606081015b0390a480f35b604051636f85e6ff60e11b81526001600160a01b0392909216600483015260248201929092526044810191909152606490fd5b9080929350813d831161053a575b6105248183611c00565b81010312610535575190388061047f565b600080fd5b503d61051a565b6040513d8b823e3d90fd5b604051636f85e6ff60e11b81526001600160a01b03929092166004830152602482018790526044820152606490fd5b60405163e8eebd3760e01b81526001600160a01b0386811660048301528481166024830152919091166044820152606490fd5b9099506105d491925060403d6040116105de575b6105cc8183611c00565b810190611c36565b919091983861044a565b503d6105c2565b6040513d84823e3d90fd5b61060f90893d8b11610616575b6106078183611c00565b810190611c53565b503861041d565b503d6105fd565b6040513d85823e3d90fd5b9094508581813d8311610650575b6106408183611c00565b81010312610535575193386103bf565b503d610636565b6040513d8e823e3d90fd5b61066e91929350611bd6565b61067b5786908638610388565b8580fd5b6040513d89823e3d90fd5b8780fd5b8880929b508198503d83116106ba575b6106a88183611c00565b81010312610535578c95519838610316565b503d61069e565b60405163dfc24d3d60e01b8152600481018a9052602490fd5b60405163dfc24d3d60e01b815260048101899052602490fd5b503461016357602080600319360112610a5d5760043590610712611d42565b6003546001600160a01b03908116808552600283526040852054919391841691908215610a45575060405192633bcb4e8360e21b8452816004850152604084602481865afa938415610a3a5786908795610a16575b5085811694867f0000000000000000000000000000000000000000000000000000000000000000166040516370a0823160e01b9182825280600483015285826024818c5afa908b8215610a0a5788818b8e8b94966109d2575b610829959697507f000000000000000000000000000000000000000000000000000000000000000016916107f684303386611dc4565b60405163095ea7b360e01b81526001600160a01b0390921660048301526024820193909352938492839182906044820190565b03925af18015610657576109b5575b50604080516254772560e21b81526004810189905290816024818f8d5af19a8b15610657578c918d9c610990575b508a9082160361095d5750604051928352600483015284826024818b5afa8015610952578a90610923575b61089b9250611c6b565b9687036108dd5780871061054c5750506040519485528401527f705661fa3a970960d8791236e32945efdda156e72c9d7b76505b6ccbdc48501b60403394a480f35b604051633b0e6a4960e11b815260048101849052601b60248201527f41646170746572206d69732d7265706f727465642073686172657300000000006044820152606490fd5b508482813d831161094b575b6109398183611c00565b810103126105355761089b9151610891565b503d61092f565b6040513d8c823e3d90fd5b60405163e8eebd3760e01b81526001600160a01b038a811660048301528781166024830152919091166044820152606490fd5b6109ad919c508b925060403d6040116105de576105cc8183611c00565b9b9091610866565b6109cb90873d8911610616576106078183611c00565b5038610838565b5050505090915082813d8311610a03575b6109ed8183611c00565b81010312610535579051899186888d8b866107c0565b503d6109e3565b604051903d90823e3d90fd5b9050610a3291945060403d6040116105de576105cc8183611c00565b939038610767565b6040513d88823e3d90fd5b6024906040519063dfc24d3d60e01b82526004820152fd5b5080fd5b503461016357606036600319011261016357600435610a7e611b71565b6001600160a01b036044358181169391929084900361053557610a9f611d42565b8260035416938486526020926002845284604088205416958615610a455750604051634ab9e16b60e01b81529380856004818a5afa948515610f32578895610efb575b508585169660405195630a28a47760e01b875283600488015282876024818c5afa968715610952578a97610ecc575b508615610eb35789887f000000000000000000000000000000000000000000000000000000000000000016803b15610a5d57604051631c7fc97360e11b81526001600160a01b0384166004820152602481018a90523060448201529082908290606490829084905af180156105e557610e9b575b505081610b95886024948c611f53565b838b6040519485809263508fef7760e11b82528c6004830152855af1928315610e90578b93610e61575b50848310610e2e57610bff858a7f00000000000000000000000000000000000000000000000000000000000000001694610bfa828b88611e1f565b611c6b565b918b83610c49575b8b7fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed31353165960808c8e8d8d8d8d6040519586528501526040840152166060820152a280f35b60405163095ea7b360e01b8082526001600160a01b038516600483015260248201869052959b949a9994989497949694959291859082908e908290816044810103925af18015610e2157610e04575b506040516254772560e21b81528a60048201528d60408260248184895af1909181610de2575b50610d6a57505090604483928d6040519c8d948593845260048401528160248401525af197881561095257816080987fc2b45953ce7f14f6d1f9273fb9620e4e5eea889991ca73f256b7ef8e1988e84c927fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed3135316599b610d4d575b50604051908152a15b91939681939596388b610c07565b610d6390833d8511610616576106078183611c00565b5038610d36565b889a508093949698919597999b508c92501603610db257505050917fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed31353165995939160809593610d3f565b60405163e8eebd3760e01b81526001600160a01b0392831660048201529282166024840152166044820152606490fd5b610dfc91925060403d6040116105de576105cc8183611c00565b509038610cbe565b610e1a90853d8711610616576106078183611c00565b5038610c98565b8e604051903d90823e3d90fd5b506040516322ce378760e11b81526001600160a01b03919091166004820152602481018490526044810191909152606490fd5b9092508381813d8311610e89575b610e798183611c00565b8101031261053557519138610bbf565b503d610e6f565b6040513d8d823e3d90fd5b610ea490611bd6565b610eaf578938610b85565b8980fd5b6040516352e4307960e11b8152600481018a9052602490fd5b9096508281813d8311610ef4575b610ee48183611c00565b8101031261053557519538610b11565b503d610eda565b9080955081813d8311610f2b575b610f138183611c00565b8101031261068a57610f2490611c22565b9338610ae2565b503d610f09565b6040513d8a823e3d90fd5b5034610163578060031936011261016357602090604051908152f35b503461016357602080600319360112610a5d5760043590610f78611d08565b6040516370a0823160e01b81523060048201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811693909291908282602481885afa918215610a3a578692611177575b5081156111595780158015611150575b156111485750925b82600354168086526002835283604087205416908115610a455750604051634ab9e16b60e01b8152918383600481855afa92831561067f57879361110d575b5060405163095ea7b360e01b81526001600160a01b038316600482015260248101879052908490829060449082908b905af1801561067f576110f0575b506040516254772560e21b81528560048201526040816024818a865af190811561067f5787916110d0575b508481169483168503610db257867fde5535ecf375c1fc5a04be89bec3dee7e25472f1a743e5da0ee098dd9d700bad60408888888351928352820152a180f35b6110e9915060403d6040116105de576105cc8183611c00565b5038611090565b61110690843d8611610616576106078183611c00565b5038611065565b9092508381813d8311611141575b6111258183611c00565b8101031261113d5761113690611c22565b9138611028565b8680fd5b503d61111b565b905092610fe9565b50818111610fe1565b60448587604051916354f076c560e11b835260048301526024820152fd5b9091508281813d831161119f575b61118f8183611c00565b8101031261053557519038610fd1565b503d611185565b50346101635760403660031901126101635760406111c2611b71565b91600435815280602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b50346101635760403660031901126101635761120b611b87565b611213611b71565b61121b611d08565b6001600160a01b038181169190821580156113a9575b61139757604051634ab9e16b60e01b8152936020928386600481885afa95861561067f578796611360575b50828216958684821603610db257505050838552600282528060408620541680151580611356575b6113385750838552600282526040852080546001600160a01b0319168417905584907f000000000000000000000000000000000000000000000000000000000000000016803b15610a5d5781809160246040518094819363fac09e8760e01b83528a60048401525af1611320575b50507fe5e39617beb2a298b9fa1c3928582d9a96ba7ef7c920acd1117d1d415568670a91604051908152a280f35b61132990611bd6565b6113345783386112f2565b8380fd5b846044916040519163fa9938bf60e01b835260048301526024820152fd5b5083811415611284565b9095508381813d8311611390575b6113788183611c00565b8101031261113d5761138990611c22565b943861125c565b503d61136e565b60405163d92e233d60e01b8152600490fd5b5080841615611231565b50346101635780600319360112610163576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461016357602036600319011261016357611412611b87565b61141a611d08565b6001600160a01b039081168083526002602052604083205490919081169081156114f45782845260026020526040842080546001600160a01b031916905583907f000000000000000000000000000000000000000000000000000000000000000016803b15610a5d57818091602460405180948193631c46bc6f60e01b83528960048401525af180156105e5576114dc575b505060207f80d565a25be79c22ac744d2eb2cf727b98545a88dd1396b53ce6a045aacd558291604051908152a280f35b6114e590611bd6565b6114f05782386114ac565b8280fd5b60405163dfc24d3d60e01b815260048101849052602490fd5b503461016357602036600319011261016357611527611b87565b61152f611d08565b6001600160a01b039081168083526002602052604083205490911615610a4557600380546001600160a01b031916821790557f24924ec42babd548ca3fd6321ab17d9c16c025f8996cbfac050500587609b1748280a280f35b5034610163576040366003190112610163576115a2611b71565b336001600160a01b038216036115be5761021a90600435611ede565b60405163334bd91960e11b8152600490fd5b50346101635760403660031901126101635761021a6004356115f0611b71565b90808452836020526116086001604086200154611d9e565b611e60565b503461016357602036600319011261016357600160406020926004358152808452200154604051908152f35b50346101635761164836611b9d565b611653939293611c8e565b8115611a2e576001600160a01b038316158015611a1d575b611397576040519060c0820182811067ffffffffffffffff821117611a095760409081528683526020808401888152848301899052606085018990526080850189905260a085018990526001600160a01b038781168a526002808452848b2054821687528982168b52909252918820548116909152825116156119e85760208201516001600160a01b0316156119c75781516001600160a01b03908116604080850182905260208581015190931660608601525163e0e5c1ab60e01b8152600481018690529190829060249082905afa90811561067f578791611995575b508060808401521561196d5760018060a01b0360608301511690604060808401516024825180958193633bcb4e8360e21b835260048301525afa91821561067f5787908893611949575b506001600160a01b038781169082160361191357508160a08401528082106118e557506117cd90508230336001600160a01b038716611dc4565b846001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169061180990859083908816611e1f565b60a0830151813b156114f057604051631c7fc97360e11b81526001600160a01b0388166004820152602481019190915233604482015291908290606490829084905af18015610a3a576118b2575b5060a08101516080909101516040805193845260208401929092529082015233926001600160a01b039081169216907f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539080606081016104d3565b946118de7f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539296611bd6565b9490611857565b604051636f85e6ff60e11b81526001600160a01b038716600482015260248101929092526044820152606490fd5b602084015160405163e8eebd3760e01b81526001600160a01b039182166004820152888216602482015291166044820152606490fd5b905061196591925060403d6040116105de576105cc8183611c00565b919038611793565b6040516354f076c560e11b81526001600160a01b038516600482015260248101849052604490fd5b90506020813d6020116119bf575b816119b060209383611c00565b8101031261113d575138611749565b3d91506119a3565b60405163dfc24d3d60e01b81526001600160a01b0386166004820152602490fd5b60405163dfc24d3d60e01b81526001600160a01b0385166004820152602490fd5b634e487b7160e01b87526041600452602487fd5b506001600160a01b0384161561166b565b604051633b0e6a4960e11b815260206004820152601b60248201527f496e70757420616d6f756e742063616e6e6f74206265207a65726f00000000006044820152606490fd5b50346101635780600319360112610163576020600154604051908152f35b50346101635780600319360112610163576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346101635780600319360112610163576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b905034610a5d576020366003190112610a5d5760043563ffffffff60e01b81168091036114f05760209250637965db0b60e01b8114908115611b60575b5015158152f35b6301ffc9a760e01b14905038611b59565b602435906001600160a01b038216820361053557565b600435906001600160a01b038216820361053557565b6080906003190112610535576001600160a01b039060043582811681036105355791602435908116810361053557906044359060643590565b67ffffffffffffffff8111611bea57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117611bea57604052565b51906001600160a01b038216820361053557565b9190826040910312610535576020611c4d83611c22565b92015190565b90816020910312610535575180151581036105355790565b91908203918211611c7857565b634e487b7160e01b600052601160045260246000fd5b3360009081527f442b21db4ee30744d8435a797a25e6c1c72e1e7b189fd6a63533411360d93da660205260409020547f3a4b3a1f03347d0616bb4d34491485029b5c8f56cd6dc1f9e9b1524cad0936f79060ff1615611cea5750565b6044906040519063e2517d3f60e01b82523360048301526024820152fd5b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1615611cea5750565b3360009081527fee6598bb9d8813ec5dcf0988fbc9935f3bd23c22de3e37b2654f2216372e6c0860205260409020547f7fee0d6ae731e4c26a7bffbf1bb702cb3aaa110506f5b2a78cc9372669d439ae9060ff1615611cea5750565b80600052600060205260406000203360005260205260ff6040600020541615611cea5750565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a081019181831067ffffffffffffffff841117611bea57611e1d92604052612070565b565b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152611e1d91611e5b606483611c00565b612070565b9060009180835282602052604083209160018060a01b03169182845260205260ff60408420541615600014611ed957808352826020526040832082845260205260408320600160ff198254161790557f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d339380a4600190565b505090565b9060009180835282602052604083209160018060a01b03169182845260205260ff604084205416600014611ed95780835282602052604083208284526020526040832060ff1981541690557ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b339380a4600190565b60405163095ea7b360e01b602082018181526001600160a01b038516602484015260448084019690965294825294939092611f8f606485611c00565b83516000926001600160a01b039291858416918591829182855af190611fb36120e2565b8261203e575b5081612033575b5015611fd0575b50505050509050565b60405196602088015216602486015280604486015260448552608085019085821067ffffffffffffffff83111761201f57506120149394611e5b9160405282612070565b803880808080611fc7565b634e487b7160e01b81526041600452602490fd5b90503b151538611fc0565b80519192508115918215612056575b50509038611fb9565b6120699250602080918301019101611c53565b388061204d565b6000806120999260018060a01b03169360208151910182865af16120926120e2565b9083612122565b80519081151591826120c7575b50506120af5750565b60249060405190635274afe760e01b82526004820152fd5b6120da9250602080918301019101611c53565b1538806120a6565b3d1561211d573d9067ffffffffffffffff8211611bea5760405191612111601f8201601f191660200184611c00565b82523d6000602084013e565b606090565b90612149575080511561213757805190602001fd5b604051630a12f52160e11b8152600490fd5b8151158061217c575b61215a575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b1561215256fea2646970667358221220a140ad69f6c3120dea8c86000906555c5f20cb7e43b5f1018b31f7ebd3fae26864736f6c634300081800332f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d00000000000000000000000058acc2600835211dcb5847c5fa422791fd4924090000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be

Deployed Bytecode

0x608080604052600436101561001357600080fd5b600090813560e01c90816301ffc9a714611b1c575080630bece79c14611ad75780630cc2f8d214611a925780631e99981414611a745780632379e45214611639578063248a9ca31461160d5780632f2ff15d146115d057806336568abe146115885780633a5d64c51461150d578063585cd34b146113f85780635c47df42146113b35780636dacd3d7146111f157806391d14854146111a65780639bb9461f14610f59578063a217fddf14610f3d578063b460af9414610a61578063b6b55f25146106f3578063b9c7e7a514610295578063bc6d5a101461025a578063c8232bd71461021e578063d547741f146101dd578063dc369c651461018f578063e1e6548d146101665763ee1f70441461012957600080fd5b3461016357806003193601126101635760206040517f3a4b3a1f03347d0616bb4d34491485029b5c8f56cd6dc1f9e9b1524cad0936f78152f35b80fd5b50346101635780600319360112610163576003546040516001600160a01b039091168152602090f35b5034610163576020366003190112610163577fbd575a5650fa5dbcfe03ab798aec3c80a935c6d293729c1ede529f46efbfbd4760206004356101cf611d08565b80600155604051908152a180f35b50346101635760403660031901126101635761021a6004356101fd611b71565b90808452836020526102156001604086200154611d9e565b611ede565b5080f35b5034610163576020366003190112610163576020906001600160a01b039060409082610248611b87565b16815260028452205416604051908152f35b503461016357806003193601126101635760206040517f7fee0d6ae731e4c26a7bffbf1bb702cb3aaa110506f5b2a78cc9372669d439ae8152f35b5034610163576102a436611b9d565b90926102ae611c8e565b60018060a01b0380821692838752602090600282528260408920541683871696878a528460408b2054169282156106da5783156106c157908a9392916040519763e0e5c1ab60e01b93848a528c60048b0152878a602481845afa998a1561067f57879a61068e575b50887f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be16803b1561068a57604051631c7fc97360e11b81526001600160a01b03939093166004840152602483018e905230604484015287908390606490829084905af1801561067f5788928891610662575b50506103958d828d611f53565b60248d604051988993849263508fef7760e11b845260048401525af1948515610657578c95610628575b5060405163095ea7b360e01b81526001600160a01b0385166004820152602481018690527f000000000000000000000000788d96f655735f52c676a133f4dfc53cec614d4a958d918881604481868e8d165af1801561061d576105f0575b50604051906254772560e21b82526004820152604081602481858a5af19889156105e5578c91839a6105ae575b5082160361057b575080871061054c575050839060246040518094819382528860048301525afa92831561054157899361050c575b505061048d60015485611c6b565b8083106104d95750506040805196875260208701929092525084015233927f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539080606081015b0390a480f35b604051636f85e6ff60e11b81526001600160a01b0392909216600483015260248201929092526044810191909152606490fd5b9080929350813d831161053a575b6105248183611c00565b81010312610535575190388061047f565b600080fd5b503d61051a565b6040513d8b823e3d90fd5b604051636f85e6ff60e11b81526001600160a01b03929092166004830152602482018790526044820152606490fd5b60405163e8eebd3760e01b81526001600160a01b0386811660048301528481166024830152919091166044820152606490fd5b9099506105d491925060403d6040116105de575b6105cc8183611c00565b810190611c36565b919091983861044a565b503d6105c2565b6040513d84823e3d90fd5b61060f90893d8b11610616575b6106078183611c00565b810190611c53565b503861041d565b503d6105fd565b6040513d85823e3d90fd5b9094508581813d8311610650575b6106408183611c00565b81010312610535575193386103bf565b503d610636565b6040513d8e823e3d90fd5b61066e91929350611bd6565b61067b5786908638610388565b8580fd5b6040513d89823e3d90fd5b8780fd5b8880929b508198503d83116106ba575b6106a88183611c00565b81010312610535578c95519838610316565b503d61069e565b60405163dfc24d3d60e01b8152600481018a9052602490fd5b60405163dfc24d3d60e01b815260048101899052602490fd5b503461016357602080600319360112610a5d5760043590610712611d42565b6003546001600160a01b03908116808552600283526040852054919391841691908215610a45575060405192633bcb4e8360e21b8452816004850152604084602481865afa938415610a3a5786908795610a16575b5085811694867f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be166040516370a0823160e01b9182825280600483015285826024818c5afa908b8215610a0a5788818b8e8b94966109d2575b610829959697507f000000000000000000000000788d96f655735f52c676a133f4dfc53cec614d4a16916107f684303386611dc4565b60405163095ea7b360e01b81526001600160a01b0390921660048301526024820193909352938492839182906044820190565b03925af18015610657576109b5575b50604080516254772560e21b81526004810189905290816024818f8d5af19a8b15610657578c918d9c610990575b508a9082160361095d5750604051928352600483015284826024818b5afa8015610952578a90610923575b61089b9250611c6b565b9687036108dd5780871061054c5750506040519485528401527f705661fa3a970960d8791236e32945efdda156e72c9d7b76505b6ccbdc48501b60403394a480f35b604051633b0e6a4960e11b815260048101849052601b60248201527f41646170746572206d69732d7265706f727465642073686172657300000000006044820152606490fd5b508482813d831161094b575b6109398183611c00565b810103126105355761089b9151610891565b503d61092f565b6040513d8c823e3d90fd5b60405163e8eebd3760e01b81526001600160a01b038a811660048301528781166024830152919091166044820152606490fd5b6109ad919c508b925060403d6040116105de576105cc8183611c00565b9b9091610866565b6109cb90873d8911610616576106078183611c00565b5038610838565b5050505090915082813d8311610a03575b6109ed8183611c00565b81010312610535579051899186888d8b866107c0565b503d6109e3565b604051903d90823e3d90fd5b9050610a3291945060403d6040116105de576105cc8183611c00565b939038610767565b6040513d88823e3d90fd5b6024906040519063dfc24d3d60e01b82526004820152fd5b5080fd5b503461016357606036600319011261016357600435610a7e611b71565b6001600160a01b036044358181169391929084900361053557610a9f611d42565b8260035416938486526020926002845284604088205416958615610a455750604051634ab9e16b60e01b81529380856004818a5afa948515610f32578895610efb575b508585169660405195630a28a47760e01b875283600488015282876024818c5afa968715610952578a97610ecc575b508615610eb35789887f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be16803b15610a5d57604051631c7fc97360e11b81526001600160a01b0384166004820152602481018a90523060448201529082908290606490829084905af180156105e557610e9b575b505081610b95886024948c611f53565b838b6040519485809263508fef7760e11b82528c6004830152855af1928315610e90578b93610e61575b50848310610e2e57610bff858a7f000000000000000000000000788d96f655735f52c676a133f4dfc53cec614d4a1694610bfa828b88611e1f565b611c6b565b918b83610c49575b8b7fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed31353165960808c8e8d8d8d8d6040519586528501526040840152166060820152a280f35b60405163095ea7b360e01b8082526001600160a01b038516600483015260248201869052959b949a9994989497949694959291859082908e908290816044810103925af18015610e2157610e04575b506040516254772560e21b81528a60048201528d60408260248184895af1909181610de2575b50610d6a57505090604483928d6040519c8d948593845260048401528160248401525af197881561095257816080987fc2b45953ce7f14f6d1f9273fb9620e4e5eea889991ca73f256b7ef8e1988e84c927fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed3135316599b610d4d575b50604051908152a15b91939681939596388b610c07565b610d6390833d8511610616576106078183611c00565b5038610d36565b889a508093949698919597999b508c92501603610db257505050917fb82a50d120fe10f11179f7792c046bf005589c3eea490a9e3e347ed31353165995939160809593610d3f565b60405163e8eebd3760e01b81526001600160a01b0392831660048201529282166024840152166044820152606490fd5b610dfc91925060403d6040116105de576105cc8183611c00565b509038610cbe565b610e1a90853d8711610616576106078183611c00565b5038610c98565b8e604051903d90823e3d90fd5b506040516322ce378760e11b81526001600160a01b03919091166004820152602481018490526044810191909152606490fd5b9092508381813d8311610e89575b610e798183611c00565b8101031261053557519138610bbf565b503d610e6f565b6040513d8d823e3d90fd5b610ea490611bd6565b610eaf578938610b85565b8980fd5b6040516352e4307960e11b8152600481018a9052602490fd5b9096508281813d8311610ef4575b610ee48183611c00565b8101031261053557519538610b11565b503d610eda565b9080955081813d8311610f2b575b610f138183611c00565b8101031261068a57610f2490611c22565b9338610ae2565b503d610f09565b6040513d8a823e3d90fd5b5034610163578060031936011261016357602090604051908152f35b503461016357602080600319360112610a5d5760043590610f78611d08565b6040516370a0823160e01b81523060048201526001600160a01b037f000000000000000000000000788d96f655735f52c676a133f4dfc53cec614d4a811693909291908282602481885afa918215610a3a578692611177575b5081156111595780158015611150575b156111485750925b82600354168086526002835283604087205416908115610a455750604051634ab9e16b60e01b8152918383600481855afa92831561067f57879361110d575b5060405163095ea7b360e01b81526001600160a01b038316600482015260248101879052908490829060449082908b905af1801561067f576110f0575b506040516254772560e21b81528560048201526040816024818a865af190811561067f5787916110d0575b508481169483168503610db257867fde5535ecf375c1fc5a04be89bec3dee7e25472f1a743e5da0ee098dd9d700bad60408888888351928352820152a180f35b6110e9915060403d6040116105de576105cc8183611c00565b5038611090565b61110690843d8611610616576106078183611c00565b5038611065565b9092508381813d8311611141575b6111258183611c00565b8101031261113d5761113690611c22565b9138611028565b8680fd5b503d61111b565b905092610fe9565b50818111610fe1565b60448587604051916354f076c560e11b835260048301526024820152fd5b9091508281813d831161119f575b61118f8183611c00565b8101031261053557519038610fd1565b503d611185565b50346101635760403660031901126101635760406111c2611b71565b91600435815280602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b50346101635760403660031901126101635761120b611b87565b611213611b71565b61121b611d08565b6001600160a01b038181169190821580156113a9575b61139757604051634ab9e16b60e01b8152936020928386600481885afa95861561067f578796611360575b50828216958684821603610db257505050838552600282528060408620541680151580611356575b6113385750838552600282526040852080546001600160a01b0319168417905584907f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be16803b15610a5d5781809160246040518094819363fac09e8760e01b83528a60048401525af1611320575b50507fe5e39617beb2a298b9fa1c3928582d9a96ba7ef7c920acd1117d1d415568670a91604051908152a280f35b61132990611bd6565b6113345783386112f2565b8380fd5b846044916040519163fa9938bf60e01b835260048301526024820152fd5b5083811415611284565b9095508381813d8311611390575b6113788183611c00565b8101031261113d5761138990611c22565b943861125c565b503d61136e565b60405163d92e233d60e01b8152600490fd5b5080841615611231565b50346101635780600319360112610163576040517f00000000000000000000000058acc2600835211dcb5847c5fa422791fd4924096001600160a01b03168152602090f35b503461016357602036600319011261016357611412611b87565b61141a611d08565b6001600160a01b039081168083526002602052604083205490919081169081156114f45782845260026020526040842080546001600160a01b031916905583907f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be16803b15610a5d57818091602460405180948193631c46bc6f60e01b83528960048401525af180156105e5576114dc575b505060207f80d565a25be79c22ac744d2eb2cf727b98545a88dd1396b53ce6a045aacd558291604051908152a280f35b6114e590611bd6565b6114f05782386114ac565b8280fd5b60405163dfc24d3d60e01b815260048101849052602490fd5b503461016357602036600319011261016357611527611b87565b61152f611d08565b6001600160a01b039081168083526002602052604083205490911615610a4557600380546001600160a01b031916821790557f24924ec42babd548ca3fd6321ab17d9c16c025f8996cbfac050500587609b1748280a280f35b5034610163576040366003190112610163576115a2611b71565b336001600160a01b038216036115be5761021a90600435611ede565b60405163334bd91960e11b8152600490fd5b50346101635760403660031901126101635761021a6004356115f0611b71565b90808452836020526116086001604086200154611d9e565b611e60565b503461016357602036600319011261016357600160406020926004358152808452200154604051908152f35b50346101635761164836611b9d565b611653939293611c8e565b8115611a2e576001600160a01b038316158015611a1d575b611397576040519060c0820182811067ffffffffffffffff821117611a095760409081528683526020808401888152848301899052606085018990526080850189905260a085018990526001600160a01b038781168a526002808452848b2054821687528982168b52909252918820548116909152825116156119e85760208201516001600160a01b0316156119c75781516001600160a01b03908116604080850182905260208581015190931660608601525163e0e5c1ab60e01b8152600481018690529190829060249082905afa90811561067f578791611995575b508060808401521561196d5760018060a01b0360608301511690604060808401516024825180958193633bcb4e8360e21b835260048301525afa91821561067f5787908893611949575b506001600160a01b038781169082160361191357508160a08401528082106118e557506117cd90508230336001600160a01b038716611dc4565b846001600160a01b037f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be81169061180990859083908816611e1f565b60a0830151813b156114f057604051631c7fc97360e11b81526001600160a01b0388166004820152602481019190915233604482015291908290606490829084905af18015610a3a576118b2575b5060a08101516080909101516040805193845260208401929092529082015233926001600160a01b039081169216907f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539080606081016104d3565b946118de7f34eb53881682710349fbce503317e7cba1eb6dcdeeb2c86b8dd00f0fe510ba539296611bd6565b9490611857565b604051636f85e6ff60e11b81526001600160a01b038716600482015260248101929092526044820152606490fd5b602084015160405163e8eebd3760e01b81526001600160a01b039182166004820152888216602482015291166044820152606490fd5b905061196591925060403d6040116105de576105cc8183611c00565b919038611793565b6040516354f076c560e11b81526001600160a01b038516600482015260248101849052604490fd5b90506020813d6020116119bf575b816119b060209383611c00565b8101031261113d575138611749565b3d91506119a3565b60405163dfc24d3d60e01b81526001600160a01b0386166004820152602490fd5b60405163dfc24d3d60e01b81526001600160a01b0385166004820152602490fd5b634e487b7160e01b87526041600452602487fd5b506001600160a01b0384161561166b565b604051633b0e6a4960e11b815260206004820152601b60248201527f496e70757420616d6f756e742063616e6e6f74206265207a65726f00000000006044820152606490fd5b50346101635780600319360112610163576020600154604051908152f35b50346101635780600319360112610163576040517f000000000000000000000000788d96f655735f52c676a133f4dfc53cec614d4a6001600160a01b03168152602090f35b50346101635780600319360112610163576040517f0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be6001600160a01b03168152602090f35b905034610a5d576020366003190112610a5d5760043563ffffffff60e01b81168091036114f05760209250637965db0b60e01b8114908115611b60575b5015158152f35b6301ffc9a760e01b14905038611b59565b602435906001600160a01b038216820361053557565b600435906001600160a01b038216820361053557565b6080906003190112610535576001600160a01b039060043582811681036105355791602435908116810361053557906044359060643590565b67ffffffffffffffff8111611bea57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117611bea57604052565b51906001600160a01b038216820361053557565b9190826040910312610535576020611c4d83611c22565b92015190565b90816020910312610535575180151581036105355790565b91908203918211611c7857565b634e487b7160e01b600052601160045260246000fd5b3360009081527f442b21db4ee30744d8435a797a25e6c1c72e1e7b189fd6a63533411360d93da660205260409020547f3a4b3a1f03347d0616bb4d34491485029b5c8f56cd6dc1f9e9b1524cad0936f79060ff1615611cea5750565b6044906040519063e2517d3f60e01b82523360048301526024820152fd5b3360009081527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5602052604081205460ff1615611cea5750565b3360009081527fee6598bb9d8813ec5dcf0988fbc9935f3bd23c22de3e37b2654f2216372e6c0860205260409020547f7fee0d6ae731e4c26a7bffbf1bb702cb3aaa110506f5b2a78cc9372669d439ae9060ff1615611cea5750565b80600052600060205260406000203360005260205260ff6040600020541615611cea5750565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a081019181831067ffffffffffffffff841117611bea57611e1d92604052612070565b565b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152611e1d91611e5b606483611c00565b612070565b9060009180835282602052604083209160018060a01b03169182845260205260ff60408420541615600014611ed957808352826020526040832082845260205260408320600160ff198254161790557f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d339380a4600190565b505090565b9060009180835282602052604083209160018060a01b03169182845260205260ff604084205416600014611ed95780835282602052604083208284526020526040832060ff1981541690557ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b339380a4600190565b60405163095ea7b360e01b602082018181526001600160a01b038516602484015260448084019690965294825294939092611f8f606485611c00565b83516000926001600160a01b039291858416918591829182855af190611fb36120e2565b8261203e575b5081612033575b5015611fd0575b50505050509050565b60405196602088015216602486015280604486015260448552608085019085821067ffffffffffffffff83111761201f57506120149394611e5b9160405282612070565b803880808080611fc7565b634e487b7160e01b81526041600452602490fd5b90503b151538611fc0565b80519192508115918215612056575b50509038611fb9565b6120699250602080918301019101611c53565b388061204d565b6000806120999260018060a01b03169360208151910182865af16120926120e2565b9083612122565b80519081151591826120c7575b50506120af5750565b60249060405190635274afe760e01b82526004820152fd5b6120da9250602080918301019101611c53565b1538806120a6565b3d1561211d573d9067ffffffffffffffff8211611bea5760405191612111601f8201601f191660200184611c00565b82523d6000602084013e565b606090565b90612149575080511561213757805190602001fd5b604051630a12f52160e11b8152600490fd5b8151158061217c575b61215a575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b1561215256fea2646970667358221220a140ad69f6c3120dea8c86000906555c5f20cb7e43b5f1018b31f7ebd3fae26864736f6c63430008180033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000058acc2600835211dcb5847c5fa422791fd4924090000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be

-----Decoded View---------------
Arg [0] : _dStakeToken (address): 0x58AcC2600835211Dcb5847c5Fa422791Fd492409
Arg [1] : _collateralVault (address): 0x5432ed4A370718D6904485e2Fc114762C68Cc7BE

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 00000000000000000000000058acc2600835211dcb5847c5fa422791fd492409
Arg [1] : 0000000000000000000000005432ed4a370718d6904485e2fc114762c68cc7be


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.