creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@bb-referral/ReferralSystem.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.20;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\n\nimport './ReferralSystemStorage.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\n\n/// @notice ReferralSystem contract is a contract that allows to create a referral codes and collect referral rewards\n/// @author 0xLumos-Labs\n/// @dev allows infinite nesting of referrals due to design of the contract of referrers being able to have referrers\n/// @dev superior referrer is a referrer that invited another referrer\n/// @dev inferior referrer is a referrer that have been invited by some referrer\n/// @dev creator of referral code can be a first referrer ever existed, than he will never pay referral fees to his superior referrer\ncontract ReferralSystem is ReferralSystemStorage, Ownable {\n\tusing SafeERC20 for IERC20;\n\t/* ======== STORAGE ======== */\n\n\tuint256 public SUPERIOR_REFERRER_SHARE_BPS;\n\n\tmapping(bytes32 codeHash => string code) private codeByHash;\n\n\t/* ======== CONSTRUCTOR ======== */\n\n\tconstructor(uint256 _superiorReferrerShareBps) Ownable(msg.sender) {\n\t\tSUPERIOR_REFERRER_SHARE_BPS = _superiorReferrerShareBps;\n\t}\n\n\t/* ======== ERRORS ======== */\n\n\terror InvalidReferralCodeLength();\n\terror ReferralCodeUnavailable();\n\terror ReferralCodeNotExist();\n\terror NoRewardAccruedForReferrer();\n\terror ZeroAmountPassed();\n\n\t/* ======== EVENTS ======== */\n\n\tevent ReferralCodeRegistered(\n\t\tstring referralCode,\n\t\tbytes32 indexed referralCodeHash,\n\t\taddress indexed referrer,\n\t\tbytes32 indexed superiorReferralCodeHash\n\t);\n\n\tevent ReferralRewardAccrued(\n\t\taddress indexed token,\n\t\tuint256 reward,\n\t\taddress indexed referrer,\n\t\tbytes32 referralCodeHash\n\t);\n\n\tevent ReferralRegisteredWithReferralCode(\n\t\taddress indexed referral,\n\t\tbytes32 indexed referralCodeHash\n\t);\n\n\tevent ReferralRewardWithdrawn(\n\t\taddress indexed referrer,\n\t\taddress indexed token,\n\t\tuint256 reward\n\t);\n\n\tevent ReferralRewardShareUpdated(uint256 newReferrerShareBps);\n\n\t/* ======== MUTABLE FUNCTIONS ======== */\n\n\t/// @notice new referrer can be registered with a referral code of another referrer\n\t/// @notice meaning that the new referrer will be a referral of the referrer and will share a reward with referrer\n\tfunction registerReferralCode(\n\t\tstring calldata referralCode,\n\t\taddress referrer,\n\t\tbytes32 superiorReferralCodeHash\n\t) public {\n\t\tbytes32 referralCodeHash = getReferralCodeHash(referralCode);\n\n\t\tif (!isReferralCodeAvailable(referralCodeHash))\n\t\t\trevert ReferralCodeUnavailable();\n\n\t\tif (bytes(referralCode).length == 0) revert InvalidReferralCodeLength();\n\t\tif (\n\t\t\tsuperiorReferralCodeHash != bytes32(0) &&\n\t\t\t!isReferralCodeExist(superiorReferralCodeHash)\n\t\t) revert ReferralCodeNotExist();\n\n\t\t_saveReferralCode(referralCode);\n\n\t\t_setReferralCodeData(referralCode, referrer, superiorReferralCodeHash);\n\n\t\temit ReferralCodeRegistered(\n\t\t\treferralCode,\n\t\t\treferralCodeHash,\n\t\t\treferrer,\n\t\t\tsuperiorReferralCodeHash\n\t\t);\n\t}\n\n\tfunction registerReferral(\n\t\taddress referral,\n\t\tbytes32 referralCodeHash\n\t) public {\n\t\tif (!isReferralCodeExist(referralCodeHash))\n\t\t\trevert ReferralCodeNotExist();\n\n\t\t_setReferralCodeToAddress(referral, referralCodeHash);\n\n\t\temit ReferralRegisteredWithReferralCode(referral, referralCodeHash);\n\t}\n\n\tfunction accrueNativeReferralReward(\n\t\tbytes32 referralCodeHash\n\t) public payable {\n\t\taddress referrer = getReferrerByReferralCodeHash(referralCodeHash);\n\n\t\t_accrueReferralReward(\n\t\t\taddress(0),\n\t\t\tmsg.value,\n\t\t\treferrer,\n\t\t\treferralCodeHash\n\t\t);\n\t}\n\n\tfunction accrueTokenReferralReward(\n\t\taddress token,\n\t\tuint amount,\n\t\tbytes32 referralCodeHash\n\t) public {\n\t\taddress referrer = getReferrerByReferralCodeHash(referralCodeHash);\n\n\t\tIERC20(token).safeTransferFrom(msg.sender, address(this), amount);\n\n\t\t_accrueReferralReward(token, amount, referrer, referralCodeHash);\n\t}\n\n\t/// @dev don't do checks on token\n\t/// @dev address(0) - rewards in native\n\t/// @dev a\n\tfunction _accrueReferralReward(\n\t\taddress token,\n\t\tuint amount,\n\t\taddress referrer,\n\t\tbytes32 referralCodeHash\n\t) public {\n\t\tif (referrer == address(0)) revert ReferrerNotExist();\n\n\t\t_addRewardsToReferrer(token, amount, referrer);\n\n\t\temit ReferralRewardAccrued(token, amount, referrer, referralCodeHash);\n\t}\n\n\t/// @param token address of the token to withdraw rewards for (zero address is native currency)\n\tfunction withdrawReferralRewards(address token) public returns (uint) {\n\t\tuint referralRewards = getReferrerRewards(msg.sender, token);\n\n\t\tif (referralRewards == 0) revert NoRewardAccruedForReferrer();\n\n\t\taddress superior = getSuperiorReferrer(msg.sender);\n\n\t\t_makeReferralRewards0(token, msg.sender);\n\n\t\tuint256 superiorReferrerReward = _addRewardToSuperiorReferrer(\n\t\t\ttoken,\n\t\t\treferralRewards,\n\t\t\tsuperior\n\t\t);\n\n\t\tuint256 amountToWithdraw = referralRewards - superiorReferrerReward;\n\n\t\tif (token == address(0)) {\n\t\t\tpayable(msg.sender).transfer(amountToWithdraw);\n\t\t} else {\n\t\t\tIERC20(token).safeTransfer(msg.sender, amountToWithdraw);\n\t\t}\n\n\t\temit ReferralRewardWithdrawn(msg.sender, token, amountToWithdraw);\n\n\t\treturn amountToWithdraw;\n\t}\n\n\tfunction _addRewardToSuperiorReferrer(\n\t\taddress token,\n\t\tuint inferiorReward,\n\t\taddress superior\n\t) internal returns (uint256 superiorReferrerReward) {\n\t\tif (superior == address(0)) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tsuperiorReferrerReward = calcSuperiorReferrersShare(inferiorReward);\n\n\t\t_addRewardsToReferrer(token, superiorReferrerReward, superior);\n\n\t\tbytes32 inferiorReferralCodeHash = getReferralCodeHashByReferral(\n\t\t\tmsg.sender\n\t\t);\n\n\t\temit ReferralRewardAccrued(\n\t\t\ttoken,\n\t\t\tsuperiorReferrerReward,\n\t\t\tsuperior,\n\t\t\tinferiorReferralCodeHash\n\t\t);\n\t}\n\n\tfunction _saveReferralCode(string calldata referralCode) internal {}\n\n\t/* ======== RESTRICTED FUNCTIONS ======== */\n\n\tfunction updateReferralRewardShare(\n\t\tuint256 newSuperiorReferrerShareBps\n\t) public onlyOwner {\n\t\tSUPERIOR_REFERRER_SHARE_BPS = newSuperiorReferrerShareBps;\n\n\t\temit ReferralRewardShareUpdated(newSuperiorReferrerShareBps);\n\t}\n\n\t/* ======== VIEW FUNCTIONS ======== */\n\n\tfunction calcSuperiorReferrersShare(\n\t\tuint256 amount\n\t) public view returns (uint256) {\n\t\treturn (amount * SUPERIOR_REFERRER_SHARE_BPS) / 10000;\n\t}\n\n\tfunction isReferralCodeAvailable(\n\t\tbytes32 referralCodeHash\n\t) public view returns (bool) {\n\t\treturn getReferrerByReferralCodeHash(referralCodeHash) == address(0);\n\t}\n\n\tfunction isReferralCodeExist(\n\t\tbytes32 referralCodeHash\n\t) public view returns (bool) {\n\t\treturn getReferrerByReferralCodeHash(referralCodeHash) != address(0);\n\t}\n}\n"
      },
      "@bb-referral/ReferralSystemStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.20;\n\ncontract ReferralSystemStorage {\n\t/* ======== DATA TYPES ======== */\n\n\tstruct ReferrerData {\n\t\t// address(0) is native currency\n\t\tmapping(address => uint256) referralRewards;\n\t\taddress superiorReferrer;\n\t}\n\n\tmapping(address referrer => ReferrerData) private referrerData;\n\tmapping(address referral => bytes32 referralCodeHash)\n\t\tprivate codeByReferral;\n\n\tmapping(bytes32 referralCodeHash => string referralCode) private codeByHash;\n\t//     private superiorReferrer;\n\n\t/* ======== ERRORS ======== */\n\n\terror ReferrerNotExist();\n\terror ZeroAddressPassed();\n\terror ZeroReferralCodeHashPassed();\n\terror ZeroRewardPassed();\n\n\t/* ======== STORAGE ======== */\n\n\tmapping(bytes32 referralCodeHash => address referrer)\n\t\tprivate referrerByReferralCodeHash;\n\n\t/* ======== MUTABLE FUNCTIONS ======== */\n\n\tfunction _setReferralCodeData(\n\t\tstring calldata referralCode,\n\t\taddress referrer,\n\t\tbytes32 superiorReferralCodeHash\n\t) internal {\n\t\tbytes32 referralCodeHash = getReferralCodeHash(referralCode);\n\t\tcodeByHash[referralCodeHash] = referralCode;\n\n\t\tif (referrer == address(0)) revert ZeroAddressPassed();\n\t\tif (referralCodeHash == bytes32(0x0))\n\t\t\trevert ZeroReferralCodeHashPassed();\n\n\t\treferrerByReferralCodeHash[referralCodeHash] = referrer;\n\n\t\taddress _superiorReferrer = getReferrerByReferralCodeHash(\n\t\t\tsuperiorReferralCodeHash\n\t\t);\n\n\t\treferrerData[referrer].superiorReferrer = _superiorReferrer;\n\t}\n\n\tfunction _setReferralCodeToAddress(\n\t\taddress referral,\n\t\tbytes32 referralCodeHash\n\t) internal {\n\t\tif (referral == address(0)) revert ZeroAddressPassed();\n\t\tif (referralCodeHash == bytes32(0x0))\n\t\t\trevert ZeroReferralCodeHashPassed();\n\t\tcodeByReferral[referral] = referralCodeHash;\n\t}\n\n\tfunction _addRewardsToReferrer(\n\t\taddress token,\n\t\tuint256 reward,\n\t\taddress referrer\n\t) internal {\n\t\tif (reward == 0) revert ZeroRewardPassed();\n\t\tif (referrer == address(0)) revert ZeroAddressPassed();\n\n\t\treferrerData[referrer].referralRewards[token] += reward;\n\t}\n\n\tfunction _makeReferralRewards0(address token, address referrer) internal {\n\t\treferrerData[referrer].referralRewards[token] = 0;\n\t}\n\n\t/* ======== VIEW FUNCTIONS ======== */\n\n\tfunction getReferrerByReferralCode(\n\t\tstring calldata referralCode\n\t) public view returns (address referrer) {\n\t\tbytes32 referralCodeHash = keccak256(abi.encodePacked(referralCode));\n\t\treferrer = referrerByReferralCodeHash[referralCodeHash];\n\n\t\tif (referrer == address(0)) revert ReferrerNotExist();\n\t}\n\n\tfunction getReferrerByReferralCodeHash(\n\t\tbytes32 referralCodeHash\n\t) public view returns (address referrer) {\n\t\treferrer = referrerByReferralCodeHash[referralCodeHash];\n\n\t\t// if (referrer == address(0)) revert ReferrerNotExist(referralCodeHash);\n\t}\n\n\tfunction getReferrerRewards(\n\t\taddress referrer,\n\t\taddress token\n\t) public view returns (uint) {\n\t\treturn referrerData[referrer].referralRewards[token];\n\t}\n\n\tfunction getSuperiorReferrer(\n\t\taddress referrer\n\t) public view returns (address) {\n\t\treturn referrerData[referrer].superiorReferrer;\n\t}\n\n\tfunction getReferralCodeHashByReferral(\n\t\taddress referral\n\t) public view returns (bytes32 referralCodeHash) {\n\t\treferralCodeHash = codeByReferral[referral];\n\t}\n\n\tfunction getReferralCodeByHash(\n\t\tbytes32 referralCodeHash\n\t) public view returns (string memory referralCode) {\n\t\treferralCode = codeByHash[referralCodeHash];\n\t}\n\n\tfunction getReferralCodeHash(\n\t\tstring calldata code\n\t) public pure returns (bytes32) {\n\t\treturn keccak256(abi.encodePacked(code));\n\t}\n}\n"
      },
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/interfaces/draft-IERC6093.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.\n */\ninterface IERC20Errors {\n    /**\n     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     * @param balance Current balance for the interacting account.\n     * @param needed Minimum amount required to perform a transfer.\n     */\n    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n    /**\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     */\n    error ERC20InvalidSender(address sender);\n\n    /**\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\n     * @param receiver Address to which tokens are being transferred.\n     */\n    error ERC20InvalidReceiver(address receiver);\n\n    /**\n     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\n     * @param allowance Amount of tokens a `spender` is allowed to operate with.\n     * @param needed Minimum amount required to perform a transfer.\n     */\n    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n    /**\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n     * @param approver Address initiating an approval operation.\n     */\n    error ERC20InvalidApprover(address approver);\n\n    /**\n     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n     * @param spender Address that may be allowed to operate on tokens without being their owner.\n     */\n    error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.\n */\ninterface IERC721Errors {\n    /**\n     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.\n     * Used in balance queries.\n     * @param owner Address of the current owner of a token.\n     */\n    error ERC721InvalidOwner(address owner);\n\n    /**\n     * @dev Indicates a `tokenId` whose `owner` is the zero address.\n     * @param tokenId Identifier number of a token.\n     */\n    error ERC721NonexistentToken(uint256 tokenId);\n\n    /**\n     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     * @param tokenId Identifier number of a token.\n     * @param owner Address of the current owner of a token.\n     */\n    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n    /**\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     */\n    error ERC721InvalidSender(address sender);\n\n    /**\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\n     * @param receiver Address to which tokens are being transferred.\n     */\n    error ERC721InvalidReceiver(address receiver);\n\n    /**\n     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\n     * @param tokenId Identifier number of a token.\n     */\n    error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n    /**\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n     * @param approver Address initiating an approval operation.\n     */\n    error ERC721InvalidApprover(address approver);\n\n    /**\n     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\n     */\n    error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.\n */\ninterface IERC1155Errors {\n    /**\n     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     * @param balance Current balance for the interacting account.\n     * @param needed Minimum amount required to perform a transfer.\n     * @param tokenId Identifier number of a token.\n     */\n    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n    /**\n     * @dev Indicates a failure with the token `sender`. Used in transfers.\n     * @param sender Address whose tokens are being transferred.\n     */\n    error ERC1155InvalidSender(address sender);\n\n    /**\n     * @dev Indicates a failure with the token `receiver`. Used in transfers.\n     * @param receiver Address to which tokens are being transferred.\n     */\n    error ERC1155InvalidReceiver(address receiver);\n\n    /**\n     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\n     * @param owner Address of the current owner of a token.\n     */\n    error ERC1155MissingApprovalForAll(address operator, address owner);\n\n    /**\n     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n     * @param approver Address initiating an approval operation.\n     */\n    error ERC1155InvalidApprover(address approver);\n\n    /**\n     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n     * @param operator Address that may be allowed to operate on tokens without being their owner.\n     */\n    error ERC1155InvalidOperator(address operator);\n\n    /**\n     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n     * Used in batch transfers.\n     * @param idsLength Length of the array of token identifiers\n     * @param valuesLength Length of the array of token amounts\n     */\n    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/ERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n    mapping(address account => uint256) private _balances;\n\n    mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor(string memory name_, string memory symbol_) {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the default value returned by this function, unless\n     * it's overridden.\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `value`.\n     */\n    function transfer(address to, uint256 value) public virtual returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, value);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 value) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, value);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `value`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `value`.\n     */\n    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, value);\n        _transfer(from, to, value);\n        return true;\n    }\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * NOTE: This function is not virtual, {_update} should be overridden instead.\n     */\n    function _transfer(address from, address to, uint256 value) internal {\n        if (from == address(0)) {\n            revert ERC20InvalidSender(address(0));\n        }\n        if (to == address(0)) {\n            revert ERC20InvalidReceiver(address(0));\n        }\n        _update(from, to, value);\n    }\n\n    /**\n     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n     * this function.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _update(address from, address to, uint256 value) internal virtual {\n        if (from == address(0)) {\n            // Overflow check required: The rest of the code assumes that totalSupply never overflows\n            _totalSupply += value;\n        } else {\n            uint256 fromBalance = _balances[from];\n            if (fromBalance < value) {\n                revert ERC20InsufficientBalance(from, fromBalance, value);\n            }\n            unchecked {\n                // Overflow not possible: value <= fromBalance <= totalSupply.\n                _balances[from] = fromBalance - value;\n            }\n        }\n\n        if (to == address(0)) {\n            unchecked {\n                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n                _totalSupply -= value;\n            }\n        } else {\n            unchecked {\n                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n                _balances[to] += value;\n            }\n        }\n\n        emit Transfer(from, to, value);\n    }\n\n    /**\n     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n     * Relies on the `_update` mechanism\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * NOTE: This function is not virtual, {_update} should be overridden instead.\n     */\n    function _mint(address account, uint256 value) internal {\n        if (account == address(0)) {\n            revert ERC20InvalidReceiver(address(0));\n        }\n        _update(address(0), account, value);\n    }\n\n    /**\n     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n     * Relies on the `_update` mechanism.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * NOTE: This function is not virtual, {_update} should be overridden instead\n     */\n    function _burn(address account, uint256 value) internal {\n        if (account == address(0)) {\n            revert ERC20InvalidSender(address(0));\n        }\n        _update(account, address(0), value);\n    }\n\n    /**\n     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     *\n     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n     */\n    function _approve(address owner, address spender, uint256 value) internal {\n        _approve(owner, spender, value, true);\n    }\n\n    /**\n     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n     *\n     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n     * `Approval` event during `transferFrom` operations.\n     *\n     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n     * true using the following override:\n     * ```\n     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n     *     super._approve(owner, spender, value, true);\n     * }\n     * ```\n     *\n     * Requirements are the same as {_approve}.\n     */\n    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n        if (owner == address(0)) {\n            revert ERC20InvalidApprover(address(0));\n        }\n        if (spender == address(0)) {\n            revert ERC20InvalidSpender(address(0));\n        }\n        _allowances[owner][spender] = value;\n        if (emitEvent) {\n            emit Approval(owner, spender, value);\n        }\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `value`.\n     *\n     * Does not update the allowance value in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Does not emit an {Approval} event.\n     */\n    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            if (currentAllowance < value) {\n                revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n            }\n            unchecked {\n                _approve(owner, spender, currentAllowance - value, false);\n            }\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n *     doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n *     token.safeTransferFrom(msg.sender, address(this), value);\n *     ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\n */\ninterface IERC20Permit {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     *\n     * CAUTION: See Security Considerations above.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC20Permit} from \"../extensions/IERC20Permit.sol\";\nimport {Address} from \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    /**\n     * @dev An operation with an ERC20 token failed.\n     */\n    error SafeERC20FailedOperation(address token);\n\n    /**\n     * @dev Indicates a failed `decreaseAllowance` request.\n     */\n    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));\n    }\n\n    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        forceApprove(token, spender, oldAllowance + value);\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n     * value, non-reverting calls are assumed to be successful.\n     */\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n        unchecked {\n            uint256 currentAllowance = token.allowance(address(this), spender);\n            if (currentAllowance < requestedDecrease) {\n                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n            }\n            forceApprove(token, spender, currentAllowance - requestedDecrease);\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     */\n    function forceApprove(IERC20 token, address spender, uint256 value) internal {\n        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));\n\n        if (!_callOptionalReturnBool(token, approvalCall)) {\n            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));\n            _callOptionalReturn(token, approvalCall);\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data);\n        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     *\n     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n     */\n    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n        // and not revert is the subcall reverts.\n\n        (bool success, bytes memory returndata) = address(token).call(data);\n        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev The ETH balance of the account is not enough to perform the operation.\n     */\n    error AddressInsufficientBalance(address account);\n\n    /**\n     * @dev There's no code at `target` (it is not a contract).\n     */\n    error AddressEmptyCode(address target);\n\n    /**\n     * @dev A call to an address target failed. The target may have reverted.\n     */\n    error FailedInnerCall();\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        if (address(this).balance < amount) {\n            revert AddressInsufficientBalance(address(this));\n        }\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        if (!success) {\n            revert FailedInnerCall();\n        }\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason or custom error, it is bubbled\n     * up by this function (like regular Solidity function calls). However, if\n     * the call reverted with no returned reason, this function reverts with a\n     * {FailedInnerCall} error.\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        if (address(this).balance < value) {\n            revert AddressInsufficientBalance(address(this));\n        }\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target\n     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an\n     * unsuccessful call.\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata\n    ) internal view returns (bytes memory) {\n        if (!success) {\n            _revert(returndata);\n        } else {\n            // only check if target is a contract if the call was successful and the return data is empty\n            // otherwise we already know that it was a contract\n            if (returndata.length == 0 && target.code.length == 0) {\n                revert AddressEmptyCode(target);\n            }\n            return returndata;\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the\n     * revert reason or with a default {FailedInnerCall} error.\n     */\n    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {\n        if (!success) {\n            _revert(returndata);\n        } else {\n            return returndata;\n        }\n    }\n\n    /**\n     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.\n     */\n    function _revert(bytes memory returndata) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert FailedInnerCall();\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "contracts/FeeSender.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.20;\n\nimport \"@bb-referral/ReferralSystem.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nabstract contract FeeSender is Ownable {\n    using SafeERC20 for ERC20;\n\n    ReferralSystem public referralSystem;\n\n    uint public constant BASIS_POINTS = 10000;\n\n    address public feeReceiver;\n\n    uint256 public baseFee;\n    uint256 public discountedBaseFee;\n\n    uint256 public referralFeeOfBaseFee; // Takes share of protocol fee to\n\n    event ProtocolFeePercentageUpdated(\n        uint256 oldFeeInBasisPoints,\n        uint256 newFeeInBasisPoints\n    );\n\n    event ReferralFeePercentageUpdated(\n        uint256 oldFeeInBasisPoints,\n        uint256 newFeeInBasisPoints\n    );\n\n    event BaseFeePercentageUpdated(\n        uint256 oldBaseFeeInBasisPoints,\n        uint256 oldDiscountedBaseFeeInBasisPoints,\n        uint256 newBaseFee,\n        uint256 newDiscountedBaseFee\n    );\n\n    event ReferralFeeUpdated(uint256 oldReferralFee, uint256 newReferralFee);\n\n    event FeeReceiverUpdated(address oldFeeReceiver, address newFeeReceiver);\n\n    constructor(\n        address referralSystem_,\n        address feeReceiver_,\n        uint256 baseFee_,\n        uint256 discountedBaseFee_,\n        uint256 referralFeeInBasisPointsOfBaseFee_\n    ) Ownable(msg.sender) {\n        referralSystem = ReferralSystem(referralSystem_);\n\n        feeReceiver = feeReceiver_;\n\n        baseFee = baseFee_;\n        discountedBaseFee = discountedBaseFee_;\n\n        referralFeeOfBaseFee = referralFeeInBasisPointsOfBaseFee_;\n    }\n\n    function _sendFees(\n        address token,\n        uint actionAmount,\n        bytes32 referralCodeHash\n    ) internal returns (uint totalFees) {\n        (\n            uint256 protocolFee,\n            uint256 referralFee\n        ) = _getProtocolAndReferralFees(\n                msg.sender,\n                actionAmount,\n                referralCodeHash\n            );\n\n        totalFees = protocolFee + referralFee;\n\n        _isNative(token)\n            ? _sendProtocolFeesInNative(protocolFee)\n            : _sendProtocolFeesInToken(token, protocolFee);\n\n        if (referralFee == 0) return totalFees;\n\n        bytes32 registeredReferralCodeHash = referralSystem\n            .getReferralCodeHashByReferral(msg.sender);\n\n        _isNative(token)\n            ? _sendReferralFeesInNative(referralFee, registeredReferralCodeHash)\n            : _sendReferralFeesInToken(\n                token,\n                referralFee,\n                registeredReferralCodeHash\n            );\n    }\n\n    /* ========== RESTRICTED FUNCTIONS ========== */\n\n    function updateBaseFeePercentage(\n        uint256 newBaseFee_,\n        uint256 newDiscountedBaseFee_\n    ) external onlyOwner {\n        uint256 oldBaseFeeInBasisPoints = baseFee;\n        uint256 oldDiscountedBaseFeeInBasisPoints = discountedBaseFee;\n\n        baseFee = newBaseFee_;\n        discountedBaseFee = newDiscountedBaseFee_;\n\n        emit BaseFeePercentageUpdated(\n            oldBaseFeeInBasisPoints,\n            oldDiscountedBaseFeeInBasisPoints,\n            newBaseFee_,\n            newDiscountedBaseFee_\n        );\n    }\n\n    function updateProtocolFeeReceiver(\n        address feeReceiver_\n    ) external onlyOwner {\n        address oldFeeReceiver = feeReceiver;\n        feeReceiver = feeReceiver_;\n\n        emit FeeReceiverUpdated(oldFeeReceiver, feeReceiver_);\n    }\n\n    function updateReferralFeeBasisPoints(\n        uint referralFeeInBasisPointsOfBaseFee_\n    ) external onlyOwner {\n        uint oldReferralFee = referralFeeOfBaseFee;\n\n        referralFeeOfBaseFee = referralFeeInBasisPointsOfBaseFee_;\n\n        emit ReferralFeeUpdated(\n            oldReferralFee,\n            referralFeeInBasisPointsOfBaseFee_\n        );\n    }\n\n    /* ========== INTERNAL FUNCTIONS ========== */\n\n    function _getProtocolAndReferralFees(\n        address referral,\n        uint256 actionAmount,\n        bytes32 referralCodeHash\n    ) internal returns (uint256 protocolFee, uint256 referralFee) {\n        bool isInReferralSystem = _getReferralStatus(referral);\n\n        uint256 _baseFee;\n\n        if (isInReferralSystem) {\n            // Make discount on base fee\n            _baseFee = (actionAmount * discountedBaseFee) / BASIS_POINTS;\n            referralFee = (_baseFee * referralFeeOfBaseFee) / BASIS_POINTS;\n        } else {\n            if (referralCodeHash == bytes32(0)) {\n                _baseFee = (actionAmount * baseFee) / BASIS_POINTS;\n                referralFee = 0;\n            } else {\n                referralSystem.registerReferral(referral, referralCodeHash);\n\n                _baseFee = (actionAmount * discountedBaseFee) / BASIS_POINTS;\n                referralFee = (_baseFee * referralFeeOfBaseFee) / BASIS_POINTS;\n            }\n        }\n\n        protocolFee = _baseFee - referralFee;\n    }\n\n    function _isNative(address token) internal pure returns (bool) {\n        return token == address(0);\n    }\n\n    function _getReferralStatus(address referral) internal view returns (bool) {\n        bytes32 recordedReferralCodeHash = referralSystem\n            .getReferralCodeHashByReferral(referral);\n\n        return recordedReferralCodeHash != bytes32(0);\n    }\n\n    function _sendProtocolFeesInNative(uint256 protocolFee) internal {\n        payable(feeReceiver).transfer(protocolFee);\n    }\n\n    function _sendProtocolFeesInToken(\n        address token,\n        uint256 protocolFee\n    ) internal {\n        ERC20(token).safeTransfer(feeReceiver, protocolFee);\n    }\n\n    function _sendReferralFeesInNative(\n        uint256 referralFee,\n        bytes32 referralCodeHash\n    ) internal {\n        referralSystem.accrueNativeReferralReward{value: referralFee}(\n            referralCodeHash\n        );\n    }\n\n    function _sendReferralFeesInToken(\n        address token,\n        uint256 referralFee,\n        bytes32 referralCodeHash\n    ) internal {\n        ERC20(token).approve(address(referralSystem), referralFee);\n\n        referralSystem.accrueTokenReferralReward(\n            token,\n            referralFee,\n            referralCodeHash\n        );\n    }\n}\n"
      },
      "contracts/interfaces/IVault.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IVault {\n    function token() external view returns (address);\n\n    function underlying() external view returns (address);\n\n    function name() external view returns (string memory);\n\n    function symbol() external view returns (string memory);\n\n    function decimals() external view returns (uint8);\n\n    function controller() external view returns (address);\n\n    function governance() external view returns (address);\n\n    function getPricePerFullShare() external view returns (uint256);\n\n    function deposit() external returns (uint256);\n\n    function deposit(uint256) external returns (uint256);\n\n    function deposit(uint256, address) external returns (uint256);\n\n    function depositAll() external;\n\n    function withdraw(uint256) external;\n\n    function withdrawAll() external;\n}\n"
      },
      "contracts/YearnV2Proxy.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.20;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./interfaces/IVault.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"./FeeSender.sol\";\n\ncontract YearnV2Proxy is FeeSender {\n    using SafeERC20 for IERC20;\n\n    event DepositWithFee(\n        uint256 amountIn,\n        uint256 amountWithoutFee,\n        uint256 fee\n    );\n\n    constructor(\n        address referralSystem_,\n        address feeReceiver_,\n        uint256 baseFee_,\n        uint256 discountedBaseFee_,\n        uint256 referralFeeOfBaseFee_\n    )\n        FeeSender(\n            referralSystem_,\n            feeReceiver_,\n            baseFee_,\n            discountedBaseFee_,\n            referralFeeOfBaseFee_\n        )\n    {}\n\n    function deposit(\n        address vault,\n        uint256 amount,\n        bytes32 referralCodeHash\n    ) external returns (uint256 shares) {\n        address token = IVault(vault).token();\n        IERC20 srcToken = IERC20(token);\n        uint256 newAmount = deductFee(srcToken, amount, referralCodeHash);\n\n        srcToken.safeIncreaseAllowance(vault, newAmount);\n\n        shares = IVault(vault).deposit(newAmount, msg.sender);\n    }\n\n    function deductFee(\n        IERC20 token,\n        uint256 amount,\n        bytes32 referralCodeHash\n    ) internal returns (uint256 newAmount) {\n        token.safeTransferFrom(msg.sender, address(this), amount);\n\n        uint256 fee = _sendFees(address(token), amount, referralCodeHash);\n        newAmount = amount - fee;\n\n        emit DepositWithFee(amount, newAmount, fee);\n    }\n}\n"
      }
    },
    "settings": {
      "viaIR": true,
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "paris",
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}