false
true
0

Contract Address Details

0x3545AD8CAE619b2F40aD11C591154F2567c45E1e

Contract Name
FarmFactory
Creator
0xb8386e–f548d1 at 0xb14b31–172dc8
Balance
22,500,000 PLS ( )
Tokens
Fetching tokens...
Transactions
6 Transactions
Transfers
0 Transfers
Gas Used
4,298,900
Last Balance Update
26094033
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
FarmFactory




Optimization enabled
true
Compiler version
v0.8.20+commit.a1b79de6




Optimization runs
200
EVM Version
paris




Verified at
2026-02-12T22:36:08.409503Z

contracts/FarmFactory.sol

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

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./Farm.sol";

contract FarmFactory is Ownable {
    using SafeERC20 for IERC20;

    uint256 public farmCost;
    address public paymentReceiver;
    address public feeReceiver;

    address[] public farms;

    uint256 public farmCount;
    mapping(address => bool) public isFarm;

    event FarmCreated(address indexed farmAddress);
    event FundsCollected(address indexed receiver, uint256 amount);

    constructor() Ownable() {
        paymentReceiver = address(0x32463B4CC953e43c18F46e01859a0f64b20CA78E);
        feeReceiver = address(0x32fB5663619A657839A80133994E45c5e5cDf427);
        farmCost = 5000000 * 10**18;
    }

    function createFarm(address rewardsToken, address stakingToken, uint256 depositFeeBP, uint256 withdrawFeeBP) external payable {
        require(rewardsToken != address(0), "Invalid rewards token");
        require(stakingToken != address(0), "Invalid staking token");
        require(msg.value >= farmCost, "Insufficient payment");
        Farm newFarm = new Farm(rewardsToken, stakingToken , depositFeeBP, withdrawFeeBP);
        newFarm.transferOwnership(msg.sender);
        farms.push(address(newFarm));
        isFarm[address(newFarm)] = true;
        farmCount++;

        //10% sent to emit single-sided pool
        uint256 feeShare = (farmCost * 10) / 100;
        (bool success, ) = payable(feeReceiver).call{value: feeShare}("");
        require(success, "Transfer failed");

        emit FarmCreated(address(newFarm));
    }

    function getFarms() external view returns (address[] memory) {
        return farms;
    }

    function getFarmsPaginated(uint256 offset, uint256 limit) external view returns (address[] memory) {
        uint256 end = offset + limit;
        if (end > farms.length) {
            end = farms.length;
        }
        address[] memory paginatedFarms = new address[](end - offset);
        for (uint256 i = offset; i < end; i++) {
            paginatedFarms[i - offset] = farms[i];
        }
        return paginatedFarms;
    }

    struct FarmDetails {
        address farmAddress;
        address rewardsToken;
        address stakingToken;
        address owner;
        uint256 periodFinish;
        uint256 rewardRate;
        uint256 rewardsDuration;
        uint256 lastUpdateTime;
        uint256 rewardPerTokenStored;
        uint256 totalSupply;
        uint256 lastTimeRewardApplicable;
        uint256 rewardPerToken;
        uint256 rewardForDuration;
        uint256 rewardsTokenBalance;
        uint256 stakingTokenBalance;
        bool periodFinished;
        bool paused;
    }

    function getFarmDetails(address farmAddress) external view returns (FarmDetails memory) {
        require(isFarm[farmAddress], "Not a valid farm");

        Farm farm = Farm(farmAddress);

        IERC20 rewardsToken = farm.rewardsToken();
        IERC20 stakingToken = farm.stakingToken();
        
        return FarmDetails({
            farmAddress: farmAddress,
            rewardsToken: address(rewardsToken),
            stakingToken: address(stakingToken),
            owner: farm.owner(),
            periodFinish: farm.periodFinish(),
            rewardRate: farm.rewardRate(),
            rewardsDuration: farm.rewardsDuration(),
            lastUpdateTime: farm.lastUpdateTime(),
            rewardPerTokenStored: farm.rewardPerTokenStored(),
            totalSupply: farm.totalSupply(),
            lastTimeRewardApplicable: farm.lastTimeRewardApplicable(),
            rewardPerToken: farm.rewardPerToken(),
            rewardForDuration: farm.getRewardForDuration(),
            rewardsTokenBalance: rewardsToken.balanceOf(farmAddress),
            stakingTokenBalance: stakingToken.balanceOf(farmAddress),
            periodFinished: farm.checkPeriodFinish(),
            paused: farm.paused()
        });
    }

    function addFarm(address farmAddress) external onlyOwner {
        require(farmAddress != address(0), "Invalid farm address");
        require(!isFarm[farmAddress], "Farm already added");
        farms.push(farmAddress);
        isFarm[farmAddress] = true;
        farmCount++;
        emit FarmCreated(farmAddress);
    }

    function removeFarm(address farmAddress) external onlyOwner {
        require(isFarm[farmAddress], "Not a valid farm");
        isFarm[farmAddress] = false;

        for (uint256 i = 0; i < farms.length; i++) {
            if (farms[i] == farmAddress) {
                farms[i] = farms[farms.length - 1];
                farms.pop();
                farmCount--;
                break;
            }
        }
    }

    //cost for a new farm
    function setFarmCost(uint256 _farmCost) external onlyOwner {
        farmCost = _farmCost;
    }

    //set payment receiver address
    function setPaymentReceiver(address _paymentReceiver) external onlyOwner {
        require(_paymentReceiver != address(0), "Invalid receiver address");
        paymentReceiver = _paymentReceiver;
    }

    function setFeeReceiver(address _feeReceiver) external onlyOwner {
        require(_feeReceiver != address(0), "Invalid receiver address");
        feeReceiver = _feeReceiver;
    }

    //dev payment
    function collectFunds() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No funds to collect");
        (bool success, ) = payable(paymentReceiver).call{value: balance}("");
        require(success, "Transfer failed");
        emit FundsCollected(paymentReceiver, balance);
    }
}
        

@openzeppelin/contracts/access/Ownable.sol

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

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

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

@openzeppelin/contracts/interfaces/IERC4626.sol

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

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/security/Pausable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
          

@openzeppelin/contracts/security/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * 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}.
     *
     * 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 default value returned by this function, unless
     * it's 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 {}
}
          

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

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

@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol

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

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../utils/SafeERC20.sol";
import "../../../interfaces/IERC4626.sol";
import "../../../utils/math/Math.sol";

/**
 * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626].
 *
 * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for
 * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
 * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this
 * contract and not the "assets" token which is an independent contract.
 *
 * [CAUTION]
 * ====
 * In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning
 * with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation
 * attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial
 * deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may
 * similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by
 * verifying the amount received is as expected, using a wrapper that performs these checks such as
 * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
 *
 * Since v4.9, this implementation uses virtual assets and shares to mitigate that risk. The `_decimalsOffset()`
 * corresponds to an offset in the decimal representation between the underlying asset's decimals and the vault
 * decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which itself
 * determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default offset
 * (0) makes it non-profitable, as a result of the value being captured by the virtual shares (out of the attacker's
 * donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more
 * expensive than it is profitable. More details about the underlying math can be found
 * xref:erc4626.adoc#inflation-attack[here].
 *
 * The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
 * to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
 * will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
 * bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
 * `_convertToShares` and `_convertToAssets` functions.
 *
 * To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
 * ====
 *
 * _Available since v4.7._
 */
abstract contract ERC4626 is ERC20, IERC4626 {
    using Math for uint256;

    IERC20 private immutable _asset;
    uint8 private immutable _underlyingDecimals;

    /**
     * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777).
     */
    constructor(IERC20 asset_) {
        (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
        _underlyingDecimals = success ? assetDecimals : 18;
        _asset = asset_;
    }

    /**
     * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
     */
    function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
        (bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
            abi.encodeWithSelector(IERC20Metadata.decimals.selector)
        );
        if (success && encodedDecimals.length >= 32) {
            uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
            if (returnedDecimals <= type(uint8).max) {
                return (true, uint8(returnedDecimals));
            }
        }
        return (false, 0);
    }

    /**
     * @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
     * "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
     * asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
     *
     * See {IERC20Metadata-decimals}.
     */
    function decimals() public view virtual override(IERC20Metadata, ERC20) returns (uint8) {
        return _underlyingDecimals + _decimalsOffset();
    }

    /** @dev See {IERC4626-asset}. */
    function asset() public view virtual override returns (address) {
        return address(_asset);
    }

    /** @dev See {IERC4626-totalAssets}. */
    function totalAssets() public view virtual override returns (uint256) {
        return _asset.balanceOf(address(this));
    }

    /** @dev See {IERC4626-convertToShares}. */
    function convertToShares(uint256 assets) public view virtual override returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-convertToAssets}. */
    function convertToAssets(uint256 shares) public view virtual override returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-maxDeposit}. */
    function maxDeposit(address) public view virtual override returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxMint}. */
    function maxMint(address) public view virtual override returns (uint256) {
        return type(uint256).max;
    }

    /** @dev See {IERC4626-maxWithdraw}. */
    function maxWithdraw(address owner) public view virtual override returns (uint256) {
        return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
    }

    /** @dev See {IERC4626-maxRedeem}. */
    function maxRedeem(address owner) public view virtual override returns (uint256) {
        return balanceOf(owner);
    }

    /** @dev See {IERC4626-previewDeposit}. */
    function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-previewMint}. */
    function previewMint(uint256 shares) public view virtual override returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Up);
    }

    /** @dev See {IERC4626-previewWithdraw}. */
    function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
        return _convertToShares(assets, Math.Rounding.Up);
    }

    /** @dev See {IERC4626-previewRedeem}. */
    function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
        return _convertToAssets(shares, Math.Rounding.Down);
    }

    /** @dev See {IERC4626-deposit}. */
    function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
        require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");

        uint256 shares = previewDeposit(assets);
        _deposit(_msgSender(), receiver, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-mint}.
     *
     * As opposed to {deposit}, minting is allowed even if the vault is in a state where the price of a share is zero.
     * In this case, the shares will be minted without requiring any assets to be deposited.
     */
    function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
        require(shares <= maxMint(receiver), "ERC4626: mint more than max");

        uint256 assets = previewMint(shares);
        _deposit(_msgSender(), receiver, assets, shares);

        return assets;
    }

    /** @dev See {IERC4626-withdraw}. */
    function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256) {
        require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");

        uint256 shares = previewWithdraw(assets);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return shares;
    }

    /** @dev See {IERC4626-redeem}. */
    function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256) {
        require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");

        uint256 assets = previewRedeem(shares);
        _withdraw(_msgSender(), receiver, owner, assets, shares);

        return assets;
    }

    /**
     * @dev Internal conversion function (from assets to shares) with support for rounding direction.
     */
    function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
        return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
    }

    /**
     * @dev Internal conversion function (from shares to assets) with support for rounding direction.
     */
    function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) {
        return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
    }

    /**
     * @dev Deposit/mint common workflow.
     */
    function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
        // If _asset is ERC777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
        // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
        // assets are transferred and before the shares are minted, which is a valid state.
        // slither-disable-next-line reentrancy-no-eth
        SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
        _mint(receiver, shares);

        emit Deposit(caller, receiver, assets, shares);
    }

    /**
     * @dev Withdraw/redeem common workflow.
     */
    function _withdraw(
        address caller,
        address receiver,
        address owner,
        uint256 assets,
        uint256 shares
    ) internal virtual {
        if (caller != owner) {
            _spendAllowance(owner, caller, shares);
        }

        // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
        // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
        // calls the vault, which is assumed not malicious.
        //
        // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
        // shares are burned and after the assets are transferred, which is a valid state.
        _burn(owner, shares);
        SafeERC20.safeTransfer(_asset, receiver, assets);

        emit Withdraw(caller, receiver, owner, assets, shares);
    }

    function _decimalsOffset() internal view virtual returns (uint8) {
        return 0;
    }
}
          

@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

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

@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

@openzeppelin/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}
          

@openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/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);
        }
    }
}
          

@openzeppelin/contracts/utils/Context.sol

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

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

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

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

@openzeppelin/contracts/utils/math/Math.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 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 256, 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 << 3) < value ? 1 : 0);
        }
    }
}
          

@openzeppelin/contracts/utils/math/SafeMath.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
          

contracts/Bank.sol

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

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";

interface IPulseXStableSwapThreePool {
    function coins(uint256 i) external view returns (address);
    function token() external view returns (address); // LP token
    function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount) external payable;
    function remove_liquidity_one_coin(uint256 _token_amount, uint256 i, uint256 min_amount) external;
    function calc_token_amount(uint256[3] calldata amounts, bool deposit) external view returns (uint256);
    function calc_withdraw_one_coin(uint256 _token_amount, uint256 i) external view returns (uint256);
}

contract CurveV3ThreePool4626Vault is ERC4626, ReentrancyGuard {
    using SafeERC20 for IERC20;

    // ------------------------- errors -------------------------

    error InvalidIndex();
    error UnsupportedNativeCoin();
    error ZeroAmount();
    error Slippage();
    error NotSupportedAsset();

    // ------------------------- immutables -------------------------

    // Underlying Curve-v3-style pool
    IPulseXStableSwapThreePool public immutable pool;

    // The LP token is the ERC-4626 asset()
    IERC20 public immutable lpToken;

    // Underlying pool coins (cached for gas / UX)
    address public immutable coin0;
    address public immutable coin1;
    address public immutable coin2;

    // PulseX pool uses this sentinel for native PLS
    address public constant PLS_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    // ------------------------- events -------------------------

    event DepositUnderlying(
        address indexed caller,
        address indexed receiver,
        uint256 indexed i,
        uint256 amountIn,
        uint256 sharesOut
    );

    event RedeemUnderlying(
        address indexed caller,
        address indexed receiver,
        address indexed owner,
        uint256 i,
        uint256 sharesIn,
        uint256 amountOut
    );

    // ------------------------- constructor -------------------------

    constructor(
        IPulseXStableSwapThreePool _pool,
        string memory name_,
        string memory symbol_
    )
        ERC20(name_, symbol_)
        ERC4626(IERC20Metadata(_pool.token()))
    {
        pool = _pool;

        address lp = _pool.token();
        lpToken = IERC20(lp);

        // Cache coins
        coin0 = _pool.coins(0);
        coin1 = _pool.coins(1);
        coin2 = _pool.coins(2);

        // Approve pool to burn LP from this vault during withdrawals (remove_liquidity_one_coin uses burnFrom(msg.sender))
        IERC20(lp).forceApprove(address(_pool), type(uint256).max);

        // NOTE: coin approvals are done lazily in depositUnderlying() per coin.
    }

    // ------------------------- ERC-4626 core -------------------------

    /**
     * @dev Total managed assets in ERC-4626 terms are LP tokens held by this vault.
     */
    function totalAssets() public view override returns (uint256) {
        return lpToken.balanceOf(address(this));
    }

    /**
     * @dev We want “1 share == 1 LP token” semantics.
     * Because asset()==LP and we mint/burn 1:1, conversions are identity.
     * (ERC4626 default is ratio-based; overriding removes edge cases with dust.)
     */
    function convertToShares(uint256 assets) public pure override returns (uint256) {
        return assets;
    }

    function convertToAssets(uint256 shares) public pure override returns (uint256) {
        return shares;
    }

    function previewDeposit(uint256 assets) public pure override returns (uint256) {
        return assets;
    }

    function previewMint(uint256 shares) public pure override returns (uint256) {
        return shares;
    }

    function previewWithdraw(uint256 assets) public pure override returns (uint256) {
        return assets;
    }

    function previewRedeem(uint256 shares) public pure override returns (uint256) {
        return shares;
    }

    // ------------------------- underlying helpers (zap in/out) -------------------------

    /**
     * @notice Deposit an underlying pool coin (stable) and receive vault shares (== LP tokens minted).
     * @param i Coin index (0..2).
     * @param amountIn Amount of that coin to deposit.
     * @param minSharesOut Minimum acceptable shares (LP) minted (slippage protection).
     * @param receiver Receiver of vault shares.
     */
    function depositUnderlying(
        uint256 i,
        uint256 amountIn,
        uint256 minSharesOut,
        address receiver
    ) external nonReentrant returns (uint256 sharesOut) {
        if (amountIn == 0) revert ZeroAmount();
        if (i > 2) revert InvalidIndex();

        address coin = _coin(i);
        if (coin == PLS_ADDRESS) revert UnsupportedNativeCoin();

        // Pull underlying from user
        IERC20(coin).safeTransferFrom(msg.sender, address(this), amountIn);

        // Approve pool (lazy / tight)
        IERC20(coin).forceApprove(address(pool), 0);
        IERC20(coin).forceApprove(address(pool), amountIn);

        // Build amounts array
        uint256[3] memory amounts;
        amounts[i] = amountIn;

        // Snapshot LP before
        uint256 lpBefore = lpToken.balanceOf(address(this));

        // Mint LP to this vault
        pool.add_liquidity(amounts, 0);

        // Compute LP received
        uint256 lpAfter = lpToken.balanceOf(address(this));
        sharesOut = lpAfter - lpBefore;

        if (sharesOut < minSharesOut) revert Slippage();

        // Mint vault shares 1:1 with LP received
        _mint(receiver, sharesOut);

        emit DepositUnderlying(msg.sender, receiver, i, amountIn, sharesOut);
    }

    /**
     * @notice Quote expected shares (LP) from depositing an underlying coin via pool math.
     *         This uses pool.calc_token_amount (rough / simplified, as noted in pool comments).
     */
    function previewDepositUnderlying(uint256 i, uint256 amountIn) external view returns (uint256 sharesOut) {
        if (i > 2) revert InvalidIndex();
        uint256[3] memory amounts;
        amounts[i] = amountIn;
        sharesOut = pool.calc_token_amount(amounts, true);
    }

    /**
     * @notice Redeem vault shares into a single underlying coin (stable) using remove_liquidity_one_coin.
     * @param i Coin index (0..2).
     * @param shares Shares to redeem (== LP amount to burn).
     * @param minAmountOut Minimum coin amount out (slippage protection).
     * @param receiver Receiver of underlying coin.
     * @param owner Owner of the shares (allows redeeming via allowance like ERC-4626 redeem).
     */
    function redeemUnderlying(
        uint256 i,
        uint256 shares,
        uint256 minAmountOut,
        address receiver,
        address owner
    ) external nonReentrant returns (uint256 amountOut) {
        if (shares == 0) revert ZeroAmount();
        if (i > 2) revert InvalidIndex();

        address coin = _coin(i);
        if (coin == PLS_ADDRESS) revert UnsupportedNativeCoin();

        // Spend allowance if needed (mirrors ERC4626.redeem pattern)
        if (msg.sender != owner) {
            _spendAllowance(owner, msg.sender, shares);
        }

        // Burn shares first (so reentrancy can’t manipulate share supply)
        _burn(owner, shares);

        // Snapshot coin before
        uint256 beforeBal = IERC20(coin).balanceOf(address(this));

        // Burn LP (from this vault) and receive coin i to this vault
        pool.remove_liquidity_one_coin(shares, i, minAmountOut);

        // Compute amount out and forward to receiver
        uint256 afterBal = IERC20(coin).balanceOf(address(this));
        amountOut = afterBal - beforeBal;

        // pool already enforced minAmountOut, but keep invariant explicit
        if (amountOut < minAmountOut) revert Slippage();

        IERC20(coin).safeTransfer(receiver, amountOut);

        emit RedeemUnderlying(msg.sender, receiver, owner, i, shares, amountOut);
    }

    /**
     * @notice Quote expected underlying out from redeeming shares via pool math.
     */
    function previewRedeemUnderlying(uint256 i, uint256 shares) external view returns (uint256 amountOut) {
        if (i > 2) revert InvalidIndex();
        amountOut = pool.calc_withdraw_one_coin(shares, i);
    }

    // ------------------------- internals -------------------------

    function _coin(uint256 i) internal view returns (address) {
        if (i == 0) return coin0;
        if (i == 1) return coin1;
        if (i == 2) return coin2;
        revert InvalidIndex();
    }
}
          

contracts/Farm.sol

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

import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract Farm is ReentrancyGuard, Ownable, Pausable {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */
    IERC20 public rewardsToken;
    IERC20 public stakingToken;
    uint256 public periodFinish = 0;
    uint256 public rewardRate = 0;
    uint256 public rewardsDuration = 7 days;
    uint256 public lastUpdateTime;
    uint256 public rewardPerTokenStored;
    
    uint256 public depositFeeBP = 0;
    uint256 public withdrawFeeBP = 0;
    uint256 public constant BPS_DENOMINATOR = 10000;

    mapping(address => uint256) public userRewardPerTokenPaid;
    mapping(address => uint256) public rewards;

    uint256 private _totalSupply;
    mapping(address => uint256) private _balances;

    /* ========== CONSTRUCTOR ========== */

    constructor(
        address _rewardsToken,
        address _stakingToken,
        uint256 _depositFeeBP,
        uint256 _withdrawFeeBP
    ) {
        require(_depositFeeBP <= 900, "Deposit fee too high");
        require(_withdrawFeeBP <= 900, "Withdraw fee too high"); //max 4%
        
        rewardsToken = IERC20(_rewardsToken);
        stakingToken = IERC20(_stakingToken);

        depositFeeBP = _depositFeeBP;
        withdrawFeeBP = _withdrawFeeBP;
    }

    /* ========== VIEWS ========== */

    function totalSupply() external view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) external view returns (uint256) {
        return _balances[account];
    }

    function lastTimeRewardApplicable() public view returns (uint256) {
        return Math.min(block.timestamp, periodFinish);
    }

    function checkPeriodFinish() public view returns (bool) {
        return block.timestamp > periodFinish;
    }

    function rewardPerToken() public view returns (uint256) {
        if (_totalSupply == 0) {
            return rewardPerTokenStored;
        }
        return
            rewardPerTokenStored.add(
                lastTimeRewardApplicable()
                    .sub(lastUpdateTime)
                    .mul(rewardRate)
                    .mul(1e18)
                    .div(_totalSupply)
            );
    }

    function earned(address account) public view returns (uint256) {
        return
            _balances[account]
                .mul(rewardPerToken().sub(userRewardPerTokenPaid[account]))
                .div(1e18)
                .add(rewards[account]);
    }

    function getRewardForDuration() external view returns (uint256) {
        return rewardRate.mul(rewardsDuration);
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function stake(uint256 amount) external nonReentrant whenNotPaused updateReward(msg.sender) {
        require(amount > 0, "Cannot stake 0");
        if (depositFeeBP > 0) {
            uint256 fee = amount.mul(depositFeeBP).div(BPS_DENOMINATOR);
            uint256 amountAfterFee = amount.sub(fee);
            _totalSupply = _totalSupply.add(amountAfterFee);
            _balances[msg.sender] = _balances[msg.sender].add(amountAfterFee);
            stakingToken.safeTransferFrom(msg.sender, address(this), amount);
            stakingToken.safeTransfer(owner(), fee);
            emit Staked(msg.sender, amountAfterFee);
        } else {
            _totalSupply = _totalSupply.add(amount);
            _balances[msg.sender] = _balances[msg.sender].add(amount);
            stakingToken.safeTransferFrom(msg.sender, address(this), amount);
            emit Staked(msg.sender, amount);
        }
    }

    function withdraw(uint256 amount) public nonReentrant updateReward(msg.sender) {
        require(amount > 0, "Cannot withdraw 0");
        if(withdrawFeeBP > 0) {
            uint256 fee = amount.mul(withdrawFeeBP).div(BPS_DENOMINATOR);
            uint256 amountAfterFee = amount.sub(fee);
            _totalSupply = _totalSupply.sub(amount);
            _balances[msg.sender] = _balances[msg.sender].sub(amount);
            stakingToken.safeTransfer(msg.sender, amountAfterFee);
            stakingToken.safeTransfer(owner(), fee);
            emit Withdrawn(msg.sender, amountAfterFee);
        } else {
            _totalSupply = _totalSupply.sub(amount);
            _balances[msg.sender] = _balances[msg.sender].sub(amount);
            stakingToken.safeTransfer(msg.sender, amount);
            emit Withdrawn(msg.sender, amount);
        }
    }

    function getReward() public nonReentrant updateReward(msg.sender) {
        uint256 reward = rewards[msg.sender];
        if (reward > 0) {
            rewards[msg.sender] = 0;
            rewardsToken.safeTransfer(msg.sender, reward);
            emit RewardPaid(msg.sender, reward);
        }
    }

    function exit() external {
        withdraw(_balances[msg.sender]);
        getReward();
    }

    function _freeRewardsBalance() internal view returns (uint256) {
        uint256 bal = rewardsToken.balanceOf(address(this));
        if (address(stakingToken) == address(rewardsToken)) {
            require(bal >= _totalSupply, "Balance < principal");
            return bal - _totalSupply;
        }
        return bal;
    }

    function notifyRewardAmount(uint256 reward) internal updateReward(address(0)) {
        require(block.timestamp >= periodFinish, "Period not finished");

        rewardRate = reward / rewardsDuration;

        uint256 free = _freeRewardsBalance();
        require(rewardRate <= free.div(rewardsDuration), "Provided reward too high");

        lastUpdateTime = block.timestamp;
        periodFinish = block.timestamp + rewardsDuration;
        emit RewardAdded(reward);
    }

    function fundAndNotify(uint256 amount) external onlyOwner {
        require(amount > 0, "amount=0");
        require(block.timestamp >= periodFinish, "Period not finished");
        rewardsToken.safeTransferFrom(msg.sender, address(this), amount);
        notifyRewardAmount(amount);
    }

    /* ========== RESTRICTED FUNCTIONS ========== */

    function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner {
        require(tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken), "Cannot withdraw the staking or rewards tokens");
        IERC20(tokenAddress).safeTransfer(owner(), tokenAmount);
        emit Recovered(tokenAddress, tokenAmount);
    }

    function setRewardsDuration(uint256 _rewardsDuration) external onlyOwner {
        require(block.timestamp > periodFinish,"Previous rewards period must be complete before changing the duration for the new period");
        rewardsDuration = _rewardsDuration;
        emit RewardsDurationUpdated(rewardsDuration);
    }

    /* ========== MODIFIERS ========== */

    modifier updateReward(address account) {
        rewardPerTokenStored = rewardPerToken();
        lastUpdateTime = lastTimeRewardApplicable();
        if (account != address(0)) {
            rewards[account] = earned(account);
            userRewardPerTokenPaid[account] = rewardPerTokenStored;
        }
        _;
    }

    /* ========== EVENTS ========== */

    event RewardAdded(uint256 reward);
    event Staked(address indexed user, uint256 amount);
    event Withdrawn(address indexed user, uint256 amount);
    event RewardPaid(address indexed user, uint256 reward);
    event RewardsDurationUpdated(uint256 newDuration);
    event Recovered(address token, uint256 amount);
}
          

contracts/Strategy.sol

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

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

interface IEMISSIONS {
    function depositOnBehalfOf(uint256 _pid, uint256 _amount, address _referrer, address _staker) external;
    function withdraw(uint256 _pid, uint256 _amount) external;
    function deposit(uint256 _pid, uint256 _amount, address _referrer) external;
    
}

interface IEmitRewards {
    function stake(uint256 amount) external;
    function withdraw(uint256 amount) external;
    function getReward() external;
}

interface Router {
    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
}

contract Strategy is Ownable {
    IEMISSIONS public emissions;
    IEmitRewards public emitRewards;

    uint16 public constant BPS_DENOM = 10_000;

    struct Allocation {
        uint32 pid;      // plenty large; shrink types for cheaper storage
        uint16 bps;      // 0..10000
    }

    Allocation[] public allocations;

    // pid => index+1 (0 means "not present")
    mapping(uint256 => uint256) public pidIndex;

    constructor(address _emissions, address _emitRewards) {
        emissions = IEMISSIONS(_emissions);
        emitRewards = IEmitRewards(_emitRewards);
    }

    // ---- views ----
    function allocationsLength() external view returns (uint256) {
        return allocations.length;
    }

    function totalBps() public view returns (uint256 total) {
        for (uint256 i = 0; i < allocations.length; i++) {
            total += allocations[i].bps;
        }
    }

    // ---- admin ----

    /// @notice Add a new pid with a weight
    function addPool(uint256 pid, uint16 bps) external onlyOwner {
        require(bps > 0, "BPS=0");
        require(pidIndex[pid] == 0, "PID exists");
        allocations.push(Allocation(uint32(pid), bps));
        pidIndex[pid] = allocations.length; // index+1
        require(totalBps() <= BPS_DENOM, "Total > 100%");
    }

    /// @notice Update weight for an existing pid
    function setPoolBps(uint256 pid, uint16 newBps) external onlyOwner {
        require(newBps > 0, "BPS=0");
        uint256 idxPlus = pidIndex[pid];
        require(idxPlus != 0, "PID missing");
        allocations[idxPlus - 1].bps = newBps;
        require(totalBps() <= BPS_DENOM, "Total > 100%");
    }

    /// @notice Remove a pid entirely (swap and pop)
    function removePool(uint256 pid) external onlyOwner {
        uint256 idxPlus = pidIndex[pid];
        require(idxPlus != 0, "PID missing");
        uint256 idx = idxPlus - 1;

        uint256 last = allocations.length - 1;
        if (idx != last) {
            Allocation memory moved = allocations[last];
            allocations[idx] = moved;
            pidIndex[moved.pid] = idx + 1;
        }

        allocations.pop();
        delete pidIndex[pid];
    }

    /// @notice Set the entire allocation set atomically (recommended)
    function setAllocations(uint32[] calldata pids, uint16[] calldata bps) external onlyOwner {
        require(pids.length == bps.length, "Len mismatch");
        require(pids.length > 0, "Empty");

        // clear old
        for (uint256 i = 0; i < allocations.length; i++) {
            delete pidIndex[allocations[i].pid];
        }
        delete allocations;

        uint256 total;
        for (uint256 i = 0; i < pids.length; i++) {
            require(bps[i] > 0, "BPS=0");
            require(pidIndex[pids[i]] == 0, "Dup pid");
            allocations.push(Allocation(pids[i], bps[i]));
            pidIndex[pids[i]] = allocations.length;
            total += bps[i];
        }
        require(total == BPS_DENOM, "Total != 100%");
    }

    // ---- actions ----
    function getReward() external {
        emitRewards.getReward();
    }
}
          

Compiler Settings

{"viaIR":true,"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{},"evmVersion":"paris"}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"FarmCreated","inputs":[{"type":"address","name":"farmAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"FundsCollected","inputs":[{"type":"address","name":"receiver","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addFarm","inputs":[{"type":"address","name":"farmAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"collectFunds","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[],"name":"createFarm","inputs":[{"type":"address","name":"rewardsToken","internalType":"address"},{"type":"address","name":"stakingToken","internalType":"address"},{"type":"uint256","name":"depositFeeBP","internalType":"uint256"},{"type":"uint256","name":"withdrawFeeBP","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"farmCost","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"farmCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"farms","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"feeReceiver","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct FarmFactory.FarmDetails","components":[{"type":"address","name":"farmAddress","internalType":"address"},{"type":"address","name":"rewardsToken","internalType":"address"},{"type":"address","name":"stakingToken","internalType":"address"},{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"periodFinish","internalType":"uint256"},{"type":"uint256","name":"rewardRate","internalType":"uint256"},{"type":"uint256","name":"rewardsDuration","internalType":"uint256"},{"type":"uint256","name":"lastUpdateTime","internalType":"uint256"},{"type":"uint256","name":"rewardPerTokenStored","internalType":"uint256"},{"type":"uint256","name":"totalSupply","internalType":"uint256"},{"type":"uint256","name":"lastTimeRewardApplicable","internalType":"uint256"},{"type":"uint256","name":"rewardPerToken","internalType":"uint256"},{"type":"uint256","name":"rewardForDuration","internalType":"uint256"},{"type":"uint256","name":"rewardsTokenBalance","internalType":"uint256"},{"type":"uint256","name":"stakingTokenBalance","internalType":"uint256"},{"type":"bool","name":"periodFinished","internalType":"bool"},{"type":"bool","name":"paused","internalType":"bool"}]}],"name":"getFarmDetails","inputs":[{"type":"address","name":"farmAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getFarms","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getFarmsPaginated","inputs":[{"type":"uint256","name":"offset","internalType":"uint256"},{"type":"uint256","name":"limit","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isFarm","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"paymentReceiver","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeFarm","inputs":[{"type":"address","name":"farmAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setFarmCost","inputs":[{"type":"uint256","name":"_farmCost","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setFeeReceiver","inputs":[{"type":"address","name":"_feeReceiver","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPaymentReceiver","inputs":[{"type":"address","name":"_paymentReceiver","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]}]
              

Contract Creation Code

0x608080604052346100a65760008054336001600160a01b0319808316821784557332fb5663619a657839a80133994e45c5e5cdf4279390926001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a37332463b4cc953e43c18f46e01859a0f64b20ca78e81600254161760025560035416176003556a0422ca8b0a00a42500000060015561306890816100ac8239f35b600080fdfe61018060405260043610156200001457600080fd5b6000803560e01c806306723ef314620014b75780630a8e214c14620014975780630c64255414620014775780634febcb34146200120f5780635b9806281462001155578063637012c7146200111257806365ebf99a14620010be578063715018a614620010605780637da470ea14620010175780638da5cb5b1462000fee5780639dc4ac8a1462000f57578063aff7b07d1462000e39578063b3f006741462000e0e578063b9f793e11462000de7578063cb37f3b21462000dbc578063efdcd9741462000d68578063f2fde38b1462000c9b578063fb779ea514620002755763fd2daf1e146200010357600080fd5b34620002725760203660031901126200027257620001206200160e565b6200012a62001673565b6001600160a01b0390811680835260066020526040832054620001509060ff1662001821565b808352600660205260408320805460ff19169055825b600454808210156200026b5783836200017f8462001625565b929054600393841b1c1614620001a25750506200019c9062001751565b62000166565b9250929060001993848101908111620002575790620001d883620001ca620001f79462001625565b905490871b1c169162001625565b90919082549060031b9160018060a01b03809116831b921b1916179055565b600454801562000243578301916200020f8362001625565b81939154921b1b19169055600455600590815480156200022f5701905580f35b634e487b7160e01b84526011600452602484fd5b634e487b7160e01b85526031600452602485fd5b634e487b7160e01b86526011600452602486fd5b5050505080f35b80fd5b5034620002725760203660031901126200027257620002936200160e565b6101605280610200604051620002a981620016cc565b8281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e08201528261010082015282610120820152826101408201528261016082015282610180820152826101a0820152826101c0820152826101e0820152015260018060a01b036101605116815260066020526200033560ff60408320541662001821565b60405163d1af0c7d60e01b815261016051602090829060049082906001600160a01b03165afa801562000c6a578260e05262000c75575b506040516372f702f360e01b815261016051602090829060049082906001600160a01b03165afa90811562000c6a57829162000c34575b50604051638da5cb5b60e01b815261016051602090829060049082906001600160a01b03165afa90811562000c2957839162000bdc575b5060405163ebe2b12b60e01b815261016051602090829060049082906001600160a01b03165afa90811562000bd157849162000b99575b50604051633d8523f760e11b815261016051602090829060049082906001600160a01b03165afa90811562000b8e57859162000b56575b5060405163386a952560e01b815261016051602090829060049082906001600160a01b03165afa90811562000b4b57869162000b13575b5060405163c8f33c9160e01b815261016051602090829060049082906001600160a01b03165afa90811562000b0857879162000ad0575b506040519063df136d6560e01b825260208260048160018060a01b0361016051165afa91821562000ac557889262000a8b575b50604051926318160ddd60e01b845260208460048160018060a01b0361016051165afa93841562000a8057899462000a46575b50604051946380faa57d60e01b865260208660048160018060a01b0361016051165afa95861562000a3b578a9662000a01575b506040519663cd3daf9d60e01b885260208860048160018060a01b0361016051165afa978815620009f6578b98620009bc575b5060405198631c1f78eb60e01b8a5260208a60048160018060a01b0361016051165afa998a1562000977578c9a62000982575b5060405160c08181526370a0823160e01b9091526101605181516001600160a01b03918216600490910152905160e0516020926024918391165afa9a8b1562000977578c9b6200093b575b6040516101208181526370a0823160e01b9091526101605181516001600160a01b039182166004909101529051602091602490829085165afa9c8d15620008b857809d620008f8575b604051637d8278a360e01b815261016051602090829060049082906001600160a01b03165afa806101405215620008eb57816101005261014051620008c4575b5060405190635c975abb60e01b825260208260048160018060a01b0361016051165afa908115620008b85760805262000880575b50620006cf6040518060a052620016cc565b60018060a01b03610160511660a0515260018060a01b0360e05116602060a051015260018060a01b0316604060a051015260018060a01b0316606060a0510152608060a051015260a08051015260c060a051015260e060a051015261010060a051015261012060a051015261014060a051015261016060a051015261018060a05101526101a060a05101526101c060a05101526101005115156101e060a0510152608051151561020060a051015261022060405160018060a01b036101605116815260018060a01b03602060a051015116602082015260018060a01b03604060a051015116604082015260018060a01b03606060a0510151166060820152608060a0510151608082015260a08051015160a082015260c060a051015160c082015260e060a051015160e082015261010060a051015161010082015261012060a051015161012082015261014060a051015161014082015261016060a051015161016082015261018060a05101516101808201526101a060a05101516101a08201526101c060a05101516101c08201526101e060a051015115156101e082015261020060a05101511515610200820152f35b620008a69060203d602011620008b0575b6200089d818362001700565b81019062001882565b60805238620006bd565b503d62000891565b604051903d90823e3d90fd5b620008e09060203d602011620008b0576200089d818362001700565b610100523862000689565b50604051903d90823e3d90fd5b9c5060203d60201162000933575b62000915816101205162001700565b6020610120518092810103126200092e57519c62000649565b600080fd5b503d62000906565b9a5060203d6020116200096f575b620009578160c05162001700565b602060c0518092810103126200092e57519a62000600565b503d62000949565b6040513d8e823e3d90fd5b9099506020813d602011620009b3575b81620009a16020938362001700565b810103126200092e57519838620005b5565b3d915062000992565b9097506020813d602011620009ed575b81620009db6020938362001700565b810103126200092e5751963862000582565b3d9150620009cc565b6040513d8d823e3d90fd5b9095506020813d60201162000a32575b8162000a206020938362001700565b810103126200092e575194386200054f565b3d915062000a11565b6040513d8c823e3d90fd5b9093506020813d60201162000a77575b8162000a656020938362001700565b810103126200092e575192386200051c565b3d915062000a56565b6040513d8b823e3d90fd5b9091506020813d60201162000abc575b8162000aaa6020938362001700565b810103126200092e57519038620004e9565b3d915062000a9b565b6040513d8a823e3d90fd5b90506020813d60201162000aff575b8162000aee6020938362001700565b810103126200092e575138620004b6565b3d915062000adf565b6040513d89823e3d90fd5b90506020813d60201162000b42575b8162000b316020938362001700565b810103126200092e5751386200047f565b3d915062000b22565b6040513d88823e3d90fd5b90506020813d60201162000b85575b8162000b746020938362001700565b810103126200092e57513862000448565b3d915062000b65565b6040513d87823e3d90fd5b90506020813d60201162000bc8575b8162000bb76020938362001700565b810103126200092e57513862000411565b3d915062000ba8565b6040513d86823e3d90fd5b90506020813d60201162000c20575b8162000bfa6020938362001700565b8101031262000c1c57516001600160a01b038116810362000c1c5738620003da565b8280fd5b3d915062000beb565b6040513d85823e3d90fd5b62000c5b915060203d60201162000c62575b62000c52818362001700565b81019062001861565b38620003a3565b503d62000c46565b6040513d84823e3d90fd5b62000c919060203d60201162000c625762000c52818362001700565b60e052386200036c565b503462000272576020366003190112620002725762000cb96200160e565b62000cc362001673565b6001600160a01b0390811690811562000d1457600054826001600160601b0360a01b821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b503462000272576020366003190112620002725762000d866200160e565b62000d9062001673565b6001600160a01b031662000da68115156200189c565b6001600160601b0360a01b600354161760035580f35b503462000272578060031936011262000272576002546040516001600160a01b039091168152602090f35b503462000272576020366003190112620002725762000e0562001673565b60043560015580f35b503462000272578060031936011262000272576003546040516001600160a01b039091168152602090f35b503462000272576020366003190112620002725762000e576200160e565b62000e6162001673565b6001600160a01b03811690811562000f1b57818352600660205260ff60408420541662000ee15762000e939062001723565b808252600660205260408220600160ff1982541617905562000eb760055462001751565b6005557f46963f16723a084f2199eb74021bd97647aa6c8960612a9a031ce509d40d4ca78280a280f35b60405162461bcd60e51b815260206004820152601260248201527111985c9b48185b1c9958591e48185919195960721b6044820152606490fd5b60405162461bcd60e51b8152602060048201526014602482015273496e76616c6964206661726d206164647265737360601b6044820152606490fd5b50346200027257806003193601126200027257604051600480548083529083526020808301937f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b92915b82821062000fcd5762000fc98562000fbc8189038262001700565b60405191829182620015c8565b0390f35b83546001600160a01b03168652948501946001938401939091019062000fa1565b50346200027257806003193601126200027257546040516001600160a01b039091168152602090f35b50346200027257602036600319011262000272576004359060045482101562000272576020620010478362001625565b905460405160039290921b1c6001600160a01b03168152f35b503462000272578060031936011262000272576200107d62001673565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5034620002725760203660031901126200027257620010dc6200160e565b620010e662001673565b6001600160a01b0316620010fc8115156200189c565b6001600160601b0360a01b600254161760025580f35b503462000272576020366003190112620002725760209060ff906040906001600160a01b03620011416200160e565b168152600684522054166040519015158152f35b503462000272578060031936011262000272576200117262001673565b478015620011d4577f067e335270006737485da9eba56ed0753a5339fffc5dc1b53ea849447c98db54602060018060a01b03620011c5858080808886600254165af1620011be62001777565b50620017bb565b6002541692604051908152a280f35b60405162461bcd60e51b8152602060048201526013602482015272139bc8199d5b991cc81d1bc818dbdb1b1958dd606a1b6044820152606490fd5b5060803660031901126200027257620012276200160e565b6001600160a01b03602480358281169390849003620013ad57821680156200143b578315620013ff576001543410620013c45760405190611749948583019167ffffffffffffffff9684841088851117620013b15791608093918593620018ea8539825260208201526044356040820152606435606082015203019085f0801562000bd157821692833b15620013ad5760405163f2fde38b60e01b8152336004820152908582848183895af1801562000b4b5762001384575b5050620012ed8362001723565b828452600660205260408420600160ff198254161790556200131160055462001751565b60055560015490600a820291808304600a14901517156200137257508380806200134b94606482950490600354165af1620011be62001777565b7f46963f16723a084f2199eb74021bd97647aa6c8960612a9a031ce509d40d4ca78280a280f35b634e487b7160e01b8552601160045284fd5b81959295116200139a57604052923880620012e0565b634e487b7160e01b825260416004528482fd5b8480fd5b634e487b7160e01b895260416004528589fd5b60405162461bcd60e51b81526020600482015260148184015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015818401527424b73b30b634b21039ba30b5b4b733903a37b5b2b760591b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015818401527424b73b30b634b2103932bbb0b93239903a37b5b2b760591b6044820152606490fd5b503462000272578060031936011262000272576020600154604051908152f35b503462000272578060031936011262000272576020600554604051908152f35b50346200027257604036600319011262000272576004356024918235820190818311620015b557600454808311620015ac575b50620014f78383620017fa565b92620015038462001808565b9362001513604051958662001700565b80855262001524601f199162001808565b01906020913683870137805b84811062001548576040518062000fc98882620015c8565b620015538162001625565b905490620015628484620017fa565b918851831015620015995760039190911b1c6001600160a01b031660059190911b8701840152620015939062001751565b62001530565b634e487b7160e01b875260326004528987fd5b915038620014ea565b634e487b7160e01b815260116004528390fd5b6020908160408183019282815285518094520193019160005b828110620015f0575050505090565b83516001600160a01b031685529381019392810192600101620015e1565b600435906001600160a01b03821682036200092e57565b6004548110156200165d5760046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0190600090565b634e487b7160e01b600052603260045260246000fd5b6000546001600160a01b031633036200168857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b610220810190811067ffffffffffffffff821117620016ea57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117620016ea57604052565b6004549068010000000000000000821015620016ea57620001d88260016200174f940160045562001625565b565b6000198114620017615760010190565b634e487b7160e01b600052601160045260246000fd5b3d15620017b6573d9067ffffffffffffffff8211620016ea5760405191620017aa601f8201601f19166020018462001700565b82523d6000602084013e565b606090565b15620017c357565b60405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606490fd5b919082039182116200176157565b67ffffffffffffffff8111620016ea5760051b60200190565b156200182957565b60405162461bcd60e51b815260206004820152601060248201526f4e6f7420612076616c6964206661726d60801b6044820152606490fd5b908160209103126200092e57516001600160a01b03811681036200092e5790565b908160209103126200092e575180151581036200092e5790565b15620018a457565b60405162461bcd60e51b815260206004820152601860248201527f496e76616c6964207265636569766572206164647265737300000000000000006044820152606490fdfe60803461019257601f6200174938819003918201601f19168301916001600160401b038311848410176101975780849260809460405283398101031261019257610048816101ad565b90610055602082016101ad565b91606060408301519201519260016000556001549060405160018060a01b0392338482167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a36001600160a81b0319163360ff60a01b1916176001556000600481905560055562093a80600655610384908186116101505750851161010b578160018060a01b0319931683600254161760025516906003541617600355600955600a556040516115879081620001c28239f35b60405162461bcd60e51b815260206004820152601560248201527f57697468647261772066656520746f6f206869676800000000000000000000006044820152606490fd5b62461bcd60e51b815260206004820152601460248201527f4465706f7369742066656520746f6f20686967680000000000000000000000006044820152606490fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b03821682036101925756fe60406080815260048036101561001457600080fd5b600091823560e01c80628cc26214610f235780630700037d14610eeb57806318160ddd14610ecc5780631c1f78eb14610ea85780632e1a7d4d14610d3d578063386a952514610d1e5780633d18b91214610c5757806354747a7014610c385780635c975abb14610c1157806370a0823114610bd9578063715018a614610b7957806372f702f314610b505780637b0a47ee14610b315780637d8278a314610b1157806380faa57d14610af45780638980f11f146109e85780638b876347146109b05780638da5cb5b14610987578063a694fc3a146107b9578063aa07547d1461079a578063c8f33c911461077b578063cc1a378f14610695578063cd3daf9d14610671578063d1af0c7d14610648578063df136d6514610629578063e1a4521814610608578063e9fad8ee14610399578063ebe2b12b1461037b578063f2fde38b146102af5763ff3e5d041461016957600080fd5b346102ab5760203660031901126102ab57813591610185610f64565b821561027e57610198815442101561143a565b6002546101b3908490309033906001600160a01b03166111c1565b6101bb610fd1565b6008556101c6610fbc565b6007556101d6815442101561143a565b6006546101e38185611074565b806005556101f8826101f361147c565b611074565b1061023b57917fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d93916102316020944260075542611047565b905551908152a180f35b506020606492519162461bcd60e51b8352820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152fd5b6020606492519162461bcd60e51b835282015260086024820152670616d6f756e743d360c41b6044820152fd5b8280fd5b5090346102ab5760203660031901126102ab576102ca610f49565b906102d3610f64565b6001600160a01b03918216928315610329575050600154826bffffffffffffffffffffffff60a01b821617600155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b5090346102ab57826003193601126102ab5760209250549051908152f35b5090346102ab57826003193601126102ab57338352602090600e8252828420546103c16110f0565b6103c9610fd1565b6008556103d4610fbc565b60075533151591826105e4575b81156105ad5750600a541561053b57610460612710610402600a5484611061565b046104306104108285611054565b9361041d81600d54611054565b600d55338952600e875287892054611054565b338852600e86528688205560018060a01b036104518433836003541661117e565b6003546001548216911661117e565b83519081527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5833392a25b600184556104976110f0565b61049f610fd1565b6008556104aa610fbc565b600755610517575b338352600c81528183209081549284846104ce575b6001815580f35b7fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04869355610506843360018060a01b036002541661117e565b519283523392a238808080846104c7565b61052033611094565b338452600c825282842055600854600b8252828420556104b2565b61054781600d54611054565b600d55338552600e835261055e8185872054611054565b338652600e84528486205561057e813360018060a01b036003541661117e565b83519081527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5833392a261048b565b845162461bcd60e51b81529081018490526011602482015270043616e6e6f74207769746864726177203607c1b6044820152606490fd5b6105ed33611094565b338752600c855285872055600854600b8552858720556103e1565b838234610625578160031936011261062557602090516127108152f35b5080fd5b8382346106255781600319360112610625576020906008549051908152f35b83823461062557816003193601126106255760025490516001600160a01b039091168152602090f35b83823461062557816003193601126106255760209061068e610fd1565b9051908152f35b50346102ab5760203660031901126102ab578135916106b2610f64565b80544211156106ed5750816020917ffb46ca5a5e06d4540d6387b930a7c978bce0db5f449ec6b3f5d07c6e1d44f2d39360065551908152a180f35b602060a492519162461bcd60e51b8352820152605860248201527f50726576696f7573207265776172647320706572696f64206d7573742062652060448201527f636f6d706c657465206265666f7265206368616e67696e67207468652064757260648201527f6174696f6e20666f7220746865206e657720706572696f6400000000000000006084820152fd5b8382346106255781600319360112610625576020906007549051908152f35b838234610625578160031936011261062557602090600a549051908152f35b50346102ab5760209081600319360112610983578235926107d86110f0565b60ff60015460a01c1661094f576107ed610fd1565b6008556107f8610fbc565b6007553361092b575b83156108f957506009547f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d929190156108a75761089961271061084660095487611061565b046108518187611054565b9561085e87600d54611047565b600d55338852600e855261087587858a2054611047565b338952600e86528489205561045160018060a01b03918260035416309033906111c1565b519283523392a26001815580f35b6108b384600d54611047565b600d55338552600e82526108ca8482872054611047565b338652600e8352818620556108ed8460018060a01b0360035416309033906111c1565b519283523392a26104c7565b82606492519162461bcd60e51b8352820152600e60248201526d043616e6e6f74207374616b6520360941b6044820152fd5b61093433611094565b338652600c845282862055600854600b845282862055610801565b82606492519162461bcd60e51b8352820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152fd5b8380fd5b83823461062557816003193601126106255760015490516001600160a01b039091168152602090f35b8382346106255760203660031901126106255760209181906001600160a01b036109d8610f49565b168152600b845220549051908152f35b50919034610625578260031936011261062557610a03610f49565b60243591610a0f610f64565b6003546001600160a01b03838116929091821683141580610ae6575b15610a8d575094610a6784610a87937f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa289798600154169061117e565b516001600160a01b03909216825260208201929092529081906040820190565b0390a180f35b608490602088519162461bcd60e51b8352820152602d60248201527f43616e6e6f7420776974686472617720746865207374616b696e67206f72207260448201526c65776172647320746f6b656e7360981b6064820152fd5b508160025416831415610a2b565b83823461062557816003193601126106255760209061068e610fbc565b5090346102ab57826003193601126102ab57602092505442119051908152f35b8382346106255781600319360112610625576020906005549051908152f35b83823461062557816003193601126106255760035490516001600160a01b039091168152602090f35b8334610bd65780600319360112610bd657610b92610f64565b600180546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b8382346106255760203660031901126106255760209181906001600160a01b03610c01610f49565b168152600e845220549051908152f35b83823461062557816003193601126106255760209060ff60015460a01c1690519015158152f35b8382346106255781600319360112610625576020906009549051908152f35b838234610625578160031936011261062557610c716110f0565b610c79610fd1565b600855610c84610fbc565b60075533610cf8575b338252600c602052808220908282549283610cab575b506001815580f35b55600254610cc590839033906001600160a01b031661117e565b519081527fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e048660203392a281808281610ca3565b610d0133611094565b338352600c60205281832055600854600b60205281832055610c8d565b8382346106255781600319360112610625576020906006549051908152f35b50346102ab576020908160031936011261098357823592610d5c6110f0565b610d64610fd1565b600855610d6f610fbc565b60075533610e84575b8315610e4f5750600a547f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d592919015610e0c57610899612710610dbd600a5487611061565b04610deb610dcb8288611054565b96610dd881600d54611054565b600d55338952600e865284892054611054565b338852600e85528388205560018060a01b036104518733836003541661117e565b610e1884600d54611054565b600d55338552600e8252610e2f8482872054611054565b338652600e8352818620556108ed843360018060a01b036003541661117e565b82606492519162461bcd60e51b83528201526011602482015270043616e6e6f74207769746864726177203607c1b6044820152fd5b610e8d33611094565b338652600c845282862055600854600b845282862055610d78565b83823461062557816003193601126106255760209061068e60055460065490611061565b838234610625578160031936011261062557602090600d549051908152f35b8382346106255760203660031901126106255760209181906001600160a01b03610f13610f49565b168152600c845220549051908152f35b8382346106255760203660031901126106255760209061068e610f44610f49565b611094565b600435906001600160a01b0382168203610f5f57565b600080fd5b6001546001600160a01b03163303610f7857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b600454804210600014610fce57504290565b90565b600d54801561104057600854610ffd610ff4610feb610fbc565b60075490611054565b60055490611061565b670de0b6b3a76400009081810291818304149015171561102a57610fce9261102491611074565b90611047565b634e487b7160e01b600052601160045260246000fd5b5060085490565b9190820180921161102a57565b9190820391821161102a57565b8181029291811591840414171561102a57565b811561107e570490565b634e487b7160e01b600052601260045260246000fd5b610fce9060018060a01b031660406000828152600e602052670de0b6b3a76400006110df838320546110d96110c7610fd1565b878652600b6020528686205490611054565b90611061565b04928152600c602052205490611047565b600260005414611101576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b90601f8019910116810190811067ffffffffffffffff82111761116857604052565b634e487b7160e01b600052604160045260246000fd5b60405163a9059cbb60e01b60208201526001600160a01b039290921660248301526044808301939093529181526111bf916111ba606483611146565b611216565b565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a081019181831067ffffffffffffffff841117611168576111bf926040525b60018060a01b0316906040516040810167ffffffffffffffff9082811082821117611168576040526020938483527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564858401526000808587829751910182855af1903d1561135b573d92831161134757906112b1939291604051926112a488601f19601f8401160185611146565b83523d868885013e611366565b805191821591848315611323575b5050509050156112cc5750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b91938180945001031261062557820151908115158203610bd65750803880846112bf565b634e487b7160e01b85526041600452602485fd5b906112b19392506060915b919290156113c8575081511561137a575090565b3b156113835790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156113db5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b828510611421575050604492506000838284010152601f80199101168101030190fd5b84810182015186860160440152938101938593506113fe565b1561144157565b60405162461bcd60e51b815260206004820152601360248201527214195c9a5bd9081b9bdd08199a5b9a5cda1959606a1b6044820152606490fd5b6002546040516370a0823160e01b8152306004820152906001600160a01b0390811690602083602481855afa92831561154557600093611512575b5060035416146114c45790565b600d548082106114d757610fce91611054565b60405162461bcd60e51b815260206004820152601360248201527210985b185b98d9480f081c1c9a5b98da5c185b606a1b6044820152606490fd5b90926020823d821161153d575b8161152c60209383611146565b81010312610bd657505191386114b7565b3d915061151f565b6040513d6000823e3d90fdfea264697066735822122042159179ee1e5873a19d2b7ec31c7516742bb09558321c8a45ac63ff0402302d64736f6c63430008140033a2646970667358221220abe0f1c28064f6a3e8062d76f584dc5309859b71776c9a5a1a7873cf0a784e1164736f6c63430008140033

Deployed ByteCode

0x61018060405260043610156200001457600080fd5b6000803560e01c806306723ef314620014b75780630a8e214c14620014975780630c64255414620014775780634febcb34146200120f5780635b9806281462001155578063637012c7146200111257806365ebf99a14620010be578063715018a614620010605780637da470ea14620010175780638da5cb5b1462000fee5780639dc4ac8a1462000f57578063aff7b07d1462000e39578063b3f006741462000e0e578063b9f793e11462000de7578063cb37f3b21462000dbc578063efdcd9741462000d68578063f2fde38b1462000c9b578063fb779ea514620002755763fd2daf1e146200010357600080fd5b34620002725760203660031901126200027257620001206200160e565b6200012a62001673565b6001600160a01b0390811680835260066020526040832054620001509060ff1662001821565b808352600660205260408320805460ff19169055825b600454808210156200026b5783836200017f8462001625565b929054600393841b1c1614620001a25750506200019c9062001751565b62000166565b9250929060001993848101908111620002575790620001d883620001ca620001f79462001625565b905490871b1c169162001625565b90919082549060031b9160018060a01b03809116831b921b1916179055565b600454801562000243578301916200020f8362001625565b81939154921b1b19169055600455600590815480156200022f5701905580f35b634e487b7160e01b84526011600452602484fd5b634e487b7160e01b85526031600452602485fd5b634e487b7160e01b86526011600452602486fd5b5050505080f35b80fd5b5034620002725760203660031901126200027257620002936200160e565b6101605280610200604051620002a981620016cc565b8281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e08201528261010082015282610120820152826101408201528261016082015282610180820152826101a0820152826101c0820152826101e0820152015260018060a01b036101605116815260066020526200033560ff60408320541662001821565b60405163d1af0c7d60e01b815261016051602090829060049082906001600160a01b03165afa801562000c6a578260e05262000c75575b506040516372f702f360e01b815261016051602090829060049082906001600160a01b03165afa90811562000c6a57829162000c34575b50604051638da5cb5b60e01b815261016051602090829060049082906001600160a01b03165afa90811562000c2957839162000bdc575b5060405163ebe2b12b60e01b815261016051602090829060049082906001600160a01b03165afa90811562000bd157849162000b99575b50604051633d8523f760e11b815261016051602090829060049082906001600160a01b03165afa90811562000b8e57859162000b56575b5060405163386a952560e01b815261016051602090829060049082906001600160a01b03165afa90811562000b4b57869162000b13575b5060405163c8f33c9160e01b815261016051602090829060049082906001600160a01b03165afa90811562000b0857879162000ad0575b506040519063df136d6560e01b825260208260048160018060a01b0361016051165afa91821562000ac557889262000a8b575b50604051926318160ddd60e01b845260208460048160018060a01b0361016051165afa93841562000a8057899462000a46575b50604051946380faa57d60e01b865260208660048160018060a01b0361016051165afa95861562000a3b578a9662000a01575b506040519663cd3daf9d60e01b885260208860048160018060a01b0361016051165afa978815620009f6578b98620009bc575b5060405198631c1f78eb60e01b8a5260208a60048160018060a01b0361016051165afa998a1562000977578c9a62000982575b5060405160c08181526370a0823160e01b9091526101605181516001600160a01b03918216600490910152905160e0516020926024918391165afa9a8b1562000977578c9b6200093b575b6040516101208181526370a0823160e01b9091526101605181516001600160a01b039182166004909101529051602091602490829085165afa9c8d15620008b857809d620008f8575b604051637d8278a360e01b815261016051602090829060049082906001600160a01b03165afa806101405215620008eb57816101005261014051620008c4575b5060405190635c975abb60e01b825260208260048160018060a01b0361016051165afa908115620008b85760805262000880575b50620006cf6040518060a052620016cc565b60018060a01b03610160511660a0515260018060a01b0360e05116602060a051015260018060a01b0316604060a051015260018060a01b0316606060a0510152608060a051015260a08051015260c060a051015260e060a051015261010060a051015261012060a051015261014060a051015261016060a051015261018060a05101526101a060a05101526101c060a05101526101005115156101e060a0510152608051151561020060a051015261022060405160018060a01b036101605116815260018060a01b03602060a051015116602082015260018060a01b03604060a051015116604082015260018060a01b03606060a0510151166060820152608060a0510151608082015260a08051015160a082015260c060a051015160c082015260e060a051015160e082015261010060a051015161010082015261012060a051015161012082015261014060a051015161014082015261016060a051015161016082015261018060a05101516101808201526101a060a05101516101a08201526101c060a05101516101c08201526101e060a051015115156101e082015261020060a05101511515610200820152f35b620008a69060203d602011620008b0575b6200089d818362001700565b81019062001882565b60805238620006bd565b503d62000891565b604051903d90823e3d90fd5b620008e09060203d602011620008b0576200089d818362001700565b610100523862000689565b50604051903d90823e3d90fd5b9c5060203d60201162000933575b62000915816101205162001700565b6020610120518092810103126200092e57519c62000649565b600080fd5b503d62000906565b9a5060203d6020116200096f575b620009578160c05162001700565b602060c0518092810103126200092e57519a62000600565b503d62000949565b6040513d8e823e3d90fd5b9099506020813d602011620009b3575b81620009a16020938362001700565b810103126200092e57519838620005b5565b3d915062000992565b9097506020813d602011620009ed575b81620009db6020938362001700565b810103126200092e5751963862000582565b3d9150620009cc565b6040513d8d823e3d90fd5b9095506020813d60201162000a32575b8162000a206020938362001700565b810103126200092e575194386200054f565b3d915062000a11565b6040513d8c823e3d90fd5b9093506020813d60201162000a77575b8162000a656020938362001700565b810103126200092e575192386200051c565b3d915062000a56565b6040513d8b823e3d90fd5b9091506020813d60201162000abc575b8162000aaa6020938362001700565b810103126200092e57519038620004e9565b3d915062000a9b565b6040513d8a823e3d90fd5b90506020813d60201162000aff575b8162000aee6020938362001700565b810103126200092e575138620004b6565b3d915062000adf565b6040513d89823e3d90fd5b90506020813d60201162000b42575b8162000b316020938362001700565b810103126200092e5751386200047f565b3d915062000b22565b6040513d88823e3d90fd5b90506020813d60201162000b85575b8162000b746020938362001700565b810103126200092e57513862000448565b3d915062000b65565b6040513d87823e3d90fd5b90506020813d60201162000bc8575b8162000bb76020938362001700565b810103126200092e57513862000411565b3d915062000ba8565b6040513d86823e3d90fd5b90506020813d60201162000c20575b8162000bfa6020938362001700565b8101031262000c1c57516001600160a01b038116810362000c1c5738620003da565b8280fd5b3d915062000beb565b6040513d85823e3d90fd5b62000c5b915060203d60201162000c62575b62000c52818362001700565b81019062001861565b38620003a3565b503d62000c46565b6040513d84823e3d90fd5b62000c919060203d60201162000c625762000c52818362001700565b60e052386200036c565b503462000272576020366003190112620002725762000cb96200160e565b62000cc362001673565b6001600160a01b0390811690811562000d1457600054826001600160601b0360a01b821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b503462000272576020366003190112620002725762000d866200160e565b62000d9062001673565b6001600160a01b031662000da68115156200189c565b6001600160601b0360a01b600354161760035580f35b503462000272578060031936011262000272576002546040516001600160a01b039091168152602090f35b503462000272576020366003190112620002725762000e0562001673565b60043560015580f35b503462000272578060031936011262000272576003546040516001600160a01b039091168152602090f35b503462000272576020366003190112620002725762000e576200160e565b62000e6162001673565b6001600160a01b03811690811562000f1b57818352600660205260ff60408420541662000ee15762000e939062001723565b808252600660205260408220600160ff1982541617905562000eb760055462001751565b6005557f46963f16723a084f2199eb74021bd97647aa6c8960612a9a031ce509d40d4ca78280a280f35b60405162461bcd60e51b815260206004820152601260248201527111985c9b48185b1c9958591e48185919195960721b6044820152606490fd5b60405162461bcd60e51b8152602060048201526014602482015273496e76616c6964206661726d206164647265737360601b6044820152606490fd5b50346200027257806003193601126200027257604051600480548083529083526020808301937f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b92915b82821062000fcd5762000fc98562000fbc8189038262001700565b60405191829182620015c8565b0390f35b83546001600160a01b03168652948501946001938401939091019062000fa1565b50346200027257806003193601126200027257546040516001600160a01b039091168152602090f35b50346200027257602036600319011262000272576004359060045482101562000272576020620010478362001625565b905460405160039290921b1c6001600160a01b03168152f35b503462000272578060031936011262000272576200107d62001673565b600080546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5034620002725760203660031901126200027257620010dc6200160e565b620010e662001673565b6001600160a01b0316620010fc8115156200189c565b6001600160601b0360a01b600254161760025580f35b503462000272576020366003190112620002725760209060ff906040906001600160a01b03620011416200160e565b168152600684522054166040519015158152f35b503462000272578060031936011262000272576200117262001673565b478015620011d4577f067e335270006737485da9eba56ed0753a5339fffc5dc1b53ea849447c98db54602060018060a01b03620011c5858080808886600254165af1620011be62001777565b50620017bb565b6002541692604051908152a280f35b60405162461bcd60e51b8152602060048201526013602482015272139bc8199d5b991cc81d1bc818dbdb1b1958dd606a1b6044820152606490fd5b5060803660031901126200027257620012276200160e565b6001600160a01b03602480358281169390849003620013ad57821680156200143b578315620013ff576001543410620013c45760405190611749948583019167ffffffffffffffff9684841088851117620013b15791608093918593620018ea8539825260208201526044356040820152606435606082015203019085f0801562000bd157821692833b15620013ad5760405163f2fde38b60e01b8152336004820152908582848183895af1801562000b4b5762001384575b5050620012ed8362001723565b828452600660205260408420600160ff198254161790556200131160055462001751565b60055560015490600a820291808304600a14901517156200137257508380806200134b94606482950490600354165af1620011be62001777565b7f46963f16723a084f2199eb74021bd97647aa6c8960612a9a031ce509d40d4ca78280a280f35b634e487b7160e01b8552601160045284fd5b81959295116200139a57604052923880620012e0565b634e487b7160e01b825260416004528482fd5b8480fd5b634e487b7160e01b895260416004528589fd5b60405162461bcd60e51b81526020600482015260148184015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015818401527424b73b30b634b21039ba30b5b4b733903a37b5b2b760591b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015818401527424b73b30b634b2103932bbb0b93239903a37b5b2b760591b6044820152606490fd5b503462000272578060031936011262000272576020600154604051908152f35b503462000272578060031936011262000272576020600554604051908152f35b50346200027257604036600319011262000272576004356024918235820190818311620015b557600454808311620015ac575b50620014f78383620017fa565b92620015038462001808565b9362001513604051958662001700565b80855262001524601f199162001808565b01906020913683870137805b84811062001548576040518062000fc98882620015c8565b620015538162001625565b905490620015628484620017fa565b918851831015620015995760039190911b1c6001600160a01b031660059190911b8701840152620015939062001751565b62001530565b634e487b7160e01b875260326004528987fd5b915038620014ea565b634e487b7160e01b815260116004528390fd5b6020908160408183019282815285518094520193019160005b828110620015f0575050505090565b83516001600160a01b031685529381019392810192600101620015e1565b600435906001600160a01b03821682036200092e57565b6004548110156200165d5760046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0190600090565b634e487b7160e01b600052603260045260246000fd5b6000546001600160a01b031633036200168857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b610220810190811067ffffffffffffffff821117620016ea57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117620016ea57604052565b6004549068010000000000000000821015620016ea57620001d88260016200174f940160045562001625565b565b6000198114620017615760010190565b634e487b7160e01b600052601160045260246000fd5b3d15620017b6573d9067ffffffffffffffff8211620016ea5760405191620017aa601f8201601f19166020018462001700565b82523d6000602084013e565b606090565b15620017c357565b60405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606490fd5b919082039182116200176157565b67ffffffffffffffff8111620016ea5760051b60200190565b156200182957565b60405162461bcd60e51b815260206004820152601060248201526f4e6f7420612076616c6964206661726d60801b6044820152606490fd5b908160209103126200092e57516001600160a01b03811681036200092e5790565b908160209103126200092e575180151581036200092e5790565b15620018a457565b60405162461bcd60e51b815260206004820152601860248201527f496e76616c6964207265636569766572206164647265737300000000000000006044820152606490fdfe60803461019257601f6200174938819003918201601f19168301916001600160401b038311848410176101975780849260809460405283398101031261019257610048816101ad565b90610055602082016101ad565b91606060408301519201519260016000556001549060405160018060a01b0392338482167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a36001600160a81b0319163360ff60a01b1916176001556000600481905560055562093a80600655610384908186116101505750851161010b578160018060a01b0319931683600254161760025516906003541617600355600955600a556040516115879081620001c28239f35b60405162461bcd60e51b815260206004820152601560248201527f57697468647261772066656520746f6f206869676800000000000000000000006044820152606490fd5b62461bcd60e51b815260206004820152601460248201527f4465706f7369742066656520746f6f20686967680000000000000000000000006044820152606490fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b03821682036101925756fe60406080815260048036101561001457600080fd5b600091823560e01c80628cc26214610f235780630700037d14610eeb57806318160ddd14610ecc5780631c1f78eb14610ea85780632e1a7d4d14610d3d578063386a952514610d1e5780633d18b91214610c5757806354747a7014610c385780635c975abb14610c1157806370a0823114610bd9578063715018a614610b7957806372f702f314610b505780637b0a47ee14610b315780637d8278a314610b1157806380faa57d14610af45780638980f11f146109e85780638b876347146109b05780638da5cb5b14610987578063a694fc3a146107b9578063aa07547d1461079a578063c8f33c911461077b578063cc1a378f14610695578063cd3daf9d14610671578063d1af0c7d14610648578063df136d6514610629578063e1a4521814610608578063e9fad8ee14610399578063ebe2b12b1461037b578063f2fde38b146102af5763ff3e5d041461016957600080fd5b346102ab5760203660031901126102ab57813591610185610f64565b821561027e57610198815442101561143a565b6002546101b3908490309033906001600160a01b03166111c1565b6101bb610fd1565b6008556101c6610fbc565b6007556101d6815442101561143a565b6006546101e38185611074565b806005556101f8826101f361147c565b611074565b1061023b57917fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d93916102316020944260075542611047565b905551908152a180f35b506020606492519162461bcd60e51b8352820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152fd5b6020606492519162461bcd60e51b835282015260086024820152670616d6f756e743d360c41b6044820152fd5b8280fd5b5090346102ab5760203660031901126102ab576102ca610f49565b906102d3610f64565b6001600160a01b03918216928315610329575050600154826bffffffffffffffffffffffff60a01b821617600155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b5090346102ab57826003193601126102ab5760209250549051908152f35b5090346102ab57826003193601126102ab57338352602090600e8252828420546103c16110f0565b6103c9610fd1565b6008556103d4610fbc565b60075533151591826105e4575b81156105ad5750600a541561053b57610460612710610402600a5484611061565b046104306104108285611054565b9361041d81600d54611054565b600d55338952600e875287892054611054565b338852600e86528688205560018060a01b036104518433836003541661117e565b6003546001548216911661117e565b83519081527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5833392a25b600184556104976110f0565b61049f610fd1565b6008556104aa610fbc565b600755610517575b338352600c81528183209081549284846104ce575b6001815580f35b7fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04869355610506843360018060a01b036002541661117e565b519283523392a238808080846104c7565b61052033611094565b338452600c825282842055600854600b8252828420556104b2565b61054781600d54611054565b600d55338552600e835261055e8185872054611054565b338652600e84528486205561057e813360018060a01b036003541661117e565b83519081527f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5833392a261048b565b845162461bcd60e51b81529081018490526011602482015270043616e6e6f74207769746864726177203607c1b6044820152606490fd5b6105ed33611094565b338752600c855285872055600854600b8552858720556103e1565b838234610625578160031936011261062557602090516127108152f35b5080fd5b8382346106255781600319360112610625576020906008549051908152f35b83823461062557816003193601126106255760025490516001600160a01b039091168152602090f35b83823461062557816003193601126106255760209061068e610fd1565b9051908152f35b50346102ab5760203660031901126102ab578135916106b2610f64565b80544211156106ed5750816020917ffb46ca5a5e06d4540d6387b930a7c978bce0db5f449ec6b3f5d07c6e1d44f2d39360065551908152a180f35b602060a492519162461bcd60e51b8352820152605860248201527f50726576696f7573207265776172647320706572696f64206d7573742062652060448201527f636f6d706c657465206265666f7265206368616e67696e67207468652064757260648201527f6174696f6e20666f7220746865206e657720706572696f6400000000000000006084820152fd5b8382346106255781600319360112610625576020906007549051908152f35b838234610625578160031936011261062557602090600a549051908152f35b50346102ab5760209081600319360112610983578235926107d86110f0565b60ff60015460a01c1661094f576107ed610fd1565b6008556107f8610fbc565b6007553361092b575b83156108f957506009547f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d929190156108a75761089961271061084660095487611061565b046108518187611054565b9561085e87600d54611047565b600d55338852600e855261087587858a2054611047565b338952600e86528489205561045160018060a01b03918260035416309033906111c1565b519283523392a26001815580f35b6108b384600d54611047565b600d55338552600e82526108ca8482872054611047565b338652600e8352818620556108ed8460018060a01b0360035416309033906111c1565b519283523392a26104c7565b82606492519162461bcd60e51b8352820152600e60248201526d043616e6e6f74207374616b6520360941b6044820152fd5b61093433611094565b338652600c845282862055600854600b845282862055610801565b82606492519162461bcd60e51b8352820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152fd5b8380fd5b83823461062557816003193601126106255760015490516001600160a01b039091168152602090f35b8382346106255760203660031901126106255760209181906001600160a01b036109d8610f49565b168152600b845220549051908152f35b50919034610625578260031936011261062557610a03610f49565b60243591610a0f610f64565b6003546001600160a01b03838116929091821683141580610ae6575b15610a8d575094610a6784610a87937f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa289798600154169061117e565b516001600160a01b03909216825260208201929092529081906040820190565b0390a180f35b608490602088519162461bcd60e51b8352820152602d60248201527f43616e6e6f7420776974686472617720746865207374616b696e67206f72207260448201526c65776172647320746f6b656e7360981b6064820152fd5b508160025416831415610a2b565b83823461062557816003193601126106255760209061068e610fbc565b5090346102ab57826003193601126102ab57602092505442119051908152f35b8382346106255781600319360112610625576020906005549051908152f35b83823461062557816003193601126106255760035490516001600160a01b039091168152602090f35b8334610bd65780600319360112610bd657610b92610f64565b600180546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b8382346106255760203660031901126106255760209181906001600160a01b03610c01610f49565b168152600e845220549051908152f35b83823461062557816003193601126106255760209060ff60015460a01c1690519015158152f35b8382346106255781600319360112610625576020906009549051908152f35b838234610625578160031936011261062557610c716110f0565b610c79610fd1565b600855610c84610fbc565b60075533610cf8575b338252600c602052808220908282549283610cab575b506001815580f35b55600254610cc590839033906001600160a01b031661117e565b519081527fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e048660203392a281808281610ca3565b610d0133611094565b338352600c60205281832055600854600b60205281832055610c8d565b8382346106255781600319360112610625576020906006549051908152f35b50346102ab576020908160031936011261098357823592610d5c6110f0565b610d64610fd1565b600855610d6f610fbc565b60075533610e84575b8315610e4f5750600a547f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d592919015610e0c57610899612710610dbd600a5487611061565b04610deb610dcb8288611054565b96610dd881600d54611054565b600d55338952600e865284892054611054565b338852600e85528388205560018060a01b036104518733836003541661117e565b610e1884600d54611054565b600d55338552600e8252610e2f8482872054611054565b338652600e8352818620556108ed843360018060a01b036003541661117e565b82606492519162461bcd60e51b83528201526011602482015270043616e6e6f74207769746864726177203607c1b6044820152fd5b610e8d33611094565b338652600c845282862055600854600b845282862055610d78565b83823461062557816003193601126106255760209061068e60055460065490611061565b838234610625578160031936011261062557602090600d549051908152f35b8382346106255760203660031901126106255760209181906001600160a01b03610f13610f49565b168152600c845220549051908152f35b8382346106255760203660031901126106255760209061068e610f44610f49565b611094565b600435906001600160a01b0382168203610f5f57565b600080fd5b6001546001600160a01b03163303610f7857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b600454804210600014610fce57504290565b90565b600d54801561104057600854610ffd610ff4610feb610fbc565b60075490611054565b60055490611061565b670de0b6b3a76400009081810291818304149015171561102a57610fce9261102491611074565b90611047565b634e487b7160e01b600052601160045260246000fd5b5060085490565b9190820180921161102a57565b9190820391821161102a57565b8181029291811591840414171561102a57565b811561107e570490565b634e487b7160e01b600052601260045260246000fd5b610fce9060018060a01b031660406000828152600e602052670de0b6b3a76400006110df838320546110d96110c7610fd1565b878652600b6020528686205490611054565b90611061565b04928152600c602052205490611047565b600260005414611101576002600055565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b90601f8019910116810190811067ffffffffffffffff82111761116857604052565b634e487b7160e01b600052604160045260246000fd5b60405163a9059cbb60e01b60208201526001600160a01b039290921660248301526044808301939093529181526111bf916111ba606483611146565b611216565b565b6040516323b872dd60e01b60208201526001600160a01b03928316602482015292909116604483015260648083019390935291815260a081019181831067ffffffffffffffff841117611168576111bf926040525b60018060a01b0316906040516040810167ffffffffffffffff9082811082821117611168576040526020938483527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564858401526000808587829751910182855af1903d1561135b573d92831161134757906112b1939291604051926112a488601f19601f8401160185611146565b83523d868885013e611366565b805191821591848315611323575b5050509050156112cc5750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b91938180945001031261062557820151908115158203610bd65750803880846112bf565b634e487b7160e01b85526041600452602485fd5b906112b19392506060915b919290156113c8575081511561137a575090565b3b156113835790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156113db5750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b828510611421575050604492506000838284010152601f80199101168101030190fd5b84810182015186860160440152938101938593506113fe565b1561144157565b60405162461bcd60e51b815260206004820152601360248201527214195c9a5bd9081b9bdd08199a5b9a5cda1959606a1b6044820152606490fd5b6002546040516370a0823160e01b8152306004820152906001600160a01b0390811690602083602481855afa92831561154557600093611512575b5060035416146114c45790565b600d548082106114d757610fce91611054565b60405162461bcd60e51b815260206004820152601360248201527210985b185b98d9480f081c1c9a5b98da5c185b606a1b6044820152606490fd5b90926020823d821161153d575b8161152c60209383611146565b81010312610bd657505191386114b7565b3d915061151f565b6040513d6000823e3d90fdfea264697066735822122042159179ee1e5873a19d2b7ec31c7516742bb09558321c8a45ac63ff0402302d64736f6c63430008140033a2646970667358221220abe0f1c28064f6a3e8062d76f584dc5309859b71776c9a5a1a7873cf0a784e1164736f6c63430008140033