-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEscrowTapped.sol
More file actions
77 lines (62 loc) · 2.82 KB
/
EscrowTapped.sol
File metadata and controls
77 lines (62 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: CC-BY-NC-3.0
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
/// @author cschmidt.eth
/// @title A simple escrow contract
contract EscrowTapped is Ownable {
using SafeMath for uint256;
mapping(address => mapping(address => uint256)) private _funds; // wei
mapping(address => bool) public whitelist;
uint256 public changeJar;
uint256 public percentage;
constructor() {
whitelist[msg.sender] = true;
percentage = 1;
}
/// @param _sender the address paying into the escrow balance
/// @param _receiver the address receiving from the escrow balance
/// @return uint256 the balance amount in wei
function checkBalance(address _sender, address _receiver) public view returns(uint256) {
return _funds[_sender][_receiver];
}
/// @param _to the address to which funds will be released
/// @notice percentage cannot be changed for funds already deposited
function depositFunds(address _to) public payable {
uint256 _percentage = percentage;
if (whitelist[_to] || whitelist[msg.sender]) _percentage = 0;
uint256 _change = msg.value.mul(_percentage).div(100);
uint256 _remaining = msg.value.sub(_change);
changeJar += _change;
_funds[msg.sender][_to] += _remaining;
}
/// @param _to the address to which funds will be released
/// @param _amount the amount of wei to be released
function releaseFunds(address _to, uint256 _amount) public {
require(_amount <= _funds[msg.sender][_to], "NSF");
(bool success, ) = _to.call{value: _amount}("");
require(success, "failed to send ether");
_funds[msg.sender][_to] -= _amount;
}
/// @param _to the address to which funds will be returned
/// @param _amount the amount of wei to be returned
function returnFunds(address _to, uint256 _amount) public {
require(_amount <= _funds[_to][msg.sender], "NSF");
(bool success, ) = _to.call{value: _amount}("");
require(success, "failed to send ether");
_funds[_to][msg.sender] -= _amount;
}
/// @param _address the address to be added or removed from whitelist
/// @param _whitelisted the new value of their whitelist status
function setWhitelist(address _address, bool _whitelisted) public onlyOwner() {
whitelist[_address] = _whitelisted;
}
/// @param _percentage the percentage to update the dev fee to
function setPercentage(uint256 _percentage) public onlyOwner() {
percentage = _percentage;
}
function emptyJar() public {
(bool success, ) = owner().call{value: changeJar}("");
require(success, "failed to send ether");
}
}