ETH Price: $3,270.84 (-2.23%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Claim Asset From180847332023-09-07 13:05:35503 days ago1694091935IN
0xb20a1745...26e547F9D
0 ETH0.0027140816.34993562
Safe Transfer Fr...176113882023-07-03 5:32:11569 days ago1688362331IN
0xb20a1745...26e547F9D
0 ETH0.0007599313.08274515
Safe Transfer Fr...176092212023-07-02 22:13:23569 days ago1688336003IN
0xb20a1745...26e547F9D
0 ETH0.0007756413.35317151
Set Approval For...174221822023-06-06 15:05:59596 days ago1686063959IN
0xb20a1745...26e547F9D
0 ETH0.0014439731.24740157

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Block
From
To
170305972023-04-12 7:59:35651 days ago1681286375  Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AssetTransferRights

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 46 : AssetTransferRights.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;

import "@openzeppelin/access/Ownable.sol";
import "@openzeppelin/token/ERC721/ERC721.sol";
import "@openzeppelin/token/ERC721/IERC721.sol";
import "@openzeppelin/proxy/utils/Initializable.sol";

import "@safe/common/Enum.sol";
import "@safe/GnosisSafe.sol";

import "MultiToken/MultiToken.sol";

import "@pwn-safe/factory/IPWNSafeValidator.sol";
import "@pwn-safe/guard/IAssetTransferRightsGuard.sol";
import "@pwn-safe/module/RecipientPermissionManager.sol";
import "@pwn-safe/module/TokenizedAssetManager.sol";
import "@pwn-safe/Whitelist.sol";


/**
 * @title Asset Transfer Rights contract
 * @notice This contract represents tokenized transfer rights of underlying asset (ATR token).
 *         ATR token can be used in lending protocols instead of an underlying asset.
 * @dev Is used as a module of Gnosis Safe contract wallet.
 */
contract AssetTransferRights is
	Ownable,
	Initializable,
	TokenizedAssetManager,
	RecipientPermissionManager,
	ERC721
{
	using MultiToken for MultiToken.Asset;


	/*----------------------------------------------------------*|
	|*  # VARIABLES & CONSTANTS DEFINITIONS                     *|
	|*----------------------------------------------------------*/

	string public constant VERSION = "0.1.0";

	/**
	 * @notice Last minted token id.
	 * @dev First used token id is 1.
	 *      If `lastTokenId` == 0, there is no ATR token minted yet.
	 */
	uint256 public lastTokenId;

	/**
	 * @notice Address of the safe validator.
	 * @dev Safe validator keeps track of valid PWN Safes.
	 */
	IPWNSafeValidator public safeValidator;

	/**
	 * @notice Address of the ATR guard.
	 */
	IAssetTransferRightsGuard public atrGuard;

	/**
	 * @notice Address of the whitelist contract.
	 * @dev If used, only assets that are whitelisted could be tokenized.
	 */
	Whitelist public whitelist;

	/**
	 * @dev ATR token metadata URI with `{id}` placeholder.
	 */
	string private _metadataUri;


	/*----------------------------------------------------------*|
	|*  # CONSTRUCTOR                                           *|
	|*----------------------------------------------------------*/

	constructor(address _whitelist)
		Ownable()
		ERC721("Asset Transfer Rights", "ATR")
	{
		whitelist = Whitelist(_whitelist);
	}

	function initialize(address _safeValidator, address _atrGuard) external initializer {
		safeValidator = IPWNSafeValidator(_safeValidator);
		atrGuard = IAssetTransferRightsGuard(_atrGuard);
	}


	/*----------------------------------------------------------*|
	|*  # ASSET TRANSFER RIGHTS TOKEN                           *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Tokenize given assets transfer rights and mint ATR token.
	 * @dev Requirements:
	 *      - caller has to be PWNSafe
	 *      - cannot tokenize transfer rights of ATR token
	 *      - in case whitelist is used, asset has to be whitelisted
	 *      - cannot tokenize invalid asset. See {MultiToken-isValid}
	 *      - cannot have operator set for that asset collection (setApprovalForAll) (ERC721 / ERC1155)
	 *      - in case of ERC721 assets, cannot tokenize approved asset, but other tokens can be approved
	 *      - in case of ERC20 assets, asset cannot have any approval
	 * @param asset Asset struct defined in MultiToken library. See {MultiToken-Asset}
	 * @return Id of newly minted ATR token
	 */
	function mintAssetTransferRightsToken(MultiToken.Asset memory asset) public returns (uint256) {
		// Check that msg.sender is PWNSafe
		require(safeValidator.isValidSafe(msg.sender) == true, "Caller is not a PWNSafe");

		// Check that asset address is not ATR contract address
		require(asset.assetAddress != address(this), "Attempting to tokenize ATR token");

		// Check that address is whitelisted
		require(whitelist.canBeTokenized(asset.assetAddress) == true, "Asset is not whitelisted");

		// Check that category is not CryptoKitties
		// CryptoKitties are not supported because of an auction feature.
		require(asset.category != MultiToken.Category.CryptoKitties, "Invalid provided category");

		// Check that given asset is valid
		// -> 0 address, correct provided category, struct format
		require(asset.isValid(), "Asset is not valid");

		// Check that asset collection doesn't have approvals
		require(atrGuard.hasOperatorFor(msg.sender, asset.assetAddress) == false, "Some asset from collection has an approval");

		// Check that ERC721 asset don't have approval
		if (asset.category == MultiToken.Category.ERC721) {
			address approved = IERC721(asset.assetAddress).getApproved(asset.id);
			require(approved == address(0), "Asset has an approved address");
		}

		// Check if asset can be tokenized
		require(_canBeTokenized(msg.sender, asset), "Insufficient balance to tokenize");

		// Set ATR token id
		uint256 atrTokenId = ++lastTokenId;

		// Store asset data
		_storeTokenizedAsset(atrTokenId, asset);

		// Update tokenized balance
		_increaseTokenizedBalance(atrTokenId, msg.sender, asset);

		// Mint ATR token
		_mint(msg.sender, atrTokenId);

		emit TransferViaATR(address(0), msg.sender, atrTokenId, asset);

		return atrTokenId;
	}

	/**
	 * @notice Tokenize given asset batch transfer rights and mint ATR tokens.
	 * @dev Function will iterate over given list and call `mintAssetTransferRightsToken` on each of them.
	 *      Requirements: See {AssetTransferRights-mintAssetTransferRightsToken}.
	 * @param assets List of assets to tokenize their transfer rights.
	 */
	function mintAssetTransferRightsTokenBatch(MultiToken.Asset[] calldata assets) external {
		for (uint256 i; i < assets.length; ++i) {
			mintAssetTransferRightsToken(assets[i]);
		}
	}

	/**
	 * @notice Burn ATR token and "untokenize" that assets transfer rights.
	 * @dev Token owner can burn the token if it's in the same safe as tokenized asset or via flag in `claimAssetFrom` function.
	 *      Requirements:
	 *      - caller has to be ATR token owner
	 *      - safe has to be a tokenized asset owner or ATR token has to be invalid (after recovery from e.g. stalking attack)
	 * @param atrTokenId ATR token id which should be burned.
	 */
	function burnAssetTransferRightsToken(uint256 atrTokenId) public {
		// Load asset
		MultiToken.Asset memory asset = assets[atrTokenId];

		// Check that token is indeed tokenized
		require(asset.assetAddress != address(0), "Asset transfer rights are not tokenized");

		// Check that caller is ATR token owner
		require(ownerOf(atrTokenId) == msg.sender, "Caller is not ATR token owner");

		if (isInvalid[atrTokenId] == false) {

			// Check asset balance
			require(asset.balanceOf(msg.sender) >= asset.getTransferAmount(), "Insufficient balance of a tokenize asset");

			// Update tokenized balance
			require(_decreaseTokenizedBalance(atrTokenId, msg.sender, asset), "Tokenized asset is not in a safe");

			emit TransferViaATR(msg.sender, address(0), atrTokenId, asset);
		}

		// Clear asset data
		_clearTokenizedAsset(atrTokenId);

		// Burn ATR token
		_burn(atrTokenId);
	}

	/**
	 * @notice Burn ATR token list and "untokenize" assets transfer rights.
	 * @dev Function will iterate over given list and all `burnAssetTransferRightsToken` on each of them.
	 *      Requirements: See {AssetTransferRights-burnAssetTransferRightsToken}.
	 * @param atrTokenIds ATR token id list which should be burned
	 */
	function burnAssetTransferRightsTokenBatch(uint256[] calldata atrTokenIds) external {
		for (uint256 i; i < atrTokenIds.length; ++i) {
			burnAssetTransferRightsToken(atrTokenIds[i]);
		}
	}


	/*----------------------------------------------------------*|
	|*  # TRANSFER ASSET WITH ATR TOKEN                         *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Transfer assets via ATR token to a caller.
	 * @dev Asset can be transferred only to a callers address.
	 *      Flag `burnToken` will burn the ATR token and transfer asset to any address (don't have to be PWNSafe).
	 *      Requirements:
	 *      - caller has to be an ATR token owner
	 *      - if `burnToken` is false, caller has to be PWNSafe, otherwise it could be any address
	 *      - if `burnToken` is false, caller must not have any approvals for asset collection
	 * @param from PWNSafe address from which to transfer asset.
	 * @param atrTokenId ATR token id which is used for the transfer.
	 * @param burnToken Flag to burn an ATR token in the same transaction.
	 */
	function claimAssetFrom(
		address payable from,
		uint256 atrTokenId,
		bool burnToken
	) external {
		// Load asset
		MultiToken.Asset memory asset = assets[atrTokenId];

		_initialChecks(asset, from, msg.sender, atrTokenId);

		// Process asset transfer
		_processTransferAssetFrom(asset, from, msg.sender, atrTokenId, burnToken);
	}

	/**
	 * @notice Transfer assets via ATR token to any address.
	 * @dev Asset can be transferred to any address, but needs to have recipient permission.
	 *      Permission can be granted on-chain, through off-chain signature or via ERC1271.
	 *      Flag `burnToken` will burn the ATR token and transfer asset to any address (don't have to be PWNSafe).
	 *      Requirements:
	 *      - caller has to be an ATR token owner
	 *      - if `burnToken` is false, caller has to be PWNSafe, otherwise it could be any address
	 *      - if `burnToken` is false, caller must not have any approvals for asset collection
	 *      - caller has to have recipients permission (granted on-chain, signed off-chain or via ERC1271)
	 * @param from PWNSafe address from which to transfer asset.
	 * @param atrTokenId ATR token id which is used for the transfer.
	 * @param burnToken Flag to burn an ATR token in the same transaction.
	 * @param permission Struct representing recipient permission. See {RecipientPermissionManager-RecipientPermission}.
	 * @param permissionSignature Signature of permission struct hash. In case of on-chain permission or when ERC1271 don't need it, pass empty data.
	 */
	function transferAssetFrom(
		address payable from,
		uint256 atrTokenId,
		bool burnToken,
		RecipientPermission memory permission,
		bytes calldata permissionSignature
	) external {
		// Load asset
		MultiToken.Asset memory asset = assets[atrTokenId];

		_initialChecks(asset, from, permission.recipient, atrTokenId);

		// Use valid permission
		_useValidPermission(msg.sender, asset, permission, permissionSignature);

		// Process asset transfer
		_processTransferAssetFrom(asset, from, permission.recipient, atrTokenId, burnToken);
	}

	/**
	 * @dev Check basic transfer conditions.
	 * @param asset Struct representing asset to be transferred. See {MultiToken-Asset}.
	 * @param from Address from which an asset will be transferred.
	 * @param to Address to which an asset will be transferred.
	 * @param atrTokenId Id of an ATR token which represents the underlying asset.
	 */
	function _initialChecks(
		MultiToken.Asset memory asset,
		address payable from,
		address to,
		uint256 atrTokenId
	) private view {
		// Check that transferring to different address
		require(from != to, "Attempting to transfer asset to the same address");

		// Check that asset transfer rights are tokenized
		require(asset.assetAddress != address(0), "Transfer rights are not tokenized");

		// Check that sender is ATR token owner
		require(ownerOf(atrTokenId) == msg.sender, "Caller is not ATR token owner");

		// Check that ATR token is not invalid
		require(!isInvalid[atrTokenId], "ATR token is invalid due to recovered invalid tokenized balance");
	}

	/**
	 * @dev Process internal state of an asset transfer and execute it.
	 * @param asset Struct representing asset to be transferred. See {MultiToken-Asset}.
	 * @param from Address from which an asset will be transferred.
	 * @param to Address to which an asset will be transferred.
	 * @param atrTokenId Id of an ATR token which represents the underlying asset.
	 * @param burnToken Flag to burn ATR token in the same transaction.
	 */
	function _processTransferAssetFrom(
		MultiToken.Asset memory asset,
		address payable from,
		address to,
		uint256 atrTokenId,
		bool burnToken
	) private {
		// Update tokenized balance (would fail for invalid ATR token)
		require(_decreaseTokenizedBalance(atrTokenId, from, asset), "Asset is not in a target safe");

		if (burnToken == true) {
			// Burn the ATR token
			_clearTokenizedAsset(atrTokenId);

			_burn(atrTokenId);
		} else {
			// Fail if recipient is not PWNSafe
			require(safeValidator.isValidSafe(to) == true, "Attempting to transfer asset to non PWNSafe address");

			// Check that recipient doesn't have approvals for the token collection
			require(atrGuard.hasOperatorFor(to, asset.assetAddress) == false, "Receiver has approvals set for an asset");

			// Update tokenized balance
			_increaseTokenizedBalance(atrTokenId, to, asset);
		}

		// Transfer asset from `from` safe
		bool success = GnosisSafe(from).execTransactionFromModule({
			to: asset.assetAddress,
			value: 0,
			data: asset.transferAssetFromCalldata(from, to, true),
			operation: Enum.Operation.Call
		});
		require(success, "Asset transfer failed");

		emit TransferViaATR(from, burnToken ? address(0) : to, atrTokenId, asset);
	}


	/*----------------------------------------------------------*|
	|*  # ATR TOKEN METADATA                                    *|
	|*----------------------------------------------------------*/

	/**
     * @dev See {IERC721Metadata-tokenURI}.
     */
	function tokenURI(uint256 tokenId) override public view returns (string memory) {
		_requireMinted(tokenId);
		return _metadataUri;
	}

	/**
	 * @notice Set new ATR token metadata URI.
	 * @param metadataUri New metadata URI.
	 */
	function setMetadataUri(string memory metadataUri) external onlyOwner {
		_metadataUri = metadataUri;
	}

}

File 2 of 46 : MultiToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/interfaces/IERC20.sol";
import "@openzeppelin/interfaces/IERC721.sol";
import "@openzeppelin/interfaces/IERC1155.sol";
import "@openzeppelin/token/ERC20/extensions/draft-IERC20Permit.sol";
import "@openzeppelin/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/utils/introspection/ERC165Checker.sol";

import "@MT/interfaces/ICryptoKitties.sol";


library MultiToken {
    using ERC165Checker for address;
    using SafeERC20 for IERC20;

    bytes4 public constant ERC20_INTERFACE_ID = 0x36372b07;
    bytes4 public constant ERC721_INTERFACE_ID = 0x80ac58cd;
    bytes4 public constant ERC1155_INTERFACE_ID = 0xd9b67a26;
    bytes4 public constant CRYPTO_KITTIES_INTERFACE_ID = 0x9a20483d;

    /**
     * @title Category
     * @dev Enum representation Asset category.
     */
    enum Category {
        ERC20,
        ERC721,
        ERC1155,
        CryptoKitties
    }

    /**
     * @title Asset
     * @param category Corresponding asset category.
     * @param assetAddress Address of the token contract defining the asset.
     * @param id TokenID of an NFT or 0.
     * @param amount Amount of fungible tokens or 0 -> 1.
     */
    struct Asset {
        Category category;
        address assetAddress;
        uint256 id;
        uint256 amount;
    }


    /*----------------------------------------------------------*|
    |*  # FACTORY FUNCTIONS                                     *|
    |*----------------------------------------------------------*/

    function ERC20(address assetAddress, uint256 amount) internal pure returns (Asset memory) {
        return Asset(Category.ERC20, assetAddress, 0, amount);
    }

    function ERC721(address assetAddress, uint256 id) internal pure returns (Asset memory) {
        return Asset(Category.ERC721, assetAddress, id, 0);
    }

    function ERC1155(address assetAddress, uint256 id, uint256 amount) internal pure returns (Asset memory) {
        return Asset(Category.ERC1155, assetAddress, id, amount);
    }

    function ERC1155(address assetAddress, uint256 id) internal pure returns (Asset memory) {
        return Asset(Category.ERC1155, assetAddress, id, 0);
    }

    function CryptoKitties(address assetAddress, uint256 id) internal pure returns (Asset memory) {
        return Asset(Category.CryptoKitties, assetAddress, id, 0);
    }


    /*----------------------------------------------------------*|
    |*  # TRANSFER ASSET                                        *|
    |*----------------------------------------------------------*/

    /**
     * transferAssetFrom
     * @dev Wrapping function for `transferFrom` calls on various token interfaces.
     *      If `source` is `address(this)`, function `transfer` is called instead of `transferFrom` for ERC20 category.
     * @param asset Struct defining all necessary context of a token.
     * @param source Account/address that provided the allowance.
     * @param dest Destination address.
     */
    function transferAssetFrom(Asset memory asset, address source, address dest) internal {
        _transferAssetFrom(asset, source, dest, false);
    }

    /**
     * safeTransferAssetFrom
     * @dev Wrapping function for `safeTransferFrom` calls on various token interfaces.
     *      If `source` is `address(this)`, function `transfer` is called instead of `transferFrom` for ERC20 category.
     * @param asset Struct defining all necessary context of a token.
     * @param source Account/address that provided the allowance.
     * @param dest Destination address.
     */
    function safeTransferAssetFrom(Asset memory asset, address source, address dest) internal {
        _transferAssetFrom(asset, source, dest, true);
    }

    function _transferAssetFrom(Asset memory asset, address source, address dest, bool isSafe) private {
        if (asset.category == Category.ERC20) {
            if (source == address(this))
                IERC20(asset.assetAddress).safeTransfer(dest, asset.amount);
            else
                IERC20(asset.assetAddress).safeTransferFrom(source, dest, asset.amount);

        } else if (asset.category == Category.ERC721) {
            if (!isSafe)
                IERC721(asset.assetAddress).transferFrom(source, dest, asset.id);
            else
                IERC721(asset.assetAddress).safeTransferFrom(source, dest, asset.id, "");

        } else if (asset.category == Category.ERC1155) {
            IERC1155(asset.assetAddress).safeTransferFrom(source, dest, asset.id, asset.amount == 0 ? 1 : asset.amount, "");

        } else if (asset.category == Category.CryptoKitties) {
            if (source == address(this))
                ICryptoKitties(asset.assetAddress).transfer(dest, asset.id);
            else
                ICryptoKitties(asset.assetAddress).transferFrom(source, dest, asset.id);

        } else {
            revert("MultiToken: Unsupported category");
        }
    }

    /**
     * getTransferAmount
     * @dev Get amount of asset that would be transferred.
     *      NFTs (ERC721, CryptoKitties & ERC1155 with amount 0) with return 1.
     *      Fungible tokens will return its amount (ERC20 with 0 amount is valid state).
     *      In combination with `MultiToken.balanceOf`, `getTransferAmount` can be used to check successful asset transfer.
     * @param asset Struct defining all necessary context of a token.
     * @return Number of tokens that would be transferred of the asset.
     */
    function getTransferAmount(Asset memory asset) internal pure returns (uint256) {
        if (asset.category == Category.ERC20)
            return asset.amount;
        else if (asset.category == Category.ERC1155 && asset.amount > 0)
            return asset.amount;
        else // Return 1 for ERC721, CryptoKitties and ERC1155 used as NFTs (amount = 0)
            return 1;
    }


    /*----------------------------------------------------------*|
    |*  # TRANSFER ASSET CALLDATA                               *|
    |*----------------------------------------------------------*/

    /**
     * transferAssetFromCalldata
     * @dev Wrapping function for `transferFrom` calladata on various token interfaces.
     *      If `fromSender` is true, function `transfer` is returned instead of `transferFrom` for ERC20 category.
     * @param asset Struct defining all necessary context of a token.
     * @param source Account/address that provided the allowance.
     * @param dest Destination address.
     */
    function transferAssetFromCalldata(Asset memory asset, address source, address dest, bool fromSender) pure internal returns (bytes memory) {
        return _transferAssetFromCalldata(asset, source, dest, fromSender, false);
    }

    /**
     * safeTransferAssetFromCalldata
     * @dev Wrapping function for `safeTransferFrom` calladata on various token interfaces.
     *      If `fromSender` is true, function `transfer` is returned instead of `transferFrom` for ERC20 category.
     * @param asset Struct defining all necessary context of a token.
     * @param source Account/address that provided the allowance.
     * @param dest Destination address.
     */
    function safeTransferAssetFromCalldata(Asset memory asset, address source, address dest, bool fromSender) pure internal returns (bytes memory) {
        return _transferAssetFromCalldata(asset, source, dest, fromSender, true);
    }

    function _transferAssetFromCalldata(Asset memory asset, address source, address dest, bool fromSender, bool isSafe) pure private returns (bytes memory) {
        if (asset.category == Category.ERC20) {
            if (fromSender) {
                return abi.encodeWithSignature(
                    "transfer(address,uint256)", dest, asset.amount
                );
            } else {
                return abi.encodeWithSignature(
                    "transferFrom(address,address,uint256)", source, dest, asset.amount
                );
            }
        } else if (asset.category == Category.ERC721) {
            if (!isSafe) {
                return abi.encodeWithSignature(
                    "transferFrom(address,address,uint256)", source, dest, asset.id
                );
            } else {
                return abi.encodeWithSignature(
                    "safeTransferFrom(address,address,uint256,bytes)", source, dest, asset.id, ""
                );
            }

        } else if (asset.category == Category.ERC1155) {
            return abi.encodeWithSignature(
                "safeTransferFrom(address,address,uint256,uint256,bytes)", source, dest, asset.id, asset.amount == 0 ? 1 : asset.amount, ""
            );

        } else if (asset.category == Category.CryptoKitties) {
            if (fromSender) {
                return abi.encodeWithSignature(
                    "transfer(address,uint256)", dest, asset.id
                );
            } else {
                return abi.encodeWithSignature(
                    "transferFrom(address,address,uint256)", source, dest, asset.id
                );
            }

        } else {
            revert("MultiToken: Unsupported category");
        }
    }


    /*----------------------------------------------------------*|
    |*  # PERMIT                                                *|
    |*----------------------------------------------------------*/

    /**
     * permit
     * @dev Wrapping function for granting approval via permit signature.
     * @param asset Struct defining all necessary context of a token.
     * @param owner Account/address that signed the permit.
     * @param spender Account/address that would be granted approval to `asset`.
     * @param permitData Data about permit deadline (uint256) and permit signature (64/65 bytes).
     *                   Deadline and signature should be pack encoded together.
     *                   Signature can be standard (65 bytes) or compact (64 bytes) defined in EIP-2098.
     */
    function permit(Asset memory asset, address owner, address spender, bytes memory permitData) internal {
        if (asset.category == Category.ERC20) {

            // Parse deadline and permit signature parameters
            uint256 deadline;
            bytes32 r;
            bytes32 s;
            uint8 v;

            // Parsing signature parameters used from OpenZeppelins ECDSA library
            // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/83277ff916ac4f58fec072b8f28a252c1245c2f1/contracts/utils/cryptography/ECDSA.sol

            // Deadline (32 bytes) + standard signature data (65 bytes) -> 97 bytes
            if (permitData.length == 97) {
                assembly {
                    deadline := mload(add(permitData, 0x20))
                    r := mload(add(permitData, 0x40))
                    s := mload(add(permitData, 0x60))
                    v := byte(0, mload(add(permitData, 0x80)))
                }
            }
            // Deadline (32 bytes) + compact signature data (64 bytes) -> 96 bytes
            else if (permitData.length == 96) {
                bytes32 vs;

                assembly {
                    deadline := mload(add(permitData, 0x20))
                    r := mload(add(permitData, 0x40))
                    vs := mload(add(permitData, 0x60))
                }

                s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
                v = uint8((uint256(vs) >> 255) + 27);
            } else {
                revert("MultiToken::Permit: Invalid permit length");
            }

            // Call permit with parsed parameters
            IERC20Permit(asset.assetAddress).permit(owner, spender, asset.amount, deadline, v, r, s);

        } else {
            // Currently supporting only ERC20 signed approvals via ERC2612
            revert("MultiToken::Permit: Unsupported category");
        }
    }


    /*----------------------------------------------------------*|
    |*  # BALANCE OF                                            *|
    |*----------------------------------------------------------*/

    /**
     * balanceOf
     * @dev Wrapping function for checking balances on various token interfaces.
     * @param asset Struct defining all necessary context of a token.
     * @param target Target address to be checked.
     */
    function balanceOf(Asset memory asset, address target) internal view returns (uint256) {
        if (asset.category == Category.ERC20) {
            return IERC20(asset.assetAddress).balanceOf(target);

        } else if (asset.category == Category.ERC721) {
            return IERC721(asset.assetAddress).ownerOf(asset.id) == target ? 1 : 0;

        } else if (asset.category == Category.ERC1155) {
            return IERC1155(asset.assetAddress).balanceOf(target, asset.id);

        } else if (asset.category == Category.CryptoKitties) {
            return ICryptoKitties(asset.assetAddress).ownerOf(asset.id) == target ? 1 : 0;

        } else {
            revert("MultiToken: Unsupported category");
        }
    }


    /*----------------------------------------------------------*|
    |*  # APPROVE ASSET                                         *|
    |*----------------------------------------------------------*/

    /**
     * approveAsset
     * @dev Wrapping function for `approve` calls on various token interfaces.
     *      By using `safeApprove` for ERC20, caller can set allowance to 0 or from 0.
     *      Cannot set non-zero value if allowance is also non-zero.
     * @param asset Struct defining all necessary context of a token.
     * @param target Account/address that would be granted approval to `asset`.
     */
    function approveAsset(Asset memory asset, address target) internal {
        if (asset.category == Category.ERC20) {
            IERC20(asset.assetAddress).safeApprove(target, asset.amount);

        } else if (asset.category == Category.ERC721) {
            IERC721(asset.assetAddress).approve(target, asset.id);

        } else if (asset.category == Category.ERC1155) {
            IERC1155(asset.assetAddress).setApprovalForAll(target, true);

        } else if (asset.category == Category.CryptoKitties) {
            ICryptoKitties(asset.assetAddress).approve(target, asset.id);

        } else {
            revert("MultiToken: Unsupported category");
        }
    }


    /*----------------------------------------------------------*|
    |*  # ASSET CHECKS                                          *|
    |*----------------------------------------------------------*/

    /**
     * isValid
     * @dev Checks that provided asset is contract, has correct format and stated category.
     *      Fungible tokens (ERC20) have to have id = 0.
     *      NFT (ERC721, CryptoKitties) tokens have to have amount = 0.
     *      Correct asset category is determined via ERC165.
     *      The check assumes, that asset contract implements only one token standard at a time.
     * @param asset Asset that is examined.
     * @return True if assets amount and id is valid in stated category.
     */
    function isValid(Asset memory asset) internal view returns (bool) {
        if (asset.category == Category.ERC20) {
            // Check format
            if (asset.id != 0)
                return false;

            // ERC20 has optional ERC165 implementation
            if (asset.assetAddress.supportsERC165()) {
                // If ERC20 implements ERC165, it has to return true for its interface id
                return asset.assetAddress.supportsERC165InterfaceUnchecked(ERC20_INTERFACE_ID);

            } else {
                // In case token doesn't implement ERC165, its safe to assume that provided category is correct,
                // because any other category have to implement ERC165.

                // Check that asset address is contract
                // Tip: asset address will return code length 0, if this code is called from the asset constructor
                return asset.assetAddress.code.length > 0;
            }

        } else if (asset.category == Category.ERC721) {
            // Check format
            if (asset.amount != 0)
                return false;

            // Check it's ERC721 via ERC165
            return asset.assetAddress.supportsInterface(ERC721_INTERFACE_ID);

        } else if (asset.category == Category.ERC1155) {
            // Check it's ERC1155 via ERC165
            return asset.assetAddress.supportsInterface(ERC1155_INTERFACE_ID);

        } else if (asset.category == Category.CryptoKitties) {
            // Check format
            if (asset.amount != 0)
                return false;

            // Check it's CryptoKitties via ERC165
            return asset.assetAddress.supportsInterface(CRYPTO_KITTIES_INTERFACE_ID);

        } else {
            revert("MultiToken: Unsupported category");
        }
    }

    /**
     * isSameAs
     * @dev Compare two assets, ignoring their amounts.
     * @param asset First asset to examine.
     * @param otherAsset Second asset to examine.
     * @return True if both structs represents the same asset.
     */
    function isSameAs(Asset memory asset, Asset memory otherAsset) internal pure returns (bool) {
        return
            asset.category == otherAsset.category &&
            asset.assetAddress == otherAsset.assetAddress &&
            asset.id == otherAsset.id;
    }
}

File 3 of 46 : ICryptoKitties.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICryptoKitties {
    // Required methods
    function totalSupply() external view returns (uint256 total);
    function balanceOf(address _owner) external view returns (uint256 balance);
    function ownerOf(uint256 _tokenId) external view returns (address owner);
    function approve(address _to, uint256 _tokenId) external;
    function transfer(address _to, uint256 _tokenId) external;
    function transferFrom(address _from, address _to, uint256 _tokenId) external;

    // Optional
    function name() external view returns (string memory name);
    function symbol() external view returns (string memory symbol);
    function tokensOfOwner(address _owner) external view returns (uint256[] memory tokenIds);
    function tokenMetadata(uint256 _tokenId, string memory _preferredTransport) external view returns (string memory infoUrl);

    // Events
    event Transfer(address from, address to, uint256 tokenId);
    event Approval(address owner, address approved, uint256 tokenId);

    // ERC-165 Compatibility (https://github.com/ethereum/EIPs/issues/165)
    // Is not part of the interface id
    function supportsInterface(bytes4 _interfaceID) external view returns (bool);
}

File 4 of 46 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

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

File 5 of 46 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1155.sol)

pragma solidity ^0.8.0;

import "../token/ERC1155/IERC1155.sol";

File 6 of 46 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 7 of 46 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";

File 8 of 46 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol)

pragma solidity ^0.8.0;

import "../token/ERC721/IERC721.sol";

File 9 of 46 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

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

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

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

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

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

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

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

File 10 of 46 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
        external
        view
        returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 14 of 46 : ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: address zero is not a valid owner");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: invalid token ID");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        _requireMinted(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not token owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        _requireMinted(tokenId);

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
        _safeTransfer(from, to, tokenId, data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

        _afterTokenTransfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);

        _afterTokenTransfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        delete _tokenApprovals[tokenId];

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` has not been minted yet.
     */
    function _requireMinted(uint256 tokenId) internal view virtual {
        require(_exists(tokenId), "ERC721: invalid token ID");
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}

File 15 of 46 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

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

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

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

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

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

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

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

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

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

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

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

File 16 of 46 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 17 of 46 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

File 19 of 46 : 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;
    }
}

File 20 of 46 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

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

File 21 of 46 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

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

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

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

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

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

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

File 22 of 46 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 23 of 46 : ERC165Checker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Checker.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface,
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return
            supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
            !supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
    }

    /**
     * @dev Returns a boolean array where each value corresponds to the
     * interfaces passed in and whether they're supported or not. This allows
     * you to batch check interfaces for a contract where your expectation
     * is that some interfaces may not be supported.
     *
     * See {IERC165-supportsInterface}.
     *
     * _Available since v3.4._
     */
    function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)
        internal
        view
        returns (bool[] memory)
    {
        // an array of booleans corresponding to interfaceIds and whether they're supported or not
        bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);

        // query support of ERC165 itself
        if (supportsERC165(account)) {
            // query support of each interface in interfaceIds
            for (uint256 i = 0; i < interfaceIds.length; i++) {
                interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
            }
        }

        return interfaceIdsSupported;
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in _interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
        bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);
        (bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams);
        if (result.length < 32) return false;
        return success && abi.decode(result, (bool));
    }
}

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

pragma solidity ^0.8.0;

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

File 25 of 46 : EnumerableMap.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableMap.sol)

pragma solidity ^0.8.0;

import "./EnumerableSet.sol";

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * The following map types are supported:
 *
 * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
 * - `address -> uint256` (`AddressToUintMap`) since v4.6.0
 * - `bytes32 -> bytes32` (`Bytes32ToBytes32`) since v4.6.0
 * - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
 * - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an array of EnumerableMap.
 * ====
 */
library EnumerableMap {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct Bytes32ToBytes32Map {
        // Storage of keys
        EnumerableSet.Bytes32Set _keys;
        mapping(bytes32 => bytes32) _values;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        Bytes32ToBytes32Map storage map,
        bytes32 key,
        bytes32 value
    ) internal returns (bool) {
        map._values[key] = value;
        return map._keys.add(key);
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
        delete map._values[key];
        return map._keys.remove(key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
        return map._keys.contains(key);
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
        return map._keys.length();
    }

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

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
        bytes32 value = map._values[key];
        if (value == bytes32(0)) {
            return (contains(map, key), bytes32(0));
        } else {
            return (true, value);
        }
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || contains(map, key), "EnumerableMap: nonexistent key");
        return value;
    }

    /**
     * @dev Same as {_get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {_tryGet}.
     */
    function get(
        Bytes32ToBytes32Map storage map,
        bytes32 key,
        string memory errorMessage
    ) internal view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || contains(map, key), errorMessage);
        return value;
    }

    // UintToUintMap

    struct UintToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        UintToUintMap storage map,
        uint256 key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

    /**
     * @dev Returns the element 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(UintToUintMap storage map, uint256 index) internal view returns (uint256, uint256) {
        (bytes32 key, bytes32 value) = at(map._inner, index);
        return (uint256(key), uint256(value));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(key)));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        UintToUintMap storage map,
        uint256 key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(key), errorMessage));
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        UintToAddressMap storage map,
        uint256 key,
        address value
    ) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToAddressMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

    /**
     * @dev Returns the element 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(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) {
        (bytes32 key, bytes32 value) = at(map._inner, index);
        return (uint256(key), address(uint160(uint256(value))));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(get(map._inner, bytes32(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        UintToAddressMap storage map,
        uint256 key,
        string memory errorMessage
    ) internal view returns (address) {
        return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));
    }

    // AddressToUintMap

    struct AddressToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        AddressToUintMap storage map,
        address key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(AddressToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

    /**
     * @dev Returns the element 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(AddressToUintMap storage map, uint256 index) internal view returns (address, uint256) {
        (bytes32 key, bytes32 value) = at(map._inner, index);
        return (address(uint160(uint256(key))), uint256(value));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        AddressToUintMap storage map,
        address key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));
    }

    // Bytes32ToUintMap

    struct Bytes32ToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        Bytes32ToUintMap storage map,
        bytes32 key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, key, bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

    /**
     * @dev Returns the element 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(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32, uint256) {
        (bytes32 key, bytes32 value) = at(map._inner, index);
        return (key, uint256(value));
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, key);
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
        return uint256(get(map._inner, key));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        Bytes32ToUintMap storage map,
        bytes32 key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, key, errorMessage));
    }
}

File 26 of 46 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (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.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

    /**
     * @dev Returns the number of values 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;

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

        return result;
    }
}

File 27 of 46 : GnosisSafe.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "./base/ModuleManager.sol";
import "./base/OwnerManager.sol";
import "./base/FallbackManager.sol";
import "./base/GuardManager.sol";
import "./common/EtherPaymentFallback.sol";
import "./common/Singleton.sol";
import "./common/SignatureDecoder.sol";
import "./common/SecuredTokenTransfer.sol";
import "./common/StorageAccessible.sol";
import "./interfaces/ISignatureValidator.sol";
import "./external/GnosisSafeMath.sol";

/// @title Gnosis Safe - A multisignature wallet with support for confirmations using signed messages based on ERC191.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafe is
    EtherPaymentFallback,
    Singleton,
    ModuleManager,
    OwnerManager,
    SignatureDecoder,
    SecuredTokenTransfer,
    ISignatureValidatorConstants,
    FallbackManager,
    StorageAccessible,
    GuardManager
{
    using GnosisSafeMath for uint256;

    string public constant VERSION = "1.3.0";

    // keccak256(
    //     "EIP712Domain(uint256 chainId,address verifyingContract)"
    // );
    bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH = 0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218;

    // keccak256(
    //     "SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)"
    // );
    bytes32 private constant SAFE_TX_TYPEHASH = 0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8;

    event SafeSetup(address indexed initiator, address[] owners, uint256 threshold, address initializer, address fallbackHandler);
    event ApproveHash(bytes32 indexed approvedHash, address indexed owner);
    event SignMsg(bytes32 indexed msgHash);
    event ExecutionFailure(bytes32 txHash, uint256 payment);
    event ExecutionSuccess(bytes32 txHash, uint256 payment);

    uint256 public nonce;
    bytes32 private _deprecatedDomainSeparator;
    // Mapping to keep track of all message hashes that have been approve by ALL REQUIRED owners
    mapping(bytes32 => uint256) public signedMessages;
    // Mapping to keep track of all hashes (message or transaction) that have been approve by ANY owners
    mapping(address => mapping(bytes32 => uint256)) public approvedHashes;

    // This constructor ensures that this contract can only be used as a master copy for Proxy contracts
    constructor() {
        // By setting the threshold it is not possible to call setup anymore,
        // so we create a Safe with 0 owners and threshold 1.
        // This is an unusable Safe, perfect for the singleton
        threshold = 1;
    }

    /// @dev Setup function sets initial storage of contract.
    /// @param _owners List of Safe owners.
    /// @param _threshold Number of required confirmations for a Safe transaction.
    /// @param to Contract address for optional delegate call.
    /// @param data Data payload for optional delegate call.
    /// @param fallbackHandler Handler for fallback calls to this contract
    /// @param paymentToken Token that should be used for the payment (0 is ETH)
    /// @param payment Value that should be paid
    /// @param paymentReceiver Adddress that should receive the payment (or 0 if tx.origin)
    function setup(
        address[] calldata _owners,
        uint256 _threshold,
        address to,
        bytes calldata data,
        address fallbackHandler,
        address paymentToken,
        uint256 payment,
        address payable paymentReceiver
    ) external {
        // setupOwners checks if the Threshold is already set, therefore preventing that this method is called twice
        setupOwners(_owners, _threshold);
        if (fallbackHandler != address(0)) internalSetFallbackHandler(fallbackHandler);
        // As setupOwners can only be called if the contract has not been initialized we don't need a check for setupModules
        setupModules(to, data);

        if (payment > 0) {
            // To avoid running into issues with EIP-170 we reuse the handlePayment function (to avoid adjusting code of that has been verified we do not adjust the method itself)
            // baseGas = 0, gasPrice = 1 and gas = payment => amount = (payment + 0) * 1 = payment
            handlePayment(payment, 0, 1, paymentToken, paymentReceiver);
        }
        emit SafeSetup(msg.sender, _owners, _threshold, to, fallbackHandler);
    }

    /// @dev Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction.
    ///      Note: The fees are always transferred, even if the user transaction fails.
    /// @param to Destination address of Safe transaction.
    /// @param value Ether value of Safe transaction.
    /// @param data Data payload of Safe transaction.
    /// @param operation Operation type of Safe transaction.
    /// @param safeTxGas Gas that should be used for the Safe transaction.
    /// @param baseGas Gas costs that are independent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund)
    /// @param gasPrice Gas price that should be used for the payment calculation.
    /// @param gasToken Token address (or 0 if ETH) that is used for the payment.
    /// @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).
    /// @param signatures Packed signature data ({bytes32 r}{bytes32 s}{uint8 v})
    function execTransaction(
        address to,
        uint256 value,
        bytes calldata data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes memory signatures
    ) public payable virtual returns (bool success) {
        bytes32 txHash;
        // Use scope here to limit variable lifetime and prevent `stack too deep` errors
        {
            bytes memory txHashData =
                encodeTransactionData(
                    // Transaction info
                    to,
                    value,
                    data,
                    operation,
                    safeTxGas,
                    // Payment info
                    baseGas,
                    gasPrice,
                    gasToken,
                    refundReceiver,
                    // Signature info
                    nonce
                );
            // Increase nonce and execute transaction.
            nonce++;
            txHash = keccak256(txHashData);
            checkSignatures(txHash, txHashData, signatures);
        }
        address guard = getGuard();
        {
            if (guard != address(0)) {
                Guard(guard).checkTransaction(
                    // Transaction info
                    to,
                    value,
                    data,
                    operation,
                    safeTxGas,
                    // Payment info
                    baseGas,
                    gasPrice,
                    gasToken,
                    refundReceiver,
                    // Signature info
                    signatures,
                    msg.sender
                );
            }
        }
        // We require some gas to emit the events (at least 2500) after the execution and some to perform code until the execution (500)
        // We also include the 1/64 in the check that is not send along with a call to counteract potential shortings because of EIP-150
        require(gasleft() >= ((safeTxGas * 64) / 63).max(safeTxGas + 2500) + 500, "GS010");
        // Use scope here to limit variable lifetime and prevent `stack too deep` errors
        {
            uint256 gasUsed = gasleft();
            // If the gasPrice is 0 we assume that nearly all available gas can be used (it is always more than safeTxGas)
            // We only substract 2500 (compared to the 3000 before) to ensure that the amount passed is still higher than safeTxGas
            success = execute(to, value, data, operation, gasPrice == 0 ? (gasleft() - 2500) : safeTxGas);
            gasUsed = gasUsed.sub(gasleft());
            // If no safeTxGas and no gasPrice was set (e.g. both are 0), then the internal tx is required to be successful
            // This makes it possible to use `estimateGas` without issues, as it searches for the minimum gas where the tx doesn't revert
            require(success || safeTxGas != 0 || gasPrice != 0, "GS013");
            // We transfer the calculated tx costs to the tx.origin to avoid sending it to intermediate contracts that have made calls
            uint256 payment = 0;
            if (gasPrice > 0) {
                payment = handlePayment(gasUsed, baseGas, gasPrice, gasToken, refundReceiver);
            }
            if (success) emit ExecutionSuccess(txHash, payment);
            else emit ExecutionFailure(txHash, payment);
        }
        {
            if (guard != address(0)) {
                Guard(guard).checkAfterExecution(txHash, success);
            }
        }
    }

    function handlePayment(
        uint256 gasUsed,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver
    ) private returns (uint256 payment) {
        // solhint-disable-next-line avoid-tx-origin
        address payable receiver = refundReceiver == address(0) ? payable(tx.origin) : refundReceiver;
        if (gasToken == address(0)) {
            // For ETH we will only adjust the gas price to not be higher than the actual used gas price
            payment = gasUsed.add(baseGas).mul(gasPrice < tx.gasprice ? gasPrice : tx.gasprice);
            require(receiver.send(payment), "GS011");
        } else {
            payment = gasUsed.add(baseGas).mul(gasPrice);
            require(transferToken(gasToken, receiver, payment), "GS012");
        }
    }

    /**
     * @dev Checks whether the signature provided is valid for the provided data, hash. Will revert otherwise.
     * @param dataHash Hash of the data (could be either a message hash or transaction hash)
     * @param data That should be signed (this is passed to an external validator contract)
     * @param signatures Signature data that should be verified. Can be ECDSA signature, contract signature (EIP-1271) or approved hash.
     */
    function checkSignatures(
        bytes32 dataHash,
        bytes memory data,
        bytes memory signatures
    ) public view {
        // Load threshold to avoid multiple storage loads
        uint256 _threshold = threshold;
        // Check that a threshold is set
        require(_threshold > 0, "GS001");
        checkNSignatures(dataHash, data, signatures, _threshold);
    }

    /**
     * @dev Checks whether the signature provided is valid for the provided data, hash. Will revert otherwise.
     * @param dataHash Hash of the data (could be either a message hash or transaction hash)
     * @param data That should be signed (this is passed to an external validator contract)
     * @param signatures Signature data that should be verified. Can be ECDSA signature, contract signature (EIP-1271) or approved hash.
     * @param requiredSignatures Amount of required valid signatures.
     */
    function checkNSignatures(
        bytes32 dataHash,
        bytes memory data,
        bytes memory signatures,
        uint256 requiredSignatures
    ) public view {
        // Check that the provided signature data is not too short
        require(signatures.length >= requiredSignatures.mul(65), "GS020");
        // There cannot be an owner with address 0.
        address lastOwner = address(0);
        address currentOwner;
        uint8 v;
        bytes32 r;
        bytes32 s;
        uint256 i;
        for (i = 0; i < requiredSignatures; i++) {
            (v, r, s) = signatureSplit(signatures, i);
            if (v == 0) {
                // If v is 0 then it is a contract signature
                // When handling contract signatures the address of the contract is encoded into r
                currentOwner = address(uint160(uint256(r)));

                // Check that signature data pointer (s) is not pointing inside the static part of the signatures bytes
                // This check is not completely accurate, since it is possible that more signatures than the threshold are send.
                // Here we only check that the pointer is not pointing inside the part that is being processed
                require(uint256(s) >= requiredSignatures.mul(65), "GS021");

                // Check that signature data pointer (s) is in bounds (points to the length of data -> 32 bytes)
                require(uint256(s).add(32) <= signatures.length, "GS022");

                // Check if the contract signature is in bounds: start of data is s + 32 and end is start + signature length
                uint256 contractSignatureLen;
                // solhint-disable-next-line no-inline-assembly
                assembly {
                    contractSignatureLen := mload(add(add(signatures, s), 0x20))
                }
                require(uint256(s).add(32).add(contractSignatureLen) <= signatures.length, "GS023");

                // Check signature
                bytes memory contractSignature;
                // solhint-disable-next-line no-inline-assembly
                assembly {
                    // The signature data for contract signatures is appended to the concatenated signatures and the offset is stored in s
                    contractSignature := add(add(signatures, s), 0x20)
                }
                require(ISignatureValidator(currentOwner).isValidSignature(data, contractSignature) == EIP1271_MAGIC_VALUE, "GS024");
            } else if (v == 1) {
                // If v is 1 then it is an approved hash
                // When handling approved hashes the address of the approver is encoded into r
                currentOwner = address(uint160(uint256(r)));
                // Hashes are automatically approved by the sender of the message or when they have been pre-approved via a separate transaction
                require(msg.sender == currentOwner || approvedHashes[currentOwner][dataHash] != 0, "GS025");
            } else if (v > 30) {
                // If v > 30 then default va (27,28) has been adjusted for eth_sign flow
                // To support eth_sign and similar we adjust v and hash the messageHash with the Ethereum message prefix before applying ecrecover
                currentOwner = ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)), v - 4, r, s);
            } else {
                // Default is the ecrecover flow with the provided data hash
                // Use ecrecover with the messageHash for EOA signatures
                currentOwner = ecrecover(dataHash, v, r, s);
            }
            require(currentOwner > lastOwner && owners[currentOwner] != address(0) && currentOwner != SENTINEL_OWNERS, "GS026");
            lastOwner = currentOwner;
        }
    }

    /// @dev Allows to estimate a Safe transaction.
    ///      This method is only meant for estimation purpose, therefore the call will always revert and encode the result in the revert data.
    ///      Since the `estimateGas` function includes refunds, call this method to get an estimated of the costs that are deducted from the safe with `execTransaction`
    /// @param to Destination address of Safe transaction.
    /// @param value Ether value of Safe transaction.
    /// @param data Data payload of Safe transaction.
    /// @param operation Operation type of Safe transaction.
    /// @return Estimate without refunds and overhead fees (base transaction and payload data gas costs).
    /// @notice Deprecated in favor of common/StorageAccessible.sol and will be removed in next version.
    function requiredTxGas(
        address to,
        uint256 value,
        bytes calldata data,
        Enum.Operation operation
    ) external returns (uint256) {
        uint256 startGas = gasleft();
        // We don't provide an error message here, as we use it to return the estimate
        require(execute(to, value, data, operation, gasleft()));
        uint256 requiredGas = startGas - gasleft();
        // Convert response to string and return via error message
        revert(string(abi.encodePacked(requiredGas)));
    }

    /**
     * @dev Marks a hash as approved. This can be used to validate a hash that is used by a signature.
     * @param hashToApprove The hash that should be marked as approved for signatures that are verified by this contract.
     */
    function approveHash(bytes32 hashToApprove) external {
        require(owners[msg.sender] != address(0), "GS030");
        approvedHashes[msg.sender][hashToApprove] = 1;
        emit ApproveHash(hashToApprove, msg.sender);
    }

    /// @dev Returns the chain id used by this contract.
    function getChainId() public view returns (uint256) {
        uint256 id;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            id := chainid()
        }
        return id;
    }

    function domainSeparator() public view returns (bytes32) {
        return keccak256(abi.encode(DOMAIN_SEPARATOR_TYPEHASH, getChainId(), this));
    }

    /// @dev Returns the bytes that are hashed to be signed by owners.
    /// @param to Destination address.
    /// @param value Ether value.
    /// @param data Data payload.
    /// @param operation Operation type.
    /// @param safeTxGas Gas that should be used for the safe transaction.
    /// @param baseGas Gas costs for that are independent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund)
    /// @param gasPrice Maximum gas price that should be used for this transaction.
    /// @param gasToken Token address (or 0 if ETH) that is used for the payment.
    /// @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).
    /// @param _nonce Transaction nonce.
    /// @return Transaction hash bytes.
    function encodeTransactionData(
        address to,
        uint256 value,
        bytes calldata data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address refundReceiver,
        uint256 _nonce
    ) public view returns (bytes memory) {
        bytes32 safeTxHash =
            keccak256(
                abi.encode(
                    SAFE_TX_TYPEHASH,
                    to,
                    value,
                    keccak256(data),
                    operation,
                    safeTxGas,
                    baseGas,
                    gasPrice,
                    gasToken,
                    refundReceiver,
                    _nonce
                )
            );
        return abi.encodePacked(bytes1(0x19), bytes1(0x01), domainSeparator(), safeTxHash);
    }

    /// @dev Returns hash to be signed by owners.
    /// @param to Destination address.
    /// @param value Ether value.
    /// @param data Data payload.
    /// @param operation Operation type.
    /// @param safeTxGas Fas that should be used for the safe transaction.
    /// @param baseGas Gas costs for data used to trigger the safe transaction.
    /// @param gasPrice Maximum gas price that should be used for this transaction.
    /// @param gasToken Token address (or 0 if ETH) that is used for the payment.
    /// @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).
    /// @param _nonce Transaction nonce.
    /// @return Transaction hash.
    function getTransactionHash(
        address to,
        uint256 value,
        bytes calldata data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address refundReceiver,
        uint256 _nonce
    ) public view returns (bytes32) {
        return keccak256(encodeTransactionData(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce));
    }
}

File 28 of 46 : Executor.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "../common/Enum.sol";

/// @title Executor - A contract that can execute transactions
/// @author Richard Meissner - <[email protected]>
contract Executor {
    function execute(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        uint256 txGas
    ) internal returns (bool success) {
        if (operation == Enum.Operation.DelegateCall) {
            // solhint-disable-next-line no-inline-assembly
            assembly {
                success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
            }
        } else {
            // solhint-disable-next-line no-inline-assembly
            assembly {
                success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
            }
        }
    }
}

File 29 of 46 : FallbackManager.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "../common/SelfAuthorized.sol";

/// @title Fallback Manager - A contract that manages fallback calls made to this contract
/// @author Richard Meissner - <[email protected]>
contract FallbackManager is SelfAuthorized {
    event ChangedFallbackHandler(address handler);

    // keccak256("fallback_manager.handler.address")
    bytes32 internal constant FALLBACK_HANDLER_STORAGE_SLOT = 0x6c9a6c4a39284e37ed1cf53d337577d14212a4870fb976a4366c693b939918d5;

    function internalSetFallbackHandler(address handler) internal {
        bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            sstore(slot, handler)
        }
    }

    /// @dev Allows to add a contract to handle fallback calls.
    ///      Only fallback calls without value and with data will be forwarded.
    ///      This can only be done via a Safe transaction.
    /// @param handler contract to handle fallbacks calls.
    function setFallbackHandler(address handler) public authorized {
        internalSetFallbackHandler(handler);
        emit ChangedFallbackHandler(handler);
    }

    // solhint-disable-next-line payable-fallback,no-complex-fallback
    fallback() external {
        bytes32 slot = FALLBACK_HANDLER_STORAGE_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            let handler := sload(slot)
            if iszero(handler) {
                return(0, 0)
            }
            calldatacopy(0, 0, calldatasize())
            // The msg.sender address is shifted to the left by 12 bytes to remove the padding
            // Then the address without padding is stored right after the calldata
            mstore(calldatasize(), shl(96, caller()))
            // Add 20 bytes for the address appended add the end
            let success := call(gas(), handler, 0, 0, add(calldatasize(), 20), 0, 0)
            returndatacopy(0, 0, returndatasize())
            if iszero(success) {
                revert(0, returndatasize())
            }
            return(0, returndatasize())
        }
    }
}

File 30 of 46 : GuardManager.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

import "../common/Enum.sol";
import "../common/SelfAuthorized.sol";

interface Guard {
    function checkTransaction(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes memory signatures,
        address msgSender
    ) external;

    function checkAfterExecution(bytes32 txHash, bool success) external;
}

/// @title Fallback Manager - A contract that manages fallback calls made to this contract
/// @author Richard Meissner - <[email protected]>
contract GuardManager is SelfAuthorized {
    event ChangedGuard(address guard);
    // keccak256("guard_manager.guard.address")
    bytes32 internal constant GUARD_STORAGE_SLOT = 0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8;

    /// @dev Set a guard that checks transactions before execution
    /// @param guard The address of the guard to be used or the 0 address to disable the guard
    function setGuard(address guard) external authorized {
        bytes32 slot = GUARD_STORAGE_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            sstore(slot, guard)
        }
        emit ChangedGuard(guard);
    }

    function getGuard() internal view returns (address guard) {
        bytes32 slot = GUARD_STORAGE_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            guard := sload(slot)
        }
    }
}

File 31 of 46 : ModuleManager.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "../common/Enum.sol";
import "../common/SelfAuthorized.sol";
import "./Executor.sol";

/// @title Module Manager - A contract that manages modules that can execute transactions via this contract
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract ModuleManager is SelfAuthorized, Executor {
    event EnabledModule(address module);
    event DisabledModule(address module);
    event ExecutionFromModuleSuccess(address indexed module);
    event ExecutionFromModuleFailure(address indexed module);

    address internal constant SENTINEL_MODULES = address(0x1);

    mapping(address => address) internal modules;

    function setupModules(address to, bytes memory data) internal {
        require(modules[SENTINEL_MODULES] == address(0), "GS100");
        modules[SENTINEL_MODULES] = SENTINEL_MODULES;
        if (to != address(0))
            // Setup has to complete successfully or transaction fails.
            require(execute(to, 0, data, Enum.Operation.DelegateCall, gasleft()), "GS000");
    }

    /// @dev Allows to add a module to the whitelist.
    ///      This can only be done via a Safe transaction.
    /// @notice Enables the module `module` for the Safe.
    /// @param module Module to be whitelisted.
    function enableModule(address module) public authorized {
        // Module address cannot be null or sentinel.
        require(module != address(0) && module != SENTINEL_MODULES, "GS101");
        // Module cannot be added twice.
        require(modules[module] == address(0), "GS102");
        modules[module] = modules[SENTINEL_MODULES];
        modules[SENTINEL_MODULES] = module;
        emit EnabledModule(module);
    }

    /// @dev Allows to remove a module from the whitelist.
    ///      This can only be done via a Safe transaction.
    /// @notice Disables the module `module` for the Safe.
    /// @param prevModule Module that pointed to the module to be removed in the linked list
    /// @param module Module to be removed.
    function disableModule(address prevModule, address module) public authorized {
        // Validate module address and check that it corresponds to module index.
        require(module != address(0) && module != SENTINEL_MODULES, "GS101");
        require(modules[prevModule] == module, "GS103");
        modules[prevModule] = modules[module];
        modules[module] = address(0);
        emit DisabledModule(module);
    }

    /// @dev Allows a Module to execute a Safe transaction without any further confirmations.
    /// @param to Destination address of module transaction.
    /// @param value Ether value of module transaction.
    /// @param data Data payload of module transaction.
    /// @param operation Operation type of module transaction.
    function execTransactionFromModule(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation
    ) public virtual returns (bool success) {
        // Only whitelisted modules are allowed.
        require(msg.sender != SENTINEL_MODULES && modules[msg.sender] != address(0), "GS104");
        // Execute transaction without further confirmations.
        success = execute(to, value, data, operation, gasleft());
        if (success) emit ExecutionFromModuleSuccess(msg.sender);
        else emit ExecutionFromModuleFailure(msg.sender);
    }

    /// @dev Allows a Module to execute a Safe transaction without any further confirmations and return data
    /// @param to Destination address of module transaction.
    /// @param value Ether value of module transaction.
    /// @param data Data payload of module transaction.
    /// @param operation Operation type of module transaction.
    function execTransactionFromModuleReturnData(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation
    ) public returns (bool success, bytes memory returnData) {
        success = execTransactionFromModule(to, value, data, operation);
        // solhint-disable-next-line no-inline-assembly
        assembly {
            // Load free memory location
            let ptr := mload(0x40)
            // We allocate memory for the return data by setting the free memory location to
            // current free memory location + data size + 32 bytes for data size value
            mstore(0x40, add(ptr, add(returndatasize(), 0x20)))
            // Store the size
            mstore(ptr, returndatasize())
            // Store the data
            returndatacopy(add(ptr, 0x20), 0, returndatasize())
            // Point the return data to the correct memory location
            returnData := ptr
        }
    }

    /// @dev Returns if an module is enabled
    /// @return True if the module is enabled
    function isModuleEnabled(address module) public view returns (bool) {
        return SENTINEL_MODULES != module && modules[module] != address(0);
    }

    /// @dev Returns array of modules.
    /// @param start Start of the page.
    /// @param pageSize Maximum number of modules that should be returned.
    /// @return array Array of modules.
    /// @return next Start of the next page.
    function getModulesPaginated(address start, uint256 pageSize) external view returns (address[] memory array, address next) {
        // Init array with max page size
        array = new address[](pageSize);

        // Populate return array
        uint256 moduleCount = 0;
        address currentModule = modules[start];
        while (currentModule != address(0x0) && currentModule != SENTINEL_MODULES && moduleCount < pageSize) {
            array[moduleCount] = currentModule;
            currentModule = modules[currentModule];
            moduleCount++;
        }
        next = currentModule;
        // Set correct size of returned array
        // solhint-disable-next-line no-inline-assembly
        assembly {
            mstore(array, moduleCount)
        }
    }
}

File 32 of 46 : OwnerManager.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
import "../common/SelfAuthorized.sol";

/// @title OwnerManager - Manages a set of owners and a threshold to perform actions.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract OwnerManager is SelfAuthorized {
    event AddedOwner(address owner);
    event RemovedOwner(address owner);
    event ChangedThreshold(uint256 threshold);

    address internal constant SENTINEL_OWNERS = address(0x1);

    mapping(address => address) internal owners;
    uint256 internal ownerCount;
    uint256 internal threshold;

    /// @dev Setup function sets initial storage of contract.
    /// @param _owners List of Safe owners.
    /// @param _threshold Number of required confirmations for a Safe transaction.
    function setupOwners(address[] memory _owners, uint256 _threshold) internal {
        // Threshold can only be 0 at initialization.
        // Check ensures that setup function can only be called once.
        require(threshold == 0, "GS200");
        // Validate that threshold is smaller than number of added owners.
        require(_threshold <= _owners.length, "GS201");
        // There has to be at least one Safe owner.
        require(_threshold >= 1, "GS202");
        // Initializing Safe owners.
        address currentOwner = SENTINEL_OWNERS;
        for (uint256 i = 0; i < _owners.length; i++) {
            // Owner address cannot be null.
            address owner = _owners[i];
            require(owner != address(0) && owner != SENTINEL_OWNERS && owner != address(this) && currentOwner != owner, "GS203");
            // No duplicate owners allowed.
            require(owners[owner] == address(0), "GS204");
            owners[currentOwner] = owner;
            currentOwner = owner;
        }
        owners[currentOwner] = SENTINEL_OWNERS;
        ownerCount = _owners.length;
        threshold = _threshold;
    }

    /// @dev Allows to add a new owner to the Safe and update the threshold at the same time.
    ///      This can only be done via a Safe transaction.
    /// @notice Adds the owner `owner` to the Safe and updates the threshold to `_threshold`.
    /// @param owner New owner address.
    /// @param _threshold New threshold.
    function addOwnerWithThreshold(address owner, uint256 _threshold) public authorized {
        // Owner address cannot be null, the sentinel or the Safe itself.
        require(owner != address(0) && owner != SENTINEL_OWNERS && owner != address(this), "GS203");
        // No duplicate owners allowed.
        require(owners[owner] == address(0), "GS204");
        owners[owner] = owners[SENTINEL_OWNERS];
        owners[SENTINEL_OWNERS] = owner;
        ownerCount++;
        emit AddedOwner(owner);
        // Change threshold if threshold was changed.
        if (threshold != _threshold) changeThreshold(_threshold);
    }

    /// @dev Allows to remove an owner from the Safe and update the threshold at the same time.
    ///      This can only be done via a Safe transaction.
    /// @notice Removes the owner `owner` from the Safe and updates the threshold to `_threshold`.
    /// @param prevOwner Owner that pointed to the owner to be removed in the linked list
    /// @param owner Owner address to be removed.
    /// @param _threshold New threshold.
    function removeOwner(
        address prevOwner,
        address owner,
        uint256 _threshold
    ) public authorized {
        // Only allow to remove an owner, if threshold can still be reached.
        require(ownerCount - 1 >= _threshold, "GS201");
        // Validate owner address and check that it corresponds to owner index.
        require(owner != address(0) && owner != SENTINEL_OWNERS, "GS203");
        require(owners[prevOwner] == owner, "GS205");
        owners[prevOwner] = owners[owner];
        owners[owner] = address(0);
        ownerCount--;
        emit RemovedOwner(owner);
        // Change threshold if threshold was changed.
        if (threshold != _threshold) changeThreshold(_threshold);
    }

    /// @dev Allows to swap/replace an owner from the Safe with another address.
    ///      This can only be done via a Safe transaction.
    /// @notice Replaces the owner `oldOwner` in the Safe with `newOwner`.
    /// @param prevOwner Owner that pointed to the owner to be replaced in the linked list
    /// @param oldOwner Owner address to be replaced.
    /// @param newOwner New owner address.
    function swapOwner(
        address prevOwner,
        address oldOwner,
        address newOwner
    ) public authorized {
        // Owner address cannot be null, the sentinel or the Safe itself.
        require(newOwner != address(0) && newOwner != SENTINEL_OWNERS && newOwner != address(this), "GS203");
        // No duplicate owners allowed.
        require(owners[newOwner] == address(0), "GS204");
        // Validate oldOwner address and check that it corresponds to owner index.
        require(oldOwner != address(0) && oldOwner != SENTINEL_OWNERS, "GS203");
        require(owners[prevOwner] == oldOwner, "GS205");
        owners[newOwner] = owners[oldOwner];
        owners[prevOwner] = newOwner;
        owners[oldOwner] = address(0);
        emit RemovedOwner(oldOwner);
        emit AddedOwner(newOwner);
    }

    /// @dev Allows to update the number of required confirmations by Safe owners.
    ///      This can only be done via a Safe transaction.
    /// @notice Changes the threshold of the Safe to `_threshold`.
    /// @param _threshold New threshold.
    function changeThreshold(uint256 _threshold) public authorized {
        // Validate that threshold is smaller than number of owners.
        require(_threshold <= ownerCount, "GS201");
        // There has to be at least one Safe owner.
        require(_threshold >= 1, "GS202");
        threshold = _threshold;
        emit ChangedThreshold(threshold);
    }

    function getThreshold() public view returns (uint256) {
        return threshold;
    }

    function isOwner(address owner) public view returns (bool) {
        return owner != SENTINEL_OWNERS && owners[owner] != address(0);
    }

    /// @dev Returns array of owners.
    /// @return Array of Safe owners.
    function getOwners() public view returns (address[] memory) {
        address[] memory array = new address[](ownerCount);

        // populate return array
        uint256 index = 0;
        address currentOwner = owners[SENTINEL_OWNERS];
        while (currentOwner != SENTINEL_OWNERS) {
            array[index] = currentOwner;
            currentOwner = owners[currentOwner];
            index++;
        }
        return array;
    }
}

File 33 of 46 : Enum.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title Enum - Collection of enums
/// @author Richard Meissner - <[email protected]>
contract Enum {
    enum Operation {Call, DelegateCall}
}

File 34 of 46 : EtherPaymentFallback.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title EtherPaymentFallback - A contract that has a fallback to accept ether payments
/// @author Richard Meissner - <[email protected]>
contract EtherPaymentFallback {
    event SafeReceived(address indexed sender, uint256 value);

    /// @dev Fallback function accepts Ether transactions.
    receive() external payable {
        emit SafeReceived(msg.sender, msg.value);
    }
}

File 35 of 46 : SecuredTokenTransfer.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title SecuredTokenTransfer - Secure token transfer
/// @author Richard Meissner - <[email protected]>
contract SecuredTokenTransfer {
    /// @dev Transfers a token and returns if it was a success
    /// @param token Token that should be transferred
    /// @param receiver Receiver to whom the token should be transferred
    /// @param amount The amount of tokens that should be transferred
    function transferToken(
        address token,
        address receiver,
        uint256 amount
    ) internal returns (bool transferred) {
        // 0xa9059cbb - keccack("transfer(address,uint256)")
        bytes memory data = abi.encodeWithSelector(0xa9059cbb, receiver, amount);
        // solhint-disable-next-line no-inline-assembly
        assembly {
            // We write the return value to scratch space.
            // See https://docs.soliditylang.org/en/v0.7.6/internals/layout_in_memory.html#layout-in-memory
            let success := call(sub(gas(), 10000), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            switch returndatasize()
                case 0 {
                    transferred := success
                }
                case 0x20 {
                    transferred := iszero(or(iszero(success), iszero(mload(0))))
                }
                default {
                    transferred := 0
                }
        }
    }
}

File 36 of 46 : SelfAuthorized.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title SelfAuthorized - authorizes current contract to perform actions
/// @author Richard Meissner - <[email protected]>
contract SelfAuthorized {
    function requireSelfCall() private view {
        require(msg.sender == address(this), "GS031");
    }

    modifier authorized() {
        // This is a function call as it minimized the bytecode size
        requireSelfCall();
        _;
    }
}

File 37 of 46 : SignatureDecoder.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title SignatureDecoder - Decodes signatures that a encoded as bytes
/// @author Richard Meissner - <[email protected]>
contract SignatureDecoder {
    /// @dev divides bytes signature into `uint8 v, bytes32 r, bytes32 s`.
    /// @notice Make sure to peform a bounds check for @param pos, to avoid out of bounds access on @param signatures
    /// @param pos which signature to read. A prior bounds check of this parameter should be performed, to avoid out of bounds access
    /// @param signatures concatenated rsv signatures
    function signatureSplit(bytes memory signatures, uint256 pos)
        internal
        pure
        returns (
            uint8 v,
            bytes32 r,
            bytes32 s
        )
    {
        // The signature format is a compact form of:
        //   {bytes32 r}{bytes32 s}{uint8 v}
        // Compact means, uint8 is not padded to 32 bytes.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            let signaturePos := mul(0x41, pos)
            r := mload(add(signatures, add(signaturePos, 0x20)))
            s := mload(add(signatures, add(signaturePos, 0x40)))
            // Here we are loading the last 32 bytes, including 31 bytes
            // of 's'. There is no 'mload8' to do this.
            //
            // 'byte' is not working due to the Solidity parser, so lets
            // use the second best option, 'and'
            v := and(mload(add(signatures, add(signaturePos, 0x41))), 0xff)
        }
    }
}

File 38 of 46 : Singleton.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title Singleton - Base for singleton contracts (should always be first super contract)
///         This contract is tightly coupled to our proxy contract (see `proxies/GnosisSafeProxy.sol`)
/// @author Richard Meissner - <[email protected]>
contract Singleton {
    // singleton always needs to be first declared variable, to ensure that it is at the same location as in the Proxy contract.
    // It should also always be ensured that the address is stored alone (uses a full word)
    address private singleton;
}

File 39 of 46 : StorageAccessible.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/// @title StorageAccessible - generic base contract that allows callers to access all internal storage.
/// @notice See https://github.com/gnosis/util-contracts/blob/bb5fe5fb5df6d8400998094fb1b32a178a47c3a1/contracts/StorageAccessible.sol
contract StorageAccessible {
    /**
     * @dev Reads `length` bytes of storage in the currents contract
     * @param offset - the offset in the current contract's storage in words to start reading from
     * @param length - the number of words (32 bytes) of data to read
     * @return the bytes that were read.
     */
    function getStorageAt(uint256 offset, uint256 length) public view returns (bytes memory) {
        bytes memory result = new bytes(length * 32);
        for (uint256 index = 0; index < length; index++) {
            // solhint-disable-next-line no-inline-assembly
            assembly {
                let word := sload(add(offset, index))
                mstore(add(add(result, 0x20), mul(index, 0x20)), word)
            }
        }
        return result;
    }

    /**
     * @dev Performs a delegetecall on a targetContract in the context of self.
     * Internally reverts execution to avoid side effects (making it static).
     *
     * This method reverts with data equal to `abi.encode(bool(success), bytes(response))`.
     * Specifically, the `returndata` after a call to this method will be:
     * `success:bool || response.length:uint256 || response:bytes`.
     *
     * @param targetContract Address of the contract containing the code to execute.
     * @param calldataPayload Calldata that should be sent to the target contract (encoded method name and arguments).
     */
    function simulateAndRevert(address targetContract, bytes memory calldataPayload) external {
        // solhint-disable-next-line no-inline-assembly
        assembly {
            let success := delegatecall(gas(), targetContract, add(calldataPayload, 0x20), mload(calldataPayload), 0, 0)

            mstore(0x00, success)
            mstore(0x20, returndatasize())
            returndatacopy(0x40, 0, returndatasize())
            revert(0, add(returndatasize(), 0x40))
        }
    }
}

File 40 of 46 : GnosisSafeMath.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/**
 * @title GnosisSafeMath
 * @dev Math operations with safety checks that revert on error
 * Renamed from SafeMath to GnosisSafeMath to avoid conflicts
 * TODO: remove once open zeppelin update to solc 0.5.0
 */
library GnosisSafeMath {
    /**
     * @dev Multiplies two numbers, reverts on overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b);

        return c;
    }

    /**
     * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Adds two numbers, reverts on overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a);

        return c;
    }

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

File 41 of 46 : ISignatureValidator.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

contract ISignatureValidatorConstants {
    // bytes4(keccak256("isValidSignature(bytes,bytes)")
    bytes4 internal constant EIP1271_MAGIC_VALUE = 0x20c13b0b;
}

abstract contract ISignatureValidator is ISignatureValidatorConstants {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param _data Arbitrary length data signed on the behalf of address(this)
     * @param _signature Signature byte array associated with _data
     *
     * MUST return the bytes4 magic value 0x20c13b0b when function passes.
     * MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)
     * MUST allow external calls
     */
    function isValidSignature(bytes memory _data, bytes memory _signature) public view virtual returns (bytes4);
}

File 42 of 46 : Whitelist.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;

import "@openzeppelin/access/Ownable.sol";


/**
 * @title Whitelist contract
 * @notice Contract responsible for managing whitelist of assets which are permited to have their transfer rights tokenized.
 *         Whitelist is temporarily solution for onboarding first users and will be dropped in the future.
 */
contract Whitelist is Ownable {

    /*----------------------------------------------------------*|
    |*  # VARIABLES & CONSTANTS DEFINITIONS                     *|
    |*----------------------------------------------------------*/

    /**
     * @notice Stored flag that incidates, whether ATR token minting is permited only to whitelisted assets.
     */
    bool public useWhitelist;

    /**
     * @notice Whitelist of asset addresses, which are permited to mint their transfer rights.
     * @dev Used only if `useWhitelist` flag is set to true.
     */
    mapping (address => bool) public isWhitelisted;

    /**
     * @notice Whitelist of library addresses, which are permited to be called via delegatecall.
     * @dev Always used, even if `useWhitelist` flag is set to false.
     */
    mapping (address => bool) public isWhitelistedLib;


    /*----------------------------------------------------------*|
    |*  # EVENTS & ERRORS DEFINITIONS                           *|
    |*----------------------------------------------------------*/

    /**
     * @dev Emitted when asset address is whitelisted.
     */
    event AssetWhitelisted(address indexed assetAddress, bool indexed isWhitelisted);


    /*----------------------------------------------------------*|
    |*  # CONSTRUCTOR                                           *|
    |*----------------------------------------------------------*/

    constructor() Ownable() {

    }


    /*----------------------------------------------------------*|
    |*  # GETTERS                                               *|
    |*----------------------------------------------------------*/

    /**
     * @notice Get if an asset can have its transfer rights tokenized.
     * @param assetAddress Address of asset which transfer rights should be tokenized.
     * @return True if asset is whitelisted or whitelist is not used at all.
     */
    function canBeTokenized(address assetAddress) external view returns (bool) {
        if (!useWhitelist)
            return true;

        return isWhitelisted[assetAddress];
    }


    /*----------------------------------------------------------*|
    |*  # SETTERS                                               *|
    |*----------------------------------------------------------*/

    /**
     * @notice Set if ATR token minting is restricted by the whitelist.
     * @dev Set `useWhitelist` stored flag.
     * @param _useWhitelist New `useWhitelist` flag value.
     */
    function setUseWhitelist(bool _useWhitelist) external onlyOwner {
        useWhitelist = _useWhitelist;
    }

    /**
     * @notice Set if asset address is whitelisted.
     * @dev Set `isWhitelisted` mapping value.
     * @param assetAddress Address of the whitelisted asset.
     * @param _isWhitelisted New `isWhitelisted` mapping value.
     */
    function setIsWhitelisted(address assetAddress, bool _isWhitelisted) public onlyOwner {
        isWhitelisted[assetAddress] = _isWhitelisted;

        emit AssetWhitelisted(assetAddress, _isWhitelisted);
    }

    /**
     * @notice Set if asset addresses from a list are whitelisted.
     * @dev Set `isWhitelisted` mapping value for every address in a list.
     * @param assetAddresses List of whitelisted asset addresses.
     * @param _isWhitelisted New `isWhitelisted` mapping value for every address in a list.
     */
    function setIsWhitelistedBatch(address[] calldata assetAddresses, bool _isWhitelisted) external onlyOwner {
        uint256 length = assetAddresses.length;
        for (uint256 i; i < length;) {
            setIsWhitelisted(assetAddresses[i], _isWhitelisted);
            unchecked { ++i; }
        }
    }

    /**
     * @notice Set if library address is whitelisted.
     * @dev Set `isWhitelistedLib` mapping value.
     * @param libAddress Address of the whitelisted library.
     * @param _isWhitelisted New `isWhitelisted` mapping value.
     */
    function setIsWhitelistedLib(address libAddress, bool _isWhitelisted) public onlyOwner {
        isWhitelistedLib[libAddress] = _isWhitelisted;
    }

}

File 43 of 46 : IPWNSafeValidator.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;


/**
 * @title PWNSafe Validator
 * @notice PWNSafe Validator is used in AssetTransferRights contract to determine
 *         if transfer via ATR token is possible without burning the ATR token.
 */
interface IPWNSafeValidator {

	/**
	 * @param safe Address that is tested to be a valid PWNSafe
	 * @return True if `safe` address is valid PWNSafe
	 */
	function isValidSafe(address safe) external view returns (bool);

}

File 44 of 46 : IAssetTransferRightsGuard.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;


/**
 * @title Asset Transfer Rights Guard Interface
 */
interface IAssetTransferRightsGuard {

	/**
	 * @dev Utility function used by AssetTransferRights contract to get information
	 *      about approvals for some asset contract on a wallet.
	 * @param safeAddress Address of a safe in question
	 * @param assetAddress Address of an asset contract
	 * @return True if wallet has at least one operator for given asset contract
	 */
	function hasOperatorFor(address safeAddress, address assetAddress) external view returns (bool);

}

File 45 of 46 : RecipientPermissionManager.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;

import "@openzeppelin/interfaces/IERC1271.sol";
import "@openzeppelin/utils/cryptography/ECDSA.sol";

import "MultiToken/MultiToken.sol";


/**
 * @title Recipient Permission Manager contract
 * @notice Contract responsible for checking valid recipient permissions, tracking granted and revoked permissions.
 */
abstract contract RecipientPermissionManager {

	/*----------------------------------------------------------*|
	|*  # VARIABLES & CONSTANTS DEFINITIONS                     *|
	|*----------------------------------------------------------*/

	bytes4 constant internal EIP1271_VALID_SIGNATURE = 0x1626ba7e;

	bytes32 constant internal RECIPIENT_PERMISSION_TYPEHASH = keccak256(
		"RecipientPermission(uint8 assetCategory,address assetAddress,uint256 assetId,uint256 assetAmount,bool ignoreAssetIdAndAmount,address recipient,address agent,uint40 expiration,bool isPersistent,bytes32 nonce)"
	);

	/**
	 * @title RecipientPermission
	 * @param assetCategory Category of an asset that is permitted to transfer.
	 * @param assetAddress Contract address of an asset that is permitted to transfer.
	 * @param assetId Id of an asset that is permitted to transfer.
	 * @param assetAmount Amount of an asset that is permitted to transfer.
	 * @param ignoreAssetIdAndAmount Flag statis if asset id and amount are ignored when checking permissioned asset.
	 * @param recipient Address of a recipient and permission signer.
	 * @param agent Optional address of a permitted agenat, that can process the permission. If zero value, any agent can process the permission.
	 * @param expiration Optional permission expiration timestamp (in seconds). If zero value, permission has no expiration.
	 * @param isPersistent Flag stating if permission is not going to be revoked after usage.
	 * @param nonce Additional value to enable otherwise identical permissions.
	 */
	struct RecipientPermission {
		// MultiToken.Asset
		MultiToken.Category assetCategory;
		address assetAddress;
		uint256 assetId;
		uint256 assetAmount;
		bool ignoreAssetIdAndAmount;
		// Permission signer
		address recipient;
		// Optional address of ATR token holder that will initiate a transfer
		address agent;
		// Optional (highly recommended) expiration timestamp in seconds. 0 = no expiration.
		uint40 expiration;
		bool isPersistent;
		bytes32 nonce;
	}

	/**
	 * Mapping of recipient permissions granted on-chain by recipient permission struct typed hash.
	 */
	mapping (bytes32 => bool) public grantedPermissions;

	/**
	 * Mapping of revoked recipient nonces by recipient address.
	 */
	mapping (address => mapping (bytes32 => bool)) public revokedPermissionNonces;


	/*----------------------------------------------------------*|
	|*  # EVENTS & ERRORS DEFINITIONS                           *|
	|*----------------------------------------------------------*/

	event RecipientPermissionGranted(bytes32 indexed permissionHash); // More data for dune analytics?
	event RecipientPermissionNonceRevoked(address indexed recipient, bytes32 indexed permissionNonce);


	/*----------------------------------------------------------*|
	|*  # PERMISSION MANAGEMENT                                 *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Grant recipient permission on-chain.
	 * @dev Function caller has to be permission recipient.
	 * @param permission Struct representing recipient permission. See {RecipientPermission}.
	 */
	function grantRecipientPermission(RecipientPermission calldata permission) external {
		// Check that caller is permission signer
		require(msg.sender == permission.recipient, "Sender is not permission recipient");

		bytes32 permissionHash = recipientPermissionHash(permission);

		// Check that permission is not have been granted
		require(grantedPermissions[permissionHash] == false, "Recipient permission is granted");

		// Check that permission is not have been revoked
		require(revokedPermissionNonces[msg.sender][permission.nonce] == false, "Recipient permission nonce is revoked");

		// Grant permission
		grantedPermissions[permissionHash] = true;

		// Emit event
		emit RecipientPermissionGranted(permissionHash);
	}

	/**
	 * @notice Revoke caller permission nonce.
	 * @param permissionNonce Permission nonce to be revoked for a caller.
	 */
	function revokeRecipientPermission(bytes32 permissionNonce) external {
		// Check that permission is not have been revoked
		require(revokedPermissionNonces[msg.sender][permissionNonce] == false, "Recipient permission nonce is revoked");

		// Revoke permission
		revokedPermissionNonces[msg.sender][permissionNonce] = true;

		// Emit event
		emit RecipientPermissionNonceRevoked(msg.sender, permissionNonce);
	}


	/*----------------------------------------------------------*|
	|*  # PERMISSION HASH                                       *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Hash recipient permission struct according to EIP-712.
	 * @param permission Struct representing recipient permission. See {RecipientPermission}.
	 */
	function recipientPermissionHash(RecipientPermission memory permission) public view returns (bytes32) {
		return keccak256(abi.encodePacked(
			"\x19\x01",
			// Domain separator is composing to prevent replay attack in case of an Ethereum fork
			keccak256(abi.encode(
				keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
				keccak256(bytes("AssetTransferRights")),
				keccak256(bytes("0.1")),
				block.chainid,
				address(this)
			)),
			keccak256(abi.encode(
				RECIPIENT_PERMISSION_TYPEHASH,
				permission.assetCategory,
				permission.assetAddress,
				permission.assetId,
				permission.assetAmount,
				permission.ignoreAssetIdAndAmount,
				permission.recipient,
				permission.expiration,
				permission.isPersistent,
				permission.nonce
			))
		));
	}


	/*----------------------------------------------------------*|
	|*  # VALID PERMISSION                                      *|
	|*----------------------------------------------------------*/

	/**
	 * @dev Checks if given permission is valid and mark permission as used.
	 * @param sender Address of a caller. If permission has non-zero agent address, caller has to be the agent.
	 * @param asset Struct representing asset to be transferred. See {MultiToken-Asset}.
	 * @param permission Struct representing recipient permission. See {RecipientPermission}.
	 * @param permissionSignature Signature of permission struct hash. In case of on-chain permission or when ERC1271 don't need it, pass empty data.
	 */
	function _useValidPermission(
		address sender,
		MultiToken.Asset memory asset,
		RecipientPermission memory permission,
		bytes calldata permissionSignature
	) internal {
		// Check that permission is not expired
		uint40 expiration = permission.expiration;
		require(expiration == 0 || block.timestamp < expiration, "Recipient permission is expired");

		// Check permitted agent
		address agent = permission.agent;
		require(agent == address(0) || sender == agent, "Caller is not permitted agent");

		// Check correct asset
		require(permission.assetCategory == asset.category, "Invalid permitted asset");
		require(permission.assetAddress == asset.assetAddress, "Invalid permitted asset");
		// Check id and amount if ignore flag is false
		if (permission.ignoreAssetIdAndAmount == false) {
			require(permission.assetId == asset.id, "Invalid permitted asset");
			require(permission.assetAmount == asset.amount, "Invalid permitted asset");
		} // Skip id and amount check if ignore flag is true

		// Check that permission nonce is not revoked
		address recipient = permission.recipient;
		bytes32 nonce = permission.nonce;
		require(revokedPermissionNonces[recipient][nonce] == false, "Recipient permission nonce is revoked");

		// Compute EIP-712 structured data hash
		bytes32 permissionHash = recipientPermissionHash(permission);

		// Check that permission is granted
		// Via on-chain tx, EIP-1271 or off-chain signature
		if (grantedPermissions[permissionHash] == true) {
			// Permission is granted on-chain, no need to check signature
		} else if (recipient.code.length > 0) {
			// Check that permission is valid
			require(IERC1271(recipient).isValidSignature(permissionHash, permissionSignature) == EIP1271_VALID_SIGNATURE, "Signature on behalf of contract is invalid");
		} else {
			// Check that permission signature is valid
			require(ECDSA.recover(permissionHash, permissionSignature) == recipient, "Permission signer is not stated as recipient");
		}

		// Mark used permission nonce as revoked if not persistent
		if (permission.isPersistent == false) {
			revokedPermissionNonces[recipient][nonce] = true;

			emit RecipientPermissionNonceRevoked(recipient, nonce);
		}

	}

}

File 46 of 46 : TokenizedAssetManager.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.15;

import "@openzeppelin/utils/structs/EnumerableMap.sol";
import "@openzeppelin/utils/structs/EnumerableSet.sol";

import "MultiToken/MultiToken.sol";


/**
 * @title Tokenized Asset Manager
 * @notice Contract responsible for managing tokenized asset balances.
 */
abstract contract TokenizedAssetManager {
	using EnumerableSet for EnumerableSet.UintSet;
	using EnumerableMap for EnumerableMap.UintToUintMap;
	using MultiToken for MultiToken.Asset;


	/*----------------------------------------------------------*|
	|*  # VARIABLES & CONSTANTS DEFINITIONS                     *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Invalid Tokenized Balance Report struct.
	 * @param atrTokenId Id of an ATR token, that is causing invalid tokenized balance.
	 * @param block Block number of a transaction in which was report reported.
	 */
	struct InvalidTokenizedBalanceReport {
		uint256 atrTokenId;
		uint256 block;
	}

	/**
	 * @notice Mapping of ATR token id to underlying asset
	 * @dev (ATR token id => Asset)
	 */
	mapping (uint256 => MultiToken.Asset) internal assets;

	/**
	 * @notice Mapping of safe address to set of ATR ids, that belongs to tokeniezd assets in the safe.
	 * @dev The ATR token itself doesn't have to be in the safe.
	 *      (safe => set of ATR token ids representing tokenized assets currently in owners safe)
	 */
	mapping (address => EnumerableSet.UintSet) internal tokenizedAssetsInSafe;

	/**
	 * @notice Balance of tokenized assets from asset collection in a safe
	 * @dev (safe => asset address => asset id => balance of tokenized assets currently in owners safe)
	 */
	mapping (address => mapping (address => EnumerableMap.UintToUintMap)) internal tokenizedBalances;

	/**
	 * @notice Reported invalid token balance reports.
	 * @dev Every user can have one report at a time.
	 *      Reason to divide recovery process into two transactions is to get rid of reentrancy exploits.
	 *      One could possible transfer tokenized assets from a safe and, before tokenized balance check can happen,
	 *      call recover function, that would recover the safe from that transitory invalid state
	 *      and tokenized balance check would pass, effectively bypassing transfer rights rules.
	 *      (safe => invalid tokenized balance report)
	 */
	mapping (address => InvalidTokenizedBalanceReport) private invalidTokenizedBalanceReports;

	/**
	 * @notice Mapping of invalid ATR tokens
	 * @dev After recovering safe from invalid tokenized balance state, ATR token is not burned, it's rather marked as invalid.
	 *      Main reason is to prevent other DeFi protocols from unexpected behavior in case the ATR token is used in them.
	 *      Invalid token can be burned, but cannot be used to transfer underlying asset as the holder of the asset is lost.
	 */
	mapping (uint256 => bool) public isInvalid;


	/*----------------------------------------------------------*|
	|*  # EVENTS & ERRORS DEFINITIONS                           *|
	|*----------------------------------------------------------*/

	/**
	 * @dev Emitted when asset is transferred via ATR token from `from` to `to`.
	 *      ATR token can be held by a different address.
	 */
	event TransferViaATR(address indexed from, address indexed to, uint256 indexed atrTokenId, MultiToken.Asset asset);


	/*----------------------------------------------------------*|
	|*  # CONSTRUCTOR                                           *|
	|*----------------------------------------------------------*/

	constructor() {

	}


	/*----------------------------------------------------------*|
	|*  # CHECK TOKENIZED BALANCE                               *|
	|*----------------------------------------------------------*/

	/**
	 * @dev Checks that address has sufficient balance of tokenized assets.
	 *      Fails if tokenized balance is insufficient.
	 * @param owner Address to check its tokenized balance.
	 */
	function hasSufficientTokenizedBalance(address owner) external view returns (bool) {
		uint256[] memory atrs = tokenizedAssetsInSafe[owner].values();
		for (uint256 i; i < atrs.length; ++i) {
			MultiToken.Asset memory asset = assets[atrs[i]];
			(, uint256 tokenizedBalance) = tokenizedBalances[owner][asset.assetAddress].tryGet(asset.id);
			if (asset.balanceOf(owner) < tokenizedBalance)
				return false;
		}

		return true;
	}


	/*----------------------------------------------------------*|
	|*  # CONFLICT RESOLUTION                                   *|
	|*----------------------------------------------------------*/

	/**
	 * @notice Frist step in recovering safe from invalid tokenized balance state.
	 * @dev Functions checks that state is really invalid and stores report, that is used in the second function.
	 *      Reason to divide recovery process into two transactions is to get rid of reentrancy exploits.
	 *      One could possible transfer tokenized assets from a safe and, before tokenized balance check can happen,
	 *      call recover function, that would recover the safe from that transitory invalid state
	 *      and tokenized balance check would pass, effectively bypassing transfer rights rules.
	 * @param atrTokenId Id of an ATR token that is causing the invalid tokenized balance state.
	 * @param owner Address of the safe, which holds the underlying asset of the ATR token.
	 *              Safe cannot call this function directly, because if in the insufficient tokenized balance state,
	 *              all execution calls would revert. That's why safe address needs to be passed as a parameter.
	 */
	function reportInvalidTokenizedBalance(uint256 atrTokenId, address owner) external {
		// Check if atr token is in owners safe
		// That would also check for non-existing ATR tokens
		require(tokenizedAssetsInSafe[owner].contains(atrTokenId), "Asset is not in owners safe");

		// Check if state is really invalid
		MultiToken.Asset memory asset = assets[atrTokenId];
		(, uint256 tokenizedBalance) = tokenizedBalances[owner][asset.assetAddress].tryGet(asset.id);
		require(asset.balanceOf(owner) < tokenizedBalance, "Tokenized balance is not invalid");

		// Store report
		invalidTokenizedBalanceReports[owner] = InvalidTokenizedBalanceReport(
			atrTokenId,
			block.number
		);
	}

	/**
	 * @notice Second and final step in recovering safe from invalid tokenized balance state.
	 * @dev Function expects that user called `reportInvalidTokenizedBalance` and that that transaction was included in some previous block.
	 *      At the end, it will recover safe from invalid tokenized balance caused by reported ATR token and mark that token as invalid.
	 *      Main reason for marking the token as invalid rather than burning it is to prevent other DeFi protocols
	 *      from unexpected behavior in case the ATR token is used in them.
	 */
	function recoverInvalidTokenizedBalance() external {
		address owner = msg.sender;
		InvalidTokenizedBalanceReport memory report = invalidTokenizedBalanceReports[owner];
		uint256 atrTokenId = report.atrTokenId;

		// Check that report exist
		require(report.block > 0, "No reported invalid tokenized balance");

		// Check that report was posted in different block than recover call
		require(report.block < block.number, "Report block number has to be smaller then current block number");

		// Decrease tokenized balance (would fail for invalid ATR token)
		MultiToken.Asset memory asset = assets[atrTokenId];
		require(_decreaseTokenizedBalance(atrTokenId, owner, asset), "Asset is not in callers safe");

		delete invalidTokenizedBalanceReports[owner];

		emit TransferViaATR(owner, address(0), atrTokenId, asset);

		// Mark atr token as invalid (tokens asset holder is lost)
		isInvalid[atrTokenId] = true;
	}


	/*----------------------------------------------------------*|
	|*  # VIEW                                                  *|
	|*----------------------------------------------------------*/

	/**
	 * @param atrTokenId ATR token id.
	 * @return Underlying asset of an ATR token.
	 */
	function getAsset(uint256 atrTokenId) external view returns (MultiToken.Asset memory) {
		return assets[atrTokenId];
	}

	/**
	 * @param owner PWNSafe address in question.
	 * @return List of tokenized assets owned by `owner` represented by their ATR tokens.
	 */
	function tokenizedAssetsInSafeOf(address owner) external view returns (uint256[] memory) {
		return tokenizedAssetsInSafe[owner].values();
	}

	/**
	 * @param owner PWNSafe address in question.
	 * @param assetAddress Address of asset collection.
	 * @return Number of tokenized assets owned by `owner` from asset collection.
	 */
	function numberOfTokenizedAssetsFromCollection(address owner, address assetAddress) external view returns (uint256) {
		return tokenizedBalances[owner][assetAddress].length();
	}


	/*----------------------------------------------------------*|
	|*  # INTERNAL                                              *|
	|*----------------------------------------------------------*/

	function _increaseTokenizedBalance(
		uint256 atrTokenId,
		address owner,
		MultiToken.Asset memory asset // Needs to be asset stored under given atrTokenId
	) internal {
		tokenizedAssetsInSafe[owner].add(atrTokenId);
		EnumerableMap.UintToUintMap storage map = tokenizedBalances[owner][asset.assetAddress];
		(, uint256 tokenizedBalance) = map.tryGet(asset.id);
		map.set(asset.id, tokenizedBalance + asset.getTransferAmount());
	}

	function _decreaseTokenizedBalance(
		uint256 atrTokenId,
		address owner,
		MultiToken.Asset memory asset // Needs to be asset stored under given atrTokenId
	) internal returns (bool) {
		if (tokenizedAssetsInSafe[owner].remove(atrTokenId) == false)
			return false;

		EnumerableMap.UintToUintMap storage map = tokenizedBalances[owner][asset.assetAddress];
		(, uint256 tokenizedBalance) = map.tryGet(asset.id);

		if (tokenizedBalance == asset.getTransferAmount()) {
			map.remove(asset.id);
		} else {
			map.set(asset.id, tokenizedBalance - asset.getTransferAmount());
		}

		return true;
	}

	function _canBeTokenized(
		address owner,
		MultiToken.Asset memory asset
	) internal view returns (bool) {
		uint256 balance = asset.balanceOf(owner);
		(, uint256 tokenizedBalance) = tokenizedBalances[owner][asset.assetAddress].tryGet(asset.id);
		return (balance - tokenizedBalance) >= asset.getTransferAmount();
	}

	function _storeTokenizedAsset(
		uint256 atrTokenId,
		MultiToken.Asset memory asset
	) internal {
		assets[atrTokenId] = asset;
	}

	function _clearTokenizedAsset(uint256 atrTokenId) internal {
		assets[atrTokenId] = MultiToken.Asset(MultiToken.Category.ERC20, address(0), 0, 0);
	}

}

Settings
{
  "remappings": [
    "@MT/=lib/MultiToken/src/",
    "@openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "@pwn-safe-test/=test/",
    "@pwn-safe/=src/",
    "@safe/=lib/safe-contracts/contracts/",
    "MultiToken/=lib/MultiToken/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "safe-contracts/=lib/safe-contracts/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_whitelist","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"permissionHash","type":"bytes32"}],"name":"RecipientPermissionGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"bytes32","name":"permissionNonce","type":"bytes32"}],"name":"RecipientPermissionNonceRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"atrTokenId","type":"uint256"},{"components":[{"internalType":"enum MultiToken.Category","name":"category","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"indexed":false,"internalType":"struct MultiToken.Asset","name":"asset","type":"tuple"}],"name":"TransferViaATR","type":"event"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"atrGuard","outputs":[{"internalType":"contract IAssetTransferRightsGuard","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"atrTokenId","type":"uint256"}],"name":"burnAssetTransferRightsToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"atrTokenIds","type":"uint256[]"}],"name":"burnAssetTransferRightsTokenBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"from","type":"address"},{"internalType":"uint256","name":"atrTokenId","type":"uint256"},{"internalType":"bool","name":"burnToken","type":"bool"}],"name":"claimAssetFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"atrTokenId","type":"uint256"}],"name":"getAsset","outputs":[{"components":[{"internalType":"enum MultiToken.Category","name":"category","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct MultiToken.Asset","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum MultiToken.Category","name":"assetCategory","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"assetId","type":"uint256"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"bool","name":"ignoreAssetIdAndAmount","type":"bool"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"uint40","name":"expiration","type":"uint40"},{"internalType":"bool","name":"isPersistent","type":"bool"},{"internalType":"bytes32","name":"nonce","type":"bytes32"}],"internalType":"struct RecipientPermissionManager.RecipientPermission","name":"permission","type":"tuple"}],"name":"grantRecipientPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"grantedPermissions","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"hasSufficientTokenizedBalance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_safeValidator","type":"address"},{"internalType":"address","name":"_atrGuard","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isInvalid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum MultiToken.Category","name":"category","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct MultiToken.Asset","name":"asset","type":"tuple"}],"name":"mintAssetTransferRightsToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"enum MultiToken.Category","name":"category","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct MultiToken.Asset[]","name":"assets","type":"tuple[]"}],"name":"mintAssetTransferRightsTokenBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"assetAddress","type":"address"}],"name":"numberOfTokenizedAssetsFromCollection","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum MultiToken.Category","name":"assetCategory","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"assetId","type":"uint256"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"bool","name":"ignoreAssetIdAndAmount","type":"bool"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"uint40","name":"expiration","type":"uint40"},{"internalType":"bool","name":"isPersistent","type":"bool"},{"internalType":"bytes32","name":"nonce","type":"bytes32"}],"internalType":"struct RecipientPermissionManager.RecipientPermission","name":"permission","type":"tuple"}],"name":"recipientPermissionHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"recoverInvalidTokenizedBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"atrTokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"reportInvalidTokenizedBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"permissionNonce","type":"bytes32"}],"name":"revokeRecipientPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"revokedPermissionNonces","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"safeValidator","outputs":[{"internalType":"contract IPWNSafeValidator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"metadataUri","type":"string"}],"name":"setMetadataUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"tokenizedAssetsInSafeOf","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"from","type":"address"},{"internalType":"uint256","name":"atrTokenId","type":"uint256"},{"internalType":"bool","name":"burnToken","type":"bool"},{"components":[{"internalType":"enum MultiToken.Category","name":"assetCategory","type":"uint8"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"assetId","type":"uint256"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"bool","name":"ignoreAssetIdAndAmount","type":"bool"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"uint40","name":"expiration","type":"uint40"},{"internalType":"bool","name":"isPersistent","type":"bool"},{"internalType":"bytes32","name":"nonce","type":"bytes32"}],"internalType":"struct RecipientPermissionManager.RecipientPermission","name":"permission","type":"tuple"},{"internalType":"bytes","name":"permissionSignature","type":"bytes"}],"name":"transferAssetFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"whitelist","outputs":[{"internalType":"contract Whitelist","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b50604051620050393803806200503983398101604081905262000034916200013b565b6040518060400160405280601581526020017f4173736574205472616e736665722052696768747300000000000000000000008152506040518060400160405280600381526020016220aa2960e91b815250620000a06200009a620000e760201b60201c565b620000eb565b6008620000ae838262000212565b506009620000bd828262000212565b5050601180546001600160a01b0319166001600160a01b03939093169290921790915550620002de565b3390565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156200014e57600080fd5b81516001600160a01b03811681146200016657600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200019857607f821691505b602082108103620001b957634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200020d57600081815260208120601f850160051c81016020861015620001e85750805b601f850160051c820191505b818110156200020957828155600101620001f4565b5050505b505050565b81516001600160401b038111156200022e576200022e6200016d565b62000246816200023f845462000183565b84620001bf565b602080601f8311600181146200027e5760008415620002655750858301515b600019600386901b1c1916600185901b17855562000209565b600085815260208120601f198616915b82811015620002af578886015182559484019460019091019084016200028e565b5085821015620002ce5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b614d4b80620002ee6000396000f3fe608060405234801561001057600080fd5b50600436106102535760003560e01c806391f3e9a711610146578063c7138bf0116100c3578063eac8f5b811610087578063eac8f5b81461057e578063f0028e601461059e578063f2fde38b146105b1578063f84ddf0b146105c4578063fe0ff63e146105cd578063ffa1ad74146105e057600080fd5b8063c7138bf0146104f4578063c87b56dd146104fc578063d4399f1c1461050f578063dcc7b6591461052f578063e985e9c51461054257600080fd5b8063a22cb4651161010a578063a22cb46514610485578063b7e2b09314610498578063b88d4fde146104ab578063c4177e0c146104be578063c6e705cd146104d157600080fd5b806391f3e9a71461043157806393e59dc114610444578063948f2a881461045757806395d89b411461046a5780639bdd8d311461047257600080fd5b806327fbd68d116101d45780636352211e116101985780636352211e146103b6578063636735b4146103c957806370a08231146103f7578063715018a6146104185780638da5cb5b1461042057600080fd5b806327fbd68d146103575780632a3818451461036a57806336682b4a1461037d57806342842e0e14610390578063485cc955146103a357600080fd5b80631130630c1161021b5780631130630c146102e857806315b4ec19146102fb578063215fdc811461030e57806323b872dd146103315780632475489f1461034457600080fd5b806301ffc9a71461025857806306fdde0314610280578063081812fc14610295578063095ea7b3146102c05780630e65f0fb146102d5575b600080fd5b61026b610266366004614100565b610604565b60405190151581526020015b60405180910390f35b610288610656565b6040516102779190614175565b6102a86102a3366004614188565b6106e8565b6040516001600160a01b039091168152602001610277565b6102d36102ce3660046141c1565b61070f565b005b6102d36102e3366004614320565b610829565b6102d36102f636600461444a565b6108d4565b6102d3610309366004614188565b6108ec565b61026b61031c366004614188565b60066020526000908152604090205460ff1681565b6102d361033f366004614493565b610977565b6010546102a8906001600160a01b031681565b6102d3610365366004614188565b6109a8565b6102d36103783660046144d4565b610c14565b6102d361038b366004614516565b610ca3565b6102d361039e366004614493565b610cdf565b6102d36103b136600461458b565b610cfa565b6102a86103c4366004614188565b610e4f565b61026b6103d73660046141c1565b600760209081526000928352604080842090915290825290205460ff1681565b61040a6104053660046145c4565b610eaf565b604051908152602001610277565b6102d3610f35565b6000546001600160a01b03166102a8565b61040a61043f36600461458b565b610f49565b6011546102a8906001600160a01b031681565b61040a6104653660046145e1565b610f80565b6102886114a6565b6102d3610480366004614654565b6114b5565b6102d3610493366004614679565b611666565b61026b6104a63660046145c4565b611671565b6102d36104b93660046146a7565b6117b9565b6102d36104cc366004614727565b6117eb565b61026b6104df366004614188565b60056020526000908152604090205460ff1681565b6102d3611832565b61028861050a366004614188565b611a60565b61052261051d3660046145c4565b611afd565b604051610277919061478a565b61040a61053d3660046147ce565b611b21565b61026b61055036600461458b565b6001600160a01b039182166000908152600d6020908152604080832093909416825291909152205460ff1690565b61059161058c366004614188565b611cbb565b6040516102779190614815565b600f546102a8906001600160a01b031681565b6102d36105bf3660046145c4565b611d54565b61040a600e5481565b6102d36105db366004614854565b611dcd565b610288604051806040016040528060058152602001640302e312e360dc1b81525081565b60006001600160e01b031982166380ac58cd60e01b148061063557506001600160e01b03198216635b5e139f60e01b145b8061065057506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600880546106659061486d565b80601f01602080910402602001604051908101604052809291908181526020018280546106919061486d565b80156106de5780601f106106b3576101008083540402835291602001916106de565b820191906000526020600020905b8154815290600101906020018083116106c157829003601f168201915b5050505050905090565b60006106f382611f42565b506000908152600c60205260409020546001600160a01b031690565b600061071a82610e4f565b9050806001600160a01b0316836001600160a01b03160361078c5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b03821614806107a857506107a88133610550565b61081a5760405162461bcd60e51b815260206004820152603e60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206e6f7220617070726f76656420666f7220616c6c00006064820152608401610783565b6108248383611fa1565b505050565b6000858152600160205260408082208151608081019092528054829060ff166003811115610859576108596147eb565b600381111561086a5761086a6147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015260a08501519091506108ad90829089908961200f565b6108ba33828686866121d2565b6108cb81888660a00151898961261e565b50505050505050565b6108dc612974565b60126108e882826148e7565b5050565b33600090815260076020908152604080832084845290915290205460ff16156109275760405162461bcd60e51b8152600401610783906149a7565b336000818152600760209081526040808320858452909152808220805460ff19166001179055518392917fdff79c9c1b2a91402d98aa8d3ee6169ada42a7011022c7517cddeb224f89dba891a350565b61098133826129ce565b61099d5760405162461bcd60e51b8152600401610783906149ec565b610824838383612a4d565b6000818152600160205260408082208151608081019092528054829060ff1660038111156109d8576109d86147eb565b60038111156109e9576109e96147eb565b815281546001600160a01b036101009091048116602080840191909152600184015460408401526002909301546060909201919091529082015191925016610a835760405162461bcd60e51b815260206004820152602760248201527f4173736574207472616e736665722072696768747320617265206e6f7420746f6044820152661ad95b9a5e995960ca1b6064820152608401610783565b33610a8d83610e4f565b6001600160a01b031614610ae35760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742041545220746f6b656e206f776e65720000006044820152606401610783565b60008281526005602052604081205460ff1615159003610c0257610b0681612bf8565b610b108233612c5b565b1015610b6f5760405162461bcd60e51b815260206004820152602860248201527f496e73756666696369656e742062616c616e6365206f66206120746f6b656e696044820152671e9948185cdcd95d60c21b6064820152608401610783565b610b7a823383612ea5565b610bc65760405162461bcd60e51b815260206004820181905260248201527f546f6b656e697a6564206173736574206973206e6f7420696e206120736166656044820152606401610783565b8160006001600160a01b0316336001600160a01b0316600080516020614cf683398151915284604051610bf99190614815565b60405180910390a45b610c0b82612f6b565b6108e882613002565b6000828152600160205260408082208151608081019092528054829060ff166003811115610c4457610c446147eb565b6003811115610c5557610c556147eb565b8152815461010090046001600160a01b03166020820152600182015460408201526002909101546060909101529050610c908185338661200f565b610c9d818533868661261e565b50505050565b60005b8181101561082457610ccf838383818110610cc357610cc3614a3a565b905060200201356109a8565b610cd881614a66565b9050610ca6565b610824838383604051806020016040528060008152506117b9565b600054600160a81b900460ff1615808015610d2257506000546001600160a01b90910460ff16105b80610d435750303b158015610d435750600054600160a01b900460ff166001145b610da65760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610783565b6000805460ff60a01b1916600160a01b1790558015610dd3576000805460ff60a81b1916600160a81b1790555b600f80546001600160a01b038086166001600160a01b03199283161790925560108054928516929091169190911790558015610824576000805460ff60a81b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050565b6000818152600a60205260408120546001600160a01b0316806106505760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610783565b60006001600160a01b038216610f195760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610783565b506001600160a01b03166000908152600b602052604090205490565b610f3d612974565b610f47600061309d565b565b6001600160a01b0380831660009081526003602090815260408083209385168352929052908120610f79906130ed565b9392505050565b600f546040516333d8aeb360e01b81523360048201526000916001600160a01b0316906333d8aeb390602401602060405180830381865afa158015610fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fed9190614a7f565b151560011461103e5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420612050574e536166650000000000000000006044820152606401610783565b306001600160a01b031682602001516001600160a01b0316036110a35760405162461bcd60e51b815260206004820181905260248201527f417474656d7074696e6720746f20746f6b656e697a652041545220746f6b656e6044820152606401610783565b6011546020830151604051633c4002b560e01b81526001600160a01b039182166004820152911690633c4002b590602401602060405180830381865afa1580156110f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111159190614a7f565b15156001146111665760405162461bcd60e51b815260206004820152601860248201527f4173736574206973206e6f742077686974656c697374656400000000000000006044820152606401610783565b60038251600381111561117b5761117b6147eb565b036111c85760405162461bcd60e51b815260206004820152601960248201527f496e76616c69642070726f76696465642063617465676f7279000000000000006044820152606401610783565b6111d1826130f8565b6112125760405162461bcd60e51b8152602060048201526012602482015271105cdcd95d081a5cc81b9bdd081d985b1a5960721b6044820152606401610783565b601054602083015160405163cbda439360e01b81523360048201526001600160a01b03918216602482015291169063cbda439390604401602060405180830381865afa158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a9190614a7f565b156112ea5760405162461bcd60e51b815260206004820152602a60248201527f536f6d652061737365742066726f6d20636f6c6c656374696f6e2068617320616044820152691b88185c1c1c9bdd985b60b21b6064820152608401610783565b6001825160038111156112ff576112ff6147eb565b036113d857600082602001516001600160a01b031663081812fc84604001516040518263ffffffff1660e01b815260040161133c91815260200190565b602060405180830381865afa158015611359573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137d9190614a9c565b90506001600160a01b038116156113d65760405162461bcd60e51b815260206004820152601d60248201527f41737365742068617320616e20617070726f76656420616464726573730000006044820152606401610783565b505b6113e23383613242565b61142e5760405162461bcd60e51b815260206004820181905260248201527f496e73756666696369656e742062616c616e636520746f20746f6b656e697a656044820152606401610783565b6000600e6000815461143f90614a66565b9182905550905061145081846132ae565b61145b813385613323565b61146533826133a6565b80336001600160a01b031660006001600160a01b0316600080516020614cf6833981519152866040516114989190614815565b60405180910390a492915050565b6060600980546106659061486d565b6001600160a01b03811660009081526002602052604090206114d790836134e8565b6115235760405162461bcd60e51b815260206004820152601b60248201527f4173736574206973206e6f7420696e206f776e657273207361666500000000006044820152606401610783565b6000828152600160205260408082208151608081019092528054829060ff166003811115611553576115536147eb565b6003811115611564576115646147eb565b815281546001600160a01b0361010090910481166020808401919091526001840154604080850191909152600290940154606090930192909252838301518682166000908152600384528481208685015190931681529190925291822092935090916115cf91613500565b91508190506115de8385612c5b565b1061162b5760405162461bcd60e51b815260206004820181905260248201527f546f6b656e697a65642062616c616e6365206973206e6f7420696e76616c69646044820152606401610783565b50506040805180820182529283524360208085019182526001600160a01b039093166000908152600490935291209151825551600190910155565b6108e833838361351e565b6001600160a01b03811660009081526002602052604081208190611694906135ec565b905060005b81518110156117af576000600160008484815181106116ba576116ba614a3a565b602002602001015181526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660038111156116ff576116ff6147eb565b6003811115611710576117106147eb565b815281546001600160a01b03610100909104811660208084019190915260018401546040808501919091526002909401546060909301929092528383015189821660009081526003845284812086850151909316815291909252918220929350909161177b91613500565b915081905061178a8388612c5b565b101561179c5750600095945050505050565b5050806117a890614a66565b9050611699565b5060019392505050565b6117c333836129ce565b6117df5760405162461bcd60e51b8152600401610783906149ec565b610c9d848484846135f9565b60005b818110156108245761182183838381811061180b5761180b614a3a565b90506080020180360381019061046591906145e1565b5061182b81614a66565b90506117ee565b3360008181526004602090815260409182902082518084019093528054808452600190910154918301829052906118b95760405162461bcd60e51b815260206004820152602560248201527f4e6f207265706f7274656420696e76616c696420746f6b656e697a65642062616044820152646c616e636560d81b6064820152608401610783565b438260200151106119325760405162461bcd60e51b815260206004820152603f60248201527f5265706f727420626c6f636b206e756d6265722068617320746f20626520736d60448201527f616c6c6572207468656e2063757272656e7420626c6f636b206e756d626572006064820152608401610783565b6000818152600160205260408082208151608081019092528054829060ff166003811115611962576119626147eb565b6003811115611973576119736147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015290506119ad828583612ea5565b6119f95760405162461bcd60e51b815260206004820152601c60248201527f4173736574206973206e6f7420696e2063616c6c6572732073616665000000006044820152606401610783565b6001600160a01b03841660008181526004602052604080822082815560010182905551849290600080516020614cf683398151915290611a3a908690614815565b60405180910390a4506000908152600560205260409020805460ff191660011790555050565b6060611a6b82611f42565b60128054611a789061486d565b80601f0160208091040260200160405190810160405280929190818152602001828054611aa49061486d565b8015611af15780601f10611ac657610100808354040283529160200191611af1565b820191906000526020600020905b815481529060010190602001808311611ad457829003601f168201915b50505050509050919050565b6001600160a01b0381166000908152600260205260409020606090610650906135ec565b604080518082018252601381527241737365745472616e7366657252696768747360681b602091820152815180830183526003815262302e3160e81b9082015281517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f918101919091527faa568c36dc4fb2872811520d34e84fca8452f32de983a83b7f380f9df81eb41b918101919091527f8cd160c72d102a6747abd189ac21d4a1f802e3fcc1bb8fc78cc4d558df0c7c2160608201524660808201523060a082015260009060c00160408051601f198184030181528282528051602091820120855186830151938701516060880151608089015160a08a015160e08b01516101008c01516101208d0151979a611c619a7f37216593d8f643b86b7e55224b9fd860779522b71b710bef6f1efb14b1ed48d19a98999098909101614ab9565b60405160208183030381529060405280519060200120604051602001611c9e92919061190160f01b81526002810192909252602282015260420190565b604051602081830303815290604052805190602001209050919050565b604080516080810182526000808252602082018190529181018290526060810191909152600082815260016020526040908190208151608081019092528054829060ff166003811115611d1057611d106147eb565b6003811115611d2157611d216147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015292915050565b611d5c612974565b6001600160a01b038116611dc15760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610783565b611dca8161309d565b50565b611ddd60c0820160a083016145c4565b6001600160a01b0316336001600160a01b031614611e485760405162461bcd60e51b815260206004820152602260248201527f53656e646572206973206e6f74207065726d697373696f6e20726563697069656044820152611b9d60f21b6064820152608401610783565b6000611e5c61053d368490038401846147ce565b60008181526006602052604090205490915060ff1615611ebe5760405162461bcd60e51b815260206004820152601f60248201527f526563697069656e74207065726d697373696f6e206973206772616e746564006044820152606401610783565b336000908152600760209081526040808320610120860135845290915290205460ff1615611efe5760405162461bcd60e51b8152600401610783906149a7565b600081815260066020526040808220805460ff191660011790555182917fefd1c7279e28658bb80fcef629dc73f9bccccb1a06fe0ea946adb211a193144291a25050565b6000818152600a60205260409020546001600160a01b0316611dca5760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610783565b6000818152600c6020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611fd682610e4f565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b816001600160a01b0316836001600160a01b0316036120895760405162461bcd60e51b815260206004820152603060248201527f417474656d7074696e6720746f207472616e7366657220617373657420746f2060448201526f7468652073616d65206164647265737360801b6064820152608401610783565b60208401516001600160a01b03166120ed5760405162461bcd60e51b815260206004820152602160248201527f5472616e736665722072696768747320617265206e6f7420746f6b656e697a656044820152601960fa1b6064820152608401610783565b336120f782610e4f565b6001600160a01b03161461214d5760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742041545220746f6b656e206f776e65720000006044820152606401610783565b60008181526005602052604090205460ff1615610c9d5760405162461bcd60e51b815260206004820152603f60248201527f41545220746f6b656e20697320696e76616c69642064756520746f207265636f60448201527f766572656420696e76616c696420746f6b656e697a65642062616c616e6365006064820152608401610783565b60e083015164ffffffffff811615806121f157508064ffffffffff1642105b61223d5760405162461bcd60e51b815260206004820152601f60248201527f526563697069656e74207065726d697373696f6e2069732065787069726564006044820152606401610783565b60c08401516001600160a01b03811615806122695750806001600160a01b0316876001600160a01b0316145b6122b55760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f74207065726d6974746564206167656e740000006044820152606401610783565b855160038111156122c8576122c86147eb565b855160038111156122db576122db6147eb565b146122f85760405162461bcd60e51b815260040161078390614b24565b85602001516001600160a01b031685602001516001600160a01b0316146123315760405162461bcd60e51b815260040161078390614b24565b6080850151151560000361238d5785604001518560400151146123665760405162461bcd60e51b815260040161078390614b24565b856060015185606001511461238d5760405162461bcd60e51b815260040161078390614b24565b60a08501516101208601516001600160a01b038216600090815260076020908152604080832084845290915290205460ff16156123dc5760405162461bcd60e51b8152600401610783906149a7565b60006123e788611b21565b60008181526006602052604090205490915060ff1615156001146125ac576001600160a01b0383163b156124f757604051630b135d3f60e11b808252906001600160a01b03851690631626ba7e906124479085908c908c90600401614b5b565b602060405180830381865afa158015612464573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124889190614b91565b6001600160e01b031916146124f25760405162461bcd60e51b815260206004820152602a60248201527f5369676e6174757265206f6e20626568616c66206f6620636f6e7472616374206044820152691a5cc81a5b9d985b1a5960b21b6064820152608401610783565b6125ac565b826001600160a01b03166125418289898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061362c92505050565b6001600160a01b0316146125ac5760405162461bcd60e51b815260206004820152602c60248201527f5065726d697373696f6e207369676e6572206973206e6f74207374617465642060448201526b185cc81c9958da5c1a595b9d60a21b6064820152608401610783565b6101008801511515600003612612576001600160a01b0383166000818152600760209081526040808320868452909152808220805460ff19166001179055518492917fdff79c9c1b2a91402d98aa8d3ee6169ada42a7011022c7517cddeb224f89dba891a35b50505050505050505050565b612629828587612ea5565b6126755760405162461bcd60e51b815260206004820152601d60248201527f4173736574206973206e6f7420696e20612074617267657420736166650000006044820152606401610783565b8015156001036126965761268882612f6b565b61269182613002565b612853565b600f546040516333d8aeb360e01b81526001600160a01b038581166004830152909116906333d8aeb390602401602060405180830381865afa1580156126e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127049190614a7f565b15156001146127715760405162461bcd60e51b815260206004820152603360248201527f417474656d7074696e6720746f207472616e7366657220617373657420746f206044820152726e6f6e2050574e53616665206164647265737360681b6064820152608401610783565b601054602086015160405163cbda439360e01b81526001600160a01b038681166004830152918216602482015291169063cbda439390604401602060405180830381865afa1580156127c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127eb9190614a7f565b156128485760405162461bcd60e51b815260206004820152602760248201527f52656365697665722068617320617070726f76616c732073657420666f7220616044820152661b88185cdcd95d60ca1b6064820152608401610783565b612853828487613323565b60208501516000906001600160a01b0386169063468721a7908361287a8a8a8a6001613650565b60006040518563ffffffff1660e01b815260040161289b9493929190614bae565b6020604051808303816000875af11580156128ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128de9190614a7f565b9050806129255760405162461bcd60e51b8152602060048201526015602482015274105cdcd95d081d1c985b9cd9995c8819985a5b1959605a1b6044820152606401610783565b82826129315784612934565b60005b6001600160a01b0316866001600160a01b0316600080516020614cf6833981519152896040516129649190614815565b60405180910390a4505050505050565b6000546001600160a01b03163314610f475760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610783565b6000806129da83610e4f565b9050806001600160a01b0316846001600160a01b03161480612a2157506001600160a01b038082166000908152600d602090815260408083209388168352929052205460ff165b80612a455750836001600160a01b0316612a3a846106e8565b6001600160a01b0316145b949350505050565b826001600160a01b0316612a6082610e4f565b6001600160a01b031614612ac45760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610783565b6001600160a01b038216612b265760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610783565b6000818152600c6020908152604080832080546001600160a01b03191690556001600160a01b0386168352600b9091528120805460019290612b69908490614bf6565b90915550506001600160a01b0382166000908152600b60205260408120805460019290612b97908490614c0d565b90915550506000818152600a602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60008082516003811115612c0e57612c0e6147eb565b03612c1b57506060015190565b600282516003811115612c3057612c306147eb565b148015612c41575060008260600151115b15612c4e57506060015190565b506001919050565b919050565b60008083516003811115612c7157612c716147eb565b03612cee5760208301516040516370a0823160e01b81526001600160a01b038481166004830152909116906370a08231906024015b602060405180830381865afa158015612cc3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce79190614c25565b9050610650565b600183516003811115612d0357612d036147eb565b03612dab57816001600160a01b031683602001516001600160a01b0316636352211e85604001516040518263ffffffff1660e01b8152600401612d4891815260200190565b602060405180830381865afa158015612d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d899190614a9c565b6001600160a01b031614612d9e576000612da1565b60015b60ff169050610650565b600283516003811115612dc057612dc06147eb565b03612e035760208301516040808501519051627eeac760e11b81526001600160a01b038581166004830152602482019290925291169062fdd58e90604401612ca6565b600383516003811115612e1857612e186147eb565b03612e5d57816001600160a01b031683602001516001600160a01b0316636352211e85604001516040518263ffffffff1660e01b8152600401612d4891815260200190565b60405162461bcd60e51b815260206004820181905260248201527f4d756c7469546f6b656e3a20556e737570706f727465642063617465676f72796044820152606401610783565b6001600160a01b0382166000908152600260205260408120612ec79085613669565b1515600003612ed857506000610f79565b6001600160a01b03808416600090815260036020908152604080832086830151909416835292905281812091840151612f12908390613500565b915050612f1e84612bf8565b8103612f3a576040840151612f34908390613675565b50612f5f565b612f5d8460400151612f4b86612bf8565b612f559084614bf6565b849190613681565b505b50600195945050505050565b60408051608081018252600080825260208083018290528284018290526060830182905284825260019081905292902081518154929391929091839160ff191690836003811115612fbe57612fbe6147eb565b0217905550602082015181546001600160a01b0390911661010002610100600160a81b03199091161781556040820151600182015560609091015160029091015550565b600061300d82610e4f565b905061301a600083611fa1565b6001600160a01b0381166000908152600b60205260408120805460019290613043908490614bf6565b90915550506000828152600a602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006106508261368e565b6000808251600381111561310e5761310e6147eb565b036131735760408201511561312557506000919050565b61313b82602001516001600160a01b0316613699565b1561315f576020820151610650906001600160a01b03166336372b0760e01b6136cc565b50602001516001600160a01b03163b151590565b600182516003811115613188576131886147eb565b036131be5760608201511561319f57506000919050565b6020820151610650906001600160a01b03166380ac58cd60e01b6137b5565b6002825160038111156131d3576131d36147eb565b036131f7576020820151610650906001600160a01b0316636cdb3d1360e11b6137b5565b60038251600381111561320c5761320c6147eb565b03612e5d5760608201511561322357506000919050565b6020820151610650906001600160a01b0316639a20483d60e01b6137b5565b60008061324f8385612c5b565b6040808501516001600160a01b03808816600090815260036020908152848220818a0151909316825291909152918220929350909161328d91613500565b91505061329984612bf8565b6132a38284614bf6565b101595945050505050565b6000828152600160208190526040909120825181548493839160ff1916908360038111156132de576132de6147eb565b0217905550602082015181546001600160a01b0390911661010002610100600160a81b0319909116178155604082015160018201556060909101516002909101555050565b6001600160a01b038216600090815260026020526040902061334590846137d1565b506001600160a01b03808316600090815260036020908152604080832085830151909416835292905281812091830151613380908390613500565b91505061339e836040015161339485612bf8565b612f559084614c0d565b505050505050565b6001600160a01b0382166133fc5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610783565b6000818152600a60205260409020546001600160a01b0316156134615760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610783565b6001600160a01b0382166000908152600b6020526040812080546001929061348a908490614c0d565b90915550506000818152600a602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60008181526001830160205260408120541515610f79565b600080808061350f86866137dd565b909450925050505b9250929050565b816001600160a01b0316836001600160a01b03160361357f5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610783565b6001600160a01b038381166000818152600d6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60606000610f7983613817565b613604848484612a4d565b61361084848484613872565b610c9d5760405162461bcd60e51b815260040161078390614c3e565b600080600061363b8585613970565b91509150613648816139db565b509392505050565b6060613660858585856000613b91565b95945050505050565b6000610f798383613e32565b6000610f798383613f25565b6000612a45848484613f42565b600061065082613f5f565b60006136ac826301ffc9a760e01b6136cc565b801561065057506136c5826001600160e01b03196136cc565b1592915050565b604080516001600160e01b0319831660248083019190915282518083039091018152604490910182526020810180516001600160e01b03166301ffc9a760e01b179052905160009190829081906001600160a01b0387169061753090613733908690614c90565b6000604051808303818686fa925050503d806000811461376f576040519150601f19603f3d011682016040523d82523d6000602084013e613774565b606091505b509150915060208151101561378f5760009350505050610650565b8180156137ab5750808060200190518101906137ab9190614a7f565b9695505050505050565b60006137c083613699565b8015610f795750610f7983836136cc565b6000610f798383613f69565b600081815260028301602052604081205481908061380c576137ff8585613fb8565b9250600091506135179050565b600192509050613517565b606081600001805480602002602001604051908101604052809291908181526020018280548015611af157602002820191906000526020600020905b8154815260200190600101908083116138535750505050509050919050565b60006001600160a01b0384163b1561396857604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906138b6903390899088908890600401614cac565b6020604051808303816000875af19250505080156138f1575060408051601f3d908101601f191682019092526138ee91810190614b91565b60015b61394e573d80801561391f576040519150601f19603f3d011682016040523d82523d6000602084013e613924565b606091505b5080516000036139465760405162461bcd60e51b815260040161078390614c3e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050612a45565b506001612a45565b60008082516041036139a65760208301516040840151606085015160001a61399a87828585613fc4565b94509450505050613517565b82516040036139cf57602083015160408401516139c48683836140b1565b935093505050613517565b50600090506002613517565b60008160048111156139ef576139ef6147eb565b036139f75750565b6001816004811115613a0b57613a0b6147eb565b03613a585760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610783565b6002816004811115613a6c57613a6c6147eb565b03613ab95760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610783565b6003816004811115613acd57613acd6147eb565b03613b255760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610783565b6004816004811115613b3957613b396147eb565b03611dca5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610783565b6060600086516003811115613ba857613ba86147eb565b03613c63578215613c075760608601516040516001600160a01b038616602482015260448101919091526064015b60408051601f198184030181529190526020810180516001600160e01b031663a9059cbb60e01b1790529050613660565b60608601516040516001600160a01b0380881660248301528616604482015260648101919091526084015b60408051601f198184030181529190526020810180516001600160e01b03166323b872dd60e01b1790529050613660565b600186516003811115613c7857613c786147eb565b03613d1a5781613cb15760408087015190516001600160a01b038088166024830152861660448201526064810191909152608401613c32565b60408087015190516001600160a01b03808816602483015286166044820152606481019190915260806084820152600060a482015260c40160408051601f198184030181529190526020810180516001600160e01b0316635c46a7ef60e11b1790529050613660565b600286516003811115613d2f57613d2f6147eb565b03613dbc57848487604001518860600151600014613d51578860600151613d54565b60015b6040516001600160a01b0394851660248201529390921660448401526064830152608482015260a060a4820152600060c482015260e40160408051601f198184030181529190526020810180516001600160e01b0316637921219560e11b1790529050613660565b600386516003811115613dd157613dd16147eb565b03612e5d578215613e035760408087015190516001600160a01b03861660248201526044810191909152606401613bd6565b60408087015190516001600160a01b038088166024830152861660448201526064810191909152608401613c32565b60008181526001830160205260408120548015613f1b576000613e56600183614bf6565b8554909150600090613e6a90600190614bf6565b9050818114613ecf576000866000018281548110613e8a57613e8a614a3a565b9060005260206000200154905080876000018481548110613ead57613ead614a3a565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613ee057613ee0614cdf565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610650565b6000915050610650565b60008181526002830160205260408120819055610f798383613669565b60008281526002840160205260408120829055612a4584846137d1565b6000610650825490565b6000818152600183016020526040812054613fb057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610650565b506000610650565b6000610f7983836134e8565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115613ffb57506000905060036140a8565b8460ff16601b1415801561401357508460ff16601c14155b1561402457506000905060046140a8565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614078573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166140a1576000600192509250506140a8565b9150600090505b94509492505050565b6000806001600160ff1b038316816140ce60ff86901c601b614c0d565b90506140dc87828885613fc4565b935093505050935093915050565b6001600160e01b031981168114611dca57600080fd5b60006020828403121561411257600080fd5b8135610f79816140ea565b60005b83811015614138578181015183820152602001614120565b83811115610c9d5750506000910152565b6000815180845261416181602086016020860161411d565b601f01601f19169290920160200192915050565b602081526000610f796020830184614149565b60006020828403121561419a57600080fd5b5035919050565b6001600160a01b0381168114611dca57600080fd5b8035612c56816141a1565b600080604083850312156141d457600080fd5b82356141df816141a1565b946020939093013593505050565b8015158114611dca57600080fd5b8035612c56816141ed565b634e487b7160e01b600052604160045260246000fd5b604051610140810167ffffffffffffffff8111828210171561424057614240614206565b60405290565b803560048110612c5657600080fd5b803564ffffffffff81168114612c5657600080fd5b6000610140828403121561427d57600080fd5b61428561421c565b905061429082614246565b815261429e602083016141b6565b602082015260408201356040820152606082013560608201526142c3608083016141fb565b60808201526142d460a083016141b6565b60a08201526142e560c083016141b6565b60c08201526142f660e08301614255565b60e08201526101006143098184016141fb565b818301525061012080830135818301525092915050565b6000806000806000806101c0878903121561433a57600080fd5b8635614345816141a1565b955060208701359450604087013561435c816141ed565b935061436b886060890161426a565b92506101a087013567ffffffffffffffff8082111561438957600080fd5b818901915089601f83011261439d57600080fd5b8135818111156143ac57600080fd5b8a60208285010111156143be57600080fd5b6020830194508093505050509295509295509295565b600067ffffffffffffffff808411156143ef576143ef614206565b604051601f8501601f19908116603f0116810190828211818310171561441757614417614206565b8160405280935085815286868601111561443057600080fd5b858560208301376000602087830101525050509392505050565b60006020828403121561445c57600080fd5b813567ffffffffffffffff81111561447357600080fd5b8201601f8101841361448457600080fd5b612a45848235602084016143d4565b6000806000606084860312156144a857600080fd5b83356144b3816141a1565b925060208401356144c3816141a1565b929592945050506040919091013590565b6000806000606084860312156144e957600080fd5b83356144f4816141a1565b925060208401359150604084013561450b816141ed565b809150509250925092565b6000806020838503121561452957600080fd5b823567ffffffffffffffff8082111561454157600080fd5b818501915085601f83011261455557600080fd5b81358181111561456457600080fd5b8660208260051b850101111561457957600080fd5b60209290920196919550909350505050565b6000806040838503121561459e57600080fd5b82356145a9816141a1565b915060208301356145b9816141a1565b809150509250929050565b6000602082840312156145d657600080fd5b8135610f79816141a1565b6000608082840312156145f357600080fd5b6040516080810181811067ffffffffffffffff8211171561461657614616614206565b60405261462283614246565b81526020830135614632816141a1565b6020820152604083810135908201526060928301359281019290925250919050565b6000806040838503121561466757600080fd5b8235915060208301356145b9816141a1565b6000806040838503121561468c57600080fd5b8235614697816141a1565b915060208301356145b9816141ed565b600080600080608085870312156146bd57600080fd5b84356146c8816141a1565b935060208501356146d8816141a1565b925060408501359150606085013567ffffffffffffffff8111156146fb57600080fd5b8501601f8101871361470c57600080fd5b61471b878235602084016143d4565b91505092959194509250565b6000806020838503121561473a57600080fd5b823567ffffffffffffffff8082111561475257600080fd5b818501915085601f83011261476657600080fd5b81358181111561477557600080fd5b8660208260071b850101111561457957600080fd5b6020808252825182820181905260009190848201906040850190845b818110156147c2578351835292840192918401916001016147a6565b50909695505050505050565b600061014082840312156147e157600080fd5b610f79838361426a565b634e487b7160e01b600052602160045260246000fd5b60048110614811576148116147eb565b9052565b6000608082019050614828828451614801565b60018060a01b036020840151166020830152604083015160408301526060830151606083015292915050565b6000610140828403121561486757600080fd5b50919050565b600181811c9082168061488157607f821691505b60208210810361486757634e487b7160e01b600052602260045260246000fd5b601f82111561082457600081815260208120601f850160051c810160208610156148c85750805b601f850160051c820191505b8181101561339e578281556001016148d4565b815167ffffffffffffffff81111561490157614901614206565b6149158161490f845461486d565b846148a1565b602080601f83116001811461494a57600084156149325750858301515b600019600386901b1c1916600185901b17855561339e565b600085815260208120601f198616915b828110156149795788860151825594840194600190910190840161495a565b50858210156149975787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60208082526025908201527f526563697069656e74207065726d697373696f6e206e6f6e63652069732072656040820152641d9bdad95960da1b606082015260800190565b6020808252602e908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526d1c881b9bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201614a7857614a78614a50565b5060010190565b600060208284031215614a9157600080fd5b8151610f79816141ed565b600060208284031215614aae57600080fd5b8151610f79816141a1565b8a81526101408101614ace602083018c614801565b6001600160a01b03998a1660408301526060820198909852608081019690965293151560a08601529190951660c084015264ffffffffff90941660e0830152921515610100820152610120019190915292915050565b60208082526017908201527f496e76616c6964207065726d6974746564206173736574000000000000000000604082015260600190565b83815260406020820152816040820152818360608301376000818301606090810191909152601f909201601f1916010192915050565b600060208284031215614ba357600080fd5b8151610f79816140ea565b60018060a01b0385168152836020820152608060408201526000614bd56080830185614149565b905060028310614be757614be76147eb565b82606083015295945050505050565b600082821015614c0857614c08614a50565b500390565b60008219821115614c2057614c20614a50565b500190565b600060208284031215614c3757600080fd5b5051919050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60008251614ca281846020870161411d565b9190910192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906137ab90830184614149565b634e487b7160e01b600052603160045260246000fdfe31a70554f8f78c839c1e767c22805a185303216df6011aa8c0ac32d7c7190f84a2646970667358221220e3db44d58c707f1bf059110508c9259f0d7ff917a8b16ad152a02d345c51b73c64736f6c634300080f003300000000000000000000000079ec459c3ba4c64f00353cabf5fa179e059e2e1e

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102535760003560e01c806391f3e9a711610146578063c7138bf0116100c3578063eac8f5b811610087578063eac8f5b81461057e578063f0028e601461059e578063f2fde38b146105b1578063f84ddf0b146105c4578063fe0ff63e146105cd578063ffa1ad74146105e057600080fd5b8063c7138bf0146104f4578063c87b56dd146104fc578063d4399f1c1461050f578063dcc7b6591461052f578063e985e9c51461054257600080fd5b8063a22cb4651161010a578063a22cb46514610485578063b7e2b09314610498578063b88d4fde146104ab578063c4177e0c146104be578063c6e705cd146104d157600080fd5b806391f3e9a71461043157806393e59dc114610444578063948f2a881461045757806395d89b411461046a5780639bdd8d311461047257600080fd5b806327fbd68d116101d45780636352211e116101985780636352211e146103b6578063636735b4146103c957806370a08231146103f7578063715018a6146104185780638da5cb5b1461042057600080fd5b806327fbd68d146103575780632a3818451461036a57806336682b4a1461037d57806342842e0e14610390578063485cc955146103a357600080fd5b80631130630c1161021b5780631130630c146102e857806315b4ec19146102fb578063215fdc811461030e57806323b872dd146103315780632475489f1461034457600080fd5b806301ffc9a71461025857806306fdde0314610280578063081812fc14610295578063095ea7b3146102c05780630e65f0fb146102d5575b600080fd5b61026b610266366004614100565b610604565b60405190151581526020015b60405180910390f35b610288610656565b6040516102779190614175565b6102a86102a3366004614188565b6106e8565b6040516001600160a01b039091168152602001610277565b6102d36102ce3660046141c1565b61070f565b005b6102d36102e3366004614320565b610829565b6102d36102f636600461444a565b6108d4565b6102d3610309366004614188565b6108ec565b61026b61031c366004614188565b60066020526000908152604090205460ff1681565b6102d361033f366004614493565b610977565b6010546102a8906001600160a01b031681565b6102d3610365366004614188565b6109a8565b6102d36103783660046144d4565b610c14565b6102d361038b366004614516565b610ca3565b6102d361039e366004614493565b610cdf565b6102d36103b136600461458b565b610cfa565b6102a86103c4366004614188565b610e4f565b61026b6103d73660046141c1565b600760209081526000928352604080842090915290825290205460ff1681565b61040a6104053660046145c4565b610eaf565b604051908152602001610277565b6102d3610f35565b6000546001600160a01b03166102a8565b61040a61043f36600461458b565b610f49565b6011546102a8906001600160a01b031681565b61040a6104653660046145e1565b610f80565b6102886114a6565b6102d3610480366004614654565b6114b5565b6102d3610493366004614679565b611666565b61026b6104a63660046145c4565b611671565b6102d36104b93660046146a7565b6117b9565b6102d36104cc366004614727565b6117eb565b61026b6104df366004614188565b60056020526000908152604090205460ff1681565b6102d3611832565b61028861050a366004614188565b611a60565b61052261051d3660046145c4565b611afd565b604051610277919061478a565b61040a61053d3660046147ce565b611b21565b61026b61055036600461458b565b6001600160a01b039182166000908152600d6020908152604080832093909416825291909152205460ff1690565b61059161058c366004614188565b611cbb565b6040516102779190614815565b600f546102a8906001600160a01b031681565b6102d36105bf3660046145c4565b611d54565b61040a600e5481565b6102d36105db366004614854565b611dcd565b610288604051806040016040528060058152602001640302e312e360dc1b81525081565b60006001600160e01b031982166380ac58cd60e01b148061063557506001600160e01b03198216635b5e139f60e01b145b8061065057506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600880546106659061486d565b80601f01602080910402602001604051908101604052809291908181526020018280546106919061486d565b80156106de5780601f106106b3576101008083540402835291602001916106de565b820191906000526020600020905b8154815290600101906020018083116106c157829003601f168201915b5050505050905090565b60006106f382611f42565b506000908152600c60205260409020546001600160a01b031690565b600061071a82610e4f565b9050806001600160a01b0316836001600160a01b03160361078c5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b03821614806107a857506107a88133610550565b61081a5760405162461bcd60e51b815260206004820152603e60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206e6f7220617070726f76656420666f7220616c6c00006064820152608401610783565b6108248383611fa1565b505050565b6000858152600160205260408082208151608081019092528054829060ff166003811115610859576108596147eb565b600381111561086a5761086a6147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015260a08501519091506108ad90829089908961200f565b6108ba33828686866121d2565b6108cb81888660a00151898961261e565b50505050505050565b6108dc612974565b60126108e882826148e7565b5050565b33600090815260076020908152604080832084845290915290205460ff16156109275760405162461bcd60e51b8152600401610783906149a7565b336000818152600760209081526040808320858452909152808220805460ff19166001179055518392917fdff79c9c1b2a91402d98aa8d3ee6169ada42a7011022c7517cddeb224f89dba891a350565b61098133826129ce565b61099d5760405162461bcd60e51b8152600401610783906149ec565b610824838383612a4d565b6000818152600160205260408082208151608081019092528054829060ff1660038111156109d8576109d86147eb565b60038111156109e9576109e96147eb565b815281546001600160a01b036101009091048116602080840191909152600184015460408401526002909301546060909201919091529082015191925016610a835760405162461bcd60e51b815260206004820152602760248201527f4173736574207472616e736665722072696768747320617265206e6f7420746f6044820152661ad95b9a5e995960ca1b6064820152608401610783565b33610a8d83610e4f565b6001600160a01b031614610ae35760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742041545220746f6b656e206f776e65720000006044820152606401610783565b60008281526005602052604081205460ff1615159003610c0257610b0681612bf8565b610b108233612c5b565b1015610b6f5760405162461bcd60e51b815260206004820152602860248201527f496e73756666696369656e742062616c616e6365206f66206120746f6b656e696044820152671e9948185cdcd95d60c21b6064820152608401610783565b610b7a823383612ea5565b610bc65760405162461bcd60e51b815260206004820181905260248201527f546f6b656e697a6564206173736574206973206e6f7420696e206120736166656044820152606401610783565b8160006001600160a01b0316336001600160a01b0316600080516020614cf683398151915284604051610bf99190614815565b60405180910390a45b610c0b82612f6b565b6108e882613002565b6000828152600160205260408082208151608081019092528054829060ff166003811115610c4457610c446147eb565b6003811115610c5557610c556147eb565b8152815461010090046001600160a01b03166020820152600182015460408201526002909101546060909101529050610c908185338661200f565b610c9d818533868661261e565b50505050565b60005b8181101561082457610ccf838383818110610cc357610cc3614a3a565b905060200201356109a8565b610cd881614a66565b9050610ca6565b610824838383604051806020016040528060008152506117b9565b600054600160a81b900460ff1615808015610d2257506000546001600160a01b90910460ff16105b80610d435750303b158015610d435750600054600160a01b900460ff166001145b610da65760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610783565b6000805460ff60a01b1916600160a01b1790558015610dd3576000805460ff60a81b1916600160a81b1790555b600f80546001600160a01b038086166001600160a01b03199283161790925560108054928516929091169190911790558015610824576000805460ff60a81b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050565b6000818152600a60205260408120546001600160a01b0316806106505760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610783565b60006001600160a01b038216610f195760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610783565b506001600160a01b03166000908152600b602052604090205490565b610f3d612974565b610f47600061309d565b565b6001600160a01b0380831660009081526003602090815260408083209385168352929052908120610f79906130ed565b9392505050565b600f546040516333d8aeb360e01b81523360048201526000916001600160a01b0316906333d8aeb390602401602060405180830381865afa158015610fc9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fed9190614a7f565b151560011461103e5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420612050574e536166650000000000000000006044820152606401610783565b306001600160a01b031682602001516001600160a01b0316036110a35760405162461bcd60e51b815260206004820181905260248201527f417474656d7074696e6720746f20746f6b656e697a652041545220746f6b656e6044820152606401610783565b6011546020830151604051633c4002b560e01b81526001600160a01b039182166004820152911690633c4002b590602401602060405180830381865afa1580156110f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111159190614a7f565b15156001146111665760405162461bcd60e51b815260206004820152601860248201527f4173736574206973206e6f742077686974656c697374656400000000000000006044820152606401610783565b60038251600381111561117b5761117b6147eb565b036111c85760405162461bcd60e51b815260206004820152601960248201527f496e76616c69642070726f76696465642063617465676f7279000000000000006044820152606401610783565b6111d1826130f8565b6112125760405162461bcd60e51b8152602060048201526012602482015271105cdcd95d081a5cc81b9bdd081d985b1a5960721b6044820152606401610783565b601054602083015160405163cbda439360e01b81523360048201526001600160a01b03918216602482015291169063cbda439390604401602060405180830381865afa158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a9190614a7f565b156112ea5760405162461bcd60e51b815260206004820152602a60248201527f536f6d652061737365742066726f6d20636f6c6c656374696f6e2068617320616044820152691b88185c1c1c9bdd985b60b21b6064820152608401610783565b6001825160038111156112ff576112ff6147eb565b036113d857600082602001516001600160a01b031663081812fc84604001516040518263ffffffff1660e01b815260040161133c91815260200190565b602060405180830381865afa158015611359573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137d9190614a9c565b90506001600160a01b038116156113d65760405162461bcd60e51b815260206004820152601d60248201527f41737365742068617320616e20617070726f76656420616464726573730000006044820152606401610783565b505b6113e23383613242565b61142e5760405162461bcd60e51b815260206004820181905260248201527f496e73756666696369656e742062616c616e636520746f20746f6b656e697a656044820152606401610783565b6000600e6000815461143f90614a66565b9182905550905061145081846132ae565b61145b813385613323565b61146533826133a6565b80336001600160a01b031660006001600160a01b0316600080516020614cf6833981519152866040516114989190614815565b60405180910390a492915050565b6060600980546106659061486d565b6001600160a01b03811660009081526002602052604090206114d790836134e8565b6115235760405162461bcd60e51b815260206004820152601b60248201527f4173736574206973206e6f7420696e206f776e657273207361666500000000006044820152606401610783565b6000828152600160205260408082208151608081019092528054829060ff166003811115611553576115536147eb565b6003811115611564576115646147eb565b815281546001600160a01b0361010090910481166020808401919091526001840154604080850191909152600290940154606090930192909252838301518682166000908152600384528481208685015190931681529190925291822092935090916115cf91613500565b91508190506115de8385612c5b565b1061162b5760405162461bcd60e51b815260206004820181905260248201527f546f6b656e697a65642062616c616e6365206973206e6f7420696e76616c69646044820152606401610783565b50506040805180820182529283524360208085019182526001600160a01b039093166000908152600490935291209151825551600190910155565b6108e833838361351e565b6001600160a01b03811660009081526002602052604081208190611694906135ec565b905060005b81518110156117af576000600160008484815181106116ba576116ba614a3a565b602002602001015181526020019081526020016000206040518060800160405290816000820160009054906101000a900460ff1660038111156116ff576116ff6147eb565b6003811115611710576117106147eb565b815281546001600160a01b03610100909104811660208084019190915260018401546040808501919091526002909401546060909301929092528383015189821660009081526003845284812086850151909316815291909252918220929350909161177b91613500565b915081905061178a8388612c5b565b101561179c5750600095945050505050565b5050806117a890614a66565b9050611699565b5060019392505050565b6117c333836129ce565b6117df5760405162461bcd60e51b8152600401610783906149ec565b610c9d848484846135f9565b60005b818110156108245761182183838381811061180b5761180b614a3a565b90506080020180360381019061046591906145e1565b5061182b81614a66565b90506117ee565b3360008181526004602090815260409182902082518084019093528054808452600190910154918301829052906118b95760405162461bcd60e51b815260206004820152602560248201527f4e6f207265706f7274656420696e76616c696420746f6b656e697a65642062616044820152646c616e636560d81b6064820152608401610783565b438260200151106119325760405162461bcd60e51b815260206004820152603f60248201527f5265706f727420626c6f636b206e756d6265722068617320746f20626520736d60448201527f616c6c6572207468656e2063757272656e7420626c6f636b206e756d626572006064820152608401610783565b6000818152600160205260408082208151608081019092528054829060ff166003811115611962576119626147eb565b6003811115611973576119736147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015290506119ad828583612ea5565b6119f95760405162461bcd60e51b815260206004820152601c60248201527f4173736574206973206e6f7420696e2063616c6c6572732073616665000000006044820152606401610783565b6001600160a01b03841660008181526004602052604080822082815560010182905551849290600080516020614cf683398151915290611a3a908690614815565b60405180910390a4506000908152600560205260409020805460ff191660011790555050565b6060611a6b82611f42565b60128054611a789061486d565b80601f0160208091040260200160405190810160405280929190818152602001828054611aa49061486d565b8015611af15780601f10611ac657610100808354040283529160200191611af1565b820191906000526020600020905b815481529060010190602001808311611ad457829003601f168201915b50505050509050919050565b6001600160a01b0381166000908152600260205260409020606090610650906135ec565b604080518082018252601381527241737365745472616e7366657252696768747360681b602091820152815180830183526003815262302e3160e81b9082015281517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f918101919091527faa568c36dc4fb2872811520d34e84fca8452f32de983a83b7f380f9df81eb41b918101919091527f8cd160c72d102a6747abd189ac21d4a1f802e3fcc1bb8fc78cc4d558df0c7c2160608201524660808201523060a082015260009060c00160408051601f198184030181528282528051602091820120855186830151938701516060880151608089015160a08a015160e08b01516101008c01516101208d0151979a611c619a7f37216593d8f643b86b7e55224b9fd860779522b71b710bef6f1efb14b1ed48d19a98999098909101614ab9565b60405160208183030381529060405280519060200120604051602001611c9e92919061190160f01b81526002810192909252602282015260420190565b604051602081830303815290604052805190602001209050919050565b604080516080810182526000808252602082018190529181018290526060810191909152600082815260016020526040908190208151608081019092528054829060ff166003811115611d1057611d106147eb565b6003811115611d2157611d216147eb565b8152815461010090046001600160a01b031660208201526001820154604082015260029091015460609091015292915050565b611d5c612974565b6001600160a01b038116611dc15760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610783565b611dca8161309d565b50565b611ddd60c0820160a083016145c4565b6001600160a01b0316336001600160a01b031614611e485760405162461bcd60e51b815260206004820152602260248201527f53656e646572206973206e6f74207065726d697373696f6e20726563697069656044820152611b9d60f21b6064820152608401610783565b6000611e5c61053d368490038401846147ce565b60008181526006602052604090205490915060ff1615611ebe5760405162461bcd60e51b815260206004820152601f60248201527f526563697069656e74207065726d697373696f6e206973206772616e746564006044820152606401610783565b336000908152600760209081526040808320610120860135845290915290205460ff1615611efe5760405162461bcd60e51b8152600401610783906149a7565b600081815260066020526040808220805460ff191660011790555182917fefd1c7279e28658bb80fcef629dc73f9bccccb1a06fe0ea946adb211a193144291a25050565b6000818152600a60205260409020546001600160a01b0316611dca5760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b6044820152606401610783565b6000818152600c6020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611fd682610e4f565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b816001600160a01b0316836001600160a01b0316036120895760405162461bcd60e51b815260206004820152603060248201527f417474656d7074696e6720746f207472616e7366657220617373657420746f2060448201526f7468652073616d65206164647265737360801b6064820152608401610783565b60208401516001600160a01b03166120ed5760405162461bcd60e51b815260206004820152602160248201527f5472616e736665722072696768747320617265206e6f7420746f6b656e697a656044820152601960fa1b6064820152608401610783565b336120f782610e4f565b6001600160a01b03161461214d5760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f742041545220746f6b656e206f776e65720000006044820152606401610783565b60008181526005602052604090205460ff1615610c9d5760405162461bcd60e51b815260206004820152603f60248201527f41545220746f6b656e20697320696e76616c69642064756520746f207265636f60448201527f766572656420696e76616c696420746f6b656e697a65642062616c616e6365006064820152608401610783565b60e083015164ffffffffff811615806121f157508064ffffffffff1642105b61223d5760405162461bcd60e51b815260206004820152601f60248201527f526563697069656e74207065726d697373696f6e2069732065787069726564006044820152606401610783565b60c08401516001600160a01b03811615806122695750806001600160a01b0316876001600160a01b0316145b6122b55760405162461bcd60e51b815260206004820152601d60248201527f43616c6c6572206973206e6f74207065726d6974746564206167656e740000006044820152606401610783565b855160038111156122c8576122c86147eb565b855160038111156122db576122db6147eb565b146122f85760405162461bcd60e51b815260040161078390614b24565b85602001516001600160a01b031685602001516001600160a01b0316146123315760405162461bcd60e51b815260040161078390614b24565b6080850151151560000361238d5785604001518560400151146123665760405162461bcd60e51b815260040161078390614b24565b856060015185606001511461238d5760405162461bcd60e51b815260040161078390614b24565b60a08501516101208601516001600160a01b038216600090815260076020908152604080832084845290915290205460ff16156123dc5760405162461bcd60e51b8152600401610783906149a7565b60006123e788611b21565b60008181526006602052604090205490915060ff1615156001146125ac576001600160a01b0383163b156124f757604051630b135d3f60e11b808252906001600160a01b03851690631626ba7e906124479085908c908c90600401614b5b565b602060405180830381865afa158015612464573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124889190614b91565b6001600160e01b031916146124f25760405162461bcd60e51b815260206004820152602a60248201527f5369676e6174757265206f6e20626568616c66206f6620636f6e7472616374206044820152691a5cc81a5b9d985b1a5960b21b6064820152608401610783565b6125ac565b826001600160a01b03166125418289898080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061362c92505050565b6001600160a01b0316146125ac5760405162461bcd60e51b815260206004820152602c60248201527f5065726d697373696f6e207369676e6572206973206e6f74207374617465642060448201526b185cc81c9958da5c1a595b9d60a21b6064820152608401610783565b6101008801511515600003612612576001600160a01b0383166000818152600760209081526040808320868452909152808220805460ff19166001179055518492917fdff79c9c1b2a91402d98aa8d3ee6169ada42a7011022c7517cddeb224f89dba891a35b50505050505050505050565b612629828587612ea5565b6126755760405162461bcd60e51b815260206004820152601d60248201527f4173736574206973206e6f7420696e20612074617267657420736166650000006044820152606401610783565b8015156001036126965761268882612f6b565b61269182613002565b612853565b600f546040516333d8aeb360e01b81526001600160a01b038581166004830152909116906333d8aeb390602401602060405180830381865afa1580156126e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127049190614a7f565b15156001146127715760405162461bcd60e51b815260206004820152603360248201527f417474656d7074696e6720746f207472616e7366657220617373657420746f206044820152726e6f6e2050574e53616665206164647265737360681b6064820152608401610783565b601054602086015160405163cbda439360e01b81526001600160a01b038681166004830152918216602482015291169063cbda439390604401602060405180830381865afa1580156127c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127eb9190614a7f565b156128485760405162461bcd60e51b815260206004820152602760248201527f52656365697665722068617320617070726f76616c732073657420666f7220616044820152661b88185cdcd95d60ca1b6064820152608401610783565b612853828487613323565b60208501516000906001600160a01b0386169063468721a7908361287a8a8a8a6001613650565b60006040518563ffffffff1660e01b815260040161289b9493929190614bae565b6020604051808303816000875af11580156128ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128de9190614a7f565b9050806129255760405162461bcd60e51b8152602060048201526015602482015274105cdcd95d081d1c985b9cd9995c8819985a5b1959605a1b6044820152606401610783565b82826129315784612934565b60005b6001600160a01b0316866001600160a01b0316600080516020614cf6833981519152896040516129649190614815565b60405180910390a4505050505050565b6000546001600160a01b03163314610f475760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610783565b6000806129da83610e4f565b9050806001600160a01b0316846001600160a01b03161480612a2157506001600160a01b038082166000908152600d602090815260408083209388168352929052205460ff165b80612a455750836001600160a01b0316612a3a846106e8565b6001600160a01b0316145b949350505050565b826001600160a01b0316612a6082610e4f565b6001600160a01b031614612ac45760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610783565b6001600160a01b038216612b265760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610783565b6000818152600c6020908152604080832080546001600160a01b03191690556001600160a01b0386168352600b9091528120805460019290612b69908490614bf6565b90915550506001600160a01b0382166000908152600b60205260408120805460019290612b97908490614c0d565b90915550506000818152600a602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60008082516003811115612c0e57612c0e6147eb565b03612c1b57506060015190565b600282516003811115612c3057612c306147eb565b148015612c41575060008260600151115b15612c4e57506060015190565b506001919050565b919050565b60008083516003811115612c7157612c716147eb565b03612cee5760208301516040516370a0823160e01b81526001600160a01b038481166004830152909116906370a08231906024015b602060405180830381865afa158015612cc3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce79190614c25565b9050610650565b600183516003811115612d0357612d036147eb565b03612dab57816001600160a01b031683602001516001600160a01b0316636352211e85604001516040518263ffffffff1660e01b8152600401612d4891815260200190565b602060405180830381865afa158015612d65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d899190614a9c565b6001600160a01b031614612d9e576000612da1565b60015b60ff169050610650565b600283516003811115612dc057612dc06147eb565b03612e035760208301516040808501519051627eeac760e11b81526001600160a01b038581166004830152602482019290925291169062fdd58e90604401612ca6565b600383516003811115612e1857612e186147eb565b03612e5d57816001600160a01b031683602001516001600160a01b0316636352211e85604001516040518263ffffffff1660e01b8152600401612d4891815260200190565b60405162461bcd60e51b815260206004820181905260248201527f4d756c7469546f6b656e3a20556e737570706f727465642063617465676f72796044820152606401610783565b6001600160a01b0382166000908152600260205260408120612ec79085613669565b1515600003612ed857506000610f79565b6001600160a01b03808416600090815260036020908152604080832086830151909416835292905281812091840151612f12908390613500565b915050612f1e84612bf8565b8103612f3a576040840151612f34908390613675565b50612f5f565b612f5d8460400151612f4b86612bf8565b612f559084614bf6565b849190613681565b505b50600195945050505050565b60408051608081018252600080825260208083018290528284018290526060830182905284825260019081905292902081518154929391929091839160ff191690836003811115612fbe57612fbe6147eb565b0217905550602082015181546001600160a01b0390911661010002610100600160a81b03199091161781556040820151600182015560609091015160029091015550565b600061300d82610e4f565b905061301a600083611fa1565b6001600160a01b0381166000908152600b60205260408120805460019290613043908490614bf6565b90915550506000828152600a602052604080822080546001600160a01b0319169055518391906001600160a01b038416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a45050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006106508261368e565b6000808251600381111561310e5761310e6147eb565b036131735760408201511561312557506000919050565b61313b82602001516001600160a01b0316613699565b1561315f576020820151610650906001600160a01b03166336372b0760e01b6136cc565b50602001516001600160a01b03163b151590565b600182516003811115613188576131886147eb565b036131be5760608201511561319f57506000919050565b6020820151610650906001600160a01b03166380ac58cd60e01b6137b5565b6002825160038111156131d3576131d36147eb565b036131f7576020820151610650906001600160a01b0316636cdb3d1360e11b6137b5565b60038251600381111561320c5761320c6147eb565b03612e5d5760608201511561322357506000919050565b6020820151610650906001600160a01b0316639a20483d60e01b6137b5565b60008061324f8385612c5b565b6040808501516001600160a01b03808816600090815260036020908152848220818a0151909316825291909152918220929350909161328d91613500565b91505061329984612bf8565b6132a38284614bf6565b101595945050505050565b6000828152600160208190526040909120825181548493839160ff1916908360038111156132de576132de6147eb565b0217905550602082015181546001600160a01b0390911661010002610100600160a81b0319909116178155604082015160018201556060909101516002909101555050565b6001600160a01b038216600090815260026020526040902061334590846137d1565b506001600160a01b03808316600090815260036020908152604080832085830151909416835292905281812091830151613380908390613500565b91505061339e836040015161339485612bf8565b612f559084614c0d565b505050505050565b6001600160a01b0382166133fc5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610783565b6000818152600a60205260409020546001600160a01b0316156134615760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610783565b6001600160a01b0382166000908152600b6020526040812080546001929061348a908490614c0d565b90915550506000818152600a602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b60008181526001830160205260408120541515610f79565b600080808061350f86866137dd565b909450925050505b9250929050565b816001600160a01b0316836001600160a01b03160361357f5760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610783565b6001600160a01b038381166000818152600d6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60606000610f7983613817565b613604848484612a4d565b61361084848484613872565b610c9d5760405162461bcd60e51b815260040161078390614c3e565b600080600061363b8585613970565b91509150613648816139db565b509392505050565b6060613660858585856000613b91565b95945050505050565b6000610f798383613e32565b6000610f798383613f25565b6000612a45848484613f42565b600061065082613f5f565b60006136ac826301ffc9a760e01b6136cc565b801561065057506136c5826001600160e01b03196136cc565b1592915050565b604080516001600160e01b0319831660248083019190915282518083039091018152604490910182526020810180516001600160e01b03166301ffc9a760e01b179052905160009190829081906001600160a01b0387169061753090613733908690614c90565b6000604051808303818686fa925050503d806000811461376f576040519150601f19603f3d011682016040523d82523d6000602084013e613774565b606091505b509150915060208151101561378f5760009350505050610650565b8180156137ab5750808060200190518101906137ab9190614a7f565b9695505050505050565b60006137c083613699565b8015610f795750610f7983836136cc565b6000610f798383613f69565b600081815260028301602052604081205481908061380c576137ff8585613fb8565b9250600091506135179050565b600192509050613517565b606081600001805480602002602001604051908101604052809291908181526020018280548015611af157602002820191906000526020600020905b8154815260200190600101908083116138535750505050509050919050565b60006001600160a01b0384163b1561396857604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906138b6903390899088908890600401614cac565b6020604051808303816000875af19250505080156138f1575060408051601f3d908101601f191682019092526138ee91810190614b91565b60015b61394e573d80801561391f576040519150601f19603f3d011682016040523d82523d6000602084013e613924565b606091505b5080516000036139465760405162461bcd60e51b815260040161078390614c3e565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050612a45565b506001612a45565b60008082516041036139a65760208301516040840151606085015160001a61399a87828585613fc4565b94509450505050613517565b82516040036139cf57602083015160408401516139c48683836140b1565b935093505050613517565b50600090506002613517565b60008160048111156139ef576139ef6147eb565b036139f75750565b6001816004811115613a0b57613a0b6147eb565b03613a585760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610783565b6002816004811115613a6c57613a6c6147eb565b03613ab95760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610783565b6003816004811115613acd57613acd6147eb565b03613b255760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610783565b6004816004811115613b3957613b396147eb565b03611dca5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610783565b6060600086516003811115613ba857613ba86147eb565b03613c63578215613c075760608601516040516001600160a01b038616602482015260448101919091526064015b60408051601f198184030181529190526020810180516001600160e01b031663a9059cbb60e01b1790529050613660565b60608601516040516001600160a01b0380881660248301528616604482015260648101919091526084015b60408051601f198184030181529190526020810180516001600160e01b03166323b872dd60e01b1790529050613660565b600186516003811115613c7857613c786147eb565b03613d1a5781613cb15760408087015190516001600160a01b038088166024830152861660448201526064810191909152608401613c32565b60408087015190516001600160a01b03808816602483015286166044820152606481019190915260806084820152600060a482015260c40160408051601f198184030181529190526020810180516001600160e01b0316635c46a7ef60e11b1790529050613660565b600286516003811115613d2f57613d2f6147eb565b03613dbc57848487604001518860600151600014613d51578860600151613d54565b60015b6040516001600160a01b0394851660248201529390921660448401526064830152608482015260a060a4820152600060c482015260e40160408051601f198184030181529190526020810180516001600160e01b0316637921219560e11b1790529050613660565b600386516003811115613dd157613dd16147eb565b03612e5d578215613e035760408087015190516001600160a01b03861660248201526044810191909152606401613bd6565b60408087015190516001600160a01b038088166024830152861660448201526064810191909152608401613c32565b60008181526001830160205260408120548015613f1b576000613e56600183614bf6565b8554909150600090613e6a90600190614bf6565b9050818114613ecf576000866000018281548110613e8a57613e8a614a3a565b9060005260206000200154905080876000018481548110613ead57613ead614a3a565b6000918252602080832090910192909255918252600188019052604090208390555b8554869080613ee057613ee0614cdf565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610650565b6000915050610650565b60008181526002830160205260408120819055610f798383613669565b60008281526002840160205260408120829055612a4584846137d1565b6000610650825490565b6000818152600183016020526040812054613fb057508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610650565b506000610650565b6000610f7983836134e8565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115613ffb57506000905060036140a8565b8460ff16601b1415801561401357508460ff16601c14155b1561402457506000905060046140a8565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015614078573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166140a1576000600192509250506140a8565b9150600090505b94509492505050565b6000806001600160ff1b038316816140ce60ff86901c601b614c0d565b90506140dc87828885613fc4565b935093505050935093915050565b6001600160e01b031981168114611dca57600080fd5b60006020828403121561411257600080fd5b8135610f79816140ea565b60005b83811015614138578181015183820152602001614120565b83811115610c9d5750506000910152565b6000815180845261416181602086016020860161411d565b601f01601f19169290920160200192915050565b602081526000610f796020830184614149565b60006020828403121561419a57600080fd5b5035919050565b6001600160a01b0381168114611dca57600080fd5b8035612c56816141a1565b600080604083850312156141d457600080fd5b82356141df816141a1565b946020939093013593505050565b8015158114611dca57600080fd5b8035612c56816141ed565b634e487b7160e01b600052604160045260246000fd5b604051610140810167ffffffffffffffff8111828210171561424057614240614206565b60405290565b803560048110612c5657600080fd5b803564ffffffffff81168114612c5657600080fd5b6000610140828403121561427d57600080fd5b61428561421c565b905061429082614246565b815261429e602083016141b6565b602082015260408201356040820152606082013560608201526142c3608083016141fb565b60808201526142d460a083016141b6565b60a08201526142e560c083016141b6565b60c08201526142f660e08301614255565b60e08201526101006143098184016141fb565b818301525061012080830135818301525092915050565b6000806000806000806101c0878903121561433a57600080fd5b8635614345816141a1565b955060208701359450604087013561435c816141ed565b935061436b886060890161426a565b92506101a087013567ffffffffffffffff8082111561438957600080fd5b818901915089601f83011261439d57600080fd5b8135818111156143ac57600080fd5b8a60208285010111156143be57600080fd5b6020830194508093505050509295509295509295565b600067ffffffffffffffff808411156143ef576143ef614206565b604051601f8501601f19908116603f0116810190828211818310171561441757614417614206565b8160405280935085815286868601111561443057600080fd5b858560208301376000602087830101525050509392505050565b60006020828403121561445c57600080fd5b813567ffffffffffffffff81111561447357600080fd5b8201601f8101841361448457600080fd5b612a45848235602084016143d4565b6000806000606084860312156144a857600080fd5b83356144b3816141a1565b925060208401356144c3816141a1565b929592945050506040919091013590565b6000806000606084860312156144e957600080fd5b83356144f4816141a1565b925060208401359150604084013561450b816141ed565b809150509250925092565b6000806020838503121561452957600080fd5b823567ffffffffffffffff8082111561454157600080fd5b818501915085601f83011261455557600080fd5b81358181111561456457600080fd5b8660208260051b850101111561457957600080fd5b60209290920196919550909350505050565b6000806040838503121561459e57600080fd5b82356145a9816141a1565b915060208301356145b9816141a1565b809150509250929050565b6000602082840312156145d657600080fd5b8135610f79816141a1565b6000608082840312156145f357600080fd5b6040516080810181811067ffffffffffffffff8211171561461657614616614206565b60405261462283614246565b81526020830135614632816141a1565b6020820152604083810135908201526060928301359281019290925250919050565b6000806040838503121561466757600080fd5b8235915060208301356145b9816141a1565b6000806040838503121561468c57600080fd5b8235614697816141a1565b915060208301356145b9816141ed565b600080600080608085870312156146bd57600080fd5b84356146c8816141a1565b935060208501356146d8816141a1565b925060408501359150606085013567ffffffffffffffff8111156146fb57600080fd5b8501601f8101871361470c57600080fd5b61471b878235602084016143d4565b91505092959194509250565b6000806020838503121561473a57600080fd5b823567ffffffffffffffff8082111561475257600080fd5b818501915085601f83011261476657600080fd5b81358181111561477557600080fd5b8660208260071b850101111561457957600080fd5b6020808252825182820181905260009190848201906040850190845b818110156147c2578351835292840192918401916001016147a6565b50909695505050505050565b600061014082840312156147e157600080fd5b610f79838361426a565b634e487b7160e01b600052602160045260246000fd5b60048110614811576148116147eb565b9052565b6000608082019050614828828451614801565b60018060a01b036020840151166020830152604083015160408301526060830151606083015292915050565b6000610140828403121561486757600080fd5b50919050565b600181811c9082168061488157607f821691505b60208210810361486757634e487b7160e01b600052602260045260246000fd5b601f82111561082457600081815260208120601f850160051c810160208610156148c85750805b601f850160051c820191505b8181101561339e578281556001016148d4565b815167ffffffffffffffff81111561490157614901614206565b6149158161490f845461486d565b846148a1565b602080601f83116001811461494a57600084156149325750858301515b600019600386901b1c1916600185901b17855561339e565b600085815260208120601f198616915b828110156149795788860151825594840194600190910190840161495a565b50858210156149975787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60208082526025908201527f526563697069656e74207065726d697373696f6e206e6f6e63652069732072656040820152641d9bdad95960da1b606082015260800190565b6020808252602e908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526d1c881b9bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201614a7857614a78614a50565b5060010190565b600060208284031215614a9157600080fd5b8151610f79816141ed565b600060208284031215614aae57600080fd5b8151610f79816141a1565b8a81526101408101614ace602083018c614801565b6001600160a01b03998a1660408301526060820198909852608081019690965293151560a08601529190951660c084015264ffffffffff90941660e0830152921515610100820152610120019190915292915050565b60208082526017908201527f496e76616c6964207065726d6974746564206173736574000000000000000000604082015260600190565b83815260406020820152816040820152818360608301376000818301606090810191909152601f909201601f1916010192915050565b600060208284031215614ba357600080fd5b8151610f79816140ea565b60018060a01b0385168152836020820152608060408201526000614bd56080830185614149565b905060028310614be757614be76147eb565b82606083015295945050505050565b600082821015614c0857614c08614a50565b500390565b60008219821115614c2057614c20614a50565b500190565b600060208284031215614c3757600080fd5b5051919050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60008251614ca281846020870161411d565b9190910192915050565b6001600160a01b03858116825284166020820152604081018390526080606082018190526000906137ab90830184614149565b634e487b7160e01b600052603160045260246000fdfe31a70554f8f78c839c1e767c22805a185303216df6011aa8c0ac32d7c7190f84a2646970667358221220e3db44d58c707f1bf059110508c9259f0d7ff917a8b16ad152a02d345c51b73c64736f6c634300080f0033

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

00000000000000000000000079ec459c3ba4c64f00353cabf5fa179e059e2e1e

-----Decoded View---------------
Arg [0] : _whitelist (address): 0x79EC459C3bA4c64f00353caBF5fa179e059e2e1e

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000079ec459c3ba4c64f00353cabf5fa179e059e2e1e


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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