-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPool_verification.json
More file actions
1 lines (1 loc) · 17.2 KB
/
Copy pathPool_verification.json
File metadata and controls
1 lines (1 loc) · 17.2 KB
1
{"language":"Solidity","sources":{"src/Pool.sol":{"content":"//SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport \"./IPool.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\n\n\ncontract Pool is IPool, ReentrancyGuard {\n\n struct PoolData {\n uint256 id;\n address creator;\n status poolStatus;\n address[5] participants;\n uint256 participantCount;\n uint256 totalDeposited;\n mapping(address => uint256) userBalances;\n } \n\nenum status {\n CLOSED,\n ACTIVE\n } \n\n//mapping of pool id to pool details\nmapping(uint256 => PoolData) public pools;\n//pool counts\nuint256 public poolCount;\n\n\n\n\n\n//Admin create pool event \nevent PoolCreated(uint256 indexed poolId, address indexed creator);\n\n//Participants deposit event\nevent DepositMade(uint256 indexed poolId, address indexed participant, uint256 amount);\n\n//Participants withdraw event\nevent WithdrawalMade(uint256 indexed poolId, address indexed participant, uint256 amount);\n\n//reward distribution event\nevent awardedPot(uint256 indexed poolId, address indexed participant, uint256 amount);\n\n//CANCELL THE POOL\nevent PoolCancelled(uint256 indexed poolId, address indexed creator);\n\n//upadte admin\nevent AdminUpdated(address indexed oldAdmin, address indexed newAdmin);\n\n\n//admin address\naddress public Admin;\n//treasury address\naddress public treasury;\n//mezo token address\nIERC20 public immutable mezoToken;\n\n\nconstructor(address _admin, address _mezoToken, address _treasury) {\n require(_admin != address(0), \"Invalid admin\");\n require(_mezoToken != address(0), \"Invalid token\");\n require(_treasury != address(0), \"Invalid treasury\");\n Admin = _admin;\n mezoToken = IERC20(_mezoToken);\n treasury = _treasury;\n}\n \n\nmodifier onlyAdmin() {\n require(msg.sender == Admin, \"Only admin can perform this action\");\n _;\n}\n\n\n\n\nfunction createPool() external onlyAdmin override returns (uint256) {\n poolCount++;\n PoolData storage newPool = pools[poolCount];\n newPool.id = poolCount;\n newPool.creator = msg.sender;\n newPool.poolStatus = status.ACTIVE;\n newPool.participantCount = 0;\n emit PoolCreated(poolCount, msg.sender);\n return poolCount;\n\n}\n\n\nfunction deposit(uint256 poolId, uint256 amount) external nonReentrant override {\n PoolData storage p = pools[poolId];\n require(p.creator != address(0), \"Pool does not exist\");\n require(amount > 0, \"Amount must be greater than 0\");\n require(p.poolStatus == status.ACTIVE, \"Pool is not active\");\n\n if (p.userBalances[msg.sender] == 0) {\n require(p.participantCount < 5, \"Pool participant limit exceeded\");\n p.participants[p.participantCount] = msg.sender;\n p.participantCount++;\n }\n\n p.userBalances[msg.sender] += amount;\n p.totalDeposited += amount;\n \n\n bool success = mezoToken.transferFrom(msg.sender, address(this), amount);\n require(success, \"Transfer failed\");\n\n emit DepositMade(poolId, msg.sender, amount);\n\n }\n\nfunction withdrawDeposit(uint256 poolId) external nonReentrant {\n PoolData storage pool = pools[poolId];\n require(pool.creator != address(0), \"Pool does not exist\");\n require(pool.poolStatus == status.ACTIVE, \"Pool is not active\");\n require(pool.userBalances[msg.sender] > 0, \"No deposit\");\n \n uint256 amount = pool.userBalances[msg.sender];\n pool.userBalances[msg.sender] = 0;\n pool.totalDeposited -= amount;\n\n // find and remove participant from array\nfor (uint256 i = 0; i < pool.participantCount; i++) {\n if (pool.participants[i] == msg.sender) {\n pool.participants[i] = pool.participants[pool.participantCount - 1];\n pool.participants[pool.participantCount - 1] = address(0);\n pool.participantCount--;\n break;\n }\n}\n\n bool success = mezoToken.transfer(msg.sender, amount);\n require(success, \"Transfer failed\");\n \n emit WithdrawalMade(poolId, msg.sender, amount);\n}\n\n\n\nfunction awardPot(uint256 poolId, address winner) external onlyAdmin nonReentrant override {\n PoolData storage p = pools[poolId];\n require(p.creator != address(0), \"Pool does not exist\");\n require(p.poolStatus == status.ACTIVE, \"Pool is not active\");\n uint256 pot = p.totalDeposited;\n require(pot > 0, \"Empty pool\");\n\n bool isParticipant = false;\n for (uint256 i = 0; i < p.participantCount; i++) {\n if (p.participants[i] == winner) {\n isParticipant = true;\n }\n p.userBalances[p.participants[i]] = 0;\n }\n require(isParticipant, \"Winner is not a participant\");\n p.totalDeposited = 0;\n p.poolStatus = status.CLOSED;\n\n uint256 fee = pot / 10;\n uint256 netReward = pot - fee;\n\n bool s1 = mezoToken.transfer(winner, netReward);\n require(s1, \"Reward transfer failed\");\n bool s2 = mezoToken.transfer(treasury, fee);\n require(s2, \"Fee transfer failed\");\n\n emit awardedPot(poolId, winner, netReward);\n}\n\n\nfunction cancelPool(uint256 poolId) external onlyAdmin nonReentrant override{\n PoolData storage pool = pools[poolId];\n require(pool.creator != address(0), \"Pool does not exist\");\n require(pool.poolStatus == status.ACTIVE, \"Pool is not active\");\n pool.poolStatus = status.CLOSED;\n // Refund participants\n for (uint256 i = 0; i < pool.participantCount; i++) {\n address participant = pool.participants[i];\n // Implementation for refunding \n uint256 refund = pool.userBalances[participant];\n if (refund > 0) {\n pool.userBalances[participant] = 0;\n bool success = mezoToken.transfer(participant, refund);\n require(success, \"Transfer failed\");\n pool.totalDeposited -= refund;\n}\n }\n emit PoolCancelled(poolId, pool.creator);\n\n}\n\n\n\n function getBalance(uint256 poolId) public override view returns (uint256) {\n PoolData storage pool = pools[poolId];\n return pool.totalDeposited;\n }\n\n\n function getUserBalance(uint256 poolId, address user) external view returns (uint256) {\n return pools[poolId].userBalances[user];\n}\n\n\n\n\n function updateAdmin(address newAdmin) external onlyAdmin override {\n require(newAdmin != address(0), \"Invalid address\");\n // Implementation for updating the admin address\n address oldAdmin = Admin;\n Admin = newAdmin;\n emit AdminUpdated(oldAdmin, newAdmin);\n\n }\n\n \n\n\n}"},"src/IPool.sol":{"content":"//SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\n\n\n\ninterface IERC20 {\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n function transfer(address recipient, uint256 amount) external returns (bool);\n}\n\n\n\n\ninterface IPool {\n\n function createPool() external returns (uint256);\n\n function deposit(uint256 poolId, uint256 amount) external;\n\n function withdrawDeposit(uint256 poolId) external;\n\n function cancelPool(uint256 poolId) external;\n\n function awardPot(uint256 poolId, address winner) external;\n\n function getBalance(uint256 poolId) external view returns (uint256);\n\n\n function updateAdmin(address newAdmin) external;\n}"},"lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\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 EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\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 *\n * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced\n * by the {ReentrancyGuardTransient} variant in v6.0.\n *\n * @custom:stateless\n */\nabstract contract ReentrancyGuard {\n using StorageSlot for bytes32;\n\n // keccak256(abi.encode(uint256(keccak256(\"openzeppelin.storage.ReentrancyGuard\")) - 1)) & ~bytes32(uint256(0xff))\n bytes32 private constant REENTRANCY_GUARD_STORAGE =\n 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;\n\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 /**\n * @dev Unauthorized reentrant call.\n */\n error ReentrancyGuardReentrantCall();\n\n constructor() {\n _reentrancyGuardStorageSlot().getUint256Slot().value = 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 _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n /**\n * @dev A `view` only version of {nonReentrant}. Use to block view functions\n * from being called, preventing reading from inconsistent contract state.\n *\n * CAUTION: This is a \"view\" modifier and does not change the reentrancy\n * status. Use it only on view functions. For payable or non-payable functions,\n * use the standard {nonReentrant} modifier instead.\n */\n modifier nonReentrantView() {\n _nonReentrantBeforeView();\n _;\n }\n\n function _nonReentrantBeforeView() private view {\n if (_reentrancyGuardEntered()) {\n revert ReentrancyGuardReentrantCall();\n }\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be NOT_ENTERED\n _nonReentrantBeforeView();\n\n // Any calls to nonReentrant after this point will fail\n _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;\n }\n\n function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {\n return REENTRANCY_GUARD_STORAGE;\n }\n}\n"},"lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns a `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n assembly (\"memory-safe\") {\n r.slot := store.slot\n }\n }\n}\n"}},"settings":{"remappings":["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/","forge-std/=lib/forge-std/src/","erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/","halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/","openzeppelin-contracts/=lib/openzeppelin-contracts/"],"optimizer":{"enabled":false,"runs":200},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs","appendCBOR":true},"outputSelection":{"*":{"*":["abi","evm.bytecode.object","evm.bytecode.sourceMap","evm.bytecode.linkReferences","evm.deployedBytecode.object","evm.deployedBytecode.sourceMap","evm.deployedBytecode.linkReferences","evm.deployedBytecode.immutableReferences","evm.methodIdentifiers","metadata"]}},"evmVersion":"prague","viaIR":false,"libraries":{}}}