-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Expand file tree
/
Copy pathVestingWalletCliff.sol
More file actions
55 lines (47 loc) · 2.03 KB
/
VestingWalletCliff.sol
File metadata and controls
55 lines (47 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (finance/VestingWalletCliff.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "../utils/math/SafeCast.sol";
import {VestingWallet} from "./VestingWallet.sol";
/**
* @dev Extension of {VestingWallet} that adds a cliff to the vesting schedule.
*
* _Available since v5.1._
*/
abstract contract VestingWalletCliff is VestingWallet {
using SafeCast for *;
uint64 private immutable _cliff;
/// @dev The specified cliff duration is larger than the vesting duration.
error InvalidCliffDuration(uint64 cliffSeconds, uint64 durationSeconds);
/**
* @dev Set the duration of the cliff, in seconds. The cliff starts vesting schedule (see {VestingWallet}'s
* constructor) and ends `cliffSeconds` later.
*/
constructor(uint64 cliffSeconds) {
uint256 vestingDuration = duration();
if (cliffSeconds > vestingDuration) {
revert InvalidCliffDuration(cliffSeconds, vestingDuration.toUint64());
}
_cliff = start().toUint64() + cliffSeconds;
}
/**
* @dev Getter for the cliff timestamp.
*/
function cliff() public view virtual returns (uint256) {
return _cliff;
}
/**
* @dev Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for
* an asset given its total historical allocation. Returns 0 if the {cliff} timestamp is not met.
*
* IMPORTANT: The cliff not only makes the schedule return 0, but it also ignores every possible side
* effect from calling the inherited implementation (i.e. `super._vestingSchedule`). Carefully consider
* this caveat if the overridden implementation of this function has any (e.g. writing to memory or reverting).
*/
function _vestingSchedule(
uint256 totalAllocation,
uint64 timestamp
) internal view virtual override returns (uint256) {
return timestamp < cliff() ? 0 : super._vestingSchedule(totalAllocation, timestamp);
}
}