{ "language": "Solidity", "sources": { "contracts/Presale.sol": { "content": "// SPDX-License-Identifier: UNLICENCED\npragma solidity 0.8.11;\n\nimport '@openzeppelin/contracts/access/AccessControl.sol';\nimport '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';\n\nimport './JoyToken.sol';\nimport './xJoyToken.sol';\nimport './interfaces/IUSDT.sol';\n\nimport './interfaces/IUniswapV2Pair.sol';\nimport './libraries/UniswapV2Library.sol';\n\nerror SALE_NOT_LIVE();\nerror STILL_VESTING();\nerror WRONG_VESTING_TYPE();\nerror NOTHING_TO_WITHDRAW();\nerror COINS_NOT_SET();\nerror ONLY_OWNER();\nerror WRONG_ADDRESS();\nerror PAIR_NOT_SET();\nerror MIN_ONE_CENT();\n\ncontract Presale is AccessControl {\n /**\n * VESTING TYPES\n * Initialy there will be 5 vesting levels defined by the constructor\n * 0 - SEED\n * 1 - PRESALE\n * 2 - TEAM\n * 3 - PARTNERS\n * 4 - STAR\n *\n * It's not becoming an enum to allow users to set different vesting level after the release\n */\n\n struct VestingInfo {\n uint256 releasePercentBasisPoints; // Release percent basis points (1% = 100, 100% = 10000)\n uint256 cliff; // Cliff for release start time\n uint256 releaseStep; // How often percent step is applied\n uint256 vestingCloseTimeline; // How much time has to pass to finish vesting\n }\n\n struct DepositInfo {\n uint256 vestingType; // Tier of the type of vesting\n uint256 depositedAmount; // How many Coins amount the user has deposited.\n uint256 purchasedAmount; // How many JOY tokens the user has purchased.\n uint256 depositTime; // Deposited time\n }\n\n struct PurchaserInfo {\n uint256 firstDepositTime; // When user made his first deposit\n uint256 firstUnlockTime; // Timestamp when unlock will start\n uint256 vestingTimeFinish; // Timestamp when vesting for the purchaser will be closed\n uint256 withdrawnAmount; // Amount of JOY tokens already withdrawn by the purchaser\n DepositInfo[] deposits; // List of all deposits of the purchaser\n }\n\n JoyToken public joyToken;\n XJoyToken public xJoyToken;\n\n VestingInfo[] public vestingList;\n uint256 public currentVestingType;\n uint256 public totalPurchasers;\n address public treasuryAddress;\n address public USDC_Address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;\n address public USDT_Address = 0xdAC17F958D2ee523a2206206994597C13D831ec7;\n address public owner;\n bool public sale;\n\n mapping(uint256 => address) public purchaserAddress;\n mapping(address => PurchaserInfo) public purchaserList;\n\n event TokensPurchased(\n address indexed purchaser,\n uint256 coinAmount,\n uint256 tokenAmount\n );\n event TokensWithdrawn(address indexed purchaser, uint256 tokenAmount);\n event VestingTypeAdded(uint256 indexed level);\n event VestingTypeChanged(uint256 indexed level);\n\n modifier onSale() {\n if (!sale) revert SALE_NOT_LIVE();\n _;\n }\n\n modifier notVested(address userAddr) {\n if (!checkVestingPeriod(userAddr)) revert STILL_VESTING();\n _;\n }\n\n modifier onlyAdmin() {\n _checkRole(DEFAULT_ADMIN_ROLE);\n _;\n }\n\n modifier onlyOwner() {\n if (owner != _msgSender()) revert ONLY_OWNER();\n _;\n }\n\n constructor(\n JoyToken _joyToken,\n XJoyToken _xJoyToken,\n VestingInfo[] memory _vestingInfo,\n uint256 _initialVestingType,\n address _treasuryAddress\n ) {\n joyToken = _joyToken;\n xJoyToken = _xJoyToken;\n treasuryAddress = _treasuryAddress;\n owner = msg.sender;\n _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);\n for (uint256 i; i < _vestingInfo.length; ) {\n vestingList.push(_vestingInfo[i]);\n unchecked {\n i++;\n }\n }\n\n currentVestingType = _initialVestingType;\n startSale(false);\n }\n\n /**\n * Adding new admin to the contract\n * @param _admin - New admin to be added to administrator list\n */\n function addAdmin(address _admin) external onlyAdmin {\n _grantRole(DEFAULT_ADMIN_ROLE, _admin);\n }\n\n /**\n * Removing admin from token administrators list\n * @param _admin - Admin to be removed from admin list\n */\n function removeAdmin(address _admin) external onlyAdmin {\n if (_admin == owner) revert ONLY_OWNER();\n _revokeRole(DEFAULT_ADMIN_ROLE, _admin);\n }\n\n /**\n * Team Multisig Safe Vault\n * @param _newOwner - Contract owner address\n */\n function changeOwnership(address _newOwner) public onlyOwner {\n if (owner == _newOwner || _newOwner == address(0)) revert WRONG_ADDRESS();\n _revokeRole(DEFAULT_ADMIN_ROLE, owner);\n owner = _newOwner;\n _grantRole(DEFAULT_ADMIN_ROLE, _newOwner);\n }\n\n /**\n * Update Treasury\n * @param _treasuryAddress - New treasury multisig\n */\n function updateTreasury(address _treasuryAddress) public onlyOwner {\n treasuryAddress = _treasuryAddress;\n }\n\n /**\n * Start (or stop) the sale from happening\n * @param _start - Flag if sale should be started.\n */\n function startSale(bool _start) public onlyAdmin {\n sale = _start;\n }\n\n /**\n * Checks if given address has finished vesting.\n * @param _address - Address of the account being checked\n * @return True if given address is still locked. False otherwise.\n */\n function isLocked(address _address) public view returns (bool) {\n return block.timestamp < purchaserList[_address].vestingTimeFinish;\n }\n\n /**\n * Checks if given address is still being vested.\n * @param _address - Address of the account being checked.\n * @return True if given account is being vested anymore. False otherwise.\n */\n function checkVestingPeriod(address _address) public view returns (bool) {\n return block.timestamp > purchaserList[_address].firstUnlockTime;\n }\n\n /**\n * Adding new vesting type for vesting list.\n *\n * @param _vestingType - Struct defining new vesting level\n */\n\n function addVestingType(VestingInfo memory _vestingType)\n external\n onlyAdmin\n {\n uint256 index = vestingList.length;\n\n vestingList.push(_vestingType);\n\n emit VestingTypeAdded(index);\n }\n\n /**\n * Change vesting type.\n *\n * Switching vesting type to new level.\n * ATTENTION!: Vesting type can be only moved FORWARD so no going back to previous vestings\n *\n * @param _vestingType - Index of vesting to be switched to\n */\n function switchVesting(uint256 _vestingType) external onlyAdmin {\n if (\n _vestingType >= vestingList.length ||\n _vestingType <= currentVestingType\n ) {\n revert WRONG_VESTING_TYPE();\n }\n\n currentVestingType = _vestingType;\n emit VestingTypeChanged(_vestingType);\n }\n\n /**\n * Sets purchase and vesting information of given purchaser.\n *\n * Addresses added to this list will be blacklisted from moving XJoy tokens.\n * This is done to block trading these and use them only as a vesting token to retrieve Joy tokens after vesting period.\n * This contract will be listed as whitelisted contract to move tokens back at the end of the vesting season.\n * @param _addr - Address matched to information being set\n * @param _vestingIndex - Index of a vested address\n * @param _depositedTime - Timestamp of the deposit\n * @param _purchasedAmount - Amount of tokens purchased\n * @param _withdrawnAmount - Amount of tokens already withdrawn by the user\n */\n function addPurchase(\n address _addr,\n uint256 _vestingIndex,\n uint256 _depositedTime,\n uint256 _depositedAmount,\n uint256 _purchasedAmount,\n uint256 _withdrawnAmount\n ) external onlyAdmin {\n internalAddPurchase(\n _addr,\n _vestingIndex,\n _depositedTime,\n _depositedAmount,\n _purchasedAmount,\n _withdrawnAmount\n );\n }\n\n /**\n * Deliver vested tokens to list of users\n * @param _purchaserAddress - Addresses that should be vested\n * @param _purchaserList - List of purchasers\n * @param _transferToken - Should addresses receive tokens on top of being marked as vested\n */\n function addPurchasers(\n address[] memory _purchaserAddress,\n DepositInfo[] memory _purchaserList,\n bool _transferToken\n ) public onlyAdmin {\n for (uint256 i; i < _purchaserAddress.length; ) {\n addPurchaser(\n _purchaserAddress[i],\n _purchaserList[i].vestingType,\n _purchaserList[i].depositTime,\n _purchaserList[i].depositedAmount,\n _purchaserList[i].purchasedAmount,\n _transferToken\n );\n unchecked {\n i++;\n }\n }\n }\n\n /**\n * Add purchaser vesting schedule\n * @param _purchaserAddr - Address of the user to be vested\n * @param _vestingIndex - Index of the vested user\n * @param _depositedTime - Time of the deposit\n * @param _depositedAmount - Amount of the deposit\n * @param _purchasedAmount - Amount of tokens purchased\n * @param _transferToken - Should tokens be transfered\n */\n function addPurchaser(\n address _purchaserAddr,\n uint256 _vestingIndex,\n uint256 _depositedTime,\n uint256 _depositedAmount,\n uint256 _purchasedAmount,\n bool _transferToken\n ) public onlyAdmin {\n internalAddPurchase(\n _purchaserAddr,\n _vestingIndex,\n _depositedTime,\n _depositedAmount,\n _purchasedAmount,\n 0\n );\n if (_transferToken) {\n xJoyToken.transfer(_purchaserAddr, _purchasedAmount);\n }\n }\n\n /**\n * Lists all deposit history for given user\n * @param _address - purchaser to get deposit history of\n * @return An array of all deposit structures for given purchaser\n */\n function depositHistory(address _address)\n external\n view\n returns (DepositInfo[] memory)\n {\n return purchaserList[_address].deposits;\n }\n\n /**\n * Depositing a coin for xJoy token.\n * @param _coinAmount - Amount of tokens being deposited\n * @param _coinIndex - Index of the coin in contracts list\n */\n function deposit(uint256 _coinAmount, uint256 _coinIndex) external onSale {\n internalDeposit(\n _msgSender(),\n _coinAmount,\n _coinIndex,\n currentVestingType,\n block.timestamp\n );\n }\n\n /**\n * Withdrawing Joy tokens after vesting.\n * Amounts are automatically calculated based on current vesting plan and time.\n */\n function withdraw() external notVested(_msgSender()) {\n uint256 withdrawalAmount = calcWithdrawalAmount(_msgSender());\n uint256 xJoyTokenAmount = xJoyToken.balanceOf(address(_msgSender()));\n uint256 withdrawAmount = withdrawalAmount;\n\n if (withdrawAmount > xJoyTokenAmount) {\n withdrawAmount = xJoyTokenAmount;\n }\n\n if (withdrawAmount <= 0) revert NOTHING_TO_WITHDRAW();\n\n xJoyToken.transferFrom(_msgSender(), address(this), withdrawAmount);\n joyToken.transfer(_msgSender(), withdrawAmount);\n\n purchaserList[_msgSender()].withdrawnAmount += withdrawAmount;\n\n emit TokensWithdrawn(_msgSender(), withdrawAmount);\n }\n\n /**\n * Checks withdrawal limit for the address\n * @param _userAddr - Address that is checked for current limit\n * @return The amount of tokens address can currently withdraw\n */\n function calcWithdrawalAmount(address _userAddr)\n public\n view\n returns (uint256)\n {\n PurchaserInfo storage purchaserInfo = purchaserList[_userAddr];\n\n uint256 allowedAmount = 0;\n for (uint256 i = 0; i < purchaserInfo.deposits.length; ) {\n DepositInfo storage theDeposit = purchaserInfo.deposits[i];\n VestingInfo storage vesting = vestingList[theDeposit.vestingType];\n uint256 cliff = theDeposit.depositTime + vesting.cliff;\n if (block.timestamp > cliff) {\n if (\n block.timestamp >\n theDeposit.depositTime + vesting.vestingCloseTimeline\n ) {\n allowedAmount += theDeposit.purchasedAmount;\n } else {\n uint256 stepSize = (theDeposit.purchasedAmount * vesting.releasePercentBasisPoints) / 10000;\n uint256 stepsElapsed = (block.timestamp - cliff) / vesting.releaseStep;\n uint value = stepsElapsed * stepSize;\n if(value > theDeposit.purchasedAmount) {\n value = theDeposit.purchasedAmount;\n }\n allowedAmount += value;\n }\n }\n unchecked {\n i++;\n }\n }\n\n return allowedAmount - purchaserInfo.withdrawnAmount;\n }\n\n /**\n * Withdraws all coins transfered as deposits to owner.\n * @param _treasury - Treasury address to move all coins to.\n */\n function withdrawAllCoins(address _treasury) public onlyOwner {\n IERC20Metadata USDC = IERC20Metadata(USDC_Address);\n IUSDT USDT = IUSDT(USDT_Address);\n uint256 usdcAmount = USDC.balanceOf(address(this));\n uint256 usdtAmount = USDT.balanceOf(address(this));\n if (usdcAmount > 0) USDC.transfer(_treasury, usdcAmount);\n if (usdtAmount > 0) USDT.transfer(_treasury, usdtAmount);\n }\n\n /**\n * Withdraws all XJoy tokens to owner.\n * @param _treasury - Treasury address that should receive all xJoy tokens.\n */\n function withdrawAllxJoyTokens(address _treasury) public onlyOwner {\n uint256 tokenAmount = xJoyToken.balanceOf(address(this));\n xJoyToken.transfer(_treasury, tokenAmount);\n }\n\n /**\n * Performs real deposit in the contract.\n * @param _address - An address of the depositor\n * @param _coinAmount - Amount of coins being deposited\n * @param _coinIndex - Index of the coin being deposited\n * @param _vestingIndex - Index of the vesting\n * @param _depositTime - Time when deposit took place\n */\n function internalDeposit(\n address _address,\n uint256 _coinAmount,\n uint256 _coinIndex,\n uint256 _vestingIndex,\n uint256 _depositTime\n ) internal {\n if (_vestingIndex >= vestingList.length) {\n revert WRONG_VESTING_TYPE();\n }\n if (_coinIndex > 1) revert COINS_NOT_SET();\n\n if (_coinIndex == 0) {\n IERC20Metadata USDC = IERC20Metadata(USDC_Address);\n USDC.transferFrom(_address, treasuryAddress, _coinAmount);\n } else if (_coinIndex == 1) {\n IUSDT USDT = IUSDT(USDT_Address);\n USDT.transferFrom(_address, treasuryAddress, _coinAmount);\n }\n\n uint256 joyAmountStar = pairInfo(_coinAmount);\n xJoyToken.transfer(_address, joyAmountStar);\n\n internalAddPurchase(\n _address,\n _vestingIndex,\n _depositTime,\n _coinAmount,\n joyAmountStar,\n 0\n );\n emit TokensPurchased(_address, _coinAmount, joyAmountStar);\n }\n\n function internalAddPurchase(\n address _addr,\n uint256 _vestingIndex,\n uint256 _depositedTime,\n uint256 _depositedAmount,\n uint256 _purchasedAmount,\n uint256 _withdrawnAmount\n ) internal {\n if (_vestingIndex >= vestingList.length) {\n revert WRONG_VESTING_TYPE();\n }\n PurchaserInfo storage purchaserInfo = purchaserList[_addr];\n if (purchaserInfo.firstDepositTime == 0) {\n purchaserInfo.firstDepositTime = _depositedTime;\n purchaserAddress[totalPurchasers] = _addr;\n totalPurchasers += 1;\n xJoyToken.addToBlacklist(_addr);\n }\n\n // Get information about this vesting type\n VestingInfo storage vInfo = vestingList[uint256(_vestingIndex)];\n\n // calculate when vesting will finish\n uint256 vestingFinish = _depositedTime +\n vInfo.vestingCloseTimeline +\n vInfo.cliff;\n if (purchaserInfo.vestingTimeFinish < vestingFinish) {\n purchaserInfo.vestingTimeFinish = vestingFinish;\n }\n\n // Calculate new vestings cliff date\n uint256 unlockTime = _depositedTime + vInfo.cliff;\n if (\n purchaserInfo.firstUnlockTime > unlockTime ||\n purchaserInfo.firstUnlockTime == 0\n ) {\n purchaserInfo.firstUnlockTime = unlockTime;\n }\n\n // Update global amount of withdrawn amount by purchaser\n purchaserInfo.withdrawnAmount += _withdrawnAmount;\n\n // Last but not least - we need to add history of purchase\n purchaserInfo.deposits.push(\n DepositInfo(\n _vestingIndex,\n _depositedAmount,\n _purchasedAmount,\n _depositedTime\n )\n );\n }\n\n function pairInfo(uint256 _joyAmount)\n public\n view\n returns (uint256 joyAmountStar)\n {\n if (_joyAmount < 1e4) revert MIN_ONE_CENT();\n address FACTORY_ADDRESS = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;\n IUniswapV2Pair pair = IUniswapV2Pair(\n UniswapV2Library.pairFor(\n FACTORY_ADDRESS,\n address(joyToken),\n USDC_Address\n )\n );\n if (address(pair) == address(0)) revert PAIR_NOT_SET();\n (uint256 reserves0, uint256 reserves1, ) = pair.getReserves();\n (uint256 reserveA, uint256 reserveB) = USDC_Address == pair.token0()\n ? (reserves1, reserves0)\n : (reserves0, reserves1);\n uint256 numerator = 1e6 * reserveA; // Joy Reserve\n uint256 denominator = reserveB; // USDC Reserve\n uint256 amountOutCents = (numerator / denominator) / 1e2; // 1 cent of USDC\n uint256 joyAmountInJoy = _joyAmount / 1e4; // 1 cent of JOY\n uint256 joyAmountInCalcInCents = joyAmountInJoy * amountOutCents; // Total Joy in cents\n joyAmountStar =\n joyAmountInCalcInCents +\n ((joyAmountInCalcInCents / 100) * 55); // 55% Discount\n }\n}\n" }, "contracts/JoyToken.sol": { "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.11;\n\nimport \"./extensions/SecureToken.sol\";\n\nerror DISABLED();\nerror ALLOWED_WHITELISTED_FROM();\nerror ALLOWED_WHITELISTED_TO(); \nerror SWAP_IS_COOLING_DOWN();\n\ncontract JoyToken is SecureToken {\n\n enum TransferMode {\n DISABLED,\n ALLOWED_ALL,\n ALLOWED_WHITELISTED_FROM,\n ALLOWED_WHITELISTED_TO,\n ALLOWED_WHITELISTED_FROM_TO\n }\n\n TransferMode public transferMode;\n \n mapping (address => uint256) private swapBlock;\n\n bool public swapGuarded;\n\n /**\n * Joy Token constructor\n * @param _whitelist - Initial list of whitelisted receivers\n * @param _blacklist - Initial list of blacklisted addresses\n * @param _admins - Initial list of all administrators of the token\n */\n constructor(\n address[] memory _whitelist, \n address[] memory _blacklist, \n address[] memory _admins\n )\n SecureToken(_whitelist, _blacklist, _admins, \"Joystick\", \"JOY\") \n {\n transferMode = TransferMode.ALLOWED_ALL;\n }\n\n /**\n * Setting new transfer mode for the token\n * @param _mode - New transfer mode to be set\n */\n function setTransferMode(TransferMode _mode) public onlyAdmin {\n transferMode = _mode;\n }\n\n /**\n * Checking transfer status\n * @param from - Transfer sender\n * @param to - Transfer recipient\n */\n function _checkTransferStatus(address from, address to) private view {\n if(transferMode == TransferMode.DISABLED) revert DISABLED();\n \n if(transferMode == TransferMode.ALLOWED_WHITELISTED_FROM_TO) {\n if(blacklisted[from] || !whitelisted[from]) revert ALLOWED_WHITELISTED_FROM(); \n if(blacklisted[to] || !whitelisted[to]) revert ALLOWED_WHITELISTED_TO();\n return;\n }\n\n if(transferMode == TransferMode.ALLOWED_WHITELISTED_FROM) {\n if(blacklisted[from] || !whitelisted[from]) revert ALLOWED_WHITELISTED_FROM(); \n return;\n }\n\n if (transferMode == TransferMode.ALLOWED_WHITELISTED_TO) {\n if(blacklisted[to] || !whitelisted[to]) revert ALLOWED_WHITELISTED_TO();\n return;\n }\n }\n\n /**\n * Prevent MEV Bots from doing Sandwich Attacks and Arbitrage\n * Enforces a single JOY Transfer per transaction\n * @param _swapGuardStatus - True or false\n */\n function setProtectedSwaps(bool _swapGuardStatus) external onlyOwner {\n swapGuarded = _swapGuardStatus;\n }\n\n /**\n * Enforces atleast 1 block gap for swaps and transfers\n * This prevents MEV Bots (Maximal Extractable Value)\n * @param from - Address of sender\n * @param to - Address of recipient\n */\n function _checkSwapCooldown(address from, address to) private {\n if(swapGuarded) {\n if(swapBlock[from] == block.number) revert SWAP_IS_COOLING_DOWN();\n swapBlock[to] = block.number;\n }\n }\n\n function _beforeTokenTransfer(address from, address to, uint256) override internal virtual {\n _checkTransferStatus(from, to);\n _checkSwapCooldown(from, to);\n }\n}\n" }, "contracts/xJoyToken.sol": { "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.11;\n\nimport \"./extensions/SecureToken.sol\";\n\ncontract XJoyToken is SecureToken {\n /**\n * Flag indicating if contract is guarding transfers from blacklisted sources and sniper attacks\n */\n bool public guarding;\n\n event Guarding(bool _status);\n\n /**\n * Tokens constructor\n *\n * @param _whitelist - Initial list of whitelisted receivers\n * @param _blacklist - Initial list of blacklisted addresses\n * @param _admins - Initial list of all administrators of the token\n * @param _guarding - If SecureToken is guarding the transfers from the constructor moment\n */\n constructor(\n address[] memory _whitelist,\n address[] memory _blacklist,\n address[] memory _admins,\n bool _guarding,\n uint256 _initialSupply\n )\n SecureToken(\n _whitelist,\n _blacklist,\n _admins,\n \"xJOY Token\",\n \"xJOY\"\n )\n {\n guarding = _guarding;\n mint(_msgSender(), _initialSupply);\n }\n\n /**\n * Turning on or off guarding mechanism of the contract\n *\n * @param _guard - Flag if guarding mechanism should be turned on or off\n */\n function setGuard(bool _guard) external onlyAdmin {\n if (guarding != _guard) {\n guarding = _guard;\n emit Guarding(_guard);\n }\n }\n\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256\n ) internal virtual override {\n if (guarding) {\n require(!blacklisted[from] || whitelisted[to], \"SecureToken: This address is forbidden from making any transfers\");\n }\n }\n \n}\n" }, "contracts/interfaces/IUniswapV2Pair.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.11;\n\ninterface IUniswapV2Pair {\n event Approval(address indexed owner, address indexed spender, uint256 value);\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n function name() external pure returns (string memory);\n\n function symbol() external pure returns (string memory);\n\n function decimals() external pure returns (uint8);\n\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address owner) external view returns (uint256);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 value) external returns (bool);\n\n function transfer(address to, uint256 value) external returns (bool);\n\n function transferFrom(\n address from,\n address to,\n uint256 value\n ) external returns (bool);\n\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n function nonces(address owner) external view returns (uint256);\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 event Mint(address indexed sender, uint256 amount0, uint256 amount1);\n event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);\n event Swap(\n address indexed sender,\n uint256 amount0In,\n uint256 amount1In,\n uint256 amount0Out,\n uint256 amount1Out,\n address indexed to\n );\n event Sync(uint112 reserve0, uint112 reserve1);\n\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\n\n function factory() external view returns (address);\n\n function token0() external view returns (address);\n\n function token1() external view returns (address);\n\n function getReserves()\n external\n view\n returns (\n uint112 reserve0,\n uint112 reserve1,\n uint32 blockTimestampLast\n );\n\n function price0CumulativeLast() external view returns (uint256);\n\n function price1CumulativeLast() external view returns (uint256);\n\n function kLast() external view returns (uint256);\n\n function mint(address to) external returns (uint256 liquidity);\n\n function burn(address to) external returns (uint256 amount0, uint256 amount1);\n\n function swap(\n uint256 amount0Out,\n uint256 amount1Out,\n address to,\n bytes calldata data\n ) external;\n\n function skim(address to) external;\n\n function sync() external;\n\n function initialize(address, address) external;\n}" }, "contracts/interfaces/IUSDT.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.5.0;\n\ninterface IUSDT {\n function balanceOf(address account) external view returns (uint256);\n function transfer(address to, uint256 amount) external;\n function approve(address spender, uint value) external;\n function transferFrom(address from, address to, uint value) external;\n function allowance(address owner, address spender) external view returns (uint);\n event Approval(address indexed owner, address indexed spender, uint value);\n event Transfer(address indexed from, address indexed to, uint value);\n}" }, "contracts/libraries/UniswapV2Library.sol": { "content": "// SPDX-License-Identifier: UNLICENCED\npragma solidity =0.8.11;\n\nimport '../interfaces/IUniswapV2Pair.sol';\n\nlibrary UniswapV2Library {\n // returns sorted token addresses, used to handle return values from pairs sorted in this order\n function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {\n require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');\n (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');\n }\n\n // calculates the CREATE2 address for a pair without making any external calls\n function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {\n (address token0, address token1) = sortTokens(tokenA, tokenB);\n bytes32 tmp = keccak256(abi.encodePacked(\n hex'ff',\n factory,\n keccak256(abi.encodePacked(token0, token1)),\n hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash\n ));\n pair = address(uint160(uint256(tmp)));\n }\n\n // fetches and sorts the reserves for a pair\n function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {\n (address token0,) = sortTokens(tokenA, tokenB);\n (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();\n (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);\n }\n\n // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset\n function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {\n require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');\n require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');\n amountB = (amountA * reserveB) / reserveA;\n }\n\n // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset\n function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {\n require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');\n require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');\n uint amountInWithFee = amountIn * 997;\n uint numerator = amountInWithFee * reserveOut;\n uint denominator = (reserveIn * 1000) + amountInWithFee;\n amountOut = numerator / denominator;\n }\n\n // given an output amount of an asset and pair reserves, returns a required input amount of the other asset\n function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {\n require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');\n require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');\n uint numerator = (reserveIn * amountOut) * 1000;\n uint denominator = (reserveOut -amountOut) * 997;\n amountIn = (numerator / denominator) + 1;\n }\n\n // performs chained getAmountOut calculations on any number of pairs\n function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {\n require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');\n amounts = new uint[](path.length);\n amounts[0] = amountIn;\n for (uint i; i < path.length - 1; i++) {\n (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);\n amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);\n }\n }\n\n // performs chained getAmountIn calculations on any number of pairs\n function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {\n require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');\n amounts = new uint[](path.length);\n amounts[amounts.length - 1] = amountOut;\n for (uint i = path.length - 1; i > 0; i--) {\n (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);\n amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);\n }\n }\n}" }, "@openzeppelin/contracts/access/AccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(uint160(account), 20),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n" }, "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\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" }, "contracts/extensions/SecureToken.sol": { "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.11;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\nerror NOT_AUTHORIZED();\nerror MAX_TOTAL_SUPPLY();\n\ncontract SecureToken is AccessControl, ERC20, Ownable {\n /**\n * Maximum totalSupply \n */\n uint256 public maxTotalSupply;\n\n /**\n * A map of all blacklisted addresses\n */\n mapping(address => bool) public blacklisted;\n\n /**\n * A map of whitelisted receivers.\n */\n mapping(address => bool) public whitelisted;\n\n event WhitelistedMany(address[] _users);\n event Whitelisted(address _user);\n event RemovedFromWhitelist(address _user);\n\n event BlacklistedMany(address[] _users);\n event Blacklisted(address _user);\n event RemovedFromBlacklist(address _user);\n\n modifier onlyAdmin() {\n _checkRole(DEFAULT_ADMIN_ROLE);\n _;\n }\n\n /**\n * Constructor of SecureToken contract\n * @param _whitelist - List of addresses to be whitelisted as always allowed token transfering\n * @param _blacklist - Initial blacklisted addresses to forbid any token transfers\n * @param _admins - List of administrators that can change this contract settings\n */\n constructor(\n address[] memory _whitelist,\n address[] memory _blacklist,\n address[] memory _admins,\n string memory _name,\n string memory _symbol\n ) ERC20(_name, _symbol) {\n _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);\n\n maxTotalSupply = 5000000000 * 1e18; // 5B Joy & xJoy\n\n if (_admins.length > 0) {\n for (uint i; i < _admins.length; ) {\n _grantRole(DEFAULT_ADMIN_ROLE, _admins[i]);\n unchecked { i++; }\n }\n }\n\n if (_whitelist.length > 0) {\n addManyToWhitelist(_whitelist);\n }\n if (_blacklist.length > 0) {\n addManyToBlacklist(_blacklist);\n }\n }\n\n /**\n * Adding new admin to the contract\n * @param _admin - New admin to be added to administrator list\n */\n function addAdmin(address _admin) external onlyAdmin {\n _grantRole(DEFAULT_ADMIN_ROLE, _admin);\n }\n\n /**\n * Removing admin from token administrators list\n * @param _admin - Admin to be removed from admin list\n */\n function removeAdmin(address _admin) external onlyAdmin {\n if (_admin == owner()) revert NOT_AUTHORIZED();\n _revokeRole(DEFAULT_ADMIN_ROLE, _admin);\n }\n \n /**\n * Minting tokens for many addressess\n * @param _addrs - Address to mint new tokens to\n * @param _amounts - Amount new tokens to be minted\n */\n function mintMany(address[] memory _addrs, uint256[] memory _amounts) external onlyOwner {\n uint256 totalMinted;\n for (uint i=0; i<_addrs.length; i++) {\n _mint(_addrs[i], _amounts[i]);\n totalMinted += _amounts[i];\n }\n if(totalSupply() > maxTotalSupply) revert MAX_TOTAL_SUPPLY();\n }\n\n /**\n * Minting new tokens\n * @param _to - Address to mint new tokens to\n * @param _amount - Amount new tokens to be minted\n */\n function mint(address _to, uint256 _amount) public onlyOwner {\n if(totalSupply() + _amount > maxTotalSupply) revert MAX_TOTAL_SUPPLY();\n _mint(_to, _amount);\n }\n\n /**\n * Burning existing tokens\n * @param _from - Address to burn tokens from\n * @param _amount - Amount of tokens to be burned\n */\n function burn(address _from, uint256 _amount) public onlyOwner {\n _burn(_from, _amount);\n }\n\n /**\n * Adding new address to the blacklist\n * @param _blacklisted - New address to be added to the blacklist\n */\n function addToBlacklist(address _blacklisted) public onlyAdmin {\n blacklisted[_blacklisted] = true;\n emit Blacklisted(_blacklisted);\n }\n\n /**\n * Adding many addresses to the blacklist\n * @param _blacklisted - An array of addresses to be added to the blacklist\n */\n function addManyToBlacklist(address[] memory _blacklisted) public onlyAdmin {\n for (uint i; i < _blacklisted.length; ) {\n blacklisted[_blacklisted[i]] = true;\n unchecked { i++; }\n }\n emit BlacklistedMany(_blacklisted);\n }\n\n /**\n * Removing address from the blacklist\n * @param _address - Address to be removed from the blacklist\n */\n function removeFromBlacklist(address _address) public onlyAdmin {\n blacklisted[_address] = false;\n emit RemovedFromBlacklist(_address);\n }\n\n /**\n * Adding an address to contracts whitelist\n * @param _whitelisted - Address to be added to the whitelist\n */\n function addToWhitelist(address _whitelisted) public onlyAdmin {\n whitelisted[_whitelisted] = true;\n emit Whitelisted(_whitelisted);\n }\n\n /**\n * Adding many addresses to the whitelist\n * @param _whitelisted - An array of addresses to be added to the whitelist\n */\n function addManyToWhitelist(address[] memory _whitelisted) public onlyAdmin {\n for (uint i; i < _whitelisted.length; ) {\n whitelisted[_whitelisted[i]] = true;\n unchecked { i++; }\n }\n emit WhitelistedMany(_whitelisted);\n }\n\n /**\n * Removing an address from the whitelist\n * @param _address - Address to be removed from the whitelist\n */\n function removeFromWhitelist(address _address) public onlyAdmin {\n whitelisted[_address] = false;\n emit RemovedFromWhitelist(_address);\n }\n\n}\n" }, "@openzeppelin/contracts/token/ERC20/ERC20.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.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 * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\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 *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => 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 * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\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 override 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 override 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 value {ERC20} uses, unless this function is\n * 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 override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override 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 `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` 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 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\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 `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `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 * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` 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 function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../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 * By default, the owner account will be the one that deploys the contract. This\n * can 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 event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\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 require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing 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 require(newOwner != address(0), \"Ownable: new owner is the zero address\");\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/utils/Context.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\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" }, "@openzeppelin/contracts/token/ERC20/IERC20.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\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 amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` 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 amount) 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 `amount` as the allowance of `spender` over the 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 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` 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(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n" }, "@openzeppelin/contracts/access/IAccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n" }, "@openzeppelin/contracts/utils/Strings.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n" }, "@openzeppelin/contracts/utils/introspection/ERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" }, "@openzeppelin/contracts/utils/introspection/IERC165.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 1337 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }