{ "language": "Solidity", "sources": { "contracts/core/PandaPoolCore.sol": { "content": "/*\n ** \n ** dddddddd \n ** PPPPPPPPPPPPPPPPP d::::::d DDDDDDDDDDDDD AAA OOOOOOOOO \n ** P::::::::::::::::P d::::::d D::::::::::::DDD A:::A OO:::::::::OO \n ** P::::::PPPPPP:::::P d::::::d D:::::::::::::::DD A:::::A OO:::::::::::::OO \n ** PP:::::P P:::::P d:::::d DDD:::::DDDDD:::::D A:::::::A O:::::::OOO:::::::O\n ** P::::P P:::::Paaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d aaaaaaaaaaaaa D:::::D D:::::D A:::::::::A O::::::O O::::::O\n ** P::::P P:::::Pa::::::::::::a n:::nn::::::::nn dd::::::::::::::d a::::::::::::a D:::::D D:::::D A:::::A:::::A O:::::O O:::::O\n ** P::::PPPPPP:::::P aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d aaaaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P:::::::::::::PP a::::ann:::::::::::::::nd:::::::ddddd:::::d a::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::PPPPPPPPP aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d aaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::P aa::::::::::::a n::::n n::::nd:::::d d:::::d aa::::::::::::a D:::::D D:::::D A:::::AAAAAAAAA:::::A O:::::O O:::::O\n ** P::::P a::::aaaa::::::a n::::n n::::nd:::::d d:::::d a::::aaaa::::::a D:::::D D:::::DA:::::::::::::::::::::A O:::::O O:::::O\n ** P::::P a::::a a:::::a n::::n n::::nd:::::d d:::::d a::::a a:::::a D:::::D D:::::DA:::::AAAAAAAAAAAAA:::::A O::::::O O::::::O\n ** PP::::::PP a::::a a:::::a n::::n n::::nd::::::ddddd::::::dda::::a a:::::a DDD:::::DDDDD:::::DA:::::A A:::::AO:::::::OOO:::::::O\n ** P::::::::P a:::::aaaa::::::a n::::n n::::n d:::::::::::::::::da:::::aaaa::::::a D:::::::::::::::DDA:::::A A:::::AOO:::::::::::::OO \n ** P::::::::P a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d a::::::::::aa:::aD::::::::::::DDD A:::::A A:::::A OO:::::::::OO \n ** PPPPPPPPPP aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd aaaaaaaaaa aaaaDDDDDDDDDDDDD AAAAAAA AAAAAAA OOOOOOOOO \n ** \n*/\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.6;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport \"../interfaces/IPandaPool.sol\";\nimport \"../interfaces/IPoolKit.sol\";\n\n/**\n */\n\ncontract PandaPoolCore is Ownable, ReentrancyGuard, IERC721Receiver, IPoolKit, IPandaPool {\n using SafeERC20 for IERC20;\n\n struct BuyCommit {\n bytes32 commit;\n uint64 block;\n bool revealed;\n uint256 amountBuyMax;\n uint256 deadline;\n }\n\n struct RebornCommit {\n bytes32 commit;\n uint64 block;\n bool revealed;\n uint256 ownerTokenId;\n uint256 amountFeeMax;\n uint256 deadline;\n }\n\n address immutable public pandaToken;\n address immutable public pandaNFT;\n uint256 public minPoolNFTCount = 1000;\n\n mapping(address => bool) public admins;\n\n bool public isPoolOpen = true;\n bool public isCrOpen = true;\n mapping(uint256 => uint256) public poolNftMap;\n mapping(address => BuyCommit) public buyCommits;\n mapping(address => RebornCommit) public rebornCommits;\n mapping(address => bool) public buyCompensates;\n mapping(address => bool) public rebornCompensates;\n uint256 public poolSize = 2000;\n uint256 public poolIndexBase = 1;\n\n address public constant ZERO_ADDRESS = address(0);\n uint256 public constant NFT_TOTAL_SUPPLY = 10000;\n uint256 public constant FEE_BASE = 10000;\n uint256 public poolFeeValue = 375;\n uint256 public treasuryFeeValue = 0;\n\n\n event Redeem(address indexed recipient, uint256 ownerTokenId, uint256 receiveAmount);\n event AddLiquidity(address indexed recipient, uint256[] supplyTokens, uint256 amountPayToken, uint256 updateMinPoolNftCount);\n event RemoveLiquidity(address indexed recipient, uint256[] targetTokens, uint256 amountReceiveToken, uint256 updateMinPoolNftCount);\n event RemovePoolForUpdate(address indexed recipient, uint256[] targetTokens);\n event AddPoolForSwap(address indexed recipient, uint256[] supplyTokens);\n event WithdrawERC20(address recipient, address tokenAddress, uint256 tokenAmount);\n event WithdrawEther(address recipient, uint256 amount);\n event CommitOwnerBuy(address indexed sender, bytes32 dataHash, uint64 block); \n event CommitOwnerRebron(address indexed sender, bytes32 dataHash, uint64 block,uint256 ownerTokenId); \n event OwnerRebornRevealHash(address indexed sender, bytes32 revealHash, uint256 ownerTokenId, uint256 index, uint256 targetIndex);\n event OwnerBuyRevealHash(address indexed sender, bytes32 revealHash, uint256 index, uint256 targetIndex);\n event ResetPandaPool(uint256 size, uint256 poolIndexBase);\n event SwitchEvent(bool poolOpne, bool crOpen);\n event SetPoolFeeValue(uint256 feeValue);\n event SetTreasuryFeeValue(uint256 feeValue);\n event UpdatePandaPool(uint256 updateMinPoolNftCount);\n\n error OnlyAdminError();\n error TimeOutError(uint256 deadline, uint256 timestamp);\n error ZeroAddrError();\n error PoolCloseError();\n error NFTOwnerNotMatch(uint tokenId, address expectOwner, address realOwner);\n error MaxFeeNotMatch(uint256 maxUserFee, uint256 poolNeedFee);\n error PandaNotEnough(address sender, uint256 balance, uint256 needBalance);\n error PoolNFTTooMany(uint256 poolNftNum, uint256 upLimit);\n error MinReceiveNotMatch(uint256 exceptMinReceive, uint256 poolPayFor);\n error MaxBuyNotMatch(uint256 maxUserPayFor, uint256 poolNeedPayFor);\n error PoolNotEnoughNFT(uint256 poolBalance, uint256 downLimit);\n error UserNotEnoughNFT(address user, uint256 userBalance, uint256 needBalance);\n error PoolIndexNotMatchNFTId(uint256 index, uint256 poolTokeId, uint256 exceptTokenId);\n error TransferEhterFail(address sender, address receiver, uint256 amount);\n error AlreadyRevealedError(address sender);\n error RevealedNotMatchError(bytes32 _hash, bytes32 commit);\n error RevealHappenEarly(uint256 revealTime, uint256 commitTime);\n error RevealTooLate(uint256 revealTime, uint256 lateTime);\n error NotCompensate(address user);\n error PoolArrayIndexOutOfRange(uint256 index, uint256 size);\n error CannotWithdrawPanda();\n\n\n modifier onlyAdmin() {\n if(!admins[msg.sender] && msg.sender != owner()) {\n revert OnlyAdminError();\n }\n _;\n }\n\n modifier ensure(uint deadline) {\n if(deadline < block.timestamp) {\n revert TimeOutError(deadline, block.timestamp);\n }\n _;\n }\n\n modifier notZeroAddr(address addr_) {\n if(addr_ == ZERO_ADDRESS) {\n revert ZeroAddrError();\n }\n _;\n }\n\n modifier poolOpen() {\n if(!isPoolOpen) {\n revert PoolCloseError();\n }\n _;\n }\n\n modifier crOpen() {\n if(!isCrOpen) {\n revert PoolCloseError();\n }\n _;\n }\n\n\n \n\n /**\n * @dev Constructor.\n */\n constructor(\n address _pandaToken,\n address _pandaNft\n )\n {\n pandaToken = _pandaToken;\n pandaNFT = _pandaNft;\n }\n\n function addAdmin(address _admin) external onlyOwner {\n admins[_admin] = true;\n }\n\n function removeAdmin(address _admin) external onlyOwner {\n admins[_admin] = false;\n }\n\n \n//############################ Liquid Functions Start #####################\n\n /**\n * @dev redeem NFT, you will receive $PANDA.\n * @param _ownerTokenId The NFT Id you want to redeem\n * @param _amountRedeemMin Less than this value you will not redeem\n * @param _deadline deadline\n */\n function redeem(uint256 _ownerTokenId, uint256 _amountRedeemMin, uint256 _deadline) external override ensure(_deadline) nonReentrant poolOpen {\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if (_pandaNFT.ownerOf(_ownerTokenId) != msg.sender) {\n revert NFTOwnerNotMatch(_ownerTokenId, msg.sender, _pandaNFT.ownerOf(_ownerTokenId));\n }\n \n uint256 _price = _currentPrice();\n uint256 feeValue = poolFeeValue + treasuryFeeValue;\n if (_amountRedeemMin > _price * (FEE_BASE - feeValue) / FEE_BASE) {\n revert MinReceiveNotMatch(_amountRedeemMin, _price * (FEE_BASE - feeValue) / FEE_BASE);\n }\n _pandaNFT.safeTransferFrom(msg.sender, address(this), _ownerTokenId, \"\");\n \n IERC20(pandaToken).safeTransfer(msg.sender, _price * (FEE_BASE - feeValue) / FEE_BASE);\n _poolPushNft(_ownerTokenId);\n emit Redeem(msg.sender, _ownerTokenId, _price * (FEE_BASE - feeValue) / FEE_BASE);\n }\n\n\n /**\n * @dev owner addLiquidity.\n * @param _supplyTokens add these NFTs to pool\n * @param _amountTokenMax Above this value owner will not add liquidity\n * @param _updateMinPoolNftCount update pool min nfts \n * @param _deadline deadline\n */\n function addLiquidity(uint256[] calldata _supplyTokens, uint256 _amountTokenMax, uint256 _updateMinPoolNftCount, uint256 _deadline) external override ensure(_deadline) onlyOwner nonReentrant {\n\n uint256 _length = _supplyTokens.length;\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if(_pandaNFT.balanceOf(msg.sender) < _length) {\n revert UserNotEnoughNFT(msg.sender, _pandaNFT.balanceOf(msg.sender), _length);\n }\n\n IERC20 _pandaToken = IERC20(pandaToken);\n if (_pandaToken.balanceOf(msg.sender) < _amountTokenMax) {\n revert PandaNotEnough(msg.sender, _pandaToken.balanceOf(msg.sender), _amountTokenMax);\n }\n\n uint256 _price = _currentPrice();\n uint256 tranTokens;\n \n \n uint256 _iTokenId;\n for (uint256 i = 0; i < _length; i++) {\n _iTokenId = _supplyTokens[i];\n _pandaNFT.safeTransferFrom(msg.sender, address(this), _iTokenId, \"\");\n tranTokens += _price;\n _poolPushNft(_iTokenId);\n }\n if (_amountTokenMax < tranTokens) {\n revert MaxBuyNotMatch(_amountTokenMax, tranTokens);\n }\n _pandaToken.safeTransferFrom(msg.sender, address(this), tranTokens);\n\n if (_pandaNFT.balanceOf(address(this)) < _updateMinPoolNftCount) {\n revert PoolNotEnoughNFT(_pandaNFT.balanceOf(address(this)), _updateMinPoolNftCount);\n }\n\n if(minPoolNFTCount != _updateMinPoolNftCount) {\n minPoolNFTCount = _updateMinPoolNftCount;\n }\n emit AddLiquidity(msg.sender, _supplyTokens, tranTokens, _updateMinPoolNftCount);\n }\n\n /**\n * @dev owner removeLiquidity.\n * @param _targetTokens remove these NFTs from pool\n * @param _amountTokenMin Less than this value owner will not remove liquidity\n * @param _updateMinPoolNftCount update pool min nfts \n */\n function removeLiquidity(uint256[] calldata _targetTokens, uint256[] calldata _targetPoolIndexs, uint256 _amountTokenMin, uint256 _updateMinPoolNftCount) external override onlyOwner nonReentrant {\n uint256 _length = _targetTokens.length;\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if (_pandaNFT.balanceOf(address(this)) < _length) {\n revert PoolNotEnoughNFT(_pandaNFT.balanceOf(address(this)), _length);\n }\n\n IERC20 _pandaToken = IERC20(pandaToken);\n if (_pandaToken.balanceOf(address(this)) < _amountTokenMin) {\n revert PandaNotEnough(address(this), _pandaToken.balanceOf(address(this)), _amountTokenMin);\n }\n\n uint256 _price = _currentPrice();\n uint256 tranTokens;\n uint256 _iTargetTokenId;\n uint256 _iPoolIndex;\n for (uint256 i = 0; i < _length; i++) {\n _iTargetTokenId = _targetTokens[i];\n _iPoolIndex = _targetPoolIndexs[i];\n _pandaNFT.safeTransferFrom(address(this), msg.sender, _iTargetTokenId, \"\");\n {\n if(_getIdByIndex(_iPoolIndex) != _iTargetTokenId) {\n revert PoolIndexNotMatchNFTId(_iPoolIndex, _getIdByIndex(_iPoolIndex), _iTargetTokenId);\n }\n _poolRemoveNft(_iPoolIndex);\n }\n \n tranTokens += _price;\n }\n\n if (_amountTokenMin > tranTokens) {\n revert MinReceiveNotMatch(_amountTokenMin, tranTokens);\n }\n _pandaToken.safeTransfer(msg.sender, tranTokens);\n\n if(_pandaNFT.balanceOf(address(this)) < _updateMinPoolNftCount) {\n revert PoolNotEnoughNFT(_pandaNFT.balanceOf(address(this)), _updateMinPoolNftCount);\n }\n if(minPoolNFTCount != _updateMinPoolNftCount) {\n minPoolNFTCount = _updateMinPoolNftCount;\n }\n\n emit RemoveLiquidity(msg.sender, _targetTokens, tranTokens, _updateMinPoolNftCount);\n }\n\n\n /**\n * @dev owner removePoolForUpdate.\n * @param _targetTokens remove these NFTs from pool\n */\n function removePoolForUpdate(uint256[] calldata _targetTokens, uint256[] calldata _targetPoolIndexs) external onlyOwner nonReentrant {\n uint256 _length = _targetTokens.length;\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if (_pandaNFT.balanceOf(address(this)) < _length) {\n revert PoolNotEnoughNFT(_pandaNFT.balanceOf(address(this)), _length);\n }\n\n uint256 _iTargetTokenId;\n uint256 _iPoolIndex;\n for (uint256 i = 0; i < _length; i++) {\n _iTargetTokenId = _targetTokens[i];\n _iPoolIndex = _targetPoolIndexs[i];\n _pandaNFT.safeTransferFrom(address(this), msg.sender, _iTargetTokenId, \"\");\n {\n if(_getIdByIndex(_iPoolIndex) != _iTargetTokenId) {\n revert PoolIndexNotMatchNFTId(_iPoolIndex, _getIdByIndex(_iPoolIndex), _iTargetTokenId);\n }\n _poolRemoveNft(_iPoolIndex);\n }\n }\n\n emit RemovePoolForUpdate(msg.sender, _targetTokens);\n }\n\n\n /**\n * @dev owner addPoolforSwap.\n * @param _supplyTokens add these NFTs to pool\n */\n function addPoolForSwap(uint256[] calldata _supplyTokens) external onlyOwner nonReentrant {\n\n uint256 _length = _supplyTokens.length;\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if(_pandaNFT.balanceOf(msg.sender) < _length) {\n revert UserNotEnoughNFT(msg.sender, _pandaNFT.balanceOf(msg.sender), _length);\n }\n \n uint256 _iTokenId;\n for (uint256 i = 0; i < _length; i++) {\n _iTokenId = _supplyTokens[i];\n _pandaNFT.safeTransferFrom(msg.sender, address(this), _iTokenId, \"\");\n _poolPushNft(_iTokenId);\n }\n \n emit AddPoolForSwap(msg.sender, _supplyTokens);\n }\n\n//########################### Liquid Functions End ####################\n\n\n\n//########################### CR Buy&Reborn Functions Start ####################\n\n function addCompensate(address user) external onlyOwner {\n buyCompensates[user] = true;\n }\n function removeCompensate(address user) external onlyOwner {\n buyCompensates[user] = false;\n }\n\n function addRebornCompensate(address user) external onlyOwner {\n rebornCompensates[user] = true;\n }\n function removeRebornCompensate(address user) external onlyOwner {\n rebornCompensates[user] = false;\n }\n\n function ownerCBuy(bytes32 _dataHash) external nonReentrant {\n if (!buyCompensates[msg.sender]) {\n revert NotCompensate(msg.sender);\n }\n buyCommits[msg.sender].commit = _dataHash;\n buyCommits[msg.sender].block = uint64(block.number);\n buyCommits[msg.sender].revealed = false;\n emit CommitOwnerBuy(msg.sender, buyCommits[msg.sender].commit, buyCommits[msg.sender].block);\n }\n\n function ownerRBuy(bytes32 revealHash) external nonReentrant crOpen {\n if (!buyCompensates[msg.sender]) {\n revert NotCompensate(msg.sender);\n }\n buyCompensates[msg.sender] = false;\n if (buyCommits[msg.sender].revealed) {\n revert AlreadyRevealedError(msg.sender);\n }\n buyCommits[msg.sender].revealed=true;\n if (getHash(revealHash) != buyCommits[msg.sender].commit) {\n revert RevealedNotMatchError(getHash(revealHash), buyCommits[msg.sender].commit);\n }\n\n if (block.number <= buyCommits[msg.sender].block) {\n revert RevealHappenEarly(uint64(block.number), buyCommits[msg.sender].block);\n }\n \n if (block.number > buyCommits[msg.sender].block+250) {\n revert RevealTooLate(block.number, buyCommits[msg.sender].block+250);\n }\n //get the hash of the block that happened after they committed\n bytes32 blockHash = blockhash(buyCommits[msg.sender].block);\n //hash that with their reveal that so miner shouldn't know and mod it with some max number you want\n uint256 index = uint256(keccak256(abi.encodePacked(blockHash,revealHash))) % poolSize;\n uint256 targetIndex = _getIdByIndex(index);\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if (_pandaNFT.ownerOf(targetIndex) != address(this)) {\n revert NFTOwnerNotMatch(targetIndex, address(this), _pandaNFT.ownerOf(targetIndex));\n }\n\n if(_pandaNFT.balanceOf(address(this)) <= minPoolNFTCount) {\n revert PoolNotEnoughNFT(_pandaNFT.balanceOf(address(this)), minPoolNFTCount);\n }\n _pandaNFT.safeTransferFrom(address(this), msg.sender, targetIndex, \"\");\n _poolRemoveNft(index);\n emit OwnerBuyRevealHash(msg.sender, revealHash, index, targetIndex);\n }\n\n function ownerCReborn(uint256 _ownerTokenId, bytes32 _dataHash) external nonReentrant crOpen {\n if (!rebornCompensates[msg.sender]) {\n revert NotCompensate(msg.sender);\n }\n rebornCommits[msg.sender].commit = _dataHash;\n rebornCommits[msg.sender].block = uint64(block.number);\n rebornCommits[msg.sender].revealed = false;\n rebornCommits[msg.sender].ownerTokenId = _ownerTokenId;\n emit CommitOwnerRebron(msg.sender, buyCommits[msg.sender].commit, buyCommits[msg.sender].block, _ownerTokenId);\n }\n\n\n function ownerRReborn(bytes32 revealHash) external nonReentrant crOpen {\n if (!rebornCompensates[msg.sender]) {\n revert NotCompensate(msg.sender);\n }\n rebornCompensates[msg.sender] = false;\n if (rebornCommits[msg.sender].revealed) {\n revert AlreadyRevealedError(msg.sender);\n }\n rebornCommits[msg.sender].revealed=true;\n\n if (getHash(revealHash) != rebornCommits[msg.sender].commit) {\n revert RevealedNotMatchError(getHash(revealHash), rebornCommits[msg.sender].commit);\n }\n\n if (block.number <= rebornCommits[msg.sender].block) {\n revert RevealHappenEarly(block.number, buyCommits[msg.sender].block);\n }\n \n if (block.number > rebornCommits[msg.sender].block+250) {\n revert RevealTooLate(block.number, buyCommits[msg.sender].block+250);\n }\n\n //get the hash of the block that happened after they committed\n bytes32 blockHash = blockhash(rebornCommits[msg.sender].block);\n //hash that with their reveal that so miner shouldn't know and mod it with some max number you want\n uint256 index = uint256(keccak256(abi.encodePacked(blockHash,revealHash))) % poolSize;\n\n uint256 targetIndex = _getIdByIndex(index);\n IERC721 _pandaNFT = IERC721(pandaNFT);\n if (_pandaNFT.ownerOf(targetIndex) != address(this)) {\n revert NFTOwnerNotMatch(targetIndex, address(this), _pandaNFT.ownerOf(targetIndex));\n }\n \n _pandaNFT.safeTransferFrom(msg.sender, address(this), rebornCommits[msg.sender].ownerTokenId, \"\");\n _pandaNFT.safeTransferFrom(address(this), msg.sender, targetIndex, \"\");\n _poolPushNft(rebornCommits[msg.sender].ownerTokenId);\n _poolRemoveNft(index);\n emit OwnerRebornRevealHash(msg.sender, revealHash, rebornCommits[msg.sender].ownerTokenId, index, targetIndex);\n } \n\n function getHash(bytes32 data) public view returns(bytes32){\n return keccak256(abi.encodePacked(address(this), data));\n } \n\n//########################### CR Buy&Reborn Functions End ####################\n\n//########################### Pool Utils Functions Start ####################\n\n function _safeTransferPanda(\n address to,\n uint256 value\n ) external override onlyAdmin {\n IERC20 _pandaToken = IERC20(pandaToken);\n _pandaToken.safeTransfer(to, value);\n }\n\n function _safeTransferFromPanda(\n address from,\n address to,\n uint256 value\n ) external override onlyAdmin {\n IERC20 _pandaToken = IERC20(pandaToken);\n _pandaToken.safeTransferFrom(from, to, value);\n }\n\n function _safeTransferToPanda(\n address to,\n uint256 value\n ) external override onlyAdmin {\n IERC20 _pandaToken = IERC20(pandaToken);\n _pandaToken.safeTransfer(to, value);\n }\n\n function _safeTransferFromNFT(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external override onlyAdmin {\n IERC721 _pandaNFT = IERC721(pandaNFT);\n _pandaNFT.safeTransferFrom(from, to, tokenId, data);\n }\n\n function _poolSize() public override view returns(uint256) {\n return poolSize;\n }\n\n function _minPoolNFTCount() public override view returns(uint256) {\n return minPoolNFTCount;\n }\n\n function _poolRemoveNft(uint256 _index) public override onlyAdmin {\n if (_index >= poolSize) {\n revert PoolArrayIndexOutOfRange(_index, poolSize);\n }\n if (_index == poolSize - 1) {\n poolNftMap[_index] = 0;\n } else {\n poolNftMap[_index] = _getIdByIndex(poolSize - 1);//poolNftMap[poolSize - 1];\n poolNftMap[poolSize - 1] = 0;\n }\n poolSize--;\n }\n\n function _poolPushNft(uint256 _value) public override onlyAdmin {\n poolNftMap[poolSize] = _value;\n poolSize++;\n }\n\n function _getIdByIndex(uint256 _index) public override returns(uint256) {\n if (_index >= poolSize) {\n revert PoolArrayIndexOutOfRange(_index, poolSize);\n }\n if(poolNftMap[_index] == 0) {\n poolNftMap[_index] = _index + poolIndexBase;\n return poolNftMap[_index];\n } else {\n return poolNftMap[_index];\n }\n }\n\n /**\n * @dev calculate current price\n */\n function _currentPrice() public view override returns(uint256 _price) {\n if (IERC721(pandaNFT).balanceOf(address(this)) < NFT_TOTAL_SUPPLY) {\n _price = IERC20(pandaToken).balanceOf(address(this)) / (NFT_TOTAL_SUPPLY - poolSize);\n } else {\n _price = IERC20(pandaToken).balanceOf(address(this));\n }\n \n } \n\n\n function _resetPandaPool(uint256 _size, uint256 _poolIndexBase) external onlyOwner {\n poolSize = _size;\n poolIndexBase = _poolIndexBase;\n emit ResetPandaPool(_size, _poolIndexBase);\n } \n\n function _updatePandaPoolMin(uint256 _updateMinPoolNftCount) external onlyOwner {\n minPoolNFTCount = _updateMinPoolNftCount;\n emit UpdatePandaPool(_updateMinPoolNftCount);\n } \n\n//########################### Pool Utils Functions End ####################\n\n /**\n * @dev setLiquidityClose close or open swap、redeem、buy.\n * @param _poolOpne true or false\n * @param _crOpen true or false \n */\n function setSwitchs(bool _poolOpne, bool _crOpen) external onlyOwner {\n isPoolOpen = _poolOpne;\n isCrOpen = _crOpen;\n emit SwitchEvent(_poolOpne, _crOpen);\n }\n\n function setPoolFeeValue(uint256 _feeValue) external onlyOwner {\n poolFeeValue = _feeValue;\n emit SetPoolFeeValue(_feeValue);\n }\n\n function setTreasuryFeeValue(uint256 _feeValue) external onlyOwner {\n treasuryFeeValue = _feeValue;\n emit SetTreasuryFeeValue(_feeValue);\n }\n\n\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data ) pure external override returns (bytes4) {\n return this.onERC721Received.selector;\n } \n\n /**\n * @dev withdrawERC20 tokens.\n * @param _recipient recipient\n * @param _tokenAddress token\n * @param _tokenAmount amount\n */\n function withdrawERC20(address _recipient, address _tokenAddress, uint256 _tokenAmount) external onlyOwner notZeroAddr(_tokenAddress) {\n IERC20(_tokenAddress).safeTransfer(_recipient, _tokenAmount);\n emit WithdrawERC20(_recipient, _tokenAddress, _tokenAmount);\n }\n \n\n /**\n * @dev withdraw Ether.\n * @param recipient recipient\n * @param amount amount\n */\n function withdrawEther(address payable recipient, uint256 amount) external onlyOwner {\n (bool success,) = recipient.call{value:amount}(\"\");\n if(!success) {\n revert TransferEhterFail(msg.sender, recipient, amount);\n }\n emit WithdrawEther(recipient, amount);\n }\n\n\n fallback () external payable {}\n\n receive () external payable {}\n\n}" }, "@openzeppelin/contracts/access/Ownable.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (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 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 called by any account other than the owner.\n */\n modifier onlyOwner() {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n _;\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/security/ReentrancyGuard.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor() {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n" }, "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS,\n InvalidSignatureV\n }\n\n function _throwError(RecoverError error) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert(\"ECDSA: invalid signature\");\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert(\"ECDSA: invalid signature length\");\n } else if (error == RecoverError.InvalidSignatureS) {\n revert(\"ECDSA: invalid signature 's' value\");\n } else if (error == RecoverError.InvalidSignatureV) {\n revert(\"ECDSA: invalid signature 'v' value\");\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature` or error string. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n *\n * _Available since v4.3._\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n // Check the signature length\n // - case 65: r,s,v signature (standard)\n // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else if (signature.length == 64) {\n bytes32 r;\n bytes32 vs;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly {\n r := mload(add(signature, 0x20))\n vs := mload(add(signature, 0x40))\n }\n return tryRecover(hash, r, vs);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength);\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, signature);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address, RecoverError) {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n *\n * _Available since v4.2._\n */\n function recover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS);\n }\n if (v != 27 && v != 28) {\n return (address(0), RecoverError.InvalidSignatureV);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature);\n }\n\n return (signer, RecoverError.NoError);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n // 32 is the length in bytes of hash,\n // enforced by the type signature above\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from `s`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n }\n\n /**\n * @dev Returns an Ethereum Signed Typed Data, created from a\n * `domainSeparator` and a `structHash`. This produces hash corresponding\n * to the one signed with the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n * JSON-RPC method as part of EIP-712.\n *\n * See {recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\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/token/ERC721/IERC721.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\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`.\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 /**\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 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 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 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" }, "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": { "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n" }, "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.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 \"../IERC20.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 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 IERC20 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 IERC20 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 IERC20 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 IERC20 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(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"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" }, "contracts/interfaces/IPandaPool.sol": { "content": "/*\n ** \n ** dddddddd \n ** PPPPPPPPPPPPPPPPP d::::::d DDDDDDDDDDDDD AAA OOOOOOOOO \n ** P::::::::::::::::P d::::::d D::::::::::::DDD A:::A OO:::::::::OO \n ** P::::::PPPPPP:::::P d::::::d D:::::::::::::::DD A:::::A OO:::::::::::::OO \n ** PP:::::P P:::::P d:::::d DDD:::::DDDDD:::::D A:::::::A O:::::::OOO:::::::O\n ** P::::P P:::::Paaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d aaaaaaaaaaaaa D:::::D D:::::D A:::::::::A O::::::O O::::::O\n ** P::::P P:::::Pa::::::::::::a n:::nn::::::::nn dd::::::::::::::d a::::::::::::a D:::::D D:::::D A:::::A:::::A O:::::O O:::::O\n ** P::::PPPPPP:::::P aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d aaaaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P:::::::::::::PP a::::ann:::::::::::::::nd:::::::ddddd:::::d a::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::PPPPPPPPP aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d aaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::P aa::::::::::::a n::::n n::::nd:::::d d:::::d aa::::::::::::a D:::::D D:::::D A:::::AAAAAAAAA:::::A O:::::O O:::::O\n ** P::::P a::::aaaa::::::a n::::n n::::nd:::::d d:::::d a::::aaaa::::::a D:::::D D:::::DA:::::::::::::::::::::A O:::::O O:::::O\n ** P::::P a::::a a:::::a n::::n n::::nd:::::d d:::::d a::::a a:::::a D:::::D D:::::DA:::::AAAAAAAAAAAAA:::::A O::::::O O::::::O\n ** PP::::::PP a::::a a:::::a n::::n n::::nd::::::ddddd::::::dda::::a a:::::a DDD:::::DDDDD:::::DA:::::A A:::::AO:::::::OOO:::::::O\n ** P::::::::P a:::::aaaa::::::a n::::n n::::n d:::::::::::::::::da:::::aaaa::::::a D:::::::::::::::DDA:::::A A:::::AOO:::::::::::::OO \n ** P::::::::P a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d a::::::::::aa:::aD::::::::::::DDD A:::::A A:::::A OO:::::::::OO \n ** PPPPPPPPPP aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd aaaaaaaaaa aaaaDDDDDDDDDDDDD AAAAAAA AAAAAAA OOOOOOOOO \n ** \n*/\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.6;\n\ninterface IPandaPool {\n \n function redeem(uint256 _ownerTokenId, uint256 _amountRedeemMin, uint256 _deadline) external;\n\n function addLiquidity(uint256[] calldata _supplyTokens, uint256 _amountTokenMax, uint256 _updateMinPoolNftCount, uint256 _deadline) external;\n\n function removeLiquidity(uint256[] calldata _targetTokens, uint256[] calldata _targetPoolIndexs, uint256 _amountTokenMin, uint256 _updateMinPoolNftCount) external;\n \n}\n" }, "contracts/interfaces/IPoolKit.sol": { "content": "/*\n ** \n ** dddddddd \n ** PPPPPPPPPPPPPPPPP d::::::d DDDDDDDDDDDDD AAA OOOOOOOOO \n ** P::::::::::::::::P d::::::d D::::::::::::DDD A:::A OO:::::::::OO \n ** P::::::PPPPPP:::::P d::::::d D:::::::::::::::DD A:::::A OO:::::::::::::OO \n ** PP:::::P P:::::P d:::::d DDD:::::DDDDD:::::D A:::::::A O:::::::OOO:::::::O\n ** P::::P P:::::Paaaaaaaaaaaaa nnnn nnnnnnnn ddddddddd:::::d aaaaaaaaaaaaa D:::::D D:::::D A:::::::::A O::::::O O::::::O\n ** P::::P P:::::Pa::::::::::::a n:::nn::::::::nn dd::::::::::::::d a::::::::::::a D:::::D D:::::D A:::::A:::::A O:::::O O:::::O\n ** P::::PPPPPP:::::P aaaaaaaaa:::::an::::::::::::::nn d::::::::::::::::d aaaaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P:::::::::::::PP a::::ann:::::::::::::::nd:::::::ddddd:::::d a::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::PPPPPPPPP aaaaaaa:::::a n:::::nnnn:::::nd::::::d d:::::d aaaaaaa:::::a D:::::D D:::::D A:::::A A:::::A O:::::O O:::::O\n ** P::::P aa::::::::::::a n::::n n::::nd:::::d d:::::d aa::::::::::::a D:::::D D:::::D A:::::AAAAAAAAA:::::A O:::::O O:::::O\n ** P::::P a::::aaaa::::::a n::::n n::::nd:::::d d:::::d a::::aaaa::::::a D:::::D D:::::DA:::::::::::::::::::::A O:::::O O:::::O\n ** P::::P a::::a a:::::a n::::n n::::nd:::::d d:::::d a::::a a:::::a D:::::D D:::::DA:::::AAAAAAAAAAAAA:::::A O::::::O O::::::O\n ** PP::::::PP a::::a a:::::a n::::n n::::nd::::::ddddd::::::dda::::a a:::::a DDD:::::DDDDD:::::DA:::::A A:::::AO:::::::OOO:::::::O\n ** P::::::::P a:::::aaaa::::::a n::::n n::::n d:::::::::::::::::da:::::aaaa::::::a D:::::::::::::::DDA:::::A A:::::AOO:::::::::::::OO \n ** P::::::::P a::::::::::aa:::a n::::n n::::n d:::::::::ddd::::d a::::::::::aa:::aD::::::::::::DDD A:::::A A:::::A OO:::::::::OO \n ** PPPPPPPPPP aaaaaaaaaa aaaa nnnnnn nnnnnn ddddddddd ddddd aaaaaaaaaa aaaaDDDDDDDDDDDDD AAAAAAA AAAAAAA OOOOOOOOO \n ** \n*/\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.6;\n\ninterface IPoolKit {\n function _safeTransferPanda(address to, uint256 value) external;\n \n function _safeTransferFromPanda(address from, address to, uint256 value) external;\n\n function _safeTransferFromNFT(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n function _poolSize() external view returns(uint256);\n\n function _poolRemoveNft(uint256 _index) external;\n\n function _poolPushNft(uint256 _value) external ;\n\n function _getIdByIndex(uint256 _index) external returns(uint256);\n\n function _currentPrice() external view returns(uint256 _price);\n\n function _minPoolNFTCount() external view returns(uint256);\n\n function _safeTransferToPanda(address to,uint256 value) external ;\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/utils/Strings.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 Strings {\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/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" }, "@openzeppelin/contracts/utils/Address.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 Address {\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 Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(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" } }, "settings": { "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }