Address Details
contract

0x3d150B0f44DaE282D4E5751DD7B8ABE297CD0d49

Contract Name
AmbassadorsImplementation
Creator
0xa34737–43edab at 0xb1dd58–f1106b
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
22721592
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
AmbassadorsImplementation




Optimization enabled
true
Compiler version
v0.8.4+commit.c7e474f2




Optimization runs
200
EVM Version
istanbul




Verified at
2022-06-28T20:02:21.331563Z

contracts/ambassadors/AmbassadorsImplementation.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./interfaces/AmbassadorsStorageV1.sol";
import "../community/interfaces/ICommunityAdmin.sol";

/**
 * @notice Welcome to Ambassadors contract.
 */
contract AmbassadorsImplementation is
    Initializable,
    OwnableUpgradeable,
    ReentrancyGuardUpgradeable,
    AmbassadorsStorageV1
{
    using EnumerableSet for EnumerableSet.AddressSet;

    /**
     * @notice Triggered when an entity is added.
     *
     * @param entity Address of the entity added
     *
     */
    event EntityAdded(address indexed entity);

    /**
     * @notice Triggered when an entity is removed.
     *
     * @param entity Address of the entity removed
     *
     */
    event EntityRemoved(address indexed entity);

    /**
     * @notice Triggered when an entity replaced account address.
     *
     * @param entityIndex Entity index replacing account address
     * @param oldAccount Old account address
     * @param newAccount New account address
     *
     */
    event EntityAccountReplaced(
        uint256 entityIndex,
        address indexed oldAccount,
        address indexed newAccount
    );

    /**
     * @notice Triggered when an ambassador is added to an entity.
     *
     * @param ambassador Address of the ambassador added
     * @param entity Address of the entity where the ambassador is added
     *
     */
    event AmbassadorAdded(address indexed ambassador, address indexed entity);

    /**
     * @notice Triggered when an ambassador is removed.
     *
     * @param ambassador Address of the ambassador removed
     * @param entity Address of the entity where the ambassador is removed
     *
     */
    event AmbassadorRemoved(address indexed ambassador, address indexed entity);

    /**
     * @notice Triggered when an ambassador is replaced by the entity.
     *
     * @param ambassadorIndex Index of the ambassador being replaced
     * @param entityAccount Address of the entity where ambassador is being replaced
     * @param oldAmbassador Ambassador's old account address
     * @param newAmbassador Ambassador's new account address
     *
     */
    event AmbassadorReplaced(
        uint256 ambassadorIndex,
        address indexed entityAccount,
        address indexed oldAmbassador,
        address indexed newAmbassador
    );

    /**
     * @notice Triggered when an ambassador replaces it's own account.
     *
     * @param ambassadorIndex Index of the ambassador being replaced
     * @param entityAccount Address of the entity where ambassador is being replaced
     * @param oldAccount Ambassador's old account address
     * @param newAccount Ambassador's new account address
     *
     */
    event AmbassadorAccountReplaced(
        uint256 ambassadorIndex,
        address indexed entityAccount,
        address indexed oldAccount,
        address indexed newAccount
    );

    /**
     * @notice Triggered when an ambassador is transfered to a new entity.
     *
     * @param ambassador Ambassador address being replaced
     * @param oldEntity Entity's old account address
     * @param newEntity Entity's new account address
     *
     */
    event AmbassadorTransfered(
        address indexed ambassador,
        address indexed oldEntity,
        address indexed newEntity
    );

    /**
     * @notice Triggered when a community is transfered from one ambassador to another.
     *
     * @param fromAmbassador Ambassador address from which the community is being transfered from
     * @param toAmbassador Ambassador address to which the community is being transfered to
     * @param community Community address being transfered
     *
     */
    event AmbassadorToCommunityUpdated(
        address indexed fromAmbassador,
        address indexed toAmbassador,
        address indexed community
    );

    /**
     * @notice Triggered when a community is removed.
     *
     * @param ambassador Ambassador of the community being removed
     * @param community Community address being removed
     *
     */
    event CommunityRemoved(address indexed ambassador, address indexed community);

    /**
     * @notice Enforces sender to be an ambassador
     */
    modifier onlyAmbassador() {
        require(ambassadorByAddress[msg.sender] != 0, "Ambassador:: ONLY_AMBASSADOR");
        _;
    }

    /**
     * @notice Enforces sender to be an entity
     */
    modifier onlyEntity() {
        require(entityByAddress[msg.sender] != 0, "Ambassador:: ONLY_ENTITY");
        _;
    }

    /**
     * @notice Enforces sender to be an entity or owner
     */
    modifier onlyEntityOrOwner() {
        require(
            entityByAddress[msg.sender] != 0 || owner() == msg.sender,
            "Ambassador:: ONLY_ENTITY_OR_OWNER"
        );
        _;
    }

    /**
     * @notice Enforces sender to be te community admin contract
     */
    modifier onlyCommunityAdmin() {
        require(address(communityAdmin) == msg.sender, "Ambassador:: ONLY_COMMUNITY_ADMIN");
        _;
    }

    /**
     * @notice Used to initialize a new Ambassadors contract
     *
     * @param _communityAdmin Address of the community admin contract
     *
     */
    function initialize(ICommunityAdmin _communityAdmin) external initializer {
        __Ownable_init();
        __ReentrancyGuard_init();

        ambassadorIndex = 1;
        entityIndex = 1;
        communityAdmin = _communityAdmin;
    }

    /**
     * @notice Returns the current implementation version
     */
    function getVersion() external pure override returns (uint256) {
        return 1;
    }

    /**
     * @notice Returns boolean whether an address is ambassador or not.
     *
     * @param _ambassador Address of the ambassador
     * @return Boolean whether an address is ambassador or not
     */
    function isAmbassador(address _ambassador) public view override returns (bool) {
        return ambassadorByAddress[_ambassador] != 0;
    }

    /**
     * @notice Returns boolean whether an address is ambassador of a given community.
     *
     * @param _ambassador Address of the ambassador
     * @param _community Address of the community
     * @return Boolean whether an address is ambassador of a given community or not
     */
    function isAmbassadorOf(address _ambassador, address _community)
        public
        view
        override
        returns (bool)
    {
        return ambassadorByAddress[_ambassador] == communityToAmbassador[_community];
    }

    /**
     * @notice Returns boolean whether an address is entity responsible for ambassador of a given community.
     *
     * @param _entity Address of the entity
     * @param _community Address of the community
     * @return Boolean whether an address is entity responsible for ambassador of a given community or not
     */
    function isEntityOf(address _entity, address _community) public view override returns (bool) {
        return entityByAddress[_entity] == ambassadorToEntity[communityToAmbassador[_community]];
    }

    /**
     * @notice Returns boolean whether an address is ambassador at a given entity.
     *
     * @param _ambassador Address of the ambassador
     * @param _entityAddress Address of the entity
     * @return Boolean whether an address is ambassador at a given entity or not
     */
    function isAmbassadorAt(address _ambassador, address _entityAddress)
        public
        view
        override
        returns (bool)
    {
        return
            ambassadorToEntity[ambassadorByAddress[_ambassador]] == entityByAddress[_entityAddress];
    }

    /** Updates the address of the communityAdmin
     *
     * @param _newCommunityAdmin address of the new communityAdmin
     * @dev used only for testing the new community upgrade flow
     */
    function updateCommunityAdmin(ICommunityAdmin _newCommunityAdmin) external onlyOwner {
        communityAdmin = _newCommunityAdmin;
    }

    /**
     * @notice Registers an entity.
     *
     * @param _entity Address of the entity
     */
    function addEntity(address _entity) public override onlyOwner {
        require(entityByAddress[_entity] == 0, "Ambassador:: ALREADY_ENTITY");

        entityByAddress[_entity] = entityIndex;
        entityByIndex[entityIndex] = _entity;
        entityIndex++;

        emit EntityAdded(_entity);
    }

    /**
     * @notice Removes an entity.
     *
     * @param _entity Address of the entity
     */
    function removeEntity(address _entity) public override onlyOwner {
        uint256 entityIndex = entityByAddress[_entity];

        require(entityIndex != 0, "Ambassador:: NOT_ENTITY");
        require(entityAmbassadors[entityIndex] == 0, "Ambassador:: HAS_AMBASSADORS");

        entityByIndex[entityIndex] = address(0);
        entityByAddress[_entity] = 0;

        emit EntityRemoved(_entity);
    }

    /**
     * @notice Replace entity account.
     *
     * @param _entity Address of the entity
     * @param _newEntity New entity address
     */
    function replaceEntityAccount(address _entity, address _newEntity) external override {
        uint256 entityIndex = entityByAddress[_entity];

        require(msg.sender == _entity || msg.sender == owner(), "Ambassador:: NOT_ALLOWED");
        require(entityIndex != 0, "Ambassador:: NOT_ENTITY");

        entityByIndex[entityIndex] = _newEntity;
        entityByAddress[_newEntity] = entityByAddress[_entity];
        entityByAddress[_entity] = 0;

        emit EntityAccountReplaced(entityIndex, _entity, _newEntity);
    }

    /**
     * @notice Registers an ambassador.
     *
     * @param _ambassador Address of the ambassador
     */
    function addAmbassador(address _ambassador) external override onlyEntity {
        require(!isAmbassador(_ambassador), "Ambassador:: ALREADY_AMBASSADOR");

        uint256 entityIndex = entityByAddress[msg.sender];

        ambassadorByAddress[_ambassador] = ambassadorIndex;
        ambassadorByIndex[ambassadorIndex] = _ambassador;
        ambassadorToEntity[ambassadorIndex] = entityIndex;
        entityAmbassadors[entityIndex]++;
        ambassadorIndex++;

        emit AmbassadorAdded(_ambassador, msg.sender);
    }

    /**
     * @notice Removes an ambassador.
     *
     * @param _ambassador Address of the ambassador
     */
    function removeAmbassador(address _ambassador) external override onlyEntity {
        uint256 thisAmbassadorIndex = ambassadorByAddress[_ambassador];
        uint256 entityIndex = entityByAddress[msg.sender];

        require(isAmbassadorAt(_ambassador, msg.sender), "Ambassador:: NOT_AMBASSADOR");
        require(
            ambassadorCommunities[thisAmbassadorIndex].length() == 0,
            "Ambassador:: HAS_COMMUNITIES"
        );

        entityAmbassadors[entityIndex]--;
        ambassadorByAddress[_ambassador] = 0;

        emit AmbassadorRemoved(_ambassador, msg.sender);
    }

    /**
     * @notice Replace ambassador account. Called by ambassador.
     *
     * @param _ambassador Address of the ambassador
     * @param _newAmbassador New ambassador address
     */
    function replaceAmbassadorAccount(address _ambassador, address _newAmbassador)
        external
        override
    {
        require(msg.sender == _ambassador || msg.sender == owner(), "Ambassador:: NOT_ALLOWED");
        require(isAmbassador(_ambassador), "Ambassador:: NOT_AMBASSADOR");
        require(!isAmbassador(_newAmbassador), "Ambassador:: ALREADY_AMBASSADOR");

        uint256 thisAmbassadorIndex;
        address entityAddress;
        address oldAmbassador;
        address newAmbassador;
        (
            thisAmbassadorIndex,
            entityAddress,
            oldAmbassador,
            newAmbassador
        ) = _replaceAmbassadorAccountInternal(_ambassador, _newAmbassador);

        emit AmbassadorAccountReplaced(
            thisAmbassadorIndex,
            entityAddress,
            oldAmbassador,
            newAmbassador
        );
    }

    /**
     * @notice Replaces an ambassador. Called by entity.
     *
     * @param _oldAmbassador Address of the ambassador
     * @param _newAmbassador New ambassador address
     */
    function replaceAmbassador(address _oldAmbassador, address _newAmbassador) external override {
        require(
            isAmbassadorAt(_oldAmbassador, msg.sender) || msg.sender == owner(),
            "Ambassador:: NOT_AMBASSADOR"
        );
        require(!isAmbassador(_newAmbassador), "Ambassador:: ALREADY_AMBASSADOR");

        uint256 thisAmbassadorIndex;
        address entityAddress;
        address oldAmbassador;
        address newAmbassador;
        (
            thisAmbassadorIndex,
            entityAddress,
            oldAmbassador,
            newAmbassador
        ) = _replaceAmbassadorAccountInternal(_oldAmbassador, _newAmbassador);

        emit AmbassadorReplaced(thisAmbassadorIndex, entityAddress, oldAmbassador, newAmbassador);
    }

    /**
     * @notice Transfers an ambassador to another entity.
     *
     * @param _ambassador Address of the ambassador
     * @param _toEntity Address of the entity
     * @param _keepCommunities Boolean whether to keep the ambassador's communities or not
     */
    function transferAmbassador(
        address _ambassador,
        address _toEntity,
        bool _keepCommunities
    ) external override onlyEntityOrOwner {
        uint256 thisAmbassadorIndex = ambassadorByAddress[_ambassador];
        require(
            isAmbassadorAt(_ambassador, msg.sender) || msg.sender == owner(),
            "Ambassador:: NOT_AMBASSADOR"
        );
        require(
            ambassadorCommunities[thisAmbassadorIndex].length() == 0 || _keepCommunities == true,
            "Ambassador:: HAS_COMMUNITIES"
        );

        uint256 entityIndex = ambassadorToEntity[thisAmbassadorIndex];
        uint256 entityToIndex = entityByAddress[_toEntity];

        ambassadorToEntity[thisAmbassadorIndex] = entityToIndex;
        entityAmbassadors[entityIndex]--;
        entityAmbassadors[entityToIndex]++;

        emit AmbassadorTransfered(_ambassador, entityByIndex[entityIndex], _toEntity);
    }

    /**
     * @notice Transfers community from ambassador to another ambassador.
     *
     * @param _to Address of the ambassador to transfer the community to
     * @param _community Community address
     */
    function transferCommunityToAmbassador(address _to, address _community)
        external
        override
        onlyEntityOrOwner
    {
        address _from = ambassadorByIndex[communityToAmbassador[_community]];

        require(isAmbassadorOf(_from, _community), "Ambassador:: NOT_AMBASSADOR");
        require(!isAmbassadorOf(_to, _community), "Ambassador:: ALREADY_AMBASSADOR");
        require(
            isAmbassadorAt(_from, msg.sender) || msg.sender == owner(),
            "Ambassador:: NOT_AMBASSADOR"
        );
        require(
            isAmbassadorAt(_to, msg.sender) || msg.sender == owner(),
            "Ambassador:: NOT_AMBASSADOR"
        );

        communityToAmbassador[_community] = ambassadorByAddress[_to];
        ambassadorCommunities[ambassadorByAddress[_from]].remove(_community);
        ambassadorCommunities[ambassadorByAddress[_to]].add(_community);

        emit AmbassadorToCommunityUpdated(_from, _to, _community);
    }

    /**
     * @notice Sets community to ambassador.
     *
     * @param _ambassador Address of the ambassador
     * @param _community Community address
     */
    function setCommunityToAmbassador(address _ambassador, address _community)
        external
        override
        onlyCommunityAdmin
    {
        require(isAmbassador(_ambassador), "Ambassador:: NOT_AMBASSADOR");
        require(!isAmbassadorOf(_ambassador, _community), "Ambassador:: ALREADY_AMBASSADOR");

        uint256 thisAmbassadorIndex = ambassadorByAddress[_ambassador];

        communityToAmbassador[_community] = thisAmbassadorIndex;
        ambassadorCommunities[thisAmbassadorIndex].add(_community);

        emit AmbassadorToCommunityUpdated(address(0), _ambassador, _community);
    }

    /**
     * @notice Removes community.
     *
     * @param _community Community address
     */
    function removeCommunity(address _community) external override onlyCommunityAdmin {
        address _ambassador = ambassadorByIndex[communityToAmbassador[_community]];

        require(isAmbassadorOf(_ambassador, _community), "Ambassador:: NOT_AMBASSADOR");

        uint256 thisAmbassadorIndex = ambassadorByAddress[_ambassador];

        communityToAmbassador[_community] = 0;
        ambassadorCommunities[thisAmbassadorIndex].remove(_community);

        emit CommunityRemoved(_ambassador, _community);
    }

    /**
     * @notice Internal function, common to account replacement.
     *
     * @param _old Address of the ambassador
     * @param _new New ambassador address
     */
    function _replaceAmbassadorAccountInternal(address _old, address _new)
        private
        returns (
            uint256,
            address,
            address,
            address
        )
    {
        uint256 thisAmbassadorIndex = ambassadorByAddress[_old];
        uint256 entityIndex = ambassadorToEntity[thisAmbassadorIndex];

        ambassadorByIndex[thisAmbassadorIndex] = _new;
        ambassadorByAddress[_new] = ambassadorByAddress[_old];
        ambassadorByAddress[_old] = 0;

        return (thisAmbassadorIndex, entityByIndex[entityIndex], _old, _new);
    }
}
        

/_openzeppelin/contracts/access/Ownable.sol

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

pragma solidity ^0.8.0;

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

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

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

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

    /**
     * @dev 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 {
        _transferOwnership(address(0));
    }

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

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

/_openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Proxy.sol)

pragma solidity ^0.8.0;

import "../Proxy.sol";
import "./ERC1967Upgrade.sol";

/**
 * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
 * implementation address that can be changed. This address is stored in storage in the location specified by
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
 * implementation behind the proxy.
 */
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
    /**
     * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
     *
     * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
     * function call, and allows initializating the storage of the proxy like a Solidity constructor.
     */
    constructor(address _logic, bytes memory _data) payable {
        assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
        _upgradeToAndCall(_logic, _data, false);
    }

    /**
     * @dev Returns the current implementation address.
     */
    function _implementation() internal view virtual override returns (address impl) {
        return ERC1967Upgrade._getImplementation();
    }
}
          

/_openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeacon.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 *
 * @custom:oz-upgrades-unsafe-allow delegatecall
 */
abstract contract ERC1967Upgrade {
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallSecure(
        address newImplementation,
        bytes memory data,
        bool forceCall
    ) internal {
        address oldImplementation = _getImplementation();

        // Initial upgrade and setup call
        _setImplementation(newImplementation);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(newImplementation, data);
        }

        // Perform rollback test if not already in progress
        StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
        if (!rollbackTesting.value) {
            // Trigger rollback using upgradeTo from the new implementation
            rollbackTesting.value = true;
            Address.functionDelegateCall(
                newImplementation,
                abi.encodeWithSignature("upgradeTo(address)", oldImplementation)
            );
            rollbackTesting.value = false;
            // Check rollback was effective
            require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
            // Finally reset to the new implementation and log the upgrade
            _upgradeTo(newImplementation);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Emitted when the beacon is upgraded.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            Address.isContract(IBeacon(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(
        address newBeacon,
        bytes memory data,
        bool forceCall
    ) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        }
    }
}
          

/_openzeppelin/contracts/proxy/Proxy.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/Proxy.sol)

pragma solidity ^0.8.0;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internall call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
     * and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internall call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _beforeFallback();
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
     * is empty.
     */
    receive() external payable virtual {
        _fallback();
    }

    /**
     * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
     * call, or as part of the Solidity `fallback` or `receive` functions.
     *
     * If overriden should call `super._beforeFallback()`.
     */
    function _beforeFallback() internal virtual {}
}
          

/_openzeppelin/contracts/proxy/beacon/IBeacon.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}
          

/_openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/transparent/ProxyAdmin.sol)

pragma solidity ^0.8.0;

import "./TransparentUpgradeableProxy.sol";
import "../../access/Ownable.sol";

/**
 * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
 * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
 */
contract ProxyAdmin is Ownable {
    /**
     * @dev Returns the current implementation of `proxy`.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
        // We need to manually run the static call since the getter cannot be flagged as view
        // bytes4(keccak256("implementation()")) == 0x5c60da1b
        (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
        require(success);
        return abi.decode(returndata, (address));
    }

    /**
     * @dev Returns the current admin of `proxy`.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
        // We need to manually run the static call since the getter cannot be flagged as view
        // bytes4(keccak256("admin()")) == 0xf851a440
        (bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440");
        require(success);
        return abi.decode(returndata, (address));
    }

    /**
     * @dev Changes the admin of `proxy` to `newAdmin`.
     *
     * Requirements:
     *
     * - This contract must be the current admin of `proxy`.
     */
    function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
        proxy.changeAdmin(newAdmin);
    }

    /**
     * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
        proxy.upgradeTo(implementation);
    }

    /**
     * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
     * {TransparentUpgradeableProxy-upgradeToAndCall}.
     *
     * Requirements:
     *
     * - This contract must be the admin of `proxy`.
     */
    function upgradeAndCall(
        TransparentUpgradeableProxy proxy,
        address implementation,
        bytes memory data
    ) public payable virtual onlyOwner {
        proxy.upgradeToAndCall{value: msg.value}(implementation, data);
    }
}
          

/_openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/transparent/TransparentUpgradeableProxy.sol)

pragma solidity ^0.8.0;

import "../ERC1967/ERC1967Proxy.sol";

/**
 * @dev This contract implements a proxy that is upgradeable by an admin.
 *
 * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
 * clashing], which can potentially be used in an attack, this contract uses the
 * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
 * things that go hand in hand:
 *
 * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
 * that call matches one of the admin functions exposed by the proxy itself.
 * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
 * implementation. If the admin tries to call a function on the implementation it will fail with an error that says
 * "admin cannot fallback to proxy target".
 *
 * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing
 * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due
 * to sudden errors when trying to call a function from the proxy implementation.
 *
 * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,
 * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.
 */
contract TransparentUpgradeableProxy is ERC1967Proxy {
    /**
     * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
     * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
     */
    constructor(
        address _logic,
        address admin_,
        bytes memory _data
    ) payable ERC1967Proxy(_logic, _data) {
        assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
        _changeAdmin(admin_);
    }

    /**
     * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
     */
    modifier ifAdmin() {
        if (msg.sender == _getAdmin()) {
            _;
        } else {
            _fallback();
        }
    }

    /**
     * @dev Returns the current admin.
     *
     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function admin() external ifAdmin returns (address admin_) {
        admin_ = _getAdmin();
    }

    /**
     * @dev Returns the current implementation.
     *
     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
     */
    function implementation() external ifAdmin returns (address implementation_) {
        implementation_ = _implementation();
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     *
     * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
     */
    function changeAdmin(address newAdmin) external virtual ifAdmin {
        _changeAdmin(newAdmin);
    }

    /**
     * @dev Upgrade the implementation of the proxy.
     *
     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
     */
    function upgradeTo(address newImplementation) external ifAdmin {
        _upgradeToAndCall(newImplementation, bytes(""), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
     * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
     * proxied contract.
     *
     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
     */
    function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
        _upgradeToAndCall(newImplementation, data, true);
    }

    /**
     * @dev Returns the current admin.
     */
    function _admin() internal view virtual returns (address) {
        return _getAdmin();
    }

    /**
     * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
     */
    function _beforeFallback() internal virtual override {
        require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
        super._beforeFallback();
    }
}
          

/_openzeppelin/contracts/token/ERC20/IERC20.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

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

/_openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

/_openzeppelin/contracts/utils/Address.sol

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

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts/utils/Context.sol

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

pragma solidity ^0.8.0;

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

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

/_openzeppelin/contracts/utils/StorageSlot.sol

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

pragma solidity ^0.8.0;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

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

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

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

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

/_openzeppelin/contracts/utils/structs/EnumerableSet.sol

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

pragma solidity ^0.8.0;

/**
 * @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.
 */
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) {
        return _values(set._inner);
    }

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

        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 on 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;

        assembly {
            result := store
        }

        return result;
    }
}
          

/_openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
          

/_openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

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

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_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 {
        _transferOwnership(address(0));
    }

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

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

/_openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

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

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.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 a proxied contract can't have 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.
 *
 * 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 initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

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

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

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

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}
          

/_openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol

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

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

/_openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

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

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
    uint256[50] private __gap;
}
          

/contracts/ambassadors/interfaces/AmbassadorsStorageV1.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./IAmbassadors.sol";
import "../../community/interfaces/ICommunityAdmin.sol";

/**
 * @title Storage for Ambassadors
 * @notice For future upgrades, do not change AmbassadorsStorageV1. Create a new
 * contract which implements AmbassadorsStorageV1 and following the naming convention
 * AmbassadorsStorageVX.
 */
abstract contract AmbassadorsStorageV1 is IAmbassadors {
    uint256 public ambassadorIndex;
    uint256 public entityIndex;

    ICommunityAdmin public communityAdmin;
    // address to index
    mapping(address => uint256) public ambassadorByAddress;
    // index to address
    mapping(uint256 => address) public ambassadorByIndex;
    // communities an ambassador is responsible for
    mapping(uint256 => EnumerableSet.AddressSet) internal ambassadorCommunities;
    // community address to ambassador index
    mapping(address => uint256) public communityToAmbassador;
    // ambassador belongs to entity
    mapping(uint256 => uint256) public ambassadorToEntity;
    // entity adding ambassadors
    mapping(address => uint256) public entityByAddress;
    // entity adding ambassadors
    mapping(uint256 => address) public entityByIndex;
    // number of ambassadors an entity is responsible for
    mapping(uint256 => uint256) public entityAmbassadors;
}
          

/contracts/ambassadors/interfaces/IAmbassadors.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

interface IAmbassadors {
    function getVersion() external returns(uint256);
    function isAmbassador(address _ambassador) external view returns (bool);
    function isAmbassadorOf(address _ambassador, address _community) external view returns (bool);
    function isEntityOf(address _ambassador, address _entityAddress) external view returns (bool);
    function isAmbassadorAt(address _ambassador, address _entityAddress) external view returns (bool);

    function addEntity(address _entity) external;
    function removeEntity(address _entity) external;
    function replaceEntityAccount(address _entity, address _newEntity) external;
    function addAmbassador(address _ambassador) external;
    function removeAmbassador(address _ambassador) external;
    function replaceAmbassadorAccount(address _ambassador, address _newAmbassador) external;
    function replaceAmbassador(address _oldAmbassador, address _newAmbassador) external;
    function transferAmbassador(address _ambassador, address _toEntity, bool _keepCommunities) external;
    function transferCommunityToAmbassador(address _to, address _community) external;
    function setCommunityToAmbassador(address _ambassador, address _community) external;
    function removeCommunity(address _community) external;
}
          

/contracts/community/interfaces/ICommunity.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./ICommunityAdmin.sol";

interface ICommunity {
    enum BeneficiaryState {
        NONE, //the beneficiary hasn't been added yet
        Valid,
        Locked,
        Removed
    }

    struct Beneficiary {
        BeneficiaryState state;  //beneficiary state
        uint256 claims;          //total number of claims
        uint256 claimedAmount;   //total amount of cUSD received
        uint256 lastClaim;       //block number of the last claim
    }

    function initialize(
        address[] memory _managers,
        uint256 _claimAmount,
        uint256 _maxClaim,
        uint256 _decreaseStep,
        uint256 _baseInterval,
        uint256 _incrementInterval,
        uint256 _minTranche,
        uint256 _maxTranche,
        uint256 _maxBeneficiaries,
        ICommunity _previousCommunity
    ) external;
    function getVersion() external returns(uint256);
    function previousCommunity() external view returns(ICommunity);
    function claimAmount() external view returns(uint256);
    function baseInterval() external view returns(uint256);
    function incrementInterval() external view returns(uint256);
    function maxClaim() external view returns(uint256);
    function validBeneficiaryCount() external view returns(uint);
    function maxBeneficiaries() external view returns(uint);
    function treasuryFunds() external view returns(uint);
    function privateFunds() external view returns(uint);
    function communityAdmin() external view returns(ICommunityAdmin);
    function cUSD() external view  returns(IERC20);
    function token() external view  returns(IERC20);
    function locked() external view returns(bool);
    function beneficiaries(address _beneficiaryAddress) external view returns(
        BeneficiaryState state,
        uint256 claims,
        uint256 claimedAmount,
        uint256 lastClaim
    );
    function decreaseStep() external view returns(uint);
    function beneficiaryListAt(uint256 _index) external view returns (address);
    function beneficiaryListLength() external view returns (uint256);
    function impactMarketAddress() external pure returns (address);
    function minTranche() external view returns(uint256);
    function maxTranche() external view returns(uint256);
    function lastFundRequest() external view returns(uint256);

    function updateCommunityAdmin(ICommunityAdmin _communityAdmin) external;
    function updatePreviousCommunity(ICommunity _newPreviousCommunity) external;
    function updateBeneficiaryParams(
        uint256 _claimAmount,
        uint256 _maxClaim,
        uint256 _decreaseStep,
        uint256 _baseInterval,
        uint256 _incrementInterval
    ) external;
    function updateCommunityParams(
        uint256 _minTranche,
        uint256 _maxTranche
    ) external;
    function updateMaxBeneficiaries(uint256 _newMaxBeneficiaries) external;
    function updateToken(IERC20 _newToken, address[] memory _exchangePath) external;
    function donate(address _sender, uint256 _amount) external;
    function addTreasuryFunds(uint256 _amount) external;
    function transfer(IERC20 _token, address _to, uint256 _amount) external;
    function addManager(address _managerAddress) external;
    function removeManager(address _managerAddress) external;
    function addBeneficiaries(address[] memory _beneficiaryAddresses) external;
    function lockBeneficiary(address _beneficiaryAddress) external;
    function unlockBeneficiary(address _beneficiaryAddress) external;
    function removeBeneficiary(address _beneficiaryAddress) external;
    function claim() external;
    function lastInterval(address _beneficiaryAddress) external view returns (uint256);
    function claimCooldown(address _beneficiaryAddress) external view returns (uint256);
    function lock() external;
    function unlock() external;
    function requestFunds() external;
    function beneficiaryJoinFromMigrated(address _beneficiaryAddress) external;
    function getInitialMaxClaim() external view returns (uint256);
}
          

/contracts/community/interfaces/ICommunityAdmin.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./ICommunity.sol";
import "../../treasury/interfaces/ITreasury.sol";
import "../../governor/impactMarketCouncil/interfaces/IImpactMarketCouncil.sol";
import "../../ambassadors/interfaces/IAmbassadors.sol";

interface ICommunityAdmin {
    enum CommunityState {
        NONE,
        Valid,
        Removed,
        Migrated
    }

    function getVersion() external returns(uint256);
    function cUSD() external view returns(IERC20);
    function treasury() external view returns(ITreasury);
    function impactMarketCouncil() external view returns(IImpactMarketCouncil);
    function ambassadors() external view returns(IAmbassadors);
    function communityMiddleProxy() external view returns(address);
    function communities(address _community) external view returns(CommunityState);
    function communityImplementation() external view returns(ICommunity);
    function communityProxyAdmin() external view returns(ProxyAdmin);
    function communityListAt(uint256 _index) external view returns (address);
    function communityListLength() external view returns (uint256);
    function isAmbassadorOrEntityOfCommunity(address _community, address _ambassadorOrEntity) external view returns (bool);
    function updateTreasury(ITreasury _newTreasury) external;
    function updateImpactMarketCouncil(IImpactMarketCouncil _newImpactMarketCouncil) external;
    function updateAmbassadors(IAmbassadors _newAmbassadors) external;
    function updateCommunityMiddleProxy(address _communityMiddleProxy) external;
    function updateCommunityImplementation(ICommunity _communityImplementation_) external;
    function updateBeneficiaryParams(
        ICommunity _community,
        uint256 _claimAmount,
        uint256 _maxClaim,
        uint256 _decreaseStep,
        uint256 _baseInterval,
        uint256 _incrementInterval,
        uint256 _maxBeneficiaries
    ) external;
    function updateCommunityParams(
        ICommunity _community,
        uint256 _minTranche,
        uint256 _maxTranche
    ) external;
    function updateProxyImplementation(address _CommunityMiddleProxy, address _newLogic) external;
    function updateCommunityToken(
        ICommunity _community,
        IERC20 _newToken,
        address[] memory _exchangePath
    ) external;
    function addCommunity(
        address[] memory _managers,
        address _ambassador,
        uint256 _claimAmount,
        uint256 _maxClaim,
        uint256 _decreaseStep,
        uint256 _baseInterval,
        uint256 _incrementInterval,
        uint256 _minTranche,
        uint256 _maxTranche,
        uint256 _maxBeneficiaries
    ) external;
    function migrateCommunity(
        address[] memory _managers,
        ICommunity _previousCommunity
    ) external;
    function removeCommunity(ICommunity _community) external;
    function fundCommunity() external;
    function transfer(IERC20 _token, address _to, uint256 _amount) external;
    function transferFromCommunity(
        ICommunity _community,
        IERC20 _token,
        address _to,
        uint256 _amount
    ) external;
}
          

/contracts/governor/impactMarketCouncil/interfaces/IImpactMarketCouncil.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IImpactMarketCouncil {
    //
}
          

/contracts/treasury/interfaces/ITreasury.sol

//SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../community/interfaces/ICommunityAdmin.sol";
import "./IUniswapV2Router.sol";

interface ITreasury {
    struct Token {
        uint256 rate;
        address[] exchangePath;
    }

    function getVersion() external returns(uint256);
    function communityAdmin() external view returns(ICommunityAdmin);
    function uniswapRouter() external view returns(IUniswapV2Router);
    function updateCommunityAdmin(ICommunityAdmin _communityAdmin) external;
    function updateUniswapRouter(IUniswapV2Router _uniswapRouter) external;
    function transfer(IERC20 _token, address _to, uint256 _amount) external;
    function isToken(address _tokenAddress) external view returns (bool);
    function tokenListLength() external view returns (uint256);
    function tokenListAt(uint256 _index) external view returns (address);
    function tokens(address _tokenAddress) external view returns (uint256 rate, address[] memory exchangePath);
    function setToken(address _tokenAddress, uint256 _rate, address[] calldata _exchangePath) external;
    function removeToken(address _tokenAddress) external;
    function getConvertedAmount(address _tokenAddress, uint256 _amount) external view returns (uint256);
    function convertAmount(
        address _tokenAddress,
        uint256 _amountIn,
        uint256 _amountOutMin,
        address[] memory _exchangePath,
        uint256 _deadline
    ) external;
}
          

/contracts/treasury/interfaces/IUniswapV2Router.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.4;

interface IUniswapV2Router {
    function factory() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);

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

    function pairFor(address tokenA, address tokenB) external view returns (address);
}
          

Contract ABI

[{"type":"event","name":"AmbassadorAccountReplaced","inputs":[{"type":"uint256","name":"ambassadorIndex","internalType":"uint256","indexed":false},{"type":"address","name":"entityAccount","internalType":"address","indexed":true},{"type":"address","name":"oldAccount","internalType":"address","indexed":true},{"type":"address","name":"newAccount","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AmbassadorAdded","inputs":[{"type":"address","name":"ambassador","internalType":"address","indexed":true},{"type":"address","name":"entity","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AmbassadorRemoved","inputs":[{"type":"address","name":"ambassador","internalType":"address","indexed":true},{"type":"address","name":"entity","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AmbassadorReplaced","inputs":[{"type":"uint256","name":"ambassadorIndex","internalType":"uint256","indexed":false},{"type":"address","name":"entityAccount","internalType":"address","indexed":true},{"type":"address","name":"oldAmbassador","internalType":"address","indexed":true},{"type":"address","name":"newAmbassador","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AmbassadorToCommunityUpdated","inputs":[{"type":"address","name":"fromAmbassador","internalType":"address","indexed":true},{"type":"address","name":"toAmbassador","internalType":"address","indexed":true},{"type":"address","name":"community","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"AmbassadorTransfered","inputs":[{"type":"address","name":"ambassador","internalType":"address","indexed":true},{"type":"address","name":"oldEntity","internalType":"address","indexed":true},{"type":"address","name":"newEntity","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"CommunityRemoved","inputs":[{"type":"address","name":"ambassador","internalType":"address","indexed":true},{"type":"address","name":"community","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"EntityAccountReplaced","inputs":[{"type":"uint256","name":"entityIndex","internalType":"uint256","indexed":false},{"type":"address","name":"oldAccount","internalType":"address","indexed":true},{"type":"address","name":"newAccount","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"EntityAdded","inputs":[{"type":"address","name":"entity","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"EntityRemoved","inputs":[{"type":"address","name":"entity","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addAmbassador","inputs":[{"type":"address","name":"_ambassador","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addEntity","inputs":[{"type":"address","name":"_entity","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"ambassadorByAddress","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"ambassadorByIndex","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"ambassadorIndex","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"ambassadorToEntity","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ICommunityAdmin"}],"name":"communityAdmin","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"communityToAmbassador","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"entityAmbassadors","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"entityByAddress","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"entityByIndex","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"entityIndex","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getVersion","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"_communityAdmin","internalType":"contract ICommunityAdmin"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isAmbassador","inputs":[{"type":"address","name":"_ambassador","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isAmbassadorAt","inputs":[{"type":"address","name":"_ambassador","internalType":"address"},{"type":"address","name":"_entityAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isAmbassadorOf","inputs":[{"type":"address","name":"_ambassador","internalType":"address"},{"type":"address","name":"_community","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isEntityOf","inputs":[{"type":"address","name":"_entity","internalType":"address"},{"type":"address","name":"_community","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAmbassador","inputs":[{"type":"address","name":"_ambassador","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeCommunity","inputs":[{"type":"address","name":"_community","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeEntity","inputs":[{"type":"address","name":"_entity","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"replaceAmbassador","inputs":[{"type":"address","name":"_oldAmbassador","internalType":"address"},{"type":"address","name":"_newAmbassador","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"replaceAmbassadorAccount","inputs":[{"type":"address","name":"_ambassador","internalType":"address"},{"type":"address","name":"_newAmbassador","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"replaceEntityAccount","inputs":[{"type":"address","name":"_entity","internalType":"address"},{"type":"address","name":"_newEntity","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCommunityToAmbassador","inputs":[{"type":"address","name":"_ambassador","internalType":"address"},{"type":"address","name":"_community","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferAmbassador","inputs":[{"type":"address","name":"_ambassador","internalType":"address"},{"type":"address","name":"_toEntity","internalType":"address"},{"type":"bool","name":"_keepCommunities","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferCommunityToAmbassador","inputs":[{"type":"address","name":"_to","internalType":"address"},{"type":"address","name":"_community","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateCommunityAdmin","inputs":[{"type":"address","name":"_newCommunityAdmin","internalType":"contract ICommunityAdmin"}]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50611b93806100206000396000f3fe608060405234801561001057600080fd5b50600436106101e55760003560e01c80639ac0c6ac1161010f578063cb53f503116100a2578063df3441a811610071578063df3441a814610493578063e8729646146104b3578063f1703d24146104bc578063f2fde38b146104cf57600080fd5b8063cb53f50314610415578063d33d4ec61461045a578063dd1829961461046d578063de96587e1461048057600080fd5b8063c273f1f1116100de578063c273f1f1146103a2578063c4d66de8146103c2578063c80acb3c146103d5578063cacc3088146103f557600080fd5b80639ac0c6ac146103405780639f9abc1414610353578063b08d66b814610366578063bb26e9b61461037957600080fd5b806330a14f9511610187578063715018a611610156578063715018a6146103015780638da5cb5b14610309578063926345401461031a57806397710ab11461032d57600080fd5b806330a14f95146102a55780633ddfee0c146102b857806342e1d997146102cb5780635fac917a146102ee57600080fd5b80632426de98116101c35780632426de981461021e578063295c25d51461023e5780632af82058146102515780632de00ddc1461029257600080fd5b80630d8e6e2c146101ea578063169e7d56146102005780631df7b3cd14610215575b600080fd5b60015b6040519081526020015b60405180910390f35b61021361020e3660046118db565b6104e2565b005b6101ed60975481565b6101ed61022c3660046118bf565b609d6020526000908152604090205481565b61021361024c3660046118bf565b610603565b61027a61025f366004611961565b60a0602052600090815260409020546001600160a01b031681565b6040516001600160a01b0390911681526020016101f7565b6102136102a03660046118db565b610741565b6102136102b3366004611913565b610838565b6102136102c63660046118db565b610a0b565b6102de6102d93660046118db565b610b4d565b60405190151581526020016101f7565b60995461027a906001600160a01b031681565b610213610b89565b6033546001600160a01b031661027a565b6102136103283660046118bf565b610bbf565b61021361033b3660046118db565b610cbd565b6102de61034e3660046118bf565b610d7b565b6102136103613660046118db565b610d98565b6102de6103743660046118db565b610f9c565b61027a610387366004611961565b609b602052600090815260409020546001600160a01b031681565b6101ed6103b03660046118bf565b609f6020526000908152604090205481565b6102136103d03660046118bf565b610fc9565b6101ed6103e3366004611961565b609e6020526000908152604090205481565b6101ed610403366004611961565b60a16020526000908152604090205481565b6102de6104233660046118db565b6001600160a01b039081166000908152609d60209081526040808320548352609e825280832054949093168252609f905220541490565b6102136104683660046118bf565b6110b8565b61021361047b3660046118bf565b611104565b61021361048e3660046118bf565b61124b565b6101ed6104a13660046118bf565b609a6020526000908152604090205481565b6101ed60985481565b6102136104ca3660046118bf565b6113bd565b6102136104dd3660046118bf565b6114d3565b336001600160a01b038316148061050357506033546001600160a01b031633145b61054f5760405162461bcd60e51b8152602060048201526018602482015277105b58985cdcd8591bdc8e8e881393d517d0531313d5d15160421b60448201526064015b60405180910390fd5b61055882610d7b565b6105745760405162461bcd60e51b8152600401610546906119ef565b61057d81610d7b565b1561059a5760405162461bcd60e51b815260040161054690611a67565b6000806000806105aa868661156e565b604051848152939750919550935091506001600160a01b0380831691818516918616907fb0433a1c3702cf0bd7986f8f52d4b155e390f3f600a3677f19d9953305466d7b906020015b60405180910390a4505050505050565b336000908152609f602052604090205461065a5760405162461bcd60e51b8152602060048201526018602482015277416d6261737361646f723a3a204f4e4c595f454e5449545960401b6044820152606401610546565b61066381610d7b565b156106805760405162461bcd60e51b815260040161054690611a67565b336000908152609f6020908152604080832054609780546001600160a01b038716808752609a8652848720829055908652609b855283862080546001600160a01b0319169091179055548452609e835281842081905580845260a19092528220805491926106ed83611b17565b90915550506097805490600061070283611b17565b909155505060405133906001600160a01b038416907f7974b0235ffa33752026d77f968bed3382bcd8ce49170bbb32d3fb7494d2275e90600090a35050565b6099546001600160a01b0316331461076b5760405162461bcd60e51b815260040161054690611979565b61077482610d7b565b6107905760405162461bcd60e51b8152600401610546906119ef565b61079a8282610f9c565b156107b75760405162461bcd60e51b815260040161054690611a67565b6001600160a01b038083166000908152609a60209081526040808320549385168352609d8252808320849055838352609c90915290206107f790836115db565b506040516001600160a01b0380841691908516906000907f8e197c1b94ad42b061a1947f91c7bff6387f001a7a5a0ddee8610893706de8af908290a4505050565b336000908152609f602052604090205415158061086e5750336108636033546001600160a01b031690565b6001600160a01b0316145b61088a5760405162461bcd60e51b815260040161054690611a26565b6001600160a01b0383166000908152609a60205260409020546108ad8433610b4d565b806108c257506033546001600160a01b031633145b6108de5760405162461bcd60e51b8152600401610546906119ef565b6000818152609c602052604090206108f5906115f7565b158061090357506001821515145b61094f5760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f434f4d4d554e4954494553000000006044820152606401610546565b6000818152609e6020908152604080832080546001600160a01b0388168552609f8452828520549182905580855260a19093529083208054929391929161099583611b00565b9091555050600081815260a1602052604081208054916109b483611b17565b9091555050600082815260a060205260408082205490516001600160a01b038089169392811692908a16917ffcc524962ae2655aeb5b6c7ad6cb8e8fc45c9f14edf517beb2b48595a3cd90489190a4505050505050565b6001600160a01b0382166000818152609f602052604090205490331480610a3c57506033546001600160a01b031633145b610a835760405162461bcd60e51b8152602060048201526018602482015277105b58985cdcd8591bdc8e8e881393d517d0531313d5d15160421b6044820152606401610546565b80610aca5760405162461bcd60e51b8152602060048201526017602482015276416d6261737361646f723a3a204e4f545f454e5449545960481b6044820152606401610546565b600081815260a06020908152604080832080546001600160a01b0319166001600160a01b03878116918217909255908716808552609f84528285208054838752848720558186529490945590518481529092917f1cef456569215c66a24eca2e9e631350d3daf1f358738ba7a3df455fcdc243a4910160405180910390a3505050565b6001600160a01b038082166000908152609f60209081526040808320549386168352609a8252808320548352609e909152902054145b92915050565b6033546001600160a01b03163314610bb35760405162461bcd60e51b8152600401610546906119ba565b610bbd6000611601565b565b6099546001600160a01b03163314610be95760405162461bcd60e51b815260040161054690611979565b6001600160a01b038082166000908152609d60209081526040808320548352609b90915290205416610c1b8183610f9c565b610c375760405162461bcd60e51b8152600401610546906119ef565b6001600160a01b038082166000908152609a60209081526040808320549386168352609d8252808320839055838352609c9091529020610c779084611653565b50826001600160a01b0316826001600160a01b03167fbac68789a3f4e375a8fa2492f0930108bbb4d9e2646f37abc5ef2a94ddce06ba60405160405180910390a3505050565b610cc78233610b4d565b80610cdc57506033546001600160a01b031633145b610cf85760405162461bcd60e51b8152600401610546906119ef565b610d0181610d7b565b15610d1e5760405162461bcd60e51b815260040161054690611a67565b600080600080610d2e868661156e565b604051848152939750919550935091506001600160a01b0380831691818516918616907f9998ffadb0cd2ca491daebaaecf860ac02dd25cd317ec9ef08b5c2a0a6a5677f906020016105f3565b6001600160a01b03166000908152609a6020526040902054151590565b336000908152609f6020526040902054151580610dce575033610dc36033546001600160a01b031690565b6001600160a01b0316145b610dea5760405162461bcd60e51b815260040161054690611a26565b6001600160a01b038082166000908152609d60209081526040808320548352609b90915290205416610e1c8183610f9c565b610e385760405162461bcd60e51b8152600401610546906119ef565b610e428383610f9c565b15610e5f5760405162461bcd60e51b815260040161054690611a67565b610e698133610b4d565b80610e7e57506033546001600160a01b031633145b610e9a5760405162461bcd60e51b8152600401610546906119ef565b610ea48333610b4d565b80610eb957506033546001600160a01b031633145b610ed55760405162461bcd60e51b8152600401610546906119ef565b6001600160a01b038084166000908152609a60208181526040808420548786168552609d8352818520559385168352908152828220548252609c905220610f1c9083611653565b506001600160a01b0383166000908152609a60209081526040808320548352609c9091529020610f4c90836115db565b50816001600160a01b0316836001600160a01b0316826001600160a01b03167f8e197c1b94ad42b061a1947f91c7bff6387f001a7a5a0ddee8610893706de8af60405160405180910390a4505050565b6001600160a01b039081166000908152609d6020908152604080832054949093168252609a905220541490565b600054610100900460ff16610fe45760005460ff1615610fe8565b303b155b61104b5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610546565b600054610100900460ff1615801561106d576000805461ffff19166101011790555b611075611668565b61107d61169f565b60016097819055609855609980546001600160a01b0319166001600160a01b03841617905580156110b4576000805461ff00191690555b5050565b6033546001600160a01b031633146110e25760405162461bcd60e51b8152600401610546906119ba565b609980546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b0316331461112e5760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166000908152609f60205260409020548061118e5760405162461bcd60e51b8152602060048201526017602482015276416d6261737361646f723a3a204e4f545f454e5449545960481b6044820152606401610546565b600081815260a16020526040902054156111ea5760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f414d4241535341444f5253000000006044820152606401610546565b600081815260a06020908152604080832080546001600160a01b03191690556001600160a01b038516808452609f9092528083208390555190917f66baa8598dad476a7a23c2c39a3c9ea353a313b8050f5f2ff7df3121abe1f98391a25050565b336000908152609f60205260409020546112a25760405162461bcd60e51b8152602060048201526018602482015277416d6261737361646f723a3a204f4e4c595f454e5449545960401b6044820152606401610546565b6001600160a01b0381166000908152609a602090815260408083205433808552609f909352922054906112d6908490610b4d565b6112f25760405162461bcd60e51b8152600401610546906119ef565b6000828152609c60205260409020611309906115f7565b156113565760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f434f4d4d554e4954494553000000006044820152606401610546565b600081815260a16020526040812080549161137083611b00565b90915550506001600160a01b0383166000818152609a6020526040808220829055513392917fdf0a456c1486c80ba4cdebb55052f692736d848b7cd52f7586d824a51018483791a3505050565b6033546001600160a01b031633146113e75760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166000908152609f60205260409020541561144d5760405162461bcd60e51b815260206004820152601b60248201527f416d6261737361646f723a3a20414c52454144595f454e5449545900000000006044820152606401610546565b609880546001600160a01b0383166000818152609f6020908152604080832085905593825260a0905291822080546001600160a01b03191690911790558154919061149783611b17565b90915550506040516001600160a01b038216907fb22e19f08ff14b8507fef310677b98ad1329eba6abb5b90f147acd6475dc762b90600090a250565b6033546001600160a01b031633146114fd5760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166115625760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610546565b61156b81611601565b50565b6001600160a01b038281166000908152609a602081815260408084208054808652609e845282862054609b855283872080546001600160a01b0319168a8a169081179091559585528254958752838720959095559085905592845260a09091529091205490949116929190565b60006115f0836001600160a01b0384166116ce565b9392505050565b6000610b83825490565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006115f0836001600160a01b03841661171d565b600054610100900460ff1661168f5760405162461bcd60e51b815260040161054690611a9e565b61169761183a565b610bbd611861565b600054610100900460ff166116c65760405162461bcd60e51b815260040161054690611a9e565b610bbd611891565b600081815260018301602052604081205461171557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b83565b506000610b83565b60008181526001830160205260408120548015611830576000611741600183611ae9565b855490915060009061175590600190611ae9565b90508181146117d657600086600001828154811061178357634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050808760000184815481106117b457634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600188019052604090208390555b85548690806117f557634e487b7160e01b600052603160045260246000fd5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610b83565b6000915050610b83565b600054610100900460ff16610bbd5760405162461bcd60e51b815260040161054690611a9e565b600054610100900460ff166118885760405162461bcd60e51b815260040161054690611a9e565b610bbd33611601565b600054610100900460ff166118b85760405162461bcd60e51b815260040161054690611a9e565b6001606555565b6000602082840312156118d0578081fd5b81356115f081611b48565b600080604083850312156118ed578081fd5b82356118f881611b48565b9150602083013561190881611b48565b809150509250929050565b600080600060608486031215611927578081fd5b833561193281611b48565b9250602084013561194281611b48565b915060408401358015158114611956578182fd5b809150509250925092565b600060208284031215611972578081fd5b5035919050565b60208082526021908201527f416d6261737361646f723a3a204f4e4c595f434f4d4d554e4954595f41444d496040820152602760f91b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601b908201527f416d6261737361646f723a3a204e4f545f414d4241535341444f520000000000604082015260600190565b60208082526021908201527f416d6261737361646f723a3a204f4e4c595f454e544954595f4f525f4f574e456040820152602960f91b606082015260800190565b6020808252601f908201527f416d6261737361646f723a3a20414c52454144595f414d4241535341444f5200604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082821015611afb57611afb611b32565b500390565b600081611b0f57611b0f611b32565b506000190190565b6000600019821415611b2b57611b2b611b32565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b038116811461156b57600080fdfea2646970667358221220e6c49ec861826effc4abf9da6511a8dfc133a4e42f175b97be76cd56d20595db64736f6c63430008040033

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106101e55760003560e01c80639ac0c6ac1161010f578063cb53f503116100a2578063df3441a811610071578063df3441a814610493578063e8729646146104b3578063f1703d24146104bc578063f2fde38b146104cf57600080fd5b8063cb53f50314610415578063d33d4ec61461045a578063dd1829961461046d578063de96587e1461048057600080fd5b8063c273f1f1116100de578063c273f1f1146103a2578063c4d66de8146103c2578063c80acb3c146103d5578063cacc3088146103f557600080fd5b80639ac0c6ac146103405780639f9abc1414610353578063b08d66b814610366578063bb26e9b61461037957600080fd5b806330a14f9511610187578063715018a611610156578063715018a6146103015780638da5cb5b14610309578063926345401461031a57806397710ab11461032d57600080fd5b806330a14f95146102a55780633ddfee0c146102b857806342e1d997146102cb5780635fac917a146102ee57600080fd5b80632426de98116101c35780632426de981461021e578063295c25d51461023e5780632af82058146102515780632de00ddc1461029257600080fd5b80630d8e6e2c146101ea578063169e7d56146102005780631df7b3cd14610215575b600080fd5b60015b6040519081526020015b60405180910390f35b61021361020e3660046118db565b6104e2565b005b6101ed60975481565b6101ed61022c3660046118bf565b609d6020526000908152604090205481565b61021361024c3660046118bf565b610603565b61027a61025f366004611961565b60a0602052600090815260409020546001600160a01b031681565b6040516001600160a01b0390911681526020016101f7565b6102136102a03660046118db565b610741565b6102136102b3366004611913565b610838565b6102136102c63660046118db565b610a0b565b6102de6102d93660046118db565b610b4d565b60405190151581526020016101f7565b60995461027a906001600160a01b031681565b610213610b89565b6033546001600160a01b031661027a565b6102136103283660046118bf565b610bbf565b61021361033b3660046118db565b610cbd565b6102de61034e3660046118bf565b610d7b565b6102136103613660046118db565b610d98565b6102de6103743660046118db565b610f9c565b61027a610387366004611961565b609b602052600090815260409020546001600160a01b031681565b6101ed6103b03660046118bf565b609f6020526000908152604090205481565b6102136103d03660046118bf565b610fc9565b6101ed6103e3366004611961565b609e6020526000908152604090205481565b6101ed610403366004611961565b60a16020526000908152604090205481565b6102de6104233660046118db565b6001600160a01b039081166000908152609d60209081526040808320548352609e825280832054949093168252609f905220541490565b6102136104683660046118bf565b6110b8565b61021361047b3660046118bf565b611104565b61021361048e3660046118bf565b61124b565b6101ed6104a13660046118bf565b609a6020526000908152604090205481565b6101ed60985481565b6102136104ca3660046118bf565b6113bd565b6102136104dd3660046118bf565b6114d3565b336001600160a01b038316148061050357506033546001600160a01b031633145b61054f5760405162461bcd60e51b8152602060048201526018602482015277105b58985cdcd8591bdc8e8e881393d517d0531313d5d15160421b60448201526064015b60405180910390fd5b61055882610d7b565b6105745760405162461bcd60e51b8152600401610546906119ef565b61057d81610d7b565b1561059a5760405162461bcd60e51b815260040161054690611a67565b6000806000806105aa868661156e565b604051848152939750919550935091506001600160a01b0380831691818516918616907fb0433a1c3702cf0bd7986f8f52d4b155e390f3f600a3677f19d9953305466d7b906020015b60405180910390a4505050505050565b336000908152609f602052604090205461065a5760405162461bcd60e51b8152602060048201526018602482015277416d6261737361646f723a3a204f4e4c595f454e5449545960401b6044820152606401610546565b61066381610d7b565b156106805760405162461bcd60e51b815260040161054690611a67565b336000908152609f6020908152604080832054609780546001600160a01b038716808752609a8652848720829055908652609b855283862080546001600160a01b0319169091179055548452609e835281842081905580845260a19092528220805491926106ed83611b17565b90915550506097805490600061070283611b17565b909155505060405133906001600160a01b038416907f7974b0235ffa33752026d77f968bed3382bcd8ce49170bbb32d3fb7494d2275e90600090a35050565b6099546001600160a01b0316331461076b5760405162461bcd60e51b815260040161054690611979565b61077482610d7b565b6107905760405162461bcd60e51b8152600401610546906119ef565b61079a8282610f9c565b156107b75760405162461bcd60e51b815260040161054690611a67565b6001600160a01b038083166000908152609a60209081526040808320549385168352609d8252808320849055838352609c90915290206107f790836115db565b506040516001600160a01b0380841691908516906000907f8e197c1b94ad42b061a1947f91c7bff6387f001a7a5a0ddee8610893706de8af908290a4505050565b336000908152609f602052604090205415158061086e5750336108636033546001600160a01b031690565b6001600160a01b0316145b61088a5760405162461bcd60e51b815260040161054690611a26565b6001600160a01b0383166000908152609a60205260409020546108ad8433610b4d565b806108c257506033546001600160a01b031633145b6108de5760405162461bcd60e51b8152600401610546906119ef565b6000818152609c602052604090206108f5906115f7565b158061090357506001821515145b61094f5760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f434f4d4d554e4954494553000000006044820152606401610546565b6000818152609e6020908152604080832080546001600160a01b0388168552609f8452828520549182905580855260a19093529083208054929391929161099583611b00565b9091555050600081815260a1602052604081208054916109b483611b17565b9091555050600082815260a060205260408082205490516001600160a01b038089169392811692908a16917ffcc524962ae2655aeb5b6c7ad6cb8e8fc45c9f14edf517beb2b48595a3cd90489190a4505050505050565b6001600160a01b0382166000818152609f602052604090205490331480610a3c57506033546001600160a01b031633145b610a835760405162461bcd60e51b8152602060048201526018602482015277105b58985cdcd8591bdc8e8e881393d517d0531313d5d15160421b6044820152606401610546565b80610aca5760405162461bcd60e51b8152602060048201526017602482015276416d6261737361646f723a3a204e4f545f454e5449545960481b6044820152606401610546565b600081815260a06020908152604080832080546001600160a01b0319166001600160a01b03878116918217909255908716808552609f84528285208054838752848720558186529490945590518481529092917f1cef456569215c66a24eca2e9e631350d3daf1f358738ba7a3df455fcdc243a4910160405180910390a3505050565b6001600160a01b038082166000908152609f60209081526040808320549386168352609a8252808320548352609e909152902054145b92915050565b6033546001600160a01b03163314610bb35760405162461bcd60e51b8152600401610546906119ba565b610bbd6000611601565b565b6099546001600160a01b03163314610be95760405162461bcd60e51b815260040161054690611979565b6001600160a01b038082166000908152609d60209081526040808320548352609b90915290205416610c1b8183610f9c565b610c375760405162461bcd60e51b8152600401610546906119ef565b6001600160a01b038082166000908152609a60209081526040808320549386168352609d8252808320839055838352609c9091529020610c779084611653565b50826001600160a01b0316826001600160a01b03167fbac68789a3f4e375a8fa2492f0930108bbb4d9e2646f37abc5ef2a94ddce06ba60405160405180910390a3505050565b610cc78233610b4d565b80610cdc57506033546001600160a01b031633145b610cf85760405162461bcd60e51b8152600401610546906119ef565b610d0181610d7b565b15610d1e5760405162461bcd60e51b815260040161054690611a67565b600080600080610d2e868661156e565b604051848152939750919550935091506001600160a01b0380831691818516918616907f9998ffadb0cd2ca491daebaaecf860ac02dd25cd317ec9ef08b5c2a0a6a5677f906020016105f3565b6001600160a01b03166000908152609a6020526040902054151590565b336000908152609f6020526040902054151580610dce575033610dc36033546001600160a01b031690565b6001600160a01b0316145b610dea5760405162461bcd60e51b815260040161054690611a26565b6001600160a01b038082166000908152609d60209081526040808320548352609b90915290205416610e1c8183610f9c565b610e385760405162461bcd60e51b8152600401610546906119ef565b610e428383610f9c565b15610e5f5760405162461bcd60e51b815260040161054690611a67565b610e698133610b4d565b80610e7e57506033546001600160a01b031633145b610e9a5760405162461bcd60e51b8152600401610546906119ef565b610ea48333610b4d565b80610eb957506033546001600160a01b031633145b610ed55760405162461bcd60e51b8152600401610546906119ef565b6001600160a01b038084166000908152609a60208181526040808420548786168552609d8352818520559385168352908152828220548252609c905220610f1c9083611653565b506001600160a01b0383166000908152609a60209081526040808320548352609c9091529020610f4c90836115db565b50816001600160a01b0316836001600160a01b0316826001600160a01b03167f8e197c1b94ad42b061a1947f91c7bff6387f001a7a5a0ddee8610893706de8af60405160405180910390a4505050565b6001600160a01b039081166000908152609d6020908152604080832054949093168252609a905220541490565b600054610100900460ff16610fe45760005460ff1615610fe8565b303b155b61104b5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610546565b600054610100900460ff1615801561106d576000805461ffff19166101011790555b611075611668565b61107d61169f565b60016097819055609855609980546001600160a01b0319166001600160a01b03841617905580156110b4576000805461ff00191690555b5050565b6033546001600160a01b031633146110e25760405162461bcd60e51b8152600401610546906119ba565b609980546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b0316331461112e5760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166000908152609f60205260409020548061118e5760405162461bcd60e51b8152602060048201526017602482015276416d6261737361646f723a3a204e4f545f454e5449545960481b6044820152606401610546565b600081815260a16020526040902054156111ea5760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f414d4241535341444f5253000000006044820152606401610546565b600081815260a06020908152604080832080546001600160a01b03191690556001600160a01b038516808452609f9092528083208390555190917f66baa8598dad476a7a23c2c39a3c9ea353a313b8050f5f2ff7df3121abe1f98391a25050565b336000908152609f60205260409020546112a25760405162461bcd60e51b8152602060048201526018602482015277416d6261737361646f723a3a204f4e4c595f454e5449545960401b6044820152606401610546565b6001600160a01b0381166000908152609a602090815260408083205433808552609f909352922054906112d6908490610b4d565b6112f25760405162461bcd60e51b8152600401610546906119ef565b6000828152609c60205260409020611309906115f7565b156113565760405162461bcd60e51b815260206004820152601c60248201527f416d6261737361646f723a3a204841535f434f4d4d554e4954494553000000006044820152606401610546565b600081815260a16020526040812080549161137083611b00565b90915550506001600160a01b0383166000818152609a6020526040808220829055513392917fdf0a456c1486c80ba4cdebb55052f692736d848b7cd52f7586d824a51018483791a3505050565b6033546001600160a01b031633146113e75760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166000908152609f60205260409020541561144d5760405162461bcd60e51b815260206004820152601b60248201527f416d6261737361646f723a3a20414c52454144595f454e5449545900000000006044820152606401610546565b609880546001600160a01b0383166000818152609f6020908152604080832085905593825260a0905291822080546001600160a01b03191690911790558154919061149783611b17565b90915550506040516001600160a01b038216907fb22e19f08ff14b8507fef310677b98ad1329eba6abb5b90f147acd6475dc762b90600090a250565b6033546001600160a01b031633146114fd5760405162461bcd60e51b8152600401610546906119ba565b6001600160a01b0381166115625760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610546565b61156b81611601565b50565b6001600160a01b038281166000908152609a602081815260408084208054808652609e845282862054609b855283872080546001600160a01b0319168a8a169081179091559585528254958752838720959095559085905592845260a09091529091205490949116929190565b60006115f0836001600160a01b0384166116ce565b9392505050565b6000610b83825490565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006115f0836001600160a01b03841661171d565b600054610100900460ff1661168f5760405162461bcd60e51b815260040161054690611a9e565b61169761183a565b610bbd611861565b600054610100900460ff166116c65760405162461bcd60e51b815260040161054690611a9e565b610bbd611891565b600081815260018301602052604081205461171557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610b83565b506000610b83565b60008181526001830160205260408120548015611830576000611741600183611ae9565b855490915060009061175590600190611ae9565b90508181146117d657600086600001828154811061178357634e487b7160e01b600052603260045260246000fd5b90600052602060002001549050808760000184815481106117b457634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600188019052604090208390555b85548690806117f557634e487b7160e01b600052603160045260246000fd5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610b83565b6000915050610b83565b600054610100900460ff16610bbd5760405162461bcd60e51b815260040161054690611a9e565b600054610100900460ff166118885760405162461bcd60e51b815260040161054690611a9e565b610bbd33611601565b600054610100900460ff166118b85760405162461bcd60e51b815260040161054690611a9e565b6001606555565b6000602082840312156118d0578081fd5b81356115f081611b48565b600080604083850312156118ed578081fd5b82356118f881611b48565b9150602083013561190881611b48565b809150509250929050565b600080600060608486031215611927578081fd5b833561193281611b48565b9250602084013561194281611b48565b915060408401358015158114611956578182fd5b809150509250925092565b600060208284031215611972578081fd5b5035919050565b60208082526021908201527f416d6261737361646f723a3a204f4e4c595f434f4d4d554e4954595f41444d496040820152602760f91b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601b908201527f416d6261737361646f723a3a204e4f545f414d4241535341444f520000000000604082015260600190565b60208082526021908201527f416d6261737361646f723a3a204f4e4c595f454e544954595f4f525f4f574e456040820152602960f91b606082015260800190565b6020808252601f908201527f416d6261737361646f723a3a20414c52454144595f414d4241535341444f5200604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082821015611afb57611afb611b32565b500390565b600081611b0f57611b0f611b32565b506000190190565b6000600019821415611b2b57611b2b611b32565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b038116811461156b57600080fdfea2646970667358221220e6c49ec861826effc4abf9da6511a8dfc133a4e42f175b97be76cd56d20595db64736f6c63430008040033