-
Notifications
You must be signed in to change notification settings - Fork 12k
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 5 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 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 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 |
---|---|---|
|
@@ -6,22 +6,23 @@ import "../ownership/Ownable.sol"; | |
|
||
/** | ||
* @title RefundEscrow | ||
* @dev Escrow that holds investor funds for a unique benefitiary, and allows for | ||
* either withdrawal by the benefiatiary, or refunds to the investors. | ||
* @dev Escrow that holds funds for a beneficiary, deposited from multiple parties. | ||
* The contract owner may close the deposit period, and allow for either withdrawal | ||
* by the beneficiary, or refunds to the depositors. | ||
*/ | ||
contract RefundEscrow is ConditionalEscrow, Ownable { | ||
enum State { Active, Refunding, Closed } | ||
|
||
event Closed(); | ||
event RefundsEnabled(); | ||
event Refunded(address indexed investor, uint256 weiAmount); | ||
event Refunded(address indexed refundee, uint256 weiAmount); | ||
|
||
State public state; | ||
address public beneficiary; | ||
|
||
/** | ||
* @dev Constructor. | ||
* @param _beneficiary The beneficiary of the investments. | ||
* @param _beneficiary The beneficiary of the deposits. | ||
*/ | ||
constructor(address _beneficiary) public { | ||
require(_beneficiary != address(0)); | ||
|
@@ -31,23 +32,16 @@ contract RefundEscrow is ConditionalEscrow, Ownable { | |
|
||
/** | ||
* @dev Stores funds that may later be refunded. | ||
* @param _investor The address funds will be sent to if a refund occurs. | ||
* @param _refundee The address funds will be sent to if a refund occurs. | ||
*/ | ||
function invest(address _investor) payable public { | ||
function deposit(address _refundee) payable public { | ||
require(state == State.Active); | ||
super.deposit(_investor); | ||
} | ||
|
||
/** | ||
* @dev Disable the base deposit function, use invest instead. | ||
*/ | ||
function deposit(address _payee) payable public { | ||
revert(); | ||
super.deposit(_refundee); | ||
} | ||
|
||
/** | ||
* @dev Allows for the beneficiary to withdraw their funds, rejecting | ||
* further investments. | ||
* further deposits. | ||
*/ | ||
function close() onlyOwner public { | ||
require(state == State.Active); | ||
|
@@ -56,7 +50,7 @@ contract RefundEscrow is ConditionalEscrow, Ownable { | |
} | ||
|
||
/** | ||
* @dev Allows for refunds to take place, rejecting further investments. | ||
* @dev Allows for refunds to take place, rejecting further deposits. | ||
*/ | ||
function enableRefunds() onlyOwner public { | ||
require(state == State.Active); | ||
|
@@ -67,23 +61,23 @@ contract RefundEscrow is ConditionalEscrow, Ownable { | |
/** | ||
* @dev Withdraws the beneficiary's funds. | ||
*/ | ||
function withdraw() public { | ||
function beneficiaryWithdraw() public { | ||
require(state == State.Closed); | ||
beneficiary.transfer(address(this).balance); | ||
} | ||
|
||
/** | ||
* @dev Refunds an investor. | ||
* @param _investor The address to refund. | ||
* @dev Refunds a refundee. | ||
* @param _refundee The address to refund. | ||
*/ | ||
function refund(address _investor) public { | ||
uint256 amount = depositsOf(_investor); | ||
super.withdraw(_investor); | ||
emit Refunded(_investor, amount); | ||
function withdraw(address _refundee) public { | ||
uint256 amount = depositsOf(_refundee); | ||
super.withdraw(_refundee); | ||
emit Refunded(_refundee, amount); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove when we add events to |
||
} | ||
|
||
/** | ||
* @dev Returns whether investors can withdraw their investments (be refunded). | ||
* @dev Returns whether refundees can withdraw their deposits (be refunded). | ||
*/ | ||
function withdrawalAllowed(address _payee) public view returns (bool) { | ||
return state == State.Refunding; | ||
|
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 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
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'd like to get a second/third opinion on this name. Alternative:
withdrawToBeneficiary
.