superfluid-finance / protocol-monorepo

Superfluid Protocol Monorepo: the specification, implementations, peripherals and development kits.
https://www.superfluid.finance
Other
875 stars 239 forks source link

[automations] VestingSchedulerV2 add helpful view functions #1965

Closed kasparkallas closed 5 months ago

kasparkallas commented 5 months ago

Added and exposed getCreateVestingScheduleParamsFromAmountAndDuration

The view function can be used to know up front what will be the stored VestingSchedule values. Useful for UI-s. It's effectively the previous _createVestingScheduleFromAmountAndDuration exposed as a view function without any logic changed.

Exposed ScheduleCreationParams

The struct holds all relevant values to a vesting schedule in addition to just the ones being stored. Useful for UI-s. Separated "superfluid context" out of it as it's a technical requirement of the smart contract to enable batching transaction, not necessarily relevant to the core data of the vesting schedule.

Deleted ScheduleCreationFromAmountAndDurationParams

Less is more.

Added and exposed getMaximumNeededTokenAllowance

Added a helpful utility function to calculate what is the maximum needed ERC-20 allowance for the vesting schedule to execute successfully under all conditions. Not used by the core contract logic as allowance is meant to be handled outside, so no added risk, but useful for UI-s (that otherwise would need to calculate all of this on their own).

Used uint96 for remainderAmount

Initially I used uint256 for simplicity sake but uint96 is plenty enough.

Re-ordered VestingSchedule packing

As there's no difference in the storage size used, I opted to order it in a more backwards compatible way to V1 vesting scheduler.

Added more tests

github-actions[bot] commented 5 months ago

Changelog Reminder

Reminder to update the CHANGELOG.md for any of the modified packages in this PR.

github-actions[bot] commented 5 months ago

XKCD Comic Relif

Link: https://xkcd.com/1965 https://xkcd.com/1965