Created
April 21, 2022 07:55
-
-
Save ahbanavi/465155f3b6dc372c6f8a1ca84e151d75 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.13+commit.abaa5c0e.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.13; | |
contract SimpleSplitter { | |
event Received(address, uint256); | |
error PaymentFailed(); | |
error WrongShares(); | |
error WrongAddress(); | |
address private immutable _addr1; | |
address private immutable _addr2; | |
uint256 private immutable _share1; | |
uint256 private immutable _share2; | |
constructor(address addr1_, address addr2_, uint256 share1_, uint256 share2_) { | |
if (addr1_ == address(0) || addr2_ == address(0)) revert WrongAddress(); | |
if (share1_ + share2_ != 100) revert WrongShares(); | |
if (share1_ == 0 || share2_ == 0) revert WrongShares(); | |
_addr1 = addr1_; | |
_addr2 = addr2_; | |
_share1 = share1_; | |
_share2 = share2_; | |
} | |
receive() external payable { | |
emit Received(msg.sender, msg.value); | |
} | |
function withdraw() external { | |
uint256 balance = address(this).balance; | |
(bool success1, ) = _addr1.call{value: balance * _share1 / 100 }(""); | |
(bool success2, ) = _addr2.call{value: balance * _share2 / 100 }(""); | |
if (!success1 && !success2) revert PaymentFailed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment