Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ETHEREUM-CONTRACTS] overhaul of SuperTokenV1Library & legacy lib deprecation #2032

Merged
merged 32 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b5f0fa5
remove ida functionality from SuperTokenV1Library, IDAv1Library
d10r Oct 18, 2024
8120854
also removing CFAv1Library and IDAForwarder
d10r Oct 18, 2024
59c5898
automation contracts still need a copy of CFAv1Library
d10r Oct 18, 2024
5031da5
remove from hotfuzz
d10r Oct 20, 2024
2cb23d9
fix StreamRedirector
d10r Oct 21, 2024
9bb6cb3
distributeToPool -> distribute
d10r Oct 21, 2024
d9f6584
remove ida from hotfuzz
d10r Oct 21, 2024
a1bec25
more ida purging from hotfuzz
d10r Oct 21, 2024
ae37aca
deleted too much
d10r Oct 21, 2024
3aa5b91
add setFlowrate and setFlowrateFrom
d10r Oct 22, 2024
5c2ef14
added flowX and transferX
d10r Oct 22, 2024
aa77282
remove createPool with bool args
d10r Oct 23, 2024
eea2ab0
remove legacy VestingScheduler
d10r Oct 23, 2024
5420aa9
migrate FlowScheduler to SuperToken lib
d10r Oct 23, 2024
011ab6d
migrated VestingSchedulerV2
d10r Oct 23, 2024
bf105c9
updated README and package.json
d10r Oct 23, 2024
40e894c
updated CHANGELOG
d10r Oct 23, 2024
f2d3ba7
make getFlowRate and getFlowInfo generic and add CFA specific variants
d10r Oct 23, 2024
1185266
removed updateMemberUnits, belongs to pool iface
d10r Oct 23, 2024
549e5c7
fix test case
d10r Oct 24, 2024
4c08c7d
setFlowrate -> setCFAFlowRate
d10r Oct 28, 2024
7a26b4d
bump version
d10r Oct 28, 2024
66f3899
better test coverage
d10r Oct 28, 2024
74e1d21
fix echidna testcase
d10r Oct 29, 2024
0b33f76
setCFAFlowRate -> flow
d10r Oct 30, 2024
05733de
merge dev
d10r Nov 21, 2024
94811c6
hotfuzz peer dependency
d10r Nov 21, 2024
e160f1b
fix path
d10r Nov 21, 2024
ef13be0
added getGDAFlowRate
d10r Nov 21, 2024
20178fc
added a few more methods (aliases, variants), reorganized code, updat…
d10r Nov 21, 2024
038b0d2
doc: capitalize libraries (#2036)
DemoYeti Nov 22, 2024
a1fcf6b
more convenience & test coverage
d10r Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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