-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Escrows #1014
Merged
Merged
Escrows #1014
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2d2075a
Added basic Escrow
nventuro b879f4c
PullPayment now uses an Escrow, removing all trust from the contract
nventuro 48b64ce
Abstracted the Escrow tests to a behaviour
nventuro 3600240
Added ConditionalEscrow
nventuro fe63f2e
Added RefundableEscrow.
nventuro 3a33ffb
RefundableCrowdsale now uses a RefundEscrow, removed RefundVault.
nventuro d389fd3
Merge branch 'master' into feat/escrow
nventuro e01edb3
Renaming after code review.
nventuro 5dfb9ce
Added log test helper.
nventuro 6166248
Now allowing empty deposits and withdrawals.
nventuro cd84c37
Style fixes.
nventuro dabb3d7
Minor review comments.
nventuro 4422858
Add Deposited and Withdrawn events, removed Refunded
nventuro be8d65f
The base Escrow is now Ownable, users of it (owners) must provide metβ¦
nventuro 597aba7
Merge branch 'master' into feat/escrow
frangio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
|
||
import "../payment/ConditionalEscrow.sol"; | ||
|
||
|
||
// mock class using ConditionalEscrow | ||
contract ConditionalEscrowMock is ConditionalEscrow { | ||
mapping(address => bool) public allowed; | ||
|
||
function setAllowed(address _payee, bool _allowed) public { | ||
allowed[_payee] = _allowed; | ||
} | ||
|
||
function withdrawalAllowed(address _payee) public view returns (bool) { | ||
return allowed[_payee]; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "./Escrow.sol"; | ||
|
||
|
||
/** | ||
* @title ConditionalEscrow | ||
* @dev Base abstract escrow to only allow withdrawal if a condition is met. | ||
*/ | ||
contract ConditionalEscrow is Escrow { | ||
/** | ||
* @dev Returns whether an address is allowed to withdraw their funds. To be | ||
* implemented by derived contracts. | ||
* @param _payee The destination address of the funds. | ||
*/ | ||
function withdrawalAllowed(address _payee) public view returns (bool); | ||
|
||
function withdraw(address _payee) public { | ||
require(withdrawalAllowed(_payee)); | ||
super.withdraw(_payee); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "../math/SafeMath.sol"; | ||
import "../ownership/Ownable.sol"; | ||
|
||
|
||
/** | ||
* @title Escrow | ||
* @dev Base escrow contract, holds funds destinated to a payee until they | ||
* withdraw them. The contract that uses the escrow as its payment method | ||
* should be its owner, and provide public methods redirecting to the escrow's | ||
* deposit and withdraw. | ||
*/ | ||
contract Escrow is Ownable { | ||
using SafeMath for uint256; | ||
|
||
event Deposited(address indexed payee, uint256 weiAmount); | ||
event Withdrawn(address indexed payee, uint256 weiAmount); | ||
|
||
mapping(address => uint256) private deposits; | ||
|
||
function depositsOf(address _payee) public view returns (uint256) { | ||
return deposits[_payee]; | ||
} | ||
|
||
/** | ||
* @dev Stores the sent amount as credit to be withdrawn. | ||
* @param _payee The destination address of the funds. | ||
*/ | ||
function deposit(address _payee) public onlyOwner payable { | ||
uint256 amount = msg.value; | ||
deposits[_payee] = deposits[_payee].add(amount); | ||
|
||
emit Deposited(_payee, amount); | ||
} | ||
|
||
/** | ||
* @dev Withdraw accumulated balance for a payee. | ||
* @param _payee The address whose funds will be withdrawn and transferred to. | ||
*/ | ||
function withdraw(address _payee) public onlyOwner { | ||
uint256 payment = deposits[_payee]; | ||
assert(address(this).balance >= payment); | ||
|
||
deposits[_payee] = 0; | ||
|
||
_payee.transfer(payment); | ||
|
||
emit Withdrawn(_payee, payment); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
|
||
import "../math/SafeMath.sol"; | ||
import "./Escrow.sol"; | ||
|
||
|
||
/** | ||
* @title PullPayment | ||
* @dev Base contract supporting async send for pull payments. Inherit from this | ||
* contract and use asyncSend instead of send or transfer. | ||
* contract and use asyncTransfer instead of send or transfer. | ||
*/ | ||
contract PullPayment { | ||
using SafeMath for uint256; | ||
Escrow private escrow; | ||
|
||
mapping(address => uint256) public payments; | ||
uint256 public totalPayments; | ||
constructor() public { | ||
escrow = new Escrow(); | ||
} | ||
|
||
/** | ||
* @dev Withdraw accumulated balance, called by payee. | ||
*/ | ||
function withdrawPayments() public { | ||
address payee = msg.sender; | ||
uint256 payment = payments[payee]; | ||
|
||
require(payment != 0); | ||
require(address(this).balance >= payment); | ||
|
||
totalPayments = totalPayments.sub(payment); | ||
payments[payee] = 0; | ||
escrow.withdraw(payee); | ||
} | ||
|
||
payee.transfer(payment); | ||
/** | ||
* @dev Returns the credit owed to an address. | ||
* @param _dest The creditor's address. | ||
*/ | ||
function payments(address _dest) public view returns (uint256) { | ||
return escrow.depositsOf(_dest); | ||
} | ||
|
||
/** | ||
* @dev Called by the payer to store the sent amount as credit to be pulled. | ||
* @param dest The destination address of the funds. | ||
* @param amount The amount to transfer. | ||
* @param _dest The destination address of the funds. | ||
* @param _amount The amount to transfer. | ||
*/ | ||
function asyncSend(address dest, uint256 amount) internal { | ||
payments[dest] = payments[dest].add(amount); | ||
totalPayments = totalPayments.add(amount); | ||
function asyncTransfer(address _dest, uint256 _amount) internal { | ||
escrow.deposit.value(_amount)(_dest); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
RefundEscrow
is very much crowdsale-specific so it should be with the crowdsale stuff. Potentially in this same file. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree: a
RefundEscrow
is a payment method, a crowdsale typically using it doesn't make it crowdsale-specific. As an example, platforms like Amazon or eBay also offer refunds and act as an escrow themselves, and could extend their payment systems to add support for multiple payers.