OP Sepolia Testnet

Contract

0xDe9b3Cde510EB1B654Aeae92aB8b74a71b46F5c8

Overview

ETH Balance

0 ETH

Token Holdings

More Info

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Amount
Renounce Ownersh...112460272024-04-28 8:56:34568 days ago1714294594IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000021400940.0012003
Claim Yield112460232024-04-28 8:56:26568 days ago1714294586IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000029563440.0012003
Migrate112457362024-04-28 8:46:52568 days ago1714294012IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000037114150.0012003
Buy Share112456852024-04-28 8:45:10568 days ago1714293910IN
0xDe9b3Cde...71b46F5c8
0.02 ETH0.0000030198850.0012003
Create Share112456532024-04-28 8:44:06568 days ago1714293846IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000033293190.0012003
Buy Share112455012024-04-28 8:39:02568 days ago1714293542IN
0xDe9b3Cde...71b46F5c8
0.1 ETH0.0000039362940.0012003
Claim Yield112454712024-04-28 8:38:02568 days ago1714293482IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000045948480.0012003
Buy Share112452052024-04-28 8:29:10568 days ago1714292950IN
0xDe9b3Cde...71b46F5c8
0.01 ETH0.0000048907440.0012003
Create Share112451692024-04-28 8:27:58568 days ago1714292878IN
0xDe9b3Cde...71b46F5c8
0 ETH0.000006439070.0012003
Migrate112451102024-04-28 8:26:00568 days ago1714292760IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000084767910.0012003
Transfer Ownersh...112450282024-04-28 8:23:16568 days ago1714292596IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000540708931.50000025
Sell Share112440812024-04-28 7:51:42568 days ago1714290702IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000044986220.0012003
Sell Share112439852024-04-28 7:48:30568 days ago1714290510IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000034940330.0012003
Renounce Ownersh...112436012024-04-28 7:35:42568 days ago1714289742IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000035523790.0012003
Migrate112435972024-04-28 7:35:34568 days ago1714289734IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000038252470.0012003
Buy Share112435622024-04-28 7:34:24568 days ago1714289664IN
0xDe9b3Cde...71b46F5c8
0.02 ETH0.000003540160.0012003
Create Share112435472024-04-28 7:33:54568 days ago1714289634IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000023876480.0012003
Buy Share112435162024-04-28 7:32:52568 days ago1714289572IN
0xDe9b3Cde...71b46F5c8
0.02 ETH0.0000030839940.0012003
Create Share112434852024-04-28 7:31:50568 days ago1714289510IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000025897120.0012003
Buy Share112432582024-04-28 7:24:16568 days ago1714289056IN
0xDe9b3Cde...71b46F5c8
0.02 ETH0.0000047466060.0012003
Buy Share112430202024-04-28 7:16:20568 days ago1714288580IN
0xDe9b3Cde...71b46F5c8
0.001 ETH0.0000057180790.0012003
Buy Share112429982024-04-28 7:15:36568 days ago1714288536IN
0xDe9b3Cde...71b46F5c8
0.001 ETH0.0000057172430.0012003
Create Share112429572024-04-28 7:14:14568 days ago1714288454IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0000045406940.0012003
Migrate112385542024-04-28 4:47:28568 days ago1714279648IN
0xDe9b3Cde...71b46F5c8
0 ETH0.0002637078883.00000025

Latest 25 internal transactions (View All)

Parent Transaction Hash Block From To Amount
112457362024-04-28 8:46:52568 days ago1714294012
0xDe9b3Cde...71b46F5c8
0.045004282261799 ETH
112456852024-04-28 8:45:10568 days ago1714293910
0xDe9b3Cde...71b46F5c8
0.005000045555555 ETH
112456852024-04-28 8:45:10568 days ago1714293910
0xDe9b3Cde...71b46F5c8
0.005000045555555 ETH
112456852024-04-28 8:45:10568 days ago1714293910
0xDe9b3Cde...71b46F5c8
0.014749952166666 ETH
112456852024-04-28 8:45:10568 days ago1714293910
0xDe9b3Cde...71b46F5c8
0.000250002277777 ETH
112455012024-04-28 8:39:02568 days ago1714293542
0xDe9b3Cde...71b46F5c8
0.025004099999999 ETH
112455012024-04-28 8:39:02568 days ago1714293542
0xDe9b3Cde...71b46F5c8
0.025004099999999 ETH
112455012024-04-28 8:39:02568 days ago1714293542
0xDe9b3Cde...71b46F5c8
0.073745695 ETH
112455012024-04-28 8:39:02568 days ago1714293542
0xDe9b3Cde...71b46F5c8
0.001250204999999 ETH
112452052024-04-28 8:29:10568 days ago1714292950
0xDe9b3Cde...71b46F5c8
0.005000045555555 ETH
112452052024-04-28 8:29:10568 days ago1714292950
0xDe9b3Cde...71b46F5c8
0.005000045555555 ETH
112452052024-04-28 8:29:10568 days ago1714292950
0xDe9b3Cde...71b46F5c8
0.004749952166666 ETH
112452052024-04-28 8:29:10568 days ago1714292950
0xDe9b3Cde...71b46F5c8
0.000250002277777 ETH
112451102024-04-28 8:26:00568 days ago1714292760
0xDe9b3Cde...71b46F5c8
0.010000091150688 ETH
112451102024-04-28 8:26:00568 days ago1714292760
0xDe9b3Cde...71b46F5c8
0.010000091150688 ETH
112451102024-04-28 8:26:00568 days ago1714292760
0xDe9b3Cde...71b46F5c8
0.010000091150688 ETH
112440812024-04-28 7:51:42568 days ago1714290702
0xDe9b3Cde...71b46F5c8
0.000250009111111 ETH
112440812024-04-28 7:51:42568 days ago1714290702
0xDe9b3Cde...71b46F5c8
0.000250009111111 ETH
112440812024-04-28 7:51:42568 days ago1714290702
0xDe9b3Cde...71b46F5c8
0.004500163999999 ETH
112440812024-04-28 7:51:42568 days ago1714290702
0xDe9b3Cde...71b46F5c8
0.005000182222222 ETH
112435622024-04-28 7:34:24568 days ago1714289664
0xDe9b3Cde...71b46F5c8
0.005000045555555 ETH
112435622024-04-28 7:34:24568 days ago1714289664
0xDe9b3Cde...71b46F5c8
0.014499949888888 ETH
112435622024-04-28 7:34:24568 days ago1714289664
0xDe9b3Cde...71b46F5c8
0.000250002277777 ETH
112435622024-04-28 7:34:24568 days ago1714289664
0xDe9b3Cde...71b46F5c8
0.000250002277777 ETH
112432582024-04-28 7:24:16568 days ago1714289056
0xDe9b3Cde...71b46F5c8
0.010000227777777 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
MestSharesFactoryV1

Compiler Version
v0.8.16+commit.07a7930e

Optimization Enabled:
Yes with 200 runs

Other Settings:
london EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

/*

    Copyright 2024 MEST.
    SPDX-License-Identifier: MIT

*/

pragma solidity 0.8.16;

import "@openzeppelin/contracts/access/Ownable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IMestShare } from "../intf/IMestShare.sol";
import { IYieldAggregator } from "contracts/intf/IYieldAggregator.sol";
import { BondingCurveLib } from "../lib/BondingCurveLib.sol";

contract MestSharesFactoryV1 is Ownable {
    using SafeERC20 for IERC20;

    address public immutable mestERC1155;
    uint256 public shareIndex; 

    uint256 public referralFeePercent = 5 * 1e16;
    uint256 public creatorFeePercent = 5 * 1e16;
    CurveFixedParam public generalCurveFixedParam;

    mapping(uint256 => address) public sharesMap;
    mapping(address => uint256[]) public creatorSharesMap; 

    uint256 public depositedETHAmount; 
    IYieldAggregator public yieldAggregator;

    struct CurveFixedParam {
        uint256 basePrice;
        uint256 linearPriceSlope;
        uint256 inflectionPoint;
        uint256 inflectionPrice;
    }

    event Create(uint256 indexed shareId, address indexed creator);
    event Trade(
        address indexed user,
        uint256 indexed share,
        bool isBuy,
        uint256 quantity,
        uint256 totalPrice,
        uint256 referralFee,
        uint256 creatorFee,
        uint256 newSupply
    );
    event ClaimYield(uint256 amount, address indexed to);

    constructor(
        address _mestERC1155, 
        uint256 _basePrice, 
        uint256 _inflectionPoint, 
        uint256 _inflectionPrice,
        uint256 _linearPriceSlope
    ) {
        mestERC1155 = _mestERC1155;

        generalCurveFixedParam.basePrice = _basePrice; //5000000000000000;
        generalCurveFixedParam.inflectionPoint = _inflectionPoint; //1500;
        generalCurveFixedParam.inflectionPrice = _inflectionPrice; //102500000000000000;
        generalCurveFixedParam.linearPriceSlope = _linearPriceSlope; //0;
    }

    fallback() external payable {}

    receive() external payable {}

    function setReferralFeePercent(uint256 _feePercent) external onlyOwner {
        referralFeePercent = _feePercent;
    }

    function setCreatorFeePercent(uint256 _feePercent) external onlyOwner {
        creatorFeePercent = _feePercent;
    }

    /**
     * @notice this function used for 3 cases for setting yieldAggregator
     * case 1 address(0) -> yieldAggregator
     * case 2 yieldAggregator -> blank yieldAggregator, which won't do yield farming
     * case 3 yieldAggregator -> new yieldAggregator
     * @param _yieldAggregator yield tool address    
     */
    function migrate(address _yieldAggregator) external onlyOwner {
        require(_yieldAggregator != address(0), "Invalid yieldAggregator");
        if(address(yieldAggregator) == address(0)) {
            _setYieldAggregator(_yieldAggregator);
        } else {
            // withdraw all yieldtoken
            _withdrawAllYieldTokenToETH();

            // revoke old yieldAggregator approve
            address yieldToken = yieldAggregator.yieldToken();
            IERC20(yieldToken).safeApprove(address(yieldAggregator), 0);
            
            // change yieldAggregator
            _setYieldAggregator(_yieldAggregator);

            // deposit all ETH
            _depositAllETHToYieldToken();
        }
    }

    /**
     * @notice only for owner to get certain amount yield
     * @param amount owner claim amount
     * @param to yield receiver address
     */
    function claimYield(uint256 amount, address to) public onlyOwner {
        uint256 maxAmount = yieldAggregator.yieldMaxClaimable(depositedETHAmount);
        require(amount <= maxAmount, "Invalid yield amount");
        yieldAggregator.yieldWithdraw(amount);
        _safeTransferETH(to, amount);

        emit ClaimYield(amount, to);
    }

    // =============== internal for migrate ===================

    function _setYieldAggregator(address _yieldAggregator) internal {
        // set yieldAggregator
        yieldAggregator = IYieldAggregator(_yieldAggregator);

        // yield token approve for yieldAggregator
        address yieldToken = yieldAggregator.yieldToken();
        IERC20(yieldToken).safeApprove(_yieldAggregator, type(uint256).max);
    }

    function _withdrawAllYieldTokenToETH() internal {
        uint256 withdrawableETHAmount = yieldAggregator.yieldBalanceOf(address(this));
        yieldAggregator.yieldWithdraw(withdrawableETHAmount);
    }

    function _depositAllETHToYieldToken() internal {
        uint256 ethAmount = address(this).balance;
        _safeTransferETH(address(yieldAggregator), ethAmount);
        yieldAggregator.yieldDeposit();
    }

    // ==================== public =======================

    /**
     * @notice Calculates buy price and fees.
     * @return buyPriceAfterFee Amount user pay after fees.
     * @return buyPrice Price of shares before fees.
     * @return referralFee Fee by the protocol. If = address(0), there is no referral fee.
     * @return creatorFee Fee by the share's creator.
    */
    function getBuyPriceAfterFee(uint256 shareId, uint256 quantity, address referral)
        public
        view
        returns (uint256 buyPriceAfterFee, uint256 buyPrice, uint256 referralFee, uint256 creatorFee)
    {
        uint256 fromSupply = IMestShare(mestERC1155).shareFromSupply(shareId);
        uint256 actualReferralFeePercent = referral != address(0) ? referralFeePercent : 0;

        buyPrice = _subTotal(fromSupply, quantity);
        referralFee = buyPrice * actualReferralFeePercent / 1 ether;
        creatorFee = buyPrice * creatorFeePercent / 1 ether;
        buyPriceAfterFee = buyPrice + referralFee + creatorFee;
    }

    /**
     * @notice Calculates sell price and fees.
     * @return sellPriceAfterFee Amount user receives after fees.
     * @return sellPrice Price of shares before fees.
     * @return referralFee Fee by the protocol. If = address(0), there is no referral fee.
     * @return creatorFee Fee by the share's creator.
     */
    function getSellPriceAfterFee(uint256 shareId, uint256 quantity, address referral)
        public
        view
        returns (uint256 sellPriceAfterFee, uint256 sellPrice, uint256 referralFee, uint256 creatorFee)
    {
        uint256 fromSupply = IMestShare(mestERC1155).shareFromSupply(shareId);
        uint256 actualReferralFeePercent = referral != address(0) ? referralFeePercent : 0;
        require(fromSupply >= quantity, "Exceeds supply");

        sellPrice = _subTotal(fromSupply - quantity, quantity);
        referralFee = sellPrice * actualReferralFeePercent / 1 ether;
        creatorFee = sellPrice * creatorFeePercent / 1 ether;
        sellPriceAfterFee = sellPrice - referralFee - creatorFee;
    }

    /**
     * @dev Returns the area under the bonding curve, which is the price before any fees.
     * @param fromSupply The starting share supply.
     * @param quantity The number of shares to be minted.
     * @return subTotal The area under the bonding curve.
     */
    function _subTotal(uint256 fromSupply, uint256 quantity) internal view returns (uint256 subTotal) {
        unchecked {
            subTotal = generalCurveFixedParam.basePrice * quantity;
            subTotal += BondingCurveLib.linearSum(generalCurveFixedParam.linearPriceSlope, fromSupply, quantity);
            subTotal += BondingCurveLib.sigmoid2Sum(
                generalCurveFixedParam.inflectionPoint, generalCurveFixedParam.inflectionPrice, fromSupply, quantity
            );
        }
    }

    /**
     * @notice Create share with incremented id
     * @param creator Set the creator's address, which will be used as a fee address
     * @dev Share id is same as ERC1155 id
     */
    function createShare(address creator) public {
        sharesMap[shareIndex] = creator;
        creatorSharesMap[creator].push(shareIndex);

        emit Create(shareIndex, creator);

        shareIndex++;
    }

    /** 
     * @param shareId the id of share 
     * @param quantity the quantity of share
     * @param referral referral fee receiver
     * @dev in this case, slippage protection use msg.value insufficient
     */
    function buyShare(uint256 shareId, uint256 quantity, address referral) public payable {
        require(address(yieldAggregator) != address(0), "Invalid yieldAggregator");
        require(shareId < shareIndex, "Invalid shareId");
        address creator = sharesMap[shareId];
        uint256 fromSupply = IMestShare(mestERC1155).shareFromSupply(shareId);
        
        // Anti-frontrunining, first buyer must be creator
        require(fromSupply > 0 || msg.sender == creator, "First buyer must be creator");

        (uint256 buyPriceAfterFee, uint256 buyPrice, uint256 referralFee, uint256 creatorFee) = getBuyPriceAfterFee(shareId, quantity, referral);
        require(msg.value >= buyPriceAfterFee, "Insufficient payment");
        IMestShare(mestERC1155).shareMint(msg.sender, shareId, quantity);
        emit Trade(
            msg.sender, shareId, true, quantity, buyPriceAfterFee, referralFee, creatorFee, fromSupply + quantity
        );

        // pay fee
        _safeTransferETH(referral, referralFee);
        _safeTransferETH(creator, creatorFee);

        // refund if paid more than necessary
        uint256 refundAmount = msg.value - buyPriceAfterFee;
        if (refundAmount > 0) {
            _safeTransferETH(msg.sender, refundAmount);
        }

        // deposit to yield aggregator, e.g. Aave
        _safeTransferETH(address(yieldAggregator), buyPrice);
        yieldAggregator.yieldDeposit();
        depositedETHAmount += buyPrice;
    }

    /**
     * @param shareId the id of share
     * @param quantity the quantity of share
     * @param minETHAmount minimum amount of ETH that a user receives, used for slippage protection. If the amount is less than this ETH value, it will revert.
     * @param referral referral fee receiver
     */
    function sellShare(uint256 shareId, uint256 quantity, uint256 minETHAmount, address referral) public payable {
        require(shareId < shareIndex, "Invalid shareId");
        require(IMestShare(mestERC1155).shareBalanceOf(msg.sender, shareId) >= quantity, "Insufficient shares");
        address creator = sharesMap[shareId];

        (uint256 sellPriceAfterFee, uint256 sellPrice, uint256 referralFee, uint256 creatorFee) = getSellPriceAfterFee(shareId, quantity, referral);
        require(sellPriceAfterFee >= minETHAmount, "Insufficient minReceive");
        IMestShare(mestERC1155).shareBurn(msg.sender, shareId, quantity);
        uint256 fromSupply = IMestShare(mestERC1155).shareFromSupply(shareId);
        emit Trade(msg.sender, shareId, false, quantity, sellPriceAfterFee, referralFee, creatorFee, fromSupply);

        // withdraw from yield aggregator, e.g. Aave
        yieldAggregator.yieldWithdraw(sellPrice);
        depositedETHAmount -= sellPrice;

        // unstake ETH to user
        _safeTransferETH(msg.sender, sellPriceAfterFee);

        // pay fee
        _safeTransferETH(referral, referralFee);
        _safeTransferETH(creator, creatorFee);
    }

    /** 
     * @notice Transfers ETH to the recipient address
     * @param to The destination of the transfer
     * @param value The value to be transferred
     * @dev Fails with `Eth transfer failed`
     */ 
    function _safeTransferETH(address to, uint256 value) internal {
        if (value > 0) {
            (bool success,) = to.call{value: value}(new bytes(0));
            require(success, "Eth transfer failed");
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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);
    }
}

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

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

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

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

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

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

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

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

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

/*

    Copyright 2024 MEST.
    SPDX-License-Identifier: Apache-2.0

*/

pragma solidity 0.8.16;

interface IMestShare {
    function shareMint(address to, uint256 id, uint256 amount) external;
    function shareBurn(address from, uint256 id, uint256 amount) external;
    function shareFromSupply(uint256 id) external view returns(uint256);
    function shareBalanceOf(address user, uint256 id) external view returns(uint256);
}

/*

    Copyright 2024 MEST.
    SPDX-License-Identifier: MIT

*/

pragma solidity 0.8.16;

interface IYieldAggregator {
    function yieldDeposit() external;
    function yieldWithdraw(uint256 amount) external;
    function yieldBalanceOf(address owner) external view returns(uint256 withdrawableETHAmount);
    function yieldToken() external view returns(address);
    function yieldMaxClaimable(uint256 depositedETHAmount) external view returns(uint256 maxClaimableETH);
}

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

import "./FixedPointMathLib.sol";

library BondingCurveLib {
    function sigmoid2Sum(
        uint256 inflectionPoint,
        uint256 inflectionPrice,
        uint256 fromSupply,
        uint256 quantity
    ) internal pure returns (uint256 sum) {
        // We don't need checked arithmetic for the sum.
        // The max possible sum for the quadratic region is capped at:
        // `n * (n + 1) * (2*n + 1) * h < 2**32 * 2**33 * 2**34 * 2**128 = 2**227`.
        // The max possible sum for the sqrt region is capped at:
        // `end * (2*h * sqrt(end)) < 2**32 * 2**129 * 2**16 = 2**177`.
        // The overall sum is capped by:
        // `2**161 + 2**227 <= 2**228 < 2 **256`.
        // The result will be small enough for unchecked multiplication with a 16-bit BPS.
        unchecked {
            uint256 g = inflectionPoint;
            uint256 h = inflectionPrice;

            // Early return to save gas if either `g` or `h` is zero.
            if (g * h == 0) return 0;

            uint256 s = uint256(fromSupply) + 1;
            uint256 end = s + uint256(quantity);
            uint256 quadraticEnd = FixedPointMathLib.min(g, end);

            if (s < quadraticEnd) {
                uint256 k = uint256(fromSupply); // `s - 1`.
                uint256 n = quadraticEnd - 1;
                // In practice, `h` (units: wei) will be set to be much greater than `g * g`.
                uint256 a = FixedPointMathLib.rawDiv(h, g * g);
                // Use the closed form to compute the sum.
                // sum(i ^2)/ g^2 considered as infinitesimal and use taylor series
                sum = ((n * (n + 1) * ((n << 1) + 1) - k * (k + 1) * ((k << 1) + 1)) / 6) * a;
                s = quadraticEnd;
            }

            if (s < end) {
                uint256 c = (3 * g) >> 2;
                uint256 h2 = h << 1;
                do {
                    uint256 r = FixedPointMathLib.sqrt((s - c) * g);
                    sum += FixedPointMathLib.rawDiv(h2 * r, g);
                } while (++s != end);
            }
        }
    }

    function linearSum(
        uint256 linearPriceSlope,
        uint256 fromSupply,
        uint256 quantity
    ) internal pure returns (uint256 sum) {
        // We don't need checked arithmetic for the sum because the max possible
        // intermediate value is capped at:
        // `k * m < 2**32 * 2**128 = 2**160 < 2**256`.
        // As `quantity` is 32 bits, max possible value for `sum`
        // is capped at:
        // `2**32 * 2**160 = 2**192 < 2**256`.
        // The result will be small enough for unchecked multiplication with a 16-bit BPS.
        unchecked {
            uint256 m = linearPriceSlope;
            uint256 k = uint256(fromSupply);
            uint256 n = k + uint256(quantity);
            // Use the closed form to compute the sum.
            return m * ((n * (n + 1) - k * (k + 1)) >> 1);
        }
    }
}

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

pragma solidity ^0.8.0;

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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);
            }
        }
    }
}

File 11 of 11 : FixedPointMathLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The operation failed, as the output exceeds the maximum value of uint256.
    error ExpOverflow();

    /// @dev The operation failed, as the output exceeds the maximum value of uint256.
    error FactorialOverflow();

    /// @dev The operation failed, due to an multiplication overflow.
    error MulWadFailed();

    /// @dev The operation failed, either due to a
    /// multiplication overflow, or a division by a zero.
    error DivWadFailed();

    /// @dev The multiply-divide operation failed, either due to a
    /// multiplication overflow, or a division by a zero.
    error MulDivFailed();

    /// @dev The division failed, as the denominator is zero.
    error DivFailed();

    /// @dev The full precision multiply-divide operation failed, either due
    /// to the result being larger than 256 bits, or a division by a zero.
    error FullMulDivFailed();

    /// @dev The output is undefined, as the input is less-than-or-equal to zero.
    error LnWadUndefined();

    /// @dev The output is undefined, as the input is zero.
    error Log2Undefined();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The scalar of ETH and most ERC20s.
    uint256 internal constant WAD = 1e18;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*              SIMPLIFIED FIXED POINT OPERATIONS             */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Equivalent to `(x * y) / WAD` rounded down.
    function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
            if mul(y, gt(x, div(not(0), y))) {
                // Store the function selector of `MulWadFailed()`.
                mstore(0x00, 0xbac65e5b)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(mul(x, y), WAD)
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded up.
    function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
            if mul(y, gt(x, div(not(0), y))) {
                // Store the function selector of `MulWadFailed()`.
                mstore(0x00, 0xbac65e5b)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded down.
    function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
            if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                // Store the function selector of `DivWadFailed()`.
                mstore(0x00, 0x7c5f487d)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(mul(x, WAD), y)
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded up.
    function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
            if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
                // Store the function selector of `DivWadFailed()`.
                mstore(0x00, 0x7c5f487d)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
        }
    }

    /// @dev Equivalent to `x` to the power of `y`.
    /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
    function powWad(int256 x, int256 y) internal pure returns (int256) {
        // Using `ln(x)` means `x` must be greater than 0.
        return expWad((lnWad(x) * y) / int256(WAD));
    }

    /// @dev Returns `exp(x)`, denominated in `WAD`.
    function expWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            // When the result is < 0.5 we return zero. This happens when
            // x <= floor(log(0.5e18) * 1e18) ~ -42e18
            if (x <= -42139678854452767551) return r;

            /// @solidity memory-safe-assembly
            assembly {
                // When the result is > (2**255 - 1) / 1e18 we can not represent it as an
                // int. This happens when x >= floor(log((2**255 - 1) / 1e18) * 1e18) ~ 135.
                if iszero(slt(x, 135305999368893231589)) {
                    // Store the function selector of `ExpOverflow()`.
                    mstore(0x00, 0xa37bfec9)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }
            }

            // x is now in the range (-42, 136) * 1e18. Convert to (-42, 136) * 2**96
            // for more intermediate precision and a binary basis. This base conversion
            // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
            x = (x << 78) / 5 ** 18;

            // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
            // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
            // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
            int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
            x = x - k * 54916777467707473351141471128;

            // k is in the range [-61, 195].

            // Evaluate using a (6, 7)-term rational approximation.
            // p is made monic, we'll multiply by a scale factor later.
            int256 y = x + 1346386616545796478920950773328;
            y = ((y * x) >> 96) + 57155421227552351082224309758442;
            int256 p = y + x - 94201549194550492254356042504812;
            p = ((p * y) >> 96) + 28719021644029726153956944680412240;
            p = p * x + (4385272521454847904659076985693276 << 96);

            // We leave p in 2**192 basis so we don't need to scale it back up for the division.
            int256 q = x - 2855989394907223263936484059900;
            q = ((q * x) >> 96) + 50020603652535783019961831881945;
            q = ((q * x) >> 96) - 533845033583426703283633433725380;
            q = ((q * x) >> 96) + 3604857256930695427073651918091429;
            q = ((q * x) >> 96) - 14423608567350463180887372962807573;
            q = ((q * x) >> 96) + 26449188498355588339934803723976023;

            /// @solidity memory-safe-assembly
            assembly {
                // Div in assembly because solidity adds a zero check despite the unchecked.
                // The q polynomial won't have zeros in the domain as all its roots are complex.
                // No scaling is necessary because p is already 2**96 too large.
                r := sdiv(p, q)
            }

            // r should be in the range (0.09, 0.25) * 2**96.

            // We now need to multiply r by:
            // * the scale factor s = ~6.031367120.
            // * the 2**k factor from the range reduction.
            // * the 1e18 / 2**96 factor for base conversion.
            // We do this all at once, with an intermediate result in 2**213
            // basis, so the final right shift is always by a positive amount.
            r = int256(
                (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
            );
        }
    }

    /// @dev Returns `ln(x)`, denominated in `WAD`.
    function lnWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            /// @solidity memory-safe-assembly
            assembly {
                if iszero(sgt(x, 0)) {
                    // Store the function selector of `LnWadUndefined()`.
                    mstore(0x00, 0x1615e638)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }
            }

            // We want to convert x from 10**18 fixed point to 2**96 fixed point.
            // We do this by multiplying by 2**96 / 10**18. But since
            // ln(x * C) = ln(x) + ln(C), we can simply do nothing here
            // and add ln(2**96 / 10**18) at the end.

            // Compute k = log2(x) - 96.
            int256 k;
            /// @solidity memory-safe-assembly
            assembly {
                let v := x
                k := shl(7, lt(0xffffffffffffffffffffffffffffffff, v))
                k := or(k, shl(6, lt(0xffffffffffffffff, shr(k, v))))
                k := or(k, shl(5, lt(0xffffffff, shr(k, v))))

                // For the remaining 32 bits, use a De Bruijn lookup.
                // See: https://graphics.stanford.edu/~seander/bithacks.html
                v := shr(k, v)
                v := or(v, shr(1, v))
                v := or(v, shr(2, v))
                v := or(v, shr(4, v))
                v := or(v, shr(8, v))
                v := or(v, shr(16, v))

                // forgefmt: disable-next-item
                k := sub(or(k, byte(shr(251, mul(v, shl(224, 0x07c4acdd))),
                    0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f)), 96)
            }

            // Reduce range of x to (1, 2) * 2**96
            // ln(2^k * x) = k * ln(2) + ln(x)
            x <<= uint256(159 - k);
            x = int256(uint256(x) >> 159);

            // Evaluate using a (8, 8)-term rational approximation.
            // p is made monic, we will multiply by a scale factor later.
            int256 p = x + 3273285459638523848632254066296;
            p = ((p * x) >> 96) + 24828157081833163892658089445524;
            p = ((p * x) >> 96) + 43456485725739037958740375743393;
            p = ((p * x) >> 96) - 11111509109440967052023855526967;
            p = ((p * x) >> 96) - 45023709667254063763336534515857;
            p = ((p * x) >> 96) - 14706773417378608786704636184526;
            p = p * x - (795164235651350426258249787498 << 96);

            // We leave p in 2**192 basis so we don't need to scale it back up for the division.
            // q is monic by convention.
            int256 q = x + 5573035233440673466300451813936;
            q = ((q * x) >> 96) + 71694874799317883764090561454958;
            q = ((q * x) >> 96) + 283447036172924575727196451306956;
            q = ((q * x) >> 96) + 401686690394027663651624208769553;
            q = ((q * x) >> 96) + 204048457590392012362485061816622;
            q = ((q * x) >> 96) + 31853899698501571402653359427138;
            q = ((q * x) >> 96) + 909429971244387300277376558375;
            /// @solidity memory-safe-assembly
            assembly {
                // Div in assembly because solidity adds a zero check despite the unchecked.
                // The q polynomial is known not to have zeros in the domain.
                // No scaling required because p is already 2**96 too large.
                r := sdiv(p, q)
            }

            // r is in the range (0, 0.125) * 2**96

            // Finalization, we need to:
            // * multiply by the scale factor s = 5.549…
            // * add ln(2**96 / 10**18)
            // * add k * ln(2)
            // * multiply by 10**18 / 2**96 = 5**18 >> 78

            // mul s * 5e18 * 2**96, base is now 5**18 * 2**192
            r *= 1677202110996718588342820967067443963516166;
            // add ln(2) * k * 5e18 * 2**192
            r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;
            // add ln(2**96 / 10**18) * 5e18 * 2**192
            r += 600920179829731861736702779321621459595472258049074101567377883020018308;
            // base conversion: mul 2**18 / 2**192
            r >>= 174;
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  GENERAL NUMBER UTILITIES                  */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Calculates `floor(a * b / d)` with full precision.
    /// Throws if result overflows a uint256 or when `d` is zero.
    /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
    function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            // forgefmt: disable-next-item
            for {} 1 {} {
                // 512-bit multiply `[prod1 prod0] = x * y`.
                // Compute the product mod `2**256` and mod `2**256 - 1`
                // then 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`.

                // Least significant 256 bits of the product.
                let prod0 := mul(x, y)
                let mm := mulmod(x, y, not(0))
                // Most significant 256 bits of the product.
                let prod1 := sub(mm, add(prod0, lt(mm, prod0)))

                // Handle non-overflow cases, 256 by 256 division.
                if iszero(prod1) {
                    if iszero(d) {
                        // Store the function selector of `FullMulDivFailed()`.
                        mstore(0x00, 0xae47f702)
                        // Revert with (offset, size).
                        revert(0x1c, 0x04)
                    }
                    result := div(prod0, d)
                    break       
                }

                // Make sure the result is less than `2**256`.
                // Also prevents `d == 0`.
                if iszero(gt(d, prod1)) {
                    // Store the function selector of `FullMulDivFailed()`.
                    mstore(0x00, 0xae47f702)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }

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

                // Make division exact by subtracting the remainder from `[prod1 prod0]`.
                // Compute remainder using mulmod.
                let remainder := mulmod(x, y, d)
                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
                // Factor powers of two out of `d`.
                // Compute largest power of two divisor of `d`.
                // Always greater or equal to 1.
                let twos := and(d, sub(0, d))
                // Divide d by power of two.
                d := div(d, twos)
                // Divide [prod1 prod0] by the factors of two.
                prod0 := div(prod0, twos)
                // Shift in bits from `prod1` into `prod0`. For this we need
                // to flip `twos` such that it is `2**256 / twos`.
                // If `twos` is zero, then it becomes one.
                prod0 := or(prod0, mul(prod1, add(div(sub(0, twos), twos), 1)))
                // Invert `d mod 2**256`
                // Now that `d` is an odd number, it has an inverse
                // modulo `2**256` such that `d * inv = 1 mod 2**256`.
                // Compute the inverse by starting with a seed that is correct
                // correct for four bits. That is, `d * inv = 1 mod 2**4`.
                let inv := xor(mul(3, d), 2)
                // Now use 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.
                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
                inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
                result := mul(prod0, mul(inv, sub(2, mul(d, inv)))) // inverse mod 2**256
                break
            }
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
    /// Throws if result overflows a uint256 or when `d` is zero.
    /// Credit to Uniswap-v3-core under MIT license:
    /// https://github.com/Uniswap/v3-core/blob/contracts/libraries/FullMath.sol
    function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
        result = fullMulDiv(x, y, d);
        /// @solidity memory-safe-assembly
        assembly {
            if mulmod(x, y, d) {
                if iszero(add(result, 1)) {
                    // Store the function selector of `FullMulDivFailed()`.
                    mstore(0x00, 0xae47f702)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }
                result := add(result, 1)
            }
        }
    }

    /// @dev Returns `floor(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                // Store the function selector of `MulDivFailed()`.
                mstore(0x00, 0xad251c27)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(mul(x, y), d)
        }
    }

    /// @dev Returns `ceil(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                // Store the function selector of `MulDivFailed()`.
                mstore(0x00, 0xad251c27)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
        }
    }

    /// @dev Returns `ceil(x / d)`.
    /// Reverts if `d` is zero.
    function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(d) {
                // Store the function selector of `DivFailed()`.
                mstore(0x00, 0x65244e4e)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(x, d))), div(x, d))
        }
    }

    /// @dev Returns `max(0, x - y)`.
    function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(gt(x, y), sub(x, y))
        }
    }

    /// @dev Returns the square root of `x`.
    function sqrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
            z := 181 // The "correct" value is 1, but this saves a multiplication later.

            // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
            // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.

            // Let `y = x / 2**r`.
            // We check `y >= 2**(k + 8)` but shift right by `k` bits
            // each branch to ensure that if `x >= 256`, then `y >= 256`.
            let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffffff, shr(r, x))))
            z := shl(shr(1, r), z)

            // Goal was to get `z*z*y` within a small factor of `x`. More iterations could
            // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
            // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
            // That's not possible if `x < 256` but we can just verify those cases exhaustively.

            // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
            // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
            // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.

            // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
            // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
            // with largest error when `s = 1` and when `s = 256` or `1/256`.

            // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
            // Then we can estimate `sqrt(y)` using
            // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.

            // There is no overflow risk here since `y < 2**136` after the first branch above.
            z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.

            // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))

            // If `x+1` is a perfect square, the Babylonian method cycles between
            // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
            // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
            // Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
            // If you don't care whether the floor or ceil square root is returned, you can remove this statement.
            z := sub(z, lt(div(x, z), z))
        }
    }

    /// @dev Returns the cube root of `x`.
    /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
    /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
    function cbrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))

            z := shl(add(div(r, 3), lt(0xf, shr(r, x))), 0xff)
            z := div(z, byte(mod(r, 3), shl(232, 0x7f624b)))

            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)

            z := sub(z, lt(div(x, mul(z, z)), z))
        }
    }

    /// @dev Returns the factorial of `x`.
    function factorial(uint256 x) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            for {} 1 {} {
                if iszero(lt(10, x)) {
                    // forgefmt: disable-next-item
                    result := and(
                        shr(mul(22, x), 0x375f0016260009d80004ec0002d00001e0000180000180000200000400001),
                        0x3fffff
                    )
                    break
                }
                if iszero(lt(57, x)) {
                    let end := 31
                    result := 8222838654177922817725562880000000
                    if iszero(lt(end, x)) {
                        end := 10
                        result := 3628800
                    }
                    for { let w := not(0) } 1 {} {
                        result := mul(result, x)
                        x := add(x, w)
                        if eq(x, end) { break }
                    }
                    break
                }
                // Store the function selector of `FactorialOverflow()`.
                mstore(0x00, 0xaba0f2a2)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns the log2 of `x`.
    /// Equivalent to computing the index of the most significant bit (MSB) of `x`.
    function log2(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(x) {
                // Store the function selector of `Log2Undefined()`.
                mstore(0x00, 0x5be3aa5c)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))

            // For the remaining 32 bits, use a De Bruijn lookup.
            // See: https://graphics.stanford.edu/~seander/bithacks.html
            x := shr(r, x)
            x := or(x, shr(1, x))
            x := or(x, shr(2, x))
            x := or(x, shr(4, x))
            x := or(x, shr(8, x))
            x := or(x, shr(16, x))

            // forgefmt: disable-next-item
            r := or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))),
                0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f))
        }
    }

    /// @dev Returns the log2 of `x`, rounded up.
    function log2Up(uint256 x) internal pure returns (uint256 r) {
        unchecked {
            uint256 isNotPo2;
            assembly {
                isNotPo2 := iszero(iszero(and(x, sub(x, 1))))
            }
            return log2(x) + isNotPo2;
        }
    }

    /// @dev Returns the average of `x` and `y`.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = (x & y) + ((x ^ y) >> 1);
        }
    }

    /// @dev Returns the average of `x` and `y`.
    function avg(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = (x >> 1) + (y >> 1) + (((x & 1) + (y & 1)) >> 1);
        }
    }

    /// @dev Returns the absolute value of `x`.
    function abs(int256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let mask := sub(0, shr(255, x))
            z := xor(mask, add(mask, x))
        }
    }

    /// @dev Returns the absolute distance between `x` and `y`.
    function dist(int256 x, int256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let a := sub(y, x)
            z := xor(a, mul(xor(a, sub(x, y)), sgt(x, y)))
        }
    }

    /// @dev Returns the minimum of `x` and `y`.
    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), lt(y, x)))
        }
    }

    /// @dev Returns the minimum of `x` and `y`.
    function min(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), slt(y, x)))
        }
    }

    /// @dev Returns the maximum of `x` and `y`.
    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), gt(y, x)))
        }
    }

    /// @dev Returns the maximum of `x` and `y`.
    function max(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), sgt(y, x)))
        }
    }

    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
    function clamp(uint256 x, uint256 minValue, uint256 maxValue)
        internal
        pure
        returns (uint256 z)
    {
        z = min(max(x, minValue), maxValue);
    }

    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
    function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
        z = min(max(x, minValue), maxValue);
    }

    /// @dev Returns greatest common divisor of `x` and `y`.
    function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // forgefmt: disable-next-item
            for { z := x } y {} {
                let t := y
                y := mod(z, y)
                z := t
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   RAW NUMBER OPERATIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := div(x, y)
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := sdiv(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mod(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := smod(x, y)
        }
    }

    /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
    function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := addmod(x, y, d)
        }
    }

    /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
    function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mulmod(x, y, d)
        }
    }
}

Settings
{
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "contracts/=contracts/",
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "@rari-capital/solmate/src/=node_modules/@rari-capital/solmate/src/",
    "@ensdomains/=node_modules/@ensdomains/",
    "eth-gas-reporter/=node_modules/eth-gas-reporter/",
    "hardhat/=node_modules/hardhat/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_mestERC1155","type":"address"},{"internalType":"uint256","name":"_basePrice","type":"uint256"},{"internalType":"uint256","name":"_inflectionPoint","type":"uint256"},{"internalType":"uint256","name":"_inflectionPrice","type":"uint256"},{"internalType":"uint256","name":"_linearPriceSlope","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"ClaimYield","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"shareId","type":"uint256"},{"indexed":true,"internalType":"address","name":"creator","type":"address"}],"name":"Create","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"share","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBuy","type":"bool"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"referralFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"creatorFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newSupply","type":"uint256"}],"name":"Trade","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"uint256","name":"shareId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"referral","type":"address"}],"name":"buyShare","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"claimYield","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creator","type":"address"}],"name":"createShare","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"creatorFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"creatorSharesMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"depositedETHAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"generalCurveFixedParam","outputs":[{"internalType":"uint256","name":"basePrice","type":"uint256"},{"internalType":"uint256","name":"linearPriceSlope","type":"uint256"},{"internalType":"uint256","name":"inflectionPoint","type":"uint256"},{"internalType":"uint256","name":"inflectionPrice","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"referral","type":"address"}],"name":"getBuyPriceAfterFee","outputs":[{"internalType":"uint256","name":"buyPriceAfterFee","type":"uint256"},{"internalType":"uint256","name":"buyPrice","type":"uint256"},{"internalType":"uint256","name":"referralFee","type":"uint256"},{"internalType":"uint256","name":"creatorFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"referral","type":"address"}],"name":"getSellPriceAfterFee","outputs":[{"internalType":"uint256","name":"sellPriceAfterFee","type":"uint256"},{"internalType":"uint256","name":"sellPrice","type":"uint256"},{"internalType":"uint256","name":"referralFee","type":"uint256"},{"internalType":"uint256","name":"creatorFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mestERC1155","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_yieldAggregator","type":"address"}],"name":"migrate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referralFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"uint256","name":"minETHAmount","type":"uint256"},{"internalType":"address","name":"referral","type":"address"}],"name":"sellShare","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feePercent","type":"uint256"}],"name":"setCreatorFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feePercent","type":"uint256"}],"name":"setReferralFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shareIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"sharesMap","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"yieldAggregator","outputs":[{"internalType":"contract IYieldAggregator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a060405266b1a2bc2ec5000060025566b1a2bc2ec5000060035534801561002657600080fd5b5060405162001dd338038062001dd3833981016040819052610047916100c2565b61005033610072565b6001600160a01b03909416608052600492909255600655600755600555610117565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600080600060a086880312156100da57600080fd5b85516001600160a01b03811681146100f157600080fd5b602087015160408801516060890151608090990151929a91995097965090945092505050565b608051611c6f62000164600039600081816103b2015281816104c001528181610613015281816107bc01528181610b5e01528181610e1c01528181610f750152610ff10152611c6f6000f3fe6080604052600436106101225760003560e01c80636ff6c4b8116100a5578063c56ad1ad1161006c578063c56ad1ad14610337578063ce5494bb1461034d578063cfe147f41461036d578063d2cd5d731461038d578063e5476888146103a0578063f2fde38b146103d457005b80636ff6c4b81461028e578063715018a6146102ae5780637c88ab84146102c35780638da5cb5b146102e3578063a57d4fd21461030157005b80632a194b6d116100e95780632a194b6d146101e05780634cd14dc61461021857806353613dd314610238578063614524e21461024e57806361fa18d51461026e57005b80630e8b4d611461012b57806313c9440b1461017357806314cea158146101975780631f43b7ce146101aa5780631fdb5f53146101ca57005b3661012957005b005b34801561013757600080fd5b5060045460055460065460075461014e9392919084565b6040805194855260208501939093529183015260608201526080015b60405180910390f35b34801561017f57600080fd5b5061018960025481565b60405190815260200161016a565b6101296101a53660046119c6565b6103f4565b3480156101b657600080fd5b5061014e6101c53660046119c6565b6107b2565b3480156101d657600080fd5b50610189600a5481565b3480156101ec57600080fd5b50600b54610200906001600160a01b031681565b6040516001600160a01b03909116815260200161016a565b34801561022457600080fd5b506101296102333660046119ff565b610922565b34801561024457600080fd5b5061018960035481565b34801561025a57600080fd5b50610129610269366004611a2f565b610a95565b34801561027a57600080fd5b50610129610289366004611a48565b610aa2565b34801561029a57600080fd5b506101296102a9366004611a2f565b610b33565b3480156102ba57600080fd5b50610129610b40565b3480156102cf57600080fd5b5061014e6102de3660046119c6565b610b54565b3480156102ef57600080fd5b506000546001600160a01b0316610200565b34801561030d57600080fd5b5061020061031c366004611a2f565b6008602052600090815260409020546001600160a01b031681565b34801561034357600080fd5b5061018960015481565b34801561035957600080fd5b50610129610368366004611a48565b610c6d565b34801561037957600080fd5b50610189610388366004611a65565b610d8a565b61012961039b366004611a91565b610dbb565b3480156103ac57600080fd5b506102007f000000000000000000000000000000000000000000000000000000000000000081565b3480156103e057600080fd5b506101296103ef366004611a48565b611163565b600b546001600160a01b031661044b5760405162461bcd60e51b815260206004820152601760248201527624b73b30b634b2103cb4b2b63220b3b3b932b3b0ba37b960491b60448201526064015b60405180910390fd5b600154831061048e5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081cda185c995259608a1b6044820152606401610442565b60008381526008602052604080822054905163d2cf911560e01b8152600481018690526001600160a01b0391821692917f0000000000000000000000000000000000000000000000000000000000000000169063d2cf911590602401602060405180830381865afa158015610507573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052b9190611ad2565b905060008111806105445750336001600160a01b038316145b6105905760405162461bcd60e51b815260206004820152601b60248201527f4669727374206275796572206d7573742062652063726561746f7200000000006044820152606401610442565b6000806000806105a1898989610b54565b9350935093509350833410156105f05760405162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b6044820152606401610442565b60405163106fcedf60e21b8152336004820152602481018a9052604481018990527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906341bf3b7c90606401600060405180830381600087803b15801561065f57600080fd5b505af1158015610673573d6000803e3d6000fd5b508b92503391507f29db2a6062b25ead33a5fc8d1163c4d7f54397202547c27c1c99a20344647734905060018b8887876106ad848e611b01565b6040805196151587526020870195909552938501929092526060840152608083015260a082015260c00160405180910390a36106e987836111d9565b6106f386826111d9565b60006106ff8534611b1a565b905080156107115761071133826111d9565b600b54610727906001600160a01b0316856111d9565b600b60009054906101000a90046001600160a01b03166001600160a01b031663bb282e5c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561077757600080fd5b505af115801561078b573d6000803e3d6000fd5b5050505083600a60008282546107a19190611b01565b909155505050505050505050505050565b60008060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d2cf9115896040518263ffffffff1660e01b815260040161080891815260200190565b602060405180830381865afa158015610825573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108499190611ad2565b905060006001600160a01b038716610862576000610866565b6002545b9050878210156108a95760405162461bcd60e51b815260206004820152600e60248201526d4578636565647320737570706c7960901b6044820152606401610442565b6108bc6108b68984611b1a565b89611297565b9450670de0b6b3a76400006108d18287611b2d565b6108db9190611b4c565b9350670de0b6b3a7640000600354866108f49190611b2d565b6108fe9190611b4c565b92508261090b8587611b1a565b6109159190611b1a565b9550505093509350935093565b61092a6112c9565b600b54600a546040516328e762dd60e01b815260048101919091526000916001600160a01b0316906328e762dd90602401602060405180830381865afa158015610978573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099c9190611ad2565b9050808311156109e55760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081e5a595b1908185b5bdd5b9d60621b6044820152606401610442565b600b546040516316d7ac4560e31b8152600481018590526001600160a01b039091169063b6bd622890602401600060405180830381600087803b158015610a2b57600080fd5b505af1158015610a3f573d6000803e3d6000fd5b50505050610a4d82846111d9565b816001600160a01b03167fc82fd9ebea57700479e05121ad619652619f27f7d29858cdae6682fda41fe55284604051610a8891815260200190565b60405180910390a2505050565b610a9d6112c9565b600255565b60018054600090815260086020908152604080832080546001600160a01b0319166001600160a01b038716908117909155808452600983528184208554815480880183559186529385200192909255925492519092917f748fd6a01f0f0df2e8354235caf8fdf83654b5a47b2358be7e7bffb16b726ceb91a360018054906000610b2b83611b6e565b919050555050565b610b3b6112c9565b600355565b610b486112c9565b610b526000611323565b565b60008060008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d2cf9115896040518263ffffffff1660e01b8152600401610baa91815260200190565b602060405180830381865afa158015610bc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610beb9190611ad2565b905060006001600160a01b038716610c04576000610c08565b6002545b9050610c148289611297565b9450670de0b6b3a7640000610c298287611b2d565b610c339190611b4c565b9350670de0b6b3a764000060035486610c4c9190611b2d565b610c569190611b4c565b925082610c638587611b01565b6109159190611b01565b610c756112c9565b6001600160a01b038116610cc55760405162461bcd60e51b815260206004820152601760248201527624b73b30b634b2103cb4b2b63220b3b3b932b3b0ba37b960491b6044820152606401610442565b600b546001600160a01b0316610ce157610cde81611373565b50565b610ce961140b565b600b54604080516376d5de8560e01b815290516000926001600160a01b0316916376d5de859160048083019260209291908290030181865afa158015610d33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d579190611b87565b600b54909150610d75906001600160a01b03808416911660006114da565b610d7e82611373565b610d86611611565b5050565b60096020528160005260406000208181548110610da657600080fd5b90600052602060002001600091509150505481565b6001548410610dfe5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081cda185c995259608a1b6044820152606401610442565b6040516327e662e160e21b81523360048201526024810185905283907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690639f998b8490604401602060405180830381865afa158015610e6b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8f9190611ad2565b1015610ed35760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742073686172657360681b6044820152606401610442565b6000848152600860205260408120546001600160a01b031690808080610efa8989886107b2565b935093509350935086841015610f525760405162461bcd60e51b815260206004820152601760248201527f496e73756666696369656e74206d696e526563656976650000000000000000006044820152606401610442565b6040516317a99ced60e31b8152336004820152602481018a9052604481018990527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063bd4ce76890606401600060405180830381600087803b158015610fc157600080fd5b505af1158015610fd5573d6000803e3d6000fd5b505060405163d2cf911560e01b8152600481018c9052600092507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316915063d2cf911590602401602060405180830381865afa158015611041573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110659190611ad2565b6040805160008152602081018c9052908101879052606081018590526080810184905260a081018290529091508a9033907f29db2a6062b25ead33a5fc8d1163c4d7f54397202547c27c1c99a203446477349060c00160405180910390a3600b546040516316d7ac4560e31b8152600481018690526001600160a01b039091169063b6bd622890602401600060405180830381600087803b15801561110957600080fd5b505af115801561111d573d6000803e3d6000fd5b5050505083600a60008282546111339190611b1a565b90915550611143905033866111d9565b61114d87846111d9565b61115786836111d9565b50505050505050505050565b61116b6112c9565b6001600160a01b0381166111d05760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610442565b610cde81611323565b8015610d8657604080516000808252602082019092526001600160a01b0384169083906040516112099190611bc8565b60006040518083038185875af1925050503d8060008114611246576040519150601f19603f3d011682016040523d82523d6000602084013e61124b565b606091505b50509050806112925760405162461bcd60e51b8152602060048201526013602482015272115d1a081d1c985b9cd9995c8819985a5b1959606a1b6044820152606401610442565b505050565b600454600554908202906112ac908484611679565b60065460075491909201916112c2918585611694565b0192915050565b6000546001600160a01b03163314610b525760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610442565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600b80546001600160a01b0319166001600160a01b038316908117909155604080516376d5de8560e01b81529051600092916376d5de859160048083019260209291908290030181865afa1580156113cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f39190611b87565b9050610d866001600160a01b038216836000196114da565b600b54604051638812ebc960e01b81523060048201526000916001600160a01b031690638812ebc990602401602060405180830381865afa158015611454573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114789190611ad2565b600b546040516316d7ac4560e31b8152600481018390529192506001600160a01b03169063b6bd622890602401600060405180830381600087803b1580156114bf57600080fd5b505af11580156114d3573d6000803e3d6000fd5b5050505050565b8015806115545750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561152e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115529190611ad2565b155b6115bf5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610442565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526112929084906117cb565b600b544790611629906001600160a01b0316826111d9565b600b60009054906101000a90046001600160a01b03166001600160a01b031663bb282e5c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156114bf57600080fd5b600180830183028284018281010203901c83025b9392505050565b6000848480820283036116ac576000925050506117c3565b60018581019085870101838118818511028418808310156116f65760066001808a018a028a821b820102600019840180850290831b90920191909102030485800285040295509150815b818310156117bd576003850260021c600185901b5b60006117a1888488030270ffffffffffffffffffffffffffffffffff811160071b81811c68ffffffffffffffffff1060061b1781811c64ffffffffff1060051b1781811c62ffffff1060041b1781811c620100000160b5600192831c1b0260121c80830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c908190048111900390565b82028890049890980197506001808601958590030161170b5750505b50505050505b949350505050565b6000611820826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661189d9092919063ffffffff16565b805190915015611292578080602001905181019061183e9190611be4565b6112925760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610442565b60606117c38484600085856001600160a01b0385163b6118ff5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610442565b600080866001600160a01b0316858760405161191b9190611bc8565b60006040518083038185875af1925050503d8060008114611958576040519150601f19603f3d011682016040523d82523d6000602084013e61195d565b606091505b509150915061196d828286611978565b979650505050505050565b6060831561198757508161168d565b8251156119975782518084602001fd5b8160405162461bcd60e51b81526004016104429190611c06565b6001600160a01b0381168114610cde57600080fd5b6000806000606084860312156119db57600080fd5b833592506020840135915060408401356119f4816119b1565b809150509250925092565b60008060408385031215611a1257600080fd5b823591506020830135611a24816119b1565b809150509250929050565b600060208284031215611a4157600080fd5b5035919050565b600060208284031215611a5a57600080fd5b813561168d816119b1565b60008060408385031215611a7857600080fd5b8235611a83816119b1565b946020939093013593505050565b60008060008060808587031215611aa757600080fd5b8435935060208501359250604085013591506060850135611ac7816119b1565b939692955090935050565b600060208284031215611ae457600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115611b1457611b14611aeb565b92915050565b81810381811115611b1457611b14611aeb565b6000816000190483118215151615611b4757611b47611aeb565b500290565b600082611b6957634e487b7160e01b600052601260045260246000fd5b500490565b600060018201611b8057611b80611aeb565b5060010190565b600060208284031215611b9957600080fd5b815161168d816119b1565b60005b83811015611bbf578181015183820152602001611ba7565b50506000910152565b60008251611bda818460208701611ba4565b9190910192915050565b600060208284031215611bf657600080fd5b8151801515811461168d57600080fd5b6020815260008251806020840152611c25816040850160208701611ba4565b601f01601f1916919091016040019291505056fea2646970667358221220e124d6218d8e6912daad0a47e0220371870699af9cddd32b11c4306ccdedd90564736f6c6343000810003300000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac0000000000000000000000000000000000000000000000000011c37937e0800000000000000000000000000000000000000000000000000000000000000005dc000000000000000000000000000000000000000000000000016c2734f97a40000000000000000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x6080604052600436106101225760003560e01c80636ff6c4b8116100a5578063c56ad1ad1161006c578063c56ad1ad14610337578063ce5494bb1461034d578063cfe147f41461036d578063d2cd5d731461038d578063e5476888146103a0578063f2fde38b146103d457005b80636ff6c4b81461028e578063715018a6146102ae5780637c88ab84146102c35780638da5cb5b146102e3578063a57d4fd21461030157005b80632a194b6d116100e95780632a194b6d146101e05780634cd14dc61461021857806353613dd314610238578063614524e21461024e57806361fa18d51461026e57005b80630e8b4d611461012b57806313c9440b1461017357806314cea158146101975780631f43b7ce146101aa5780631fdb5f53146101ca57005b3661012957005b005b34801561013757600080fd5b5060045460055460065460075461014e9392919084565b6040805194855260208501939093529183015260608201526080015b60405180910390f35b34801561017f57600080fd5b5061018960025481565b60405190815260200161016a565b6101296101a53660046119c6565b6103f4565b3480156101b657600080fd5b5061014e6101c53660046119c6565b6107b2565b3480156101d657600080fd5b50610189600a5481565b3480156101ec57600080fd5b50600b54610200906001600160a01b031681565b6040516001600160a01b03909116815260200161016a565b34801561022457600080fd5b506101296102333660046119ff565b610922565b34801561024457600080fd5b5061018960035481565b34801561025a57600080fd5b50610129610269366004611a2f565b610a95565b34801561027a57600080fd5b50610129610289366004611a48565b610aa2565b34801561029a57600080fd5b506101296102a9366004611a2f565b610b33565b3480156102ba57600080fd5b50610129610b40565b3480156102cf57600080fd5b5061014e6102de3660046119c6565b610b54565b3480156102ef57600080fd5b506000546001600160a01b0316610200565b34801561030d57600080fd5b5061020061031c366004611a2f565b6008602052600090815260409020546001600160a01b031681565b34801561034357600080fd5b5061018960015481565b34801561035957600080fd5b50610129610368366004611a48565b610c6d565b34801561037957600080fd5b50610189610388366004611a65565b610d8a565b61012961039b366004611a91565b610dbb565b3480156103ac57600080fd5b506102007f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac81565b3480156103e057600080fd5b506101296103ef366004611a48565b611163565b600b546001600160a01b031661044b5760405162461bcd60e51b815260206004820152601760248201527624b73b30b634b2103cb4b2b63220b3b3b932b3b0ba37b960491b60448201526064015b60405180910390fd5b600154831061048e5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081cda185c995259608a1b6044820152606401610442565b60008381526008602052604080822054905163d2cf911560e01b8152600481018690526001600160a01b0391821692917f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac169063d2cf911590602401602060405180830381865afa158015610507573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052b9190611ad2565b905060008111806105445750336001600160a01b038316145b6105905760405162461bcd60e51b815260206004820152601b60248201527f4669727374206275796572206d7573742062652063726561746f7200000000006044820152606401610442565b6000806000806105a1898989610b54565b9350935093509350833410156105f05760405162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b6044820152606401610442565b60405163106fcedf60e21b8152336004820152602481018a9052604481018990527f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b0316906341bf3b7c90606401600060405180830381600087803b15801561065f57600080fd5b505af1158015610673573d6000803e3d6000fd5b508b92503391507f29db2a6062b25ead33a5fc8d1163c4d7f54397202547c27c1c99a20344647734905060018b8887876106ad848e611b01565b6040805196151587526020870195909552938501929092526060840152608083015260a082015260c00160405180910390a36106e987836111d9565b6106f386826111d9565b60006106ff8534611b1a565b905080156107115761071133826111d9565b600b54610727906001600160a01b0316856111d9565b600b60009054906101000a90046001600160a01b03166001600160a01b031663bb282e5c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561077757600080fd5b505af115801561078b573d6000803e3d6000fd5b5050505083600a60008282546107a19190611b01565b909155505050505050505050505050565b60008060008060007f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b031663d2cf9115896040518263ffffffff1660e01b815260040161080891815260200190565b602060405180830381865afa158015610825573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108499190611ad2565b905060006001600160a01b038716610862576000610866565b6002545b9050878210156108a95760405162461bcd60e51b815260206004820152600e60248201526d4578636565647320737570706c7960901b6044820152606401610442565b6108bc6108b68984611b1a565b89611297565b9450670de0b6b3a76400006108d18287611b2d565b6108db9190611b4c565b9350670de0b6b3a7640000600354866108f49190611b2d565b6108fe9190611b4c565b92508261090b8587611b1a565b6109159190611b1a565b9550505093509350935093565b61092a6112c9565b600b54600a546040516328e762dd60e01b815260048101919091526000916001600160a01b0316906328e762dd90602401602060405180830381865afa158015610978573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099c9190611ad2565b9050808311156109e55760405162461bcd60e51b8152602060048201526014602482015273125b9d985b1a59081e5a595b1908185b5bdd5b9d60621b6044820152606401610442565b600b546040516316d7ac4560e31b8152600481018590526001600160a01b039091169063b6bd622890602401600060405180830381600087803b158015610a2b57600080fd5b505af1158015610a3f573d6000803e3d6000fd5b50505050610a4d82846111d9565b816001600160a01b03167fc82fd9ebea57700479e05121ad619652619f27f7d29858cdae6682fda41fe55284604051610a8891815260200190565b60405180910390a2505050565b610a9d6112c9565b600255565b60018054600090815260086020908152604080832080546001600160a01b0319166001600160a01b038716908117909155808452600983528184208554815480880183559186529385200192909255925492519092917f748fd6a01f0f0df2e8354235caf8fdf83654b5a47b2358be7e7bffb16b726ceb91a360018054906000610b2b83611b6e565b919050555050565b610b3b6112c9565b600355565b610b486112c9565b610b526000611323565b565b60008060008060007f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b031663d2cf9115896040518263ffffffff1660e01b8152600401610baa91815260200190565b602060405180830381865afa158015610bc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610beb9190611ad2565b905060006001600160a01b038716610c04576000610c08565b6002545b9050610c148289611297565b9450670de0b6b3a7640000610c298287611b2d565b610c339190611b4c565b9350670de0b6b3a764000060035486610c4c9190611b2d565b610c569190611b4c565b925082610c638587611b01565b6109159190611b01565b610c756112c9565b6001600160a01b038116610cc55760405162461bcd60e51b815260206004820152601760248201527624b73b30b634b2103cb4b2b63220b3b3b932b3b0ba37b960491b6044820152606401610442565b600b546001600160a01b0316610ce157610cde81611373565b50565b610ce961140b565b600b54604080516376d5de8560e01b815290516000926001600160a01b0316916376d5de859160048083019260209291908290030181865afa158015610d33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d579190611b87565b600b54909150610d75906001600160a01b03808416911660006114da565b610d7e82611373565b610d86611611565b5050565b60096020528160005260406000208181548110610da657600080fd5b90600052602060002001600091509150505481565b6001548410610dfe5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081cda185c995259608a1b6044820152606401610442565b6040516327e662e160e21b81523360048201526024810185905283907f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b031690639f998b8490604401602060405180830381865afa158015610e6b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8f9190611ad2565b1015610ed35760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742073686172657360681b6044820152606401610442565b6000848152600860205260408120546001600160a01b031690808080610efa8989886107b2565b935093509350935086841015610f525760405162461bcd60e51b815260206004820152601760248201527f496e73756666696369656e74206d696e526563656976650000000000000000006044820152606401610442565b6040516317a99ced60e31b8152336004820152602481018a9052604481018990527f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b03169063bd4ce76890606401600060405180830381600087803b158015610fc157600080fd5b505af1158015610fd5573d6000803e3d6000fd5b505060405163d2cf911560e01b8152600481018c9052600092507f00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac6001600160a01b0316915063d2cf911590602401602060405180830381865afa158015611041573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110659190611ad2565b6040805160008152602081018c9052908101879052606081018590526080810184905260a081018290529091508a9033907f29db2a6062b25ead33a5fc8d1163c4d7f54397202547c27c1c99a203446477349060c00160405180910390a3600b546040516316d7ac4560e31b8152600481018690526001600160a01b039091169063b6bd622890602401600060405180830381600087803b15801561110957600080fd5b505af115801561111d573d6000803e3d6000fd5b5050505083600a60008282546111339190611b1a565b90915550611143905033866111d9565b61114d87846111d9565b61115786836111d9565b50505050505050505050565b61116b6112c9565b6001600160a01b0381166111d05760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610442565b610cde81611323565b8015610d8657604080516000808252602082019092526001600160a01b0384169083906040516112099190611bc8565b60006040518083038185875af1925050503d8060008114611246576040519150601f19603f3d011682016040523d82523d6000602084013e61124b565b606091505b50509050806112925760405162461bcd60e51b8152602060048201526013602482015272115d1a081d1c985b9cd9995c8819985a5b1959606a1b6044820152606401610442565b505050565b600454600554908202906112ac908484611679565b60065460075491909201916112c2918585611694565b0192915050565b6000546001600160a01b03163314610b525760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610442565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600b80546001600160a01b0319166001600160a01b038316908117909155604080516376d5de8560e01b81529051600092916376d5de859160048083019260209291908290030181865afa1580156113cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113f39190611b87565b9050610d866001600160a01b038216836000196114da565b600b54604051638812ebc960e01b81523060048201526000916001600160a01b031690638812ebc990602401602060405180830381865afa158015611454573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114789190611ad2565b600b546040516316d7ac4560e31b8152600481018390529192506001600160a01b03169063b6bd622890602401600060405180830381600087803b1580156114bf57600080fd5b505af11580156114d3573d6000803e3d6000fd5b5050505050565b8015806115545750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561152e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115529190611ad2565b155b6115bf5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610442565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526112929084906117cb565b600b544790611629906001600160a01b0316826111d9565b600b60009054906101000a90046001600160a01b03166001600160a01b031663bb282e5c6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156114bf57600080fd5b600180830183028284018281010203901c83025b9392505050565b6000848480820283036116ac576000925050506117c3565b60018581019085870101838118818511028418808310156116f65760066001808a018a028a821b820102600019840180850290831b90920191909102030485800285040295509150815b818310156117bd576003850260021c600185901b5b60006117a1888488030270ffffffffffffffffffffffffffffffffff811160071b81811c68ffffffffffffffffff1060061b1781811c64ffffffffff1060051b1781811c62ffffff1060041b1781811c620100000160b5600192831c1b0260121c80830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c908190048111900390565b82028890049890980197506001808601958590030161170b5750505b50505050505b949350505050565b6000611820826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661189d9092919063ffffffff16565b805190915015611292578080602001905181019061183e9190611be4565b6112925760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610442565b60606117c38484600085856001600160a01b0385163b6118ff5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610442565b600080866001600160a01b0316858760405161191b9190611bc8565b60006040518083038185875af1925050503d8060008114611958576040519150601f19603f3d011682016040523d82523d6000602084013e61195d565b606091505b509150915061196d828286611978565b979650505050505050565b6060831561198757508161168d565b8251156119975782518084602001fd5b8160405162461bcd60e51b81526004016104429190611c06565b6001600160a01b0381168114610cde57600080fd5b6000806000606084860312156119db57600080fd5b833592506020840135915060408401356119f4816119b1565b809150509250925092565b60008060408385031215611a1257600080fd5b823591506020830135611a24816119b1565b809150509250929050565b600060208284031215611a4157600080fd5b5035919050565b600060208284031215611a5a57600080fd5b813561168d816119b1565b60008060408385031215611a7857600080fd5b8235611a83816119b1565b946020939093013593505050565b60008060008060808587031215611aa757600080fd5b8435935060208501359250604085013591506060850135611ac7816119b1565b939692955090935050565b600060208284031215611ae457600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115611b1457611b14611aeb565b92915050565b81810381811115611b1457611b14611aeb565b6000816000190483118215151615611b4757611b47611aeb565b500290565b600082611b6957634e487b7160e01b600052601260045260246000fd5b500490565b600060018201611b8057611b80611aeb565b5060010190565b600060208284031215611b9957600080fd5b815161168d816119b1565b60005b83811015611bbf578181015183820152602001611ba7565b50506000910152565b60008251611bda818460208701611ba4565b9190910192915050565b600060208284031215611bf657600080fd5b8151801515811461168d57600080fd5b6020815260008251806020840152611c25816040850160208701611ba4565b601f01601f1916919091016040019291505056fea2646970667358221220e124d6218d8e6912daad0a47e0220371870699af9cddd32b11c4306ccdedd90564736f6c63430008100033

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

00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac0000000000000000000000000000000000000000000000000011c37937e0800000000000000000000000000000000000000000000000000000000000000005dc000000000000000000000000000000000000000000000000016c2734f97a40000000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _mestERC1155 (address): 0x71f33F2E0C6f7B8506D98cA93ca92a944efE77Ac
Arg [1] : _basePrice (uint256): 5000000000000000
Arg [2] : _inflectionPoint (uint256): 1500
Arg [3] : _inflectionPrice (uint256): 102500000000000000
Arg [4] : _linearPriceSlope (uint256): 0

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 00000000000000000000000071f33f2e0c6f7b8506d98ca93ca92a944efe77ac
Arg [1] : 0000000000000000000000000000000000000000000000000011c37937e08000
Arg [2] : 00000000000000000000000000000000000000000000000000000000000005dc
Arg [3] : 000000000000000000000000000000000000000000000000016c2734f97a4000
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
0xDe9b3Cde510EB1B654Aeae92aB8b74a71b46F5c8
Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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