Skip to content

Commit

Permalink
[automations] Vesting scheduler v2 - fix & v1 compatibility (#1977)
Browse files Browse the repository at this point in the history
* refactor: unify `createClaimableVestingSchedule` and `createVestingSchedule` functions

* refactor: reoder `createVestingScheduleFromAmountAndDuration` function params

* refactor: unify `createVestingScheduleFormAmountAndDuration` and `createClaimableVestingScheduleFormAmountAndDuration` functions

* chore: add `createVestingSchedule` v1 overload for backward compatibility

* fix: remove `cliffPeriod` parameter in `createAndExecuteVestingScheduleFromAmountAndDuration` function

* refactor: replace `_getSender(bytes(""))` by `msg.sender`
  • Loading branch information
0xPilou authored Jul 2, 2024
1 parent 5f42f63 commit d9351c2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
);
}

/// @dev IVestingScheduler.createVestingSchedule implementation.
function createVestingSchedule(
ISuperToken superToken,
address receiver,
uint32 startDate,
uint32 cliffDate,
int96 flowRate,
uint256 cliffAmount,
uint32 endDate,
bytes memory ctx
) external returns (bytes memory newCtx) {
newCtx = ctx;
address sender = _getSender(ctx);

_validateAndCreateVestingSchedule(
ScheduleCreationParams({
superToken: superToken,
sender: sender,
receiver: receiver,
startDate: _normalizeStartDate(startDate),
claimValidityDate: 0,
cliffDate: cliffDate,
flowRate: flowRate,
cliffAmount: cliffAmount,
endDate: endDate,
remainderAmount: 0
})
);
}

/// @dev IVestingScheduler.createVestingSchedule implementation.
function createVestingSchedule(
ISuperToken superToken,
Expand All @@ -94,7 +124,7 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
_validateAndCreateVestingSchedule(
ScheduleCreationParams({
superToken: superToken,
sender: _getSender(bytes("")),
sender: msg.sender,
receiver: receiver,
startDate: _normalizeStartDate(startDate),
claimValidityDate: claimValidityDate,
Expand Down Expand Up @@ -197,12 +227,10 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
uint32 cliffPeriod,
uint32 claimPeriod
) external {
address sender = _getSender(bytes(""));

_validateAndCreateVestingSchedule(
mapCreateVestingScheduleParams(
superToken,
sender,
msg.sender,
receiver,
totalAmount,
totalDuration,
Expand All @@ -219,15 +247,13 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod,
bytes memory ctx
) external returns (bytes memory newCtx) {
newCtx = _validateAndCreateAndExecuteVestingScheduleFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
ctx
);
}
Expand All @@ -237,15 +263,13 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod
uint32 totalDuration
) external {
_validateAndCreateAndExecuteVestingScheduleFromAmountAndDuration(
superToken,
receiver,
totalAmount,
totalDuration,
cliffPeriod,
bytes("")
);
}
Expand All @@ -256,7 +280,6 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod,
bytes memory ctx
) private returns (bytes memory newCtx) {
newCtx = ctx;
Expand All @@ -270,7 +293,7 @@ contract VestingSchedulerV2 is IVestingSchedulerV2, SuperAppBase {
totalAmount,
totalDuration,
_normalizeStartDate(0),
cliffPeriod,
0, // cliffPeriod
0 // claimValidityDate
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ interface IVestingSchedulerV2 {
bytes memory ctx
) external returns (bytes memory newCtx);

/**
* @dev See IVestingScheduler.createVestingSchedule overload for more details.
*/
function createVestingSchedule(
ISuperToken superToken,
address receiver,
uint32 startDate,
uint32 cliffDate,
int96 flowRate,
uint256 cliffAmount,
uint32 endDate,
bytes memory ctx
) external returns (bytes memory newCtx);

/**
* @dev See IVestingScheduler.createVestingSchedule overload for more details.
*/
Expand Down Expand Up @@ -208,15 +222,13 @@ 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 duration of the cliff period from the start date
* @param ctx Superfluid context used when batching operations. (or bytes(0) if not SF batching)
*/
function createAndExecuteVestingScheduleFromAmountAndDuration(
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod,
bytes memory ctx
) external returns (bytes memory newCtx);

Expand All @@ -227,10 +239,9 @@ interface IVestingSchedulerV2 {
ISuperToken superToken,
address receiver,
uint256 totalAmount,
uint32 totalDuration,
uint32 cliffPeriod
uint32 totalDuration
) external;

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

0 comments on commit d9351c2

Please sign in to comment.