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

Route createAVSPaymetnSubmission via SM #92

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 6 additions & 1 deletion contracts/script/HelloWorldDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ contract HelloWorldDeployer is Script {

address private deployer;
address proxyAdmin;
address rewardsOwner;
address rewardsInitiator;
IStrategy helloWorldStrategy;
CoreDeploymentLib.DeploymentData coreDeployment;
HelloWorldDeploymentLib.DeploymentData helloWorldDeployment;
HelloWorldDeploymentLib.DeploymentConfigData helloWorldConfig;
Quorum internal quorum;
ERC20Mock token;
function setUp() public virtual {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");

helloWorldConfig = HelloWorldDeploymentLib.readDeploymentConfigValues("deployments/hello-world/", block.chainid);

coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid);

token = new ERC20Mock();
Expand All @@ -50,7 +55,7 @@ contract HelloWorldDeployer is Script {
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, rewardsInitiator, rewardsOwner);

helloWorldDeployment.strategy = address(helloWorldStrategy);
helloWorldDeployment.token = address(token);
Expand Down
2 changes: 1 addition & 1 deletion contracts/script/SetupPayments.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract SetupPayments is Script {

function createAVSRewardsSubmissions(uint256 numPayments, uint256 amountPerPayment, uint32 duration, uint32 startTimestamp) public {
SetupPaymentsLib.createAVSRewardsSubmissions(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
helloWorldDeployment.helloWorldServiceManager,
helloWorldDeployment.strategy,
numPayments,
amountPerPayment,
Expand Down
3 changes: 1 addition & 2 deletions contracts/script/utils/CoreDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ library CoreDeploymentLib {
proxyAdmin, // initialOwner
IPauserRegistry(result.pauserRegistry), // _pauserRegistry
configData.rewardsCoordinator.initPausedStatus, // initialPausedStatus
/// TODO: is there a setter and is this expected?
address(0), // rewards updater
configData.rewardsCoordinator.updater,
uint32(configData.rewardsCoordinator.activationDelay), // _activationDelay
uint16(configData.rewardsCoordinator.globalOperatorCommissionBips) // _globalCommissionBips
)
Expand Down
39 changes: 37 additions & 2 deletions contracts/script/utils/HelloWorldDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ library HelloWorldDeploymentLib {
address token;
}

struct DeploymentConfigData {
address rewardsOwner;
address rewardsInitiator;
}

function deployContracts(
address proxyAdmin,
CoreDeploymentLib.DeploymentData memory core,
Quorum memory quorum
Quorum memory quorum,
address rewardsInitiator,
address owner
) internal returns (DeploymentData memory) {
DeploymentData memory result;

Expand All @@ -53,7 +60,8 @@ library HelloWorldDeploymentLib {
ECDSAStakeRegistry.initialize, (result.helloWorldServiceManager, 0, quorum)
);
UpgradeableProxyLib.upgradeAndCall(result.stakeRegistry, stakeRegistryImpl, upgradeCall);
UpgradeableProxyLib.upgrade(result.helloWorldServiceManager, helloWorldServiceManagerImpl);
upgradeCall = abi.encodeCall(HelloWorldServiceManager.initialize, (owner, rewardsInitiator));
UpgradeableProxyLib.upgradeAndCall(result.helloWorldServiceManager, helloWorldServiceManagerImpl, upgradeCall);

return result;
}
Expand Down Expand Up @@ -83,6 +91,7 @@ library HelloWorldDeploymentLib {

return data;
}


/// write to default output path
function writeDeploymentJson(
Expand All @@ -109,6 +118,32 @@ library HelloWorldDeploymentLib {
vm.writeFile(fileName, deploymentData);
console2.log("Deployment artifacts written to:", fileName);
}


function readDeploymentConfigValues(
string memory directoryPath,
string memory fileName
) internal returns (DeploymentConfigData memory) {
string memory pathToFile = string.concat(directoryPath, fileName);

require(vm.exists(pathToFile), "Deployment file does not exist");

string memory json = vm.readFile(pathToFile);

DeploymentConfigData memory data;

data.rewardsOwner = json.readAddress(".rewardsOwner");
data.rewardsInitiator = json.readAddress(".rewardsInitiator");
return data;
}

function readDeploymentConfigValues(
string memory directoryPath,
uint256 chainId
) internal returns (DeploymentConfigData memory) {
return
readDeploymentConfigValues(directoryPath, string.concat(vm.toString(chainId), ".json"));
}

function _generateDeploymentJson(
DeploymentData memory data,
Expand Down
8 changes: 4 additions & 4 deletions contracts/script/utils/SetupPaymentsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {ECDSAServiceManagerBase} from "@eigenlayer-middleware/src/unaudited/ECDSAServiceManagerBase.sol";
import {Vm} from "forge-std/Vm.sol";


Expand All @@ -16,7 +17,7 @@ library SetupPaymentsLib {
}

function createAVSRewardsSubmissions(
IRewardsCoordinator rewardsCoordinator,
address helloWorldServiceManager,
address strategy,
uint256 numPayments,
uint256 amountPerPayment,
Expand All @@ -35,14 +36,13 @@ library SetupPaymentsLib {
strategiesAndMultipliers: strategiesAndMultipliers,
token: IStrategy(strategy).underlyingToken(),
amount: amountPerPayment,
startTimestamp: startTimestamp ,
startTimestamp: startTimestamp,
duration: duration
});

rewardsSubmissions[i] = rewardsSubmission;
}

rewardsCoordinator.createAVSRewardsSubmission(rewardsSubmissions);
ECDSAServiceManagerBase(helloWorldServiceManager).createAVSRewardsSubmission(rewardsSubmissions);
}

function processClaim(
Expand Down
8 changes: 8 additions & 0 deletions contracts/src/HelloWorldServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ contract HelloWorldServiceManager is ECDSAServiceManagerBase, IHelloWorldService
)
{}

function initialize(
address initialOwner,
address _rewardsInitiator
) external initializer {
__ServiceManagerBase_init(initialOwner, _rewardsInitiator);
}

/* FUNCTIONS */
// NOTE: this function creates new task, assigns it a taskId
function createNewTask(
Expand Down Expand Up @@ -101,4 +108,5 @@ contract HelloWorldServiceManager is ECDSAServiceManagerBase, IHelloWorldService
// emitting event
emit TaskResponded(referenceTaskIndex, task, msg.sender);
}

}
8 changes: 7 additions & 1 deletion contracts/test/HelloWorldServiceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ contract HelloWorldTaskManagerSetup is Test {
Vm.Wallet key;
}

struct AVSOwner {
Vm.Wallet key;
}

Operator[] internal operators;
TrafficGenerator internal generator;
AVSOwner internal owner;

HelloWorldDeploymentLib.DeploymentData internal helloWorldDeployment;
CoreDeploymentLib.DeploymentData internal coreDeployment;
Expand All @@ -52,6 +57,7 @@ contract HelloWorldTaskManagerSetup is Test {

function setUp() public virtual {
generator = TrafficGenerator({key: vm.createWallet("generator_wallet")});
owner = AVSOwner({key: vm.createWallet("owner_wallet")});

address proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();

Expand All @@ -65,7 +71,7 @@ contract HelloWorldTaskManagerSetup is Test {
quorum.strategies.push(StrategyParams({strategy: strategy, multiplier: 10_000}));

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, owner.key.addr, owner.key.addr);
labelContracts(coreDeployment, helloWorldDeployment);
}

Expand Down
27 changes: 22 additions & 5 deletions contracts/test/SetupPaymentsLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import "../script/utils/SetupPaymentsLib.sol";
import "../script/utils/CoreDeploymentLib.sol";
import "../script/utils/HelloWorldDeploymentLib.sol";
import "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";
import "../src/IHelloWorldServiceManager.sol";
import "@eigenlayer/contracts/interfaces/IStrategy.sol";
import "@eigenlayer/contracts/libraries/Merkle.sol";
import "../script/DeployEigenLayerCore.s.sol";
import "../script/HelloWorldDeployer.s.sol";
import {StrategyFactory} from "@eigenlayer/contracts/strategies/StrategyFactory.sol";
import {HelloWorldTaskManagerSetup} from "test/HelloWorldServiceManager.t.sol";
import {ECDSAServiceManagerBase} from "@eigenlayer-middleware/src/unaudited/ECDSAServiceManagerBase.sol";
import {
Quorum,
StrategyParams,
IStrategy
} from "@eigenlayer-middleware/src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol";
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";


contract TestConstants {
uint256 constant NUM_PAYMENTS = 8;
Expand All @@ -35,10 +39,13 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup


IRewardsCoordinator public rewardsCoordinator;
IHelloWorldServiceManager public helloWorldServiceManager;
IStrategy public strategy;
address proxyAdmin;

string internal constant filePath = "test/mockData/scratch/payments.json";
address rewardsInitiator = address(1);
address rewardsOwner = address(2);


function setUp() public override virtual {
Expand All @@ -53,12 +60,18 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
quorum.strategies.push(StrategyParams({strategy: strategy, multiplier: 10_000}));

helloWorldDeployment =
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum);
HelloWorldDeploymentLib.deployContracts(proxyAdmin, coreDeployment, quorum, rewardsInitiator, rewardsOwner);
labelContracts(coreDeployment, helloWorldDeployment);


cheats.prank(rewardsOwner);
ECDSAServiceManagerBase(helloWorldDeployment.helloWorldServiceManager).setRewardsInitiator(rewardsInitiator);

rewardsCoordinator = IRewardsCoordinator(coreDeployment.rewardsCoordinator);

mockToken.mint(address(this), 100000);
mockToken.mint(address(rewardsCoordinator), 100000);
mockToken.mint(rewardsInitiator, 100000);
}


Expand All @@ -74,7 +87,7 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(rewardsCoordinator, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, address(strategy));
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);

cheats.startPrank(address(0), address(0));
cheats.startPrank(rewardsCoordinator.rewardsUpdater());
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();
}
Expand Down Expand Up @@ -149,7 +162,8 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(rewardsCoordinator, NUM_TOKEN_EARNINGS, TOKEN_EARNINGS, address(strategy));
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves =SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);

cheats.startPrank(address(0));

cheats.startPrank(rewardsCoordinator.rewardsUpdater());
SetupPaymentsLib.submitRoot(rewardsCoordinator, tokenLeaves, earnerLeaves, address(strategy), endTimestamp, NUM_EARNERS, 1, filePath);
cheats.stopPrank();

Expand All @@ -176,10 +190,13 @@ contract SetupPaymentsLibTest is Test, TestConstants, HelloWorldTaskManagerSetup
uint32 duration = rewardsCoordinator.MAX_REWARDS_DURATION();
uint32 startTimestamp = 10 days;
cheats.warp(startTimestamp + 1);
mockToken.approve(address(rewardsCoordinator), amountPerPayment * numPayments);

cheats.prank(rewardsInitiator);
mockToken.increaseAllowance(helloWorldDeployment.helloWorldServiceManager, amountPerPayment * numPayments);

cheats.startPrank(rewardsInitiator);
SetupPaymentsLib.createAVSRewardsSubmissions(
rewardsCoordinator,
address(helloWorldDeployment.helloWorldServiceManager),
address(strategy),
numPayments,
amountPerPayment,
Expand Down
4 changes: 4 additions & 0 deletions contracts/test/mockData/config/hello-world/1337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rewardsOwner": "0x",
"rewardsInitiator": "0x"
}
4 changes: 4 additions & 0 deletions contracts/test/mockData/deployments/hello-world/1337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rewardsOwner": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1",
"rewardsInitiator": "0x3C4293F66941ECa00f4950C10d4255d5c271bAe1"
}