-
Notifications
You must be signed in to change notification settings - Fork 407
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
feat(contracts): add REZ
token to Hyperlane AVS
#4786
Open
aroralanuk
wants to merge
5
commits into
audit-q3-2024
Choose a base branch
from
kunal/rez-avs
base: audit-q3-2024
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ pragma solidity >=0.8.0; | |
|
||
import "forge-std/Script.sol"; | ||
|
||
import {IStrategy} from "../../contracts/interfaces/avs/vendored/IStrategy.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {IStrategy, IStrategyFactory} from "../../contracts/interfaces/avs/vendored/IStrategy.sol"; | ||
import {IAVSDirectory} from "../../contracts/interfaces/avs/vendored/IAVSDirectory.sol"; | ||
import {IPaymentCoordinator} from "../../contracts/interfaces/avs/vendored/IPaymentCoordinator.sol"; | ||
import {IDelegationManager} from "../../contracts/interfaces/avs/vendored/IDelegationManager.sol"; | ||
|
@@ -226,4 +227,55 @@ contract DeployAVS is Script { | |
require(strategies[i] != address(0), "Strategy address is 0"); | ||
} | ||
} | ||
|
||
function addREZStrategy() external { | ||
IERC20 rezToken = IERC20(0x3B50805453023a91a8bf641e279401a0b23FA6F9); | ||
IStrategyFactory strategyFactory = IStrategyFactory( | ||
0x5e4C39Ad7A3E881585e383dB9827EB4811f6F647 | ||
); | ||
|
||
IStrategy rezStrategy = strategyFactory.deployedStrategies(rezToken); | ||
|
||
ECDSAStakeRegistry stakeRegistry = ECDSAStakeRegistry( | ||
0x272CF0BB70D3B4f79414E0823B426d2EaFd48910 | ||
); | ||
|
||
// get current quorum | ||
Quorum memory currentQuorum = stakeRegistry.quorum(); | ||
Quorum memory newQuorum; | ||
newQuorum.strategies = new StrategyParams[]( | ||
currentQuorum.strategies.length + 1 | ||
); | ||
|
||
uint256 totalStrategies = newQuorum.strategies.length; | ||
uint96 baseMultiplier = uint96(10000 / totalStrategies); | ||
|
||
uint96 remainder = 10000 % uint96(totalStrategies); | ||
|
||
for (uint256 i = 0; i < currentQuorum.strategies.length; i++) { | ||
newQuorum.strategies[i] = currentQuorum.strategies[i]; | ||
newQuorum.strategies[i].multiplier = baseMultiplier; | ||
} | ||
|
||
newQuorum.strategies[newQuorum.strategies.length - 1] = StrategyParams({ | ||
strategy: rezStrategy, | ||
multiplier: baseMultiplier + remainder | ||
}); | ||
|
||
console.log("New REZ Strategy: ", address(rezStrategy)); | ||
console.log( | ||
"New REZ Strategy Multiplier: ", | ||
baseMultiplier + remainder | ||
); | ||
|
||
// add strategy to quorum | ||
bytes memory encodedCall = abi.encodeWithSelector( | ||
stakeRegistry.updateQuorumConfig.selector, | ||
newQuorum, | ||
new address[](0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats this param? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update operator weights, if we give an empty array, it doesn't update it. |
||
); | ||
|
||
console.log("Encoded call: "); | ||
console.logBytes(encodedCall); | ||
aroralanuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.12; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {console} from "forge-std/console.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import {ECDSAStakeRegistry} from "../../contracts/avs/ECDSAStakeRegistry.sol"; | ||
import {HyperlaneServiceManager} from "../../contracts/avs/HyperlaneServiceManager.sol"; | ||
import {IStrategy, IStrategyFactory} from "../../contracts/interfaces/avs/vendored/IStrategy.sol"; | ||
import {IDelegationManager} from "../../contracts/interfaces/avs/vendored/IDelegationManager.sol"; | ||
import "../../contracts/interfaces/avs/vendored/ISignatureUtils.sol"; | ||
import {Quorum, StrategyParams} from "../../contracts/interfaces/avs/vendored/IECDSAStakeRegistryEventsAndErrors.sol"; | ||
|
||
contract REZAdditionTest is Test { | ||
string MAINNET_RPC_URL = "https://eth.llamarpc.com"; | ||
uint256 FORK_BLOCK_NUMBER = 21061545; | ||
|
||
address AW_SAFE = 0xa7ECcdb9Be08178f896c26b7BbD8C3D4E844d9Ba; | ||
address BITGET_6 = 0x1AB4973a48dc892Cd9971ECE8e01DcC7688f8F23; | ||
address PIER2 = 0x5dCdf02a7188257b7c37dD3158756dA9Ccd4A9Cb; | ||
|
||
ECDSAStakeRegistry stakeRegistry = | ||
ECDSAStakeRegistry(0x272CF0BB70D3B4f79414E0823B426d2EaFd48910); | ||
IDelegationManager delegationManager = | ||
IDelegationManager(0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A); | ||
HyperlaneServiceManager serviceManager = | ||
HyperlaneServiceManager(0xe8E59c6C8B56F2c178f63BCFC4ce5e5e2359c8fc); | ||
IERC20 rezToken = IERC20(0x3B50805453023a91a8bf641e279401a0b23FA6F9); | ||
IStrategyFactory strategyFactory = | ||
IStrategyFactory(0x5e4C39Ad7A3E881585e383dB9827EB4811f6F647); | ||
|
||
function setUp() public { | ||
vm.createSelectFork(MAINNET_RPC_URL, FORK_BLOCK_NUMBER); | ||
} | ||
|
||
function test_addREZStrategy() external { | ||
|
||
vm.startPrank(AW_SAFE); | ||
|
||
// STEP 1: update the stakeRegistry quorum with the new REZ strategy and adjust the weights accordingly to sum up to 10_000 | ||
IStrategy rezStrategy = strategyFactory.deployedStrategies(rezToken); | ||
require(address(rezStrategy).code.length > 0, "Strategy not deployed"); | ||
_setQuorum(rezStrategy); | ||
|
||
address[] memory restakeableStrategies = serviceManager | ||
.getRestakeableStrategies(); | ||
|
||
bool rezStrategyFound = false; | ||
for (uint256 i = 0; i < restakeableStrategies.length; i++) { | ||
if (restakeableStrategies[i] == address(rezStrategy)) { | ||
rezStrategyFound = true; | ||
} | ||
} | ||
require( | ||
rezStrategyFound, | ||
"REZ strategy not found in total restakeable strategies" | ||
); | ||
|
||
// STEP 2: check if a staker's REZ deposit gets accounted for | ||
uint256 amountToStake = rezToken.balanceOf(BITGET_6); | ||
|
||
IStrategy[] memory strategiesToQuery = new IStrategy[](1); | ||
strategiesToQuery[0] = rezStrategy; | ||
uint256 sharesBefore = delegationManager.getOperatorShares( | ||
PIER2, | ||
strategiesToQuery | ||
)[0]; | ||
|
||
// compute the storage slot | ||
address[] memory operatorStrategies1 = serviceManager | ||
.getOperatorRestakedStrategies(PIER2); | ||
|
||
// directly update the operator shares instead of calling | ||
bytes32 operatorSharesSlot = keccak256( | ||
abi.encode( | ||
address(rezStrategy), | ||
keccak256(abi.encode(PIER2, bytes32(uint256(152)))) | ||
) | ||
); | ||
vm.store( | ||
address(delegationManager), | ||
operatorSharesSlot, | ||
bytes32(amountToStake) | ||
); | ||
|
||
uint256 sharesAfter = delegationManager.getOperatorShares( | ||
PIER2, | ||
strategiesToQuery | ||
)[0]; | ||
assertEq(sharesAfter, sharesBefore + amountToStake); | ||
|
||
address[] memory operatorStrategies = serviceManager | ||
.getOperatorRestakedStrategies(PIER2); | ||
|
||
rezStrategyFound = false; | ||
for (uint256 i = 0; i < operatorStrategies.length; i++) { | ||
if (operatorStrategies[i] == address(rezStrategy)) { | ||
rezStrategyFound = true; | ||
} | ||
} | ||
require( | ||
rezStrategyFound, | ||
"REZ strategy not found in operator restaked strategies" | ||
); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
function _setQuorum(IStrategy rezStrategy) internal { | ||
// get current quorum | ||
Quorum memory currentQuorum = stakeRegistry.quorum(); | ||
Quorum memory newQuorum; | ||
newQuorum.strategies = new StrategyParams[]( | ||
currentQuorum.strategies.length + 1 | ||
); | ||
|
||
uint256 totalStrategies = newQuorum.strategies.length; | ||
// split the 10000 base multiplier evenly | ||
uint96 baseMultiplier = uint96(10000 / totalStrategies); | ||
|
||
uint96 remainder = 10000 % uint96(totalStrategies); | ||
|
||
for (uint256 i = 0; i < currentQuorum.strategies.length; i++) { | ||
newQuorum.strategies[i] = currentQuorum.strategies[i]; | ||
newQuorum.strategies[i].multiplier = baseMultiplier; | ||
} | ||
|
||
// add the remainder to the last strategy | ||
newQuorum.strategies[newQuorum.strategies.length - 1] = StrategyParams({ | ||
strategy: rezStrategy, | ||
multiplier: baseMultiplier + remainder | ||
}); | ||
|
||
console.log("REZ Strategy: ", address(rezStrategy)); | ||
console.log("REZ Strategy Multiplier: ", baseMultiplier + remainder); | ||
|
||
// add strategy to quorum | ||
stakeRegistry.updateQuorumConfig(newQuorum, new address[](0)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really want to apply a prorate quorum for REZ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter, we'll read it manually for ISM config.