Skip to content

Commit

Permalink
[automations][epic] Vesting Scheduler V2 (#1952)
Browse files Browse the repository at this point in the history
* chore: no-op for pull request diff

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [automations] Vesting Scheduler V2 ergonomic improvements (#1904)

* allow creation and execution of the vesting schedule in the current block

* add createVestingSchedule function which works with totalAmount and totalDuration

* add overloads without ctx

* need to improve testing coverage

* add more overloads with fewer parameters

* reorganize the functions

* add create and execute schedule mvp

* work in progress, needs proper testing

* remove try-catch from early end

* prefer reverting the early end until stream can be closed without needing the transfer (i.e. it will slightly overflow in that case)

* add dust amount fix (wip)

* needs proper test cover
* consider the log events

* rename from dustFixAmount to remainderAmount

* add to log as well

* fix test issues

* tiny comment rename

* remove functions create and execute functions with cliff period

* add a comprehensive fuzzed test for createScheduleFromAmountAndDuration

* slightly change end compensation & remainder handling

* use greater or equal handling for case when only remainder needs to be transferred
* assert transferFrom success result
* add todo-s, improve tests

* keep V1 contract, separate V2 explicitly

* update deploy script for v2

* unify deploy scripts

* use newer host.registerApp & unify deploy scripts

- add base-mainnet option

* clean-up

* add diff generation script & completely revert VestingScheduler.sol

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [AUTOMATIONS] Vesting Scheduler - add claimable schedule feature (#1944)

* added claimable vesting feature

* add check on `_executeCliffAndFlow` for claimable schedules

* updated time window condition on schedule claim

* fix typo

* add some unit tests for claiming schedules

* increased test coverage

* added claimValidityDate feature

* updated tests

* add claimValidityDate param to createSchedules function

* updated unit tests

* refactor internal function params (stack too deep) + add claimValidityDate to schedule creation event

* removed `isClaimable` boolean from VestingSchedule data structure

* remove internal function creating dupplication

* updated claim validity date check logic

* refactor: re-order the claimValidityDate in the event

- keep it as one of the last for backwards compatibility

* refactor: rename error

CannotClaimFlowOnBehalf to CannotClaimScheduleOnBehalf

* fix: remove merge issues from hardhat configs

* fix: remove duplication from hardhat config

* fix: moved & rename params struct into VestingSchedulerV2 contract

---------

Co-authored-by: Kaspar Kallas <[email protected]>
Co-authored-by: Kaspar Kallas <[email protected]>
Signed-off-by: Miao, ZhiCheng <[email protected]>

* [AUTOMATIONS] VestingSchdulerV2 improvements (#1963)

* update: change claimValidityDate to claimPeriod in function that takes amount and duration as params

* fix: clear claimValidityDate on claim + add checks to execute* functions

* update: add VestingClaimed event to `_executeCliffAndFlow` function

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [automations] VestingSchedulerV2 add helpful view functions (#1965)

* refactor: use uint96 for remainderAmount & change packing order

* feat: add `getMaximumNeededTokenAllowance` helper function with a test

* refactor: converge on view function usage

* chore: add comments

* chore: clean-up

* chore: reset whitespace

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [AUTOMATIONS] VestingSchedulerV2 claim after end date (#1964)

* update: change claimValidityDate to claimPeriod in function that takes amount and duration as params

* fix: clear claimValidityDate on claim + add checks to execute* functions

* update: add VestingClaimed event to `_executeCliffAndFlow` function

* feature: add capabilities to have claimValidityDate after endDate

* fix: rearrange `_executeCliffAndFlow` logic

* test: increased coverage for executeCliffAndFlow

* test: added revert check on `executeEndVesting` test

* refactor: clean-up

- add additional asserts
- change log event order (to match other situation)

---------

Co-authored-by: Kaspar Kallas <[email protected]>
Signed-off-by: Miao, ZhiCheng <[email protected]>

* fix: check if schedule is claimed on executeEndVesting

Signed-off-by: Miao, ZhiCheng <[email protected]>

* test: increased `getMaximumNeededTokenAllowance` coverage

Signed-off-by: Miao, ZhiCheng <[email protected]>

* feat: added remainderAmount in `VestingScheduleUpdated`

Signed-off-by: Miao, ZhiCheng <[email protected]>

* add tests & fixes

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [automations] Vesting Scheduler V2 refactoring after single-transfer feature (#1969)

* refactor: explicit functions

- _claim
- _exececuteAtSingleTransfer
- _getTotalVestedAmount

* chore: test that schedule is deleted in more places

* refactor: use more foundry bound in tests

* chore: test better the scenario where the schedule is not ended on time

* refactor: refactor to using aggregate object

- make executeCliffAndFlow public

* chore: improve the test further

* refactor: use aggregate in all places

* refactor: re-order some functions based on visibility

* chore: add small comment

* refactor: small whitespace fix

* refactor: use named parameters when using structs

* refactor: remove unnecessary comments

* fix: change type in log event

* chore: test claim event

* chore: add version

Signed-off-by: Miao, ZhiCheng <[email protected]>

* chore: add optimism hardhat config

Signed-off-by: Miao, ZhiCheng <[email protected]>

* refactor: unify `createClaimableVestingSchedule` and `createVestingSchedule` functions

Signed-off-by: Miao, ZhiCheng <[email protected]>

* refactor: reoder `createVestingScheduleFromAmountAndDuration` function params

Signed-off-by: Miao, ZhiCheng <[email protected]>

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

Signed-off-by: Miao, ZhiCheng <[email protected]>

* [automations] Vesting Scheduler V2 final clean-up (#1973)

* refactor: unify `createClaimableVestingSchedule` and `createVestingSchedule` functions

* refactor: reoder `createVestingScheduleFromAmountAndDuration` function params

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

* refactor: remove confusing overloads

* feat: add cliffPeriod to createAndExecute functions

* unify modifiers & remove a helper function

* refactor: use normalizeStartDate function to get a function to be pure

* refactor: remove unnecessary passing of ctx

* refactor: rename

* add more claim fuzz tests

* change log event semantics slightly for single transfer

* remove version

---------

Co-authored-by: Pilou <[email protected]>
Signed-off-by: Miao, ZhiCheng <[email protected]>

* [automations] Vesting scheduler v2 - fix & v1 compatibility (#1977)

* 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`

Signed-off-by: Miao, ZhiCheng <[email protected]>

* refactor: re-order functions for better readability

Signed-off-by: Miao, ZhiCheng <[email protected]>

---------

Signed-off-by: Miao, ZhiCheng <[email protected]>
Co-authored-by: Pilou <[email protected]>
  • Loading branch information
kasparkallas and 0xPilou authored Jul 23, 2024
1 parent 44b6510 commit 5106c44
Show file tree
Hide file tree
Showing 20 changed files with 3,579 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Thanks goes to these wonderful people ([🐸](https://allcontributors.org/docs/e

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
Expand Down
9 changes: 0 additions & 9 deletions packages/automation-contracts/autowrap/.env-example

This file was deleted.

11 changes: 11 additions & 0 deletions packages/automation-contracts/autowrap/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# .env-example

PRIVATE_KEY=

MUMBAI_URL=
POLYGON_URL=
BSC_URL=
OPSEPOLIA_URL=
BASE_URL=https://mainnet.base.org

ETHERSCAN_API_KEY=
46 changes: 41 additions & 5 deletions packages/automation-contracts/autowrap/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
optimizer: {
enabled: true,
runs: 200,
}
}
},
},
},
networks: {
localhost: {
Expand All @@ -29,21 +29,57 @@ module.exports = {
polygon: {
url: process.env.POLYGON_URL || "",
accounts:
process.env.POLYGON_PRIVATE_KEY !== undefined ? [process.env.POLYGON_PRIVATE_KEY] : [],
process.env.PRIVATE_KEY !== undefined
? [process.env.PRIVATE_KEY]
: [],
},
bsc: {
url: process.env.BSC_URL || "",
accounts:
process.env.BSC_PRIVATE_KEY !== undefined ? [process.env.BSC_PRIVATE_KEY] : [],
process.env.PRIVATE_KEY !== undefined
? [process.env.PRIVATE_KEY]
: [],
},
opsepolia: {
url: process.env.OPSEPOLIA_URL || "",
accounts:
process.env.PRIVATE_KEY !== undefined
? [process.env.PRIVATE_KEY]
: [],
},
"base-mainnet": {
url: process.env.BASE_URL || "",
accounts:
process.env.PRIVATE_KEY !== undefined
? [process.env.PRIVATE_KEY]
: [],
gasPrice: 1000000000,
},
},

namedAccounts: {
deployer: {
default: 0,
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
customChains: [
{
network: "opsepolia",
chainId: 11155420,
urls: {
apiURL: "https://api-sepolia-optimistic.etherscan.io/api",
browserURL: "https://sepolia-optimism.etherscan.io/",
},
},
{
network: "base-mainnet",
chainId: 8453,
urls: {
apiURL: "https://api.basescan.org/api",
browserURL: "https://basescan.org/",
},
},
],
},
};
1 change: 1 addition & 0 deletions packages/automation-contracts/autowrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"test": "forge test",
"build": "forge build",
"deploy": "npx hardhat deploy --network",
"lint": "run-s lint:*",
"lint:sol": "solhint -w 0 contracts/*.sol contracts/*/*.sol && echo '✔ Your .sol files look good.'",
"pre-commit": "if [ ! -z \"$(git status -s .)\" ];then run-s pre-commit:*;else true;fi",
Expand Down
9 changes: 0 additions & 9 deletions packages/automation-contracts/scheduler/.env-example

This file was deleted.

16 changes: 16 additions & 0 deletions packages/automation-contracts/scheduler/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .env-example

PRIVATE_KEY=

MUMBAI_URL=
POLYGON_URL=
BSC_URL=
OPSEPOLIA_URL=
BASE_URL=https://mainnet.base.org
OPTIMISM_URL=

ETHERSCAN_API_KEY=

DEPLOY_FLOW_SCHEDULER=
DEPLOY_VESTING_SCHEDULER=
DEPLOY_VESTING_SCHEDULER_V2=
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

git diff -U9999 --no-index --minimal --ignore-cr-at-eol --ignore-space-at-eol ./../contracts/interface/IVestingScheduler.sol ./../contracts/interface/IVestingSchedulerV2.sol > diff_IVestingScheduler_vs_IVestingSchedulerV2.txt
git diff -U9999 --no-index --minimal --ignore-cr-at-eol --ignore-space-at-eol ./../contracts/VestingScheduler.sol ./../contracts/VestingSchedulerV2.sol > diff_VestingScheduler_vs_VestingSchedulerV2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
using CFAv1Library for CFAv1Library.InitData;
CFAv1Library.InitData public cfaV1; //initialize cfaV1 variable

constructor(ISuperfluid host, string memory registrationKey) {
constructor(ISuperfluid host) {
// Initialize CFA Library
cfaV1 = CFAv1Library.InitData(
host,
Expand All @@ -40,7 +40,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
SuperAppDefinitions.AFTER_AGREEMENT_UPDATED_NOOP |
SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP |
SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP;
host.registerAppWithKey(configWord, registrationKey);
host.registerApp(configWord);
}

/// @dev IFlowScheduler.createFlowSchedule implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract VestingScheduler is IVestingScheduler, SuperAppBase {
uint32 public constant START_DATE_VALID_AFTER = 3 days;
uint32 public constant END_DATE_VALID_BEFORE = 1 days;

constructor(ISuperfluid host, string memory registrationKey) {
constructor(ISuperfluid host) {
cfaV1 = CFAv1Library.InitData(
host,
IConstantFlowAgreementV1(
Expand All @@ -37,7 +37,7 @@ contract VestingScheduler is IVestingScheduler, SuperAppBase {
SuperAppDefinitions.AFTER_AGREEMENT_UPDATED_NOOP |
SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP |
SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP;
host.registerAppWithKey(configWord, registrationKey);
host.registerApp(configWord);
}

/// @dev IVestingScheduler.createVestingSchedule implementation.
Expand Down Expand Up @@ -254,4 +254,4 @@ contract VestingScheduler is IVestingScheduler, SuperAppBase {
(,int96 flowRate,,) = cfaV1.cfa.getFlow(superToken, sender, receiver);
return flowRate != 0;
}
}
}
Loading

0 comments on commit 5106c44

Please sign in to comment.