Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Contract Update #157

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Installing Packages
run: yarn install
run: yarn install --frozen-lockfile
- name: Checking Formatting
run: yarn lint && yarn prettier-check
- name: Install Foundry
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ cache
script
out
.vscode
yarn.lock
yarn.lock
lcov.info
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"rules": {
"prettier/prettier": "error",
"max-line-length": ["warn", 140],
"compiler-version": ["error", "0.8.13"]
"compiler-version": ["error", "^0.8.23"]
}
}
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"license": "ISC",
"author": "Shebin John",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
Expand All @@ -35,12 +34,12 @@
"yarn": "^1.22.10"
},
"devDependencies": {
"coveralls": "^3.1.1",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"sol2uml": "^2.5.4",
"solhint": "^4.0.0",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2"
"coveralls": "3.1.1",
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1",
"sol2uml": "2.5.20",
"solhint": "4.1.1",
"solhint-plugin-prettier": "0.1.0",
"solidity-coverage": "0.8.7"
}
}
64 changes: 64 additions & 0 deletions src/ISplitter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @title Splitter
* @author Shebin John
* @notice This code implements a simple version of Splitter.
* @dev Takes an ETH input and divides it to two specified address.
*/

pragma solidity 0.8.23;

interface ISplitter {
// **************************** //
// * Events * //
// **************************** //

/**
* @notice This event is Logged when a Split happens.
* @dev Takes the address of the receivers and the value.
* @param _first The address of first receiver.
* @param _second The address of second receiver.
* @param _value The total value received by both.
*/
event Splitted(address indexed _first, address indexed _second, uint256 _value);

/**
* @notice This event is Logged when a withdraw is done.
* @dev Takes the address of user and the value user is withdrawing.
* @param _to The address of the User.
* @param _value The value being withdrawn.
*/
event Transfered(address indexed _to, uint256 _value);

// **************************** //
// * Custom Errors * //
// **************************** //

/**
* @notice This error is thrown when Zero Address is passed.
*/
error ZeroAddressNotAllowed();

/**
* @notice This error is thrown when Zero Amount is passed.
*/
error ZeroAmountNotAllowed();

// **************************** //
// * Functions * //
// **************************** //

/**
* @notice The function splits the value sent to two addresses.
* @param _first The address of first receiver.
* @param _second The address of second receiver.
* @return _status Returns the status of the Operation.
*/
function split(address _first, address _second) external payable returns (bool _status);

/**
* @notice This function helps to withdraw money from the contract.
* @dev https://stackoverflow.com/a/52438518/7520013.
* @param _amount The amount to withdraw.
*/
function withdraw(uint256 _amount) external;
}
48 changes: 9 additions & 39 deletions src/Splitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,24 @@
* @dev Takes an ETH input and divides it to two specified address.
*/

pragma solidity 0.8.13;
pragma solidity 0.8.23;

contract Splitter {
import { ISplitter } from "./ISplitter.sol";

contract Splitter is ISplitter {
// **************************** //
// * Contract variable * //
// **************************** //

mapping(address => uint256) public balances;

// **************************** //
// * Events * //
// **************************** //

/**
* @notice This event is Logged when a Split happens.
* @dev Takes the address of the receivers and the value.
* @param _first The address of first receiver.
* @param _second The address of second receiver.
* @param _value The total value received by both.
*/
event Splitted(address indexed _first, address indexed _second, uint256 _value);

/**
* @notice This event is Logged when a withdraw is done.
* @dev Takes the address of user and the value user is withdrawing.
* @param _to The address of the User.
* @param _value The value being withdrawn.
*/
event Transfered(address indexed _to, uint256 _value);

// **************************** //
// * Functions * //
// **************************** //

/**
* @notice The function splits the value sent to two addresses.
* @param _first The address of first receiver.
* @param _second The address of second receiver.
* @return _status Returns the status of the Operation.
*/
/// @inheritdoc ISplitter
function split(address _first, address _second) public payable returns (bool _status) {
require(_first != address(0) && _second != address(0), "Zero Address not Allowed");
if (_first == address(0) || _second == address(0)) revert ZeroAddressNotAllowed();

// To divide the amount to be send to _first and _second.
uint256 msgValueAmountByTwo = msg.value / 2;
Expand All @@ -61,14 +37,9 @@ contract Splitter {
return true;
}

/**
* @notice This function helps to withdraw money from the contract.
* @dev // https://stackoverflow.com/a/52438518/7520013.
* @param _amount The amount to withdraw.
* @return _status in bool.
*/
function withdraw(uint256 _amount) public returns (bool _status) {
require(_amount > 0, "Amount cannot be Zero");
/// @inheritdoc ISplitter
function withdraw(uint256 _amount) public {
if (_amount == 0) revert ZeroAmountNotAllowed();

uint256 balance = balances[msg.sender];

Expand All @@ -77,6 +48,5 @@ contract Splitter {
emit Transfered(msg.sender, _amount);

payable(msg.sender).transfer(_amount);
return true;
}
}
Loading