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

Add token vesting #476

Merged
merged 17 commits into from
Oct 5, 2017
Merged

Add token vesting #476

merged 17 commits into from
Oct 5, 2017

Conversation

martriay
Copy link
Contributor

Continues #412, fixes #274.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up @martriay! 😄 Made a few comments

using SafeMath for uint256;

event Release(uint256 amount);
event Revoke();
Copy link
Contributor

Choose a reason for hiding this comment

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

The naming convention for events is either verbs in the past tense (Revoked) or nouns (Revocation?). I prefer the first one in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also changing Release to Released then!

*/
function TokenVesting(address _beneficiary, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) {
require(_beneficiary != 0x0);
require(_cliff < _duration);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd allow _cliff == _duration too. Do you see any downsides to that?

Copy link
Contributor Author

@martriay martriay Oct 2, 2017

Choose a reason for hiding this comment

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

No, I think it's good.

function TokenVesting(address _beneficiary, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) {
require(_beneficiary != 0x0);
require(_cliff < _duration);
require(_start >= now);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this. On one hand it's aligned with our usual recommendation for preconditions, as it would prevent some errors. On the other hand, I can imagine a situation where you want to create a contract for a vesting period that has been arranged off-chain, and already begun. What do you think about doing require(_start + _duration > now) instead?

Copy link
Contributor Author

@martriay martriay Oct 2, 2017

Choose a reason for hiding this comment

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

@frangio agree! But taking that into account I think we should also allow _start + _duration < now in order to support more use cases. I'll remove this check if you're ok with with it.

}

/**
* @dev Calculates the amount that has already vested but not released.
Copy link
Contributor

Choose a reason for hiding this comment

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

"[...] but hasn't been released yet." sounds better I think.

uint256 vested = totalBalance.mul(now - start).div(duration);
uint256 unreleased = vested.sub(released[token]);

// currentBalance can be 0 in case of a revoke
Copy link
Contributor

Choose a reason for hiding this comment

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

"[...] in the case that vesting was revoked early."

});

it('should be revoked by owner if revocable is set', async function () {
const vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner } );
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why you created a new identical instance here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to make it explicit and to avoid breaking this test by changing the beforeEach instantiation, but it can be removed.

@martriay
Copy link
Contributor Author

martriay commented Oct 2, 2017

@frangio thanks for the feedback! Updated with corrections.

@frangio frangio mentioned this pull request Oct 4, 2017
2 tasks
@frangio
Copy link
Contributor

frangio commented Oct 4, 2017

LGTM! Please remove the VestedToken and LimitedTransferTokens from the repository like we had mentioned in #412.

@martriay
Copy link
Contributor Author

martriay commented Oct 4, 2017

@frangio rebased due to merge conflicts. Ready!

@frangio
Copy link
Contributor

frangio commented Oct 5, 2017

Awesome, thanks!

@frangio frangio merged commit 5aba967 into OpenZeppelin:master Oct 5, 2017
ProphetDaniel pushed a commit to classicdelta/Smart-Contracts that referenced this pull request Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants