Skip to content

Commit

Permalink
refactor: unify createVestingScheduleFormAmountAndDuration and `cre…
Browse files Browse the repository at this point in the history
…ateClaimableVestingScheduleFormAmountAndDuration` functions
  • Loading branch information
0xPilou committed Jul 1, 2024
1 parent 919b9b4 commit 55ed778
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 230 deletions.
125 changes: 18 additions & 107 deletions packages/automation-contracts/scheduler/contracts/VestingSchedulerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
uint32 totalDuration,
uint32 startDate,
uint32 cliffPeriod,
uint32 claimPeriod,
bytes memory ctx
) external returns (bytes memory newCtx) {
newCtx = _validateAndCreateVestingSchedule(
Expand All @@ -183,9 +184,9 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
receiver,
totalAmount,
totalDuration,
cliffPeriod,
startDate,
0 // claimPeriod
cliffPeriod,
claimPeriod
),
ctx
);
Expand All @@ -198,17 +199,18 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
uint256 totalAmount,
uint32 totalDuration,
uint32 startDate,
uint32 cliffPeriod
uint32 cliffPeriod,
uint32 claimPeriod
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
startDate,
0 // claimPeriod
cliffPeriod,
claimPeriod
),
bytes("")
);
Expand All @@ -220,17 +222,18 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod
uint32 cliffPeriod,
uint32 claimPeriod
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
0, // startDate
0 // claimPeriod
cliffPeriod,
claimPeriod
),
bytes("")
);
Expand All @@ -241,17 +244,18 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration
uint32 totalDuration,
uint32 claimPeriod
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
0, // cliffPeriod
0, // startDate
0 // claimPeriod
0, // cliffPeriod
claimPeriod
),
bytes("")
);
Expand Down Expand Up @@ -304,8 +308,8 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
receiver,
totalAmount,
totalDuration,
0, // cliffPeriod
0, // startDate
0, // cliffPeriod
0 // claimValidityDate
),
ctx
Expand All @@ -318,100 +322,7 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
assert(_executeCliffAndFlow(agg));
}

/// @dev IVestingScheduler.createClaimableVestingScheduleFromAmountAndDuration implementation.
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod,
uint32 startDate,
bytes memory ctx
) external returns (bytes memory newCtx) {
newCtx = _validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
startDate,
claimPeriod
),
ctx
);
}

/// @dev IVestingScheduler.createClaimableVestingScheduleFromAmountAndDuration implementation.
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod,
uint32 startDate
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
startDate,
claimPeriod
),
bytes("")
);
}

/// @dev IVestingScheduler.createVestingScheduleFromAmountAndDuration implementation.
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
0, // startDate
claimPeriod
),
bytes("")
);
}

/// @dev IVestingScheduler.createVestingScheduleFromAmountAndDuration implementation.
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod
) external {
_validateAndCreateVestingSchedule(
getCreateVestingScheduleParamsFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
0, // cliffPeriod
0, // startDate
claimPeriod
),
bytes("")
);
}

/// @dev IVestingScheduler.updateVestingSchedule implementation.
function updateVestingSchedule(
ISuperToken superToken,
address receiver,
Expand Down Expand Up @@ -668,8 +579,8 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod,
uint32 startDate,
uint32 cliffPeriod,
uint32 claimPeriod
) public view override returns (ScheduleCreationParams memory result) {
// Default to current block timestamp if no start date is provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ interface IVestingSchedulerV2 {
* @param totalDuration The total duration of the vestingß
* @param startDate Timestamp when the vesting should start
* @param cliffPeriod The cliff period of the vesting
* @param claimPeriod The claim availability period
* @param ctx Superfluid context used when batching operations. (or bytes(0) if not SF batching)
*/
function createVestingScheduleFromAmountAndDuration(
Expand All @@ -149,6 +150,7 @@ interface IVestingSchedulerV2 {
uint32 totalDuration,
uint32 startDate,
uint32 cliffPeriod,
uint32 claimPeriod,
bytes memory ctx
) external returns (bytes memory newCtx);

Expand All @@ -161,7 +163,8 @@ interface IVestingSchedulerV2 {
uint256 totalAmount,
uint32 totalDuration,
uint32 startDate,
uint32 cliffPeriod
uint32 cliffPeriod,
uint32 claimPeriod
) external;

/**
Expand All @@ -173,7 +176,8 @@ interface IVestingSchedulerV2 {
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod
uint32 cliffPeriod,
uint32 claimPeriod
) external;

/**
Expand All @@ -185,7 +189,8 @@ interface IVestingSchedulerV2 {
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration
uint32 totalDuration,
uint32 claimPeriod
) external;

/**
Expand All @@ -195,17 +200,17 @@ interface IVestingSchedulerV2 {
* @param receiver Vesting receiver
* @param totalAmount The total amount to be vested
* @param totalDuration The total duration of the vestingß
* @param cliffPeriod The cliff period of the vesting
* @param startDate Timestamp when the vesting should start
* @param cliffPeriod The cliff period of the vesting
* @param claimPeriod The claim availability period
*/
function getCreateVestingScheduleParamsFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod,
uint32 startDate,
uint32 cliffPeriod,
uint32 claimPeriod
) external returns (ScheduleCreationParams memory params);

Expand Down Expand Up @@ -257,69 +262,6 @@ interface IVestingSchedulerV2 {
uint32 totalDuration
) external;

/**
* @dev Creates a new vesting schedule that needs to be claimed by the receiver to start flowing.
* @dev The function makes it more intuitive to create a vesting schedule compared to the original function.
* @dev The function calculates the endDate, cliffDate, cliffAmount, flowRate, etc, based on the input arguments.
* @param superToken SuperToken to be vested
* @param receiver Vesting receiver
* @param totalAmount The total amount to be vested
* @param totalDuration The total duration of the vesting
* @param claimPeriod The claim availability period
* @param cliffPeriod The cliff period of the vesting
* @param startDate Timestamp when the vesting should start
* @param ctx Superfluid context used when batching operations. (or bytes(0) if not SF batching)
*/
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod,
uint32 startDate,
bytes memory ctx
) external returns (bytes memory newCtx);

/**
* @dev See IVestingScheduler.createClaimableVestingScheduleFromAmountAndDuration overload for more details.
*/
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod,
uint32 startDate
) external;

/**
* @dev See IVestingScheduler.createClaimableVestingScheduleFromAmountAndDuration overload for more details.
* The startDate is set to current block timestamp.
*/
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod,
uint32 cliffPeriod
) external;

/**
* @dev See IVestingScheduler.createClaimableVestingScheduleFromAmountAndDuration overload for more details.
* The startDate is set to current block timestamp.
* Cliff period is not applied.
*/
function createClaimableVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 claimPeriod
) external;

/**
* @dev Event emitted on update of a vesting schedule
* @param superToken The superToken to be vested
Expand Down
Loading

0 comments on commit 55ed778

Please sign in to comment.