-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Use Ownable in VestingWallet instead of an immutable beneficiary
#4508
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
Changes from 2 commits
21e01e7
9059ff1
f73699b
42a454e
4f56d4d
085aaf6
21bc8b4
ecd30f6
c70b8d0
4ce8164
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'openzeppelin-solidity': major | ||
| --- | ||
|
|
||
| `VestingWallet`: Use Ownable2Step instead of an immutable `beneficiary`. The initial owner is set to the benefactor (`msg.sender`) but transferred to the beneficiary address so that unclaimed tokens can be recovered by the benefactor. | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,12 +6,17 @@ import {IERC20} from "../token/ERC20/IERC20.sol"; | |||||||||
| import {SafeERC20} from "../token/ERC20/utils/SafeERC20.sol"; | ||||||||||
| import {Address} from "../utils/Address.sol"; | ||||||||||
| import {Context} from "../utils/Context.sol"; | ||||||||||
| import {Ownable2Step, Ownable} from "../access/Ownable2Step.sol"; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @title VestingWallet | ||||||||||
| * @dev This contract handles the vesting of Eth and ERC20 tokens for a given beneficiary. Custody of multiple tokens | ||||||||||
| * can be given to this contract, which will release the token to the beneficiary following a given vesting schedule. | ||||||||||
| * The vesting schedule is customizable through the {vestedAmount} function. | ||||||||||
| * @dev Handles the vesting of native currency and ERC20 tokens for a given beneficiary who gets the ownership of the | ||||||||||
| * contract by calling {Ownable2Step-acceptOwnership} to accept a 2-step ownership transfer setup at deployment with | ||||||||||
| * {Ownable2Step-transferOwnership}. The initial owner of this contract is the benefactor (`msg.sender`), enabling them | ||||||||||
| * to recover any unclaimed tokens. | ||||||||||
| * | ||||||||||
| * Custody of multiple tokens can be given to this contract, which will release the tokens to the beneficiary following | ||||||||||
| * a given vesting schedule that is customizable through the {vestedAmount} function. | ||||||||||
| * | ||||||||||
| * Any token transferred to this contract will follow the vesting schedule as if they were locked from the beginning. | ||||||||||
| * Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly) | ||||||||||
|
|
@@ -20,7 +25,7 @@ import {Context} from "../utils/Context.sol"; | |||||||||
| * By setting the duration to 0, one can configure this contract to behave like an asset timelock that hold tokens for | ||||||||||
| * a beneficiary until a specified time. | ||||||||||
| */ | ||||||||||
| contract VestingWallet is Context { | ||||||||||
| contract VestingWallet is Context, Ownable2Step { | ||||||||||
| event EtherReleased(uint256 amount); | ||||||||||
| event ERC20Released(address indexed token, uint256 amount); | ||||||||||
|
|
||||||||||
|
|
@@ -31,18 +36,19 @@ contract VestingWallet is Context { | |||||||||
|
|
||||||||||
| uint256 private _released; | ||||||||||
| mapping(address => uint256) private _erc20Released; | ||||||||||
| address private immutable _beneficiary; | ||||||||||
| uint64 private immutable _start; | ||||||||||
| uint64 private immutable _duration; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @dev Set the beneficiary, start timestamp and vesting duration of the vesting wallet. | ||||||||||
| * @dev Sets the sender as the initial owner, the beneficiary as the pending owner, the start timestamp and the | ||||||||||
| * vesting duration of the vesting wallet. | ||||||||||
| */ | ||||||||||
| constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable { | ||||||||||
| constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(msg.sender) { | ||||||||||
|
||||||||||
| constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(msg.sender) { | |
| constructor(address benefactorAddress, address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(benefactorAddress) { |
I think it has a few extra implications we need to consider, but I think this is definitely the way to go because a VestingWallet is the kind of contract that might be deployed with immutable clones. In such cases the deployer won't be able to claim the tokens back in case they're never claimed.
I guess the best solution to this is to allow setting a benefactor address (perhaps with a different name)
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.
you can present it as a "recovery address" in case the beneficiary doesn't claim ownership of the vesting
| constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(msg.sender) { | |
| constructor(address beneficiaryAddress, address recoveryAddress, uint64 startTimestamp, uint64 durationSeconds) payable Ownable(recoveryAddress) { |
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.
is "claiming owership of the vesting a taxable event"?
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 don't think it is, because a user claiming the ownership doesn't have access to transfer the tokens yet.
Uh oh!
There was an error while loading. Please reload this page.