-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv1.standard-json.mainnet.json
More file actions
1 lines (1 loc) · 2.61 KB
/
v1.standard-json.mainnet.json
File metadata and controls
1 lines (1 loc) · 2.61 KB
1
{"language":"Solidity","sources":{"BaseFundV1.sol":{"content":"// SPDX-License-Identifier: MIT\r\npragma solidity 0.8.24;\r\n\r\ncontract BaseFundV1 {\r\n address public owner;\r\n uint256 public goal;\r\n uint256 public deadline;\r\n uint256 public totalRaised;\r\n mapping(address => uint256) public contributions;\r\n\r\n // Events\r\n event Contribution(address indexed backer, uint256 amount);\r\n event Refunded(address indexed backer, uint256 amount);\r\n event Withdrawn(address indexed owner, uint256 amount);\r\n event GoalReached(uint256 totalRaised);\r\n\r\n // Custom Errors\r\n error NotOwner();\r\n error DeadlinePassed();\r\n error DeadlineNotReached();\r\n error GoalNotReached();\r\n error GoalAlreadyReached();\r\n error NothingToRefund();\r\n error NoETHSent();\r\n\r\n constructor(uint256 _goal, uint256 _durationInDays) {\r\n owner = msg.sender;\r\n goal = _goal;\r\n deadline = block.timestamp + (_durationInDays * 1 days);\r\n }\r\n\r\n modifier onlyOwner() {\r\n if (msg.sender != owner) revert NotOwner();\r\n _;\r\n }\r\n\r\n function contribute() external payable {\r\n if (block.timestamp >= deadline) revert DeadlinePassed();\r\n if (msg.value == 0) revert NoETHSent();\r\n\r\n contributions[msg.sender] += msg.value;\r\n totalRaised += msg.value;\r\n\r\n emit Contribution(msg.sender, msg.value);\r\n\r\n if (totalRaised >= goal) {\r\n emit GoalReached(totalRaised);\r\n }\r\n }\r\n\r\n function refund() external {\r\n if (block.timestamp < deadline) revert DeadlineNotReached();\r\n if (totalRaised >= goal) revert GoalAlreadyReached();\r\n\r\n uint256 amount = contributions[msg.sender];\r\n if (amount == 0) revert NothingToRefund();\r\n\r\n contributions[msg.sender] = 0;\r\n payable(msg.sender).transfer(amount);\r\n\r\n emit Refunded(msg.sender, amount);\r\n }\r\n\r\n function withdraw() external onlyOwner {\r\n if (block.timestamp < deadline) revert DeadlineNotReached();\r\n if (totalRaised < goal) revert GoalNotReached();\r\n\r\n uint256 amount = address(this).balance;\r\n payable(owner).transfer(amount);\r\n\r\n emit Withdrawn(owner, amount);\r\n }\r\n}\r\n"}},"settings":{"optimizer":{"enabled":true,"runs":200},"outputSelection":{"*":{"":["ast"],"*":["abi","metadata","devdoc","userdoc","storageLayout","evm.legacyAssembly","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","evm.gasEstimates","evm.assembly"]}},"remappings":[],"evmVersion":"cancun"}}