From 7184ee99b09871f86942eda0ff443efdb50a59df Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Tue, 24 Sep 2024 10:16:57 +0530 Subject: [PATCH] OZ Contract added --- reports/report.json | 4 +-- reports/report.md | 6 ++-- .../src/ContractLocksEther.sol | 36 +++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/reports/report.json b/reports/report.json index 4dfcf10f3..ea3575821 100644 --- a/reports/report.json +++ b/reports/report.json @@ -1,7 +1,7 @@ { "files_summary": { "total_source_units": 110, - "total_sloc": 3904 + "total_sloc": 3925 }, "files_details": { "files_details": [ @@ -67,7 +67,7 @@ }, { "file_path": "src/ContractLocksEther.sol", - "n_sloc": 121 + "n_sloc": 142 }, { "file_path": "src/ContractWithTodo.sol", diff --git a/reports/report.md b/reports/report.md index 8d2530c79..a2efee84f 100644 --- a/reports/report.md +++ b/reports/report.md @@ -104,7 +104,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | Key | Value | | --- | --- | | .sol Files | 110 | -| Total nSLOC | 3904 | +| Total nSLOC | 3925 | ## Files Details @@ -126,7 +126,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/ConstFuncChangeState.sol | 15 | | src/ConstantFuncsAssembly.sol | 26 | | src/ConstantsLiterals.sol | 28 | -| src/ContractLocksEther.sol | 121 | +| src/ContractLocksEther.sol | 142 | | src/ContractWithTodo.sol | 7 | | src/CostlyOperationsInsideLoops.sol | 17 | | src/Counter.sol | 20 | @@ -221,7 +221,7 @@ This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a stati | src/reused_contract_name/ContractB.sol | 7 | | src/uniswap/UniswapV2Swapper.sol | 50 | | src/uniswap/UniswapV3Swapper.sol | 150 | -| **Total** | **3904** | +| **Total** | **3925** | ## Issue Summary diff --git a/tests/contract-playground/src/ContractLocksEther.sol b/tests/contract-playground/src/ContractLocksEther.sol index 4e607cbdc..6442a270c 100644 --- a/tests/contract-playground/src/ContractLocksEther.sol +++ b/tests/contract-playground/src/ContractLocksEther.sol @@ -208,3 +208,39 @@ contract CanWithdrawChild is CanWithdrawParent { emit Deposited(msg.sender, msg.value); } } + +import "../lib/openzeppelin-contracts/contracts/utils/Address.sol"; + +// GOOD +contract CanWithdrawOZ { + using Address for address payable; + + // Event to log deposits + event Deposited(address indexed sender, uint256 indexed amount); + + // Event to log transfers + event Transferred(address indexed to, uint256 indexed amount); + + // Public payable function to receive Ether + receive() external payable { + emit Deposited(msg.sender, msg.value); + } + + // Public payable fallback function to handle any data sent with Ether + fallback() external payable { + emit Deposited(msg.sender, msg.value); + } + + // Internal function to send Ether to a given address + function _sendEther(address payable recipient, uint256 amount) internal { + require(address(this).balance >= amount, "Insufficient balance"); + require(recipient != address(0), "Invalid recipient"); + recipient.sendValue(amount); + emit Transferred(recipient, amount); + } + + // This function allows for the withdrawal of eth. Hence this contract is a GOOD contract. + function takeEthBack(uint256 amount) external { + _sendEther(payable(msg.sender), amount); + } +}