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 all 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
Binary file added .DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ npm run start:operator

```

### Create and Claim Payments

In a terminal, start a new instance of anvil and deploy the core and avs contracts
```sh
# Start anvil
npm run start:anvil-quick
# Deploy the EigenLayer contracts
npm run deploy:core

# Deploy the Hello World AVS contracts
npm run deploy:hello-world

```

In another terminal, run:

```sh
# Create payment roots
npm run create-payments-root

# Claim created payment
npm run claim-payments
```

In order to create and claim multiple payments (run the above two commands more than once), you must wait up to 5 minutes.




### Create Hello-World-AVS Tasks

Open a separate terminal window #3, execute the following commands
Expand Down
29 changes: 29 additions & 0 deletions contracts/config/core/31337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"strategyManager": {
"init_paused_status": 0,
"init_withdrawal_delay_blocks": 50400
},
"delegation": {
"init_paused_status": 0,
"init_withdrawal_delay_blocks": 50400
},
"slasher": {
"init_paused_status": 0
},
"eigenPodManager": {
"init_paused_status": 0
},
"rewardsCoordinator": {
"init_paused_status": 0,
"MAX_REWARDS_DURATION": 864000,
"MAX_RETROACTIVE_LENGTH": 86400,
"MAX_FUTURE_LENGTH": 86400,
"GENESIS_REWARDS_TIMESTAMP": 1672531200,
"rewards_updater_address": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
"rewards_updater_key": "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356",
"activation_delay": 0,
"calculation_interval_seconds": 86400,
"global_operator_commission_bips": 1000
}
}

10 changes: 10 additions & 0 deletions contracts/config/hello-world/31337.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"addresses": {
"rewardsOwner": "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f",
"rewardsInitiator": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
},
"keys": {
"rewardsOwner": "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97",
"rewardsInitiator": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
}
}
9 changes: 8 additions & 1 deletion contracts/script/DeployEigenLayerCore.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {Script} from "forge-std/Script.sol";
import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {UpgradeableProxyLib} from "./utils/UpgradeableProxyLib.sol";

contract DeployEigenLayerCore is Script {
import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";

import "forge-std/Test.sol";

contract DeployEigenlayerCore is Script, Test {
using CoreDeploymentLib for *;
using UpgradeableProxyLib for address;

Expand All @@ -22,6 +26,9 @@ contract DeployEigenLayerCore is Script {

function run() external {
vm.startBroadcast(deployer);
//set the rewards updater to the deployer address for payment flow
configData = CoreDeploymentLib.readDeploymentConfigValues("config/core/", block.chainid);
configData.rewardsCoordinator.updater = deployer;
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();
deploymentData = CoreDeploymentLib.deployContracts(proxyAdmin, configData);
vm.stopBroadcast();
Expand Down
28 changes: 20 additions & 8 deletions contracts/script/HelloWorldDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {StrategyFactory} from "@eigenlayer/contracts/strategies/StrategyFactory.sol";
import {StrategyManager} from "@eigenlayer/contracts/core/StrategyManager.sol";
import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";



import {
Expand All @@ -20,42 +22,52 @@ import {
IStrategy
} from "@eigenlayer-middleware/src/interfaces/IECDSAStakeRegistryEventsAndErrors.sol";

contract HelloWorldDeployer is Script {
import "forge-std/Test.sol";

contract HelloWorldDeployer is Script, Test {
using CoreDeploymentLib for *;
using UpgradeableProxyLib for address;

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("config/hello-world/", block.chainid);

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

}

function run() external {
vm.startBroadcast(deployer);
rewardsOwner = helloWorldConfig.rewardsOwner;
rewardsInitiator = helloWorldConfig.rewardsInitiator;
token = new ERC20Mock();
helloWorldStrategy = IStrategy(StrategyFactory(coreDeployment.strategyFactory).deployNewStrategy(token));


quorum.strategies.push(
StrategyParams({strategy: helloWorldStrategy, multiplier: 10_000})
);
}

function run() external {
vm.startBroadcast(deployer);
proxyAdmin = UpgradeableProxyLib.deployProxyAdmin();

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

helloWorldDeployment.strategy = address(helloWorldStrategy);
helloWorldDeployment.token = address(token);
vm.stopBroadcast();

vm.stopBroadcast();
verifyDeployment();
HelloWorldDeploymentLib.writeDeploymentJson(helloWorldDeployment);
}
Expand All @@ -76,4 +88,4 @@ contract HelloWorldDeployer is Script {
);
require(coreDeployment.avsDirectory != address(0), "AVSDirectory address cannot be zero");
}
}
}
124 changes: 101 additions & 23 deletions contracts/script/SetupPayments.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {HelloWorldDeploymentLib} from "./utils/HelloWorldDeploymentLib.sol";
import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {SetupPaymentsLib} from "./utils/SetupPaymentsLib.sol";
import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";
import {RewardsCoordinator} from "@eigenlayer/contracts/core/RewardsCoordinator.sol";
import {IStrategy} from "@eigenlayer/contracts/interfaces/IStrategy.sol";
import {ERC20Mock} from "../test/ERC20Mock.sol";

contract SetupPayments is Script {
struct PaymentInfo {
address[] earners;
bytes32[] earnerTokenRoots;
import "forge-std/Test.sol";

contract SetupPayments is Script, Test {
struct PaymentInfo {
address recipient;
uint256 numPayments;
uint256 amountPerPayment;
uint32 numPayments;
uint32 amountPerPayment;
uint32 duration;
uint32 startTimestamp;
uint32 endTimestamp;
Expand All @@ -22,44 +25,94 @@ contract SetupPayments is Script {

address private deployer;
CoreDeploymentLib.DeploymentData coreDeployment;
CoreDeploymentLib.DeploymentConfigData coreConfig;

HelloWorldDeploymentLib.DeploymentData helloWorldDeployment;
HelloWorldDeploymentLib.DeploymentConfigData helloWorldConfig;

RewardsCoordinator rewardsCoordinator;
string internal constant paymentInfofilePath = "test/mockData/scratch/payment_info.json";
string internal constant filePath = "test/mockData/scratch/payments.json";



uint32 constant CALCULATION_INTERVAL_SECONDS = 1 days;
uint256 constant NUM_TOKEN_EARNINGS = 1;
uint256 constant DURATION = 1 weeks;
uint32 constant DURATION = 1;
uint256 constant NUM_EARNERS = 8;

uint32 numPayments = 8;
uint32 indexToProve = 0;
uint32 amountPerPayment = 100;

address recipient = address(1);
IRewardsCoordinator.EarnerTreeMerkleLeaf[] public earnerLeaves;
address[] public earners;
uint32 startTimestamp;
uint32 endTimestamp;
uint256 cumumlativePaymentMultiplier;
address nonceSender = 0x998abeb3E57409262aE5b751f60747921B33613E;


function setUp() public {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");

coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid);
coreConfig = CoreDeploymentLib.readDeploymentConfigValues("config/core/", block.chainid);
helloWorldDeployment = HelloWorldDeploymentLib.readDeploymentJson("deployments/hello-world/", block.chainid);
helloWorldConfig = HelloWorldDeploymentLib.readDeploymentConfigValues("config/hello-world/", block.chainid);

rewardsCoordinator = RewardsCoordinator(coreDeployment.rewardsCoordinator);

// TODO: Get the filePath from config
}

function run() external {
vm.startBroadcast(helloWorldConfig.rewardsInitiatorKey);
PaymentInfo memory info = abi.decode(vm.parseJson(vm.readFile(paymentInfofilePath)), (PaymentInfo));

if(rewardsCoordinator.currRewardsCalculationEndTimestamp() == 0) {
startTimestamp = uint32(block.timestamp) - (uint32(block.timestamp) % CALCULATION_INTERVAL_SECONDS);
} else {
startTimestamp = rewardsCoordinator.currRewardsCalculationEndTimestamp() - DURATION + CALCULATION_INTERVAL_SECONDS;
}

endTimestamp = startTimestamp + 1;


if (endTimestamp > block.timestamp) {
revert("End timestamp must be in the future. Please wait to generate new payments.");
}

// sets a multiplier based on block number such that cumulativeEarnings increase accordingly for multiple runs of this script in the same session
uint256 nonce = rewardsCoordinator.getDistributionRootsLength();
amountPerPayment = uint32(amountPerPayment * (nonce + 1));

createAVSRewardsSubmissions(numPayments, amountPerPayment, startTimestamp);
vm.stopBroadcast();
vm.startBroadcast(deployer);
IRewardsCoordinator(coreDeployment.rewardsCoordinator).setRewardsUpdater(deployer);
PaymentInfo memory info = abi.decode(vm.parseJson(vm.readFile(filePath)), (PaymentInfo));

createAVSRewardsSubmissions(info.numPayments, info.amountPerPayment, info.duration, info.startTimestamp);
submitPaymentRoot(info.earners, info.endTimestamp, uint32(info.numPayments), uint32(info.amountPerPayment));

IRewardsCoordinator.EarnerTreeMerkleLeaf memory earnerLeaf = IRewardsCoordinator.EarnerTreeMerkleLeaf({
earner: info.earners[info.indexToProve],
earnerTokenRoot: info.earnerTokenRoots[info.indexToProve]
});
earners = _getEarners(deployer);
submitPaymentRoot(earners, endTimestamp, numPayments, amountPerPayment);
vm.stopBroadcast();
}

processClaim(filePath, info.indexToProve, info.recipient, earnerLeaf);
function executeProcessClaim() public {
uint256 nonce = rewardsCoordinator.getDistributionRootsLength();
amountPerPayment = uint32(amountPerPayment * nonce);

vm.startBroadcast(deployer);
earnerLeaves = _getEarnerLeaves(_getEarners(deployer), amountPerPayment, helloWorldDeployment.strategy);
processClaim(filePath, indexToProve, recipient, earnerLeaves[indexToProve], amountPerPayment);
vm.stopBroadcast();
}


function createAVSRewardsSubmissions(uint256 numPayments, uint256 amountPerPayment, uint32 duration, uint32 startTimestamp) public {
function createAVSRewardsSubmissions(uint256 numPayments, uint256 amountPerPayment, uint32 startTimestamp) public {
ERC20Mock(helloWorldDeployment.token).mint(helloWorldConfig.rewardsInitiator, amountPerPayment * numPayments);
ERC20Mock(helloWorldDeployment.token).increaseAllowance(helloWorldDeployment.helloWorldServiceManager, amountPerPayment * numPayments);
uint32 duration = rewardsCoordinator.MAX_REWARDS_DURATION();
SetupPaymentsLib.createAVSRewardsSubmissions(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
helloWorldDeployment.helloWorldServiceManager,
helloWorldDeployment.strategy,
numPayments,
amountPerPayment,
Expand All @@ -68,26 +121,30 @@ contract SetupPayments is Script {
);
}

function processClaim(string memory filePath, uint256 indexToProve, address recipient, IRewardsCoordinator.EarnerTreeMerkleLeaf memory earnerLeaf) public {
function processClaim(string memory filePath, uint256 indexToProve, address recipient, IRewardsCoordinator.EarnerTreeMerkleLeaf memory earnerLeaf, uint32 amountPerPayment) public {
SetupPaymentsLib.processClaim(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
filePath,
indexToProve,
recipient,
earnerLeaf,
NUM_TOKEN_EARNINGS,
helloWorldDeployment.strategy
helloWorldDeployment.strategy,
amountPerPayment
);
}

function submitPaymentRoot(address[] memory earners, uint32 endTimestamp, uint32 numPayments, uint32 amountPerPayment) public {
emit log_named_uint("cumumlativePaymentMultiplier", cumumlativePaymentMultiplier);
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
NUM_TOKEN_EARNINGS,
amountPerPayment,
helloWorldDeployment.strategy
);
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves = SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);
emit log_named_uint("Earner Leaves Length", earnerLeaves.length);
emit log_named_uint("numPayments", numPayments);

SetupPaymentsLib.submitRoot(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
Expand All @@ -100,4 +157,25 @@ contract SetupPayments is Script {
filePath
);
}

function _getEarnerLeaves(address[] memory earners, uint32 amountPerPayment, address strategy) internal returns (IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory) {
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
NUM_TOKEN_EARNINGS,
amountPerPayment,
strategy
);

IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves = SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);

return earnerLeaves;
}

function _getEarners(address deployer) internal returns (address[] memory) {
address[] memory earners = new address[](NUM_EARNERS);
for (uint256 i = 0; i < earners.length; i++) {
earners[i] = deployer;
}
return earners;
}
}
Loading
Loading