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

Implementation of TimelockedEscrow, ConditionalTokenEscrow, RefundTokenEscrow & TimelockedTokenEscrow #1262

Merged

Conversation

tinchoabbate
Copy link
Contributor

🚀 Description

Further exploring different types of Escrows and possible implementations, I included four new contracts:

  • ConditionalTokenEscrow: similar to the existing ConditionalEscrow, but capable of handling an ERC20 token instead of ether.
  • RefundTokenEscrow: similar to the existing RefundEscrow, but capable of handling an ERC20 token instead of ether.
  • TimelockedEscrow: an implementation of a ConditionalEscrow that prevents the withdrawal of funds that were put in escrow for a certain amount of time.
  • TimelockedTokenEscrow: an implementation of the new ConditionalTokenEscrow that prevents the withdrawal of ERC20 tokens that were put in escrow for a certain amount of time.

The implementation of tests for the new ConditionalTokenEscrow also led to a refactoring of the existing TokenEscrow tests.

  • 📘 I've reviewed the OpenZeppelin Contributor Guidelines
  • ✅ I've added tests where applicable to test my new functionality.
  • 📖 I've made sure that my contracts are well-documented.
  • 🎨 I've run the JS/Solidity linters and fixed any issues (npm run lint:all:fix).

Martin Abbatemarco added 6 commits August 29, 2018 23:11
* Extracted behavior to a different file
* Updated docs of ConditionalTokenEscrow, RefundTokenEscrow, TimelockedEscrow and TimelockedTokenEscrow contracts
@nventuro nventuro self-assigned this Aug 31, 2018
@nventuro nventuro added feature New contracts, functions, or helpers. contracts Smart contract code. breaking change Changes that break backwards compatibility of the public API. and removed breaking change Changes that break backwards compatibility of the public API. labels Aug 31, 2018
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo, great work @tinchoabbate, thanks!

I left a couple comments: mosts of them are test-suite related, but a couple have to do with the design and exploration on this space.

contracts/payment/TimelockedEscrow.sol Outdated Show resolved Hide resolved
contracts/payment/TimelockedEscrow.sol Outdated Show resolved Hide resolved
contracts/payment/RefundTokenEscrow.sol Outdated Show resolved Hide resolved
contracts/payment/TimelockedEscrow.sol Outdated Show resolved Hide resolved
test/payment/ConditionalTokenEscrow.test.js Outdated Show resolved Hide resolved
test/payment/RefundTokenEscrow.test.js Outdated Show resolved Hide resolved
test/payment/RefundTokenEscrow.test.js Outdated Show resolved Hide resolved
test/payment/RefundTokenEscrow.test.js Show resolved Hide resolved
test/payment/TimelockedEscrow.test.js Outdated Show resolved Hide resolved
*/
function withdrawalAllowed(address _payee) public view returns (bool) {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= releaseTime);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to disallow payments after this time has elapsed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the one hand, if we do not disallow payments (i.e. leaving things as they are), once the time has elapsed, the escrow can at least continue working as a regular TokenEscrow. The owner must bare this in mind though. Should we go for this approach, we ought to explicitly describe this behavior somewhere in the contract.

On the other hand, if we do disallow payments, the contract would become useless once all tokens are withdrawn from the escrow.

Even though not entirely convinced yet, I'd go for the second option. It may be stricter, but I find it more predictable. If the owner wants a regular TokenEscrow after the time has elapsed, he/she should go ahead and deploy a new contract.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the contract be useless after the time has elapsed doesn't worry me too much right now: this is part of a bigger issue in the ecosystem, and we haven't yet taken a stance (e.g. providing self-destruct mechanisms).

I also like the second option more, though I guess it all depends on what this sort of contract would be used for. A time-locked payment doesn't make too much sense IMO without the ability to cancel, and in all cancellable scenarios I can think of, I don't see a reason why you'd want to pay after the time has expired.

Martin Abbatemarco added 4 commits September 2, 2018 22:47
* Improved withdrawalAllowed to return the condition (removed require)

* Specified units of releaseTime in a comment

* Improved tests readability with context blocks
* Specified units in releaseTime as a comment

* Improved tests readability with context blocks
* Fixed contract formatting

* Improved tests readability with describe blocks

* Added tests for the state variable
@nventuro nventuro merged commit ed451a8 into OpenZeppelin:escrow-exploration Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code. feature New contracts, functions, or helpers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants