ETH Price: $3,365.24 (-1.51%)
Gas: 7 Gwei

Contract

0xb77A65E680Ba99BDFB530D3Cc0692Cd75b088bA1
 

Overview

ETH Balance

13.847334405879922516 ETH

Eth Value

$46,599.61 (@ $3,365.24/ETH)
Transaction Hash
Method
Block
From
To
Value
Sell201499532024-06-22 21:33:593 days ago1719092039IN
0xb77A65E6...75b088bA1
0 ETH0.000195072.40460024
Buy200957772024-06-15 7:43:1111 days ago1718437391IN
0xb77A65E6...75b088bA1
0.01427245 ETH0.000471933.73487725
Buy200838592024-06-13 15:41:1113 days ago1718293271IN
0xb77A65E6...75b088bA1
0.01420202 ETH0.0024436419.3389317
Buy200819682024-06-13 9:20:1113 days ago1718270411IN
0xb77A65E6...75b088bA1
0.0141319 ETH0.0012210311.17432985
Buy200807362024-06-13 5:11:4713 days ago1718255507IN
0xb77A65E6...75b088bA1
0.01406208 ETH0.0013661410.81059772
Sell200738512024-06-12 6:07:1114 days ago1718172431IN
0xb77A65E6...75b088bA1
0 ETH0.000711945.77026359
Buy200721162024-06-12 0:17:4714 days ago1718151467IN
0xb77A65E6...75b088bA1
0.01441422 ETH0.0007747.08334377
Buy200711332024-06-11 21:00:3514 days ago1718139635IN
0xb77A65E6...75b088bA1
0.01434318 ETH0.001359312.43971774
Buy200704262024-06-11 18:37:5915 days ago1718131079IN
0xb77A65E6...75b088bA1
0.01427245 ETH0.0012632511.56071192
Buy200699082024-06-11 16:54:1115 days ago1718124851IN
0xb77A65E6...75b088bA1
0.01420202 ETH0.002236220.46480407
Buy200692112024-06-11 14:33:5915 days ago1718116439IN
0xb77A65E6...75b088bA1
0.0141319 ETH0.0027381125.0580654
Sell200634992024-06-10 19:24:3515 days ago1718047475IN
0xb77A65E6...75b088bA1
0 ETH0.0015452919.05137087
Buy200604772024-06-10 9:15:5916 days ago1718010959IN
0xb77A65E6...75b088bA1
0.01406208 ETH0.000585144.63039759
Buy200546292024-06-09 13:40:4717 days ago1717940447IN
0xb77A65E6...75b088bA1
0.01399256 ETH0.0013310310.53374311
Sell200366902024-06-07 1:33:1119 days ago1717723991IN
0xb77A65E6...75b088bA1
0 ETH0.0009742310.18568679
Buy200334462024-06-06 14:41:1120 days ago1717684871IN
0xb77A65E6...75b088bA1
0.01392334 ETH0.0033910726.83680289
Buy200244352024-06-05 8:28:3521 days ago1717576115IN
0xb77A65E6...75b088bA1
0.01385443 ETH0.001010848.00051849
Buy200222092024-06-05 1:02:1121 days ago1717549331IN
0xb77A65E6...75b088bA1
0.00633004 ETH0.000653925.17513537
Sell200186172024-06-04 13:00:2322 days ago1717506023IN
0xb77A65E6...75b088bA1
0 ETH0.0008601810.89644222
Buy200183892024-06-04 12:14:4722 days ago1717503287IN
0xb77A65E6...75b088bA1
0.01385443 ETH0.0014942911.82464986
Buy200133062024-06-03 19:13:1122 days ago1717441991IN
0xb77A65E6...75b088bA1
0.0060503 ETH0.0015747210.97774943
Buy199795852024-05-30 2:08:3527 days ago1717034915IN
0xb77A65E6...75b088bA1
0.01378582 ETH0.00101268.01372459
Sell199792962024-05-30 1:10:2327 days ago1717031423IN
0xb77A65E6...75b088bA1
0 ETH0.0009268611.7411484
Buy199789052024-05-29 23:51:4727 days ago1717026707IN
0xb77A65E6...75b088bA1
0.01378582 ETH0.000886777.01724432
Sell199727492024-05-29 3:10:3528 days ago1716952235IN
0xb77A65E6...75b088bA1
0 ETH0.000596737.35475364
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To Value
201499532024-06-22 21:33:593 days ago1719092039
0xb77A65E6...75b088bA1
0.01179541 ETH
200957772024-06-15 7:43:1111 days ago1718437391
0xb77A65E6...75b088bA1
0.00129749 ETH
200957772024-06-15 7:43:1111 days ago1718437391
0xb77A65E6...75b088bA1
0.00088465 ETH
200838592024-06-13 15:41:1113 days ago1718293271
0xb77A65E6...75b088bA1
0.00129109 ETH
200838592024-06-13 15:41:1113 days ago1718293271
0xb77A65E6...75b088bA1
0.00088029 ETH
200819682024-06-13 9:20:1113 days ago1718270411
0xb77A65E6...75b088bA1
0.00128471 ETH
200819682024-06-13 9:20:1113 days ago1718270411
0xb77A65E6...75b088bA1
0.00087594 ETH
200807362024-06-13 5:11:4713 days ago1718255507
0xb77A65E6...75b088bA1
0.00127837 ETH
200807362024-06-13 5:11:4713 days ago1718255507
0xb77A65E6...75b088bA1
0.00087161 ETH
200738512024-06-12 6:07:1114 days ago1718172431
0xb77A65E6...75b088bA1
0.0705999 ETH
200721162024-06-12 0:17:4714 days ago1718151467
0xb77A65E6...75b088bA1
0.00131038 ETH
200721162024-06-12 0:17:4714 days ago1718151467
0xb77A65E6...75b088bA1
0.00089344 ETH
200711332024-06-11 21:00:3514 days ago1718139635
0xb77A65E6...75b088bA1
0.00130392 ETH
200711332024-06-11 21:00:3514 days ago1718139635
0xb77A65E6...75b088bA1
0.00088904 ETH
200704262024-06-11 18:37:5915 days ago1718131079
0xb77A65E6...75b088bA1
0.00129749 ETH
200704262024-06-11 18:37:5915 days ago1718131079
0xb77A65E6...75b088bA1
0.00088465 ETH
200699082024-06-11 16:54:1115 days ago1718124851
0xb77A65E6...75b088bA1
0.00129109 ETH
200699082024-06-11 16:54:1115 days ago1718124851
0xb77A65E6...75b088bA1
0.00088029 ETH
200692112024-06-11 14:33:5915 days ago1718116439
0xb77A65E6...75b088bA1
0.00128471 ETH
200692112024-06-11 14:33:5915 days ago1718116439
0xb77A65E6...75b088bA1
0.00087594 ETH
200634992024-06-10 19:24:3515 days ago1718047475
0xb77A65E6...75b088bA1
0.00254505 ETH
200604772024-06-10 9:15:5916 days ago1718010959
0xb77A65E6...75b088bA1
0.00127837 ETH
200604772024-06-10 9:15:5916 days ago1718010959
0xb77A65E6...75b088bA1
0.00087161 ETH
200546292024-06-09 13:40:4717 days ago1717940447
0xb77A65E6...75b088bA1
0.00127205 ETH
200546292024-06-09 13:40:4717 days ago1717940447
0xb77A65E6...75b088bA1
0.0008673 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SAM

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion
File 1 of 17 : SAM.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;

import { Ownable, OwnableRoles } from "solady/auth/OwnableRoles.sol";
import { MerkleProofLib } from "solady/utils/MerkleProofLib.sol";
import { SafeCastLib } from "solady/utils/SafeCastLib.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { IERC165 } from "openzeppelin/utils/introspection/IERC165.sol";
import { ISAM, SAMInfo } from "./interfaces/ISAM.sol";
import { ISoundCreatorV1 } from "@core/interfaces/ISoundCreatorV1.sol";
import { BondingCurveLib } from "./utils/BondingCurveLib.sol";
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
import { ISoundEditionV1_2 } from "@core/interfaces/ISoundEditionV1_2.sol";
import { LibMulticaller } from "multicaller/LibMulticaller.sol";

/*
 * @title SAM
 * @notice Module for Sound automated market.
 * @author Sound.xyz
 */
contract SAM is ISAM, Ownable {
    // =============================================================
    //                           CONSTANTS
    // =============================================================

    /**
     * @dev This is the denominator, in basis points (BPS), for any of the fees.
     */
    uint16 public constant BPS_DENOMINATOR = 10_000;

    /**
     * @dev The maximum basis points (BPS) limit allowed for the platform fees.
     */
    uint16 public constant MAX_PLATFORM_FEE_BPS = 500;

    /**
     * @dev The maximum basis points (BPS) limit allowed for the artist fees.
     */
    uint16 public constant MAX_ARTIST_FEE_BPS = 1_000;

    /**
     * @dev The maximum basis points (BPS) limit allowed for the affiliate fees.
     */
    uint16 public constant MAX_AFFILIATE_FEE_BPS = 500;

    /**
     * @dev The maximum basis points (BPS) limit allowed for the golden egg fees.
     */
    uint16 public constant MAX_GOLDEN_EGG_FEE_BPS = 500;

    // =============================================================
    //                            STORAGE
    // =============================================================

    /**
     * @dev How much platform fees have been accrued.
     */
    uint128 public platformFeesAccrued;

    /**
     * @dev The platform fee in basis points.
     */
    uint16 public platformFeeBPS;

    /**
     * @dev Just in case. Won't cost much overhead anyway since it is packed.
     */
    bool internal _reentrancyGuard;

    /**
     * @dev The platform fee address.
     */
    address public platformFeeAddress;

    /**
     * @dev List of approved edition factories.
     */
    address[] internal _approvedEditionFactories;

    /**
     * @dev The data for the sound automated markets.
     * edition => SAMData
     */
    mapping(address => SAMData) internal _samData;

    /**
     * @dev Maps an address to how much affiliate fees have they accrued.
     */
    mapping(address => uint128) public affiliateFeesAccrued;

    // =============================================================
    //                          CONSTRUCTOR
    // =============================================================

    constructor() payable {
        _initializeOwner(msg.sender);
    }

    // =============================================================
    //               PUBLIC / EXTERNAL WRITE FUNCTIONS
    // =============================================================

    /**
     * @inheritdoc ISAM
     */
    function create(
        address edition,
        uint96 basePrice,
        uint128 linearPriceSlope,
        uint128 inflectionPrice,
        uint32 inflectionPoint,
        uint32 maxSupply,
        uint32 buyFreezeTime,
        uint16 artistFeeBPS,
        uint16 goldenEggFeeBPS,
        uint16 affiliateFeeBPS,
        address editionBy,
        bytes32 editionSalt
    ) public {
        // We don't use modifiers here in order to prevent stack too deep.
        _requireOnlyEditionOwnerOrAdmin(edition); // `onlyEditionOwnerOrAdmin`.
        _requireOnlyBeforeSAMPhase(edition); // `onlyBeforeSAMPhase`.
        if (maxSupply == 0) revert InvalidMaxSupply();
        if (buyFreezeTime == 0) revert InvalidBuyFreezeTime();
        if (artistFeeBPS > MAX_ARTIST_FEE_BPS) revert InvalidArtistFeeBPS();
        if (goldenEggFeeBPS > MAX_GOLDEN_EGG_FEE_BPS) revert InvalidGoldenEggFeeBPS();
        if (affiliateFeeBPS > MAX_AFFILIATE_FEE_BPS) revert InvalidAffiliateFeeBPS();

        _requireEditionIsApproved(edition, editionBy, editionSalt);

        SAMData storage data = _samData[edition];

        if (data.created) revert SAMAlreadyExists();

        data.basePrice = basePrice;
        data.linearPriceSlope = linearPriceSlope;
        data.inflectionPrice = inflectionPrice;
        data.inflectionPoint = inflectionPoint;
        data.maxSupply = maxSupply;
        data.buyFreezeTime = buyFreezeTime;
        data.artistFeeBPS = artistFeeBPS;
        data.goldenEggFeeBPS = goldenEggFeeBPS;
        data.affiliateFeeBPS = affiliateFeeBPS;
        data.created = true;

        emit Created(
            edition,
            basePrice,
            linearPriceSlope,
            inflectionPrice,
            inflectionPoint,
            maxSupply,
            buyFreezeTime,
            artistFeeBPS,
            goldenEggFeeBPS,
            affiliateFeeBPS
        );
    }

    /**
     * For avoiding stack too deep.
     */
    struct _BuyTemps {
        uint256 fromCurveSupply;
        uint256 fromTokenId;
        uint256 requiredEtherValue;
        uint256 subTotal;
        uint256 platformFee;
        uint256 artistFee;
        uint256 goldenEggFee;
        uint256 affiliateFee;
        uint256 quantity;
        address affiliate;
        bool affiliated;
    }

    /**
     * @inheritdoc ISAM
     */
    function buy(
        address edition,
        address to,
        uint32 quantity,
        address affiliate,
        bytes32[] calldata affiliateProof,
        uint256 attributonId
    ) public payable nonReentrant {
        if (quantity == 0) revert MintZeroQuantity();

        _BuyTemps memory t;
        SAMData storage data = _getSAMData(edition);
        t.quantity = quantity; // Cache the `quantity` to avoid stack too deep.
        t.affiliate = affiliate; // Cache the `affiliate` to avoid stack too deep.
        t.fromCurveSupply = data.supply; // Cache the `data.supply`.

        if (block.timestamp >= data.buyFreezeTime) revert BuyIsFrozen();

        (
            t.requiredEtherValue,
            t.subTotal,
            t.platformFee,
            t.artistFee,
            t.goldenEggFee,
            t.affiliateFee
        ) = _totalBuyPriceAndFees(data, uint32(t.fromCurveSupply), quantity);

        if (msg.value < t.requiredEtherValue) revert Underpaid(msg.value, t.requiredEtherValue);

        unchecked {
            // Check if the purchase won't exceed the supply cap.
            if (t.fromCurveSupply + t.quantity > data.maxSupply) {
                revert ExceedsMaxSupply(uint32(data.maxSupply - t.fromCurveSupply));
            }

            // Check if the affiliate is actually affiliated for edition with the affiliate proof.
            t.affiliated = isAffiliatedWithProof(edition, affiliate, affiliateProof);
            // If affiliated, compute and accrue the affiliate fee.
            if (t.affiliated) {
                // Accrue the affiliate fee.
                if (t.affiliateFee != 0) {
                    affiliateFeesAccrued[affiliate] = SafeCastLib.toUint128(
                        uint256(affiliateFeesAccrued[affiliate]) + t.affiliateFee
                    );
                }
            } else {
                // If the affiliate is not the zero address despite not being
                // affiliated, it might be due to an invalid affiliate proof.
                // Revert to prevent redirection of fees.
                if (affiliate != address(0)) {
                    revert InvalidAffiliate();
                }
                // Otherwise, redirect the affiliate fee to the artist fee instead.
                t.artistFee += t.affiliateFee;
                t.affiliateFee = 0;
            }

            // Accrue the platform fee.
            if (t.platformFee != 0) {
                platformFeesAccrued = SafeCastLib.toUint128(uint256(platformFeesAccrued) + t.platformFee);
            }

            // Accrue the golden egg fee.
            if (t.goldenEggFee != 0) {
                data.goldenEggFeesAccrued = SafeCastLib.toUint112(uint256(data.goldenEggFeesAccrued) + t.goldenEggFee);
            }

            // Add the `subTotal` to the balance.
            data.balance = SafeCastLib.toUint112(uint256(data.balance) + t.subTotal);

            // Add `quantity` to the supply.
            data.supply = SafeCastLib.toUint32(t.fromCurveSupply + t.quantity);

            // Indicate that tokens have already been minted via the bonding curve.
            data.hasMinted = true;

            // Mint the tokens and transfer the artist fee to the edition contract.
            t.fromTokenId = ISoundEditionV1_2(edition).samMint{ value: t.artistFee }(to, quantity);

            // Refund any excess ETH.
            if (msg.value > t.requiredEtherValue) {
                SafeTransferLib.forceSafeTransferETH(msg.sender, msg.value - t.requiredEtherValue);
            }

            emit Bought(
                edition,
                to,
                t.fromTokenId,
                uint32(t.fromCurveSupply),
                uint32(t.quantity),
                uint128(t.requiredEtherValue),
                uint128(t.platformFee),
                uint128(t.artistFee),
                uint128(t.goldenEggFee),
                uint128(t.affiliateFee),
                t.affiliate,
                t.affiliated,
                attributonId
            );
        }
    }

    /**
     * @inheritdoc ISAM
     */
    function sell(
        address edition,
        uint256[] calldata tokenIds,
        uint256 minimumPayout,
        address payoutTo,
        uint256 attributonId
    ) public nonReentrant {
        uint256 quantity = tokenIds.length;
        // To prevent no-op.
        if (quantity == 0) revert BurnZeroQuantity();

        unchecked {
            SAMData storage data = _getSAMData(edition);

            uint256 supply = data.supply;

            // Revert with `InsufficientSupply(available, required)` if `supply < quantity`.
            if (supply < quantity) revert InsufficientSupply(supply, quantity);
            // Will not underflow because of the above check.
            uint256 supplyMinusQuantity = supply - quantity;

            // Compute how much to pay out.
            uint256 payout = _subTotal(data, uint32(supplyMinusQuantity), uint32(quantity));
            // Revert if the payout isn't sufficient.
            if (payout < minimumPayout) revert InsufficientPayout(payout, minimumPayout);

            // Decrease the supply.
            data.supply = uint32(supplyMinusQuantity);

            // Deduct `payout` from `data.balance`.
            uint256 balance = data.balance;
            // Second safety guard. If we actually revert here, something is wrong.
            if (balance < payout) revert("WTF");
            // Will not underflow because of the above check.
            data.balance = uint112(balance - payout);

            // Burn the tokens.
            ISoundEditionV1_2(edition).samBurn(msg.sender, tokenIds);

            // Pay out the ETH.
            SafeTransferLib.forceSafeTransferETH(payoutTo, payout);

            emit Sold(edition, payoutTo, uint32(supply), tokenIds, uint128(payout), attributonId);
        }
    }

    // Bonding curve price parameter setters:
    // --------------------------------------
    // The following functions can only be called before the SAM phase:
    // - Before the mint has concluded on the SoundEdition.
    // - Before `_samData[edition].hasMinted` is set to true.
    //
    // Once any tokens have been minted via SAM,
    // these setters cannot be called.
    //
    // These parameters must be unchangable during the SAM
    // phase to ensure the consistency between the buy and sell prices.

    /**
     * @inheritdoc ISAM
     */
    function setBasePrice(address edition, uint96 basePrice)
        public
        onlyEditionOwnerOrAdmin(edition)
        onlyBeforeSAMPhase(edition)
    {
        SAMData storage data = _getSAMData(edition);
        data.basePrice = basePrice;
        emit BasePriceSet(edition, basePrice);
    }

    /**
     * @inheritdoc ISAM
     */
    function setLinearPriceSlope(address edition, uint128 linearPriceSlope)
        public
        onlyEditionOwnerOrAdmin(edition)
        onlyBeforeSAMPhase(edition)
    {
        SAMData storage data = _getSAMData(edition);
        data.linearPriceSlope = linearPriceSlope;
        emit LinearPriceSlopeSet(edition, linearPriceSlope);
    }

    /**
     * @inheritdoc ISAM
     */
    function setInflectionPrice(address edition, uint128 inflectionPrice)
        public
        onlyEditionOwnerOrAdmin(edition)
        onlyBeforeSAMPhase(edition)
    {
        SAMData storage data = _getSAMData(edition);
        data.inflectionPrice = inflectionPrice;
        emit InflectionPriceSet(edition, inflectionPrice);
    }

    /**
     * @inheritdoc ISAM
     */
    function setInflectionPoint(address edition, uint32 inflectionPoint)
        public
        onlyEditionOwnerOrAdmin(edition)
        onlyBeforeSAMPhase(edition)
    {
        SAMData storage data = _getSAMData(edition);
        data.inflectionPoint = inflectionPoint;
        emit InflectionPointSet(edition, inflectionPoint);
    }

    // Per edition fee BPS setters:
    // ----------------------------
    // To provide flexbility, we allow the artist to adjust the fees
    // even during the SAM phase. As these BPSes cannot exceed hardcoded limits,
    // in the event that am artist account is compromised, the worse case is
    // users having to pay the maximum limits on the fees.
    //
    // Note: The golden egg fee setter is given special treatment:
    // it cannot be called once the mint has concluded on
    // SoundEdition or if any tokens have been minted.

    /**
     * @inheritdoc ISAM
     */
    function setArtistFee(address edition, uint16 bps) public onlyEditionOwnerOrAdmin(edition) {
        SAMData storage data = _getSAMData(edition);
        if (bps > MAX_ARTIST_FEE_BPS) revert InvalidArtistFeeBPS();
        data.artistFeeBPS = bps;
        emit ArtistFeeSet(edition, bps);
    }

    /**
     * @inheritdoc ISAM
     */
    function setGoldenEggFee(address edition, uint16 bps)
        public
        onlyEditionOwnerOrAdmin(edition)
        onlyBeforeSAMPhase(edition)
    {
        SAMData storage data = _getSAMData(edition);
        if (bps > MAX_GOLDEN_EGG_FEE_BPS) revert InvalidGoldenEggFeeBPS();
        data.goldenEggFeeBPS = bps;
        emit GoldenEggFeeSet(edition, bps);
    }

    /**
     * @inheritdoc ISAM
     */
    function setAffiliateFee(address edition, uint16 bps) public onlyEditionOwnerOrAdmin(edition) {
        SAMData storage data = _getSAMData(edition);
        if (bps > MAX_AFFILIATE_FEE_BPS) revert InvalidAffiliateFeeBPS();
        data.affiliateFeeBPS = bps;
        emit AffiliateFeeSet(edition, bps);
    }

    /**
     * @inheritdoc ISAM
     */
    function setAffiliateMerkleRoot(address edition, bytes32 root) public onlyEditionOwnerOrAdmin(edition) {
        // Note that we want to allow adding a root even while the bonding curve
        // is still ongoing, in case the need to prevent spam arises.

        SAMData storage data = _getSAMData(edition);
        data.affiliateMerkleRoot = root;
        emit AffiliateMerkleRootSet(edition, root);
    }

    // Other per edition setters:
    // --------------------------
    // To provide flexbility, we allow the artist to adjust these parameters
    // even during the SAM phase.
    //
    // These functions are unable to inflate the supply during the SAM phase.

    /**
     * @inheritdoc ISAM
     */
    function setMaxSupply(address edition, uint32 maxSupply) public onlyEditionOwnerOrAdmin(edition) {
        SAMData storage data = _getSAMData(edition);
        // Disallow increasing during the SAM phase.
        if (maxSupply > data.maxSupply)
            if (_inSAMPhase(edition)) revert InvalidMaxSupply();
        data.maxSupply = maxSupply;
        emit MaxSupplySet(edition, maxSupply);
    }

    /**
     * @inheritdoc ISAM
     */
    function setBuyFreezeTime(address edition, uint32 buyFreezeTime) public onlyEditionOwnerOrAdmin(edition) {
        SAMData storage data = _getSAMData(edition);
        // Disallow increasing during the SAM phase.
        if (buyFreezeTime > data.buyFreezeTime)
            if (_inSAMPhase(edition)) revert InvalidBuyFreezeTime();
        data.buyFreezeTime = buyFreezeTime;
        emit BuyFreezeTimeSet(edition, buyFreezeTime);
    }

    // Withdrawal functions:
    // ---------------------
    // These functions can be called by anyone.

    /**
     * @inheritdoc ISAM
     */
    function withdrawForAffiliate(address affiliate) public nonReentrant {
        uint128 accrued = affiliateFeesAccrued[affiliate];
        if (accrued != 0) {
            affiliateFeesAccrued[affiliate] = 0;
            SafeTransferLib.forceSafeTransferETH(affiliate, accrued);
            emit AffiliateFeesWithdrawn(affiliate, accrued);
        }
    }

    /**
     * @inheritdoc ISAM
     */
    function withdrawForPlatform() public nonReentrant {
        address to = platformFeeAddress;
        if (to == address(0)) revert PlatformFeeAddressIsZero();
        uint128 accrued = platformFeesAccrued;
        if (accrued != 0) {
            platformFeesAccrued = 0;
            SafeTransferLib.forceSafeTransferETH(to, accrued);
            emit PlatformFeesWithdrawn(accrued);
        }
    }

    /**
     * @inheritdoc ISAM
     */
    function withdrawForGoldenEgg(address edition) public nonReentrant {
        SAMData storage data = _getSAMData(edition);
        uint128 accrued = data.goldenEggFeesAccrued;
        if (accrued != 0) {
            data.goldenEggFeesAccrued = 0;
            address receipient = goldenEggFeeRecipient(edition);
            SafeTransferLib.forceSafeTransferETH(receipient, accrued);
            emit GoldenEggFeesWithdrawn(edition, receipient, accrued);
        }
    }

    // Only onwer setters:
    // -------------------
    // These functions can only be called by the owner of the SAM contract.

    /**
     * @inheritdoc ISAM
     */
    function setPlatformFee(uint16 bps) public onlyOwner {
        if (bps > MAX_PLATFORM_FEE_BPS) revert InvalidPlatformFeeBPS();
        platformFeeBPS = bps;
        emit PlatformFeeSet(bps);
    }

    /**
     * @inheritdoc ISAM
     */
    function setPlatformFeeAddress(address addr) public onlyOwner {
        if (addr == address(0)) revert PlatformFeeAddressIsZero();
        platformFeeAddress = addr;
        emit PlatformFeeAddressSet(addr);
    }

    /**
     * @inheritdoc ISAM
     */
    function setApprovedEditionFactories(address[] calldata factories) public onlyOwner {
        _approvedEditionFactories = factories;
        emit ApprovedEditionFactoriesSet(factories);
    }

    // =============================================================
    //               PUBLIC / EXTERNAL VIEW FUNCTIONS
    // =============================================================

    /**
     * @inheritdoc ISAM
     */
    function samInfo(address edition) external view returns (SAMInfo memory info) {
        SAMData storage data = _getSAMData(edition);
        info.basePrice = data.basePrice;
        info.inflectionPrice = data.inflectionPrice;
        info.linearPriceSlope = data.linearPriceSlope;
        info.inflectionPoint = data.inflectionPoint;
        info.goldenEggFeesAccrued = data.goldenEggFeesAccrued;
        info.supply = data.supply;
        info.balance = data.balance;
        info.maxSupply = data.maxSupply;
        info.buyFreezeTime = data.buyFreezeTime;
        info.artistFeeBPS = data.artistFeeBPS;
        info.affiliateFeeBPS = data.affiliateFeeBPS;
        info.goldenEggFeeBPS = data.goldenEggFeeBPS;
        info.affiliateMerkleRoot = data.affiliateMerkleRoot;
    }

    /**
     * @inheritdoc ISAM
     */
    function totalValue(
        address edition,
        uint32 fromSupply,
        uint32 quantity
    ) public view returns (uint256 total) {
        total = _subTotal(_getSAMData(edition), fromSupply, quantity);
    }

    /**
     * @inheritdoc ISAM
     */
    function totalBuyPriceAndFees(
        address edition,
        uint32 supplyForwardOffset,
        uint32 quantity
    )
        public
        view
        returns (
            uint256 total,
            uint256 platformFee,
            uint256 artistFee,
            uint256 goldenEggFee,
            uint256 affiliateFee
        )
    {
        SAMData storage data = _getSAMData(edition);
        uint256 fromSupply = uint256(data.supply) + uint256(supplyForwardOffset);
        // Reverts if the planned purchase exceeds the supply cap. Just for correctness.
        if (fromSupply + uint256(quantity) > data.maxSupply) {
            revert ExceedsMaxSupply(uint32(data.maxSupply - fromSupply));
        }
        (total, , platformFee, artistFee, goldenEggFee, affiliateFee) = _totalBuyPriceAndFees(
            data,
            SafeCastLib.toUint32(fromSupply),
            quantity
        );
    }

    /**
     * @inheritdoc ISAM
     */
    function totalSellPrice(
        address edition,
        uint32 supplyBackwardOffset,
        uint32 quantity
    ) public view returns (uint256 total) {
        SAMData storage data = _getSAMData(edition);

        // All checked math. Will revert if anything underflows.
        uint256 supply = uint256(data.supply) - uint256(supplyBackwardOffset);
        uint256 supplyMinusQuantity = supply - uint256(quantity);

        total = _subTotal(data, uint32(supplyMinusQuantity), uint32(quantity));
    }

    /**
     * @inheritdoc ISAM
     */
    function goldenEggFeeRecipient(address edition) public view returns (address recipient) {
        // We use assembly because we don't want to revert
        // if the `metadataModule` is not a valid metadata module contract.
        // Plain solidity requires an extra codesize check.
        assembly {
            // Initialize the recipient to the edition by default.
            recipient := edition
            // Store the function selector of `metadataModule()`.
            mstore(0x00, 0x3684d100)

            if iszero(and(eq(returndatasize(), 0x20), staticcall(gas(), edition, 0x1c, 0x04, 0x00, 0x20))) {
                // For better gas estimation, and to require that edition
                // is a contract with the `metadataModule()` function.
                revert(0, 0)
            }

            let metadataModule := mload(0x00)
            // Store the function selector of `getGoldenEggTokenId(address)`.
            mstore(0x00, 0x4baca2b5)
            mstore(0x20, edition)

            let success := staticcall(gas(), metadataModule, 0x1c, 0x24, 0x20, 0x20)
            if iszero(success) {
                // If there is no returndata upon revert,
                // it is likely due to an out-of-gas error.
                if iszero(returndatasize()) {
                    revert(0, 0) // For better gas estimation.
                }
            }

            if and(eq(returndatasize(), 0x20), success) {
                // Store the function selector of `ownerOf(uint256)`.
                mstore(0x00, 0x6352211e)
                // The `goldenEggTokenId` is already in slot 0x20,
                // as the previous staticcall directly writes the output to slot 0x20.

                success := staticcall(gas(), edition, 0x1c, 0x24, 0x00, 0x20)
                if iszero(success) {
                    // If there is no returndata upon revert,
                    // it is likely due to an out-of-gas error.
                    if iszero(returndatasize()) {
                        revert(0, 0) // For better gas estimation.
                    }
                }

                if and(eq(returndatasize(), 0x20), success) {
                    recipient := mload(0x00)
                }
            }
        }
    }

    /**
     * @inheritdoc ISAM
     */
    function goldenEggFeesAccrued(address edition) public view returns (uint128) {
        return _getSAMData(edition).goldenEggFeesAccrued;
    }

    /**
     * @inheritdoc ISAM
     */
    function isAffiliatedWithProof(
        address edition,
        address affiliate,
        bytes32[] calldata affiliateProof
    ) public view returns (bool) {
        bytes32 root = _getSAMData(edition).affiliateMerkleRoot;
        // If the root is empty, then use the default logic.
        if (root == bytes32(0)) {
            return affiliate != address(0);
        }
        // Otherwise, check if the affiliate is in the Merkle tree.
        // The check that that affiliate is not a zero address is to prevent libraries
        // that fill up partial Merkle trees with empty leafs from screwing things up.
        return
            affiliate != address(0) &&
            MerkleProofLib.verifyCalldata(affiliateProof, root, keccak256(abi.encodePacked(affiliate)));
    }

    /**
     * @inheritdoc ISAM
     */
    function isAffiliated(address edition, address affiliate) public view returns (bool) {
        return isAffiliatedWithProof(edition, affiliate, MerkleProofLib.emptyProof());
    }

    /**
     * @inheritdoc ISAM
     */
    function affiliateMerkleRoot(address edition) external view returns (bytes32) {
        return _getSAMData(edition).affiliateMerkleRoot;
    }

    /**
     * @inheritdoc ISAM
     */
    function approvedEditionFactories() external view returns (address[] memory) {
        return _approvedEditionFactories;
    }

    /**
     * @inheritdoc IERC165
     */
    function supportsInterface(bytes4 interfaceId) public pure override(IERC165) returns (bool) {
        return interfaceId == this.supportsInterface.selector || interfaceId == type(ISAM).interfaceId;
    }

    /**
     * @inheritdoc ISAM
     */
    function moduleInterfaceId() public pure returns (bytes4) {
        return type(ISAM).interfaceId;
    }

    // =============================================================
    //                  INTERNAL / PRIVATE HELPERS
    // =============================================================

    /**
     * @dev Requires that the caller is the owner or admin of `edition`.
     * @param edition The edition address.
     */
    modifier onlyEditionOwnerOrAdmin(address edition) {
        _requireOnlyEditionOwnerOrAdmin(edition);
        _;
    }

    /**
     * @dev Requires that the caller is the owner or admin of `edition`.
     * @param edition The edition address.
     */
    function _requireOnlyEditionOwnerOrAdmin(address edition) internal view {
        address sender = LibMulticaller.sender();
        if (sender != OwnableRoles(edition).owner())
            if (!OwnableRoles(edition).hasAnyRole(sender, ISoundEditionV1_2(edition).ADMIN_ROLE()))
                revert Unauthorized();
    }

    /**
     * @dev Guards the function from reentrancy.
     */
    modifier nonReentrant() {
        require(_reentrancyGuard == false);
        _reentrancyGuard = true;
        _;
        _reentrancyGuard = false;
    }

    /**
     * @dev Requires that the `edition` is not in SAM phase.
     * @param edition The edition address.
     */
    modifier onlyBeforeSAMPhase(address edition) {
        _requireOnlyBeforeSAMPhase(edition);
        _;
    }

    /**
     * @dev Requires that the `edition` is not in SAM phase.
     * @param edition The edition address.
     */
    function _requireOnlyBeforeSAMPhase(address edition) internal view {
        if (_inSAMPhase(edition)) revert InSAMPhase();
    }

    /**
     * @dev Returns whether the edition is in SAM phase.
     * @param edition The edition address.
     * @return result Whether the edition has any minted via SAM, or has initial mints concluded.
     */
    function _inSAMPhase(address edition) internal view returns (bool result) {
        // As long as one token has been bought on the bonding curve,
        // the initial mints have already concluded. This `hasMinted` check
        // disallows a spoofed `mintConcluded` from changing the curve parameters.
        result = _samData[edition].hasMinted || ISoundEditionV1_2(edition).mintConcluded();
    }

    /**
     * @dev Returns the storage pointer to the SAMData for `edition`.
     *      Reverts if the Sound Automated Market does not exist.
     * @param edition The edition address.
     * @return data Storage pointer to a SAMData.
     */
    function _getSAMData(address edition) internal view returns (SAMData storage data) {
        data = _samData[edition];
        if (!data.created) revert SAMDoesNotExist();
    }

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

    /**
     * @dev Returns the total buy price and the fee per BPS.
     * @param data       Storage pointer to a SAMData.
     * @param fromSupply The starting SAM supply.
     * @param quantity   The number of tokens to be minted.
     * @return total        The total buy price with fees.
     * @return subTotal     The buy price before fees.
     * @return platformFee  The platform fee.
     * @return artistFee    The artist fee.
     * @return goldenEggFee The golden egg fee.
     * @return affiliateFee The affiliate fee.
     */
    function _totalBuyPriceAndFees(
        SAMData storage data,
        uint32 fromSupply,
        uint32 quantity
    )
        internal
        view
        returns (
            uint256 total,
            uint256 subTotal,
            uint256 platformFee,
            uint256 artistFee,
            uint256 goldenEggFee,
            uint256 affiliateFee
        )
    {
        unchecked {
            subTotal = _subTotal(data, fromSupply, quantity);

            uint256 feePerBPS = FixedPointMathLib.rawDiv(subTotal, BPS_DENOMINATOR);

            platformFee = uint256(platformFeeBPS) * feePerBPS;
            artistFee = uint256(data.artistFeeBPS) * feePerBPS;
            goldenEggFee = uint256(data.goldenEggFeeBPS) * feePerBPS;
            affiliateFee = uint256(data.affiliateFeeBPS) * feePerBPS;

            total = subTotal + platformFee + artistFee + goldenEggFee + affiliateFee;
        }
    }

    /**
     * @dev Reverts if the `edition` is not created by an approved factory.
     * @param edition The edition address.
     * @param by      The address which created the edition via the factory.
     * @param salt    The salt used to create the edition via the factory.
     */
    function _requireEditionIsApproved(
        address edition,
        address by,
        bytes32 salt
    ) internal view virtual {
        uint256 n = _approvedEditionFactories.length;
        unchecked {
            // As long as there is one approved factory that states that it has
            // created the `edition`, we return from the function, instead of reverting.
            for (uint256 i; i != n; ++i) {
                address factory = _approvedEditionFactories[i];
                try ISoundCreatorV1(factory).soundEditionAddress(by, salt) returns (address addr, bool) {
                    if (addr == edition) return;
                } catch {}
            }
        }
        revert UnapprovedEdition();
    }
}

File 2 of 17 : IMetadataModule.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
 * @title IMetadataModule
 * @notice The interface for custom metadata modules.
 */
interface IMetadataModule {
    /**
     * @dev When implemented, SoundEdition's `tokenURI` redirects execution to this `tokenURI`.
     * @param tokenId The token ID to retrieve the token URI for.
     * @return The token URI string.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 3 of 17 : ISoundCreatorV1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

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

/**
 * @title ISoundCreatorV1
 * @notice The interface for the Sound edition factory.
 */
interface ISoundCreatorV1 {
    // =============================================================
    //                            EVENTS
    // =============================================================

    /**
     * @dev Emitted when an edition is created.
     * @param soundEdition The address of the edition.
     * @param deployer     The address of the deployer.
     * @param initData     The calldata to initialize SoundEdition via `abi.encodeWithSelector`.
     * @param contracts    The list of contracts called.
     * @param data         The list of calldata created via `abi.encodeWithSelector`
     * @param results      The results of calling the contracts. Use `abi.decode` to decode them.
     */
    event SoundEditionCreated(
        address indexed soundEdition,
        address indexed deployer,
        bytes initData,
        address[] contracts,
        bytes[] data,
        bytes[] results
    );

    /**
     * @dev Emitted when the edition implementation address is set.
     * @param newImplementation The new implementation address to be set.
     */
    event SoundEditionImplementationSet(address newImplementation);

    // =============================================================
    //                            ERRORS
    // =============================================================

    /**
     * @dev Thrown if the implementation address is zero.
     */
    error ImplementationAddressCantBeZero();

    /**
     * @dev Thrown if the lengths of the input arrays are not equal.
     */
    error ArrayLengthsMismatch();

    // =============================================================
    //               PUBLIC / EXTERNAL WRITE FUNCTIONS
    // =============================================================

    /**
     * @dev Creates a Sound Edition proxy, initializes it,
     *      and creates mint configurations on a given set of minter addresses.
     * @param salt      The salt used for the CREATE2 to deploy the clone to a
     *                  deterministic address.
     * @param initData  The calldata to initialize SoundEdition via
     *                  `abi.encodeWithSelector`.
     * @param contracts A list of contracts to call.
     * @param data      A list of calldata created via `abi.encodeWithSelector`
     *                  This must contain the same number of entries as `contracts`.
     * @return soundEdition Returns the address of the created contract.
     * @return results      The results of calling the contracts.
     *                      Use `abi.decode` to decode them.
     */
    function createSoundAndMints(
        bytes32 salt,
        bytes calldata initData,
        address[] calldata contracts,
        bytes[] calldata data
    ) external returns (address soundEdition, bytes[] memory results);

    /**
     * @dev Changes the SoundEdition implementation contract address.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract.
     *
     * @param newImplementation The new implementation address to be set.
     */
    function setEditionImplementation(address newImplementation) external;

    // =============================================================
    //               PUBLIC / EXTERNAL VIEW FUNCTIONS
    // =============================================================

    /**
     * @dev The address of the sound edition implementation.
     * @return The configured value.
     */
    function soundEditionImplementation() external returns (address);

    /**
     * @dev Returns the deterministic address for the sound edition clone.
     * @param by   The caller of the {createSoundAndMints} function.
     * @param salt The salt, generated on the client side.
     * @return addr The computed address.
     * @return exists Whether the contract exists.
     */
    function soundEditionAddress(address by, bytes32 salt) external view returns (address addr, bool exists);
}

File 4 of 17 : ISoundEditionV1_2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import { IERC721AUpgradeable } from "chiru-labs/ERC721A-Upgradeable/IERC721AUpgradeable.sol";
import { IERC2981Upgradeable } from "openzeppelin-upgradeable/interfaces/IERC2981Upgradeable.sol";
import { IERC165Upgradeable } from "openzeppelin-upgradeable/utils/introspection/IERC165Upgradeable.sol";

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

/**
 * @dev The information pertaining to this edition.
 */
struct EditionInfo {
    // Base URI for the tokenId.
    string baseURI;
    // Contract URI for OpenSea storefront.
    string contractURI;
    // Name of the collection.
    string name;
    // Symbol of the collection.
    string symbol;
    // Address that receives primary and secondary royalties.
    address fundingRecipient;
    // The current max mintable amount;
    uint32 editionMaxMintable;
    // The lower limit of the maximum number of tokens that can be minted.
    uint32 editionMaxMintableUpper;
    // The upper limit of the maximum number of tokens that can be minted.
    uint32 editionMaxMintableLower;
    // The timestamp (in seconds since unix epoch) after which the
    // max amount of tokens mintable will drop from
    // `maxMintableUpper` to `maxMintableLower`.
    uint32 editionCutoffTime;
    // Address of metadata module, address(0x00) if not used.
    address metadataModule;
    // The current mint randomness value.
    uint256 mintRandomness;
    // The royalty BPS (basis points).
    uint16 royaltyBPS;
    // Whether the mint randomness is enabled.
    bool mintRandomnessEnabled;
    // Whether the mint has concluded.
    bool mintConcluded;
    // Whether the metadata has been frozen.
    bool isMetadataFrozen;
    // Next token ID to be minted.
    uint256 nextTokenId;
    // Total number of tokens burned.
    uint256 totalBurned;
    // Total number of tokens minted.
    uint256 totalMinted;
    // Total number of tokens currently in existence.
    uint256 totalSupply;
}

/**
 * @title ISoundEditionV1_2
 * @notice The interface for Sound edition contracts.
 */
interface ISoundEditionV1_2 is IERC721AUpgradeable, IERC2981Upgradeable {
    // =============================================================
    //                            EVENTS
    // =============================================================

    /**
     * @dev Emitted when the metadata module is set.
     * @param metadataModule the address of the metadata module.
     */
    event MetadataModuleSet(address metadataModule);

    /**
     * @dev Emitted when the `baseURI` is set.
     * @param baseURI the base URI of the edition.
     */
    event BaseURISet(string baseURI);

    /**
     * @dev Emitted when the `contractURI` is set.
     * @param contractURI The contract URI of the edition.
     */
    event ContractURISet(string contractURI);

    /**
     * @dev Emitted when the metadata is frozen (e.g.: `baseURI` can no longer be changed).
     * @param metadataModule The address of the metadata module.
     * @param baseURI        The base URI of the edition.
     * @param contractURI    The contract URI of the edition.
     */
    event MetadataFrozen(address metadataModule, string baseURI, string contractURI);

    /**
     * @dev Emitted when the `fundingRecipient` is set.
     * @param fundingRecipient The address of the funding recipient.
     */
    event FundingRecipientSet(address fundingRecipient);

    /**
     * @dev Emitted when the `royaltyBPS` is set.
     * @param bps The new royalty, measured in basis points.
     */
    event RoyaltySet(uint16 bps);

    /**
     * @dev Emitted when the edition's maximum mintable token quantity range is set.
     * @param editionMaxMintableLower_ The lower limit of the maximum number of tokens that can be minted.
     * @param editionMaxMintableUpper_ The upper limit of the maximum number of tokens that can be minted.
     */
    event EditionMaxMintableRangeSet(uint32 editionMaxMintableLower_, uint32 editionMaxMintableUpper_);

    /**
     * @dev Emitted when the edition's cutoff time set.
     * @param editionCutoffTime_ The timestamp.
     */
    event EditionCutoffTimeSet(uint32 editionCutoffTime_);

    /**
     * @dev Emitted when the `mintRandomnessEnabled` is set.
     * @param mintRandomnessEnabled_ The boolean value.
     */
    event MintRandomnessEnabledSet(bool mintRandomnessEnabled_);

    /**
     * @dev Emitted when the `operatorFilteringEnabled` is set.
     * @param operatorFilteringEnabled_ The boolean value.
     */
    event OperatorFilteringEnablededSet(bool operatorFilteringEnabled_);

    /**
     * @dev Emitted upon initialization.
     * @param edition_                 The address of the edition.
     * @param name_                    Name of the collection.
     * @param symbol_                  Symbol of the collection.
     * @param metadataModule_          Address of metadata module, address(0x00) if not used.
     * @param baseURI_                 Base URI.
     * @param contractURI_             Contract URI for OpenSea storefront.
     * @param fundingRecipient_        Address that receives primary and secondary royalties.
     * @param royaltyBPS_              Royalty amount in bps (basis points).
     * @param editionMaxMintableLower_ The lower bound of the max mintable quantity for the edition.
     * @param editionMaxMintableUpper_ The upper bound of the max mintable quantity for the edition.
     * @param editionCutoffTime_       The timestamp after which `editionMaxMintable` drops from
     *                                 `editionMaxMintableUpper` to
     *                                 `max(_totalMinted(), editionMaxMintableLower)`.
     * @param flags_                   The bitwise OR result of the initialization flags.
     *                                 See: {METADATA_IS_FROZEN_FLAG}
     *                                 See: {MINT_RANDOMNESS_ENABLED_FLAG}
     */
    event SoundEditionInitialized(
        address indexed edition_,
        string name_,
        string symbol_,
        address metadataModule_,
        string baseURI_,
        string contractURI_,
        address fundingRecipient_,
        uint16 royaltyBPS_,
        uint32 editionMaxMintableLower_,
        uint32 editionMaxMintableUpper_,
        uint32 editionCutoffTime_,
        uint8 flags_
    );

    /**
     * @dev Emitted upon ETH withdrawal.
     * @param recipient The recipient of the withdrawal.
     * @param amount    The amount withdrawn.
     * @param caller    The account that initiated the withdrawal.
     */
    event ETHWithdrawn(address recipient, uint256 amount, address caller);

    /**
     * @dev Emitted upon ERC20 withdrawal.
     * @param recipient The recipient of the withdrawal.
     * @param tokens    The addresses of the ERC20 tokens.
     * @param amounts   The amount of each token withdrawn.
     * @param caller    The account that initiated the withdrawal.
     */
    event ERC20Withdrawn(address recipient, address[] tokens, uint256[] amounts, address caller);

    /**
     * @dev Emitted upon a mint.
     * @param to          The address to mint to.
     * @param quantity    The number of minted.
     * @param fromTokenId The first token ID minted.
     */
    event Minted(address to, uint256 quantity, uint256 fromTokenId);

    /**
     * @dev Emitted upon an airdrop.
     * @param to          The recipients of the airdrop.
     * @param quantity    The number of tokens airdropped to each address in `to`.
     * @param fromTokenId The first token ID minted to the first address in `to`.
     */
    event Airdropped(address[] to, uint256 quantity, uint256 fromTokenId);

    /**
     * @dev EIP-4906 event to signal marketplaces to refresh the metadata.
     * @param fromTokenId The starting token ID.
     * @param toTokenId   The ending token ID.
     */
    event BatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId);

    /**
     * @dev Emiited when the Sound Automated Market (i.e. bonding curve minter) is set.
     * @param sam_ The Sound Automated Market.
     */
    event SAMSet(address sam_);

    // =============================================================
    //                            ERRORS
    // =============================================================

    /**
     * @dev The edition's metadata is frozen (e.g.: `baseURI` can no longer be changed).
     */
    error MetadataIsFrozen();

    /**
     * @dev The given `royaltyBPS` is invalid.
     */
    error InvalidRoyaltyBPS();

    /**
     * @dev The given `randomnessLockedAfterMinted` value is invalid.
     */
    error InvalidRandomnessLock();

    /**
     * @dev The requested quantity exceeds the edition's remaining mintable token quantity.
     * @param available The number of tokens remaining available for mint.
     */
    error ExceedsEditionAvailableSupply(uint32 available);

    /**
     * @dev The given amount is invalid.
     */
    error InvalidAmount();

    /**
     * @dev The given `fundingRecipient` address is invalid.
     */
    error InvalidFundingRecipient();

    /**
     * @dev The `editionMaxMintableLower` must not be greater than `editionMaxMintableUpper`.
     */
    error InvalidEditionMaxMintableRange();

    /**
     * @dev The `editionMaxMintable` has already been reached.
     */
    error MaximumHasAlreadyBeenReached();

    /**
     * @dev The mint `quantity` cannot exceed `ADDRESS_BATCH_MINT_LIMIT` tokens.
     */
    error ExceedsAddressBatchMintLimit();

    /**
     * @dev The mint randomness has already been revealed.
     */
    error MintRandomnessAlreadyRevealed();

    /**
     * @dev No addresses to airdrop.
     */
    error NoAddressesToAirdrop();

    /**
     * @dev The mint has already concluded.
     */
    error MintHasConcluded();

    /**
     * @dev The mint has not concluded.
     */
    error MintNotConcluded();

    /**
     * @dev Cannot perform the operation after a token has been minted.
     */
    error MintsAlreadyExist();

    /**
     * @dev The token IDs must be in strictly ascending order.
     */
    error TokenIdsNotStrictlyAscending();

    /**
     * @dev Please wait for a while before you burn.
     */
    error CannotBurnImmediately();

    // =============================================================
    //               PUBLIC / EXTERNAL WRITE FUNCTIONS
    // =============================================================

    /**
     * @dev Initializes the contract.
     * @param name_                    Name of the collection.
     * @param symbol_                  Symbol of the collection.
     * @param metadataModule_          Address of metadata module, address(0x00) if not used.
     * @param baseURI_                 Base URI.
     * @param contractURI_             Contract URI for OpenSea storefront.
     * @param fundingRecipient_        Address that receives primary and secondary royalties.
     * @param royaltyBPS_              Royalty amount in bps (basis points).
     * @param editionMaxMintableLower_ The lower bound of the max mintable quantity for the edition.
     * @param editionMaxMintableUpper_ The upper bound of the max mintable quantity for the edition.
     * @param editionCutoffTime_       The timestamp after which `editionMaxMintable` drops from
     *                                 `editionMaxMintableUpper` to
     *                                 `max(_totalMinted(), editionMaxMintableLower)`.
     * @param flags_                   The bitwise OR result of the initialization flags.
     *                                 See: {METADATA_IS_FROZEN_FLAG}
     *                                 See: {MINT_RANDOMNESS_ENABLED_FLAG}
     */
    function initialize(
        string memory name_,
        string memory symbol_,
        address metadataModule_,
        string memory baseURI_,
        string memory contractURI_,
        address fundingRecipient_,
        uint16 royaltyBPS_,
        uint32 editionMaxMintableLower_,
        uint32 editionMaxMintableUpper_,
        uint32 editionCutoffTime_,
        uint8 flags_
    ) external;

    /**
     * @dev Mints `quantity` tokens to addrress `to`
     *      Each token will be assigned a token ID that is consecutively increasing.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have either the
     *   `ADMIN_ROLE`, `MINTER_ROLE`, which can be granted via {grantRole}.
     *   Multiple minters, such as different minter contracts,
     *   can be authorized simultaneously.
     *
     * @param to       Address to mint to.
     * @param quantity Number of tokens to mint.
     * @return fromTokenId The first token ID minted.
     */
    function mint(address to, uint256 quantity) external payable returns (uint256 fromTokenId);

    /**
     * @dev Mints `quantity` tokens to each of the addresses in `to`.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the
     *   `ADMIN_ROLE`, which can be granted via {grantRole}.
     *
     * @param to           Address to mint to.
     * @param quantity     Number of tokens to mint.
     * @return fromTokenId The first token ID minted.
     */
    function airdrop(address[] calldata to, uint256 quantity) external returns (uint256 fromTokenId);

    /**
     * @dev Mints `quantity` tokens to addrress `to`
     *      Each token will be assigned a token ID that is consecutively increasing.
     *
     * Calling conditions:
     * - The caller must be the bonding curve contract.
     *
     * @param to       Address to mint to.
     * @param quantity Number of tokens to mint.
     * @return fromTokenId The first token ID minted.
     */
    function samMint(address to, uint256 quantity) external payable returns (uint256 fromTokenId);

    /**
     * @dev Burns the `tokenIds`.
     *
     * Calling conditions:
     * - The caller must be the bonding curve contract.
     *
     * @param burner   The initiator of the burn.
     * @param tokenIds The list of token IDs to burn.
     */
    function samBurn(address burner, uint256[] calldata tokenIds) external;

    /**
     * @dev Withdraws collected ETH royalties to the fundingRecipient.
     */
    function withdrawETH() external;

    /**
     * @dev Withdraws collected ERC20 royalties to the fundingRecipient.
     * @param tokens array of ERC20 tokens to withdraw
     */
    function withdrawERC20(address[] calldata tokens) external;

    /**
     * @dev Sets metadata module.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param metadataModule Address of metadata module.
     */
    function setMetadataModule(address metadataModule) external;

    /**
     * @dev Sets global base URI.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param baseURI The base URI to be set.
     */
    function setBaseURI(string memory baseURI) external;

    /**
     * @dev Sets contract URI.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param contractURI The contract URI to be set.
     */
    function setContractURI(string memory contractURI) external;

    /**
     * @dev Freezes metadata by preventing any more changes to base URI.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     */
    function freezeMetadata() external;

    /**
     * @dev Sets funding recipient address.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param fundingRecipient Address to be set as the new funding recipient.
     */
    function setFundingRecipient(address fundingRecipient) external;

    /**
     * @dev Sets royalty amount in bps (basis points).
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param bps The new royalty basis points to be set.
     */
    function setRoyalty(uint16 bps) external;

    /**
     * @dev Sets the edition max mintable range.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param editionMaxMintableLower_ The lower limit of the maximum number of tokens that can be minted.
     * @param editionMaxMintableUpper_ The upper limit of the maximum number of tokens that can be minted.
     */
    function setEditionMaxMintableRange(uint32 editionMaxMintableLower_, uint32 editionMaxMintableUpper_) external;

    /**
     * @dev Sets the timestamp after which, the `editionMaxMintable` drops
     *      from `editionMaxMintableUpper` to `editionMaxMintableLower.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param editionCutoffTime_ The timestamp.
     */
    function setEditionCutoffTime(uint32 editionCutoffTime_) external;

    /**
     * @dev Sets whether the `mintRandomness` is enabled.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param mintRandomnessEnabled_ The boolean value.
     */
    function setMintRandomnessEnabled(bool mintRandomnessEnabled_) external;

    /**
     * @dev Sets whether OpenSea operator filtering is enabled.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param operatorFilteringEnabled_ The boolean value.
     */
    function setOperatorFilteringEnabled(bool operatorFilteringEnabled_) external;

    /**
     * @dev Emits an event to signal to marketplaces to refresh all the metadata.
     */
    function emitAllMetadataUpdate() external;

    /**
     * @dev Sets the Sound Automated Market (i.e. bonding curve minter).
     *
     * Calling conditions:
     * - The caller must be the owner of the contract, or have the `ADMIN_ROLE`.
     *
     * @param sam_ The Sound Automated Market.
     */
    function setSAM(address sam_) external;

    // =============================================================
    //               PUBLIC / EXTERNAL VIEW FUNCTIONS
    // =============================================================

    /**
     * @dev Returns the edition info.
     * @return editionInfo The latest value.
     */
    function editionInfo() external view returns (EditionInfo memory editionInfo);

    /**
     * @dev Returns the minter role flag.
     * @return The constant value.
     */
    function MINTER_ROLE() external view returns (uint256);

    /**
     * @dev Returns the admin role flag.
     * @return The constant value.
     */
    function ADMIN_ROLE() external view returns (uint256);

    /**
     * @dev Returns the bit flag to freeze the metadata on initialization.
     * @return The constant value.
     */
    function METADATA_IS_FROZEN_FLAG() external pure returns (uint8);

    /**
     * @dev Returns the bit flag to enable the mint randomness feature on initialization.
     * @return The constant value.
     */
    function MINT_RANDOMNESS_ENABLED_FLAG() external pure returns (uint8);

    /**
     * @dev Returns the bit flag to enable OpenSea operator filtering.
     * @return The constant value.
     */
    function OPERATOR_FILTERING_ENABLED_FLAG() external pure returns (uint8);

    /**
     * @dev Returns the base token URI for the collection.
     * @return The configured value.
     */
    function baseURI() external view returns (string memory);

    /**
     * @dev Returns the contract URI to be used by Opensea.
     *      See: https://docs.opensea.io/docs/contract-level-metadata
     * @return The configured value.
     */
    function contractURI() external view returns (string memory);

    /**
     * @dev Returns the address of the funding recipient.
     * @return The configured value.
     */
    function fundingRecipient() external view returns (address);

    /**
     * @dev Returns the maximum amount of tokens mintable for this edition.
     * @return The configured value.
     */
    function editionMaxMintable() external view returns (uint32);

    /**
     * @dev Returns the upper bound for the maximum tokens that can be minted for this edition.
     * @return The configured value.
     */
    function editionMaxMintableUpper() external view returns (uint32);

    /**
     * @dev Returns the lower bound for the maximum tokens that can be minted for this edition.
     * @return The configured value.
     */
    function editionMaxMintableLower() external view returns (uint32);

    /**
     * @dev Returns the timestamp after which `editionMaxMintable` drops from
     *      `editionMaxMintableUpper` to `editionMaxMintableLower`.
     * @return The configured value.
     */
    function editionCutoffTime() external view returns (uint32);

    /**
     * @dev Returns the address of the metadata module.
     * @return The configured value.
     */
    function metadataModule() external view returns (address);

    /**
     * @dev Returns the randomness based on latest block hash, which is stored upon each mint.
     *      unless {mintConcluded} is true.
     *      Used for game mechanics like the Sound Golden Egg.
     *      Returns 0 before revealed.
     *      WARNING: This value should NOT be used for any reward of significant monetary
     *      value, due to it being computed via a purely on-chain psuedorandom mechanism.
     * @return The latest value.
     */
    function mintRandomness() external view returns (uint256);

    /**
     * @dev Returns whether the `mintRandomness` has been enabled.
     * @return The configured value.
     */
    function mintRandomnessEnabled() external view returns (bool);

    /**
     * @dev Returns whether the `operatorFilteringEnabled` has been enabled.
     * @return The configured value.
     */
    function operatorFilteringEnabled() external view returns (bool);

    /**
     * @dev Returns whether the mint has been concluded.
     * @return The latest value.
     */
    function mintConcluded() external view returns (bool);

    /**
     * @dev Returns the royalty basis points.
     * @return The configured value.
     */
    function royaltyBPS() external view returns (uint16);

    /**
     * @dev Returns whether the metadata module is frozen.
     * @return The configured value.
     */
    function isMetadataFrozen() external view returns (bool);

    /**
     * @dev Returns the sound automated market, if any.
     * @return The configured value.
     */
    function sam() external view returns (address);

    /**
     * @dev Returns the next token ID to be minted.
     * @return The latest value.
     */
    function nextTokenId() external view returns (uint256);

    /**
     * @dev Returns the number of tokens minted by `owner`.
     * @param owner Address to query for number minted.
     * @return The latest value.
     */
    function numberMinted(address owner) external view returns (uint256);

    /**
     * @dev Returns the number of tokens burned by `owner`.
     * @param owner Address to query for number burned.
     * @return The latest value.
     */
    function numberBurned(address owner) external view returns (uint256);

    /**
     * @dev Returns the total amount of tokens minted.
     * @return The latest value.
     */
    function totalMinted() external view returns (uint256);

    /**
     * @dev Returns the total amount of tokens burned.
     * @return The latest value.
     */
    function totalBurned() external view returns (uint256);

    /**
     * @dev Informs other contracts which interfaces this contract supports.
     *      Required by https://eips.ethereum.org/EIPS/eip-165
     * @param interfaceId The interface id to check.
     * @return Whether the `interfaceId` is supported.
     */
    function supportsInterface(bytes4 interfaceId)
        external
        view
        override(IERC721AUpgradeable, IERC165Upgradeable)
        returns (bool);
}

File 5 of 17 : ISAM.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import { IERC165 } from "openzeppelin/utils/introspection/IERC165.sol";

/**
 * @dev Data unique to a Sound Automated Market (i.e. bonding curve mint).
 */
struct SAMInfo {
    uint96 basePrice;
    uint128 linearPriceSlope;
    uint128 inflectionPrice;
    uint32 inflectionPoint;
    uint128 goldenEggFeesAccrued;
    uint128 balance;
    uint32 supply;
    uint32 maxSupply;
    uint32 buyFreezeTime;
    uint16 artistFeeBPS;
    uint16 affiliateFeeBPS;
    uint16 goldenEggFeeBPS;
    bytes32 affiliateMerkleRoot;
}

/**
 * @title ISAM
 * @dev Interface for the Sound Automated Market module.
 * @author Sound.xyz
 */
interface ISAM is IERC165 {
    // =============================================================
    //                            STRUCTS
    // =============================================================

    struct SAMData {
        // The sigmoid inflection price of the bonding curve.
        uint128 inflectionPrice;
        // The price added to the bonding curve price.
        uint96 basePrice;
        // The sigmoid inflection point of the bonding curve.
        uint32 inflectionPoint;
        // The amount of fees accrued by the golden egg.
        uint112 goldenEggFeesAccrued;
        // The balance of the pool for the edition.
        // 112 bits is enough to represent 5,192,296,858,534,828 ETH.
        // At the point of writing, there are 120,479,006 ETH in Ethereum mainnet,
        // and 9,050,469,069 MATIC in Polygon PoS chain.
        uint112 balance;
        // The amount of tokens in the bonding curve.
        uint32 supply;
        // The slope for the additional linear component to the bonding curve price.
        uint128 linearPriceSlope;
        // The supply cap for buying tokens.
        // Note: The supply can go over the cap if the cap is manually decreased.
        uint32 maxSupply;
        // The cutoff time for buying tokens.
        uint32 buyFreezeTime;
        // The fee BPS (basis points) to pay the artist.
        uint16 artistFeeBPS;
        // The fee BPS (basis points) to pay affiliates.
        uint16 affiliateFeeBPS;
        // The fee BPS (basis points) to pay the golden egg holder.
        uint16 goldenEggFeeBPS;
        // Whether a token has already been minted on the bonding curve.
        bool hasMinted;
        // Whether the SAM has been created.
        bool created;
        // The affiliate Merkle root, if any.
        bytes32 affiliateMerkleRoot;
    }

    // =============================================================
    //                            EVENTS
    // =============================================================

    /**
     * @dev Emitted when a bonding curve is created.
     * @param edition          The edition address.
     * @param linearPriceSlope The linear price slope of the bonding curve.
     * @param inflectionPrice  The sigmoid inflection price of the bonding curve.
     * @param inflectionPoint  The sigmoid inflection point of the bonding curve.
     * @param maxSupply        The supply cap for buying tokens.
     * @param buyFreezeTime    The cutoff time for buying tokens.
     * @param artistFeeBPS     The fee BPS (basis points) to pay the artist.
     * @param goldenEggFeeBPS  The fee BPS (basis points) to pay the golden egg holder.
     * @param affiliateFeeBPS  The fee BPS (basis points) to pay affiliates.
     */
    event Created(
        address indexed edition,
        uint96 basePrice,
        uint128 linearPriceSlope,
        uint128 inflectionPrice,
        uint32 inflectionPoint,
        uint32 maxSupply,
        uint32 buyFreezeTime,
        uint16 artistFeeBPS,
        uint16 goldenEggFeeBPS,
        uint16 affiliateFeeBPS
    );

    /**
     * @dev Emitted when tokens are bought from the bonding curve.
     * @param edition         The edition address.
     * @param buyer           Address of the buyer.
     * @param fromTokenId     The starting token ID minted for the batch.
     * @param fromCurveSupply The start of the curve supply for the batch.
     * @param quantity        The number of tokens bought.
     * @param totalPayment    The total amount of ETH paid.
     * @param platformFee     The cut paid to the platform.
     * @param artistFee       The cut paid to the artist.
     * @param goldenEggFee    The cut paid to the golden egg.
     * @param affiliateFee    The cut paid to the affiliate.
     * @param affiliate       The affiliate's address.
     * @param affiliated      Whether the affiliate is affiliated.
     * @param attributionId   The attribution ID.
     */
    event Bought(
        address indexed edition,
        address indexed buyer,
        uint256 fromTokenId,
        uint32 fromCurveSupply,
        uint32 quantity,
        uint128 totalPayment,
        uint128 platformFee,
        uint128 artistFee,
        uint128 goldenEggFee,
        uint128 affiliateFee,
        address affiliate,
        bool affiliated,
        uint256 indexed attributionId
    );

    /**
     * @dev Emitted when tokens are sold into the bonding curve.
     * @param edition         The edition address.
     * @param seller          Address of the seller.
     * @param fromCurveSupply The start of the curve supply for the batch.
     * @param tokenIds        The token IDs burned.
     * @param totalPayout     The total amount of ETH paid out.
     * @param attributionId   The attribution ID.
     */
    event Sold(
        address indexed edition,
        address indexed seller,
        uint32 fromCurveSupply,
        uint256[] tokenIds,
        uint128 totalPayout,
        uint256 indexed attributionId
    );

    /**
     * @dev Emitted when the `basePrice` is updated.
     * @param edition   The edition address.
     * @param basePrice The price added to the bonding curve price.
     */
    event BasePriceSet(address indexed edition, uint96 basePrice);

    /**
     * @dev Emitted when the `linearPriceSlope` is updated.
     * @param edition          The edition address.
     * @param linearPriceSlope The linear price slope of the bonding curve.
     */
    event LinearPriceSlopeSet(address indexed edition, uint128 linearPriceSlope);

    /**
     * @dev Emitted when the `inflectionPrice` is updated.
     * @param edition         The edition address.
     * @param inflectionPrice The sigmoid inflection price of the bonding curve.
     */
    event InflectionPriceSet(address indexed edition, uint128 inflectionPrice);

    /**
     * @dev Emitted when the `inflectionPoint` is updated.
     * @param edition         The edition address.
     * @param inflectionPoint The sigmoid inflection point of the bonding curve.
     */
    event InflectionPointSet(address indexed edition, uint32 inflectionPoint);

    /**
     * @dev Emitted when the `artistFeeBPS` is updated.
     * @param edition The edition address.
     * @param bps     The affiliate fee basis points.
     */
    event ArtistFeeSet(address indexed edition, uint16 bps);

    /**
     * @dev Emitted when the `affiliateFeeBPS` is updated.
     * @param edition The edition address.
     * @param bps     The affiliate fee basis points.
     */
    event AffiliateFeeSet(address indexed edition, uint16 bps);

    /**
     * @dev Emitted when the Merkle root for an affiliate allow list is updated.
     * @param edition The edition address.
     * @param root    The Merkle root for the affiliate allow list.
     */
    event AffiliateMerkleRootSet(address indexed edition, bytes32 root);

    /**
     * @dev Emitted when the `goldenEggFeeBPS` is updated.
     * @param edition The edition address.
     * @param bps     The golden egg fee basis points.
     */
    event GoldenEggFeeSet(address indexed edition, uint16 bps);

    /**
     * @dev Emitted when the `maxSupply` updated.
     * @param edition The edition address.
     */
    event MaxSupplySet(address indexed edition, uint32 maxSupply);

    /**
     * @dev Emitted when the `buyFreezeTime` updated.
     * @param edition The edition address.
     */
    event BuyFreezeTimeSet(address indexed edition, uint32 buyFreezeTime);

    /**
     * @dev Emitted when the `platformFeeBPS` is updated.
     * @param bps The platform fee basis points.
     */
    event PlatformFeeSet(uint16 bps);

    /**
     * @dev Emitted when the `platformFeeAddress` is updated.
     * @param addr The platform fee address.
     */
    event PlatformFeeAddressSet(address addr);

    /**
     * @dev Emitted when the accrued fees for `affiliate` are withdrawn.
     * @param affiliate The affiliate address.
     * @param accrued   The amount of fees withdrawn.
     */
    event AffiliateFeesWithdrawn(address indexed affiliate, uint256 accrued);

    /**
     * @dev Emitted when the accrued fees for the golden egg of `edition` are withdrawn.
     * @param edition    The edition address.
     * @param receipient The receipient.
     * @param accrued    The amount of fees withdrawn.
     */
    event GoldenEggFeesWithdrawn(address indexed edition, address indexed receipient, uint128 accrued);

    /**
     * @dev Emitted when the accrued fees for the platform are withdrawn.
     * @param accrued The amount of fees withdrawn.
     */
    event PlatformFeesWithdrawn(uint128 accrued);

    /**
     * @dev Emitted when the approved factories are set.
     * @param factories The list of approved factories.
     */
    event ApprovedEditionFactoriesSet(address[] factories);

    // =============================================================
    //                            ERRORS
    // =============================================================

    /**
     * @dev The Ether value paid is below the value required.
     * @param paid     The amount sent to the contract.
     * @param required The amount required.
     */
    error Underpaid(uint256 paid, uint256 required);

    /**
     * @dev The Ether value paid out is below the value required.
     * @param payout   The amount to pau out..
     * @param required The amount required.
     */
    error InsufficientPayout(uint256 payout, uint256 required);

    /**
     * @dev There is not enough tokens in the Sound Automated Market for selling back.
     * @param available The number of tokens in the Sound Automated Market.
     * @param required  The amount of tokens required.
     */
    error InsufficientSupply(uint256 available, uint256 required);

    /**
     * @dev Cannot perform the operation during the SAM phase.
     */
    error InSAMPhase();

    /**
     * @dev The inflection price cannot be zero.
     */
    error InflectionPriceIsZero();

    /**
     * @dev The inflection point cannot be zero.
     */
    error InflectionPointIsZero();

    /**
     * @dev The max supply cannot be increased after the SAM has started.
     *      In the `create` function, the initial max supply cannot be zero.
     */
    error InvalidMaxSupply();

    /**
     * @dev The buy freeze time cannot be increased after the SAM has started.
     *      In the `create` function, the initial buy freeze time cannot be zero.
     */
    error InvalidBuyFreezeTime();

    /**
     * @dev The BPS for the fee cannot exceed the `MAX_PLATFORM_FEE_BPS`.
     */
    error InvalidPlatformFeeBPS();

    /**
     * @dev The BPS for the fee cannot exceed the `MAX_ARTIST_FEE_BPS`.
     */
    error InvalidArtistFeeBPS();

    /**
     * @dev The BPS for the fee cannot exceed the `MAX_AFFILAITE_FEE_BPS`.
     */
    error InvalidAffiliateFeeBPS();

    /**
     * @dev The BPS for the fee cannot exceed the `MAX_GOLDEN_EGG_FEE_BPS`.
     */
    error InvalidGoldenEggFeeBPS();

    /**
     * @dev The `affiliate` provided is invalid for the given `affiliateProof`.
     */
    error InvalidAffiliate();

    /**
     * @dev Cannot buy.
     */
    error BuyIsFrozen();

    /**
     * @dev The purchase cannot exceed the max supply.
     * @param available The number of tokens remaining available for mint.
     */
    error ExceedsMaxSupply(uint32 available);

    /**
     * @dev The platform fee address cannot be zero.
     */
    error PlatformFeeAddressIsZero();

    /**
     * @dev There already is a Sound Automated Market for `edition`.
     */
    error SAMAlreadyExists();

    /**
     * @dev There is no Sound Automated Market for `edition`.
     */
    error SAMDoesNotExist();

    /**
     * @dev Cannot mint zero tokens.
     */
    error MintZeroQuantity();

    /**
     * @dev Cannot burn zero tokens.
     */
    error BurnZeroQuantity();

    /**
     * @dev The bytecode hash of the edition is not approved.
     */
    error UnapprovedEdition();

    // =============================================================
    //               PUBLIC / EXTERNAL WRITE FUNCTIONS
    // =============================================================

    /**
     * @dev Creates a Sound Automated Market on `edition`.
     * @param edition          The edition address.
     * @param basePrice        The price added to the bonding curve price.
     * @param linearPriceSlope The linear price slope of the bonding curve.
     * @param inflectionPrice  The sigmoid inflection price of the bonding curve.
     * @param inflectionPoint  The sigmoid inflection point of the bonding curve.
     * @param maxSupply        The supply cap for buying tokens.
     * @param buyFreezeTime    The cutoff time for buying tokens.
     * @param artistFeeBPS     The fee BPS (basis points) to pay the artist.
     * @param goldenEggFeeBPS  The fee BPS (basis points) to pay the golden egg holder.
     * @param affiliateFeeBPS  The fee BPS (basis points) to pay affiliates.
     * @param editionBy        The address which created the edition via the factory.
     * @param editionSalt      The salt used to create the edition via the factory.
     */
    function create(
        address edition,
        uint96 basePrice,
        uint128 linearPriceSlope,
        uint128 inflectionPrice,
        uint32 inflectionPoint,
        uint32 maxSupply,
        uint32 buyFreezeTime,
        uint16 artistFeeBPS,
        uint16 goldenEggFeeBPS,
        uint16 affiliateFeeBPS,
        address editionBy,
        bytes32 editionSalt
    ) external;

    /**
     * @dev Mints (buys) tokens for a given edition.
     * @param edition        The edition address.
     * @param to             The address to mint to.
     * @param quantity       Token quantity to mint in song `edition`.
     * @param affiliate      The affiliate address.
     * @param affiliateProof The Merkle proof needed for verifying the affiliate, if any.
     * @param attributionId  The attribution ID.
     */
    function buy(
        address edition,
        address to,
        uint32 quantity,
        address affiliate,
        bytes32[] calldata affiliateProof,
        uint256 attributionId
    ) external payable;

    /**
     * @dev Burns (sell) tokens for a given edition.
     * @param edition       The edition address.
     * @param tokenIds      The token IDs to burn.
     * @param minimumPayout The minimum payout for the transaction to succeed.
     * @param payoutTo      The address to send the payout to.
     * @param attributionId The attribution ID.
     */
    function sell(
        address edition,
        uint256[] calldata tokenIds,
        uint256 minimumPayout,
        address payoutTo,
        uint256 attributionId
    ) external;

    /**
     * @dev Sets the base price for `edition`.
     * This will be added to the bonding curve price.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition   The edition address.
     * @param basePrice The price added to the bonding curve price.
     */
    function setBasePrice(address edition, uint96 basePrice) external;

    /**
     * @dev Sets the linear price slope for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition          The edition address.
     * @param linearPriceSlope The linear price slope of the bonding curve.
     */
    function setLinearPriceSlope(address edition, uint128 linearPriceSlope) external;

    /**
     * @dev Sets the bonding curve inflection price for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition         The edition address.
     * @param inflectionPrice The sigmoid inflection price of the bonding curve.
     */
    function setInflectionPrice(address edition, uint128 inflectionPrice) external;

    /**
     * @dev Sets the bonding curve inflection point for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition         The edition address.
     * @param inflectionPoint The sigmoid inflection point of the bonding curve.
     */
    function setInflectionPoint(address edition, uint32 inflectionPoint) external;

    /**
     * @dev Sets the artist fee for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     * @param bps     The artist fee in basis points.
     */
    function setArtistFee(address edition, uint16 bps) external;

    /**
     * @dev Sets the affiliate fee for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     * @param bps     The affiliate fee in basis points.
     */
    function setAffiliateFee(address edition, uint16 bps) external;

    /**
     * @dev Sets the affiliate Merkle root for (`edition`, `mintId`).
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     * @param root    The affiliate Merkle root, if any.
     */
    function setAffiliateMerkleRoot(address edition, bytes32 root) external;

    /**
     * @dev Sets the golden egg fee for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     * @param bps     The golden egg fee in basis points.
     */
    function setGoldenEggFee(address edition, uint16 bps) external;

    /**
     * @dev Sets the supply cap for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     */
    function setMaxSupply(address edition, uint32 maxSupply) external;

    /**
     * @dev Sets the buy freeze time for `edition`.
     *
     * Calling conditions:
     * - The caller must be the edition's owner or admin.
     *
     * @param edition The edition address.
     */
    function setBuyFreezeTime(address edition, uint32 buyFreezeTime) external;

    /**
     * @dev Withdraws all the accrued fees for `affiliate`.
     * @param affiliate The affiliate address.
     */
    function withdrawForAffiliate(address affiliate) external;

    /**
     * @dev Withdraws all the accrued fees for the platform.
     */
    function withdrawForPlatform() external;

    /**
     * @dev Withdraws all the accrued fees for the golden egg.
     * @param edition The edition address.
     */
    function withdrawForGoldenEgg(address edition) external;

    /**
     * @dev Sets the platform fee bps.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract.
     *
     * @param bps The platform fee in basis points.
     */
    function setPlatformFee(uint16 bps) external;

    /**
     * @dev Sets the platform fee address.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract.
     *
     * @param addr The platform fee address.
     */
    function setPlatformFeeAddress(address addr) external;

    /**
     * @dev Sets the list of approved edition factories.
     *
     * Calling conditions:
     * - The caller must be the owner of the contract.
     *
     * @param factories The list of approved edition factories.
     */
    function setApprovedEditionFactories(address[] calldata factories) external;

    // =============================================================
    //               PUBLIC / EXTERNAL VIEW FUNCTIONS
    // =============================================================

    /**
     * @dev This is the denominator, in basis points (BPS), for any of the fees.
     * @return The constant value.
     */
    function BPS_DENOMINATOR() external pure returns (uint16);

    /**
     * @dev The maximum basis points (BPS) limit allowed for the platform fees.
     * @return The constant value.
     */
    function MAX_PLATFORM_FEE_BPS() external pure returns (uint16);

    /**
     * @dev The maximum basis points (BPS) limit allowed for the artist fees.
     * @return The constant value.
     */
    function MAX_ARTIST_FEE_BPS() external pure returns (uint16);

    /**
     * @dev The maximum basis points (BPS) limit allowed for the affiliate fees.
     * @return The constant value.
     */
    function MAX_AFFILIATE_FEE_BPS() external pure returns (uint16);

    /**
     * @dev The maximum basis points (BPS) limit allowed for the golden egg fees.
     * @return The constant value.
     */
    function MAX_GOLDEN_EGG_FEE_BPS() external pure returns (uint16);

    /**
     * @dev Returns the platform fee basis points.
     * @return The configured value.
     */
    function platformFeeBPS() external returns (uint16);

    /**
     * @dev Returns the platform fee address.
     * @return The configured value.
     */
    function platformFeeAddress() external returns (address);

    /**
     * @dev Returns the information for the Sound Automated Market for `edition`.
     * @param edition The edition address.
     * @return The latest value.
     */
    function samInfo(address edition) external view returns (SAMInfo memory);

    /**
     * @dev Returns the total value under the bonding curve for `quantity`, from `fromSupply`.
     * @param edition    The edition address.
     * @param fromSupply The starting number of tokens in the bonding curve.
     * @param quantity   The number of tokens.
     * @return The computed value.
     */
    function totalValue(
        address edition,
        uint32 fromSupply,
        uint32 quantity
    ) external view returns (uint256);

    /**
     * @dev Returns the total amount of ETH required to buy from
     *      `supply + supplyForwardOffset` to `supply + supplyForwardOffset + quantity`.
     * @param edition             The edition address.
     * @param supplyForwardOffset The offset added to the current supply.
     * @param quantity            The number of tokens.
     * @return total        The total amount required to be paid, inclusive of all the buy fees.
     * @return platformFee  The platform fee.
     * @return artistFee    The artist fee.
     * @return goldenEggFee The golden egg fee.
     * @return affiliateFee The affiliate fee.
     */
    function totalBuyPriceAndFees(
        address edition,
        uint32 supplyForwardOffset,
        uint32 quantity
    )
        external
        view
        returns (
            uint256 total,
            uint256 platformFee,
            uint256 artistFee,
            uint256 goldenEggFee,
            uint256 affiliateFee
        );

    /**
     * @dev Returns the total amount of ETH required to sell from
     *      `supply - supplyBackwardOffset` to `supply - supplyBackwardOffset - quantity`.
     * @param edition              The edition address.
     * @param supplyBackwardOffset The offset added to the current supply.
     * @param quantity             The number of tokens.
     * @return The computed value.
     */
    function totalSellPrice(
        address edition,
        uint32 supplyBackwardOffset,
        uint32 quantity
    ) external view returns (uint256);

    /**
     * @dev The total fees accrued for the golden egg on `edition`.
     * @param edition The edition address.
     * @return The latest value.
     */
    function goldenEggFeesAccrued(address edition) external view returns (uint128);

    /**
     * @dev The receipient of the golden egg fees on `edition`.
     *      If there is no golden egg winner, the `receipient` will be the `edition`.
     * @param edition The edition address.
     * @return receipient The latest value.
     */
    function goldenEggFeeRecipient(address edition) external view returns (address receipient);

    /**
     * @dev The total fees accrued for `affiliate`.
     * @param affiliate The affiliate's address.
     * @return The latest value.
     */
    function affiliateFeesAccrued(address affiliate) external view returns (uint128);

    /**
     * @dev The total fees accrued for the platform.
     * @return The latest value.
     */
    function platformFeesAccrued() external view returns (uint128);

    /**
     * @dev Whether `affiliate` is affiliated for `edition`.
     * @param edition        The edition's address.
     * @param affiliate      The affiliate's address.
     * @param affiliateProof The Merkle proof needed for verifying the affiliate, if any.
     * @return The computed value.
     */
    function isAffiliatedWithProof(
        address edition,
        address affiliate,
        bytes32[] calldata affiliateProof
    ) external view returns (bool);

    /**
     * @dev Whether `affiliate` is affiliated for `edition`.
     * @param edition   The edition's address.
     * @param affiliate The affiliate's address.
     * @return The computed value.
     */
    function isAffiliated(address edition, address affiliate) external view returns (bool);

    /**
     * @dev Returns the list of approved edition factories.
     * @return The latest values.
     */
    function approvedEditionFactories() external view returns (address[] memory);

    /**
     * @dev Returns the affiliate Merkle root.
     * @param edition The edition's address.
     * @return The latest value.
     */
    function affiliateMerkleRoot(address edition) external view returns (bytes32);

    /**
     * @dev Returns the module's interface ID.
     * @return The constant value.
     */
    function moduleInterfaceId() external pure returns (bytes4);
}

File 6 of 17 : BondingCurveLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "solady/utils/FixedPointMathLib.sol";

library BondingCurveLib {
    function sigmoid2Sum(
        uint32 inflectionPoint,
        uint128 inflectionPrice,
        uint32 fromSupply,
        uint32 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 = ((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(
        uint128 linearPriceSlope,
        uint32 fromSupply,
        uint32 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);
        }
    }
}

File 7 of 17 : IERC721AUpgradeable.sol
// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

/**
 * @dev Interface of ERC721A.
 */
interface IERC721AUpgradeable {
    /**
     * The caller must own the token or be an approved operator.
     */
    error ApprovalCallerNotOwnerNorApproved();

    /**
     * The token does not exist.
     */
    error ApprovalQueryForNonexistentToken();

    /**
     * Cannot query the balance for the zero address.
     */
    error BalanceQueryForZeroAddress();

    /**
     * Cannot mint to the zero address.
     */
    error MintToZeroAddress();

    /**
     * The quantity of tokens minted must be more than zero.
     */
    error MintZeroQuantity();

    /**
     * The token does not exist.
     */
    error OwnerQueryForNonexistentToken();

    /**
     * The caller must own the token or be an approved operator.
     */
    error TransferCallerNotOwnerNorApproved();

    /**
     * The token must be owned by `from`.
     */
    error TransferFromIncorrectOwner();

    /**
     * Cannot safely transfer to a contract that does not implement the
     * ERC721Receiver interface.
     */
    error TransferToNonERC721ReceiverImplementer();

    /**
     * Cannot transfer to the zero address.
     */
    error TransferToZeroAddress();

    /**
     * The token does not exist.
     */
    error URIQueryForNonexistentToken();

    /**
     * The `quantity` minted with ERC2309 exceeds the safety limit.
     */
    error MintERC2309QuantityExceedsLimit();

    /**
     * The `extraData` cannot be set on an unintialized ownership slot.
     */
    error OwnershipNotInitializedForExtraData();

    // =============================================================
    //                            STRUCTS
    // =============================================================

    struct TokenOwnership {
        // The address of the owner.
        address addr;
        // Stores the start time of ownership with minimal overhead for tokenomics.
        uint64 startTimestamp;
        // Whether the token has been burned.
        bool burned;
        // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
        uint24 extraData;
    }

    // =============================================================
    //                         TOKEN COUNTERS
    // =============================================================

    /**
     * @dev Returns the total number of tokens in existence.
     * Burned tokens will reduce the count.
     * To get the total number of tokens minted, please see {_totalMinted}.
     */
    function totalSupply() external view returns (uint256);

    // =============================================================
    //                            IERC165
    // =============================================================

    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);

    // =============================================================
    //                            IERC721
    // =============================================================

    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

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

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

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

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

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

    /**
     * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom}
     * whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

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

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

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

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

    // =============================================================
    //                        IERC721Metadata
    // =============================================================

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

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);

    // =============================================================
    //                           IERC2309
    // =============================================================

    /**
     * @dev Emitted when tokens in `fromTokenId` to `toTokenId`
     * (inclusive) is transferred from `from` to `to`, as defined in the
     * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
     *
     * See {_mintERC2309} for more details.
     */
    event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}

File 8 of 17 : LibMulticaller.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/**
 * @title LibMulticaller
 * @author vectorized.eth
 * @notice Library to read the `msg.sender` of the multicaller with sender contract.
 */
library LibMulticaller {
    /**
     * @dev The address of the multicaller contract.
     */
    address internal constant MULTICALLER = 0x000000000088228fCF7b8af41Faf3955bD0B3A41;

    /**
     * @dev The address of the multicaller with sender contract.
     */
    address internal constant MULTICALLER_WITH_SENDER = 0x00000000002Fd5Aeb385D324B580FCa7c83823A0;

    /**
     * @dev Returns the caller of `aggregateWithSender` on `MULTICALLER_WITH_SENDER`.
     */
    function multicallerSender() internal view returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(
                staticcall(
                    gas(), // Remaining gas.
                    MULTICALLER_WITH_SENDER, // The multicaller.
                    0x00, // Start of calldata in memory.
                    0x00, // Length of calldata.
                    0x00, // Start of returndata in memory.
                    0x20 // Length of returndata.
                )
            ) { revert(0, 0) } // For better gas estimation.

            result := mul(mload(0x00), eq(returndatasize(), 0x20))
        }
    }

    /**
     * @dev Returns the caller of `aggregateWithSender` on `MULTICALLER_WITH_SENDER`,
     *      if the current context's `msg.sender` is `MULTICALLER_WITH_SENDER`.
     *      Otherwise, returns `msg.sender`.
     */
    function sender() internal view returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := caller()
            if eq(result, MULTICALLER_WITH_SENDER) {
                if iszero(
                    staticcall(
                        gas(), // Remaining gas.
                        MULTICALLER_WITH_SENDER, // The multicaller with sender.
                        0x00, // Start of calldata in memory.
                        0x00, // Length of calldata.
                        0x00, // Start of returndata in memory.
                        0x20 // Length of returndata.
                    )
                ) { revert(0, 0) } // For better gas estimation.

                result := mul(mload(0x00), eq(returndatasize(), 0x20))
            }
        }
    }
}

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 10 of 17 : IERC2981Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Interface for the NFT Royalty Standard.
 *
 * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
 * support for royalty payments across all NFT marketplaces and ecosystem participants.
 *
 * _Available since v4.5._
 */
interface IERC2981Upgradeable is IERC165Upgradeable {
    /**
     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice)
        external
        view
        returns (address receiver, uint256 royaltyAmount);
}

File 11 of 17 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165Upgradeable {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 12 of 17 : Ownable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
/// @dev While the ownable portion follows [EIP-173](https://eips.ethereum.org/EIPS/eip-173)
/// for compatibility, the nomenclature for the 2-step ownership handover
/// may be unique to this codebase.
abstract contract Ownable {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The caller is not authorized to call the function.
    error Unauthorized();

    /// @dev The `newOwner` cannot be the zero address.
    error NewOwnerIsZeroAddress();

    /// @dev The `pendingOwner` does not have a valid handover request.
    error NoHandoverRequest();

    /// @dev `bytes4(keccak256(bytes("Unauthorized()")))`.
    uint256 private constant _UNAUTHORIZED_ERROR_SELECTOR = 0x82b42900;

    /// @dev `bytes4(keccak256(bytes("NewOwnerIsZeroAddress()")))`.
    uint256 private constant _NEW_OWNER_IS_ZERO_ADDRESS_ERROR_SELECTOR = 0x7448fbae;

    /// @dev `bytes4(keccak256(bytes("NoHandoverRequest()")))`.
    uint256 private constant _NO_HANDOVER_REQUEST_ERROR_SELECTOR = 0x6f5e8818;

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

    /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
    /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
    /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
    /// despite it not being as lightweight as a single argument event.
    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

    /// @dev An ownership handover to `pendingOwner` has been requested.
    event OwnershipHandoverRequested(address indexed pendingOwner);

    /// @dev The ownership handover to `pendingOwner` has been canceled.
    event OwnershipHandoverCanceled(address indexed pendingOwner);

    /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
    uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
        0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;

    /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
        0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;

    /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
        0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;

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

    /// @dev The owner slot is given by: `not(_OWNER_SLOT_NOT)`.
    /// It is intentionally choosen to be a high value
    /// to avoid collision with lower slots.
    /// The choice of manual storage layout is to enable compatibility
    /// with both regular and upgradeable contracts.
    uint256 private constant _OWNER_SLOT_NOT = 0x8b78c6d8;

    /// The ownership handover slot of `newOwner` is given by:
    /// ```
    ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
    ///     let handoverSlot := keccak256(0x00, 0x20)
    /// ```
    /// It stores the expiry timestamp of the two-step ownership handover.
    uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     INTERNAL FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Initializes the owner directly without authorization guard.
    /// This function must be called upon initialization,
    /// regardless of whether the contract is upgradeable or not.
    /// This is to enable generalization to both regular and upgradeable contracts,
    /// and to save gas in case the initial owner is not the caller.
    /// For performance reasons, this function will not check if there
    /// is an existing owner.
    function _initializeOwner(address newOwner) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Clean the upper 96 bits.
            newOwner := shr(96, shl(96, newOwner))
            // Store the new value.
            sstore(not(_OWNER_SLOT_NOT), newOwner)
            // Emit the {OwnershipTransferred} event.
            log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
        }
    }

    /// @dev Sets the owner directly without authorization guard.
    function _setOwner(address newOwner) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            let ownerSlot := not(_OWNER_SLOT_NOT)
            // Clean the upper 96 bits.
            newOwner := shr(96, shl(96, newOwner))
            // Emit the {OwnershipTransferred} event.
            log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
            // Store the new value.
            sstore(ownerSlot, newOwner)
        }
    }

    /// @dev Throws if the sender is not the owner.
    function _checkOwner() internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // If the caller is not the stored owner, revert.
            if iszero(eq(caller(), sload(not(_OWNER_SLOT_NOT)))) {
                mstore(0x00, _UNAUTHORIZED_ERROR_SELECTOR)
                revert(0x1c, 0x04)
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  PUBLIC UPDATE FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Allows the owner to transfer the ownership to `newOwner`.
    function transferOwnership(address newOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(shl(96, newOwner)) {
                mstore(0x00, _NEW_OWNER_IS_ZERO_ADDRESS_ERROR_SELECTOR)
                revert(0x1c, 0x04)
            }
        }
        _setOwner(newOwner);
    }

    /// @dev Allows the owner to renounce their ownership.
    function renounceOwnership() public payable virtual onlyOwner {
        _setOwner(address(0));
    }

    /// @dev Request a two-step ownership handover to the caller.
    /// The request will be automatically expire in 48 hours (172800 seconds) by default.
    function requestOwnershipHandover() public payable virtual {
        unchecked {
            uint256 expires = block.timestamp + ownershipHandoverValidFor();
            /// @solidity memory-safe-assembly
            assembly {
                // Compute and set the handover slot to `expires`.
                mstore(0x0c, _HANDOVER_SLOT_SEED)
                mstore(0x00, caller())
                sstore(keccak256(0x0c, 0x20), expires)
                // Emit the {OwnershipHandoverRequested} event.
                log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
            }
        }
    }

    /// @dev Cancels the two-step ownership handover to the caller, if any.
    function cancelOwnershipHandover() public payable virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, caller())
            sstore(keccak256(0x0c, 0x20), 0)
            // Emit the {OwnershipHandoverCanceled} event.
            log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
        }
    }

    /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
    /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
    function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            let handoverSlot := keccak256(0x0c, 0x20)
            // If the handover does not exist, or has expired.
            if gt(timestamp(), sload(handoverSlot)) {
                mstore(0x00, _NO_HANDOVER_REQUEST_ERROR_SELECTOR)
                revert(0x1c, 0x04)
            }
            // Set the handover slot to 0.
            sstore(handoverSlot, 0)
        }
        _setOwner(pendingOwner);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   PUBLIC READ FUNCTIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the owner of the contract.
    function owner() public view virtual returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := sload(not(_OWNER_SLOT_NOT))
        }
    }

    /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
    function ownershipHandoverExpiresAt(address pendingOwner)
        public
        view
        virtual
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the handover slot.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            // Load the handover slot.
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /// @dev Returns how long a two-step ownership handover is valid for in seconds.
    function ownershipHandoverValidFor() public view virtual returns (uint64) {
        return 48 * 3600;
    }

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

    /// @dev Marks a function as only callable by the owner.
    modifier onlyOwner() virtual {
        _checkOwner();
        _;
    }
}

File 13 of 17 : OwnableRoles.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "./Ownable.sol";

/// @notice Simple single owner and multiroles authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
/// @dev While the ownable portion follows [EIP-173](https://eips.ethereum.org/EIPS/eip-173)
/// for compatibility, the nomenclature for the 2-step ownership handover and roles
/// may be unique to this codebase.
abstract contract OwnableRoles is Ownable {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev `bytes4(keccak256(bytes("Unauthorized()")))`.
    uint256 private constant _UNAUTHORIZED_ERROR_SELECTOR = 0x82b42900;

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

    /// @dev The `user`'s roles is updated to `roles`.
    /// Each bit of `roles` represents whether the role is set.
    event RolesUpdated(address indexed user, uint256 indexed roles);

    /// @dev `keccak256(bytes("RolesUpdated(address,uint256)"))`.
    uint256 private constant _ROLES_UPDATED_EVENT_SIGNATURE =
        0x715ad5ce61fc9595c7b415289d59cf203f23a94fa06f04af7e489a0a76e1fe26;

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

    /// @dev The role slot of `user` is given by:
    /// ```
    ///     mstore(0x00, or(shl(96, user), _ROLE_SLOT_SEED))
    ///     let roleSlot := keccak256(0x00, 0x20)
    /// ```
    /// This automatically ignores the upper bits of the `user` in case
    /// they are not clean, as well as keep the `keccak256` under 32-bytes.
    ///
    /// Note: This is equal to `_OWNER_SLOT_NOT` in for gas efficiency.
    uint256 private constant _ROLE_SLOT_SEED = 0x8b78c6d8;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     INTERNAL FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Grants the roles directly without authorization guard.
    /// Each bit of `roles` represents the role to turn on.
    function _grantRoles(address user, uint256 roles) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, user)
            let roleSlot := keccak256(0x0c, 0x20)
            // Load the current value and `or` it with `roles`.
            roles := or(sload(roleSlot), roles)
            // Store the new value.
            sstore(roleSlot, roles)
            // Emit the {RolesUpdated} event.
            log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), roles)
        }
    }

    /// @dev Removes the roles directly without authorization guard.
    /// Each bit of `roles` represents the role to turn off.
    function _removeRoles(address user, uint256 roles) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, user)
            let roleSlot := keccak256(0x0c, 0x20)
            // Load the current value.
            let currentRoles := sload(roleSlot)
            // Use `and` to compute the intersection of `currentRoles` and `roles`,
            // `xor` it with `currentRoles` to flip the bits in the intersection.
            roles := xor(currentRoles, and(currentRoles, roles))
            // Then, store the new value.
            sstore(roleSlot, roles)
            // Emit the {RolesUpdated} event.
            log3(0, 0, _ROLES_UPDATED_EVENT_SIGNATURE, shr(96, mload(0x0c)), roles)
        }
    }

    /// @dev Throws if the sender does not have any of the `roles`.
    function _checkRoles(uint256 roles) internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, caller())
            // Load the stored value, and if the `and` intersection
            // of the value and `roles` is zero, revert.
            if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) {
                mstore(0x00, _UNAUTHORIZED_ERROR_SELECTOR)
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Throws if the sender is not the owner,
    /// and does not have any of the `roles`.
    /// Checks for ownership first, then lazily checks for roles.
    function _checkOwnerOrRoles(uint256 roles) internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // If the caller is not the stored owner.
            // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`.
            if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) {
                // Compute the role slot.
                mstore(0x0c, _ROLE_SLOT_SEED)
                mstore(0x00, caller())
                // Load the stored value, and if the `and` intersection
                // of the value and `roles` is zero, revert.
                if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) {
                    mstore(0x00, _UNAUTHORIZED_ERROR_SELECTOR)
                    revert(0x1c, 0x04)
                }
            }
        }
    }

    /// @dev Throws if the sender does not have any of the `roles`,
    /// and is not the owner.
    /// Checks for roles first, then lazily checks for ownership.
    function _checkRolesOrOwner(uint256 roles) internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, caller())
            // Load the stored value, and if the `and` intersection
            // of the value and `roles` is zero, revert.
            if iszero(and(sload(keccak256(0x0c, 0x20)), roles)) {
                // If the caller is not the stored owner.
                // Note: `_ROLE_SLOT_SEED` is equal to `_OWNER_SLOT_NOT`.
                if iszero(eq(caller(), sload(not(_ROLE_SLOT_SEED)))) {
                    mstore(0x00, _UNAUTHORIZED_ERROR_SELECTOR)
                    revert(0x1c, 0x04)
                }
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  PUBLIC UPDATE FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Allows the owner to grant `user` `roles`.
    /// If the `user` already has a role, then it will be an no-op for the role.
    function grantRoles(address user, uint256 roles) public payable virtual onlyOwner {
        _grantRoles(user, roles);
    }

    /// @dev Allows the owner to remove `user` `roles`.
    /// If the `user` does not have a role, then it will be an no-op for the role.
    function revokeRoles(address user, uint256 roles) public payable virtual onlyOwner {
        _removeRoles(user, roles);
    }

    /// @dev Allow the caller to remove their own roles.
    /// If the caller does not have a role, then it will be an no-op for the role.
    function renounceRoles(uint256 roles) public payable virtual {
        _removeRoles(msg.sender, roles);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   PUBLIC READ FUNCTIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns whether `user` has any of `roles`.
    function hasAnyRole(address user, uint256 roles) public view virtual returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, user)
            // Load the stored value, and set the result to whether the
            // `and` intersection of the value and `roles` is not zero.
            result := iszero(iszero(and(sload(keccak256(0x0c, 0x20)), roles)))
        }
    }

    /// @dev Returns whether `user` has all of `roles`.
    function hasAllRoles(address user, uint256 roles) public view virtual returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, user)
            // Whether the stored value is contains all the set bits in `roles`.
            result := eq(and(sload(keccak256(0x0c, 0x20)), roles), roles)
        }
    }

    /// @dev Returns the roles of `user`.
    function rolesOf(address user) public view virtual returns (uint256 roles) {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the role slot.
            mstore(0x0c, _ROLE_SLOT_SEED)
            mstore(0x00, user)
            // Load the stored value.
            roles := sload(keccak256(0x0c, 0x20))
        }
    }

    /// @dev Convenience function to return a `roles` bitmap from an array of `ordinals`.
    /// This is meant for frontends like Etherscan, and is therefore not fully optimized.
    /// Not recommended to be called on-chain.
    function rolesFromOrdinals(uint8[] memory ordinals) public pure returns (uint256 roles) {
        /// @solidity memory-safe-assembly
        assembly {
            for { let i := shl(5, mload(ordinals)) } i { i := sub(i, 0x20) } {
                // We don't need to mask the values of `ordinals`, as Solidity
                // cleans dirty upper bits when storing variables into memory.
                roles := or(shl(mload(add(ordinals, i)), 1), roles)
            }
        }
    }

    /// @dev Convenience function to return an array of `ordinals` from the `roles` bitmap.
    /// This is meant for frontends like Etherscan, and is therefore not fully optimized.
    /// Not recommended to be called on-chain.
    function ordinalsFromRoles(uint256 roles) public pure returns (uint8[] memory ordinals) {
        /// @solidity memory-safe-assembly
        assembly {
            // Grab the pointer to the free memory.
            ordinals := mload(0x40)
            let ptr := add(ordinals, 0x20)
            let o := 0
            // The absence of lookup tables, De Bruijn, etc., here is intentional for
            // smaller bytecode, as this function is not meant to be called on-chain.
            for { let t := roles } 1 {} {
                mstore(ptr, o)
                // `shr` 5 is equivalent to multiplying by 0x20.
                // Push back into the ordinals array if the bit is set.
                ptr := add(ptr, shl(5, and(t, 1)))
                o := add(o, 1)
                t := shr(o, roles)
                if iszero(t) { break }
            }
            // Store the length of `ordinals`.
            mstore(ordinals, shr(5, sub(ptr, add(ordinals, 0x20))))
            // Allocate the memory.
            mstore(0x40, ptr)
        }
    }

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

    /// @dev Marks a function as only callable by an account with `roles`.
    modifier onlyRoles(uint256 roles) virtual {
        _checkRoles(roles);
        _;
    }

    /// @dev Marks a function as only callable by the owner or by an account
    /// with `roles`. Checks for ownership first, then lazily checks for roles.
    modifier onlyOwnerOrRoles(uint256 roles) virtual {
        _checkOwnerOrRoles(roles);
        _;
    }

    /// @dev Marks a function as only callable by an account with `roles`
    /// or the owner. Checks for roles first, then lazily checks for ownership.
    modifier onlyRolesOrOwner(uint256 roles) virtual {
        _checkRolesOrOwner(roles);
        _;
    }

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

    // IYKYK

    uint256 internal constant _ROLE_0 = 1 << 0;
    uint256 internal constant _ROLE_1 = 1 << 1;
    uint256 internal constant _ROLE_2 = 1 << 2;
    uint256 internal constant _ROLE_3 = 1 << 3;
    uint256 internal constant _ROLE_4 = 1 << 4;
    uint256 internal constant _ROLE_5 = 1 << 5;
    uint256 internal constant _ROLE_6 = 1 << 6;
    uint256 internal constant _ROLE_7 = 1 << 7;
    uint256 internal constant _ROLE_8 = 1 << 8;
    uint256 internal constant _ROLE_9 = 1 << 9;
    uint256 internal constant _ROLE_10 = 1 << 10;
    uint256 internal constant _ROLE_11 = 1 << 11;
    uint256 internal constant _ROLE_12 = 1 << 12;
    uint256 internal constant _ROLE_13 = 1 << 13;
    uint256 internal constant _ROLE_14 = 1 << 14;
    uint256 internal constant _ROLE_15 = 1 << 15;
    uint256 internal constant _ROLE_16 = 1 << 16;
    uint256 internal constant _ROLE_17 = 1 << 17;
    uint256 internal constant _ROLE_18 = 1 << 18;
    uint256 internal constant _ROLE_19 = 1 << 19;
    uint256 internal constant _ROLE_20 = 1 << 20;
    uint256 internal constant _ROLE_21 = 1 << 21;
    uint256 internal constant _ROLE_22 = 1 << 22;
    uint256 internal constant _ROLE_23 = 1 << 23;
    uint256 internal constant _ROLE_24 = 1 << 24;
    uint256 internal constant _ROLE_25 = 1 << 25;
    uint256 internal constant _ROLE_26 = 1 << 26;
    uint256 internal constant _ROLE_27 = 1 << 27;
    uint256 internal constant _ROLE_28 = 1 << 28;
    uint256 internal constant _ROLE_29 = 1 << 29;
    uint256 internal constant _ROLE_30 = 1 << 30;
    uint256 internal constant _ROLE_31 = 1 << 31;
    uint256 internal constant _ROLE_32 = 1 << 32;
    uint256 internal constant _ROLE_33 = 1 << 33;
    uint256 internal constant _ROLE_34 = 1 << 34;
    uint256 internal constant _ROLE_35 = 1 << 35;
    uint256 internal constant _ROLE_36 = 1 << 36;
    uint256 internal constant _ROLE_37 = 1 << 37;
    uint256 internal constant _ROLE_38 = 1 << 38;
    uint256 internal constant _ROLE_39 = 1 << 39;
    uint256 internal constant _ROLE_40 = 1 << 40;
    uint256 internal constant _ROLE_41 = 1 << 41;
    uint256 internal constant _ROLE_42 = 1 << 42;
    uint256 internal constant _ROLE_43 = 1 << 43;
    uint256 internal constant _ROLE_44 = 1 << 44;
    uint256 internal constant _ROLE_45 = 1 << 45;
    uint256 internal constant _ROLE_46 = 1 << 46;
    uint256 internal constant _ROLE_47 = 1 << 47;
    uint256 internal constant _ROLE_48 = 1 << 48;
    uint256 internal constant _ROLE_49 = 1 << 49;
    uint256 internal constant _ROLE_50 = 1 << 50;
    uint256 internal constant _ROLE_51 = 1 << 51;
    uint256 internal constant _ROLE_52 = 1 << 52;
    uint256 internal constant _ROLE_53 = 1 << 53;
    uint256 internal constant _ROLE_54 = 1 << 54;
    uint256 internal constant _ROLE_55 = 1 << 55;
    uint256 internal constant _ROLE_56 = 1 << 56;
    uint256 internal constant _ROLE_57 = 1 << 57;
    uint256 internal constant _ROLE_58 = 1 << 58;
    uint256 internal constant _ROLE_59 = 1 << 59;
    uint256 internal constant _ROLE_60 = 1 << 60;
    uint256 internal constant _ROLE_61 = 1 << 61;
    uint256 internal constant _ROLE_62 = 1 << 62;
    uint256 internal constant _ROLE_63 = 1 << 63;
    uint256 internal constant _ROLE_64 = 1 << 64;
    uint256 internal constant _ROLE_65 = 1 << 65;
    uint256 internal constant _ROLE_66 = 1 << 66;
    uint256 internal constant _ROLE_67 = 1 << 67;
    uint256 internal constant _ROLE_68 = 1 << 68;
    uint256 internal constant _ROLE_69 = 1 << 69;
    uint256 internal constant _ROLE_70 = 1 << 70;
    uint256 internal constant _ROLE_71 = 1 << 71;
    uint256 internal constant _ROLE_72 = 1 << 72;
    uint256 internal constant _ROLE_73 = 1 << 73;
    uint256 internal constant _ROLE_74 = 1 << 74;
    uint256 internal constant _ROLE_75 = 1 << 75;
    uint256 internal constant _ROLE_76 = 1 << 76;
    uint256 internal constant _ROLE_77 = 1 << 77;
    uint256 internal constant _ROLE_78 = 1 << 78;
    uint256 internal constant _ROLE_79 = 1 << 79;
    uint256 internal constant _ROLE_80 = 1 << 80;
    uint256 internal constant _ROLE_81 = 1 << 81;
    uint256 internal constant _ROLE_82 = 1 << 82;
    uint256 internal constant _ROLE_83 = 1 << 83;
    uint256 internal constant _ROLE_84 = 1 << 84;
    uint256 internal constant _ROLE_85 = 1 << 85;
    uint256 internal constant _ROLE_86 = 1 << 86;
    uint256 internal constant _ROLE_87 = 1 << 87;
    uint256 internal constant _ROLE_88 = 1 << 88;
    uint256 internal constant _ROLE_89 = 1 << 89;
    uint256 internal constant _ROLE_90 = 1 << 90;
    uint256 internal constant _ROLE_91 = 1 << 91;
    uint256 internal constant _ROLE_92 = 1 << 92;
    uint256 internal constant _ROLE_93 = 1 << 93;
    uint256 internal constant _ROLE_94 = 1 << 94;
    uint256 internal constant _ROLE_95 = 1 << 95;
    uint256 internal constant _ROLE_96 = 1 << 96;
    uint256 internal constant _ROLE_97 = 1 << 97;
    uint256 internal constant _ROLE_98 = 1 << 98;
    uint256 internal constant _ROLE_99 = 1 << 99;
    uint256 internal constant _ROLE_100 = 1 << 100;
    uint256 internal constant _ROLE_101 = 1 << 101;
    uint256 internal constant _ROLE_102 = 1 << 102;
    uint256 internal constant _ROLE_103 = 1 << 103;
    uint256 internal constant _ROLE_104 = 1 << 104;
    uint256 internal constant _ROLE_105 = 1 << 105;
    uint256 internal constant _ROLE_106 = 1 << 106;
    uint256 internal constant _ROLE_107 = 1 << 107;
    uint256 internal constant _ROLE_108 = 1 << 108;
    uint256 internal constant _ROLE_109 = 1 << 109;
    uint256 internal constant _ROLE_110 = 1 << 110;
    uint256 internal constant _ROLE_111 = 1 << 111;
    uint256 internal constant _ROLE_112 = 1 << 112;
    uint256 internal constant _ROLE_113 = 1 << 113;
    uint256 internal constant _ROLE_114 = 1 << 114;
    uint256 internal constant _ROLE_115 = 1 << 115;
    uint256 internal constant _ROLE_116 = 1 << 116;
    uint256 internal constant _ROLE_117 = 1 << 117;
    uint256 internal constant _ROLE_118 = 1 << 118;
    uint256 internal constant _ROLE_119 = 1 << 119;
    uint256 internal constant _ROLE_120 = 1 << 120;
    uint256 internal constant _ROLE_121 = 1 << 121;
    uint256 internal constant _ROLE_122 = 1 << 122;
    uint256 internal constant _ROLE_123 = 1 << 123;
    uint256 internal constant _ROLE_124 = 1 << 124;
    uint256 internal constant _ROLE_125 = 1 << 125;
    uint256 internal constant _ROLE_126 = 1 << 126;
    uint256 internal constant _ROLE_127 = 1 << 127;
    uint256 internal constant _ROLE_128 = 1 << 128;
    uint256 internal constant _ROLE_129 = 1 << 129;
    uint256 internal constant _ROLE_130 = 1 << 130;
    uint256 internal constant _ROLE_131 = 1 << 131;
    uint256 internal constant _ROLE_132 = 1 << 132;
    uint256 internal constant _ROLE_133 = 1 << 133;
    uint256 internal constant _ROLE_134 = 1 << 134;
    uint256 internal constant _ROLE_135 = 1 << 135;
    uint256 internal constant _ROLE_136 = 1 << 136;
    uint256 internal constant _ROLE_137 = 1 << 137;
    uint256 internal constant _ROLE_138 = 1 << 138;
    uint256 internal constant _ROLE_139 = 1 << 139;
    uint256 internal constant _ROLE_140 = 1 << 140;
    uint256 internal constant _ROLE_141 = 1 << 141;
    uint256 internal constant _ROLE_142 = 1 << 142;
    uint256 internal constant _ROLE_143 = 1 << 143;
    uint256 internal constant _ROLE_144 = 1 << 144;
    uint256 internal constant _ROLE_145 = 1 << 145;
    uint256 internal constant _ROLE_146 = 1 << 146;
    uint256 internal constant _ROLE_147 = 1 << 147;
    uint256 internal constant _ROLE_148 = 1 << 148;
    uint256 internal constant _ROLE_149 = 1 << 149;
    uint256 internal constant _ROLE_150 = 1 << 150;
    uint256 internal constant _ROLE_151 = 1 << 151;
    uint256 internal constant _ROLE_152 = 1 << 152;
    uint256 internal constant _ROLE_153 = 1 << 153;
    uint256 internal constant _ROLE_154 = 1 << 154;
    uint256 internal constant _ROLE_155 = 1 << 155;
    uint256 internal constant _ROLE_156 = 1 << 156;
    uint256 internal constant _ROLE_157 = 1 << 157;
    uint256 internal constant _ROLE_158 = 1 << 158;
    uint256 internal constant _ROLE_159 = 1 << 159;
    uint256 internal constant _ROLE_160 = 1 << 160;
    uint256 internal constant _ROLE_161 = 1 << 161;
    uint256 internal constant _ROLE_162 = 1 << 162;
    uint256 internal constant _ROLE_163 = 1 << 163;
    uint256 internal constant _ROLE_164 = 1 << 164;
    uint256 internal constant _ROLE_165 = 1 << 165;
    uint256 internal constant _ROLE_166 = 1 << 166;
    uint256 internal constant _ROLE_167 = 1 << 167;
    uint256 internal constant _ROLE_168 = 1 << 168;
    uint256 internal constant _ROLE_169 = 1 << 169;
    uint256 internal constant _ROLE_170 = 1 << 170;
    uint256 internal constant _ROLE_171 = 1 << 171;
    uint256 internal constant _ROLE_172 = 1 << 172;
    uint256 internal constant _ROLE_173 = 1 << 173;
    uint256 internal constant _ROLE_174 = 1 << 174;
    uint256 internal constant _ROLE_175 = 1 << 175;
    uint256 internal constant _ROLE_176 = 1 << 176;
    uint256 internal constant _ROLE_177 = 1 << 177;
    uint256 internal constant _ROLE_178 = 1 << 178;
    uint256 internal constant _ROLE_179 = 1 << 179;
    uint256 internal constant _ROLE_180 = 1 << 180;
    uint256 internal constant _ROLE_181 = 1 << 181;
    uint256 internal constant _ROLE_182 = 1 << 182;
    uint256 internal constant _ROLE_183 = 1 << 183;
    uint256 internal constant _ROLE_184 = 1 << 184;
    uint256 internal constant _ROLE_185 = 1 << 185;
    uint256 internal constant _ROLE_186 = 1 << 186;
    uint256 internal constant _ROLE_187 = 1 << 187;
    uint256 internal constant _ROLE_188 = 1 << 188;
    uint256 internal constant _ROLE_189 = 1 << 189;
    uint256 internal constant _ROLE_190 = 1 << 190;
    uint256 internal constant _ROLE_191 = 1 << 191;
    uint256 internal constant _ROLE_192 = 1 << 192;
    uint256 internal constant _ROLE_193 = 1 << 193;
    uint256 internal constant _ROLE_194 = 1 << 194;
    uint256 internal constant _ROLE_195 = 1 << 195;
    uint256 internal constant _ROLE_196 = 1 << 196;
    uint256 internal constant _ROLE_197 = 1 << 197;
    uint256 internal constant _ROLE_198 = 1 << 198;
    uint256 internal constant _ROLE_199 = 1 << 199;
    uint256 internal constant _ROLE_200 = 1 << 200;
    uint256 internal constant _ROLE_201 = 1 << 201;
    uint256 internal constant _ROLE_202 = 1 << 202;
    uint256 internal constant _ROLE_203 = 1 << 203;
    uint256 internal constant _ROLE_204 = 1 << 204;
    uint256 internal constant _ROLE_205 = 1 << 205;
    uint256 internal constant _ROLE_206 = 1 << 206;
    uint256 internal constant _ROLE_207 = 1 << 207;
    uint256 internal constant _ROLE_208 = 1 << 208;
    uint256 internal constant _ROLE_209 = 1 << 209;
    uint256 internal constant _ROLE_210 = 1 << 210;
    uint256 internal constant _ROLE_211 = 1 << 211;
    uint256 internal constant _ROLE_212 = 1 << 212;
    uint256 internal constant _ROLE_213 = 1 << 213;
    uint256 internal constant _ROLE_214 = 1 << 214;
    uint256 internal constant _ROLE_215 = 1 << 215;
    uint256 internal constant _ROLE_216 = 1 << 216;
    uint256 internal constant _ROLE_217 = 1 << 217;
    uint256 internal constant _ROLE_218 = 1 << 218;
    uint256 internal constant _ROLE_219 = 1 << 219;
    uint256 internal constant _ROLE_220 = 1 << 220;
    uint256 internal constant _ROLE_221 = 1 << 221;
    uint256 internal constant _ROLE_222 = 1 << 222;
    uint256 internal constant _ROLE_223 = 1 << 223;
    uint256 internal constant _ROLE_224 = 1 << 224;
    uint256 internal constant _ROLE_225 = 1 << 225;
    uint256 internal constant _ROLE_226 = 1 << 226;
    uint256 internal constant _ROLE_227 = 1 << 227;
    uint256 internal constant _ROLE_228 = 1 << 228;
    uint256 internal constant _ROLE_229 = 1 << 229;
    uint256 internal constant _ROLE_230 = 1 << 230;
    uint256 internal constant _ROLE_231 = 1 << 231;
    uint256 internal constant _ROLE_232 = 1 << 232;
    uint256 internal constant _ROLE_233 = 1 << 233;
    uint256 internal constant _ROLE_234 = 1 << 234;
    uint256 internal constant _ROLE_235 = 1 << 235;
    uint256 internal constant _ROLE_236 = 1 << 236;
    uint256 internal constant _ROLE_237 = 1 << 237;
    uint256 internal constant _ROLE_238 = 1 << 238;
    uint256 internal constant _ROLE_239 = 1 << 239;
    uint256 internal constant _ROLE_240 = 1 << 240;
    uint256 internal constant _ROLE_241 = 1 << 241;
    uint256 internal constant _ROLE_242 = 1 << 242;
    uint256 internal constant _ROLE_243 = 1 << 243;
    uint256 internal constant _ROLE_244 = 1 << 244;
    uint256 internal constant _ROLE_245 = 1 << 245;
    uint256 internal constant _ROLE_246 = 1 << 246;
    uint256 internal constant _ROLE_247 = 1 << 247;
    uint256 internal constant _ROLE_248 = 1 << 248;
    uint256 internal constant _ROLE_249 = 1 << 249;
    uint256 internal constant _ROLE_250 = 1 << 250;
    uint256 internal constant _ROLE_251 = 1 << 251;
    uint256 internal constant _ROLE_252 = 1 << 252;
    uint256 internal constant _ROLE_253 = 1 << 253;
    uint256 internal constant _ROLE_254 = 1 << 254;
    uint256 internal constant _ROLE_255 = 1 << 255;
}

File 14 of 17 : 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)
        }
    }
}

File 15 of 17 : MerkleProofLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
library MerkleProofLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*            MERKLE PROOF VERIFICATION OPERATIONS            */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
        internal
        pure
        returns (bool isValid)
    {
        /// @solidity memory-safe-assembly
        assembly {
            if mload(proof) {
                // Initialize `offset` to the offset of `proof` elements in memory.
                let offset := add(proof, 0x20)
                // Left shift by 5 is equivalent to multiplying by 0x20.
                let end := add(offset, shl(5, mload(proof)))
                // Iterate over proof elements to compute root hash.
                for {} 1 {} {
                    // Slot of `leaf` in scratch space.
                    // If the condition is true: 0x20, otherwise: 0x00.
                    let scratch := shl(5, gt(leaf, mload(offset)))
                    // Store elements to hash contiguously in scratch space.
                    // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                    mstore(scratch, leaf)
                    mstore(xor(scratch, 0x20), mload(offset))
                    // Reuse `leaf` to store the hash to reduce stack operations.
                    leaf := keccak256(0x00, 0x40)
                    offset := add(offset, 0x20)
                    if iszero(lt(offset, end)) { break }
                }
            }
            isValid := eq(leaf, root)
        }
    }

    /// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
    function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
        internal
        pure
        returns (bool isValid)
    {
        /// @solidity memory-safe-assembly
        assembly {
            if proof.length {
                // Left shift by 5 is equivalent to multiplying by 0x20.
                let end := add(proof.offset, shl(5, proof.length))
                // Initialize `offset` to the offset of `proof` in the calldata.
                let offset := proof.offset
                // Iterate over proof elements to compute root hash.
                for {} 1 {} {
                    // Slot of `leaf` in scratch space.
                    // If the condition is true: 0x20, otherwise: 0x00.
                    let scratch := shl(5, gt(leaf, calldataload(offset)))
                    // Store elements to hash contiguously in scratch space.
                    // Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
                    mstore(scratch, leaf)
                    mstore(xor(scratch, 0x20), calldataload(offset))
                    // Reuse `leaf` to store the hash to reduce stack operations.
                    leaf := keccak256(0x00, 0x40)
                    offset := add(offset, 0x20)
                    if iszero(lt(offset, end)) { break }
                }
            }
            isValid := eq(leaf, root)
        }
    }

    /// @dev Returns whether all `leafs` exist in the Merkle tree with `root`,
    /// given `proof` and `flags`.
    function verifyMultiProof(
        bytes32[] memory proof,
        bytes32 root,
        bytes32[] memory leafs,
        bool[] memory flags
    ) internal pure returns (bool isValid) {
        // Rebuilds the root by consuming and producing values on a queue.
        // The queue starts with the `leafs` array, and goes into a `hashes` array.
        // After the process, the last element on the queue is verified
        // to be equal to the `root`.
        //
        // The `flags` array denotes whether the sibling
        // should be popped from the queue (`flag == true`), or
        // should be popped from the `proof` (`flag == false`).
        /// @solidity memory-safe-assembly
        assembly {
            // Cache the lengths of the arrays.
            let leafsLength := mload(leafs)
            let proofLength := mload(proof)
            let flagsLength := mload(flags)

            // Advance the pointers of the arrays to point to the data.
            leafs := add(0x20, leafs)
            proof := add(0x20, proof)
            flags := add(0x20, flags)

            // If the number of flags is correct.
            for {} eq(add(leafsLength, proofLength), add(flagsLength, 1)) {} {
                // For the case where `proof.length + leafs.length == 1`.
                if iszero(flagsLength) {
                    // `isValid = (proof.length == 1 ? proof[0] : leafs[0]) == root`.
                    isValid := eq(mload(xor(leafs, mul(xor(proof, leafs), proofLength))), root)
                    break
                }

                // We can use the free memory space for the queue.
                // We don't need to allocate, since the queue is temporary.
                let hashesFront := mload(0x40)
                // Copy the leafs into the hashes.
                // Sometimes, a little memory expansion costs less than branching.
                // Should cost less, even with a high free memory offset of 0x7d00.
                // Left shift by 5 is equivalent to multiplying by 0x20.
                leafsLength := shl(5, leafsLength)
                for { let i := 0 } iszero(eq(i, leafsLength)) { i := add(i, 0x20) } {
                    mstore(add(hashesFront, i), mload(add(leafs, i)))
                }
                // Compute the back of the hashes.
                let hashesBack := add(hashesFront, leafsLength)
                // This is the end of the memory for the queue.
                // We recycle `flagsLength` to save on stack variables
                // (this trick may not always save gas).
                flagsLength := add(hashesBack, shl(5, flagsLength))

                for {} 1 {} {
                    // Pop from `hashes`.
                    let a := mload(hashesFront)
                    // Pop from `hashes`.
                    let b := mload(add(hashesFront, 0x20))
                    hashesFront := add(hashesFront, 0x40)

                    // If the flag is false, load the next proof,
                    // else, pops from the queue.
                    if iszero(mload(flags)) {
                        // Loads the next proof.
                        b := mload(proof)
                        proof := add(proof, 0x20)
                        // Unpop from `hashes`.
                        hashesFront := sub(hashesFront, 0x20)
                    }

                    // Advance to the next flag.
                    flags := add(flags, 0x20)

                    // Slot of `a` in scratch space.
                    // If the condition is true: 0x20, otherwise: 0x00.
                    let scratch := shl(5, gt(a, b))
                    // Hash the scratch space and push the result onto the queue.
                    mstore(scratch, a)
                    mstore(xor(scratch, 0x20), b)
                    mstore(hashesBack, keccak256(0x00, 0x40))
                    hashesBack := add(hashesBack, 0x20)
                    if iszero(lt(hashesBack, flagsLength)) { break }
                }
                // Checks if the last value in the queue is same as the root.
                isValid := eq(mload(sub(hashesBack, 0x20)), root)
                break
            }
        }
    }

    /// @dev Returns whether all `leafs` exist in the Merkle tree with `root`,
    /// given `proof` and `flags`.
    function verifyMultiProofCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32[] calldata leafs,
        bool[] calldata flags
    ) internal pure returns (bool isValid) {
        // Rebuilds the root by consuming and producing values on a queue.
        // The queue starts with the `leafs` array, and goes into a `hashes` array.
        // After the process, the last element on the queue is verified
        // to be equal to the `root`.
        //
        // The `flags` array denotes whether the sibling
        // should be popped from the queue (`flag == true`), or
        // should be popped from the `proof` (`flag == false`).
        /// @solidity memory-safe-assembly
        assembly {
            // If the number of flags is correct.
            for {} eq(add(leafs.length, proof.length), add(flags.length, 1)) {} {
                // For the case where `proof.length + leafs.length == 1`.
                if iszero(flags.length) {
                    // `isValid = (proof.length == 1 ? proof[0] : leafs[0]) == root`.
                    // forgefmt: disable-next-item
                    isValid := eq(
                        calldataload(
                            xor(leafs.offset, mul(xor(proof.offset, leafs.offset), proof.length))
                        ),
                        root
                    )
                    break
                }

                // We can use the free memory space for the queue.
                // We don't need to allocate, since the queue is temporary.
                let hashesFront := mload(0x40)
                // Copy the leafs into the hashes.
                // Sometimes, a little memory expansion costs less than branching.
                // Should cost less, even with a high free memory offset of 0x7d00.
                // Left shift by 5 is equivalent to multiplying by 0x20.
                calldatacopy(hashesFront, leafs.offset, shl(5, leafs.length))
                // Compute the back of the hashes.
                let hashesBack := add(hashesFront, shl(5, leafs.length))
                // This is the end of the memory for the queue.
                // We recycle `flags.length` to save on stack variables
                // (this trick may not always save gas).
                flags.length := add(hashesBack, shl(5, flags.length))

                // We don't need to make a copy of `proof.offset` or `flags.offset`,
                // as they are pass-by-value (this trick may not always save gas).

                for {} 1 {} {
                    // Pop from `hashes`.
                    let a := mload(hashesFront)
                    // Pop from `hashes`.
                    let b := mload(add(hashesFront, 0x20))
                    hashesFront := add(hashesFront, 0x40)

                    // If the flag is false, load the next proof,
                    // else, pops from the queue.
                    if iszero(calldataload(flags.offset)) {
                        // Loads the next proof.
                        b := calldataload(proof.offset)
                        proof.offset := add(proof.offset, 0x20)
                        // Unpop from `hashes`.
                        hashesFront := sub(hashesFront, 0x20)
                    }

                    // Advance to the next flag offset.
                    flags.offset := add(flags.offset, 0x20)

                    // Slot of `a` in scratch space.
                    // If the condition is true: 0x20, otherwise: 0x00.
                    let scratch := shl(5, gt(a, b))
                    // Hash the scratch space and push the result onto the queue.
                    mstore(scratch, a)
                    mstore(xor(scratch, 0x20), b)
                    mstore(hashesBack, keccak256(0x00, 0x40))
                    hashesBack := add(hashesBack, 0x20)
                    if iszero(lt(hashesBack, flags.length)) { break }
                }
                // Checks if the last value in the queue is same as the root.
                isValid := eq(mload(sub(hashesBack, 0x20)), root)
                break
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   EMPTY CALLDATA HELPERS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns an empty calldata bytes32 array.
    function emptyProof() internal pure returns (bytes32[] calldata proof) {
        /// @solidity memory-safe-assembly
        assembly {
            proof.length := 0
        }
    }

    /// @dev Returns an empty calldata bytes32 array.
    function emptyLeafs() internal pure returns (bytes32[] calldata leafs) {
        /// @solidity memory-safe-assembly
        assembly {
            leafs.length := 0
        }
    }

    /// @dev Returns an empty calldata bool array.
    function emptyFlags() internal pure returns (bool[] calldata flags) {
        /// @solidity memory-safe-assembly
        assembly {
            flags.length := 0
        }
    }
}

File 16 of 17 : SafeCastLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Safe integer casting library that reverts on overflow.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeCastLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
library SafeCastLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error Overflow();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*          UNSIGNED INTEGER SAFE CASTING OPERATIONS          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    function toUint8(uint256 x) internal pure returns (uint8) {
        if (x >= 1 << 8) _revertOverflow();
        return uint8(x);
    }

    function toUint16(uint256 x) internal pure returns (uint16) {
        if (x >= 1 << 16) _revertOverflow();
        return uint16(x);
    }

    function toUint24(uint256 x) internal pure returns (uint24) {
        if (x >= 1 << 24) _revertOverflow();
        return uint24(x);
    }

    function toUint32(uint256 x) internal pure returns (uint32) {
        if (x >= 1 << 32) _revertOverflow();
        return uint32(x);
    }

    function toUint40(uint256 x) internal pure returns (uint40) {
        if (x >= 1 << 40) _revertOverflow();
        return uint40(x);
    }

    function toUint48(uint256 x) internal pure returns (uint48) {
        if (x >= 1 << 48) _revertOverflow();
        return uint48(x);
    }

    function toUint56(uint256 x) internal pure returns (uint56) {
        if (x >= 1 << 56) _revertOverflow();
        return uint56(x);
    }

    function toUint64(uint256 x) internal pure returns (uint64) {
        if (x >= 1 << 64) _revertOverflow();
        return uint64(x);
    }

    function toUint72(uint256 x) internal pure returns (uint72) {
        if (x >= 1 << 72) _revertOverflow();
        return uint72(x);
    }

    function toUint80(uint256 x) internal pure returns (uint80) {
        if (x >= 1 << 80) _revertOverflow();
        return uint80(x);
    }

    function toUint88(uint256 x) internal pure returns (uint88) {
        if (x >= 1 << 88) _revertOverflow();
        return uint88(x);
    }

    function toUint96(uint256 x) internal pure returns (uint96) {
        if (x >= 1 << 96) _revertOverflow();
        return uint96(x);
    }

    function toUint104(uint256 x) internal pure returns (uint104) {
        if (x >= 1 << 104) _revertOverflow();
        return uint104(x);
    }

    function toUint112(uint256 x) internal pure returns (uint112) {
        if (x >= 1 << 112) _revertOverflow();
        return uint112(x);
    }

    function toUint120(uint256 x) internal pure returns (uint120) {
        if (x >= 1 << 120) _revertOverflow();
        return uint120(x);
    }

    function toUint128(uint256 x) internal pure returns (uint128) {
        if (x >= 1 << 128) _revertOverflow();
        return uint128(x);
    }

    function toUint136(uint256 x) internal pure returns (uint136) {
        if (x >= 1 << 136) _revertOverflow();
        return uint136(x);
    }

    function toUint144(uint256 x) internal pure returns (uint144) {
        if (x >= 1 << 144) _revertOverflow();
        return uint144(x);
    }

    function toUint152(uint256 x) internal pure returns (uint152) {
        if (x >= 1 << 152) _revertOverflow();
        return uint152(x);
    }

    function toUint160(uint256 x) internal pure returns (uint160) {
        if (x >= 1 << 160) _revertOverflow();
        return uint160(x);
    }

    function toUint168(uint256 x) internal pure returns (uint168) {
        if (x >= 1 << 168) _revertOverflow();
        return uint168(x);
    }

    function toUint176(uint256 x) internal pure returns (uint176) {
        if (x >= 1 << 176) _revertOverflow();
        return uint176(x);
    }

    function toUint184(uint256 x) internal pure returns (uint184) {
        if (x >= 1 << 184) _revertOverflow();
        return uint184(x);
    }

    function toUint192(uint256 x) internal pure returns (uint192) {
        if (x >= 1 << 192) _revertOverflow();
        return uint192(x);
    }

    function toUint200(uint256 x) internal pure returns (uint200) {
        if (x >= 1 << 200) _revertOverflow();
        return uint200(x);
    }

    function toUint208(uint256 x) internal pure returns (uint208) {
        if (x >= 1 << 208) _revertOverflow();
        return uint208(x);
    }

    function toUint216(uint256 x) internal pure returns (uint216) {
        if (x >= 1 << 216) _revertOverflow();
        return uint216(x);
    }

    function toUint224(uint256 x) internal pure returns (uint224) {
        if (x >= 1 << 224) _revertOverflow();
        return uint224(x);
    }

    function toUint232(uint256 x) internal pure returns (uint232) {
        if (x >= 1 << 232) _revertOverflow();
        return uint232(x);
    }

    function toUint240(uint256 x) internal pure returns (uint240) {
        if (x >= 1 << 240) _revertOverflow();
        return uint240(x);
    }

    function toUint248(uint256 x) internal pure returns (uint248) {
        if (x >= 1 << 248) _revertOverflow();
        return uint248(x);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*           SIGNED INTEGER SAFE CASTING OPERATIONS           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    function toInt8(int256 x) internal pure returns (int8) {
        int8 y = int8(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt16(int256 x) internal pure returns (int16) {
        int16 y = int16(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt24(int256 x) internal pure returns (int24) {
        int24 y = int24(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt32(int256 x) internal pure returns (int32) {
        int32 y = int32(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt40(int256 x) internal pure returns (int40) {
        int40 y = int40(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt48(int256 x) internal pure returns (int48) {
        int48 y = int48(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt56(int256 x) internal pure returns (int56) {
        int56 y = int56(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt64(int256 x) internal pure returns (int64) {
        int64 y = int64(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt72(int256 x) internal pure returns (int72) {
        int72 y = int72(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt80(int256 x) internal pure returns (int80) {
        int80 y = int80(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt88(int256 x) internal pure returns (int88) {
        int88 y = int88(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt96(int256 x) internal pure returns (int96) {
        int96 y = int96(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt104(int256 x) internal pure returns (int104) {
        int104 y = int104(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt112(int256 x) internal pure returns (int112) {
        int112 y = int112(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt120(int256 x) internal pure returns (int120) {
        int120 y = int120(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt128(int256 x) internal pure returns (int128) {
        int128 y = int128(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt136(int256 x) internal pure returns (int136) {
        int136 y = int136(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt144(int256 x) internal pure returns (int144) {
        int144 y = int144(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt152(int256 x) internal pure returns (int152) {
        int152 y = int152(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt160(int256 x) internal pure returns (int160) {
        int160 y = int160(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt168(int256 x) internal pure returns (int168) {
        int168 y = int168(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt176(int256 x) internal pure returns (int176) {
        int176 y = int176(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt184(int256 x) internal pure returns (int184) {
        int184 y = int184(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt192(int256 x) internal pure returns (int192) {
        int192 y = int192(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt200(int256 x) internal pure returns (int200) {
        int200 y = int200(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt208(int256 x) internal pure returns (int208) {
        int208 y = int208(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt216(int256 x) internal pure returns (int216) {
        int216 y = int216(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt224(int256 x) internal pure returns (int224) {
        int224 y = int224(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt232(int256 x) internal pure returns (int232) {
        int232 y = int232(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt240(int256 x) internal pure returns (int240) {
        int240 y = int240(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt248(int256 x) internal pure returns (int248) {
        int248 y = int248(x);
        if (x != y) _revertOverflow();
        return y;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      PRIVATE HELPERS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    function _revertOverflow() private pure {
        /// @solidity memory-safe-assembly
        assembly {
            // Store the function selector of `Overflow()`.
            mstore(0x00, 0x35278d12)
            // Revert with (offset, size).
            revert(0x1c, 0x04)
        }
    }
}

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

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Caution! This library won't check that a token has code, responsibility is delegated to the caller.
library SafeTransferLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ETH transfer has failed.
    error ETHTransferFailed();

    /// @dev The ERC20 `transferFrom` has failed.
    error TransferFromFailed();

    /// @dev The ERC20 `transfer` has failed.
    error TransferFailed();

    /// @dev The ERC20 `approve` has failed.
    error ApproveFailed();

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

    /// @dev Suggested gas stipend for contract receiving ETH
    /// that disallows any storage writes.
    uint256 internal constant _GAS_STIPEND_NO_STORAGE_WRITES = 2300;

    /// @dev Suggested gas stipend for contract receiving ETH to perform a few
    /// storage reads and writes, but low enough to prevent griefing.
    /// Multiply by a small constant (e.g. 2), if needed.
    uint256 internal constant _GAS_STIPEND_NO_GRIEF = 100000;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       ETH OPERATIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Sends `amount` (in wei) ETH to `to`.
    /// Reverts upon failure.
    function safeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    /// The `gasStipend` can be set to a low enough value to prevent
    /// storage writes or gas griefing.
    ///
    /// If sending via the normal procedure fails, force sends the ETH by
    /// creating a temporary contract which uses `SELFDESTRUCT` to force send the ETH.
    ///
    /// Reverts if the current contract has insufficient balance.
    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // If insufficient balance, revert.
            if lt(selfbalance(), amount) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(gasStipend, to, amount, 0, 0, 0, 0)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                // We can directly use `SELFDESTRUCT` in the contract creation.
                // Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
                pop(create(amount, 0x0b, 0x16))
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a gas stipend
    /// equal to `_GAS_STIPEND_NO_GRIEF`. This gas stipend is a reasonable default
    /// for 99% of cases and can be overriden with the three-argument version of this
    /// function if necessary.
    ///
    /// If sending via the normal procedure fails, force sends the ETH by
    /// creating a temporary contract which uses `SELFDESTRUCT` to force send the ETH.
    ///
    /// Reverts if the current contract has insufficient balance.
    function forceSafeTransferETH(address to, uint256 amount) internal {
        // Manually inlined because the compiler doesn't inline functions with branches.
        /// @solidity memory-safe-assembly
        assembly {
            // If insufficient balance, revert.
            if lt(selfbalance(), amount) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(_GAS_STIPEND_NO_GRIEF, to, amount, 0, 0, 0, 0)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                // We can directly use `SELFDESTRUCT` in the contract creation.
                // Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
                pop(create(amount, 0x0b, 0x16))
            }
        }
    }

    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    /// The `gasStipend` can be set to a low enough value to prevent
    /// storage writes or gas griefing.
    ///
    /// Simply use `gasleft()` for `gasStipend` if you don't need a gas stipend.
    ///
    /// Note: Does NOT revert upon failure.
    /// Returns whether the transfer of ETH is successful instead.
    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and check if it succeeded or not.
            success := call(gasStipend, to, amount, 0, 0, 0, 0)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      ERC20 OPERATIONS                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for
    /// the current contract to manage.
    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.

            // Store the function selector of `transferFrom(address,address,uint256)`.
            mstore(0x00, 0x23b872dd)
            mstore(0x20, from) // Store the `from` argument.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x60, amount) // Store the `amount` argument.

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends all of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for
    /// the current contract to manage.
    function safeTransferAllFrom(address token, address from, address to)
        internal
        returns (uint256 amount)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.

            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
            mstore(0x20, from) // Store the `from` argument.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            // Store the function selector of `transferFrom(address,address,uint256)`.
            mstore(0x00, 0x23b872dd)
            mstore(0x40, to) // Store the `to` argument.
            // The `amount` argument is already written to the memory word at 0x6a.
            amount := mload(0x60)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransfer(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x1a, to) // Store the `to` argument.
            mstore(0x3a, amount) // Store the `amount` argument.
            // Store the function selector of `transfer(address,uint256)`,
            // left by 6 bytes (enough for 8tb of memory represented by the free memory pointer).
            // We waste 6-3 = 3 bytes to save on 6 runtime gas (PUSH1 0x224 SHL).
            mstore(0x00, 0xa9059cbb000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x16, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten,
            // which is guaranteed to be zero, if less than 8tb of memory is used.
            mstore(0x3a, 0)
        }
    }

    /// @dev Sends all of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransferAll(address token, address to) internal returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
            mstore(0x20, address()) // Store the address of the current contract.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x3a, 0x20)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            mstore(0x1a, to) // Store the `to` argument.
            // The `amount` argument is already written to the memory word at 0x3a.
            amount := mload(0x3a)
            // Store the function selector of `transfer(address,uint256)`,
            // left by 6 bytes (enough for 8tb of memory represented by the free memory pointer).
            // We waste 6-3 = 3 bytes to save on 6 runtime gas (PUSH1 0x224 SHL).
            mstore(0x00, 0xa9059cbb000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x16, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten,
            // which is guaranteed to be zero, if less than 8tb of memory is used.
            mstore(0x3a, 0)
        }
    }

    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
    /// Reverts upon failure.
    function safeApprove(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x1a, to) // Store the `to` argument.
            mstore(0x3a, amount) // Store the `amount` argument.
            // Store the function selector of `approve(address,uint256)`,
            // left by 6 bytes (enough for 8tb of memory represented by the free memory pointer).
            // We waste 6-3 = 3 bytes to save on 6 runtime gas (PUSH1 0x224 SHL).
            mstore(0x00, 0x095ea7b3000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x16, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `ApproveFailed()`.
                mstore(0x00, 0x3e3f8f73)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten,
            // which is guaranteed to be zero, if less than 8tb of memory is used.
            mstore(0x3a, 0)
        }
    }

    /// @dev Returns the amount of ERC20 `token` owned by `account`.
    /// Returns zero if the `token` does not exist.
    function balanceOf(address token, address account) internal view returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
            mstore(0x20, account) // Store the `account` argument.
            amount :=
                mul(
                    mload(0x20),
                    and( // The arguments of `and` are evaluated from right to left.
                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                        staticcall(gas(), token, 0x1c, 0x24, 0x20, 0x20)
                    )
                )
        }
    }
}

Settings
{
  "remappings": [
    "@core/=contracts/core/",
    "@modules/=contracts/modules/",
    "ERC721A-Upgradeable/=lib/ERC721A-Upgradeable/contracts/",
    "chiru-labs/ERC721A-Upgradeable/=lib/ERC721A-Upgradeable/contracts/",
    "closedsea/=lib/closedsea/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/closedsea/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "erc721a-upgradeable/=lib/closedsea/lib/erc721a-upgradeable/contracts/",
    "erc721a/=lib/closedsea/lib/erc721a/contracts/",
    "forge-std/=lib/forge-std/src/",
    "multicaller/=lib/multicaller/src/",
    "murky/=lib/murky/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "operator-filter-registry/=lib/closedsea/lib/operator-filter-registry/",
    "preapprove/=lib/preapprove/src/",
    "solady/=lib/solady/src/",
    "solmate/=lib/solady/lib/solmate/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1000
  },
  "metadata": {
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"payable","type":"constructor"},{"inputs":[],"name":"BurnZeroQuantity","type":"error"},{"inputs":[],"name":"BuyIsFrozen","type":"error"},{"inputs":[{"internalType":"uint32","name":"available","type":"uint32"}],"name":"ExceedsMaxSupply","type":"error"},{"inputs":[],"name":"InSAMPhase","type":"error"},{"inputs":[],"name":"InflectionPointIsZero","type":"error"},{"inputs":[],"name":"InflectionPriceIsZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"payout","type":"uint256"},{"internalType":"uint256","name":"required","type":"uint256"}],"name":"InsufficientPayout","type":"error"},{"inputs":[{"internalType":"uint256","name":"available","type":"uint256"},{"internalType":"uint256","name":"required","type":"uint256"}],"name":"InsufficientSupply","type":"error"},{"inputs":[],"name":"InvalidAffiliate","type":"error"},{"inputs":[],"name":"InvalidAffiliateFeeBPS","type":"error"},{"inputs":[],"name":"InvalidArtistFeeBPS","type":"error"},{"inputs":[],"name":"InvalidBuyFreezeTime","type":"error"},{"inputs":[],"name":"InvalidGoldenEggFeeBPS","type":"error"},{"inputs":[],"name":"InvalidMaxSupply","type":"error"},{"inputs":[],"name":"InvalidPlatformFeeBPS","type":"error"},{"inputs":[],"name":"MintZeroQuantity","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"PlatformFeeAddressIsZero","type":"error"},{"inputs":[],"name":"SAMAlreadyExists","type":"error"},{"inputs":[],"name":"SAMDoesNotExist","type":"error"},{"inputs":[],"name":"UnapprovedEdition","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[{"internalType":"uint256","name":"paid","type":"uint256"},{"internalType":"uint256","name":"required","type":"uint256"}],"name":"Underpaid","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint16","name":"bps","type":"uint16"}],"name":"AffiliateFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"affiliate","type":"address"},{"indexed":false,"internalType":"uint256","name":"accrued","type":"uint256"}],"name":"AffiliateFeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"bytes32","name":"root","type":"bytes32"}],"name":"AffiliateMerkleRootSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"factories","type":"address[]"}],"name":"ApprovedEditionFactoriesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint16","name":"bps","type":"uint16"}],"name":"ArtistFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint96","name":"basePrice","type":"uint96"}],"name":"BasePriceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromTokenId","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"fromCurveSupply","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"quantity","type":"uint32"},{"indexed":false,"internalType":"uint128","name":"totalPayment","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"platformFee","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"artistFee","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"goldenEggFee","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"affiliateFee","type":"uint128"},{"indexed":false,"internalType":"address","name":"affiliate","type":"address"},{"indexed":false,"internalType":"bool","name":"affiliated","type":"bool"},{"indexed":true,"internalType":"uint256","name":"attributionId","type":"uint256"}],"name":"Bought","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint32","name":"buyFreezeTime","type":"uint32"}],"name":"BuyFreezeTimeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint96","name":"basePrice","type":"uint96"},{"indexed":false,"internalType":"uint128","name":"linearPriceSlope","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"inflectionPrice","type":"uint128"},{"indexed":false,"internalType":"uint32","name":"inflectionPoint","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"maxSupply","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"buyFreezeTime","type":"uint32"},{"indexed":false,"internalType":"uint16","name":"artistFeeBPS","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"goldenEggFeeBPS","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"affiliateFeeBPS","type":"uint16"}],"name":"Created","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint16","name":"bps","type":"uint16"}],"name":"GoldenEggFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":true,"internalType":"address","name":"receipient","type":"address"},{"indexed":false,"internalType":"uint128","name":"accrued","type":"uint128"}],"name":"GoldenEggFeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint32","name":"inflectionPoint","type":"uint32"}],"name":"InflectionPointSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint128","name":"inflectionPrice","type":"uint128"}],"name":"InflectionPriceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint128","name":"linearPriceSlope","type":"uint128"}],"name":"LinearPriceSlopeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":false,"internalType":"uint32","name":"maxSupply","type":"uint32"}],"name":"MaxSupplySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"PlatformFeeAddressSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"bps","type":"uint16"}],"name":"PlatformFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"accrued","type":"uint128"}],"name":"PlatformFeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"edition","type":"address"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"uint32","name":"fromCurveSupply","type":"uint32"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"indexed":false,"internalType":"uint128","name":"totalPayout","type":"uint128"},{"indexed":true,"internalType":"uint256","name":"attributionId","type":"uint256"}],"name":"Sold","type":"event"},{"inputs":[],"name":"BPS_DENOMINATOR","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_AFFILIATE_FEE_BPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_ARTIST_FEE_BPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_GOLDEN_EGG_FEE_BPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PLATFORM_FEE_BPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"affiliateFeesAccrued","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"}],"name":"affiliateMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"approvedEditionFactories","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint32","name":"quantity","type":"uint32"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bytes32[]","name":"affiliateProof","type":"bytes32[]"},{"internalType":"uint256","name":"attributonId","type":"uint256"}],"name":"buy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint96","name":"basePrice","type":"uint96"},{"internalType":"uint128","name":"linearPriceSlope","type":"uint128"},{"internalType":"uint128","name":"inflectionPrice","type":"uint128"},{"internalType":"uint32","name":"inflectionPoint","type":"uint32"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"uint32","name":"buyFreezeTime","type":"uint32"},{"internalType":"uint16","name":"artistFeeBPS","type":"uint16"},{"internalType":"uint16","name":"goldenEggFeeBPS","type":"uint16"},{"internalType":"uint16","name":"affiliateFeeBPS","type":"uint16"},{"internalType":"address","name":"editionBy","type":"address"},{"internalType":"bytes32","name":"editionSalt","type":"bytes32"}],"name":"create","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"}],"name":"goldenEggFeeRecipient","outputs":[{"internalType":"address","name":"recipient","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"}],"name":"goldenEggFeesAccrued","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"address","name":"affiliate","type":"address"}],"name":"isAffiliated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bytes32[]","name":"affiliateProof","type":"bytes32[]"}],"name":"isAffiliatedWithProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"moduleInterfaceId","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownershipHandoverValidFor","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeeBPS","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeesAccrued","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"}],"name":"samInfo","outputs":[{"components":[{"internalType":"uint96","name":"basePrice","type":"uint96"},{"internalType":"uint128","name":"linearPriceSlope","type":"uint128"},{"internalType":"uint128","name":"inflectionPrice","type":"uint128"},{"internalType":"uint32","name":"inflectionPoint","type":"uint32"},{"internalType":"uint128","name":"goldenEggFeesAccrued","type":"uint128"},{"internalType":"uint128","name":"balance","type":"uint128"},{"internalType":"uint32","name":"supply","type":"uint32"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"uint32","name":"buyFreezeTime","type":"uint32"},{"internalType":"uint16","name":"artistFeeBPS","type":"uint16"},{"internalType":"uint16","name":"affiliateFeeBPS","type":"uint16"},{"internalType":"uint16","name":"goldenEggFeeBPS","type":"uint16"},{"internalType":"bytes32","name":"affiliateMerkleRoot","type":"bytes32"}],"internalType":"struct SAMInfo","name":"info","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"uint256","name":"minimumPayout","type":"uint256"},{"internalType":"address","name":"payoutTo","type":"address"},{"internalType":"uint256","name":"attributonId","type":"uint256"}],"name":"sell","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint16","name":"bps","type":"uint16"}],"name":"setAffiliateFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"bytes32","name":"root","type":"bytes32"}],"name":"setAffiliateMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"factories","type":"address[]"}],"name":"setApprovedEditionFactories","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint16","name":"bps","type":"uint16"}],"name":"setArtistFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint96","name":"basePrice","type":"uint96"}],"name":"setBasePrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"buyFreezeTime","type":"uint32"}],"name":"setBuyFreezeTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint16","name":"bps","type":"uint16"}],"name":"setGoldenEggFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"inflectionPoint","type":"uint32"}],"name":"setInflectionPoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint128","name":"inflectionPrice","type":"uint128"}],"name":"setInflectionPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint128","name":"linearPriceSlope","type":"uint128"}],"name":"setLinearPriceSlope","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"maxSupply","type":"uint32"}],"name":"setMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"bps","type":"uint16"}],"name":"setPlatformFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setPlatformFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"supplyForwardOffset","type":"uint32"},{"internalType":"uint32","name":"quantity","type":"uint32"}],"name":"totalBuyPriceAndFees","outputs":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"platformFee","type":"uint256"},{"internalType":"uint256","name":"artistFee","type":"uint256"},{"internalType":"uint256","name":"goldenEggFee","type":"uint256"},{"internalType":"uint256","name":"affiliateFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"supplyBackwardOffset","type":"uint32"},{"internalType":"uint32","name":"quantity","type":"uint32"}],"name":"totalSellPrice","outputs":[{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"},{"internalType":"uint32","name":"fromSupply","type":"uint32"},{"internalType":"uint32","name":"quantity","type":"uint32"}],"name":"totalValue","outputs":[{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"affiliate","type":"address"}],"name":"withdrawForAffiliate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"edition","type":"address"}],"name":"withdrawForGoldenEgg","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawForPlatform","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405261000d33610012565b61004e565b6001600160a01b0316638b78c6d8198190558060007f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a350565b613682806200005e6000396000f3fe6080604052600436106103135760003560e01c80639a3befc81161019a578063d1197d8a116100e1578063ed14834f1161008a578063f574029611610064578063f574029614610890578063fb015260146108b0578063fee81cf4146108d057600080fd5b8063ed14834f1461084a578063f04e283e1461086a578063f2fde38b1461087d57600080fd5b8063e1a45218116100bb578063e1a45218146107e5578063e9b3d5e7146107fb578063ebaaa3a11461082857600080fd5b8063d1197d8a14610791578063d7533f02146107b1578063dc2b66e8146107cf57600080fd5b8063b27c350411610143578063bbd1b0ee1161011d578063bbd1b0ee1461072f578063bd51f99e1461074f578063c7dd32281461076f57600080fd5b8063b27c3504146106cf578063b7711cbf146106ef578063bb06b9141461070f57600080fd5b8063ac1fc22c11610174578063ac1fc22c14610666578063ae6a7a8b1461069c578063afab4364146106bc57600080fd5b80639a3befc8146105dc5780639c186843146105fe578063aa2300b01461064657600080fd5b80635bb028441161025e5780638b7c895d116102075780639375da5a116101e15780639375da5a1461057c578063954c40091461059c57806399136dae146105bc57600080fd5b80638b7c895d146105435780638d01513c146103645780638da5cb5b1461056357600080fd5b80635dcbb465116102385780635dcbb4651461051b5780636c5f55f714610364578063715018a61461053b57600080fd5b80635bb02844146104bb5780635cb3a54e146104db5780635cbc742c146104fb57600080fd5b806326a36f59116102c057806341f6ec4f1161029a57806341f6ec4f1461045b57806345091b401461047b57806354d1f13d146104b357600080fd5b806326a36f59146103ed57806334cf8f0e1461040d57806336765d591461042d57600080fd5b806322163b86116102f157806322163b861461038d578063241ec00b146103c557806325692962146103e557600080fd5b806301ffc9a71461031857806308bfa2bf1461034d5780630d8a845614610364575b600080fd5b34801561032457600080fd5b50610338610333366004612df2565b610903565b60405190151581526020015b60405180910390f35b34801561035957600080fd5b50610362610953565b005b34801561037057600080fd5b5061037a6101f481565b60405161ffff9091168152602001610344565b34801561039957600080fd5b506000546103ad906001600160801b031681565b6040516001600160801b039091168152602001610344565b3480156103d157600080fd5b506103626103e0366004612e31565b610a33565b610362610b16565b3480156103f957600080fd5b50610362610408366004612e9a565b610b66565b34801561041957600080fd5b50610362610428366004612f2a565b610e54565b34801561043957600080fd5b5061044d610448366004612e31565b610f33565b604051908152602001610344565b34801561046757600080fd5b50610362610476366004612fa4565b610f48565b34801561048757600080fd5b5061049b610496366004612e31565b6112b3565b6040516001600160a01b039091168152602001610344565b610362611349565b3480156104c757600080fd5b5061044d6104d636600461307f565b611385565b3480156104e757600080fd5b5061044d6104f636600461307f565b6113a2565b34801561050757600080fd5b506103626105163660046130c4565b6113ff565b34801561052757600080fd5b506103ad610536366004612e31565b6114b8565b6103626114d6565b34801561054f57600080fd5b5061036261055e3660046130df565b6114ea565b34801561056f57600080fd5b50638b78c6d8195461049b565b34801561058857600080fd5b50610362610597366004612e31565b61153c565b3480156105a857600080fd5b506103626105b7366004612f2a565b6115c6565b3480156105c857600080fd5b506103626105d7366004613121565b61169b565b3480156105e857600080fd5b506105f1611750565b604051610344919061314d565b34801561060a57600080fd5b5061061e61061936600461307f565b6117b2565b604080519586526020860194909452928401919091526060830152608082015260a001610344565b34801561065257600080fd5b5061033861066136600461319a565b61187d565b34801561067257600080fd5b506103ad610681366004612e31565b6004602052600090815260409020546001600160801b031681565b3480156106a857600080fd5b506103626106b73660046131ff565b611908565b6103626106ca36600461322b565b611999565b3480156106db57600080fd5b506103626106ea366004613121565b611fd4565b3480156106fb57600080fd5b5061036261070a366004612f2a565b612089565b34801561071b57600080fd5b5061036261072a3660046131ff565b612106565b34801561073b57600080fd5b5061036261074a3660046132c0565b612187565b34801561075b57600080fd5b5061036261076a3660046132ec565b612225565b34801561077b57600080fd5b5060405163a3c2dbc760e01b8152602001610344565b34801561079d57600080fd5b506103386107ac366004613318565b61227f565b3480156107bd57600080fd5b506040516202a3008152602001610344565b3480156107db57600080fd5b5061037a6103e881565b3480156107f157600080fd5b5061037a61271081565b34801561080757600080fd5b5061081b610816366004612e31565b612294565b6040516103449190613351565b34801561083457600080fd5b5060005461037a90600160801b900461ffff1681565b34801561085657600080fd5b5060015461049b906001600160a01b031681565b610362610878366004612e31565b6123d6565b61036261088b366004612e31565b612416565b34801561089c57600080fd5b506103626108ab366004612e31565b61243d565b3480156108bc57600080fd5b506103626108cb366004613121565b612526565b3480156108dc57600080fd5b5061044d6108eb366004612e31565b63389a75e1600c908152600091909152602090205490565b60006001600160e01b031982167f01ffc9a700000000000000000000000000000000000000000000000000000000148061094d57506001600160e01b0319821663a3c2dbc760e01b145b92915050565b600054600160901b900460ff161561096a57600080fd5b6000805460ff60901b1916600160901b1790556001546001600160a01b0316806109a7576040516362ccef3360e01b815260040160405180910390fd5b6000546001600160801b03168015610a2257600080546fffffffffffffffffffffffffffffffff191690556109e5826001600160801b0383166125e5565b6040516001600160801b03821681527fa8a9aa21b43d916fdaf4bdf9975892e984e7dbe00c0befea632d6fe5bbead73a9060200160405180910390a15b50506000805460ff60901b19169055565b600054600160901b900460ff1615610a4a57600080fd5b6000805460ff60901b1916600160901b178155610a6682612626565b60018101549091506001600160701b03168015610b04576001820180546dffffffffffffffffffffffffffff191690556000610aa1846112b3565b9050610ab681836001600160801b03166125e5565b6040516001600160801b03831681526001600160a01b0380831691908616907fe9d03ae127c81928b88a95c4fb19c4e0451215b9c03456a73faef64de215f2cc9060200160405180910390a3505b50506000805460ff60901b1916905550565b60006202a30067ffffffffffffffff164201905063389a75e1600c5233600052806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a250565b600054600160901b900460ff1615610b7d57600080fd5b6000805460ff60901b1916600160901b1781558490819003610bcb576040517fca67be2000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610bd688612626565b6001810154909150600160e01b900463ffffffff1682811015610c34576040517f9e4c446100000000000000000000000000000000000000000000000000000000815260048101829052602481018490526044015b60405180910390fd5b8281036000610c44848387612688565b905087811015610c8a576040517fda3db5b00000000000000000000000000000000000000000000000000000000081526004810182905260248101899052604401610c2b565b6001840180546001600160e01b0316600160e01b63ffffffff8516021790819055600160701b90046001600160701b031681811015610d25576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f57544600000000000000000000000000000000000000000000000000000000006044820152606401610c2b565b6001850180547fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff16600160701b8484036001600160701b0316021790556040517fad66829f0000000000000000000000000000000000000000000000000000000081526001600160a01b038d169063ad66829f90610dab9033908f908f906004016134b9565b600060405180830381600087803b158015610dc557600080fd5b505af1158015610dd9573d6000803e3d6000fd5b50505050610de788836125e5565b86886001600160a01b03168d6001600160a01b03167f944b3f0b3c7f4118bf6e875f507afdd5eaafb7679ff8753036c6004bfcece497878f8f88604051610e3194939291906134e5565b60405180910390a450506000805460ff60901b1916905550505050505050505050565b81610e5e816126f4565b6000610e6984612626565b600281015490915063ffffffff600160801b90910481169084161115610eb057610e928461288f565b15610eb05760405163066f305360e21b815260040160405180910390fd5b6002810180547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff16600160801b63ffffffff8616908102919091179091556040519081526001600160a01b038516907f23cb1f116dd4d609eb56f337c5dc684f6b86077a9f40eb92f230715d6a1bd148906020015b60405180910390a250505050565b6000610f3e82612626565b6003015492915050565b610f518c6126f4565b610f5a8c61291d565b8663ffffffff16600003610f815760405163066f305360e21b815260040160405180910390fd5b8563ffffffff16600003610fa8576040516337a7abd960e01b815260040160405180910390fd5b6103e861ffff86161115610fcf57604051633a53216960e11b815260040160405180910390fd5b6101f461ffff85161115610ff6576040516333a27d9760e21b815260040160405180910390fd5b6101f461ffff8416111561101d57604051631a52ce6f60e01b815260040160405180910390fd5b6110288c838361295d565b6001600160a01b038c1660009081526003602052604090206002810154600160f81b900460ff1615611086576040517ffa5190c400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8b8160000160106101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff1602179055508a8160020160006101000a8154816001600160801b0302191690836001600160801b03160217905550898160000160006101000a8154816001600160801b0302191690836001600160801b031602179055508881600001601c6101000a81548163ffffffff021916908363ffffffff160217905550878160020160106101000a81548163ffffffff021916908363ffffffff160217905550868160020160146101000a81548163ffffffff021916908363ffffffff160217905550858160020160186101000a81548161ffff021916908361ffff1602179055508481600201601c6101000a81548161ffff021916908361ffff1602179055508381600201601a6101000a81548161ffff021916908361ffff160217905550600181600201601f6101000a81548160ff0219169083151502179055508c6001600160a01b03167f8cde7b696b606d38ecf5d8a7c3ee73d9c309af7d1d1015bee3d7c936995ed90f8d8d8d8d8d8d8d8d8d60405161129c999897969594939291906bffffffffffffffffffffffff9990991689526001600160801b0397881660208a015295909616604088015263ffffffff9384166060880152918316608087015290911660a085015261ffff90811660c085015291821660e0840152166101008201526101200190565b60405180910390a250505050505050505050505050565b6000819050633684d100600052602060006004601c855afa60203d14166112d957600080fd5b600051634baca2b5600052826020526020806024601c845afa905080611303573d61130357600080fd5b8060203d14161561134357636352211e600052602060006024601c865afa905080611332573d61133257600080fd5b8060203d1416156113435760005191505b50919050565b63389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2565b600061139a61139385612626565b8484612688565b949350505050565b6000806113ae85612626565b60018101549091506000906113d39063ffffffff80881691600160e01b900416613535565b905060006113e763ffffffff861683613535565b90506113f4838287612688565b979650505050505050565b611407612a77565b6101f461ffff82161115611447576040517f3d1e858400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080547fffffffffffffffffffffffffffff0000ffffffffffffffffffffffffffffffff16600160801b61ffff8416908102919091179091556040519081527f1426859b6b96e2e9ae302b23a42f763f4b0ae916a71a093e61c77120458b2e95906020015b60405180910390a150565b60006114c382612626565b600101546001600160701b031692915050565b6114de612a77565b6114e86000612a92565b565b6114f2612a77565b6114fe60028383612d76565b507f2064bc349588754d7a319f7e3e19098d6c481de9010cb8faabc2e4d1ccb8a9c68282604051611530929190613548565b60405180910390a15050565b611544612a77565b6001600160a01b03811661156b576040516362ccef3360e01b815260040160405180910390fd5b6001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383169081179091556040519081527fda1940b15ab63ed4db791f1c7ec186c01a546f6ce58fa1dcc0561b8638a1bd12906020016114ad565b816115d0816126f4565b60006115db84612626565b600281015490915063ffffffff600160a01b90910481169084161115611622576116048461288f565b15611622576040516337a7abd960e01b815260040160405180910390fd5b6002810180547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff16600160a01b63ffffffff8616908102919091179091556040519081526001600160a01b038516907fd85122012af450d91e115e674dcb75510396079ec3f9add017bfd6029ac57c3190602001610f25565b816116a5816126f4565b60006116b084612626565b90506101f461ffff841611156116d957604051631a52ce6f60e01b815260040160405180910390fd5b6002810180547fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b61ffff8616908102919091179091556040519081526001600160a01b038516907fbc4b9cc81e8abf70807d993342483076cb584d9453ea4243b108310dd44c87ee90602001610f25565b606060028054806020026020016040519081016040528092919081815260200182805480156117a857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161178a575b5050505050905090565b6000806000806000806117c489612626565b60018101549091506000906117e99063ffffffff808c1691600160e01b900416613596565b600283015490915063ffffffff600160801b90910481169061180d908a1683613596565b1115611852576002820154611830908290600160801b900463ffffffff16613535565b60405163af73298160e01b815263ffffffff9091166004820152602401610c2b565b6118658261185f83612ad0565b8a612aea565b949f929e50909c509a50919850909650505050505050565b60008061188986612626565b600301549050806118a75750506001600160a01b038316151561139a565b6001600160a01b038516158015906118fe57506040516bffffffffffffffffffffffff19606087901b1660208201526118fe9085908590849060340160405160208183030381529060405280519060200120612b62565b9695505050505050565b81611912816126f4565b8261191c8161291d565b600061192785612626565b6002810180546fffffffffffffffffffffffffffffffff19166001600160801b0387169081179091556040519081529091506001600160a01b038616907faf9934e1e24ed8c894e4dc1c9a96f50ae8d56628b7066199edc3f2ca245378a4906020015b60405180910390a25050505050565b600054600160901b900460ff16156119b057600080fd5b6000805460ff60901b1916600160901b17815563ffffffff86169003611a02576040517fb562e8dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611a6a60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b031681526020016000151581525090565b6000611a7589612626565b63ffffffff8089166101008501526001600160a01b0388166101208501526001820154600160e01b9004811684526002820154919250600160a01b909104164210611aec576040517fdf3981b000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611afb81836000015189612aea565b60e088015260c087015260a08601526080850152606084015260408301819052341015611b635760408083015190517ff3ebc3840000000000000000000000000000000000000000000000000000000081523460048201526024810191909152604401610c2b565b60028101546101008301518351600160801b90920463ffffffff1691011115611bbb578151600282015460405163af73298160e01b815263ffffffff600160801b909204821692909203166004820152602401610c2b565b611bc78987878761187d565b158015610140840152611c565760e082015115611c515760e08201516001600160a01b038716600090815260046020526040902054611c11916001600160801b0390911601612b9c565b6001600160a01b038716600090815260046020526040902080546fffffffffffffffffffffffffffffffff19166001600160801b03929092169190911790555b611cad565b6001600160a01b03861615611c97576040517f20d6c38900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60e08201805160a0840180519091019052600090525b608082015115611cfe576080820151600054611cd4916001600160801b0390911601612b9c565b600080546fffffffffffffffffffffffffffffffff19166001600160801b03929092169190911790555b60c082015115611d515760c08201516001820154611d27916001600160701b0390911601612bb1565b6001820180546dffffffffffffffffffffffffffff19166001600160701b03929092169190911790555b60608201516001820154611d7691600160701b9091046001600160701b031601612bb1565b6001820180546001600160701b0392909216600160701b027fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff9092169190911790556101008201518251611dca9101612ad0565b6001820180546001600160e01b0316600160e01b63ffffffff93841602179055600282018054600160f01b7fff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90911617905560a08301516040517f6f134cf40000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152928a166024820152918b1691636f134cf4919060440160206040518083038185885af1158015611e8b573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611eb091906135a9565b60208301526040820151341115611ed157611ed133836040015134036125e5565b82886001600160a01b03168a6001600160a01b03167f15845fbb9632d61f45d5c5fdd89d6caa7e378568af4cd871d42622224fdef75085602001518660000151876101000151886040015189608001518a60a001518b60c001518c60e001518d61012001518e6101400151604051611fb49a99989796959493929190998a5263ffffffff98891660208b01529690971660408901526001600160801b039485166060890152928416608088015290831660a0870152821660c08601521660e08401526001600160a01b039190911661010083015215156101208201526101400190565b60405180910390a450506000805460ff60901b1916905550505050505050565b81611fde816126f4565b6000611fe984612626565b90506103e861ffff8416111561201257604051633a53216960e11b815260040160405180910390fd5b6002810180547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b61ffff8616908102919091179091556040519081526001600160a01b038516907fc1f9d307740252602e3d93a4e35515536b7bdc62f0cbeb8e4ef65186f25e45bb90602001610f25565b81612093816126f4565b8261209d8161291d565b60006120a885612626565b80546001600160e01b0316600160e01b63ffffffff87169081029190911782556040519081529091506001600160a01b038616907f40b551a5bfa5b9a3ca031f8a3b912f66a42567c869b7df66b3d05d791ac985f09060200161198a565b81612110816126f4565b8261211a8161291d565b600061212585612626565b80546fffffffffffffffffffffffffffffffff19166001600160801b03861690811782556040519081529091506001600160a01b038616907f42aa13794032388632d506ac79fbb376ccf220fa0f83178cf1f26f6fb37c63889060200161198a565b81612191816126f4565b8261219b8161291d565b60006121a685612626565b80547fffffffff000000000000000000000000ffffffffffffffffffffffffffffffff16600160801b6bffffffffffffffffffffffff87169081029190911782556040519081529091506001600160a01b038616907f25626c9c16fddd2ddcf085e04ee7e54af24bd69023afef74c1a33ee6fc77dd1d9060200161198a565b8161222f816126f4565b600061223a84612626565b600381018490556040518481529091506001600160a01b038516907f89239be3d24ce581b82b186bce054ab48a0c360101cee4c9352efda104b7580890602001610f25565b600061228d8383368461187d565b9392505050565b604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290529061230683612626565b8054600160801b8082046bffffffffffffffffffffffff1685526001600160801b03808316604087015260028401549081166020870152600160e01b9283900463ffffffff908116606088015260018501546001600160701b0380821660808a0152858204831660c08a0152600160701b9091041660a0880152918104821660e0870152600160a01b8104909116610100860152600160c01b810461ffff908116610120870152600160d01b82048116610140870152919004166101608401526003015461018083015250919050565b6123de612a77565b63389a75e1600c52806000526020600c20805442111561240657636f5e88186000526004601cfd5b6000905561241381612a92565b50565b61241e612a77565b8060601b61243457637448fbae6000526004601cfd5b61241381612a92565b600054600160901b900460ff161561245457600080fd5b6000805460ff60901b1916600160901b1781556001600160a01b0382168152600460205260409020546001600160801b03168015610a22576001600160a01b038216600090815260046020526040902080546fffffffffffffffffffffffffffffffff191690556124ce826001600160801b0383166125e5565b6040516001600160801b03821681526001600160a01b038316907f0a1adaaf9d9caba9cf65528900e946b718d511ebd66ae81d5eb71e7fd0122c4a9060200160405180910390a250506000805460ff60901b19169055565b81612530816126f4565b8261253a8161291d565b600061254585612626565b90506101f461ffff8516111561256e576040516333a27d9760e21b815260040160405180910390fd5b6002810180547fffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff16600160e01b61ffff8716908102919091179091556040519081526001600160a01b038616907fa978cb3745fe012b6e358b0f334bef6d60e2a405347b022f707648fbc302c9389060200161198a565b804710156125fb5763b12d13eb6000526004601cfd5b6000806000808486620186a0f161262257816000526073600b5360ff6020536016600b82f0505b5050565b6001600160a01b03811660009081526003602052604090206002810154600160f81b900460ff16612683576040517f9a510a6d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b825460028401546001600160801b03908116600163ffffffff8681168281018102878316918201808501020390921c929092026bffffffffffffffffffffffff600160801b86041690910201926126ec92600160e01b820490921691168585612bc6565b019392505050565b60006126fe612d21565b9050816001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561273e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061276291906135c2565b6001600160a01b0316816001600160a01b03161461262257816001600160a01b031663514e62fc82846001600160a01b03166375b238fc6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127ec91906135a9565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381865afa158015612835573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285991906135ef565b612622576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038116600090815260036020526040812060020154600160f01b900460ff168061094d5750816001600160a01b031663a6f32d436040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094d91906135ef565b6129268161288f565b15612413576040517fa637a0b500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025460005b818114612a445760006002828154811061297f5761297f61360a565b6000918252602090912001546040517f5004b7a00000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301526024820187905290911691508190635004b7a0906044016040805180830381865afa925050508015612a10575060408051601f3d908101601f19168201909252612a0d91810190613620565b60015b15612a3b57876001600160a01b0316826001600160a01b031603612a38575050505050505050565b50505b50600101612963565b506040517fc3c1444700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b638b78c6d8195433146114e8576382b429006000526004601cfd5b638b78c6d81980546001600160a01b039092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355565b60006401000000008210612ae657612ae6612d68565b5090565b600080600080600080612afe898989612688565b94506000612710860460005460029b909b0154600160d01b810461ffff9081168302600160e01b830482168402600160c01b90930482168402600160801b909e04909116929092028881018d01820183019d989c909b509950975095945050505050565b60008315612b94578360051b8501855b803580851160051b94855260209485185260406000209301818110612b725750505b501492915050565b6000600160801b8210612ae657612ae6612d68565b6000600160701b8210612ae657612ae6612d68565b600063ffffffff85166001600160801b0385168082028303612bed5760009250505061139a565b600163ffffffff86811682810192918716010183811881851102841880831015612c4d576006600163ffffffff8a16818101026401fffffffe8b831b16820102600019840180850290831b90920191909102030485800285040295509150815b81831015612d14576003850260021c600185901b5b6000612cf8888488030270ffffffffffffffffffffffffffffffffff811160071b81811c68ffffffffffffffffff1060061b1781811c64ffffffffff1060051b1781811c62ffffff1060041b1781811c620100000160b5600192831c1b0260121c80830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c908190048111900390565b820288900498909801975060018086019585900301612c625750505b5050505050949350505050565b336e2fd5aeb385d324b580fca7c838239f198101612d6557602060008060006e2fd5aeb385d324b580fca7c83823a05afa612d5b57600080fd5b506000513d602014025b90565b6335278d126000526004601cfd5b828054828255906000526020600020908101928215612dd6579160200282015b82811115612dd657815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03843516178255602090920191600190910190612d96565b50612ae69291505b80821115612ae65760008155600101612dde565b600060208284031215612e0457600080fd5b81356001600160e01b03198116811461228d57600080fd5b6001600160a01b038116811461241357600080fd5b600060208284031215612e4357600080fd5b813561228d81612e1c565b60008083601f840112612e6057600080fd5b50813567ffffffffffffffff811115612e7857600080fd5b6020830191508360208260051b8501011115612e9357600080fd5b9250929050565b60008060008060008060a08789031215612eb357600080fd5b8635612ebe81612e1c565b9550602087013567ffffffffffffffff811115612eda57600080fd5b612ee689828a01612e4e565b909650945050604087013592506060870135612f0181612e1c565b80925050608087013590509295509295509295565b803563ffffffff8116811461268357600080fd5b60008060408385031215612f3d57600080fd5b8235612f4881612e1c565b9150612f5660208401612f16565b90509250929050565b80356bffffffffffffffffffffffff8116811461268357600080fd5b80356001600160801b038116811461268357600080fd5b803561ffff8116811461268357600080fd5b6000806000806000806000806000806000806101808d8f031215612fc757600080fd5b8c35612fd281612e1c565b9b50612fe060208e01612f5f565b9a50612fee60408e01612f7b565b9950612ffc60608e01612f7b565b985061300a60808e01612f16565b975061301860a08e01612f16565b965061302660c08e01612f16565b955061303460e08e01612f92565b94506130436101008e01612f92565b93506130526101208e01612f92565b92506101408d013561306381612e1c565b809250506101608d013590509295989b509295989b509295989b565b60008060006060848603121561309457600080fd5b833561309f81612e1c565b92506130ad60208501612f16565b91506130bb60408501612f16565b90509250925092565b6000602082840312156130d657600080fd5b61228d82612f92565b600080602083850312156130f257600080fd5b823567ffffffffffffffff81111561310957600080fd5b61311585828601612e4e565b90969095509350505050565b6000806040838503121561313457600080fd5b823561313f81612e1c565b9150612f5660208401612f92565b6020808252825182820181905260009190848201906040850190845b8181101561318e5783516001600160a01b031683529284019291840191600101613169565b50909695505050505050565b600080600080606085870312156131b057600080fd5b84356131bb81612e1c565b935060208501356131cb81612e1c565b9250604085013567ffffffffffffffff8111156131e757600080fd5b6131f387828801612e4e565b95989497509550505050565b6000806040838503121561321257600080fd5b823561321d81612e1c565b9150612f5660208401612f7b565b600080600080600080600060c0888a03121561324657600080fd5b873561325181612e1c565b9650602088013561326181612e1c565b955061326f60408901612f16565b9450606088013561327f81612e1c565b9350608088013567ffffffffffffffff81111561329b57600080fd5b6132a78a828b01612e4e565b989b979a5095989497959660a090950135949350505050565b600080604083850312156132d357600080fd5b82356132de81612e1c565b9150612f5660208401612f5f565b600080604083850312156132ff57600080fd5b823561330a81612e1c565b946020939093013593505050565b6000806040838503121561332b57600080fd5b823561333681612e1c565b9150602083013561334681612e1c565b809150509250929050565b81516bffffffffffffffffffffffff1681526101a08101602083015161338260208401826001600160801b03169052565b50604083015161339d60408401826001600160801b03169052565b5060608301516133b5606084018263ffffffff169052565b5060808301516133d060808401826001600160801b03169052565b5060a08301516133eb60a08401826001600160801b03169052565b5060c083015161340360c084018263ffffffff169052565b5060e083015161341b60e084018263ffffffff169052565b506101008381015163ffffffff16908301526101208084015161ffff9081169184019190915261014080850151821690840152610160808501519091169083015261018092830151929091019190915290565b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8311156134a057600080fd5b8260051b80836020870137939093016020019392505050565b6001600160a01b03841681526040602082015260006134dc60408301848661346e565b95945050505050565b63ffffffff8516815260606020820152600061350560608301858761346e565b90506001600160801b038316604083015295945050505050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561094d5761094d61351f565b60208082528181018390526000908460408401835b8681101561358b57823561357081612e1c565b6001600160a01b03168252918301919083019060010161355d565b509695505050505050565b8082018082111561094d5761094d61351f565b6000602082840312156135bb57600080fd5b5051919050565b6000602082840312156135d457600080fd5b815161228d81612e1c565b8051801515811461268357600080fd5b60006020828403121561360157600080fd5b61228d826135df565b634e487b7160e01b600052603260045260246000fd5b6000806040838503121561363357600080fd5b825161363e81612e1c565b9150612f56602084016135df56fea2646970667358221220f6a1f7b056f08fb9b6cfee9e08f4a85d243d1a68f932e8a7d47ed381743c014d64736f6c63430008130033

Deployed Bytecode

0x6080604052600436106103135760003560e01c80639a3befc81161019a578063d1197d8a116100e1578063ed14834f1161008a578063f574029611610064578063f574029614610890578063fb015260146108b0578063fee81cf4146108d057600080fd5b8063ed14834f1461084a578063f04e283e1461086a578063f2fde38b1461087d57600080fd5b8063e1a45218116100bb578063e1a45218146107e5578063e9b3d5e7146107fb578063ebaaa3a11461082857600080fd5b8063d1197d8a14610791578063d7533f02146107b1578063dc2b66e8146107cf57600080fd5b8063b27c350411610143578063bbd1b0ee1161011d578063bbd1b0ee1461072f578063bd51f99e1461074f578063c7dd32281461076f57600080fd5b8063b27c3504146106cf578063b7711cbf146106ef578063bb06b9141461070f57600080fd5b8063ac1fc22c11610174578063ac1fc22c14610666578063ae6a7a8b1461069c578063afab4364146106bc57600080fd5b80639a3befc8146105dc5780639c186843146105fe578063aa2300b01461064657600080fd5b80635bb028441161025e5780638b7c895d116102075780639375da5a116101e15780639375da5a1461057c578063954c40091461059c57806399136dae146105bc57600080fd5b80638b7c895d146105435780638d01513c146103645780638da5cb5b1461056357600080fd5b80635dcbb465116102385780635dcbb4651461051b5780636c5f55f714610364578063715018a61461053b57600080fd5b80635bb02844146104bb5780635cb3a54e146104db5780635cbc742c146104fb57600080fd5b806326a36f59116102c057806341f6ec4f1161029a57806341f6ec4f1461045b57806345091b401461047b57806354d1f13d146104b357600080fd5b806326a36f59146103ed57806334cf8f0e1461040d57806336765d591461042d57600080fd5b806322163b86116102f157806322163b861461038d578063241ec00b146103c557806325692962146103e557600080fd5b806301ffc9a71461031857806308bfa2bf1461034d5780630d8a845614610364575b600080fd5b34801561032457600080fd5b50610338610333366004612df2565b610903565b60405190151581526020015b60405180910390f35b34801561035957600080fd5b50610362610953565b005b34801561037057600080fd5b5061037a6101f481565b60405161ffff9091168152602001610344565b34801561039957600080fd5b506000546103ad906001600160801b031681565b6040516001600160801b039091168152602001610344565b3480156103d157600080fd5b506103626103e0366004612e31565b610a33565b610362610b16565b3480156103f957600080fd5b50610362610408366004612e9a565b610b66565b34801561041957600080fd5b50610362610428366004612f2a565b610e54565b34801561043957600080fd5b5061044d610448366004612e31565b610f33565b604051908152602001610344565b34801561046757600080fd5b50610362610476366004612fa4565b610f48565b34801561048757600080fd5b5061049b610496366004612e31565b6112b3565b6040516001600160a01b039091168152602001610344565b610362611349565b3480156104c757600080fd5b5061044d6104d636600461307f565b611385565b3480156104e757600080fd5b5061044d6104f636600461307f565b6113a2565b34801561050757600080fd5b506103626105163660046130c4565b6113ff565b34801561052757600080fd5b506103ad610536366004612e31565b6114b8565b6103626114d6565b34801561054f57600080fd5b5061036261055e3660046130df565b6114ea565b34801561056f57600080fd5b50638b78c6d8195461049b565b34801561058857600080fd5b50610362610597366004612e31565b61153c565b3480156105a857600080fd5b506103626105b7366004612f2a565b6115c6565b3480156105c857600080fd5b506103626105d7366004613121565b61169b565b3480156105e857600080fd5b506105f1611750565b604051610344919061314d565b34801561060a57600080fd5b5061061e61061936600461307f565b6117b2565b604080519586526020860194909452928401919091526060830152608082015260a001610344565b34801561065257600080fd5b5061033861066136600461319a565b61187d565b34801561067257600080fd5b506103ad610681366004612e31565b6004602052600090815260409020546001600160801b031681565b3480156106a857600080fd5b506103626106b73660046131ff565b611908565b6103626106ca36600461322b565b611999565b3480156106db57600080fd5b506103626106ea366004613121565b611fd4565b3480156106fb57600080fd5b5061036261070a366004612f2a565b612089565b34801561071b57600080fd5b5061036261072a3660046131ff565b612106565b34801561073b57600080fd5b5061036261074a3660046132c0565b612187565b34801561075b57600080fd5b5061036261076a3660046132ec565b612225565b34801561077b57600080fd5b5060405163a3c2dbc760e01b8152602001610344565b34801561079d57600080fd5b506103386107ac366004613318565b61227f565b3480156107bd57600080fd5b506040516202a3008152602001610344565b3480156107db57600080fd5b5061037a6103e881565b3480156107f157600080fd5b5061037a61271081565b34801561080757600080fd5b5061081b610816366004612e31565b612294565b6040516103449190613351565b34801561083457600080fd5b5060005461037a90600160801b900461ffff1681565b34801561085657600080fd5b5060015461049b906001600160a01b031681565b610362610878366004612e31565b6123d6565b61036261088b366004612e31565b612416565b34801561089c57600080fd5b506103626108ab366004612e31565b61243d565b3480156108bc57600080fd5b506103626108cb366004613121565b612526565b3480156108dc57600080fd5b5061044d6108eb366004612e31565b63389a75e1600c908152600091909152602090205490565b60006001600160e01b031982167f01ffc9a700000000000000000000000000000000000000000000000000000000148061094d57506001600160e01b0319821663a3c2dbc760e01b145b92915050565b600054600160901b900460ff161561096a57600080fd5b6000805460ff60901b1916600160901b1790556001546001600160a01b0316806109a7576040516362ccef3360e01b815260040160405180910390fd5b6000546001600160801b03168015610a2257600080546fffffffffffffffffffffffffffffffff191690556109e5826001600160801b0383166125e5565b6040516001600160801b03821681527fa8a9aa21b43d916fdaf4bdf9975892e984e7dbe00c0befea632d6fe5bbead73a9060200160405180910390a15b50506000805460ff60901b19169055565b600054600160901b900460ff1615610a4a57600080fd5b6000805460ff60901b1916600160901b178155610a6682612626565b60018101549091506001600160701b03168015610b04576001820180546dffffffffffffffffffffffffffff191690556000610aa1846112b3565b9050610ab681836001600160801b03166125e5565b6040516001600160801b03831681526001600160a01b0380831691908616907fe9d03ae127c81928b88a95c4fb19c4e0451215b9c03456a73faef64de215f2cc9060200160405180910390a3505b50506000805460ff60901b1916905550565b60006202a30067ffffffffffffffff164201905063389a75e1600c5233600052806020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a250565b600054600160901b900460ff1615610b7d57600080fd5b6000805460ff60901b1916600160901b1781558490819003610bcb576040517fca67be2000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610bd688612626565b6001810154909150600160e01b900463ffffffff1682811015610c34576040517f9e4c446100000000000000000000000000000000000000000000000000000000815260048101829052602481018490526044015b60405180910390fd5b8281036000610c44848387612688565b905087811015610c8a576040517fda3db5b00000000000000000000000000000000000000000000000000000000081526004810182905260248101899052604401610c2b565b6001840180546001600160e01b0316600160e01b63ffffffff8516021790819055600160701b90046001600160701b031681811015610d25576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f57544600000000000000000000000000000000000000000000000000000000006044820152606401610c2b565b6001850180547fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff16600160701b8484036001600160701b0316021790556040517fad66829f0000000000000000000000000000000000000000000000000000000081526001600160a01b038d169063ad66829f90610dab9033908f908f906004016134b9565b600060405180830381600087803b158015610dc557600080fd5b505af1158015610dd9573d6000803e3d6000fd5b50505050610de788836125e5565b86886001600160a01b03168d6001600160a01b03167f944b3f0b3c7f4118bf6e875f507afdd5eaafb7679ff8753036c6004bfcece497878f8f88604051610e3194939291906134e5565b60405180910390a450506000805460ff60901b1916905550505050505050505050565b81610e5e816126f4565b6000610e6984612626565b600281015490915063ffffffff600160801b90910481169084161115610eb057610e928461288f565b15610eb05760405163066f305360e21b815260040160405180910390fd5b6002810180547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff16600160801b63ffffffff8616908102919091179091556040519081526001600160a01b038516907f23cb1f116dd4d609eb56f337c5dc684f6b86077a9f40eb92f230715d6a1bd148906020015b60405180910390a250505050565b6000610f3e82612626565b6003015492915050565b610f518c6126f4565b610f5a8c61291d565b8663ffffffff16600003610f815760405163066f305360e21b815260040160405180910390fd5b8563ffffffff16600003610fa8576040516337a7abd960e01b815260040160405180910390fd5b6103e861ffff86161115610fcf57604051633a53216960e11b815260040160405180910390fd5b6101f461ffff85161115610ff6576040516333a27d9760e21b815260040160405180910390fd5b6101f461ffff8416111561101d57604051631a52ce6f60e01b815260040160405180910390fd5b6110288c838361295d565b6001600160a01b038c1660009081526003602052604090206002810154600160f81b900460ff1615611086576040517ffa5190c400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8b8160000160106101000a8154816bffffffffffffffffffffffff02191690836bffffffffffffffffffffffff1602179055508a8160020160006101000a8154816001600160801b0302191690836001600160801b03160217905550898160000160006101000a8154816001600160801b0302191690836001600160801b031602179055508881600001601c6101000a81548163ffffffff021916908363ffffffff160217905550878160020160106101000a81548163ffffffff021916908363ffffffff160217905550868160020160146101000a81548163ffffffff021916908363ffffffff160217905550858160020160186101000a81548161ffff021916908361ffff1602179055508481600201601c6101000a81548161ffff021916908361ffff1602179055508381600201601a6101000a81548161ffff021916908361ffff160217905550600181600201601f6101000a81548160ff0219169083151502179055508c6001600160a01b03167f8cde7b696b606d38ecf5d8a7c3ee73d9c309af7d1d1015bee3d7c936995ed90f8d8d8d8d8d8d8d8d8d60405161129c999897969594939291906bffffffffffffffffffffffff9990991689526001600160801b0397881660208a015295909616604088015263ffffffff9384166060880152918316608087015290911660a085015261ffff90811660c085015291821660e0840152166101008201526101200190565b60405180910390a250505050505050505050505050565b6000819050633684d100600052602060006004601c855afa60203d14166112d957600080fd5b600051634baca2b5600052826020526020806024601c845afa905080611303573d61130357600080fd5b8060203d14161561134357636352211e600052602060006024601c865afa905080611332573d61133257600080fd5b8060203d1416156113435760005191505b50919050565b63389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2565b600061139a61139385612626565b8484612688565b949350505050565b6000806113ae85612626565b60018101549091506000906113d39063ffffffff80881691600160e01b900416613535565b905060006113e763ffffffff861683613535565b90506113f4838287612688565b979650505050505050565b611407612a77565b6101f461ffff82161115611447576040517f3d1e858400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080547fffffffffffffffffffffffffffff0000ffffffffffffffffffffffffffffffff16600160801b61ffff8416908102919091179091556040519081527f1426859b6b96e2e9ae302b23a42f763f4b0ae916a71a093e61c77120458b2e95906020015b60405180910390a150565b60006114c382612626565b600101546001600160701b031692915050565b6114de612a77565b6114e86000612a92565b565b6114f2612a77565b6114fe60028383612d76565b507f2064bc349588754d7a319f7e3e19098d6c481de9010cb8faabc2e4d1ccb8a9c68282604051611530929190613548565b60405180910390a15050565b611544612a77565b6001600160a01b03811661156b576040516362ccef3360e01b815260040160405180910390fd5b6001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383169081179091556040519081527fda1940b15ab63ed4db791f1c7ec186c01a546f6ce58fa1dcc0561b8638a1bd12906020016114ad565b816115d0816126f4565b60006115db84612626565b600281015490915063ffffffff600160a01b90910481169084161115611622576116048461288f565b15611622576040516337a7abd960e01b815260040160405180910390fd5b6002810180547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff16600160a01b63ffffffff8616908102919091179091556040519081526001600160a01b038516907fd85122012af450d91e115e674dcb75510396079ec3f9add017bfd6029ac57c3190602001610f25565b816116a5816126f4565b60006116b084612626565b90506101f461ffff841611156116d957604051631a52ce6f60e01b815260040160405180910390fd5b6002810180547fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff16600160d01b61ffff8616908102919091179091556040519081526001600160a01b038516907fbc4b9cc81e8abf70807d993342483076cb584d9453ea4243b108310dd44c87ee90602001610f25565b606060028054806020026020016040519081016040528092919081815260200182805480156117a857602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161178a575b5050505050905090565b6000806000806000806117c489612626565b60018101549091506000906117e99063ffffffff808c1691600160e01b900416613596565b600283015490915063ffffffff600160801b90910481169061180d908a1683613596565b1115611852576002820154611830908290600160801b900463ffffffff16613535565b60405163af73298160e01b815263ffffffff9091166004820152602401610c2b565b6118658261185f83612ad0565b8a612aea565b949f929e50909c509a50919850909650505050505050565b60008061188986612626565b600301549050806118a75750506001600160a01b038316151561139a565b6001600160a01b038516158015906118fe57506040516bffffffffffffffffffffffff19606087901b1660208201526118fe9085908590849060340160405160208183030381529060405280519060200120612b62565b9695505050505050565b81611912816126f4565b8261191c8161291d565b600061192785612626565b6002810180546fffffffffffffffffffffffffffffffff19166001600160801b0387169081179091556040519081529091506001600160a01b038616907faf9934e1e24ed8c894e4dc1c9a96f50ae8d56628b7066199edc3f2ca245378a4906020015b60405180910390a25050505050565b600054600160901b900460ff16156119b057600080fd5b6000805460ff60901b1916600160901b17815563ffffffff86169003611a02576040517fb562e8dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611a6a60405180610160016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b031681526020016000151581525090565b6000611a7589612626565b63ffffffff8089166101008501526001600160a01b0388166101208501526001820154600160e01b9004811684526002820154919250600160a01b909104164210611aec576040517fdf3981b000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611afb81836000015189612aea565b60e088015260c087015260a08601526080850152606084015260408301819052341015611b635760408083015190517ff3ebc3840000000000000000000000000000000000000000000000000000000081523460048201526024810191909152604401610c2b565b60028101546101008301518351600160801b90920463ffffffff1691011115611bbb578151600282015460405163af73298160e01b815263ffffffff600160801b909204821692909203166004820152602401610c2b565b611bc78987878761187d565b158015610140840152611c565760e082015115611c515760e08201516001600160a01b038716600090815260046020526040902054611c11916001600160801b0390911601612b9c565b6001600160a01b038716600090815260046020526040902080546fffffffffffffffffffffffffffffffff19166001600160801b03929092169190911790555b611cad565b6001600160a01b03861615611c97576040517f20d6c38900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60e08201805160a0840180519091019052600090525b608082015115611cfe576080820151600054611cd4916001600160801b0390911601612b9c565b600080546fffffffffffffffffffffffffffffffff19166001600160801b03929092169190911790555b60c082015115611d515760c08201516001820154611d27916001600160701b0390911601612bb1565b6001820180546dffffffffffffffffffffffffffff19166001600160701b03929092169190911790555b60608201516001820154611d7691600160701b9091046001600160701b031601612bb1565b6001820180546001600160701b0392909216600160701b027fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff9092169190911790556101008201518251611dca9101612ad0565b6001820180546001600160e01b0316600160e01b63ffffffff93841602179055600282018054600160f01b7fff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90911617905560a08301516040517f6f134cf40000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152928a166024820152918b1691636f134cf4919060440160206040518083038185885af1158015611e8b573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611eb091906135a9565b60208301526040820151341115611ed157611ed133836040015134036125e5565b82886001600160a01b03168a6001600160a01b03167f15845fbb9632d61f45d5c5fdd89d6caa7e378568af4cd871d42622224fdef75085602001518660000151876101000151886040015189608001518a60a001518b60c001518c60e001518d61012001518e6101400151604051611fb49a99989796959493929190998a5263ffffffff98891660208b01529690971660408901526001600160801b039485166060890152928416608088015290831660a0870152821660c08601521660e08401526001600160a01b039190911661010083015215156101208201526101400190565b60405180910390a450506000805460ff60901b1916905550505050505050565b81611fde816126f4565b6000611fe984612626565b90506103e861ffff8416111561201257604051633a53216960e11b815260040160405180910390fd5b6002810180547fffffffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b61ffff8616908102919091179091556040519081526001600160a01b038516907fc1f9d307740252602e3d93a4e35515536b7bdc62f0cbeb8e4ef65186f25e45bb90602001610f25565b81612093816126f4565b8261209d8161291d565b60006120a885612626565b80546001600160e01b0316600160e01b63ffffffff87169081029190911782556040519081529091506001600160a01b038616907f40b551a5bfa5b9a3ca031f8a3b912f66a42567c869b7df66b3d05d791ac985f09060200161198a565b81612110816126f4565b8261211a8161291d565b600061212585612626565b80546fffffffffffffffffffffffffffffffff19166001600160801b03861690811782556040519081529091506001600160a01b038616907f42aa13794032388632d506ac79fbb376ccf220fa0f83178cf1f26f6fb37c63889060200161198a565b81612191816126f4565b8261219b8161291d565b60006121a685612626565b80547fffffffff000000000000000000000000ffffffffffffffffffffffffffffffff16600160801b6bffffffffffffffffffffffff87169081029190911782556040519081529091506001600160a01b038616907f25626c9c16fddd2ddcf085e04ee7e54af24bd69023afef74c1a33ee6fc77dd1d9060200161198a565b8161222f816126f4565b600061223a84612626565b600381018490556040518481529091506001600160a01b038516907f89239be3d24ce581b82b186bce054ab48a0c360101cee4c9352efda104b7580890602001610f25565b600061228d8383368461187d565b9392505050565b604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290529061230683612626565b8054600160801b8082046bffffffffffffffffffffffff1685526001600160801b03808316604087015260028401549081166020870152600160e01b9283900463ffffffff908116606088015260018501546001600160701b0380821660808a0152858204831660c08a0152600160701b9091041660a0880152918104821660e0870152600160a01b8104909116610100860152600160c01b810461ffff908116610120870152600160d01b82048116610140870152919004166101608401526003015461018083015250919050565b6123de612a77565b63389a75e1600c52806000526020600c20805442111561240657636f5e88186000526004601cfd5b6000905561241381612a92565b50565b61241e612a77565b8060601b61243457637448fbae6000526004601cfd5b61241381612a92565b600054600160901b900460ff161561245457600080fd5b6000805460ff60901b1916600160901b1781556001600160a01b0382168152600460205260409020546001600160801b03168015610a22576001600160a01b038216600090815260046020526040902080546fffffffffffffffffffffffffffffffff191690556124ce826001600160801b0383166125e5565b6040516001600160801b03821681526001600160a01b038316907f0a1adaaf9d9caba9cf65528900e946b718d511ebd66ae81d5eb71e7fd0122c4a9060200160405180910390a250506000805460ff60901b19169055565b81612530816126f4565b8261253a8161291d565b600061254585612626565b90506101f461ffff8516111561256e576040516333a27d9760e21b815260040160405180910390fd5b6002810180547fffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff16600160e01b61ffff8716908102919091179091556040519081526001600160a01b038616907fa978cb3745fe012b6e358b0f334bef6d60e2a405347b022f707648fbc302c9389060200161198a565b804710156125fb5763b12d13eb6000526004601cfd5b6000806000808486620186a0f161262257816000526073600b5360ff6020536016600b82f0505b5050565b6001600160a01b03811660009081526003602052604090206002810154600160f81b900460ff16612683576040517f9a510a6d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b825460028401546001600160801b03908116600163ffffffff8681168281018102878316918201808501020390921c929092026bffffffffffffffffffffffff600160801b86041690910201926126ec92600160e01b820490921691168585612bc6565b019392505050565b60006126fe612d21565b9050816001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561273e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061276291906135c2565b6001600160a01b0316816001600160a01b03161461262257816001600160a01b031663514e62fc82846001600160a01b03166375b238fc6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127ec91906135a9565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381865afa158015612835573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285991906135ef565b612622576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038116600090815260036020526040812060020154600160f01b900460ff168061094d5750816001600160a01b031663a6f32d436040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094d91906135ef565b6129268161288f565b15612413576040517fa637a0b500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025460005b818114612a445760006002828154811061297f5761297f61360a565b6000918252602090912001546040517f5004b7a00000000000000000000000000000000000000000000000000000000081526001600160a01b0387811660048301526024820187905290911691508190635004b7a0906044016040805180830381865afa925050508015612a10575060408051601f3d908101601f19168201909252612a0d91810190613620565b60015b15612a3b57876001600160a01b0316826001600160a01b031603612a38575050505050505050565b50505b50600101612963565b506040517fc3c1444700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b638b78c6d8195433146114e8576382b429006000526004601cfd5b638b78c6d81980546001600160a01b039092169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355565b60006401000000008210612ae657612ae6612d68565b5090565b600080600080600080612afe898989612688565b94506000612710860460005460029b909b0154600160d01b810461ffff9081168302600160e01b830482168402600160c01b90930482168402600160801b909e04909116929092028881018d01820183019d989c909b509950975095945050505050565b60008315612b94578360051b8501855b803580851160051b94855260209485185260406000209301818110612b725750505b501492915050565b6000600160801b8210612ae657612ae6612d68565b6000600160701b8210612ae657612ae6612d68565b600063ffffffff85166001600160801b0385168082028303612bed5760009250505061139a565b600163ffffffff86811682810192918716010183811881851102841880831015612c4d576006600163ffffffff8a16818101026401fffffffe8b831b16820102600019840180850290831b90920191909102030485800285040295509150815b81831015612d14576003850260021c600185901b5b6000612cf8888488030270ffffffffffffffffffffffffffffffffff811160071b81811c68ffffffffffffffffff1060061b1781811c64ffffffffff1060051b1781811c62ffffff1060041b1781811c620100000160b5600192831c1b0260121c80830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c908190048111900390565b820288900498909801975060018086019585900301612c625750505b5050505050949350505050565b336e2fd5aeb385d324b580fca7c838239f198101612d6557602060008060006e2fd5aeb385d324b580fca7c83823a05afa612d5b57600080fd5b506000513d602014025b90565b6335278d126000526004601cfd5b828054828255906000526020600020908101928215612dd6579160200282015b82811115612dd657815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03843516178255602090920191600190910190612d96565b50612ae69291505b80821115612ae65760008155600101612dde565b600060208284031215612e0457600080fd5b81356001600160e01b03198116811461228d57600080fd5b6001600160a01b038116811461241357600080fd5b600060208284031215612e4357600080fd5b813561228d81612e1c565b60008083601f840112612e6057600080fd5b50813567ffffffffffffffff811115612e7857600080fd5b6020830191508360208260051b8501011115612e9357600080fd5b9250929050565b60008060008060008060a08789031215612eb357600080fd5b8635612ebe81612e1c565b9550602087013567ffffffffffffffff811115612eda57600080fd5b612ee689828a01612e4e565b909650945050604087013592506060870135612f0181612e1c565b80925050608087013590509295509295509295565b803563ffffffff8116811461268357600080fd5b60008060408385031215612f3d57600080fd5b8235612f4881612e1c565b9150612f5660208401612f16565b90509250929050565b80356bffffffffffffffffffffffff8116811461268357600080fd5b80356001600160801b038116811461268357600080fd5b803561ffff8116811461268357600080fd5b6000806000806000806000806000806000806101808d8f031215612fc757600080fd5b8c35612fd281612e1c565b9b50612fe060208e01612f5f565b9a50612fee60408e01612f7b565b9950612ffc60608e01612f7b565b985061300a60808e01612f16565b975061301860a08e01612f16565b965061302660c08e01612f16565b955061303460e08e01612f92565b94506130436101008e01612f92565b93506130526101208e01612f92565b92506101408d013561306381612e1c565b809250506101608d013590509295989b509295989b509295989b565b60008060006060848603121561309457600080fd5b833561309f81612e1c565b92506130ad60208501612f16565b91506130bb60408501612f16565b90509250925092565b6000602082840312156130d657600080fd5b61228d82612f92565b600080602083850312156130f257600080fd5b823567ffffffffffffffff81111561310957600080fd5b61311585828601612e4e565b90969095509350505050565b6000806040838503121561313457600080fd5b823561313f81612e1c565b9150612f5660208401612f92565b6020808252825182820181905260009190848201906040850190845b8181101561318e5783516001600160a01b031683529284019291840191600101613169565b50909695505050505050565b600080600080606085870312156131b057600080fd5b84356131bb81612e1c565b935060208501356131cb81612e1c565b9250604085013567ffffffffffffffff8111156131e757600080fd5b6131f387828801612e4e565b95989497509550505050565b6000806040838503121561321257600080fd5b823561321d81612e1c565b9150612f5660208401612f7b565b600080600080600080600060c0888a03121561324657600080fd5b873561325181612e1c565b9650602088013561326181612e1c565b955061326f60408901612f16565b9450606088013561327f81612e1c565b9350608088013567ffffffffffffffff81111561329b57600080fd5b6132a78a828b01612e4e565b989b979a5095989497959660a090950135949350505050565b600080604083850312156132d357600080fd5b82356132de81612e1c565b9150612f5660208401612f5f565b600080604083850312156132ff57600080fd5b823561330a81612e1c565b946020939093013593505050565b6000806040838503121561332b57600080fd5b823561333681612e1c565b9150602083013561334681612e1c565b809150509250929050565b81516bffffffffffffffffffffffff1681526101a08101602083015161338260208401826001600160801b03169052565b50604083015161339d60408401826001600160801b03169052565b5060608301516133b5606084018263ffffffff169052565b5060808301516133d060808401826001600160801b03169052565b5060a08301516133eb60a08401826001600160801b03169052565b5060c083015161340360c084018263ffffffff169052565b5060e083015161341b60e084018263ffffffff169052565b506101008381015163ffffffff16908301526101208084015161ffff9081169184019190915261014080850151821690840152610160808501519091169083015261018092830151929091019190915290565b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8311156134a057600080fd5b8260051b80836020870137939093016020019392505050565b6001600160a01b03841681526040602082015260006134dc60408301848661346e565b95945050505050565b63ffffffff8516815260606020820152600061350560608301858761346e565b90506001600160801b038316604083015295945050505050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561094d5761094d61351f565b60208082528181018390526000908460408401835b8681101561358b57823561357081612e1c565b6001600160a01b03168252918301919083019060010161355d565b509695505050505050565b8082018082111561094d5761094d61351f565b6000602082840312156135bb57600080fd5b5051919050565b6000602082840312156135d457600080fd5b815161228d81612e1c565b8051801515811461268357600080fd5b60006020828403121561360157600080fd5b61228d826135df565b634e487b7160e01b600052603260045260246000fd5b6000806040838503121561363357600080fd5b825161363e81612e1c565b9150612f56602084016135df56fea2646970667358221220f6a1f7b056f08fb9b6cfee9e08f4a85d243d1a68f932e8a7d47ed381743c014d64736f6c63430008130033

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
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.