MON Price: $0.021624 (-2.45%)

Contract

0x7Af453d862c3BAD618F506751fAC145F947F3d99

Overview

MON Balance

Monad Chain LogoMonad Chain LogoMonad Chain Logo0 MON

MON Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Referral

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
london EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {ReferralStore} from "./ReferralStore.sol";
import {Signable} from "./Signable.sol";
import {DataStore} from "./DataStore.sol";
import "./Roles.sol";

/// @title Referral
/// @notice A contract for managing referrals
contract Referral is Roles {
    /// @notice Emitted when a new referrer is registered
    /// @param referrer The address of the referrer
    /// @param referralCode The referral code
    event ReferralRegistered(address referrer, string referralCode);

    /// @notice Emitted when a referrer is set for a user
    /// @param referee The address of the user
    /// @param referralCode The referral code
    /// @param referrer The address of the referrer
    event ReferralSet(address referee, string referralCode, address referrer);

    Signable public signable;
    ReferralStore public referralStore;
    DataStore public dataStore;

    /// @notice Initialize the contract
    /// @param rs The address of the RoleStore
    /// @param ds The address of the DataStore contract
    function initialize(address rs, address ds) external initializer {
        roleStore = RoleStore(rs);
        dataStore = DataStore(ds);
        _setGov(msg.sender);
    }

    /// @notice Link the contract
    function link() external onlyGov {
        signable = Signable(dataStore.getAddress("Signable"));
        referralStore = ReferralStore(dataStore.getAddress("ReferralStore"));
    }

    /// @notice Register a new referrer
    /// @param _referralCode The referral code
    /// @param _signature The signature of the referrer
    function registerReferral(
        string memory _referralCode,
        bytes memory _signature
    ) external {
        require(
            signable.verify(_referralCode, msg.sender, _signature),
            "!invalid-signature"
        );
        require(
            !referralStore.isBlacklisted(msg.sender),
            "!referrer-blacklisted"
        );
        require(
            referralStore.getReferrerByReferralCode(_referralCode) ==
                address(0),
            "!ref-code-exists"
        );
        require(
            bytes(referralStore.getReferralCode(msg.sender)).length == 0,
            "!referrer-already-registered"
        );
        referralStore.registerReferral(msg.sender, _referralCode);
        emit ReferralRegistered(msg.sender, _referralCode);
    }

    /// @notice Set a referrer for a user
    /// @param _referralCode The referral code
    /// @param _signature The signature of the referrer
    function setReferrer(
        string memory _referralCode,
        bytes memory _signature
    ) external {
        require(
            signable.verify(_referralCode, msg.sender, _signature),
            "!invalid-signature"
        );
        require(
            !referralStore.isBlacklisted(msg.sender),
            "!referee-blacklisted"
        );
        require(
            referralStore.getReferrer(msg.sender) == address(0),
            "!referee-already-registered"
        );
        address referrer = referralStore.getReferrerByReferralCode(
            _referralCode
        );
        require(referrer != msg.sender, "!self-referral");
        require(referrer != address(0), "!ref-code-not-registered");
        require(
            !referralStore.isBlacklisted(referrer),
            "!referrer-blacklisted"
        );
        referralStore.setReferrer(msg.sender, _referralCode);
        emit ReferralSet(msg.sender, _referralCode, referrer);
    }
}

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

import "./Roles.sol";

/// @title ReferralStore
/// @notice Persistent storage for Referral.sol
contract ReferralStore is Roles {
    uint256 constant BPS_DIVIDER = 10000; // 100%

    mapping(address => address) public refereeToReferrer; // referree -> referrer
    mapping(string => address) public referralCodeToReferrer; // referral code -> referrer
    mapping(address => string) public referrerToReferralCode; // referrer -> referral code
    mapping(address => uint256) public referralFeeShare; // user -> referral fee share
    mapping(address => uint256) public rebateFeeShare; // user -> rebate fee share
    mapping(address => bool) public blacklisted; // user -> blacklisted

    uint256 public referrerCount; // number of referrers
    uint256 public refereeCount; // number of referees
    uint256 public defaultReferralFeeShare;
    uint256 public defaultRebateFeeShare;

    bool public referralEnabled;

    event ReferralFeeShareSet(address user, uint256 referralFeeShare);
    event RebateFeeShareSet(address user, uint256 rebateFeeShare);

    /// @notice Initialize the contract
    /// @param rs The address of the RoleStore
    function initialize(address rs) external initializer {
        roleStore = RoleStore(rs);
        _setGov(msg.sender);
        referralEnabled = true;
        defaultReferralFeeShare = 125;
        defaultRebateFeeShare = 125;
    }

    function setReferralEnabled(bool _referralEnabled) external onlyGov {
        referralEnabled = _referralEnabled;
    }

    function setDefaultReferralFeeShare(
        uint256 _defaultReferralFeeShare
    ) external onlyGov {
        defaultReferralFeeShare = _defaultReferralFeeShare;
    }

    function setDefaultRebateFeeShare(
        uint256 _defaultRebateFeeShare
    ) external onlyGov {
        defaultRebateFeeShare = _defaultRebateFeeShare;
    }

    /// @notice Blacklist a user
    /// @param _referee The address of the user
    function blacklist(address _referee) external onlyGov {
        blacklisted[_referee] = true;
    }

    /// @notice Unblacklist a user
    /// @param _referee The address of the user
    function unblacklist(address _referee) external onlyGov {
        blacklisted[_referee] = false;
    }

    /// @notice Check if a user is blacklisted
    /// @param user The address of the user
    /// @return True if the user is blacklisted, false otherwise
    function isBlacklisted(address user) external view returns (bool) {
        return blacklisted[user];
    }

    /// @notice Register a new referrer
    /// @param _referrer The address of the referrer
    /// @param _referralCode The referral code
    function registerReferral(
        address _referrer,
        string memory _referralCode
    ) external onlyContract {
        referralCodeToReferrer[_referralCode] = _referrer;
        referrerToReferralCode[_referrer] = _referralCode;
        rebateFeeShare[_referrer] = defaultRebateFeeShare;
        referrerCount++;
    }

    /// @notice Set a referrer for a user
    /// @param _referee The address of the user
    /// @param _referralCode The referral code
    function setReferrer(
        address _referee,
        string memory _referralCode
    ) external onlyContract {
        address referrer = referralCodeToReferrer[_referralCode];
        refereeToReferrer[_referee] = referrer;
        referralFeeShare[_referee] = defaultReferralFeeShare;
        refereeCount++;
    }

    /// @notice Set the referral fee share for a user
    /// @param _user The address of the user
    /// @param _referralFeeShare The referral fee share
    function setReferralFeeShare(
        address _user,
        uint256 _referralFeeShare
    ) external onlyGov {
        referralFeeShare[_user] = _referralFeeShare;
        emit ReferralFeeShareSet(_user, _referralFeeShare);
    }

    /// @notice Set the referral fee shares for a users
    /// @param _users The addresses of the users
    /// @param _referralFeeShares The referral fee shares
    function setReferralFeeShares(
        address[] calldata _users,
        uint256[] calldata _referralFeeShares
    ) external onlyGov {
        for (uint256 i = 0; i < _users.length; i++) {
            referralFeeShare[_users[i]] = _referralFeeShares[i];
            emit ReferralFeeShareSet(_users[i], _referralFeeShares[i]);
        }
    }

    /// @notice Set the rebate fee share for a user
    /// @param _user The address of the user
    /// @param _rebateFeeShare The rebate fee share
    function setRebateFeeShare(
        address _user,
        uint256 _rebateFeeShare
    ) external onlyGov {
        rebateFeeShare[_user] = _rebateFeeShare;
        emit RebateFeeShareSet(_user, _rebateFeeShare);
    }

    /// @notice Set the rebate fee shares for a users
    /// @param _users The addresses of the users
    /// @param _rebateFeeShares The rebate fee shares
    function setRebateFeeShares(
        address[] calldata _users,
        uint256[] calldata _rebateFeeShares
    ) external onlyGov {
        for (uint256 i = 0; i < _users.length; i++) {
            rebateFeeShare[_users[i]] = _rebateFeeShares[i];
            emit RebateFeeShareSet(_users[i], _rebateFeeShares[i]);
        }
    }

    /// @notice Get the rebate fee share for a user
    /// @param _user The address of the user
    /// @return The rebate fee share
    function getRebateFeeShare(address _user) external view returns (uint256) {
        if (blacklisted[_user] || !referralEnabled) {
            return 0;
        }
        return rebateFeeShare[_user];
    }

    /// @notice Get the referral fee share for a user
    /// @param _user The address of the user
    /// @return The referral fee share
    function getReferralFeeShare(
        address _user
    ) external view returns (uint256) {
        if (blacklisted[_user] || !referralEnabled) {
            return 0;
        }
        return referralFeeShare[_user];
    }

    /// @notice Get the referrer by referral code
    /// @param _referralCode The referral code
    /// @return The address of the referrer
    function getReferrerByReferralCode(
        string memory _referralCode
    ) external view returns (address) {
        return referralCodeToReferrer[_referralCode];
    }

    /// @notice Get the referral code for a referrer
    /// @param _referrer The address of the referrer
    /// @return The referral code
    function getReferralCode(
        address _referrer
    ) external view returns (string memory) {
        return referrerToReferralCode[_referrer];
    }

    /// @notice Get the referrer for a user
    /// @param _referee The address of the user
    /// @return The address of the referrer
    function getReferrer(address _referee) external view returns (address) {
        return refereeToReferrer[_referee];
    }

    /// @notice Get the rebate fee shares for multiple users
    /// @param users The addresses of the users
    /// @return The rebate fee shares
    function getRebateFeeShares(
        address[] calldata users
    ) external view returns (uint256[] memory) {
        uint256[] memory rebateShares = new uint256[](users.length);
        for (uint256 i = 0; i < users.length; i++) {
            if (blacklisted[users[i]] || !referralEnabled) {
                rebateShares[i] = 0;
            } else {
                rebateShares[i] = rebateFeeShare[users[i]];
            }
        }
        return rebateShares;
    }

    /// @notice Get the referral fee shares for multiple users
    /// @param users The addresses of the users
    /// @return The referral fee shares
    function getReferralFeeShares(
        address[] calldata users
    ) external view returns (uint256[] memory) {
        uint256[] memory referralShares = new uint256[](users.length);
        for (uint256 i = 0; i < users.length; i++) {
            if (blacklisted[users[i]] || !referralEnabled) {
                referralShares[i] = 0;
            } else {
                referralShares[i] = referralFeeShare[users[i]];
            }
        }
        return referralShares;
    }
}

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

import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import "./Ownable.sol";

contract Signable is EIP712, Ownable {
    using ECDSA for bytes32;

    string private constant SIGNING_DOMAIN = "PinguReferral";
    string private constant SIGNATURE_VERSION = "1";

    address private signer;

    constructor() EIP712(SIGNING_DOMAIN, SIGNATURE_VERSION) {}

    bytes32 private constant TYPEHASH =
        keccak256("Referral(string refcode,address user)");

    function setSigner(address _signer) external onlyOwner {
        signer = _signer;
    }

    function verify(
        string calldata refcode,
        address user,
        bytes calldata signature
    ) external view returns (bool) {
        bytes32 structHash = keccak256(
            abi.encode(TYPEHASH, keccak256(bytes(refcode)), user)
        );

        bytes32 digest = _hashTypedDataV4(structHash);

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

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

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

/// @title DataStore
/// @notice General purpose storage contract
/// @dev Access is restricted to governance
contract DataStore is Governable {
    // Key-value stores
    mapping(bytes32 => uint256) public uintValues;
    mapping(bytes32 => int256) public intValues;
    mapping(bytes32 => address) public addressValues;
    mapping(bytes32 => bytes32) public dataValues;
    mapping(bytes32 => bool) public boolValues;
    mapping(bytes32 => string) public stringValues;

    function initialize() external initializer {
        _setGov(msg.sender);
    }

    /// @param key The key for the record
    /// @param value value to store
    /// @param overwrite Overwrites existing value if set to true
    function setUint(
        string calldata key,
        uint256 value,
        bool overwrite
    ) external onlyGov returns (bool) {
        bytes32 hash = getHash(key);
        if (overwrite || uintValues[hash] == 0) {
            uintValues[hash] = value;
            return true;
        }
        return false;
    }

    /// @param key The key for the record
    function getUint(string calldata key) external view returns (uint256) {
        return uintValues[getHash(key)];
    }

    /// @param key The key for the record
    /// @param value value to store
    /// @param overwrite Overwrites existing value if set to true
    function setInt(
        string calldata key,
        int256 value,
        bool overwrite
    ) external onlyGov returns (bool) {
        bytes32 hash = getHash(key);
        if (overwrite || intValues[hash] == 0) {
            intValues[hash] = value;
            return true;
        }
        return false;
    }

    /// @param key The key for the record
    function getInt(string calldata key) external view returns (int256) {
        return intValues[getHash(key)];
    }

    /// @param key The key for the record
    /// @param value address to store
    /// @param overwrite Overwrites existing value if set to true
    function setAddress(
        string calldata key,
        address value,
        bool overwrite
    ) external onlyGov returns (bool) {
        bytes32 hash = getHash(key);
        if (overwrite || addressValues[hash] == address(0)) {
            addressValues[hash] = value;
            return true;
        }
        return false;
    }

    /// @param key The key for the record
    function getAddress(string calldata key) external view returns (address) {
        return addressValues[getHash(key)];
    }

    /// @param key The key for the record
    /// @param value byte value to store
    function setData(
        string calldata key,
        bytes32 value
    ) external onlyGov returns (bool) {
        dataValues[getHash(key)] = value;
        return true;
    }

    /// @param key The key for the record
    function getData(string calldata key) external view returns (bytes32) {
        return dataValues[getHash(key)];
    }

    /// @param key The key for the record
    /// @param value value to store (true / false)
    function setBool(
        string calldata key,
        bool value
    ) external onlyGov returns (bool) {
        boolValues[getHash(key)] = value;
        return true;
    }

    /// @param key The key for the record
    function getBool(string calldata key) external view returns (bool) {
        return boolValues[getHash(key)];
    }

    /// @param key The key for the record
    /// @param value string to store
    function setString(
        string calldata key,
        string calldata value
    ) external onlyGov returns (bool) {
        stringValues[getHash(key)] = value;
        return true;
    }

    /// @param key The key for the record
    function getString(
        string calldata key
    ) external view returns (string memory) {
        return stringValues[getHash(key)];
    }

    /// @param key string to hash
    function getHash(string memory key) public pure returns (bytes32) {
        return keccak256(abi.encodePacked(key));
    }
}

File 5 of 16 : Roles.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

import "./Governable.sol";
import "./RoleStore.sol";

/// @title Roles
/// @notice Role-based access control mechanism via onlyContract modifier
abstract contract Roles is Governable {
    bytes32 internal constant CONTRACT_ROLE = keccak256("CONTRACT");

    RoleStore public roleStore;

    /// @dev Reverts if caller address has not the contract role
    modifier onlyContract() {
        require(roleStore.hasRole(msg.sender, CONTRACT_ROLE), "!contract-role");
        _;
    }
}

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

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic 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 their contracts 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].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // 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 _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @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) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, 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 ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}

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

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @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,
        InvalidSignatureV // Deprecated in v4.8
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode 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 {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]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        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);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode 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 {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        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]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        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.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // 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);
        }

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

        return (signer, RecoverError.NoError);
    }

    /**
     * @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) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.17;

import "./Context.sol";

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

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

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

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

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

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

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

/// @title Governable
/// @notice Basic access control mechanism, gov has access to certain functions
abstract contract Governable is Initializable {
    address public gov;

    event SetGov(address prevGov, address nextGov);

    /// @dev Reverts if called by any account other than gov
    modifier onlyGov() {
        require(msg.sender == gov, "!gov");
        _;
    }

    /// @notice Sets a new governance address
    /// @dev Only callable by governance
    function setGov(address _gov) external onlyGov {
        _setGov(_gov);
    }

    /// @notice Sets a new governance address
    /// @dev Internal function without access restriction
    function _setGov(address _gov) internal {
        require(_gov != address(0), "!zero-gov");
        address prevGov = gov;
        gov = _gov;
        emit SetGov(prevGov, _gov);
    }
}

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

import "./EnumerableSet.sol";
import "./Governable.sol";

/**
 * @title  RoleStore
 * @notice Role-based access control mechanism. Governance can grant and
 *         revoke roles dynamically via {grantRole} and {revokeRole}
 */
contract RoleStore is Governable {
    // Libraries
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.Bytes32Set;

    event RoleGranted(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );
    event RoleRevoked(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );

    // Set of roles
    EnumerableSet.Bytes32Set internal roles;

    // Role -> address
    mapping(bytes32 => EnumerableSet.AddressSet) internal roleMembers;

    function initialize() external initializer {
        _setGov(msg.sender);
    }

    /// @notice Grants `role` to `account`
    /// @dev Only callable by governance
    function grantRole(address account, bytes32 role) external onlyGov {
        // add role if not already present
        if (!roles.contains(role)) roles.add(role);

        require(roleMembers[role].add(account));
        emit RoleGranted(role, account, msg.sender);
    }

    /// @notice Revokes `role` from `account`
    /// @dev Only callable by governance
    function revokeRole(address account, bytes32 role) external onlyGov {
        require(roleMembers[role].remove(account));
        emit RoleRevoked(role, account, msg.sender);

        // Remove role if it has no longer any members
        if (roleMembers[role].length() == 0) {
            roles.remove(role);
        }
    }

    /// @notice Returns `true` if `account` has been granted `role`
    function hasRole(
        address account,
        bytes32 role
    ) external view returns (bool) {
        return roleMembers[role].contains(account);
    }

    /// @notice Returns number of roles
    function getRoleCount() external view returns (uint256) {
        return roles.length();
    }
}

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

pragma solidity ^0.8.0;

import "./math/Math.sol";

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

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

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

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

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

// SPDX-License-Identifier: MIT

pragma solidity 0.8.17;

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

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

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

pragma solidity ^0.8.2;

import "../../utils/Address.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity 0.8.17;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(
        Set storage set,
        bytes32 value
    ) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(
        Set storage set,
        uint256 index
    ) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        Bytes32Set storage set,
        bytes32 value
    ) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        Bytes32Set storage set,
        uint256 index
    ) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        Bytes32Set storage set
    ) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        AddressSet storage set,
        address value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        AddressSet storage set,
        uint256 index
    ) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        AddressSet storage set
    ) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(
        UintSet storage set,
        uint256 value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(
        UintSet storage set,
        uint256 value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(
        UintSet storage set,
        uint256 index
    ) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(
        UintSet storage set
    ) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

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

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

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

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

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

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

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

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

Settings
{
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "chainlink/=node_modules/@chainlink/",
    "pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity/",
    "@uniswap/v2-periphery/=node_modules/@uniswap/v2-periphery/",
    "@uniswap/v2-core/=node_modules/@uniswap/v2-core/",
    "ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "viaIR": true
}

Contract Security Audit

Contract ABI

API
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"string","name":"referralCode","type":"string"}],"name":"ReferralRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"referee","type":"address"},{"indexed":false,"internalType":"string","name":"referralCode","type":"string"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"}],"name":"ReferralSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"prevGov","type":"address"},{"indexed":false,"internalType":"address","name":"nextGov","type":"address"}],"name":"SetGov","type":"event"},{"inputs":[],"name":"dataStore","outputs":[{"internalType":"contract DataStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gov","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rs","type":"address"},{"internalType":"address","name":"ds","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"link","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"referralStore","outputs":[{"internalType":"contract ReferralStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_referralCode","type":"string"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"registerReferral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roleStore","outputs":[{"internalType":"contract RoleStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_gov","type":"address"}],"name":"setGov","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_referralCode","type":"string"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"setReferrer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signable","outputs":[{"internalType":"contract Signable","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

6080806040523461001657610e67908161001c8239f35b600080fdfe608060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a5114610ab8575081631c4695f41461097c578163485cc9551461081d5781634a4a7b04146107f4578163660d0d67146107cc57816368f8b4c0146107a35781636c0ba1911461041857816370eedc57146100fd57508063cfad57a2146100be5763d4dd357e1461009357600080fd5b346100ba57816003193601126100ba5760035490516001600160a01b039091168152602090f35b5080fd5b82346100fa5760203660031901126100fa576100f76100db610adf565b6100f260018060a01b03845460101c163314610c02565b610c34565b80f35b80fd5b9190503461028b5761010e36610b99565b600254835163846d1d8360e01b81529294926001600160a01b0392602092839183918616908290819061014590338d848d01610d56565b03915afa90811561035857906101629188916103fb575b50610d8a565b816003541691845163fe575a8760e01b815233858201528281602481875afa9081156103c4579061019b9189916103ce575b5015610dcb565b845163df2f6e2960e01b81528481018390528281806101bd602482018b610d31565b0381875afa9081156103c4578891610397575b50166103625783516324b100d160e21b815233848201528681602481865afa9081156103585787916102db575b50516102995750908185923b1561028b57848391610231938387518096819582946318d3082160e21b845233908401610e0f565b03925af1801561028f57610277575b5081517f79a86b4c4524bb1efe5d0f41282fada9d4697494d4e44e5fabeec124283a765a9080610271863383610e0f565b0390a180f35b61028090610afa565b61028b578238610240565b8280fd5b83513d84823e3d90fd5b9050606492519162461bcd60e51b8352820152601c60248201527f2172656665727265722d616c72656164792d72656769737465726564000000006044820152fd5b90503d8088833e6102ec8183610b24565b81019082818303126103545780519067ffffffffffffffff8211610350570181601f8201121561035457805161032181610b46565b9261032e88519485610b24565b8184528482840101116103505761034a91848085019101610d0e565b386101fd565b8880fd5b8780fd5b85513d89823e3d90fd5b9050606492519162461bcd60e51b8352820152601060248201526f217265662d636f64652d65786973747360801b6044820152fd5b6103b79150833d85116103bd575b6103af8183610b24565b810190610cd7565b386101d0565b503d6103a5565b86513d8a823e3d90fd5b6103ee9150843d86116103f4575b6103e68183610b24565b810190610cf6565b38610194565b503d6103dc565b6104129150833d85116103f4576103e68183610b24565b3861015c565b9190503461028b5761045b9161042d36610b99565b9160018060a01b03928360025416908551809263846d1d8360e01b8252818060209a8b95338a8a8501610d56565b03915afa908115610358579061047791889161078c5750610d8a565b826003541690845163fe575a8760e01b94858252338383015260249188818481885afa9081156106cd578a9161076f575b50610736578651634a9fefc760e01b8152338482015288818481885afa9081156106cd579082918b91610719575b50166106d757865163df2f6e2960e01b81528381018990528881806104fd8682018a610d31565b0381885afa9081156106cd578a916106b0575b50169433861461067d57851561063b57908789939288519283918252888583015281875afa908115610631579061054e91849161061a575015610dcb565b823b156100ba5761057792849183885180968195829463fd0dfb8560e01b845233908401610e0f565b03925af18015610610576105d0575b50917f4b14a61cf22b66b103723cab1369493f61f531559bc5569ee978191c2b5bdfb593916105c660609483519586953387528601526060850190610d31565b918301520390a180f35b916105c660609492966106047f4b14a61cf22b66b103723cab1369493f61f531559bc5569ee978191c2b5bdfb59795610afa565b96929450509193610586565b84513d88823e3d90fd5b6103ee9150893d8b116103f4576103e68183610b24565b87513d85823e3d90fd5b865162461bcd60e51b81528084018990526018818401527f217265662d636f64652d6e6f742d7265676973746572656400000000000000006044820152606490fd5b865162461bcd60e51b8152808401899052600e818401526d085cd95b198b5c9959995c9c985b60921b6044820152606490fd5b6106c79150893d8b116103bd576103af8183610b24565b38610510565b88513d8c823e3d90fd5b865162461bcd60e51b8152808401899052601b818401527f21726566657265652d616c72656164792d7265676973746572656400000000006044820152606490fd5b61073091508a3d8c116103bd576103af8183610b24565b386104d6565b865162461bcd60e51b815280840189905260148184015273085c9959995c99594b589b1858dadb1a5cdd195960621b6044820152606490fd5b6107869150893d8b116103f4576103e68183610b24565b386104a8565b6104129150873d89116103f4576103e68183610b24565b5050346100ba57816003193601126100ba5760025490516001600160a01b039091168152602090f35b90503461028b578260031936011261028b575490516001600160a01b03909116815260209150f35b5050346100ba57816003193601126100ba5760015490516001600160a01b039091168152602090f35b90503461028b578160031936011261028b57610837610adf565b6001600160a01b03919060243583811691908290036109785785549360ff8560081c16159485809661096b575b8015610954575b156108fa5760ff1981166001178855856108e9575b506bffffffffffffffffffffffff60a01b91168160015416176001558254161790556108ab33610c34565b6108b3575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b61ffff191661010117875538610880565b865162461bcd60e51b8152602081870152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b15801561086b5750600160ff82161461086b565b50600160ff821610610864565b8580fd5b9190503461028b578260031936011261028b5760018060a01b03906109a882855460101c163314610c02565b8183541681519363bf40fac160e01b808652602092838388015260086024880152675369676e61626c6560c01b60448801528387606481845afa968715610aae578897610a84575b509160648493928493886bffffffffffffffffffffffff60a01b9a168a6002541617600255875196879485938452830152600d60248301526c526566657272616c53746f726560981b60448301525afa928315610a7b57508592610a5e575b50501690600354161760035580f35b610a749250803d106103bd576103af8183610b24565b3880610a4f565b513d87823e3d90fd5b84939197508392610aa3606492853d87116103bd576103af8183610b24565b9892945092506109f0565b85513d8a823e3d90fd5b8490346100ba57816003193601126100ba57905460101c6001600160a01b03168152602090f35b600435906001600160a01b0382168203610af557565b600080fd5b67ffffffffffffffff8111610b0e57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117610b0e57604052565b67ffffffffffffffff8111610b0e57601f01601f191660200190565b929192610b6e82610b46565b91610b7c6040519384610b24565b829481845281830111610af5578281602093846000960137010152565b906040600319830112610af55767ffffffffffffffff600435818111610af55783602382011215610af55783816024610bd793600401359101610b62565b92602435918211610af55780602383011215610af557816024610bff93600401359101610b62565b90565b15610c0957565b606460405162461bcd60e51b815260206004820152600460248201526310b3b7bb60e11b6044820152fd5b6001600160a01b03818116918215610ca6576000805462010000600160b01b03198116601093841b62010000600160b01b031617909155604080519190921c909216825260208201929092527f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f7859190a1565b60405162461bcd60e51b815260206004820152600960248201526810bd32b93796b3b7bb60b91b6044820152606490fd5b90816020910312610af557516001600160a01b0381168103610af55790565b90816020910312610af557518015158103610af55790565b60005b838110610d215750506000910152565b8181015183820152602001610d11565b90602091610d4a81518092818552858086019101610d0e565b601f01601f1916010190565b610d6c610bff9492606083526060830190610d31565b6001600160a01b039093166020820152808303604090910152610d31565b15610d9157565b60405162461bcd60e51b815260206004820152601260248201527121696e76616c69642d7369676e617475726560701b6044820152606490fd5b15610dd257565b60405162461bcd60e51b8152602060048201526015602482015274085c9959995c9c995c8b589b1858dadb1a5cdd1959605a1b6044820152606490fd5b6001600160a01b039091168152604060208201819052610bff92910190610d3156fea2646970667358221220a81327c32b6041d0e3118e3de13a54e5f41a9733614ab2078679f465fce8366864736f6c63430008110033

Deployed Bytecode

0x608060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a5114610ab8575081631c4695f41461097c578163485cc9551461081d5781634a4a7b04146107f4578163660d0d67146107cc57816368f8b4c0146107a35781636c0ba1911461041857816370eedc57146100fd57508063cfad57a2146100be5763d4dd357e1461009357600080fd5b346100ba57816003193601126100ba5760035490516001600160a01b039091168152602090f35b5080fd5b82346100fa5760203660031901126100fa576100f76100db610adf565b6100f260018060a01b03845460101c163314610c02565b610c34565b80f35b80fd5b9190503461028b5761010e36610b99565b600254835163846d1d8360e01b81529294926001600160a01b0392602092839183918616908290819061014590338d848d01610d56565b03915afa90811561035857906101629188916103fb575b50610d8a565b816003541691845163fe575a8760e01b815233858201528281602481875afa9081156103c4579061019b9189916103ce575b5015610dcb565b845163df2f6e2960e01b81528481018390528281806101bd602482018b610d31565b0381875afa9081156103c4578891610397575b50166103625783516324b100d160e21b815233848201528681602481865afa9081156103585787916102db575b50516102995750908185923b1561028b57848391610231938387518096819582946318d3082160e21b845233908401610e0f565b03925af1801561028f57610277575b5081517f79a86b4c4524bb1efe5d0f41282fada9d4697494d4e44e5fabeec124283a765a9080610271863383610e0f565b0390a180f35b61028090610afa565b61028b578238610240565b8280fd5b83513d84823e3d90fd5b9050606492519162461bcd60e51b8352820152601c60248201527f2172656665727265722d616c72656164792d72656769737465726564000000006044820152fd5b90503d8088833e6102ec8183610b24565b81019082818303126103545780519067ffffffffffffffff8211610350570181601f8201121561035457805161032181610b46565b9261032e88519485610b24565b8184528482840101116103505761034a91848085019101610d0e565b386101fd565b8880fd5b8780fd5b85513d89823e3d90fd5b9050606492519162461bcd60e51b8352820152601060248201526f217265662d636f64652d65786973747360801b6044820152fd5b6103b79150833d85116103bd575b6103af8183610b24565b810190610cd7565b386101d0565b503d6103a5565b86513d8a823e3d90fd5b6103ee9150843d86116103f4575b6103e68183610b24565b810190610cf6565b38610194565b503d6103dc565b6104129150833d85116103f4576103e68183610b24565b3861015c565b9190503461028b5761045b9161042d36610b99565b9160018060a01b03928360025416908551809263846d1d8360e01b8252818060209a8b95338a8a8501610d56565b03915afa908115610358579061047791889161078c5750610d8a565b826003541690845163fe575a8760e01b94858252338383015260249188818481885afa9081156106cd578a9161076f575b50610736578651634a9fefc760e01b8152338482015288818481885afa9081156106cd579082918b91610719575b50166106d757865163df2f6e2960e01b81528381018990528881806104fd8682018a610d31565b0381885afa9081156106cd578a916106b0575b50169433861461067d57851561063b57908789939288519283918252888583015281875afa908115610631579061054e91849161061a575015610dcb565b823b156100ba5761057792849183885180968195829463fd0dfb8560e01b845233908401610e0f565b03925af18015610610576105d0575b50917f4b14a61cf22b66b103723cab1369493f61f531559bc5569ee978191c2b5bdfb593916105c660609483519586953387528601526060850190610d31565b918301520390a180f35b916105c660609492966106047f4b14a61cf22b66b103723cab1369493f61f531559bc5569ee978191c2b5bdfb59795610afa565b96929450509193610586565b84513d88823e3d90fd5b6103ee9150893d8b116103f4576103e68183610b24565b87513d85823e3d90fd5b865162461bcd60e51b81528084018990526018818401527f217265662d636f64652d6e6f742d7265676973746572656400000000000000006044820152606490fd5b865162461bcd60e51b8152808401899052600e818401526d085cd95b198b5c9959995c9c985b60921b6044820152606490fd5b6106c79150893d8b116103bd576103af8183610b24565b38610510565b88513d8c823e3d90fd5b865162461bcd60e51b8152808401899052601b818401527f21726566657265652d616c72656164792d7265676973746572656400000000006044820152606490fd5b61073091508a3d8c116103bd576103af8183610b24565b386104d6565b865162461bcd60e51b815280840189905260148184015273085c9959995c99594b589b1858dadb1a5cdd195960621b6044820152606490fd5b6107869150893d8b116103f4576103e68183610b24565b386104a8565b6104129150873d89116103f4576103e68183610b24565b5050346100ba57816003193601126100ba5760025490516001600160a01b039091168152602090f35b90503461028b578260031936011261028b575490516001600160a01b03909116815260209150f35b5050346100ba57816003193601126100ba5760015490516001600160a01b039091168152602090f35b90503461028b578160031936011261028b57610837610adf565b6001600160a01b03919060243583811691908290036109785785549360ff8560081c16159485809661096b575b8015610954575b156108fa5760ff1981166001178855856108e9575b506bffffffffffffffffffffffff60a01b91168160015416176001558254161790556108ab33610c34565b6108b3575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b61ffff191661010117875538610880565b865162461bcd60e51b8152602081870152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608490fd5b50303b15801561086b5750600160ff82161461086b565b50600160ff821610610864565b8580fd5b9190503461028b578260031936011261028b5760018060a01b03906109a882855460101c163314610c02565b8183541681519363bf40fac160e01b808652602092838388015260086024880152675369676e61626c6560c01b60448801528387606481845afa968715610aae578897610a84575b509160648493928493886bffffffffffffffffffffffff60a01b9a168a6002541617600255875196879485938452830152600d60248301526c526566657272616c53746f726560981b60448301525afa928315610a7b57508592610a5e575b50501690600354161760035580f35b610a749250803d106103bd576103af8183610b24565b3880610a4f565b513d87823e3d90fd5b84939197508392610aa3606492853d87116103bd576103af8183610b24565b9892945092506109f0565b85513d8a823e3d90fd5b8490346100ba57816003193601126100ba57905460101c6001600160a01b03168152602090f35b600435906001600160a01b0382168203610af557565b600080fd5b67ffffffffffffffff8111610b0e57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117610b0e57604052565b67ffffffffffffffff8111610b0e57601f01601f191660200190565b929192610b6e82610b46565b91610b7c6040519384610b24565b829481845281830111610af5578281602093846000960137010152565b906040600319830112610af55767ffffffffffffffff600435818111610af55783602382011215610af55783816024610bd793600401359101610b62565b92602435918211610af55780602383011215610af557816024610bff93600401359101610b62565b90565b15610c0957565b606460405162461bcd60e51b815260206004820152600460248201526310b3b7bb60e11b6044820152fd5b6001600160a01b03818116918215610ca6576000805462010000600160b01b03198116601093841b62010000600160b01b031617909155604080519190921c909216825260208201929092527f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f7859190a1565b60405162461bcd60e51b815260206004820152600960248201526810bd32b93796b3b7bb60b91b6044820152606490fd5b90816020910312610af557516001600160a01b0381168103610af55790565b90816020910312610af557518015158103610af55790565b60005b838110610d215750506000910152565b8181015183820152602001610d11565b90602091610d4a81518092818552858086019101610d0e565b601f01601f1916010190565b610d6c610bff9492606083526060830190610d31565b6001600160a01b039093166020820152808303604090910152610d31565b15610d9157565b60405162461bcd60e51b815260206004820152601260248201527121696e76616c69642d7369676e617475726560701b6044820152606490fd5b15610dd257565b60405162461bcd60e51b8152602060048201526015602482015274085c9959995c9c995c8b589b1858dadb1a5cdd1959605a1b6044820152606490fd5b6001600160a01b039091168152604060208201819052610bff92910190610d3156fea2646970667358221220a81327c32b6041d0e3118e3de13a54e5f41a9733614ab2078679f465fce8366864736f6c63430008110033

Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.