{ "language": "Solidity", "sources": { "contracts/vaults/strategies/BAYCApeStakingStrategy.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\nimport \"./AbstractApeStakingStrategy.sol\";\n\ncontract BAYCApeStakingStrategy is AbstractApeStakingStrategy {\n function _depositSelector() internal pure override returns (bytes4) {\n return IApeStaking.depositBAYC.selector;\n }\n\n function _withdrawSelector() internal pure override returns (bytes4) {\n return IApeStaking.withdrawBAYC.selector;\n }\n\n function _claimSelector() internal pure override returns (bytes4) {\n return IApeStaking.claimBAYC.selector;\n }\n\n function _depositBAKCCalldata(\n IApeStaking.PairNftDepositWithAmount[] calldata _nfts\n ) internal pure override returns (bytes memory) {\n return\n abi.encodeWithSelector(\n IApeStaking.depositBAKC.selector,\n _nfts,\n new IApeStaking.PairNftDepositWithAmount[](0)\n );\n }\n\n function _withdrawBAKCCalldata(IApeStaking.PairNftWithdrawWithAmount[] memory _nfts)\n internal\n pure\n override\n returns (bytes memory)\n {\n return\n abi.encodeWithSelector(\n IApeStaking.withdrawBAKC.selector,\n _nfts,\n new IApeStaking.PairNftWithdrawWithAmount[](0)\n );\n }\n\n function _claimBAKCCalldata(\n IApeStaking.PairNft[] memory _nfts,\n address _recipient\n ) internal pure override returns (bytes memory) {\n return\n abi.encodeWithSelector(\n IApeStaking.claimBAKC.selector,\n _nfts,\n new IApeStaking.PairNft[](0),\n _recipient\n );\n }\n}\n" }, "contracts/vaults/strategies/AbstractApeStakingStrategy.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\nimport \"@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\";\n\nimport \"../../interfaces/IStandardNFTStrategy.sol\";\nimport \"../../interfaces/IApeStaking.sol\";\nimport \"../../interfaces/ISimpleUserProxy.sol\";\n\nabstract contract AbstractApeStakingStrategy is\n AccessControlUpgradeable,\n PausableUpgradeable,\n IStandardNFTStrategy\n{\n using SafeERC20Upgradeable for IERC20Upgradeable;\n using AddressUpgradeable for address;\n\n error ZeroAddress();\n error InvalidLength();\n error Unauthorized();\n error FlashLoanFailed();\n\n bytes32 public constant VAULT_ROLE = keccak256(\"VAULT_ROLE\");\n\n IApeStaking public apeStaking;\n IERC20Upgradeable public ape;\n address public mainNftContract;\n IERC721Upgradeable public bakcContract;\n uint256 public mainPoolId;\n uint256 public bakcPoolId;\n\n address public clonesImplementation;\n\n function initialize(\n address _apeStaking,\n address _ape,\n address _mainNftContract,\n address _bakcContract,\n uint256 _mainPoolId,\n uint256 _backPoolId,\n address _clonesImplementation\n ) external initializer {\n if (_apeStaking == address(0)) revert ZeroAddress();\n\n if (_ape == address(0)) revert ZeroAddress();\n\n if (_mainNftContract == address(0)) revert ZeroAddress();\n\n if (_bakcContract == address(0)) revert ZeroAddress();\n\n if (_clonesImplementation == address(0)) revert ZeroAddress();\n\n _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);\n\n apeStaking = IApeStaking(_apeStaking);\n ape = IERC20Upgradeable(_ape);\n mainNftContract = _mainNftContract;\n bakcContract = IERC721Upgradeable(_bakcContract);\n mainPoolId = _mainPoolId;\n bakcPoolId = _backPoolId;\n clonesImplementation = _clonesImplementation;\n\n _pause();\n }\n\n function kind() external pure override returns (Kind) {\n return Kind.STANDARD;\n }\n\n /// @return The user proxy address for `_account`\n function depositAddress(address _account)\n public\n view\n override\n returns (address)\n {\n return\n ClonesUpgradeable.predictDeterministicAddress(\n clonesImplementation,\n _salt(_account)\n );\n }\n\n function isDeposited(address _owner, uint256 _nftIndex)\n external\n view\n override\n returns (bool)\n {\n return\n IERC721Upgradeable(mainNftContract).ownerOf(_nftIndex) ==\n ClonesUpgradeable.predictDeterministicAddress(\n clonesImplementation,\n _salt(_owner)\n );\n }\n\n function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {\n _pause();\n }\n\n function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {\n _unpause();\n }\n\n /// @notice Function called by the NFT Vault after sending NFTs to the address calculated by {depositAddress}.\n /// Deploys a clone contract at `depositAddress(_owner)` if it doesn't exist and stakes APE tokens\n /// @param _owner The owner of the NFTs that have been deposited\n /// @param _nftIndexes The indexes of the NFTs that have been deposited\n /// @param _data Array containing the amounts of tokens to stake with the NFTs\n function afterDeposit(\n address _owner,\n uint256[] calldata _nftIndexes,\n bytes calldata _data\n ) external override onlyRole(VAULT_ROLE) {\n uint256 totalAmount;\n IApeStaking.SingleNft[] memory nfts;\n\n uint256[] memory amounts = abi.decode(_data, (uint256[]));\n uint256 length = amounts.length;\n if (length != _nftIndexes.length) revert InvalidLength();\n\n nfts = new IApeStaking.SingleNft[](length);\n\n for (uint256 i; i < length; ++i) {\n uint256 amount = amounts[i];\n totalAmount += amount;\n nfts[i] = IApeStaking.SingleNft({\n tokenId: uint32(_nftIndexes[i]),\n amount: uint224(amount)\n });\n }\n\n address implementation = clonesImplementation;\n bytes32 salt = _salt(_owner);\n address clone = ClonesUpgradeable.predictDeterministicAddress(\n implementation,\n salt\n );\n\n IERC20Upgradeable _ape = ape;\n _ape.safeTransferFrom(_owner, clone, totalAmount);\n\n IApeStaking _apeStaking = apeStaking;\n\n if (!clone.isContract()) {\n ClonesUpgradeable.cloneDeterministic(implementation, salt);\n ISimpleUserProxy(clone).initialize(address(this));\n ISimpleUserProxy(clone).doCall(\n address(_ape),\n abi.encodeWithSelector(\n IERC20Upgradeable.approve.selector,\n address(_apeStaking),\n 2**256 - 1\n )\n );\n }\n\n ISimpleUserProxy(clone).doCall(\n address(_apeStaking),\n abi.encodeWithSelector(_depositSelector(), nfts)\n );\n }\n\n /// @notice Function called by the NFT Vault to withdraw an NFT from the strategy.\n /// Staked APE tokens and the committed BAKC (if there is one) are sent back to `_owner`\n /// @param _owner The owner of the NFT to withdraw\n /// @param _recipient The address to send the NFT to\n /// @param _nftIndex Index of the NFT to withdraw\n function withdraw(\n address _owner,\n address _recipient,\n uint256 _nftIndex\n ) external override onlyRole(VAULT_ROLE) {\n address clone = _getCloneOrRevert(_owner);\n\n IApeStaking _apeStaking = apeStaking;\n uint256 _mainPoolId = mainPoolId;\n\n {\n (uint256 stakedAmount, ) = _apeStaking.nftPosition(\n _mainPoolId,\n _nftIndex\n );\n if (stakedAmount > 0) {\n IApeStaking.SingleNft[]\n memory nfts = new IApeStaking.SingleNft[](1);\n nfts[0] = IApeStaking.SingleNft({\n tokenId: uint32(_nftIndex),\n amount: uint224(stakedAmount)\n });\n\n ISimpleUserProxy(clone).doCall(\n address(_apeStaking),\n abi.encodeWithSelector(_withdrawSelector(), nfts, _owner)\n );\n }\n }\n\n {\n (uint256 bakcIndex, bool isPaired) = _apeStaking.mainToBakc(\n _mainPoolId,\n _nftIndex\n );\n if (isPaired) {\n {\n (uint256 stakedAmount, ) = _apeStaking.nftPosition(\n bakcPoolId,\n bakcIndex\n );\n IApeStaking.PairNftWithdrawWithAmount[]\n memory nfts = new IApeStaking.PairNftWithdrawWithAmount[](\n 1\n );\n nfts[0] = IApeStaking.PairNftWithdrawWithAmount({\n mainTokenId: uint32(_nftIndex),\n bakcTokenId: uint32(bakcIndex),\n amount: uint184(stakedAmount),\n isUncommit: true\n });\n ISimpleUserProxy(clone).doCall(\n address(_apeStaking),\n _withdrawBAKCCalldata(nfts)\n );\n }\n\n IERC20Upgradeable _ape = ape;\n uint256 balance = _ape.balanceOf(clone);\n\n ISimpleUserProxy(clone).doCall(\n address(_ape),\n abi.encodeWithSelector(\n _ape.transfer.selector,\n _owner,\n balance\n )\n );\n\n ISimpleUserProxy(clone).doCall(\n address(bakcContract),\n abi.encodeWithSelector(\n IERC721Upgradeable.transferFrom.selector,\n clone,\n _owner,\n bakcIndex\n )\n );\n }\n }\n\n ISimpleUserProxy(clone).doCall(\n mainNftContract,\n abi.encodeWithSelector(\n IERC721Upgradeable.transferFrom.selector,\n clone,\n _recipient,\n _nftIndex\n )\n );\n }\n\n /// @dev Allows the vault to flash loan the NFTs without having to withdraw them from this strategy.\n /// Useful for claiming airdrops. Can only be called by the vault.\n /// This function assumes that the vault will also call {flashLoanEnd}.\n /// It's not an actual flash loan function as it doesn't expect the NFTs to be returned at the end of the call,\n /// but instead it trusts the vault to do the necessary safety checks.\n /// @param _owner The owner of the NFTs to flash loan\n /// @param _recipient The address to send the NFTs to\n /// @param _nftIndexes The NFTs to send (main collection - BAYC/MAYC)\n /// @param _additionalData ABI encoded `uint256` array containing the list of BAKC IDs to send \n function flashLoanStart(\n address _owner,\n address _recipient,\n uint256[] memory _nftIndexes,\n bytes calldata _additionalData\n ) external override onlyRole(VAULT_ROLE) returns (address) {\n uint256 _length = _nftIndexes.length;\n if (_length == 0) revert InvalidLength();\n\n address _clone = _getCloneOrRevert(_owner);\n address _nftContract = mainNftContract;\n for (uint256 i; i < _length; ++i) {\n ISimpleUserProxy(_clone).doCall(\n _nftContract,\n abi.encodeWithSelector(\n IERC721Upgradeable.transferFrom.selector,\n _clone,\n _recipient,\n _nftIndexes[i]\n )\n );\n }\n\n //reused to avoid stack too deep\n _nftIndexes = abi.decode(_additionalData, (uint256[]));\n _length = _nftIndexes.length;\n\n if (_length > 0) {\n _nftContract = address(bakcContract);\n for (uint256 i; i < _length; ++i) {\n ISimpleUserProxy(_clone).doCall(\n _nftContract,\n abi.encodeWithSelector(\n IERC721Upgradeable.transferFrom.selector,\n _clone,\n _recipient,\n _nftIndexes[i]\n )\n );\n }\n }\n\n return _clone;\n }\n\n /// @dev Flash loan end function. Checks if the BAKCs in `_additionalData` have been returned.\n /// It doesn't perform any safety checks on the main collection IDs as they are already done by the vault.\n /// @param _owner The owner of the returned NFTs\n /// @param _additionalData Array containing the list of BAKC ids returned.\n function flashLoanEnd(\n address _owner,\n uint256[] calldata,\n bytes calldata _additionalData\n ) external view override onlyRole(VAULT_ROLE) {\n IERC721Upgradeable _bakcContract = bakcContract;\n uint256[] memory _bakcIndexes = abi.decode(\n _additionalData,\n (uint256[])\n );\n uint256 _length = _bakcIndexes.length;\n if (_length > 0) {\n address _clone = _getCloneOrRevert(_owner);\n for (uint256 i; i < _length; ++i) {\n if (_bakcContract.ownerOf(_bakcIndexes[i]) != _clone)\n revert FlashLoanFailed();\n }\n }\n }\n\n /// @notice Allows users to stake additional tokens for NFTs that have already been deposited in the strategy\n /// @param _nfts NFT IDs and token amounts to deposit\n function stakeTokensMain(IApeStaking.SingleNft[] calldata _nfts) external {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n address clone = _getCloneOrRevert(msg.sender);\n\n uint256 totalAmount;\n for (uint256 i; i < length; ++i) {\n totalAmount += _nfts[i].amount;\n }\n\n ape.safeTransferFrom(msg.sender, clone, totalAmount);\n\n ISimpleUserProxy(clone).doCall(\n address(apeStaking),\n abi.encodeWithSelector(_depositSelector(), _nfts)\n );\n }\n\n /// @notice Allows users to pair their committed NFTs with BAKCs in the BAKC pool and increase their APE stake.\n /// Automatically commits the BAKCs specified in `_nfts` if they aren't already\n /// @param _nfts NFT IDs, BAKC IDs and token amounts to deposit\n function stakeTokensBAKC(\n IApeStaking.PairNftDepositWithAmount[] calldata _nfts\n ) external {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n address clone = _getCloneOrRevert(msg.sender);\n\n uint256 totalAmount;\n IERC721Upgradeable bakc = bakcContract;\n for (uint256 i; i < length; i++) {\n IApeStaking.PairNftDepositWithAmount memory pair = _nfts[i];\n\n if (bakc.ownerOf(pair.bakcTokenId) != clone)\n bakc.transferFrom(msg.sender, clone, pair.bakcTokenId);\n\n totalAmount += _nfts[i].amount;\n }\n\n ape.safeTransferFrom(msg.sender, clone, totalAmount);\n\n ISimpleUserProxy(clone).doCall(\n address(apeStaking),\n _depositBAKCCalldata(_nfts)\n );\n }\n\n /// @notice Allows users to withdraw tokens from NFTs that have been deposited in the strategy\n /// @param _nfts NFT IDs and token amounts to withdraw\n /// @param _recipient The address to send the tokens to\n function withdrawTokensMain(\n IApeStaking.SingleNft[] calldata _nfts,\n address _recipient\n ) external {\n if (_nfts.length == 0) revert InvalidLength();\n\n ISimpleUserProxy clone = ISimpleUserProxy(\n _getCloneOrRevert(msg.sender)\n );\n\n clone.doCall(\n address(apeStaking),\n abi.encodeWithSelector(_withdrawSelector(), _nfts, _recipient)\n );\n }\n\n /// @notice Allows users to withdraw tokens deposited in the BAKC pool\n /// @param _nfts NFT IDs, BAKC IDs and token amounts to withdraw\n /// @param _recipient The Address to send the tokens to\n function withdrawTokensBAKC(\n IApeStaking.PairNftWithdrawWithAmount[] calldata _nfts,\n address _recipient\n ) external {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n address clone = _getCloneOrRevert(msg.sender);\n\n ISimpleUserProxy(clone).doCall(\n address(apeStaking),\n _withdrawBAKCCalldata(_nfts)\n );\n\n //the withdrawBAKC function in ApeStaking lacks a recipient argument, so we have to manually send APE tokens\n IERC20Upgradeable _ape = ape;\n uint256 balance = _ape.balanceOf(clone);\n\n ISimpleUserProxy(clone).doCall(\n address(_ape),\n abi.encodeWithSelector(_ape.transfer.selector, _recipient, balance)\n );\n }\n\n /// @notice Allows users to withdraw committed BAKC NFTs.\n /// @param _nfts The BAKC IDs to withdraw\n /// @param _recipient The address to send NFTs to\n function withdrawBAKC(uint256[] calldata _nfts, address _recipient)\n external\n {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n address clone = _getCloneOrRevert(msg.sender);\n\n IApeStaking _apeStaking = apeStaking;\n address _bakcContract = address(bakcContract);\n\n uint256 _mainPoolId = mainPoolId;\n for (uint256 i; i < length; ++i) {\n uint256 index = _nfts[i];\n\n (uint256 mainIndex, bool isPaired) = _apeStaking.bakcToMain(\n _nfts[i],\n _mainPoolId\n );\n if (isPaired) {\n IApeStaking.PairNftWithdrawWithAmount[]\n memory pairs = new IApeStaking.PairNftWithdrawWithAmount[](\n 1\n );\n pairs[0] = IApeStaking.PairNftWithdrawWithAmount({\n mainTokenId: uint32(mainIndex),\n bakcTokenId: uint32(index),\n amount: 0, //isUncommit set to true sends back the whole staked amount\n isUncommit: true\n });\n\n ISimpleUserProxy(clone).doCall(\n address(_apeStaking),\n _withdrawBAKCCalldata(pairs)\n );\n }\n\n ISimpleUserProxy(clone).doCall(\n _bakcContract,\n abi.encodeWithSelector(\n IERC721Upgradeable.transferFrom.selector,\n clone,\n _recipient,\n index\n )\n );\n }\n\n //the withdrawBAKC function in ApeStaking lacks a recipient argument, so we have to manually send APE tokens\n IERC20Upgradeable _ape = ape;\n uint256 balance = _ape.balanceOf(clone);\n\n ISimpleUserProxy(clone).doCall(\n address(_ape),\n abi.encodeWithSelector(_ape.transfer.selector, _recipient, balance)\n );\n }\n\n /// @notice Allows users to claim rewards from the Ape staking contract\n /// @param _nfts NFT IDs to claim tokens for\n function claimMain(uint256[] memory _nfts, address _recipient) external {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n ISimpleUserProxy clone = ISimpleUserProxy(\n _getCloneOrRevert(msg.sender)\n );\n clone.doCall(\n address(apeStaking),\n abi.encodeWithSelector(_claimSelector(), _nfts, _recipient)\n );\n }\n\n /// @notice Allows users to claim rewards from the BAKC pool\n /// @param _nfts Pair NFT IDs to claim for\n function claimBAKC(IApeStaking.PairNft[] calldata _nfts, address _recipient)\n external\n {\n uint256 length = _nfts.length;\n if (length == 0) revert InvalidLength();\n\n ISimpleUserProxy clone = ISimpleUserProxy(\n _getCloneOrRevert(msg.sender)\n );\n clone.doCall(\n address(apeStaking),\n _claimBAKCCalldata(_nfts, _recipient)\n );\n }\n\n function _getCloneOrRevert(address _account)\n internal\n view\n returns (address clone)\n {\n clone = depositAddress(_account);\n if (!clone.isContract()) revert Unauthorized();\n }\n\n function _salt(address _address) internal pure returns (bytes32) {\n return keccak256(abi.encode(_address));\n }\n\n function _depositSelector() internal view virtual returns (bytes4);\n\n function _withdrawSelector() internal view virtual returns (bytes4);\n\n function _claimSelector() internal view virtual returns (bytes4);\n\n function _depositBAKCCalldata(\n IApeStaking.PairNftDepositWithAmount[] calldata _nfts\n ) internal view virtual returns (bytes memory);\n\n function _withdrawBAKCCalldata(\n IApeStaking.PairNftWithdrawWithAmount[] memory _nfts\n ) internal view virtual returns (bytes memory);\n\n function _claimBAKCCalldata(\n IApeStaking.PairNft[] memory _nfts,\n address _recipient\n ) internal view virtual returns (bytes memory);\n}\n" }, "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlUpgradeable.sol\";\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../utils/StringsUpgradeable.sol\";\nimport \"../utils/introspection/ERC165Upgradeable.sol\";\nimport \"../proxy/utils/Initializable.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 AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {\n function __AccessControl_init() internal onlyInitializing {\n }\n\n function __AccessControl_init_unchained() internal onlyInitializing {\n }\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, _msgSender());\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(IAccessControlUpgradeable).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 `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 StringsUpgradeable.toHexString(uint160(account), 20),\n \" is missing role \",\n StringsUpgradeable.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 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 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 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 * [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 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 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 /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n" }, "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n require(!paused(), \"Pausable: paused\");\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n require(paused(), \"Pausable: not paused\");\n _;\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n" }, "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.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 IERC20Upgradeable {\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 /**\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" }, "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721Upgradeable is IERC165Upgradeable {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n}\n" }, "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20Upgradeable.sol\";\nimport \"../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable {\n using AddressUpgradeable for address;\n\n function safeTransfer(\n IERC20Upgradeable token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20Upgradeable token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20Upgradeable token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20Upgradeable token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20Upgradeable token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\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(IERC20Upgradeable 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, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n" }, "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for\n * deploying minimal proxy contracts, also known as \"clones\".\n *\n * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies\n * > a minimal bytecode implementation that delegates all calls to a known, fixed address.\n *\n * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`\n * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the\n * deterministic method.\n *\n * _Available since v3.4._\n */\nlibrary ClonesUpgradeable {\n /**\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n *\n * This function uses the create opcode, which should never revert.\n */\n function clone(address implementation) internal returns (address instance) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n instance := create(0, ptr, 0x37)\n }\n require(instance != address(0), \"ERC1167: create failed\");\n }\n\n /**\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n *\n * This function uses the create2 opcode and a `salt` to deterministically deploy\n * the clone. Using the same `implementation` and `salt` multiple time will revert, since\n * the clones cannot be deployed twice at the same address.\n */\n function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n instance := create2(0, ptr, 0x37, salt)\n }\n require(instance != address(0), \"ERC1167: create2 failed\");\n }\n\n /**\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n */\n function predictDeterministicAddress(\n address implementation,\n bytes32 salt,\n address deployer\n ) internal pure returns (address predicted) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)\n mstore(add(ptr, 0x38), shl(0x60, deployer))\n mstore(add(ptr, 0x4c), salt)\n mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))\n predicted := keccak256(add(ptr, 0x37), 0x55)\n }\n }\n\n /**\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n */\n function predictDeterministicAddress(address implementation, bytes32 salt)\n internal\n view\n returns (address predicted)\n {\n return predictDeterministicAddress(implementation, salt, address(this));\n }\n}\n" }, "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\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, it is bubbled up by this\n * function (like regular Solidity function calls).\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 * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\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 * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\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\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n" }, "contracts/interfaces/IStandardNFTStrategy.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\nimport \"./IGenericNFTStrategy.sol\";\n\ninterface IStandardNFTStrategy is IGenericNFTStrategy {\n function afterDeposit(address _owner, uint256[] calldata _nftIndexes, bytes calldata _data) external;\n function withdraw(address _owner, address _recipient, uint256 _nftIndex) external;\n function flashLoanStart(address _owner, address _recipient, uint256[] calldata _nftIndexes, bytes calldata _additionalData) external returns (address _depositAddress);\n function flashLoanEnd(address _owner, uint256[] calldata _nftIndexes, bytes calldata _additionalData) external;\n function isDeposited(address _owner, uint256 _nftIndex) external view returns (bool);\n}" }, "contracts/interfaces/IApeStaking.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\ninterface IApeStaking {\n \n struct SingleNft {\n uint32 tokenId;\n uint224 amount;\n }\n\n struct PairNft {\n uint128 mainTokenId;\n uint128 bakcTokenId;\n }\n\n struct PairNftDepositWithAmount {\n uint32 mainTokenId;\n uint32 bakcTokenId;\n uint184 amount;\n }\n\n struct PairNftWithdrawWithAmount {\n uint32 mainTokenId;\n uint32 bakcTokenId;\n uint184 amount;\n bool isUncommit;\n }\n\n function nftPosition(uint256 _poolId, uint256 _nftId) external view returns (uint256, int256);\n function bakcToMain(uint256 _nftId, uint256 _poolId) external view returns (uint248, bool);\n function mainToBakc(uint256 _poolId, uint256 _nftId) external view returns (uint248, bool);\n\n function depositBAYC(SingleNft[] calldata _nfts) external;\n function depositMAYC(SingleNft[] calldata _nfts) external;\n function depositBAKC(PairNftDepositWithAmount[] calldata _baycPairs, PairNftDepositWithAmount[] calldata _maycPairs) external;\n function withdrawBAYC(SingleNft[] calldata _nfts, address _recipient) external;\n function withdrawMAYC(SingleNft[] calldata _nfts, address _recipient) external;\n function withdrawBAKC(PairNftWithdrawWithAmount[] calldata _baycPairs, PairNftWithdrawWithAmount[] calldata _maycPairs) external;\n function claimBAYC(uint256[] calldata _nfts, address _recipient) external;\n function claimMAYC(uint256[] calldata _nfts, address _recipient) external;\n function claimBAKC(PairNft[] calldata _baycPairs, PairNft[] calldata _maycPairs, address _recipient) external;\n}" }, "contracts/interfaces/ISimpleUserProxy.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\ninterface ISimpleUserProxy {\n function doCall(address _target, bytes calldata _data) external payable;\n function initialize(address _owner) external;\n}" }, "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.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 IAccessControlUpgradeable {\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-upgradeable/utils/ContextUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\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 ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\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 /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n" }, "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary StringsUpgradeable {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\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" }, "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165Upgradeable.sol\";\nimport \"../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165Upgradeable {\n function __ERC165_init() internal onlyInitializing {\n }\n\n function __ERC165_init_unchained() internal onlyInitializing {\n }\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165Upgradeable).interfaceId;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n" }, "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the\n * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() initializer {}\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Modifier to protect an initializer function from being invoked twice.\n */\n modifier initializer() {\n // If the contract is initializing we ignore whether _initialized is set in order to support multiple\n // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the\n // contract may have been reentered.\n require(_initializing ? _isConstructor() : !_initialized, \"Initializable: contract is already initialized\");\n\n bool isTopLevelCall = !_initializing;\n if (isTopLevelCall) {\n _initializing = true;\n _initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n _initializing = false;\n }\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} modifier, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n function _isConstructor() private view returns (bool) {\n return !AddressUpgradeable.isContract(address(this));\n }\n}\n" }, "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.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 IERC165Upgradeable {\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" }, "contracts/interfaces/IGenericNFTStrategy.sol": { "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity ^0.8.4;\n\ninterface IGenericNFTStrategy {\n enum Kind {\n STANDARD,\n FLASH\n }\n\n function kind() external view returns (Kind);\n function depositAddress(address _account) external view returns (address);\n}" } }, "settings": { "optimizer": { "enabled": true, "runs": 300 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }