Sepolia Testnet

Contract

0xeAF3114423a85c778c681638496591EEfC3a15Bc

Overview

ETH Balance

54.947385189264169659 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Buy Keys With Pa...58213522024-05-02 11:52:00354 days ago1714650720IN
0xeAF31144...EfC3a15Bc
0.00441924 ETH0.001352347.52772009
Buy Keys58201682024-05-02 7:31:00354 days ago1714635060IN
0xeAF31144...EfC3a15Bc
0.002475 ETH0.000459053.66987216
Buy Keys With Pa...58150222024-05-01 12:12:00355 days ago1714565520IN
0xeAF31144...EfC3a15Bc
0.00453507 ETH0.000350831.95278816
Buy Keys58142202024-05-01 9:05:48355 days ago1714554348IN
0xeAF31144...EfC3a15Bc
0.00006875 ETH0.000066450.53125279
Buy Keys With Pa...58120212024-05-01 0:41:48355 days ago1714524108IN
0xeAF31144...EfC3a15Bc
0.00440541 ETH0.000179741.00048099
Pay58118322024-05-01 0:01:12355 days ago1714521672IN
0xeAF31144...EfC3a15Bc
0.00265211 ETH0.000038050.50046383
Buy Keys With Pa...58112862024-04-30 22:01:12356 days ago1714514472IN
0xeAF31144...EfC3a15Bc
0.01848639 ETH0.000179751.00051276
Pay58107232024-04-30 20:00:00356 days ago1714507200IN
0xeAF31144...EfC3a15Bc
0.00340139 ETH0.00008021.05458069
Pay58102022024-04-30 18:03:36356 days ago1714500216IN
0xeAF31144...EfC3a15Bc
0.00335334 ETH0.000121531.59791917
Pay58101982024-04-30 18:02:48356 days ago1714500168IN
0xeAF31144...EfC3a15Bc
0.00335334 ETH0.000115361.51680136
Buy Keys58095092024-04-30 15:32:48356 days ago1714491168IN
0xeAF31144...EfC3a15Bc
0.00171875 ETH0.000887917.09835116
Pay58090442024-04-30 13:49:00356 days ago1714484940IN
0xeAF31144...EfC3a15Bc
0.00265506 ETH0.0009832612.93007953
Pay58090272024-04-30 13:45:00356 days ago1714484700IN
0xeAF31144...EfC3a15Bc
0.00265332 ETH0.0010941914.38650142
Buy Keys With Pa...58084532024-04-30 11:33:24356 days ago1714476804IN
0xeAF31144...EfC3a15Bc
0.00435463 ETH0.001393947.75929726
Pay58071792024-04-30 6:39:24356 days ago1714459164IN
0xeAF31144...EfC3a15Bc
0.0025231 ETH0.00026753.51719983
Buy Keys With Pa...58043612024-04-29 19:46:00357 days ago1714419960IN
0xeAF31144...EfC3a15Bc
0.00416989 ETH0.000139260.77529812
Buy Keys With Pa...58031162024-04-29 15:14:36357 days ago1714403676IN
0xeAF31144...EfC3a15Bc
0.00416148 ETH0.000737244.1035392
Buy Keys With Pa...58026842024-04-29 13:41:24357 days ago1714398084IN
0xeAF31144...EfC3a15Bc
0.00421054 ETH0.000367792.04727904
Pay58025432024-04-29 13:10:24357 days ago1714396224IN
0xeAF31144...EfC3a15Bc
0.00158004 ETH0.000125711.6529419
Buy Keys With Pa...58024812024-04-29 12:56:24357 days ago1714395384IN
0xeAF31144...EfC3a15Bc
0.00227624 ETH0.000332021.84845371
Pay58022322024-04-29 12:00:48357 days ago1714392048IN
0xeAF31144...EfC3a15Bc
0.00158329 ETH0.00017312.27633153
Sell Keys58022092024-04-29 11:55:48357 days ago1714391748IN
0xeAF31144...EfC3a15Bc
0 ETH0.00026572.41211845
Buy Keys58021912024-04-29 11:52:00357 days ago1714391520IN
0xeAF31144...EfC3a15Bc
0.00006875 ETH0.000281882.25351181
Buy Keys58021542024-04-29 11:44:00357 days ago1714391040IN
0xeAF31144...EfC3a15Bc
0.00006875 ETH0.000199641.89255165
Buy Keys With Pa...58021012024-04-29 11:32:24357 days ago1714390344IN
0xeAF31144...EfC3a15Bc
0.00384805 ETH0.000356281.98321145
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Method Block
From
To
Add Reward58213522024-05-02 11:52:00354 days ago1714650720
0xeAF31144...EfC3a15Bc
0.0000024 ETH
Transfer58213522024-05-02 11:52:00354 days ago1714650720
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58213522024-05-02 11:52:00354 days ago1714650720
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Add Reward58201682024-05-02 7:31:00354 days ago1714635060
0xeAF31144...EfC3a15Bc
0.00009 ETH
Transfer58201682024-05-02 7:31:00354 days ago1714635060
0xeAF31144...EfC3a15Bc
0.0000675 ETH
Transfer58201682024-05-02 7:31:00354 days ago1714635060
0xeAF31144...EfC3a15Bc
0.0000675 ETH
Add Reward58150222024-05-01 12:12:00355 days ago1714565520
0xeAF31144...EfC3a15Bc
0.0000024 ETH
Transfer58150222024-05-01 12:12:00355 days ago1714565520
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58150222024-05-01 12:12:00355 days ago1714565520
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Add Reward58142202024-05-01 9:05:48355 days ago1714554348
0xeAF31144...EfC3a15Bc
0.0000025 ETH
Transfer58142202024-05-01 9:05:48355 days ago1714554348
0xeAF31144...EfC3a15Bc
0.00000187 ETH
Transfer58142202024-05-01 9:05:48355 days ago1714554348
0xeAF31144...EfC3a15Bc
0.00000187 ETH
Add Reward58120212024-05-01 0:41:48355 days ago1714524108
0xeAF31144...EfC3a15Bc
0.0000024 ETH
Transfer58120212024-05-01 0:41:48355 days ago1714524108
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58120212024-05-01 0:41:48355 days ago1714524108
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58118322024-05-01 0:01:12355 days ago1714521672
0xeAF31144...EfC3a15Bc
0.00265211 ETH
Add Reward58112862024-04-30 22:01:12356 days ago1714514472
0xeAF31144...EfC3a15Bc
0.0000024 ETH
Transfer58112862024-04-30 22:01:12356 days ago1714514472
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58112862024-04-30 22:01:12356 days ago1714514472
0xeAF31144...EfC3a15Bc
0.0000018 ETH
Transfer58107232024-04-30 20:00:00356 days ago1714507200
0xeAF31144...EfC3a15Bc
0.00340139 ETH
Transfer58102022024-04-30 18:03:36356 days ago1714500216
0xeAF31144...EfC3a15Bc
0.00335334 ETH
Transfer58101982024-04-30 18:02:48356 days ago1714500168
0xeAF31144...EfC3a15Bc
0.00335334 ETH
Add Reward58095092024-04-30 15:32:48356 days ago1714491168
0xeAF31144...EfC3a15Bc
0.0000625 ETH
Transfer58095092024-04-30 15:32:48356 days ago1714491168
0xeAF31144...EfC3a15Bc
0.00004687 ETH
Transfer58095092024-04-30 15:32:48356 days ago1714491168
0xeAF31144...EfC3a15Bc
0.00004687 ETH
View All Internal Transactions
Loading...
Loading

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

Contract Name:
MemefiKeys

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 15 runs

Other Settings:
paris EvmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 15 : MemefiKeys.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import {IMemefiManagement} from "../management/IMemefiManagement.sol";
import {MemefiSwapable} from "./MemefiSwapable.sol";
import {IFeesDistributor} from "./IFeesDistributor.sol";

contract MemefiKeys is MemefiSwapable, EIP712 {
    modifier onlyMainAdmin() {
        require(msg.sender == memefiManagement.mainAdmin(), "Not a main owner");
        _;
    }

    // --------- EVENTS ---------- //
    event Trade(
        address indexed trader,
        address indexed subject,
        uint256 keyAmount,
        uint256 tokenAmount,
        uint256 protocolFee,
        uint256 subjectFee,
        uint256 supply,
        uint256 nonce,
        uint256 rewardIndexOf,
        uint256 pendingRewards,
        bool isBuy,
        bool isSwapped
    );

    event Payed(
        address indexed payer,
        uint256 paymentType,
        address paymentToken,
        uint256 amount,
        uint256 nonce
    );

    event RewardAdded(
        address indexed subject,
        uint256 amount,
        uint256 rewardIndex,
        uint256[] nonces
    );

    event RewardWithdraw(
        address indexed receiver,
        address indexed subject,
        uint256 amount,
        uint256 rewardIndexOf
    );

    event NewSigner(address newSigner);

    event NewRewardDistributor(address newRewardDistributor);

    // --------- VARIABLES ---------- //
    uint256 public protocolFeePercent;
    uint256 public subjectFeePercent;
    uint256 public revenueFeePercent;
    uint256 public constant firstKeyPrice = 6e13; // 0,00006 ETH

    IFeesDistributor public feesDistributor;

    // Nonce => used times
    mapping(uint256 => uint256) public nonceUsingCount;

    // KeysSubject => (Holder => Balance)
    mapping(address => mapping(address => uint256)) public keysBalance;

    // KeysSubject => Supply
    mapping(address => uint256) public keysSupply;

    uint256 private constant MULTIPLIER = 1e18;
    // KeysSubject => RewardIndex
    mapping(address => uint256) private rewardIndex;
    // KeysSubject => (Holder => RewardIndex)
    mapping(address => mapping(address => uint256)) private rewardIndexOf;
    // KeysSubject => (Holder => Earned)
    mapping(address => mapping(address => uint256)) private earned;

    // --------- CONSTRUCTOR ---------- //

    constructor(
        address _memefiManagement
    )
        EIP712("Memefi", "1")
        MemefiSwapable(_memefiManagement)
    {
        feesDistributor = IFeesDistributor(memefiManagement.feesDistributor());
        protocolFeePercent = 30000000000000000;
        subjectFeePercent = 30000000000000000;
        revenueFeePercent = 40000000000000000;
    }

    // --------- ADMIN FUNCTIONS ---------- //

    function setFees(
        uint256 _protocolFeePercent,
        uint256 _subjectFeePercent,
        uint256 _revenueFeePercent
    ) public onlyMainAdmin {
        require(
            _protocolFeePercent + _subjectFeePercent + _revenueFeePercent <=
                100000000000000000,
            "Fees must be less than 10%"
        );
        protocolFeePercent = _protocolFeePercent;
        subjectFeePercent = _subjectFeePercent;
        revenueFeePercent = _revenueFeePercent;
    }

    // --------- MATH FUNCTIONS ---------- //
    function _calculatePriceAndFees(
        uint256 supply,
        uint256 amount
    ) internal view returns (uint256, uint256, uint256, uint256) {
        uint256 price = getPrice(supply, amount);
        (
            uint256 protocolFee,
            uint256 subjectFee,
            uint256 revenueFee
        ) = _calculateFees(price);
        return (price, protocolFee, subjectFee, revenueFee);
    }

    function _calculateFees(
        uint256 price
    ) internal view returns (uint256, uint256, uint256) {
        uint256 protocolFee = (price * protocolFeePercent) / 1 ether;
        uint256 subjectFee = (price * subjectFeePercent) / 1 ether;
        uint256 revenueFee = (price * revenueFeePercent) / 1 ether;
        return (protocolFee, subjectFee, revenueFee);
    }

    function getPrice(
        uint256 supply,
        uint256 amount
    ) public view returns (uint256) {
        if (amount == 0) return 0;
        if (supply == 0) {
            return firstKeyPrice + getPrice(1, amount - 1);
        }
        uint256 sum1 = ((supply - 1) * (supply) * (2 * (supply - 1) + 1)) / 6;
        uint256 sum2 = ((supply - 1 + amount) *
            (supply + amount) *
            (2 * (supply - 1 + amount) + 1)) / 6;
        uint256 summation = sum2 - sum1;
        uint256 price = ((summation * 1 ether) / 16000);

        if (isSwapped) {
            return _calculateMemefiFromEth(price);
        }
        return price;
    }

    function getBuyPrice(
        address keysSubject,
        uint256 amount
    ) public view returns (uint256) {
        return getPrice(keysSupply[keysSubject], amount);
    }

    function getSellPrice(
        address keysSubject,
        uint256 amount
    ) public view returns (uint256) {
        return getPrice(keysSupply[keysSubject] - amount, amount);
    }

    function getBuyPriceAfterFee(
        address keysSubject,
        uint256 amount
    ) public view returns (uint256) {
        uint256 price = getBuyPrice(keysSubject, amount);
        (
            uint256 protocolFee,
            uint256 subjectFee,
            uint256 revenueFee
        ) = _calculateFees(price);
        return price + protocolFee + subjectFee + revenueFee;
    }

    function getSellPriceAfterFee(
        address keysSubject,
        uint256 amount
    ) public view returns (uint256) {
        uint256 price = getSellPrice(keysSubject, amount);
        (
            uint256 protocolFee,
            uint256 subjectFee,
            uint256 revenueFee
        ) = _calculateFees(price);
        return price - protocolFee - subjectFee - revenueFee;
    }

    function calculateReward(
        address keysSubject,
        address account
    ) external view returns (uint256) {
        return
            earned[keysSubject][account] +
            _calculateRewards(keysSubject, account);
    }

    function _updateRewards(address keysSubject, address account) private {
        earned[keysSubject][account] += _calculateRewards(keysSubject, account);
        rewardIndexOf[keysSubject][account] = rewardIndex[keysSubject];
    }

    // --------- SIGNATURE FUNCTIONS ---------- //

    function _checkSignatureKeys(
        address paymentToken,
        uint256 paymentAmount,
        uint256[] memory itemIds,
        uint256[] memory itemMaxUsers,
        uint256 paymentType,
        uint256 nonce,
        uint256 deadline,
        bytes memory signature
    ) internal returns (bool) {
        require(deadline >= block.timestamp, "Signature expired");

        bytes32 typedHash = _hashTypedDataV4(
            keccak256(
                abi.encode(
                    keccak256(
                        "Payment(address executor,address paymentToken,uint256 paymentAmount,uint256[] itemIds,uint256[] itemMaxUsers,uint256 paymentType,uint256 nonce,uint256 deadline)"
                    ),
                    msg.sender,
                    paymentToken,
                    paymentAmount,
                    keccak256(abi.encodePacked(itemIds)),
                    keccak256(abi.encodePacked(itemMaxUsers)),
                    paymentType,
                    nonce,
                    deadline
                )
            )
        );

        return ECDSA.recover(typedHash, signature) == memefiManagement.signer();
    }

    function _checkSignatureRewards(
        address subject,
        uint256 amount,
        uint256 amountToSubject,
        uint256 nonce,
        bytes memory signature
    ) internal returns (bool) {
        bytes32 typedHash = _hashTypedDataV4(
            keccak256(
                abi.encode(
                    keccak256(
                        "AddReward(address subject,uint256 amount,uint256 amountToSubject,uint256 nonce)"
                    ),
                    subject,
                    amount,
                    amountToSubject,
                    nonce
                )
            )
        );

        return ECDSA.recover(typedHash, signature) == memefiManagement.signer();
    }

    // --------- REENTRENCY FUNCTIONS ---------- //

    function _useNonce(uint256 nonce, uint256 maxUseCount) internal {
        require(nonceUsingCount[nonce] < maxUseCount, "Nonce already used");
        nonceUsingCount[nonce] += 1;
    }

    // --------- MAIN FUNCTIONS ---------- //

    function _paymentTransfer(
        address paymentToken,
        uint256 paymentAmount,
        uint256 price,
        uint256 protocolFee,
        uint256 subjectFee,
        uint256 revenueFee
    ) internal {
        uint256 ethPaymentAmount = paymentToken == address(0)
            ? paymentAmount
            : 0;
        if (paymentToken == address(0)) {
            require(
                msg.value ==
                    price +
                        protocolFee +
                        subjectFee +
                        revenueFee +
                        ethPaymentAmount,
                "Insufficient payment"
            );
        } else {
            if (paymentAmount > 0) {
                IERC20(paymentToken).transferFrom(
                    msg.sender,
                    memefiManagement.treasury(),
                    paymentAmount
                );
            }
        }
    }

    function _addKeysBalanceAndSupply(
        address keysSubject,
        uint256 amount
    ) internal {
        keysBalance[keysSubject][msg.sender] += amount;
        keysSupply[keysSubject] += amount;
    }

    function _removeKeysBalanceAndSupply(
        address keysSubject,
        uint256 amount
    ) internal {
        keysBalance[keysSubject][msg.sender] -= amount;
        keysSupply[keysSubject] -= amount;
    }

    function _addKeysWithTransfer(
        address paymentToken,
        uint256 paymentAmount,
        uint256 supply,
        uint256 amount,
        address keysSubject,
        uint256 nonce
    ) internal {
        (
            uint256 price,
            uint256 protocolFee,
            uint256 subjectFee,
            uint256 revenueFee
        ) = _calculatePriceAndFees(supply, amount);

        _paymentTransfer(
            paymentToken,
            paymentAmount,
            price,
            protocolFee,
            subjectFee,
            revenueFee
        );

        _addKeysBalanceAndSupply(keysSubject, amount);

        _transferTokens(
            keysSubject,
            price,
            protocolFee,
            subjectFee,
            revenueFee,
            false
        );

        _emitTrade(
            keysSubject,
            amount,
            price,
            protocolFee,
            subjectFee,
            nonce,
            true
        );
    }

    function _emitTrade(
        address keySubject,
        uint256 amount,
        uint256 price,
        uint256 protocolFee,
        uint256 subjectFee,
        uint256 nonce,
        bool isBuy
    ) internal {
        uint256 rewardIndexOfP = rewardIndexOf[keySubject][msg.sender];
        uint256 earnedP = _calculateRewards(keySubject, msg.sender);
        uint256 supply = keysSupply[keySubject];
        emit Trade(
            msg.sender,
            keySubject,
            amount,
            price,
            protocolFee,
            subjectFee,
            supply,
            nonce,
            rewardIndexOfP,
            earnedP,
            isBuy,
            isSwapped
        );
    }

    function _removeKeysWithTransfer(
        uint256 supply,
        uint256 amount,
        address keysSubject
    ) internal {
        (
            uint256 price,
            uint256 protocolFee,
            uint256 subjectFee,
            uint256 revenueFee
        ) = _calculatePriceAndFees(supply - amount, amount);
        require(
            keysBalance[keysSubject][msg.sender] >= amount,
            "Insufficient keys"
        );
        
        _removeKeysBalanceAndSupply(keysSubject, amount);

        _transferTokens(
            keysSubject,
            price,
            protocolFee,
            subjectFee,
            revenueFee,
            true
        );

        _emitTrade(
            keysSubject,
            amount,
            price,
            protocolFee,
            subjectFee,
            0,
            false
        );
    }

    function _transaferEthIfNeeded(address to, uint256 amount) internal {
        if (amount > 0) {
            (bool success, ) = to.call{value: amount}("");
            require(success, "Unable to send funds");
        }
    }

    function _transferMemefiIfNeeded(address to, uint256 amount) internal {
        if (amount > 0) {
            memefiToken.transfer(to, amount);
        }
    }

    function _transferTokens(
        address keysSubject,
        uint256 price,
        uint256 protocolFee,
        uint256 subjectFee,
        uint256 revenueFee,
        bool isSell
    ) internal {
        if (!isSwapped) {
            if (isSell) {
                _transaferEthIfNeeded(
                    msg.sender,
                    price - protocolFee - subjectFee - revenueFee
                );
            }
            _transaferEthIfNeeded(memefiManagement.treasury(), protocolFee);
            _transaferEthIfNeeded(keysSubject, subjectFee);
            feesDistributor.addReward{value: revenueFee}(revenueFee);
        } else {
            if (!isSell) {
                memefiToken.transferFrom(msg.sender, address(this), price);
            } else {
                memefiToken.transfer(
                    msg.sender,
                    price - protocolFee - subjectFee - revenueFee
                );
            }
            _transferMemefiIfNeeded(memefiManagement.treasury(), protocolFee);
            _transferMemefiIfNeeded(keysSubject, subjectFee);
            if (
                memefiToken.allowance(address(this), address(feesDistributor)) <
                revenueFee
            ) {
                memefiToken.approve(
                    address(feesDistributor),
                    type(uint256).max
                );
            }
            feesDistributor.addReward(revenueFee);
        }
    }

    function buyKeysWithPayment(
        address keysSubject,
        uint256 amount,
        address paymentToken,
        uint256 paymentAmount,
        uint256[] memory itemIds,
        uint256[] memory itemMaxUsers,
        uint256, // backwards compatibility
        uint256 nonce,
        uint256 deadline,
        bytes memory signature
    ) public payable {
        // we dont use pay() function because paymnet will be done in _buyKeys() function
        require(nonce > 0, "Nonce required");
        require(itemIds.length == itemMaxUsers.length, "Len mismatch");
        _useNonce(nonce, 1);
        for (uint256 i = 0; i < itemIds.length; i++) {
            _useNonce(itemIds[i], itemMaxUsers[i]);
        }
        require(
            _checkSignatureKeys(
                paymentToken,
                paymentAmount,
                itemIds,
                itemMaxUsers,
                0,
                nonce,
                deadline,
                signature
            ),
            "Invalid signature"
        );

        _buyKeys(paymentToken, paymentAmount, keysSubject, amount, nonce);
    }

    function pay(
        address paymentToken,
        uint256 paymentAmount,
        uint256[] memory itemIds,
        uint256[] memory itemMaxUsers,
        uint256 paymentType,
        uint256 nonce,
        uint256 deadline,
        bytes memory signature
    ) public payable {
        require(nonce > 0, "Nonce required");
        require(itemIds.length == itemMaxUsers.length, "Len mismatch");
        require(paymentAmount > 0, "Payment amount must be greater than 0");
        _useNonce(nonce, 1);
        for (uint256 i = 0; i < itemIds.length; i++) {
            _useNonce(itemIds[i], itemMaxUsers[i]);
        }
        require(
            _checkSignatureKeys(
                paymentToken,
                paymentAmount,
                itemIds,
                itemMaxUsers,
                paymentType,
                nonce,
                deadline,
                signature
            ),
            "Invalid signature"
        );

        if (paymentToken == address(0)) {
            require(msg.value == paymentAmount, "Invalid payment amount");
            (bool success, ) = memefiManagement.treasury().call{
                value: msg.value
            }("");
            require(success, "Unable to send funds");
        } else {
            IERC20(paymentToken).transferFrom(
                msg.sender,
                memefiManagement.treasury(),
                paymentAmount
            );
        }
        emit Payed(msg.sender, paymentType, paymentToken, paymentAmount, nonce);
    }

    function buyKeys(address keysSubject, uint256 amount) public payable {
        require(
            keysSupply[keysSubject] > 0,
            "Initial key must be bought with payment"
        );
        _buyKeys(address(0), 0, keysSubject, amount, 0);
    }

    function _buyKeys(
        address paymentToken,
        uint256 paymentAmount,
        address keysSubject,
        uint256 amount,
        uint256 nonce
    ) internal {
        uint256 supply = keysSupply[keysSubject];
        require(
            supply > 0 || keysSubject == msg.sender,
            "Only the keys' subject can buy the first key"
        );

        //Updating rewards
        _updateRewards(keysSubject, msg.sender);

        //Add keys
        _addKeysWithTransfer(
            paymentToken,
            paymentAmount,
            supply,
            amount,
            keysSubject,
            nonce
        );
    }

    function sellKeys(address keysSubject, uint256 amount) public payable {
        uint256 supply = keysSupply[keysSubject];
        require(supply > amount, "Cannot sell the last key");

        //Updating rewards
        _updateRewards(keysSubject, msg.sender);

        //Remove keys
        _removeKeysWithTransfer(supply, amount, keysSubject);
    }

    function addRewardsInBatches(
        address[] memory subjects,
        uint256[] memory amountsToAdd,
        uint256[] memory amountsToSubject,
        uint256[] memory nonces,
        bytes[] memory signatures
    ) external {
        require(subjects.length > 0, "No subjects");
        if (subjects.length == 1) {
            return
                addRewards(
                    subjects[0],
                    amountsToAdd,
                    amountsToSubject,
                    nonces,
                    signatures
                );
        }
        uint256 batchesCount;
        uint256[] memory batchesStartIndexes = new uint256[](subjects.length);
        for (uint256 i = 1; i < subjects.length; i++) {
            if (i == 0) {
                batchesCount++;
                batchesStartIndexes[batchesCount] = i;
            } else {
                if (subjects[i] != subjects[i - 1]) {
                    batchesCount++;
                    batchesStartIndexes[batchesCount] = i;
                }
            }
        }
        for (uint256 i = 0; i < batchesCount; i++) {
            uint256 batchStartIndex = batchesStartIndexes[i];
            uint256 batchLastIndex = i == batchesCount - 1
                ? subjects.length - 1
                : batchesStartIndexes[i + 1] - 1;
            uint256 len = batchLastIndex - batchStartIndex + 1;
            uint256[] memory batchAmountsToAdd = new uint256[](len);
            uint256[] memory batchAmountsToSubject = new uint256[](len);
            uint256[] memory batchNonces = new uint256[](len);
            bytes[] memory batchSignatures = new bytes[](len);
            for (uint256 j = batchStartIndex; j <= batchLastIndex; j++) {
                uint256 intIndex = j - batchStartIndex;
                batchAmountsToAdd[intIndex] = amountsToAdd[j];
                batchAmountsToSubject[intIndex] = amountsToSubject[j];
                batchNonces[intIndex] = nonces[j];
                batchSignatures[intIndex] = signatures[j];
            }
            addRewards(
                subjects[i],
                batchAmountsToAdd,
                batchAmountsToSubject,
                batchNonces,
                batchSignatures
            );
        }
    }

    function addRewards(
        address subject,
        uint256[] memory amountsToAdd,
        uint256[] memory amountsToSubject,
        uint256[] memory nonces,
        bytes[] memory signatures
    ) public {
        require(
            amountsToAdd.length == nonces.length &&
                nonces.length == amountsToSubject.length,
            "Arrays length mismatch"
        );

        require(
            keysBalance[subject][msg.sender] > 0,
            "Only keyholder can add rewards"
        );

        uint256 rewardsSum;
        uint256 sumToSubject;
        for (uint256 i = 0; i < amountsToAdd.length; i++) {
            require(
                _checkSignatureRewards(
                    subject,
                    amountsToAdd[i],
                    amountsToSubject[i],
                    nonces[i],
                    signatures[i]
                ),
                "Invalid signature"
            );
            _useNonce(nonces[i], 1);
            rewardsSum += amountsToAdd[i];
            sumToSubject += amountsToSubject[i];
        }

        _addReward(subject, rewardsSum, nonces);
        _withdrawReward(subject, msg.sender);

        if (!isSwapped) {
            (bool success1, ) = subject.call{value: sumToSubject}("");
            require(success1, "Unable to send funds");
        } else {
            memefiToken.transfer(subject, sumToSubject);
        }
    }

    function _addReward(
        address keysSubject,
        uint256 reward,
        uint256[] memory nonces
    ) internal {
        require(isSwapped, "Available only after swap");
        memefiToken.transferFrom(
            memefiManagement.rewardDistributor(),
            address(this),
            reward
        );
        rewardIndex[keysSubject] +=
            (reward * MULTIPLIER) /
            keysSupply[keysSubject];

        emit RewardAdded(keysSubject, reward, rewardIndex[keysSubject], nonces);
    }

    function _calculateRewards(
        address keysSubject,
        address account
    ) private view returns (uint256) {
        uint256 keys = keysBalance[keysSubject][account];
        return
            (keys *
                (rewardIndex[keysSubject] -
                    rewardIndexOf[keysSubject][account])) / MULTIPLIER;
    }

    function _withdrawReward(
        address keySubject,
        address rewardReceiver
    ) internal returns (uint256) {
        require(isSwapped, "Available only after swap");
        _updateRewards(keySubject, rewardReceiver);

        uint256 reward = earned[keySubject][rewardReceiver];

        if (reward > 0) {
            earned[keySubject][rewardReceiver] = 0;
            memefiToken.transfer(rewardReceiver, reward);
            emit RewardWithdraw(
                rewardReceiver,
                keySubject,
                reward,
                rewardIndexOf[keySubject][rewardReceiver]
            );
        }

        return reward;
    }

    function withdrawReward(address keySubject) public returns (uint256) {
        uint256 reward = _withdrawReward(keySubject, msg.sender);
        require(reward > 0, "No reward to withdraw");
        return reward;
    }

    function withdrawRewards(
        address[] memory keySubjects
    ) external returns (uint256) {
        uint256 totalReward;
        for (uint256 i = 0; i < keySubjects.length; i++) {
            totalReward += _withdrawReward(keySubjects[i], msg.sender);
        }
        require(totalReward > 0, "No reward to withdraw");
        return totalReward;
    }
}

File 2 of 15 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

File 4 of 15 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.20;

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

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
     * {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 6 of 15 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

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

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

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

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

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

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

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

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 7 of 15 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

File 8 of 15 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
 * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
 * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
 * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

File 9 of 15 : MessageHashUtils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

File 10 of 15 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

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

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

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

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

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

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

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 11 of 15 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 12 of 15 : IFeesDistributor.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

interface IFeesDistributor {
    function addReward(uint256 reward) external payable;
}

File 13 of 15 : MemefiSwapable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import {IERC20Burnable} from "../tokens/IERC20Burnable.sol";
import {IMemefiManagement} from "../management/IMemefiManagement.sol";

abstract contract MemefiSwapable {
    event TokenSwap(bool swapped);

    bool public isSwapped;
    uint256 public ethToMemefiRate; // 1 full eth = n memefi
    IERC20Burnable public memefiToken;
    IMemefiManagement public memefiManagement;

    constructor(address _memefiManagement) {
        memefiManagement = IMemefiManagement(_memefiManagement);
        memefiToken = IERC20Burnable(memefiManagement.memefiToken());
    }

    function swapToMemefi(uint256 _ethToMemefiRate) virtual external {
        _swapToMemefi(_ethToMemefiRate);
    }

    function _swapToMemefi(uint256 _ethToMemefiRate) internal {
        require(msg.sender == address(memefiManagement), "Only management");
        require(!isSwapped, "Already swapped");
        isSwapped = true;
        ethToMemefiRate = _ethToMemefiRate;
        uint256 ethBalance = address(this).balance;
        (bool success, ) = memefiManagement.treasury().call{value: ethBalance}(
            ""
        );
        require(success, "Unable to send funds");
        uint256 memefiAmount = _calculateMemefiFromEth(ethBalance);
        memefiToken.transferFrom(msg.sender, address(this), memefiAmount);
        emit TokenSwap(true);
    }

    function _calculateMemefiFromEth(
        uint256 ethAmount
    ) internal view returns (uint256) {
        return (ethAmount * ethToMemefiRate) / 1 ether;
    }

    function _calculateEthFromMemefi(
        uint256 memefiAmount
    ) internal view returns (uint256) {
        return (memefiAmount * 1 ether) / ethToMemefiRate;
    }
}

File 14 of 15 : IMemefiManagement.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

interface IMemefiManagement {
    function treasury() external returns (address);

    function signer() external returns (address);

    function rewardDistributor() external returns (address);

    function mainAdmin() external returns (address);

    function hasRole(
        uint256 role,
        address walletAddress
    ) external view returns (bool);

    function uniqueRoleAddress(
        uint256 uniqueRole
    ) external view returns (address);

    function memefiToken() external returns (address);

    function storageSlot(uint256 _slot) external view returns (string memory);

    function feesDistributor() external returns (address);
}

File 15 of 15 : IERC20Burnable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

interface IERC20Burnable {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

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

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

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

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

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

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

    function burn(uint256 amount) external;
    function burnFrom(address account, uint256 value) external;
}

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

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_memefiManagement","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newRewardDistributor","type":"address"}],"name":"NewRewardDistributor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newSigner","type":"address"}],"name":"NewSigner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"payer","type":"address"},{"indexed":false,"internalType":"uint256","name":"paymentType","type":"uint256"},{"indexed":false,"internalType":"address","name":"paymentToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"Payed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"subject","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardIndex","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"nonces","type":"uint256[]"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"subject","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardIndexOf","type":"uint256"}],"name":"RewardWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"swapped","type":"bool"}],"name":"TokenSwap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"trader","type":"address"},{"indexed":true,"internalType":"address","name":"subject","type":"address"},{"indexed":false,"internalType":"uint256","name":"keyAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"subjectFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewardIndexOf","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pendingRewards","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isBuy","type":"bool"},{"indexed":false,"internalType":"bool","name":"isSwapped","type":"bool"}],"name":"Trade","type":"event"},{"inputs":[{"internalType":"address","name":"subject","type":"address"},{"internalType":"uint256[]","name":"amountsToAdd","type":"uint256[]"},{"internalType":"uint256[]","name":"amountsToSubject","type":"uint256[]"},{"internalType":"uint256[]","name":"nonces","type":"uint256[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"addRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"subjects","type":"address[]"},{"internalType":"uint256[]","name":"amountsToAdd","type":"uint256[]"},{"internalType":"uint256[]","name":"amountsToSubject","type":"uint256[]"},{"internalType":"uint256[]","name":"nonces","type":"uint256[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"addRewardsInBatches","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"buyKeys","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint256[]","name":"itemIds","type":"uint256[]"},{"internalType":"uint256[]","name":"itemMaxUsers","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"buyKeysWithPayment","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"calculateReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ethToMemefiRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feesDistributor","outputs":[{"internalType":"contract IFeesDistributor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"firstKeyPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getBuyPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getBuyPriceAfterFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getSellPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getSellPriceAfterFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isSwapped","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"keysBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"keysSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"memefiManagement","outputs":[{"internalType":"contract IMemefiManagement","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"memefiToken","outputs":[{"internalType":"contract IERC20Burnable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nonceUsingCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"uint256","name":"paymentAmount","type":"uint256"},{"internalType":"uint256[]","name":"itemIds","type":"uint256[]"},{"internalType":"uint256[]","name":"itemMaxUsers","type":"uint256[]"},{"internalType":"uint256","name":"paymentType","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"pay","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"protocolFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revenueFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"keysSubject","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sellKeys","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeePercent","type":"uint256"},{"internalType":"uint256","name":"_subjectFeePercent","type":"uint256"},{"internalType":"uint256","name":"_revenueFeePercent","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"subjectFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ethToMemefiRate","type":"uint256"}],"name":"swapToMemefi","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"keySubject","type":"address"}],"name":"withdrawReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"keySubjects","type":"address[]"}],"name":"withdrawRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x6080604052600436106101525760003560e01c80630f026f6d146101575780631dd1b2bb1461018a57806321c2024d146101c25780632267a89c146101e457806324dc441d146102045780632d826bdf1461021a57806330abda3f14610234578063324777bf14610247578063342465cb1461025a5780634635256e146102705780634d3b17cc14610290578063592de11d146102a65780635cf4ee91146102b957806362d76d06146102d95780637756df44146102f95780637ca44fcf1461032657806384b0196e146103465780638e0bae7f1461036e5780639111ac891461038e5780639ae71781146103a1578063b86e321c146103c1578063cc768b61146103e1578063cec10c111461040b578063d45fdfed1461042b578063d6e6eb9f1461044b578063e575ab9614610461578063e6e88e291461048e578063ead097c0146104ae578063fc255d65146104ce575b600080fd5b34801561016357600080fd5b50610177610172366004612fb5565b610506565b6040519081526020015b60405180910390f35b34801561019657600080fd5b506003546101aa906001600160a01b031681565b6040516001600160a01b039091168152602001610181565b3480156101ce57600080fd5b506101e26101dd3660046131a3565b610557565b005b3480156101f057600080fd5b506101776101ff366004612fb5565b61085d565b34801561021057600080fd5b5061017760075481565b34801561022657600080fd5b50610177653691d6afc00081565b6101e2610242366004613262565b6108a1565b6101e261025536600461333d565b61098e565b34801561026657600080fd5b5061017760085481565b34801561027c57600080fd5b5061017761028b366004612fb5565b610d1c565b34801561029c57600080fd5b5061017760015481565b6101e26102b4366004612fb5565b610d46565b3480156102c557600080fd5b506101776102d43660046133fc565b610dce565b3480156102e557600080fd5b506101776102f4366004613482565b610f2a565b34801561030557600080fd5b506101776103143660046134b6565b600a6020526000908152604090205481565b34801561033257600080fd5b506101776103413660046134cf565b610f9b565b34801561035257600080fd5b5061035b610fd7565b6040516101819796959493929190613589565b34801561037a57600080fd5b506009546101aa906001600160a01b031681565b6101e261039c366004612fb5565b61101d565b3480156103ad57600080fd5b506101776103bc366004612fb5565b61109a565b3480156103cd57600080fd5b506101776103dc3660046135f9565b6110c8565b3480156103ed57600080fd5b506000546103fb9060ff1681565b6040519015158152602001610181565b34801561041757600080fd5b506101e2610426366004613616565b6110f7565b34801561043757600080fd5b506101e26104463660046134b6565b61123a565b34801561045757600080fd5b5061017760065481565b34801561046d57600080fd5b5061017761047c3660046135f9565b600c6020526000908152604090205481565b34801561049a57600080fd5b506101e26104a9366004613642565b611246565b3480156104ba57600080fd5b506002546101aa906001600160a01b031681565b3480156104da57600080fd5b506101776104e93660046134cf565b600b60209081526000928352604080842090915290825290205481565b6000806105138484610d1c565b90506000806000610523846116da565b91945092509050808261053685876136a9565b61054091906136a9565b61054a91906136a9565b9450505050505b92915050565b81518451148015610569575082518251145b6105b35760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b60448201526064015b60405180910390fd5b6001600160a01b0385166000908152600b602090815260408083203384529091529020546106235760405162461bcd60e51b815260206004820152601e60248201527f4f6e6c79206b6579686f6c6465722063616e206164642072657761726473000060448201526064016105aa565b60008060005b8651811015610743576106a388888381518110610648576106486136bc565b6020026020010151888481518110610662576106626136bc565b602002602001015188858151811061067c5761067c6136bc565b6020026020010151888681518110610696576106966136bc565b6020026020010151611759565b6106bf5760405162461bcd60e51b81526004016105aa906136d2565b6106e38582815181106106d4576106d46136bc565b60200260200101516001611874565b8681815181106106f5576106f56136bc565b60200260200101518361070891906136a9565b925085818151811061071c5761071c6136bc565b60200260200101518261072f91906136a9565b91508061073b816136fd565b915050610629565b5061074f8783866118ee565b6107598733611aaa565b5060005460ff166107dd576000876001600160a01b03168260405160006040518083038185875af1925050503d80600081146107b1576040519150601f19603f3d011682016040523d82523d6000602084013e6107b6565b606091505b50509050806107d75760405162461bcd60e51b81526004016105aa90613716565b50610854565b60025460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb9061080f908a908590600401613744565b6020604051808303816000875af115801561082e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610852919061375d565b505b50505050505050565b60008061086a848461109a565b9050600080600061087a846116da565b91945092509050808261088d858761377f565b610897919061377f565b61054a919061377f565b600083116108c15760405162461bcd60e51b81526004016105aa90613792565b84518651146108e25760405162461bcd60e51b81526004016105aa906137ba565b6108ed836001611874565b60005b86518110156109475761093587828151811061090e5761090e6136bc565b6020026020010151878381518110610928576109286136bc565b6020026020010151611874565b8061093f816136fd565b9150506108f0565b50610959888888886000888888611c02565b6109755760405162461bcd60e51b81526004016105aa906136d2565b61098288888c8c87611db8565b50505050505050505050565b600083116109ae5760405162461bcd60e51b81526004016105aa90613792565b84518651146109cf5760405162461bcd60e51b81526004016105aa906137ba565b60008711610a2d5760405162461bcd60e51b815260206004820152602560248201527f5061796d656e7420616d6f756e74206d75737420626520677265617465722074604482015264068616e20360dc1b60648201526084016105aa565b610a38836001611874565b60005b8651811015610a6b57610a5987828151811061090e5761090e6136bc565b80610a63816136fd565b915050610a3b565b50610a7c8888888888888888611c02565b610a985760405162461bcd60e51b81526004016105aa906136d2565b6001600160a01b038816610bd357863414610aee5760405162461bcd60e51b8152602060048201526016602482015275125b9d985b1a59081c185e5b595b9d08185b5bdd5b9d60521b60448201526064016105aa565b600354604080516361d027b360e01b815290516000926001600160a01b0316916361d027b3916004808301926020929190829003018187875af1158015610b39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5d91906137e0565b6001600160a01b03163460405160006040518083038185875af1925050503d8060008114610ba7576040519150601f19603f3d011682016040523d82523d6000602084013e610bac565b606091505b5050905080610bcd5760405162461bcd60e51b81526004016105aa90613716565b50610cc0565b876001600160a01b03166323b872dd33600360009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b81526004016020604051808303816000875af1158015610c38573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c5c91906137e0565b8a6040518463ffffffff1660e01b8152600401610c7b939291906137fd565b6020604051808303816000875af1158015610c9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cbe919061375d565b505b604080518581526001600160a01b038a1660208201529081018890526060810184905233907fce6d38800f185a3ea05a466d1da359c3aedecb48740391666def25626b8e71ca9060800160405180910390a25050505050505050565b6001600160a01b0382166000908152600c6020526040812054610d3f9083610dce565b9392505050565b6001600160a01b0382166000908152600c6020526040902054610dbb5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c206b6579206d75737420626520626f756768742077697468206044820152661c185e5b595b9d60ca1b60648201526084016105aa565b610dca60008084846000611db8565b5050565b600081600003610de057506000610551565b82600003610e0e57610df760016102d4818561377f565b610e0790653691d6afc0006136a9565b9050610551565b60006006610e1d60018661377f565b610e28906002613821565b610e339060016136a9565b85610e3f60018261377f565b610e499190613821565b610e539190613821565b610e5d9190613838565b90506000600684610e6f60018861377f565b610e7991906136a9565b610e84906002613821565b610e8f9060016136a9565b610e9986886136a9565b86610ea560018a61377f565b610eaf91906136a9565b610eb99190613821565b610ec39190613821565b610ecd9190613838565b90506000610edb838361377f565b90506000613e80610ef483670de0b6b3a7640000613821565b610efe9190613838565b60005490915060ff1615610f2057610f1581611e68565b945050505050610551565b9695505050505050565b60008060005b8351811015610f7a57610f5c848281518110610f4e57610f4e6136bc565b602002602001015133611aaa565b610f6690836136a9565b915080610f72816136fd565b915050610f30565b50600081116105515760405162461bcd60e51b81526004016105aa9061385a565b6000610fa78383611e8b565b6001600160a01b038085166000908152600f6020908152604080832093871683529290522054610d3f91906136a9565b600060608060008060006060610feb611f06565b610ff3611f38565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6001600160a01b0382166000908152600c60205260409020548181116110805760405162461bcd60e51b815260206004820152601860248201527743616e6e6f742073656c6c20746865206c617374206b657960401b60448201526064016105aa565b61108a8333611f65565b611095818385611fdc565b505050565b6001600160a01b0382166000908152600c6020526040812054610d3f906110c290849061377f565b83610dce565b6000806110d58333611aaa565b9050600081116105515760405162461bcd60e51b81526004016105aa9061385a565b600360009054906101000a90046001600160a01b03166001600160a01b031663fb6b04ba6040518163ffffffff1660e01b81526004016020604051808303816000875af115801561114c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061117091906137e0565b6001600160a01b0316336001600160a01b0316146111c35760405162461bcd60e51b815260206004820152601060248201526f2737ba10309036b0b4b71037bbb732b960811b60448201526064016105aa565b67016345785d8a0000816111d784866136a9565b6111e191906136a9565b111561122c5760405162461bcd60e51b815260206004820152601a60248201527946656573206d757374206265206c657373207468616e2031302560301b60448201526064016105aa565b600692909255600755600855565b6112438161208e565b50565b60008551116112855760405162461bcd60e51b815260206004820152600b60248201526a4e6f207375626a6563747360a81b60448201526064016105aa565b84516001036112ba576112b5856000815181106112a4576112a46136bc565b602002602001015185858585610557565b6116d3565b60008086516001600160401b038111156112d6576112d6612fe1565b6040519080825280602002602001820160405280156112ff578160200160208202803683370190505b50905060015b87518110156113db57806000036113475782611320816136fd565b93505080828481518110611336576113366136bc565b6020026020010181815250506113c9565b8761135360018361377f565b81518110611363576113636136bc565b60200260200101516001600160a01b0316888281518110611386576113866136bc565b60200260200101516001600160a01b0316146113c957826113a6816136fd565b935050808284815181106113bc576113bc6136bc565b6020026020010181815250505b806113d3816136fd565b915050611305565b5060005b828110156108525760008282815181106113fb576113fb6136bc565b602002602001015190506000600185611414919061377f565b831461144e5760018461142785836136a9565b81518110611437576114376136bc565b6020026020010151611449919061377f565b61145c565b60018a5161145c919061377f565b9050600061146a838361377f565b6114759060016136a9565b90506000816001600160401b0381111561149157611491612fe1565b6040519080825280602002602001820160405280156114ba578160200160208202803683370190505b5090506000826001600160401b038111156114d7576114d7612fe1565b604051908082528060200260200182016040528015611500578160200160208202803683370190505b5090506000836001600160401b0381111561151d5761151d612fe1565b604051908082528060200260200182016040528015611546578160200160208202803683370190505b5090506000846001600160401b0381111561156357611563612fe1565b60405190808252806020026020018201604052801561159657816020015b60608152602001906001900390816115815790505b509050865b8681116116a35760006115ae898361377f565b90508f82815181106115c2576115c26136bc565b60200260200101518682815181106115dc576115dc6136bc565b6020026020010181815250508e82815181106115fa576115fa6136bc565b6020026020010151858281518110611614576116146136bc565b6020026020010181815250508d8281518110611632576116326136bc565b602002602001015184828151811061164c5761164c6136bc565b6020026020010181815250508c828151811061166a5761166a6136bc565b6020026020010151838281518110611684576116846136bc565b602002602001018190525050808061169b906136fd565b91505061159b565b506116b98f89815181106112a4576112a46136bc565b5050505050505080806116cb906136fd565b9150506113df565b5050505050565b600080600080670de0b6b3a7640000600654866116f79190613821565b6117019190613838565b90506000670de0b6b3a76400006007548761171c9190613821565b6117269190613838565b90506000670de0b6b3a7640000600854886117419190613821565b61174b9190613838565b929791965091945092505050565b604080517f2ae13b3e9f43dd3f483ddedf916486af119d991a488c9df2f4c08da49b92358260208201526001600160a01b03871691810191909152606081018590526080810184905260a0810183905260009081906117d19060c0015b604051602081830303815290604052805190602001206122ce565b9050600360009054906101000a90046001600160a01b03166001600160a01b031663238ac9336040518163ffffffff1660e01b81526004016020604051808303816000875af1158015611828573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184c91906137e0565b6001600160a01b031661185f82856122fb565b6001600160a01b031614979650505050505050565b6000828152600a602052604090205481116118c65760405162461bcd60e51b8152602060048201526012602482015271139bdb98d948185b1c9958591e481d5cd95960721b60448201526064016105aa565b6000828152600a602052604081208054600192906118e59084906136a9565b90915550505050565b60005460ff166119105760405162461bcd60e51b81526004016105aa90613889565b600254600354604080516356610b3560e11b815290516001600160a01b03938416936323b872dd93169163acc2166a91600480830192602092919082900301816000875af1158015611966573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198a91906137e0565b30856040518463ffffffff1660e01b81526004016119aa939291906137fd565b6020604051808303816000875af11580156119c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ed919061375d565b506001600160a01b0383166000908152600c6020526040902054611a19670de0b6b3a764000084613821565b611a239190613838565b6001600160a01b0384166000908152600d602052604081208054909190611a4b9084906136a9565b90915550506001600160a01b0383166000818152600d6020526040908190205490517fa6af97c57588b1f0a3d42c13588e8017f413111a8e7f5b9cc832899bfe18d42e91611a9d9186919086906138bc565b60405180910390a2505050565b6000805460ff16611acd5760405162461bcd60e51b81526004016105aa90613889565b611ad78383611f65565b6001600160a01b038084166000908152600f60209081526040808320938616835292905220548015610d3f576001600160a01b038085166000908152600f60209081526040808320878516845290915280822091909155600254905163a9059cbb60e01b815291169063a9059cbb90611b569086908590600401613744565b6020604051808303816000875af1158015611b75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b99919061375d565b506001600160a01b038481166000818152600e6020908152604080832094881680845294825291829020548251868152918201529192917f95ce0e9616a1212f228bd4500789cf3572aab0777f130b1a29484dbff0587acd910160405180910390a39392505050565b600042831015611c485760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b60448201526064016105aa565b6000611d127fe99b1c2a501b1c1e183b113a9d9b7c30f5e07f07821bf8cd7d0a38961d366eb8338c8c8c604051602001611c8291906138e4565b604051602081830303815290604052805190602001208c604051602001611ca991906138e4565b60408051601f198184030181528282528051602091820120908301979097526001600160a01b0395861690820152939092166060840152608083015260a082015260c081019190915260e0810188905261010081018790526101208101869052610140016117b6565b9050600360009054906101000a90046001600160a01b03166001600160a01b031663238ac9336040518163ffffffff1660e01b81526004016020604051808303816000875af1158015611d69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d8d91906137e0565b6001600160a01b0316611da082856122fb565b6001600160a01b0316149a9950505050505050505050565b6001600160a01b0383166000908152600c602052604090205480151580611de757506001600160a01b03841633145b611e485760405162461bcd60e51b815260206004820152602c60248201527f4f6e6c7920746865206b65797327207375626a6563742063616e20627579207460448201526b6865206669727374206b657960a01b60648201526084016105aa565b611e528433611f65565b611e60868683868887612325565b505050505050565b6000670de0b6b3a764000060015483611e819190613821565b6105519190613838565b6001600160a01b038083166000818152600b6020908152604080832094861680845294825280832054848452600e835281842095845294825280832054938352600d909152812054909291670de0b6b3a764000091611eea919061377f565b611ef49083613821565b611efe9190613838565b949350505050565b6060611f337f4d656d65666900000000000000000000000000000000000000000000000000066004612374565b905090565b6060611f337f31000000000000000000000000000000000000000000000000000000000000016005612374565b611f6f8282611e8b565b6001600160a01b038084166000908152600f6020908152604080832093861683529290529081208054909190611fa69084906136a9565b90915550506001600160a01b039182166000908152600d6020908152604080832054600e83528184209490951683529290522055565b6000808080611ff4611fee878961377f565b87612418565b6001600160a01b0389166000908152600b60209081526040808320338452909152902054939750919550935091508611156120655760405162461bcd60e51b8152602060048201526011602482015270496e73756666696369656e74206b65797360781b60448201526064016105aa565b61206f858761244e565b61207e858585858560016124ae565b61085485878686866000806128bb565b6003546001600160a01b031633146120da5760405162461bcd60e51b815260206004820152600f60248201526e13db9b1e481b585b9859d95b595b9d608a1b60448201526064016105aa565b60005460ff161561211f5760405162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e481cddd85c1c1959608a1b60448201526064016105aa565b6000805460ff191660019081178255829055600354604080516361d027b360e01b815290514793926001600160a01b0316916361d027b3916004808301926020929190829003018187875af115801561217c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121a091906137e0565b6001600160a01b03168260405160006040518083038185875af1925050503d80600081146121ea576040519150601f19603f3d011682016040523d82523d6000602084013e6121ef565b606091505b50509050806122105760405162461bcd60e51b81526004016105aa90613716565b600061221b83611e68565b6002546040516323b872dd60e01b81529192506001600160a01b0316906323b872dd90612250903390309086906004016137fd565b6020604051808303816000875af115801561226f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612293919061375d565b50604051600181527f4f6b7f5618fe80c81afadeb37727fb4e6b3b8f4f8cf736dba0416ce046082d829060200160405180910390a150505050565b60006105516122db612992565b8360405161190160f01b8152600281019290925260228201526042902090565b60008060008061230b8686612abd565b92509250925061231b8282612b0a565b5090949350505050565b6000806000806123358888612418565b935093509350935061234b8a8a86868686612bc3565b6123558688612d10565b612364868585858560006124ae565b61098286888686868a60016128bb565b606060ff831461238757610e0783612d70565b8180546123939061391a565b80601f01602080910402602001604051908101604052809291908181526020018280546123bf9061391a565b801561240c5780601f106123e15761010080835404028352916020019161240c565b820191906000526020600020905b8154815290600101906020018083116123ef57829003601f168201915b50505050509050610551565b600080600080600061242a8787610dce565b9050600080600061243a846116da565b959c919b5099509397509295505050505050565b6001600160a01b0382166000908152600b602090815260408083203384529091528120805483929061248190849061377f565b90915550506001600160a01b0382166000908152600c6020526040812080548392906118e590849061377f565b60005460ff166125cd5780156124e7576124e73383856124ce888a61377f565b6124d8919061377f565b6124e2919061377f565b612daf565b600354604080516361d027b360e01b8152905161255e926001600160a01b0316916361d027b391600480830192602092919082900301816000875af1158015612534573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061255891906137e0565b85612daf565b6125688684612daf565b600954604051631d3793b160e21b8152600481018490526001600160a01b03909116906374de4ec49084906024016000604051808303818588803b1580156125af57600080fd5b505af11580156125c3573d6000803e3d6000fd5b5050505050611e60565b8061264f576002546040516323b872dd60e01b81526001600160a01b03909116906323b872dd9061260690339030908a906004016137fd565b6020604051808303816000875af1158015612625573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612649919061375d565b506126e3565b6002546001600160a01b031663a9059cbb33848661266d898b61377f565b612677919061377f565b612681919061377f565b6040518363ffffffff1660e01b815260040161269e929190613744565b6020604051808303816000875af11580156126bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126e1919061375d565b505b600354604080516361d027b360e01b8152905161275a926001600160a01b0316916361d027b391600480830192602092919082900301816000875af1158015612730573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061275491906137e0565b85612e28565b6127648684612e28565b600254600954604051636eb1769f60e11b81523060048201526001600160a01b0391821660248201528492919091169063dd62ed3e90604401602060405180830381865afa1580156127ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127de9190613954565b10156128615760025460095460405163095ea7b360e01b81526001600160a01b039283169263095ea7b39261281c9291169060001990600401613744565b6020604051808303816000875af115801561283b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285f919061375d565b505b600954604051631d3793b160e21b8152600481018490526001600160a01b03909116906374de4ec490602401600060405180830381600087803b1580156128a757600080fd5b505af1158015610982573d6000803e3d6000fd5b6001600160a01b0387166000908152600e6020908152604080832033808552925282205491906128ec908a90611e8b565b6001600160a01b038a166000818152600c6020908152604080832054925481518e81529283018d90529082018b9052606082018a90526080820183905260a0820189905260c0820187905260e0820185905287151561010083015260ff1615156101208201529293509133907fb400e306993fb63a4ea13da81d56e7ea20a340634136fb0e03d97564eda2f2b7906101400160405180910390a350505050505050505050565b6000306001600160a01b037f000000000000000000000000eaf3114423a85c778c681638496591eefc3a15bc161480156129eb57507f0000000000000000000000000000000000000000000000000000000000aa36a746145b15612a1557507f324f4e4a656fdc63fe2bbca397fa2ddea57584baf98d8ec868f092fdb84b4a0090565b611f33604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527fcc225e45ed82df463c9b335646835adb36462e9f000f6da87056c704bbd5ca46918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60008060008351604103612af75760208401516040850151606086015160001a612ae988828585612ea3565b955095509550505050612b03565b50508151600091506002905b9250925092565b6000826003811115612b1e57612b1e61396d565b03612b27575050565b6001826003811115612b3b57612b3b61396d565b03612b595760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115612b6d57612b6d61396d565b03612b8e5760405163fce698f760e01b8152600481018290526024016105aa565b6003826003811115612ba257612ba261396d565b03610dca576040516335e2f38360e21b8152600481018290526024016105aa565b60006001600160a01b03871615612bdb576000612bdd565b855b90506001600160a01b038716612c6257808284612bfa87896136a9565b612c0491906136a9565b612c0e91906136a9565b612c1891906136a9565b3414612c5d5760405162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b60448201526064016105aa565b610854565b851561085457866001600160a01b03166323b872dd33600360009054906101000a90046001600160a01b03166001600160a01b03166361d027b36040518163ffffffff1660e01b81526004016020604051808303816000875af1158015612ccd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cf191906137e0565b896040518463ffffffff1660e01b815260040161080f939291906137fd565b6001600160a01b0382166000908152600b6020908152604080832033845290915281208054839290612d439084906136a9565b90915550506001600160a01b0382166000908152600c6020526040812080548392906118e59084906136a9565b60606000612d7d83612f68565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b8015610dca576000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114612e02576040519150601f19603f3d011682016040523d82523d6000602084013e612e07565b606091505b50509050806110955760405162461bcd60e51b81526004016105aa90613716565b8015610dca5760025460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90612e609085908590600401613744565b6020604051808303816000875af1158015612e7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611095919061375d565b600080806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03841115612ed45750600091506003905082612f5e565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015612f28573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116612f5457506000925060019150829050612f5e565b9250600091508190505b9450945094915050565b600060ff8216601f81111561055157604051632cd44ac360e21b815260040160405180910390fd5b6001600160a01b038116811461124357600080fd5b8035612fb081612f90565b919050565b60008060408385031215612fc857600080fd5b8235612fd381612f90565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561301f5761301f612fe1565b604052919050565b60006001600160401b0382111561304057613040612fe1565b5060051b60200190565b600082601f83011261305b57600080fd5b8135602061307061306b83613027565b612ff7565b82815260059290921b8401810191818101908684111561308f57600080fd5b8286015b848110156130aa5780358352918301918301613093565b509695505050505050565b600082601f8301126130c657600080fd5b81356001600160401b038111156130df576130df612fe1565b6130f2601f8201601f1916602001612ff7565b81815284602083860101111561310757600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261313557600080fd5b8135602061314561306b83613027565b82815260059290921b8401810191818101908684111561316457600080fd5b8286015b848110156130aa5780356001600160401b038111156131875760008081fd5b6131958986838b01016130b5565b845250918301918301613168565b600080600080600060a086880312156131bb57600080fd5b85356131c681612f90565b945060208601356001600160401b03808211156131e257600080fd5b6131ee89838a0161304a565b9550604088013591508082111561320457600080fd5b61321089838a0161304a565b9450606088013591508082111561322657600080fd5b61323289838a0161304a565b9350608088013591508082111561324857600080fd5b5061325588828901613124565b9150509295509295909350565b6000806000806000806000806000806101408b8d03121561328257600080fd5b61328b8b612fa5565b995060208b013598506132a060408c01612fa5565b975060608b0135965060808b01356001600160401b03808211156132c357600080fd5b6132cf8e838f0161304a565b975060a08d01359150808211156132e557600080fd5b6132f18e838f0161304a565b965060c08d0135955060e08d013594506101008d013593506101208d013591508082111561331e57600080fd5b5061332b8d828e016130b5565b9150509295989b9194979a5092959850565b600080600080600080600080610100898b03121561335a57600080fd5b61336389612fa5565b97506020890135965060408901356001600160401b038082111561338657600080fd5b6133928c838d0161304a565b975060608b01359150808211156133a857600080fd5b6133b48c838d0161304a565b965060808b0135955060a08b0135945060c08b0135935060e08b01359150808211156133df57600080fd5b506133ec8b828c016130b5565b9150509295985092959890939650565b6000806040838503121561340f57600080fd5b50508035926020909101359150565b600082601f83011261342f57600080fd5b8135602061343f61306b83613027565b82815260059290921b8401810191818101908684111561345e57600080fd5b8286015b848110156130aa57803561347581612f90565b8352918301918301613462565b60006020828403121561349457600080fd5b81356001600160401b038111156134aa57600080fd5b611efe8482850161341e565b6000602082840312156134c857600080fd5b5035919050565b600080604083850312156134e257600080fd5b82356134ed81612f90565b915060208301356134fd81612f90565b809150509250929050565b6000815180845260005b8181101561352e57602081850181015186830182015201613512565b506000602082860101526020601f19601f83011685010191505092915050565b600081518084526020808501945080840160005b8381101561357e57815187529582019590820190600101613562565b509495945050505050565b60ff60f81b8816815260e0602082015260006135a860e0830189613508565b82810360408401526135ba8189613508565b606084018890526001600160a01b038716608085015260a0840186905283810360c085015290506135eb818561354e565b9a9950505050505050505050565b60006020828403121561360b57600080fd5b8135610d3f81612f90565b60008060006060848603121561362b57600080fd5b505081359360208301359350604090920135919050565b600080600080600060a0868803121561365a57600080fd5b85356001600160401b038082111561367157600080fd5b61367d89838a0161341e565b965060208801359150808211156131e257600080fd5b634e487b7160e01b600052601160045260246000fd5b8082018082111561055157610551613693565b634e487b7160e01b600052603260045260246000fd5b602080825260119082015270496e76616c6964207369676e617475726560781b604082015260600190565b60006001820161370f5761370f613693565b5060010190565b602080825260149082015273556e61626c6520746f2073656e642066756e647360601b604082015260600190565b6001600160a01b03929092168252602082015260400190565b60006020828403121561376f57600080fd5b81518015158114610d3f57600080fd5b8181038181111561055157610551613693565b6020808252600e908201526d139bdb98d9481c995c5d5a5c995960921b604082015260600190565b6020808252600c908201526b098cadc40dad2e6dac2e8c6d60a31b604082015260600190565b6000602082840312156137f257600080fd5b8151610d3f81612f90565b6001600160a01b039384168152919092166020820152604081019190915260600190565b808202811582820484141761055157610551613693565b60008261385557634e487b7160e01b600052601260045260246000fd5b500490565b6020808252601590820152744e6f2072657761726420746f20776974686472617760581b604082015260600190565b6020808252601990820152780417661696c61626c65206f6e6c79206166746572207377617603c1b604082015260600190565b8381528260208201526060604082015260006138db606083018461354e565b95945050505050565b815160009082906020808601845b8381101561390e578151855293820193908201906001016138f2565b50929695505050505050565b600181811c9082168061392e57607f821691505b60208210810361394e57634e487b7160e01b600052602260045260246000fd5b50919050565b60006020828403121561396657600080fd5b5051919050565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220923c04bd73930d76c2ed2831ac1284f75ff8031c21b2736463ed3e69546594e364736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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