Skip to content

Commit

Permalink
[ETHEREUM-CONTRACTS] overhaul of SuperTokenV1Library & legacy lib dep…
Browse files Browse the repository at this point in the history
…recation (#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
  • Loading branch information
d10r authored Nov 22, 2024
1 parent 5b5c548 commit ec92f23
Show file tree
Hide file tree
Showing 47 changed files with 1,167 additions and 9,764 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Before interacting with the Superfluid community, please read and understand our

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

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

Additionally recommended:
- jq
Expand Down
2 changes: 1 addition & 1 deletion packages/automation-contracts/autowrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.3.0",
"devDependencies": {
"@openzeppelin/contracts": "^4.9.6",
"@superfluid-finance/ethereum-contracts": "^1.11.1",
"@superfluid-finance/ethereum-contracts": "^1.12.0",
"@superfluid-finance/metadata": "^1.5.2"
},
"license": "MIT",
Expand Down
14 changes: 4 additions & 10 deletions packages/automation-contracts/scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ Deployment script will deploy all contracts and verify them on Etherscan.
npx hardhat deploy --network <network>
```


#### Deployed Contracts

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

#### Mainnets
| | FlowScheduler | VestingScheduler |
|---------|-------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| Polygon | [0x47D34512492D95A3531A628e5B85e32fAFaC1b42](https://polygonscan.com/address/0x47D34512492D95A3531A628e5B85e32fAFaC1b42#code) | [0xF9B3b4c23d08ebcBb8A70F5C7471E3Edd3ddF210](https://polygonscan.com/address/0xF9B3b4c23d08ebcBb8A70F5C7471E3Edd3ddF210#code) |
| BSC | [0x1D65c6d3AD39d454Ea8F682c49aE7744706eA96d](https://bscscan.com/address/0x1D65c6d3AD39d454Ea8F682c49aE7744706eA96d#code) | [0x4f268bfB109439D7c23A903c237cdBEbd7E987a1](https://bscscan.com/address/0x4f268bfB109439D7c23A903c237cdBEbd7E987a1#code) |
In package version 1.3.0 VestingScheduler (v1) was removed, as it's not gonna be used for new production deployments.
VestingSchedulerV2 and FlowScheduler were modified to use the SuperTokenV1Library instead of the deprecated CFAv1Library.
31 changes: 10 additions & 21 deletions packages/automation-contracts/scheduler/contracts/FlowScheduler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// solhint-disable not-rely-on-time
pragma solidity ^0.8.0;
import {
ISuperfluid, ISuperToken, SuperAppDefinitions, IConstantFlowAgreementV1
ISuperfluid, ISuperToken, SuperAppDefinitions
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
import { SuperAppBase } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperAppBase.sol";
import { CFAv1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";
import { IFlowScheduler } from "./interface/IFlowScheduler.sol";

/**
Expand All @@ -14,24 +14,12 @@ import { IFlowScheduler } from "./interface/IFlowScheduler.sol";
*/
contract FlowScheduler is IFlowScheduler, SuperAppBase {

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

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

constructor(ISuperfluid host) {
// Initialize CFA Library
cfaV1 = CFAv1Library.InitData(
host,
IConstantFlowAgreementV1(
address(
host.getAgreementClass(
keccak256("org.superfluid-finance.agreements.ConstantFlowAgreement.v1")
)
)
)
);

// super app registration. This is a dumb superApp, only for frontend batching calls.
uint256 configWord = SuperAppDefinitions.APP_LEVEL_FINAL |
SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP |
Expand All @@ -41,6 +29,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP |
SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP;
host.registerApp(configWord);
HOST = host;
}

/// @dev IFlowScheduler.createFlowSchedule implementation.
Expand Down Expand Up @@ -158,7 +147,7 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {
}

// Create a flow accordingly as per the flow schedule data.
cfaV1.createFlowByOperator(sender, receiver, superToken, schedule.flowRate, userData);
superToken.createFlowFrom(sender, receiver, schedule.flowRate, userData);

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

cfaV1.deleteFlowByOperator(sender, receiver, superToken, userData);
superToken.deleteFlowFrom(sender, receiver, userData);

emit DeleteFlowExecuted(
superToken,
Expand All @@ -209,8 +198,8 @@ contract FlowScheduler is IFlowScheduler, SuperAppBase {

function _getSender(bytes memory ctx) internal view returns(address sender) {
if(ctx.length != 0) {
if(msg.sender != address(cfaV1.host)) revert HostInvalid();
sender = cfaV1.host.decodeCtx(ctx).msgSender;
if(msg.sender != address(HOST)) revert HostInvalid();
sender = HOST.decodeCtx(ctx).msgSender;
} else {
sender = msg.sender;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ pragma solidity ^0.8.0;

import { FlowScheduler } from "./FlowScheduler.sol";
import {
ISuperToken, IConstantFlowAgreementV1
ISuperToken
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";

contract FlowSchedulerResolver {

using SuperTokenV1Library for ISuperToken;

FlowScheduler public flowScheduler;

constructor(address _flowScheduler) {
Expand All @@ -17,7 +20,7 @@ contract FlowSchedulerResolver {

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

FlowScheduler.FlowSchedule memory flowSchedule = flowScheduler.getFlowSchedule(
superToken,
sender,
superToken,
sender,
receiver
);

(, IConstantFlowAgreementV1 cfa) = flowScheduler.cfaV1();
(,uint8 permissions, int96 flowRateAllowance) = cfa.getFlowOperatorData(
ISuperToken(superToken),
sender,
address(flowScheduler)
);
(,int96 currentFlowRate,,) = cfa.getFlow(ISuperToken(superToken), sender, receiver);
(bool allowCreate, , bool allowDelete, int96 flowRateAllowance) =
ISuperToken(superToken).getFlowPermissions(sender, address(flowScheduler));

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

// 1. needs create and delete permission
// 2. scheduled flowRate must not be greater than allowance
if ( !allowCreate || !allowDelete || flowSchedule.flowRate > flowRateAllowance ) {
// return canExec as false and non-executable payload
return (
false,
"0x"
);

}

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

}

// 1. start date must be set (flow schedule exists)
// 2. start date must have been past
// 3. max delay must have not been exceeded
// 4. enough erc20 allowance to transfer the optional start amount
else if ( flowSchedule.startDate != 0 &&
block.timestamp >= flowSchedule.startDate &&
block.timestamp >= flowSchedule.startDate &&
block.timestamp <= flowSchedule.startDate + flowSchedule.startMaxDelay &&
ISuperToken(superToken).allowance(sender, address(flowScheduler)) >= flowSchedule.startAmount ) {

// return canExec as true and executeCreateFlow payload
return (
true,
Expand Down
Loading

0 comments on commit ec92f23

Please sign in to comment.