Skip to content

Commit ec92f23

Browse files
authored
[ETHEREUM-CONTRACTS] overhaul of SuperTokenV1Library & legacy lib deprecation (#2032)
* remove CFAv1Library and CFAIDAv1Library * remove IDA functionality from SuperTokenV1Library * remove IDAForwarder * port automation contracts to SuperTokenV1Library * remove legacy VestingScheduler * various changes in SuperTokenV1Library * bump ethereum-contracts version to 1.12.0
1 parent 5b5c548 commit ec92f23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1167
-9764
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Before interacting with the Superfluid community, please read and understand our
1010

1111
At minimum, you will need to have these available in your development environment:
1212

13-
- yarn, sufficiently recent version, the actual yarn version is locked in `.yarnrc`.
14-
- nodejs 18.x.
13+
- Yarn, sufficiently recent version, the actual yarn version is locked in `.yarnrc`.
14+
- Node.js 18.x.
1515

1616
Additionally recommended:
1717
- jq

packages/automation-contracts/autowrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.3.0",
55
"devDependencies": {
66
"@openzeppelin/contracts": "^4.9.6",
7-
"@superfluid-finance/ethereum-contracts": "^1.11.1",
7+
"@superfluid-finance/ethereum-contracts": "^1.12.0",
88
"@superfluid-finance/metadata": "^1.5.2"
99
},
1010
"license": "MIT",

packages/automation-contracts/scheduler/README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,10 @@ Deployment script will deploy all contracts and verify them on Etherscan.
4949
npx hardhat deploy --network <network>
5050
```
5151

52-
5352
#### Deployed Contracts
5453

55-
#### Testnets
56-
| | FlowScheduler | VestingScheduler |
57-
|----------|--------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
58-
| OP Sepolia | [0x73B1Ce21d03ad389C2A291B1d1dc4DAFE7B5Dc68](https://sepolia-optimism.etherscan.io/address/0x73B1Ce21d03ad389C2A291B1d1dc4DAFE7B5Dc68) | [0x27444c0235a4D921F3106475faeba0B5e7ABDD7a](https://sepolia-optimism.etherscan.io/address/0x27444c0235a4D921F3106475faeba0B5e7ABDD7a) |
54+
Contract addresses can be found in https://explorer.superfluid.finance/protocol, with the data source being `networks.json` in the metadata package.
55+
All current production deployments are based on the codebase found in version 1.2.0 of the scheduler package.
5956

60-
#### Mainnets
61-
| | FlowScheduler | VestingScheduler |
62-
|---------|-------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
63-
| Polygon | [0x47D34512492D95A3531A628e5B85e32fAFaC1b42](https://polygonscan.com/address/0x47D34512492D95A3531A628e5B85e32fAFaC1b42#code) | [0xF9B3b4c23d08ebcBb8A70F5C7471E3Edd3ddF210](https://polygonscan.com/address/0xF9B3b4c23d08ebcBb8A70F5C7471E3Edd3ddF210#code) |
64-
| BSC | [0x1D65c6d3AD39d454Ea8F682c49aE7744706eA96d](https://bscscan.com/address/0x1D65c6d3AD39d454Ea8F682c49aE7744706eA96d#code) | [0x4f268bfB109439D7c23A903c237cdBEbd7E987a1](https://bscscan.com/address/0x4f268bfB109439D7c23A903c237cdBEbd7E987a1#code) |
57+
In package version 1.3.0 VestingScheduler (v1) was removed, as it's not gonna be used for new production deployments.
58+
VestingSchedulerV2 and FlowScheduler were modified to use the SuperTokenV1Library instead of the deprecated CFAv1Library.

packages/automation-contracts/scheduler/contracts/FlowScheduler.sol

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// solhint-disable not-rely-on-time
33
pragma solidity ^0.8.0;
44
import {
5-
ISuperfluid, ISuperToken, SuperAppDefinitions, IConstantFlowAgreementV1
5+
ISuperfluid, ISuperToken, SuperAppDefinitions
66
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
77
import { SuperAppBase } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperAppBase.sol";
8-
import { CFAv1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
8+
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";
99
import { IFlowScheduler } from "./interface/IFlowScheduler.sol";
1010

1111
/**
@@ -14,24 +14,12 @@ import { IFlowScheduler } from "./interface/IFlowScheduler.sol";
1414
*/
1515
contract FlowScheduler is IFlowScheduler, SuperAppBase {
1616

17-
mapping(bytes32 => FlowSchedule) public flowSchedules; // id = keccak(supertoken, sender, receiver)
17+
using SuperTokenV1Library for ISuperToken;
1818

19-
using CFAv1Library for CFAv1Library.InitData;
20-
CFAv1Library.InitData public cfaV1; //initialize cfaV1 variable
19+
ISuperfluid public immutable HOST;
20+
mapping(bytes32 => FlowSchedule) public flowSchedules; // id = keccak(supertoken, sender, receiver)
2121

2222
constructor(ISuperfluid host) {
23-
// Initialize CFA Library
24-
cfaV1 = CFAv1Library.InitData(
25-
host,
26-
IConstantFlowAgreementV1(
27-
address(
28-
host.getAgreementClass(
29-
keccak256("org.superfluid-finance.agreements.ConstantFlowAgreement.v1")
30-
)
31-
)
32-
)
33-
);
34-
3523
// super app registration. This is a dumb superApp, only for frontend batching calls.
3624
uint256 configWord = SuperAppDefinitions.APP_LEVEL_FINAL |
3725
SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP |
@@ -41,6 +29,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
4129
SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP |
4230
SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP;
4331
host.registerApp(configWord);
32+
HOST = host;
4433
}
4534

4635
/// @dev IFlowScheduler.createFlowSchedule implementation.
@@ -158,7 +147,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
158147
}
159148

160149
// Create a flow accordingly as per the flow schedule data.
161-
cfaV1.createFlowByOperator(sender, receiver, superToken, schedule.flowRate, userData);
150+
superToken.createFlowFrom(sender, receiver, schedule.flowRate, userData);
162151

163152
emit CreateFlowExecuted(
164153
superToken,
@@ -188,7 +177,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
188177
// revert if userData was set by user, but caller didn't provide it
189178
if ((userData.length != 0 ? keccak256(userData) : bytes32(0x0)) != schedule.userData) revert UserDataInvalid();
190179

191-
cfaV1.deleteFlowByOperator(sender, receiver, superToken, userData);
180+
superToken.deleteFlowFrom(sender, receiver, userData);
192181

193182
emit DeleteFlowExecuted(
194183
superToken,
@@ -209,8 +198,8 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
209198

210199
function _getSender(bytes memory ctx) internal view returns(address sender) {
211200
if(ctx.length != 0) {
212-
if(msg.sender != address(cfaV1.host)) revert HostInvalid();
213-
sender = cfaV1.host.decodeCtx(ctx).msgSender;
201+
if(msg.sender != address(HOST)) revert HostInvalid();
202+
sender = HOST.decodeCtx(ctx).msgSender;
214203
} else {
215204
sender = msg.sender;
216205
}

packages/automation-contracts/scheduler/contracts/FlowSchedulerResolver.sol

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ pragma solidity ^0.8.0;
44

55
import { FlowScheduler } from "./FlowScheduler.sol";
66
import {
7-
ISuperToken, IConstantFlowAgreementV1
7+
ISuperToken
88
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
9+
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";
910

1011
contract FlowSchedulerResolver {
1112

13+
using SuperTokenV1Library for ISuperToken;
14+
1215
FlowScheduler public flowScheduler;
1316

1417
constructor(address _flowScheduler) {
@@ -17,7 +20,7 @@ contract FlowSchedulerResolver {
1720

1821
/**
1922
* @dev Gelato resolver that checks whether Flow Scheduler action can be taken
20-
* @notice Make sure ACL permissions and ERC20 approvals are set for `flowScheduler`
23+
* @notice Make sure ACL permissions and ERC20 approvals are set for `flowScheduler`
2124
* before using Gelato automation with this resolver
2225
* @return bool whether there is a valid Flow Scheduler action to be taken or not
2326
* @return bytes the function payload to be executed (empty if none)
@@ -29,30 +32,24 @@ contract FlowSchedulerResolver {
2932
) external view returns( bool , bytes memory ) {
3033

3134
FlowScheduler.FlowSchedule memory flowSchedule = flowScheduler.getFlowSchedule(
32-
superToken,
33-
sender,
35+
superToken,
36+
sender,
3437
receiver
3538
);
3639

37-
(, IConstantFlowAgreementV1 cfa) = flowScheduler.cfaV1();
38-
(,uint8 permissions, int96 flowRateAllowance) = cfa.getFlowOperatorData(
39-
ISuperToken(superToken),
40-
sender,
41-
address(flowScheduler)
42-
);
43-
(,int96 currentFlowRate,,) = cfa.getFlow(ISuperToken(superToken), sender, receiver);
40+
(bool allowCreate, , bool allowDelete, int96 flowRateAllowance) =
41+
ISuperToken(superToken).getFlowPermissions(sender, address(flowScheduler));
4442

45-
// 1. permissions must not be create/update/delete (7) or create/delete (5)
46-
// 2. scheduled flowRate must not be greater than allowance
47-
if ( ( permissions != 5 && permissions != 7 )
48-
|| flowSchedule.flowRate > flowRateAllowance ) {
43+
int96 currentFlowRate = ISuperToken(superToken).getFlowRate(sender, receiver);
4944

45+
// 1. needs create and delete permission
46+
// 2. scheduled flowRate must not be greater than allowance
47+
if ( !allowCreate || !allowDelete || flowSchedule.flowRate > flowRateAllowance ) {
5048
// return canExec as false and non-executable payload
5149
return (
5250
false,
5351
"0x"
5452
);
55-
5653
}
5754

5855
// 1. end date must be set (flow schedule exists)
@@ -76,16 +73,16 @@ contract FlowSchedulerResolver {
7673
);
7774

7875
}
79-
76+
8077
// 1. start date must be set (flow schedule exists)
8178
// 2. start date must have been past
8279
// 3. max delay must have not been exceeded
8380
// 4. enough erc20 allowance to transfer the optional start amount
8481
else if ( flowSchedule.startDate != 0 &&
85-
block.timestamp >= flowSchedule.startDate &&
82+
block.timestamp >= flowSchedule.startDate &&
8683
block.timestamp <= flowSchedule.startDate + flowSchedule.startMaxDelay &&
8784
ISuperToken(superToken).allowance(sender, address(flowScheduler)) >= flowSchedule.startAmount ) {
88-
85+
8986
// return canExec as true and executeCreateFlow payload
9087
return (
9188
true,

0 commit comments

Comments
 (0)