ETH Price: $3,328.03 (+6.62%)

Contract

0xD9E1AF0a23150E0Dd53E9D36311Cd31311961Eef

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

> 10 Internal Transactions and > 10 Token Transfers found.

Latest 25 internal transactions (View All)

Parent Transaction Hash Block From To
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720843392023-03-21 10:09:09994 days ago1679393349
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720746692023-03-21 9:29:17994 days ago1679390957
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720547962023-03-21 8:07:59995 days ago1679386079
0xD9E1AF0a...311961Eef
0 ETH
720498482023-03-21 7:47:39995 days ago1679384859
0xD9E1AF0a...311961Eef
0 ETH
720498482023-03-21 7:47:39995 days ago1679384859
0xD9E1AF0a...311961Eef
0 ETH
720498482023-03-21 7:47:39995 days ago1679384859
0xD9E1AF0a...311961Eef
0 ETH
720498482023-03-21 7:47:39995 days ago1679384859
0xD9E1AF0a...311961Eef
0 ETH
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xb7aA4Bf9...7bf316599
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
SynapseStrategy

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 1 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

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

import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { SafeETH } from "../../libraries/SafeETH.sol";
import { HarvestSwapParams } from "../../interfaces/Structs.sol";
import { IStargateRouter } from "../../interfaces/stargate/IStargateRouter.sol";
import { ISynapseSwap } from "../../interfaces/synapse/ISynapseSwap.sol";
import { MiniChef2Farm, FarmConfig } from "../../strategies/adapters/MiniChef2Farm.sol";
import { ISCYStrategy } from "../../interfaces/ERC5115/ISCYStrategy.sol";
import { StratAuthLight } from "../../common/StratAuthLight.sol";

// import "hardhat/console.sol";

// This synapsePool assumes that sharedDecimans and localDecimals are the same
contract SynapseStrategy is MiniChef2Farm, ISCYStrategy, StratAuthLight {
	using SafeERC20 for IERC20;

	uint256 public _nTokens;
	ISynapseSwap public synapsePool;
	IERC20 public lpToken;
	IERC20 public underlying;
	uint8 public coinId;

	constructor(
		address _vault,
		address _lpToken,
		address _synapsePool,
		uint8 _coinId,
		FarmConfig memory _farmConfig
	) MiniChef2Farm(_farmConfig) {
		vault = _vault;
		coinId = _coinId;
		synapsePool = ISynapseSwap(_synapsePool);
		lpToken = IERC20(_lpToken);
		underlying = synapsePool.getToken(coinId);
		underlying.safeApprove(_synapsePool, type(uint256).max);
		IERC20(lpToken).safeApprove(address(farm), type(uint256).max);
		IERC20(lpToken).safeApprove(_synapsePool, type(uint256).max);
		_nTokens = ISynapseSwap(synapsePool).calculateRemoveLiquidity(1).length;
	}

	function deposit(uint256 amount) public onlyVault returns (uint256) {
		uint256[] memory amounts = new uint256[](_nTokens);
		amounts[coinId] = amount;
		// min LP tokens is checked in redeem method
		uint256 lp = ISynapseSwap(synapsePool).addLiquidity(amounts, 0, block.timestamp);
		_depositIntoFarm(lp);
		return lp;
	}

	function redeem(address recipient, uint256 amount)
		external
		onlyVault
		returns (uint256 amountOut)
	{
		if (amount == 0) return 0;
		_withdrawFromFarm(amount);
		amountOut = ISynapseSwap(synapsePool).removeLiquidityOneToken(
			amount,
			coinId,
			0,
			block.timestamp
		);
		underlying.safeTransfer(recipient, amountOut);
	}

	function getTvl() public view returns (uint256) {
		(uint256 balance, ) = farm.userInfo(uint256(farmId), address(this));
		if (balance == 0) return 0;
		return ISynapseSwap(synapsePool).calculateRemoveLiquidityOneToken(balance, coinId);
	}

	function closePosition(uint256) external onlyVault returns (uint256 amountOut) {
		(uint256 balance, ) = farm.userInfo(farmId, address(this));
		_withdrawFromFarm(balance);
		amountOut = ISynapseSwap(synapsePool).removeLiquidityOneToken(
			balance,
			coinId,
			0,
			block.timestamp
		);
		underlying.safeTransfer(address(vault), amountOut);
	}

	function getAndUpdateTvl() external returns (uint256) {
		return getTvl();
	}

	function getMaxTvl() external view returns (uint256) {
		return IERC20(lpToken).totalSupply() / 10; // 10% of total deposits
	}

	function collateralToUnderlying() external view returns (uint256) {
		return ISynapseSwap(synapsePool).calculateRemoveLiquidityOneToken(1e18, coinId);
	}

	function harvest(HarvestSwapParams[] calldata params, HarvestSwapParams[] calldata)
		external
		onlyVault
		returns (uint256[] memory harvested, uint256[] memory)
	{
		uint256 amountOut = _harvestFarm(params[0]);
		if (amountOut > 0) deposit(amountOut);
		harvested = new uint256[](1);
		harvested[0] = amountOut;
		return (harvested, new uint256[](0));
	}

	function getWithdrawAmnt(uint256 lpTokens) public view returns (uint256) {
		return ISynapseSwap(synapsePool).calculateRemoveLiquidityOneToken(lpTokens, coinId);
	}

	function getDepositAmnt(uint256 uAmnt) public view returns (uint256) {
		uint256[] memory amounts = new uint256[](_nTokens);
		amounts[coinId] = uAmnt;
		return ISynapseSwap(synapsePool).calculateTokenAmount(amounts, true);
	}

	function getLpToken() public view returns (address) {
		return address(lpToken);
	}

	function getLpBalance() public view returns (uint256) {
		return _getFarmLp();
	}
}

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

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../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:
 *
 * ```
 * 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}:
 *
 * ```
 * 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.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    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 override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @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 override 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 override 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 override 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 `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @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 Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @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.
     *
     * _Available since v3.1._
     */
    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 `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

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

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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 v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @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.
 */
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].
     */
    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 v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

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

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./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);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @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 v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";

struct AuthConfig {
	address owner;
	address guardian;
	address manager;
}

contract Auth is AccessControl {
	event OwnershipTransferInitiated(address owner, address pendingOwner);
	event OwnershipTransferred(address oldOwner, address newOwner);

	////////// CONSTANTS //////////

	/// Update vault params, perform time-sensitive operations, set manager
	bytes32 public constant GUARDIAN = keccak256("GUARDIAN");

	/// Hot-wallet bots that route funds between vaults, rebalance and harvest strategies
	bytes32 public constant MANAGER = keccak256("MANAGER");

	/// Add and remove vaults and strategies and other critical operations behind timelock
	/// Default admin role
	/// There should only be one owner, so it is not a role
	address public owner;
	address public pendingOwner;

	modifier onlyOwner() {
		require(msg.sender == owner, "ONLY_OWNER");
		_;
	}

	constructor(AuthConfig memory authConfig) {
		/// Set up the roles
		// owner can manage all roles
		owner = authConfig.owner;
		emit OwnershipTransferred(address(0), authConfig.owner);

		// TODO do we want cascading roles like this?
		_grantRole(DEFAULT_ADMIN_ROLE, authConfig.owner);
		_grantRole(GUARDIAN, authConfig.owner);
		_grantRole(GUARDIAN, authConfig.guardian);
		_grantRole(MANAGER, authConfig.owner);
		_grantRole(MANAGER, authConfig.guardian);
		_grantRole(MANAGER, authConfig.manager);

		/// Allow the guardian role to manage manager
		_setRoleAdmin(MANAGER, GUARDIAN);
	}

	// ----------- Ownership -----------

	/// @dev Init transfer of ownership of the contract to a new account (`_pendingOwner`).
	/// @param _pendingOwner pending owner of contract
	/// Can only be called by the current owner.
	function transferOwnership(address _pendingOwner) external onlyOwner {
		pendingOwner = _pendingOwner;
		emit OwnershipTransferInitiated(owner, _pendingOwner);
	}

	/// @dev Accept transfer of ownership of the contract.
	/// Can only be called by the pendingOwner.
	function acceptOwnership() external {
		address newOwner = pendingOwner;
		require(msg.sender == newOwner, "ONLY_PENDING_OWNER");
		address oldOwner = owner;
		owner = newOwner;

		// revoke the DEFAULT ADMIN ROLE from prev owner
		_revokeRole(DEFAULT_ADMIN_ROLE, oldOwner);
		_revokeRole(GUARDIAN, oldOwner);
		_revokeRole(MANAGER, oldOwner);

		_grantRole(DEFAULT_ADMIN_ROLE, newOwner);
		_grantRole(GUARDIAN, newOwner);
		_grantRole(MANAGER, newOwner);

		emit OwnershipTransferred(oldOwner, newOwner);
	}
}

File 16 of 26 : StratAuthLight.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import { Auth } from "./Auth.sol";
import { EAction } from "../interfaces/Structs.sol";
import { SectorErrors } from "../interfaces/SectorErrors.sol";

// import "hardhat/console.sol";

abstract contract StratAuthLight is SectorErrors {
	address public vault;

	modifier onlyVault() {
		if (msg.sender != vault) revert OnlyVault();
		_;
	}

	event EmergencyAction(address indexed target, bytes data);

	/// @notice calls arbitrary function on target contract in case of emergency
	function emergencyAction(EAction[] calldata actions) public payable onlyVault {
		uint256 l = actions.length;
		for (uint256 i; i < l; ++i) {
			address target = actions[i].target;
			bytes memory data = actions[i].data;
			(bool success, ) = target.call{ value: actions[i].value }(data);
			require(success, "emergencyAction failed");
			emit EmergencyAction(target, data);
		}
	}
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.16;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { HarvestSwapParams } from "../../interfaces/Structs.sol";
import { SectorErrors } from "../../interfaces/SectorErrors.sol";

interface ISCYStrategy {
	function underlying() external view returns (IERC20);

	function deposit(uint256 amount) external returns (uint256);

	function redeem(address to, uint256 amount) external returns (uint256 amntOut);

	function closePosition(uint256 slippageParam) external returns (uint256);

	function getAndUpdateTvl() external returns (uint256);

	function getTvl() external view returns (uint256);

	function getMaxTvl() external view returns (uint256);

	function collateralToUnderlying() external view returns (uint256);

	function harvest(
		HarvestSwapParams[] calldata farm1Params,
		HarvestSwapParams[] calldata farm2Parms
	) external returns (uint256[] memory harvest1, uint256[] memory harvest2);

	function getWithdrawAmnt(uint256 lpTokens) external view returns (uint256);

	function getDepositAmnt(uint256 uAmnt) external view returns (uint256);

	function getLpBalance() external view returns (uint256);

	function getLpToken() external view returns (address);
}

File 18 of 26 : SectorErrors.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.16;

interface SectorErrors {
	error NotImplemented();
	error MaxTvlReached();
	error StrategyHasBalance();
	error MinLiquidity();
	error OnlyVault();
	error ZeroAmount();
}

File 19 of 26 : Structs.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

enum CallType {
	ADD_LIQUIDITY_AND_MINT,
	BORROWB,
	REMOVE_LIQ_AND_REPAY
}

enum VaultType {
	Strategy,
	Aggregator
}

enum EpochType {
	None,
	Withdraw,
	Full
}

enum NativeToken {
	None,
	Underlying,
	Short
}

struct CalleeData {
	CallType callType;
	bytes data;
}
struct AddLiquidityAndMintCalldata {
	uint256 uAmnt;
	uint256 sAmnt;
}
struct BorrowBCalldata {
	uint256 borrowAmount;
	bytes data;
}
struct RemoveLiqAndRepayCalldata {
	uint256 removeLpAmnt;
	uint256 repayUnderlying;
	uint256 repayShort;
	uint256 borrowUnderlying;
	// uint256 amountAMin;
	// uint256 amountBMin;
}

struct HarvestSwapParams {
	address[] path; //path that the token takes
	uint256 min; // min price of in token * 1e18 (computed externally based on spot * slippage + fees)
	uint256 deadline;
	bytes pathData; // uniswap3 path data
}

struct IMXConfig {
	address vault;
	address underlying;
	address short;
	address uniPair;
	address poolToken;
	address farmToken;
	address farmRouter;
}

struct HLPConfig {
	string symbol;
	string name;
	address underlying;
	address short;
	address cTokenLend;
	address cTokenBorrow;
	address uniPair;
	address uniFarm;
	address farmToken;
	uint256 farmId;
	address farmRouter;
	address comptroller;
	address lendRewardRouter;
	address lendRewardToken;
	address vault;
	NativeToken nativeToken;
}

struct EAction {
	address target;
	uint256 value;
	bytes data;
}

// SPDX-License-Identifier: BUSL-1.1

pragma solidity 0.8.16;

struct lzTxObj {
	uint256 dstGasForCall;
	uint256 dstNativeAmount;
	bytes dstNativeAddr;
}

interface IStargateRouter {
	function factory() external view returns (address);

	function addLiquidity(
		uint256 _poolId,
		uint256 _amountLD,
		address _to
	) external;

	function swap(
		uint16 _dstChainId,
		uint256 _srcPoolId,
		uint256 _dstPoolId,
		address payable _refundAddress,
		uint256 _amountLD,
		uint256 _minAmountLD,
		lzTxObj memory _lzTxParams,
		bytes calldata _to,
		bytes calldata _payload
	) external payable;

	function redeemRemote(
		uint16 _dstChainId,
		uint256 _srcPoolId,
		uint256 _dstPoolId,
		address payable _refundAddress,
		uint256 _amountLP,
		uint256 _minAmountLD,
		bytes calldata _to,
		lzTxObj memory _lzTxParams
	) external payable;

	function instantRedeemLocal(
		uint16 _srcPoolId,
		uint256 _amountLP,
		address _to
	) external returns (uint256);

	function redeemLocal(
		uint16 _dstChainId,
		uint256 _srcPoolId,
		uint256 _dstPoolId,
		address payable _refundAddress,
		uint256 _amountLP,
		bytes calldata _to,
		lzTxObj memory _lzTxParams
	) external payable;

	function sendCredits(
		uint16 _dstChainId,
		uint256 _srcPoolId,
		uint256 _dstPoolId,
		address payable _refundAddress
	) external payable;

	function quoteLayerZeroFee(
		uint16 _dstChainId,
		uint8 _functionType,
		bytes calldata _toAddress,
		bytes calldata _transferAndCallPayload,
		lzTxObj memory _lzTxParams
	) external view returns (uint256, uint256);
}

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

interface ISynapseSwap {
	// pool data view functions
	function pooledTokens() external view returns (address[] memory);

	function getA() external view returns (uint256);

	function getToken(uint8 index) external view returns (IERC20);

	function getTokenIndex(address tokenAddress) external view returns (uint8);

	function getTokenBalance(uint8 index) external view returns (uint256);

	function getVirtualPrice() external view returns (uint256);

	// min return calculation functions
	function calculateSwap(
		uint8 tokenIndexFrom,
		uint8 tokenIndexTo,
		uint256 dx
	) external view returns (uint256);

	function calculateTokenAmount(uint256[] calldata amounts, bool deposit)
		external
		view
		returns (uint256);

	function calculateRemoveLiquidity(uint256 amount) external view returns (uint256[] memory);

	function calculateRemoveLiquidityOneToken(uint256 tokenAmount, uint8 tokenIndex)
		external
		view
		returns (uint256 availableTokenAmount);

	// state modifying functions
	function initialize(
		IERC20[] memory pooledTokens,
		uint8[] memory decimals,
		string memory lpTokenName,
		string memory lpTokenSymbol,
		uint256 a,
		uint256 fee,
		uint256 adminFee,
		address lpTokenTargetAddress
	) external;

	function swap(
		uint8 tokenIndexFrom,
		uint8 tokenIndexTo,
		uint256 dx,
		uint256 minDy,
		uint256 deadline
	) external returns (uint256);

	function addLiquidity(
		uint256[] calldata amounts,
		uint256 minToMint,
		uint256 deadline
	) external returns (uint256);

	function removeLiquidity(
		uint256 amount,
		uint256[] calldata minAmounts,
		uint256 deadline
	) external returns (uint256[] memory);

	function removeLiquidityOneToken(
		uint256 tokenAmount,
		uint8 tokenIndex,
		uint256 minAmount,
		uint256 deadline
	) external returns (uint256);

	function removeLiquidityImbalance(
		uint256[] calldata amounts,
		uint256 maxBurnAmount,
		uint256 deadline
	) external returns (uint256);

	function swapStorage()
		external
		view
		returns (
			uint256 initialA,
			uint256 futureA,
			uint256 initialATime,
			uint256 futureATime,
			uint256 swapFee,
			uint256 adminFee,
			address lpToken
		);
}

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IStakingRewards is IERC20 {
	function stakingToken() external view returns (address);

	function lastTimeRewardApplicable() external view returns (uint256);

	function rewardPerToken() external view returns (uint256);

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

	function getRewardForDuration() external view returns (uint256);

	function stakeWithPermit(
		uint256 amount,
		uint256 deadline,
		uint8 v,
		bytes32 r,
		bytes32 s
	) external;

	function stake(uint256 amount) external;

	function withdraw(uint256 amount) external;

	function getReward() external;

	function exit() external;
}

// some farms use sushi interface
interface IMasterChef {
	// depositing 0 amount will withdraw the rewards (harvest)
	function deposit(uint256 _pid, uint256 _amount) external;

	function withdraw(uint256 _pid, uint256 _amount) external;

	function userInfo(uint256 _pid, address _user) external view returns (uint256, uint256);

	function emergencyWithdraw(uint256 _pid) external;

	function pendingTokens(uint256 _pid, address _user)
		external
		view
		returns (
			uint256,
			address,
			string memory,
			uint256
		);
}

interface IMiniChefV2 {
	struct UserInfo {
		uint256 amount;
		int256 rewardDebt;
	}

	struct PoolInfo {
		uint128 accSushiPerShare;
		uint64 lastRewardTime;
		uint64 allocPoint;
	}

	function poolLength() external view returns (uint256);

	function updatePool(uint256 pid) external returns (IMiniChefV2.PoolInfo memory);

	function userInfo(uint256 _pid, address _user) external view returns (uint256, int256);

	function deposit(
		uint256 pid,
		uint256 amount,
		address to
	) external;

	function withdraw(
		uint256 pid,
		uint256 amount,
		address to
	) external;

	function harvest(uint256 pid, address to) external;

	function withdrawAndHarvest(
		uint256 pid,
		uint256 amount,
		address to
	) external;

	function emergencyWithdraw(uint256 pid, address to) external;
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import "./IUniswapV3SwapCallback.sol";

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
	struct ExactInputSingleParams {
		address tokenIn;
		address tokenOut;
		uint24 fee;
		address recipient;
		uint256 deadline;
		uint256 amountIn;
		uint256 amountOutMinimum;
		uint160 sqrtPriceLimitX96;
	}

	/// @notice Swaps `amountIn` of one token for as much as possible of another token
	/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
	/// @return amountOut The amount of the received token
	function exactInputSingle(ExactInputSingleParams calldata params)
		external
		payable
		returns (uint256 amountOut);

	struct ExactInputParams {
		bytes path;
		address recipient;
		uint256 deadline;
		uint256 amountIn;
		uint256 amountOutMinimum;
	}

	/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
	/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
	/// @return amountOut The amount of the received token
	function exactInput(ExactInputParams calldata params)
		external
		payable
		returns (uint256 amountOut);

	struct ExactOutputSingleParams {
		address tokenIn;
		address tokenOut;
		uint24 fee;
		address recipient;
		uint256 deadline;
		uint256 amountOut;
		uint256 amountInMaximum;
		uint160 sqrtPriceLimitX96;
	}

	/// @notice Swaps as little as possible of one token for `amountOut` of another token
	/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
	/// @return amountIn The amount of the input token
	function exactOutputSingle(ExactOutputSingleParams calldata params)
		external
		payable
		returns (uint256 amountIn);

	struct ExactOutputParams {
		bytes path;
		address recipient;
		uint256 deadline;
		uint256 amountOut;
		uint256 amountInMaximum;
	}

	/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
	/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
	/// @return amountIn The amount of the input token
	function exactOutput(ExactOutputParams calldata params)
		external
		payable
		returns (uint256 amountIn);
}

File 24 of 26 : IUniswapV3SwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
	/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
	/// @dev In the implementation you must pay the pool tokens owed for the swap.
	/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
	/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
	/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
	/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
	/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
	/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
	/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
	function uniswapV3SwapCallback(
		int256 amount0Delta,
		int256 amount1Delta,
		bytes calldata data
	) external;
}

// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.16;

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

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

		require(callStatus, "ETH_TRANSFER_FAILED");
	}
}

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

import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IMiniChefV2 } from "../../interfaces/uniswap/IStakingRewards.sol";
import { HarvestSwapParams } from "../../interfaces/Structs.sol";
import { ISwapRouter } from "../../interfaces/uniswap/ISwapRouter.sol";

// import "hardhat/console.sol";

struct FarmConfig {
	address farm;
	uint16 farmId;
	address router;
	address farmToken;
}

abstract contract MiniChef2Farm {
	using SafeERC20 for IERC20;

	IMiniChefV2 public farm;
	ISwapRouter public farmRouter;
	IERC20 public farmToken;
	uint256 public farmId;

	event HarvestedToken(address token, uint256 amount, uint256 amountUnderlying);

	constructor(FarmConfig memory farmConfig) {
		farm = IMiniChefV2(farmConfig.farm);
		farmRouter = ISwapRouter(farmConfig.router);
		farmToken = IERC20(farmConfig.farmToken);
		farmId = farmConfig.farmId;
		farmToken.safeApprove(address(farmRouter), type(uint256).max);
	}

	function _withdrawFromFarm(uint256 amount) internal {
		farm.withdraw(farmId, amount, address(this));
	}

	function _depositIntoFarm(uint256 amount) internal {
		farm.deposit(farmId, amount, address(this));
	}

	function _getFarmLp() internal view returns (uint256 lp) {
		(lp, ) = farm.userInfo(farmId, address(this));
	}

	function _harvestFarm(HarvestSwapParams calldata swapParams)
		internal
		returns (uint256 amountOut)
	{
		farm.harvest(farmId, address(this));

		uint256 harvested = farmToken.balanceOf(address(this));
		if (harvested == 0) return 0;

		ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
			path: swapParams.pathData,
			recipient: address(this),
			deadline: block.timestamp,
			amountIn: harvested,
			amountOutMinimum: swapParams.min
		});
		amountOut = farmRouter.exactInput(params);
		emit HarvestedToken(address(farmToken), harvested, amountOut);
	}
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_lpToken","type":"address"},{"internalType":"address","name":"_synapsePool","type":"address"},{"internalType":"uint8","name":"_coinId","type":"uint8"},{"components":[{"internalType":"address","name":"farm","type":"address"},{"internalType":"uint16","name":"farmId","type":"uint16"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"farmToken","type":"address"}],"internalType":"struct FarmConfig","name":"_farmConfig","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"MaxTvlReached","type":"error"},{"inputs":[],"name":"MinLiquidity","type":"error"},{"inputs":[],"name":"NotImplemented","type":"error"},{"inputs":[],"name":"OnlyVault","type":"error"},{"inputs":[],"name":"StrategyHasBalance","type":"error"},{"inputs":[],"name":"ZeroAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"EmergencyAction","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountUnderlying","type":"uint256"}],"name":"HarvestedToken","type":"event"},{"inputs":[],"name":"_nTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"closePosition","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"coinId","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralToUnderlying","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct EAction[]","name":"actions","type":"tuple[]"}],"name":"emergencyAction","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"farm","outputs":[{"internalType":"contract IMiniChefV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farmId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farmRouter","outputs":[{"internalType":"contract ISwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farmToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAndUpdateTvl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"uAmnt","type":"uint256"}],"name":"getDepositAmnt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLpBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLpToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxTvl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTvl","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lpTokens","type":"uint256"}],"name":"getWithdrawAmnt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"pathData","type":"bytes"}],"internalType":"struct HarvestSwapParams[]","name":"params","type":"tuple[]"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"pathData","type":"bytes"}],"internalType":"struct HarvestSwapParams[]","name":"","type":"tuple[]"}],"name":"harvest","outputs":[{"internalType":"uint256[]","name":"harvested","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lpToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"synapsePool","outputs":[{"internalType":"contract ISynapseSwap","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

0x60806040523480156200001157600080fd5b5060405162002359380380620023598339810160408190526200003491620006de565b8051600080546001600160a01b039283166001600160a01b03199182161790915560408301516001805491841691831682179055606084015160028054919094169216821790925560208084015161ffff166003558392620000a492916000199062000de86200027c821b17901c565b50600480546001600160a01b03199081166001600160a01b038881169190911783556008805460ff60a01b1916600160a01b60ff888116820292909217928390556006805486168a861690811790915560078054909616948b169490941790945560405162415c3360e91b81529390910416928201929092526382b8660090602401602060405180830381865afa15801562000144573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200016a9190620007c9565b600880546001600160a01b0319166001600160a01b03929092169182179055620001a490846000196200027c602090811b62000de817901c565b600054600754620001d1916001600160a01b0391821691166000196200027c602090811b62000de817901c565b600754620001f8906001600160a01b0316846000196200027c602090811b62000de817901c565b60065460405163797d695b60e11b8152600160048201526001600160a01b039091169063f2fad2b690602401600060405180830381865afa15801562000242573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200026c9190810190620007f0565b5160055550620009579350505050565b801580620002fa5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015620002d2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002f89190620008a0565b155b620003725760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e63650000000000000000000060648201526084015b60405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b0390811663095ea7b360e01b17909152620003ca918591620003cf16565b505050565b60006200042b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316620004ad60201b62000f28179092919060201c565b805190915015620003ca57808060200190518101906200044c9190620008ba565b620003ca5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840162000369565b6060620004be8484600085620004c6565b949350505050565b606082471015620005295760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840162000369565b600080866001600160a01b0316858760405162000547919062000904565b60006040518083038185875af1925050503d806000811462000586576040519150601f19603f3d011682016040523d82523d6000602084013e6200058b565b606091505b5090925090506200059f87838387620005aa565b979650505050505050565b606083156200061e57825160000362000616576001600160a01b0385163b620006165760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640162000369565b5081620004be565b620004be8383815115620006355781518083602001fd5b8060405162461bcd60e51b815260040162000369919062000922565b6001600160a01b03811681146200066757600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715620006a557620006a56200066a565b60405290565b604051601f8201601f191681016001600160401b0381118282101715620006d657620006d66200066a565b604052919050565b6000806000806000858703610100811215620006f957600080fd5b8651620007068162000651565b6020880151909650620007198162000651565b60408801519095506200072c8162000651565b606088015190945060ff811681146200074457600080fd5b92506080607f19820112156200075957600080fd5b506200076462000680565b6080870151620007748162000651565b815260a087015161ffff811681146200078c57600080fd5b602082015260c0870151620007a18162000651565b604082015260e0870151620007b68162000651565b6060820152949793965091945092919050565b600060208284031215620007dc57600080fd5b8151620007e98162000651565b9392505050565b600060208083850312156200080457600080fd5b82516001600160401b03808211156200081c57600080fd5b818501915085601f8301126200083157600080fd5b8151818111156200084657620008466200066a565b8060051b915062000859848301620006ab565b81815291830184019184810190888411156200087457600080fd5b938501935b83851015620008945784518252938501939085019062000879565b98975050505050505050565b600060208284031215620008b357600080fd5b5051919050565b600060208284031215620008cd57600080fd5b81518015158114620007e957600080fd5b60005b83811015620008fb578181015183820152602001620008e1565b50506000910152565b6000825162000918818460208701620008de565b9190910192915050565b602081526000825180602084015262000943816040850160208701620008de565b601f01601f19169190910160400192915050565b6119f280620009676000396000f3fe6080604052600436106101105760003560e01c8063016f1869146101155780630d55046c1461013e5780631e9a69501461016b578063278de0001461018b57806329ebc534146101a15780632a1ebce1146101b65780633164ffd8146101e4578063358d6a041461020457806336e9332d146102195780635fcbd28514610239578063632765cf146102595780636f307dc3146102795780637df3927e146102995780638214f5a4146102ae5780638421403d146102cc5780639a79bf8e146102e1578063a126d60114610301578063b6b55f2514610321578063c2442f9314610341578063c7fe2d6414610361578063d075dd4214610376578063fbfa77cf1461038b578063fc6d8a11146103ab575b600080fd5b34801561012157600080fd5b5061012b60055481565b6040519081526020015b60405180910390f35b34801561014a57600080fd5b5060015461015e906001600160a01b031681565b60405161013591906114ef565b34801561017757600080fd5b5061012b61018636600461151a565b6103de565b34801561019757600080fd5b5061012b60035481565b3480156101ad57600080fd5b5061012b6104cb565b3480156101c257600080fd5b506101d66101d136600461158f565b610559565b604051610135929190611635565b3480156101f057600080fd5b5060065461015e906001600160a01b031681565b34801561021057600080fd5b5061012b610645565b34801561022557600080fd5b5060005461015e906001600160a01b031681565b34801561024557600080fd5b5060075461015e906001600160a01b031681565b34801561026557600080fd5b5061012b610274366004611663565b6106ca565b34801561028557600080fd5b5060085461015e906001600160a01b031681565b6102ac6102a736600461167c565b61074b565b005b3480156102ba57600080fd5b506007546001600160a01b031661015e565b3480156102d857600080fd5b5061012b61094f565b3480156102ed57600080fd5b5061012b6102fc366004611663565b610959565b34801561030d57600080fd5b5061012b61031c366004611663565b610a4b565b34801561032d57600080fd5b5061012b61033c366004611663565b610ba5565b34801561034d57600080fd5b5060025461015e906001600160a01b031681565b34801561036d57600080fd5b5061012b610cd5565b34801561038257600080fd5b5061012b610cdb565b34801561039757600080fd5b5060045461015e906001600160a01b031681565b3480156103b757600080fd5b506008546103cc90600160a01b900460ff1681565b60405160ff9091168152602001610135565b6004546000906001600160a01b0316331461040c57604051638d1af8bd60e01b815260040160405180910390fd5b8160000361041c575060006104c5565b61042582610f3f565b6006546008546040516301f1d0ab60e51b81526001600160a01b0390921691633e3a156091610468918691600160a01b900460ff169060009042906004016116bd565b6020604051808303816000875af1158015610487573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ab91906116db565b6008549091506104c5906001600160a01b03168483610fa9565b92915050565b60065460085460405163342a87a160e01b81526000926001600160a01b03169163342a87a19161051391670de0b6b3a764000091600160a01b90910460ff16906004016116f4565b602060405180830381865afa158015610530573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055491906116db565b905090565b60045460609081906001600160a01b0316331461058957604051638d1af8bd60e01b815260040160405180910390fd5b60006105b8878760008181106105a1576105a1611705565b90506020028101906105b3919061171b565b610fc8565b905080156105cb576105c981610ba5565b505b604080516001808252818301909252906020808301908036833701905050925080836000815181106105ff576105ff611705565b6020908102919091010152826000604051908082528060200260200182016040528015610636578160200160208202803683370190505b50925092505094509492505050565b6000600a600760009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561069c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c091906116db565b6105549190611751565b60065460085460405163342a87a160e01b81526000926001600160a01b03169163342a87a19161070a918691600160a01b90910460ff16906004016116f4565b602060405180830381865afa158015610727573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c591906116db565b6004546001600160a01b0316331461077657604051638d1af8bd60e01b815260040160405180910390fd5b8060005b8181101561094957600084848381811061079657610796611705565b90506020028101906107a89190611773565b6107b6906020810190611789565b905060008585848181106107cc576107cc611705565b90506020028101906107de9190611773565b6107ec9060408101906117a4565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093945050506001600160a01b038416905087878681811061083f5761083f611705565b90506020028101906108519190611773565b6020013583604051610863919061180e565b60006040518083038185875af1925050503d80600081146108a0576040519150601f19603f3d011682016040523d82523d6000602084013e6108a5565b606091505b50509050806108f45760405162461bcd60e51b8152602060048201526016602482015275195b595c99d95b98de5058dd1a5bdb8819985a5b195960521b60448201526064015b60405180910390fd5b826001600160a01b03167fa9f1cb7eee5fc621e043c1ef431febb0f901998a6c0cbdf70147b0fe4d9f5a6a8360405161092d919061184c565b60405180910390a2505050806109429061185f565b905061077a565b50505050565b60006105546111fb565b6000806005546001600160401b038111156109765761097661173b565b60405190808252806020026020018201604052801561099f578160200160208202803683370190505b50600854815191925084918391600160a01b900460ff169081106109c5576109c5611705565b6020908102919091010152600654604051637355940360e11b81526001600160a01b039091169063e6ab280690610a03908490600190600401611886565b602060405180830381865afa158015610a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4491906116db565b9392505050565b6004546000906001600160a01b03163314610a7957604051638d1af8bd60e01b815260040160405180910390fd5b600080546003546040516393f1a40b60e01b81526001600160a01b03909216916393f1a40b91610aad9130906004016118aa565b6040805180830381865afa158015610ac9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aed91906118c1565b509050610af981610f3f565b6006546008546040516301f1d0ab60e51b81526001600160a01b0390921691633e3a156091610b3c918591600160a01b900460ff169060009042906004016116bd565b6020604051808303816000875af1158015610b5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7f91906116db565b600454600854919350610b9f916001600160a01b03908116911684610fa9565b50919050565b6004546000906001600160a01b03163314610bd357604051638d1af8bd60e01b815260040160405180910390fd5b60006005546001600160401b03811115610bef57610bef61173b565b604051908082528060200260200182016040528015610c18578160200160208202803683370190505b50600854815191925084918391600160a01b900460ff16908110610c3e57610c3e611705565b6020908102919091010152600654604051634d49e87d60e01b81526000916001600160a01b031690634d49e87d90610c7e908590859042906004016118e5565b6020604051808303816000875af1158015610c9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc191906116db565b9050610ccc8161126f565b9150505b919050565b60006105545b600080546003546040516393f1a40b60e01b815283926001600160a01b0316916393f1a40b91610d10919030906004016118aa565b6040805180830381865afa158015610d2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d5091906118c1565b50905080600003610d6357600091505090565b60065460085460405163342a87a160e01b81526001600160a01b039092169163342a87a191610da1918591600160a01b900460ff16906004016116f4565b602060405180830381865afa158015610dbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de291906116db565b91505090565b801580610e625750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906116db565b155b610ecd5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016108eb565b610f238363095ea7b360e01b8484604051602401610eec92919061190a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526112a4565b505050565b6060610f378484600085611376565b949350505050565b600054600354604051630ad58d2f60e01b81526001600160a01b0390921691630ad58d2f91610f749185903090600401611923565b600060405180830381600087803b158015610f8e57600080fd5b505af1158015610fa2573d6000803e3d6000fd5b5050505050565b610f238363a9059cbb60e01b8484604051602401610eec92919061190a565b60008054600354604051630c7e663b60e11b81526001600160a01b03909216916318fccc7691610ffc9130906004016118aa565b600060405180830381600087803b15801561101657600080fd5b505af115801561102a573d6000803e3d6000fd5b50506002546040516370a0823160e01b8152600093506001600160a01b0390911691506370a08231906110619030906004016114ef565b602060405180830381865afa15801561107e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a291906116db565b9050806000036110b55750600092915050565b60006040518060a001604052808580606001906110d291906117a4565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525030602080830191909152426040808401919091526060830186905290870135608090920191909152600154905163c04b8d5960e01b81529192506001600160a01b03169063c04b8d5990611161908490600401611942565b6020604051808303816000875af1158015611180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a491906116db565b600254604080516001600160a01b0390921682526020820185905281018290529093507fc7b659727374d70cd5dafd7334a8ade5fced5d56668b2801da8a16f128949f0c9060600160405180910390a15050919050565b600080546003546040516393f1a40b60e01b81526001600160a01b03909216916393f1a40b9161122f9130906004016118aa565b6040805180830381865afa15801561124b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9f91906118c1565b600054600354604051638dbdbe6d60e01b81526001600160a01b0390921691638dbdbe6d91610f749185903090600401611923565b60006112f9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610f289092919063ffffffff16565b805190915015610f235780806020019051810190611317919061199a565b610f235760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108eb565b6060824710156113d75760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108eb565b600080866001600160a01b031685876040516113f3919061180e565b60006040518083038185875af1925050503d8060008114611430576040519150601f19603f3d011682016040523d82523d6000602084013e611435565b606091505b509150915061144687838387611451565b979650505050505050565b606083156114c05782516000036114b9576001600160a01b0385163b6114b95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108eb565b5081610f37565b610f3783838151156114d55781518083602001fd5b8060405162461bcd60e51b81526004016108eb919061184c565b6001600160a01b0391909116815260200190565b80356001600160a01b0381168114610cd057600080fd5b6000806040838503121561152d57600080fd5b61153683611503565b946020939093013593505050565b60008083601f84011261155657600080fd5b5081356001600160401b0381111561156d57600080fd5b6020830191508360208260051b850101111561158857600080fd5b9250929050565b600080600080604085870312156115a557600080fd5b84356001600160401b03808211156115bc57600080fd5b6115c888838901611544565b909650945060208701359150808211156115e157600080fd5b506115ee87828801611544565b95989497509550505050565b600081518084526020808501945080840160005b8381101561162a5781518752958201959082019060010161160e565b509495945050505050565b60408152600061164860408301856115fa565b828103602084015261165a81856115fa565b95945050505050565b60006020828403121561167557600080fd5b5035919050565b6000806020838503121561168f57600080fd5b82356001600160401b038111156116a557600080fd5b6116b185828601611544565b90969095509350505050565b93845260ff9290921660208401526040830152606082015260800190565b6000602082840312156116ed57600080fd5b5051919050565b91825260ff16602082015260400190565b634e487b7160e01b600052603260045260246000fd5b60008235607e1983360301811261173157600080fd5b9190910192915050565b634e487b7160e01b600052604160045260246000fd5b60008261176e57634e487b7160e01b600052601260045260246000fd5b500490565b60008235605e1983360301811261173157600080fd5b60006020828403121561179b57600080fd5b610a4482611503565b6000808335601e198436030181126117bb57600080fd5b8301803591506001600160401b038211156117d557600080fd5b60200191503681900382131561158857600080fd5b60005b838110156118055781810151838201526020016117ed565b50506000910152565b600082516117318184602087016117ea565b600081518084526118388160208601602086016117ea565b601f01601f19169290920160200192915050565b602081526000610a446020830184611820565b60006001820161187f57634e487b7160e01b600052601160045260246000fd5b5060010190565b60408152600061189960408301856115fa565b905082151560208301529392505050565b9182526001600160a01b0316602082015260400190565b600080604083850312156118d457600080fd5b505080516020909101519092909150565b6060815260006118f860608301866115fa565b60208301949094525060400152919050565b6001600160a01b03929092168252602082015260400190565b92835260208301919091526001600160a01b0316604082015260600190565b602081526000825160a0602084015261195e60c0840182611820565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b6000602082840312156119ac57600080fd5b81518015158114610a4457600080fdfea2646970667358221220321c63347f848eaa3d22243da0d02853f7ce4ec9bcb1efde170681d96d9fcd0a64736f6c634300081000330000000000000000000000005fecb965c834101fd26d6d7d392da69746b87585000000000000000000000000d70a52248e546a3b260849386410c7170c7bd1e9000000000000000000000000a067668661c84476afcdc6fa5d758c4c01c34352000000000000000000000000000000000000000000000000000000000000000100000000000000000000000073186f2cf2493f20836b17b21ae79fc12934e2070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000080f6aed32fc474dd5717105dba5ea57268f46eb

Deployed Bytecode

0x6080604052600436106101105760003560e01c8063016f1869146101155780630d55046c1461013e5780631e9a69501461016b578063278de0001461018b57806329ebc534146101a15780632a1ebce1146101b65780633164ffd8146101e4578063358d6a041461020457806336e9332d146102195780635fcbd28514610239578063632765cf146102595780636f307dc3146102795780637df3927e146102995780638214f5a4146102ae5780638421403d146102cc5780639a79bf8e146102e1578063a126d60114610301578063b6b55f2514610321578063c2442f9314610341578063c7fe2d6414610361578063d075dd4214610376578063fbfa77cf1461038b578063fc6d8a11146103ab575b600080fd5b34801561012157600080fd5b5061012b60055481565b6040519081526020015b60405180910390f35b34801561014a57600080fd5b5060015461015e906001600160a01b031681565b60405161013591906114ef565b34801561017757600080fd5b5061012b61018636600461151a565b6103de565b34801561019757600080fd5b5061012b60035481565b3480156101ad57600080fd5b5061012b6104cb565b3480156101c257600080fd5b506101d66101d136600461158f565b610559565b604051610135929190611635565b3480156101f057600080fd5b5060065461015e906001600160a01b031681565b34801561021057600080fd5b5061012b610645565b34801561022557600080fd5b5060005461015e906001600160a01b031681565b34801561024557600080fd5b5060075461015e906001600160a01b031681565b34801561026557600080fd5b5061012b610274366004611663565b6106ca565b34801561028557600080fd5b5060085461015e906001600160a01b031681565b6102ac6102a736600461167c565b61074b565b005b3480156102ba57600080fd5b506007546001600160a01b031661015e565b3480156102d857600080fd5b5061012b61094f565b3480156102ed57600080fd5b5061012b6102fc366004611663565b610959565b34801561030d57600080fd5b5061012b61031c366004611663565b610a4b565b34801561032d57600080fd5b5061012b61033c366004611663565b610ba5565b34801561034d57600080fd5b5060025461015e906001600160a01b031681565b34801561036d57600080fd5b5061012b610cd5565b34801561038257600080fd5b5061012b610cdb565b34801561039757600080fd5b5060045461015e906001600160a01b031681565b3480156103b757600080fd5b506008546103cc90600160a01b900460ff1681565b60405160ff9091168152602001610135565b6004546000906001600160a01b0316331461040c57604051638d1af8bd60e01b815260040160405180910390fd5b8160000361041c575060006104c5565b61042582610f3f565b6006546008546040516301f1d0ab60e51b81526001600160a01b0390921691633e3a156091610468918691600160a01b900460ff169060009042906004016116bd565b6020604051808303816000875af1158015610487573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ab91906116db565b6008549091506104c5906001600160a01b03168483610fa9565b92915050565b60065460085460405163342a87a160e01b81526000926001600160a01b03169163342a87a19161051391670de0b6b3a764000091600160a01b90910460ff16906004016116f4565b602060405180830381865afa158015610530573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055491906116db565b905090565b60045460609081906001600160a01b0316331461058957604051638d1af8bd60e01b815260040160405180910390fd5b60006105b8878760008181106105a1576105a1611705565b90506020028101906105b3919061171b565b610fc8565b905080156105cb576105c981610ba5565b505b604080516001808252818301909252906020808301908036833701905050925080836000815181106105ff576105ff611705565b6020908102919091010152826000604051908082528060200260200182016040528015610636578160200160208202803683370190505b50925092505094509492505050565b6000600a600760009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561069c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c091906116db565b6105549190611751565b60065460085460405163342a87a160e01b81526000926001600160a01b03169163342a87a19161070a918691600160a01b90910460ff16906004016116f4565b602060405180830381865afa158015610727573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104c591906116db565b6004546001600160a01b0316331461077657604051638d1af8bd60e01b815260040160405180910390fd5b8060005b8181101561094957600084848381811061079657610796611705565b90506020028101906107a89190611773565b6107b6906020810190611789565b905060008585848181106107cc576107cc611705565b90506020028101906107de9190611773565b6107ec9060408101906117a4565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092018290525093945050506001600160a01b038416905087878681811061083f5761083f611705565b90506020028101906108519190611773565b6020013583604051610863919061180e565b60006040518083038185875af1925050503d80600081146108a0576040519150601f19603f3d011682016040523d82523d6000602084013e6108a5565b606091505b50509050806108f45760405162461bcd60e51b8152602060048201526016602482015275195b595c99d95b98de5058dd1a5bdb8819985a5b195960521b60448201526064015b60405180910390fd5b826001600160a01b03167fa9f1cb7eee5fc621e043c1ef431febb0f901998a6c0cbdf70147b0fe4d9f5a6a8360405161092d919061184c565b60405180910390a2505050806109429061185f565b905061077a565b50505050565b60006105546111fb565b6000806005546001600160401b038111156109765761097661173b565b60405190808252806020026020018201604052801561099f578160200160208202803683370190505b50600854815191925084918391600160a01b900460ff169081106109c5576109c5611705565b6020908102919091010152600654604051637355940360e11b81526001600160a01b039091169063e6ab280690610a03908490600190600401611886565b602060405180830381865afa158015610a20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4491906116db565b9392505050565b6004546000906001600160a01b03163314610a7957604051638d1af8bd60e01b815260040160405180910390fd5b600080546003546040516393f1a40b60e01b81526001600160a01b03909216916393f1a40b91610aad9130906004016118aa565b6040805180830381865afa158015610ac9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610aed91906118c1565b509050610af981610f3f565b6006546008546040516301f1d0ab60e51b81526001600160a01b0390921691633e3a156091610b3c918591600160a01b900460ff169060009042906004016116bd565b6020604051808303816000875af1158015610b5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7f91906116db565b600454600854919350610b9f916001600160a01b03908116911684610fa9565b50919050565b6004546000906001600160a01b03163314610bd357604051638d1af8bd60e01b815260040160405180910390fd5b60006005546001600160401b03811115610bef57610bef61173b565b604051908082528060200260200182016040528015610c18578160200160208202803683370190505b50600854815191925084918391600160a01b900460ff16908110610c3e57610c3e611705565b6020908102919091010152600654604051634d49e87d60e01b81526000916001600160a01b031690634d49e87d90610c7e908590859042906004016118e5565b6020604051808303816000875af1158015610c9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc191906116db565b9050610ccc8161126f565b9150505b919050565b60006105545b600080546003546040516393f1a40b60e01b815283926001600160a01b0316916393f1a40b91610d10919030906004016118aa565b6040805180830381865afa158015610d2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d5091906118c1565b50905080600003610d6357600091505090565b60065460085460405163342a87a160e01b81526001600160a01b039092169163342a87a191610da1918591600160a01b900460ff16906004016116f4565b602060405180830381865afa158015610dbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de291906116db565b91505090565b801580610e625750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa158015610e3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6091906116db565b155b610ecd5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016108eb565b610f238363095ea7b360e01b8484604051602401610eec92919061190a565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526112a4565b505050565b6060610f378484600085611376565b949350505050565b600054600354604051630ad58d2f60e01b81526001600160a01b0390921691630ad58d2f91610f749185903090600401611923565b600060405180830381600087803b158015610f8e57600080fd5b505af1158015610fa2573d6000803e3d6000fd5b5050505050565b610f238363a9059cbb60e01b8484604051602401610eec92919061190a565b60008054600354604051630c7e663b60e11b81526001600160a01b03909216916318fccc7691610ffc9130906004016118aa565b600060405180830381600087803b15801561101657600080fd5b505af115801561102a573d6000803e3d6000fd5b50506002546040516370a0823160e01b8152600093506001600160a01b0390911691506370a08231906110619030906004016114ef565b602060405180830381865afa15801561107e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110a291906116db565b9050806000036110b55750600092915050565b60006040518060a001604052808580606001906110d291906117a4565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525030602080830191909152426040808401919091526060830186905290870135608090920191909152600154905163c04b8d5960e01b81529192506001600160a01b03169063c04b8d5990611161908490600401611942565b6020604051808303816000875af1158015611180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a491906116db565b600254604080516001600160a01b0390921682526020820185905281018290529093507fc7b659727374d70cd5dafd7334a8ade5fced5d56668b2801da8a16f128949f0c9060600160405180910390a15050919050565b600080546003546040516393f1a40b60e01b81526001600160a01b03909216916393f1a40b9161122f9130906004016118aa565b6040805180830381865afa15801561124b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9f91906118c1565b600054600354604051638dbdbe6d60e01b81526001600160a01b0390921691638dbdbe6d91610f749185903090600401611923565b60006112f9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610f289092919063ffffffff16565b805190915015610f235780806020019051810190611317919061199a565b610f235760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108eb565b6060824710156113d75760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108eb565b600080866001600160a01b031685876040516113f3919061180e565b60006040518083038185875af1925050503d8060008114611430576040519150601f19603f3d011682016040523d82523d6000602084013e611435565b606091505b509150915061144687838387611451565b979650505050505050565b606083156114c05782516000036114b9576001600160a01b0385163b6114b95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108eb565b5081610f37565b610f3783838151156114d55781518083602001fd5b8060405162461bcd60e51b81526004016108eb919061184c565b6001600160a01b0391909116815260200190565b80356001600160a01b0381168114610cd057600080fd5b6000806040838503121561152d57600080fd5b61153683611503565b946020939093013593505050565b60008083601f84011261155657600080fd5b5081356001600160401b0381111561156d57600080fd5b6020830191508360208260051b850101111561158857600080fd5b9250929050565b600080600080604085870312156115a557600080fd5b84356001600160401b03808211156115bc57600080fd5b6115c888838901611544565b909650945060208701359150808211156115e157600080fd5b506115ee87828801611544565b95989497509550505050565b600081518084526020808501945080840160005b8381101561162a5781518752958201959082019060010161160e565b509495945050505050565b60408152600061164860408301856115fa565b828103602084015261165a81856115fa565b95945050505050565b60006020828403121561167557600080fd5b5035919050565b6000806020838503121561168f57600080fd5b82356001600160401b038111156116a557600080fd5b6116b185828601611544565b90969095509350505050565b93845260ff9290921660208401526040830152606082015260800190565b6000602082840312156116ed57600080fd5b5051919050565b91825260ff16602082015260400190565b634e487b7160e01b600052603260045260246000fd5b60008235607e1983360301811261173157600080fd5b9190910192915050565b634e487b7160e01b600052604160045260246000fd5b60008261176e57634e487b7160e01b600052601260045260246000fd5b500490565b60008235605e1983360301811261173157600080fd5b60006020828403121561179b57600080fd5b610a4482611503565b6000808335601e198436030181126117bb57600080fd5b8301803591506001600160401b038211156117d557600080fd5b60200191503681900382131561158857600080fd5b60005b838110156118055781810151838201526020016117ed565b50506000910152565b600082516117318184602087016117ea565b600081518084526118388160208601602086016117ea565b601f01601f19169290920160200192915050565b602081526000610a446020830184611820565b60006001820161187f57634e487b7160e01b600052601160045260246000fd5b5060010190565b60408152600061189960408301856115fa565b905082151560208301529392505050565b9182526001600160a01b0316602082015260400190565b600080604083850312156118d457600080fd5b505080516020909101519092909150565b6060815260006118f860608301866115fa565b60208301949094525060400152919050565b6001600160a01b03929092168252602082015260400190565b92835260208301919091526001600160a01b0316604082015260600190565b602081526000825160a0602084015261195e60c0840182611820565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b6000602082840312156119ac57600080fd5b81518015158114610a4457600080fdfea2646970667358221220321c63347f848eaa3d22243da0d02853f7ce4ec9bcb1efde170681d96d9fcd0a64736f6c63430008100033

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
[ Download: CSV Export  ]

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.