Skip to content

Commit

Permalink
added to ReadMe
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Nov 8, 2024
1 parent b2d2776 commit 81984e3
Showing 5 changed files with 64 additions and 14 deletions.
Binary file added .DS_Store
Binary file not shown.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -82,6 +82,31 @@ npm run start:operator

```

### Create and Claim Payments
```sh
# Start local anvil chain
npm run start:anvil
```

In another terminal, run:
```sh
# 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
```


### Create Hello-World-AVS Tasks

Open a separate terminal window #3, execute the following commands
31 changes: 27 additions & 4 deletions contracts/script/SetupPayments.s.sol
Original file line number Diff line number Diff line change
@@ -37,13 +37,15 @@ contract SetupPayments is Script, Test {

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

uint32 numPayments = 8;
uint32 indexToProve = 0;
uint32 amountPerPayment = 100;
//this is to track how many times we've run the script to set cumulative earnings properly
uint32 numPaymentClaimSessions = 1;

address recipient = address(1);
IRewardsCoordinator.EarnerTreeMerkleLeaf[] public earnerLeaves;
@@ -69,16 +71,29 @@ contract SetupPayments is Script, Test {
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);
emit log_named_uint("Start Timestamp", startTimestamp);
} else {
emit log_named_uint("Rewards Calculation End Timestamp", rewardsCoordinator.currRewardsCalculationEndTimestamp());
emit log_named_uint("Calculation Interval Seconds", CALCULATION_INTERVAL_SECONDS);
startTimestamp = rewardsCoordinator.currRewardsCalculationEndTimestamp() - DURATION + CALCULATION_INTERVAL_SECONDS;
}

startTimestamp = uint32(block.timestamp) - (uint32(block.timestamp) % CALCULATION_INTERVAL_SECONDS);
endTimestamp = startTimestamp + 1;

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

createAVSRewardsSubmissions(numPayments, amountPerPayment, startTimestamp);
vm.stopBroadcast();
vm.startBroadcast(deployer);
earners = _getEarners();
submitPaymentRoot(earners, endTimestamp, numPayments, amountPerPayment);
vm.stopBroadcast();
numPaymentClaimSessions++;
}

function executeProcessClaim() public {
@@ -118,7 +133,7 @@ contract SetupPayments is Script, Test {
bytes32[] memory tokenLeaves = SetupPaymentsLib.createTokenLeaves(
IRewardsCoordinator(coreDeployment.rewardsCoordinator),
NUM_TOKEN_EARNINGS,
amountPerPayment,
amountPerPayment * numPaymentClaimSessions,
helloWorldDeployment.strategy
);
IRewardsCoordinator.EarnerTreeMerkleLeaf[] memory earnerLeaves = SetupPaymentsLib.createEarnerLeaves(earners, tokenLeaves);
@@ -138,7 +153,15 @@ contract SetupPayments is Script, Test {
}

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

emit log_named_uint("PAYMENT SESSIONS", numPaymentClaimSessions);

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

return earnerLeaves;
18 changes: 9 additions & 9 deletions contracts/test/mockData/scratch/payments.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"leaves": [
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51",
"0x855a8f20541c81d6176860d70e5052761e63753e3a596de4802d3469fbb66d51"
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc",
"0xdc4955d01f4e8f8fc13e61d1da56189f6db850395aebbbcbc211202b934970fc"
],
"tokenLeaves": [
"0x5a388246e7ca57a446739415dfaa85443f20b442a0b81409e962cd986a71ba98"
"0xe0c89917f508e4c4cb8aff33403a849560a853d87c90011da2a9bb86811fa248"
]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -5,11 +5,13 @@
"scripts": {
"start:operator": "ts-node operator/index.ts",
"start:traffic": "ts-node operator/createNewTasks.ts",
"start:anvil": "anvil",
"start:anvil": "anvil --block-time 0.002",
"deploy:core": "cd contracts && forge script script/DeployEigenLayerCore.s.sol --rpc-url http://localhost:8545 --broadcast",
"deploy:hello-world": "cd contracts && forge script script/HelloWorldDeployer.s.sol --rpc-url http://localhost:8545 --broadcast",
"deploy:core-debug": "cd contracts && forge script script/DeployEigenLayerCore.s.sol --rpc-url http://localhost:8545 --broadcast --revert-strings debug",
"deploy:hello-world-debug": "cd contracts && forge script script/HelloWorldDeployer.s.sol --rpc-url http://localhost:8545 --broadcast --revert-strings debug",
"run:create-payments-root": "cd contracts && forge script script/SetupPayments.s.sol --rpc-url http://localhost:8545 --broadcast -v --sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"run:claim-payments": "cd contracts && forge script script/SetupPayments.s.sol --rpc-url http://localhost:8545 --broadcast --sig \"executeProcessClaim()\" -v --sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"build": "cd contracts && forge build",
"extract:abis": "node utils/abis.js",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest"

0 comments on commit 81984e3

Please sign in to comment.