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

feat: make targets to modify strategies #1530

Open
wants to merge 14 commits into
base: staging
Choose a base branch
from
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ verifier_disable:
@echo "Disabling verifier with ID: $(VERIFIER_ID)"
@. contracts/scripts/.env && . contracts/scripts/disable_verifier.sh $(VERIFIER_ID)

strategies_get_weight:
@echo "Getting weight of strategy: $(STRATEGY_INDEX)"
@. contracts/scripts/.env && . contracts/scripts/get_strategy_weight.sh $(STRATEGY_INDEX)

strategies_update_weight:
@echo "Updating strategy weights: "
@echo "STRATEGY_INDICES: $(STRATEGY_INDICES)"
@echo "NEW_MULTIPLIERS: $(NEW_MULTIPLIERS)"
@. contracts/scripts/.env && . contracts/scripts/update_strategy_weight.sh $(STRATEGY_INDICES) $(NEW_MULTIPLIERS)
uri-99 marked this conversation as resolved.
Show resolved Hide resolved

strategies_remove:
@echo "Removing strategies: $(INDICES_TO_REMOVE)"
@. contracts/scripts/.env && . contracts/scripts/remove_strategy.sh $(INDICES_TO_REMOVE)

strategies_get_addresses:
@echo "Getting strategy addresses"
@. contracts/scripts/.env && . contracts/scripts/get_restakeable_strategies.sh

__BATCHER__:

BURST_SIZE ?= 5
Expand Down
38 changes: 38 additions & 0 deletions contracts/scripts/get_restakeable_strategies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# cd to the directory of this script so that this can be run from anywhere
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
# At this point we are in contracts/scripts
cd "$parent_path"

# At this point we are in contracts
cd ../

if [ -z "$OUTPUT_PATH" ]; then
echo "OUTPUT_PATH env var is not set"
exit 1
fi

if [ -z "$RPC_URL" ]; then
echo "RPC_URL env var is not set"
exit 1
fi

ALIGNED_SERVICE_MANAGER=$(jq -r '.addresses.alignedLayerServiceManager' "$OUTPUT_PATH")

## Using in this cast call:

# /**
# * @notice Returns the list of strategies that the AVS supports for restaking
# * @dev This function is intended to be called off-chain
# * @dev No guarantee is made on uniqueness of each element in the returned array.
# * The off-chain service should do that validation separately
# */
# function getRestakeableStrategies() external view returns (address[] memory) {

cast call $ALIGNED_SERVICE_MANAGER "getRestakeableStrategies()(address[])" --rpc-url $RPC_URL

# Expected output:
# [addresses]
# example:
# [0xc5a5C42992dECbae36851359345FE25997F5C42d, 0x80528D6e9A2BAbFc766965E0E26d5aB08D9CFaF9]
51 changes: 51 additions & 0 deletions contracts/scripts/get_strategy_weight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# cd to the directory of this script so that this can be run from anywhere
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
# At this point we are in contracts/scripts
cd "$parent_path"

# At this point we are in contracts
cd ../

if [ "$#" -ne 1 ]; then
echo "Error: 1 arguments is required, STRATEGY_INDEX"
exit 1
fi

STRATEGY_INDEX=$1

if [ -z "$OUTPUT_PATH" ]; then
echo "OUTPUT_PATH env var is not set"
exit 1
fi

if [ -z "$RPC_URL" ]; then
echo "RPC_URL env var is not set"
exit 1
fi

STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")

## Using in this cast call:

# struct StrategyParams {
# IStrategy strategy; (iface -> address)
# uint96 multiplier;
# }

# /// @notice Returns the strategy and weight multiplier for the `index`'th strategy in the quorum `quorumNumber`
# function strategyParamsByIndex(
# uint8 quorumNumber,
# uint256 index
# ) public view returns (StrategyParams memory)
#

QUORUM_NUMER=0x0 #Aligned has only 1 quorum for now

cast call $STAKE_REGISTRY "strategyParamsByIndex(uint8,uint256)((address,uint96))" $QUORUM_NUMER $STRATEGY_INDEX --rpc-url $RPC_URL

# Expected output:
# (strategy_address, multiplier)
# example:
# (0xc5a5C42992dECbae36851359345FE25997F5C42d, 1000000000000000000 [1e18])
67 changes: 67 additions & 0 deletions contracts/scripts/remove_strategy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

# cd to the directory of this script so that this can be run from anywhere
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
# At this point we are in contracts/scripts
cd "$parent_path"

# At this point we are in contracts
cd ../

if [ "$#" -ne 1 ]; then
echo "Error: 1 arguments is required, INDICES_TO_REMOVE"
exit 1
fi

INDICES_TO_REMOVE=$1

if [[ ! "$INDICES_TO_REMOVE" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
echo "The INDICES_TO_REMOVE doesn't match the required format: [0,1,...,n]"
exit 1
fi

if [ -z "$MULTISIG" ]; then
echo "MULTISIG env var is not set"
exit 1
fi
if [ "$MULTISIG" = false ]; then
if [ -z "$PRIVATE_KEY" ]; then
echo "PRIVATE_KEY env var is not set"
exit 1
fi
if [ -z "$RPC_URL" ]; then
echo "RPC_URL env var is not set"
exit 1
fi
if [ -z "$OUTPUT_PATH" ]; then
echo "OUTPUT_PATH env var is not set"
exit 1
fi
STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")
fi


## Using in this cast call:

# /**
# * @notice This function is used for removing strategies and their associated weights from the
# * mapping strategyParams for a specific @param quorumNumber.
# * @dev higher indices should be *first* in the list of @param indicesToRemove, since otherwise
# * the removal of lower index entries will cause a shift in the indices of the other strategiesToRemove
# */
# function removeStrategies(uint8 quorumNumber, uint256[] calldata indicesToRemove) external;

QUORUM_NUMBER=0 #Aligned has only 1 quorum for now

data=$(cast calldata "removeStrategies(uint8, uint256[])()" $QUORUM_NUMBER $INDICES_TO_REMOVE)

if [ "$MULTISIG" = false ]; then
echo "Executing remove strategies transaction"

cast send $STAKE_REGISTRY $data \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY
else
echo "You can propose the remove strategies transaction with the multisig using this calldata:"
echo $data
fi
100 changes: 100 additions & 0 deletions contracts/scripts/update_strategy_weight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

# cd to the directory of this script so that this can be run from anywhere
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
# At this point we are in contracts/scripts
cd "$parent_path"

# At this point we are in contracts
cd ../

if [ "$#" -ne 2 ]; then
echo "Error: 2 arguments are required, STRATEGY_INDICES and NEW_MULTIPLIERS"
exit 1
fi

STRATEGY_INDICES=$1
NEW_MULTIPLIERS=$2


if [[ ! "$STRATEGY_INDICES" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
echo "The STRATEGY_INDICES doesn't match the required format: [0,1,...,n]"
exit 1
fi

if [ -z "$NEW_MULTIPLIERS" ]; then
echo "NEW_MULTIPLIERS env var is not set"
exit 1
fi
if [[ ! "$NEW_MULTIPLIERS" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
echo "The NEW_MULTIPLIERS doesn't match the required format: [0,1,...,n]"
exit 1
fi

count_elements() {
local var="$1"
# Remove brackets and count elements by splitting on commas
echo "$var" | sed 's/[\[\]]//g' | awk -F',' '{print NF}'
}
count1=$(count_elements "$STRATEGY_INDICES")
count2=$(count_elements "$NEW_MULTIPLIERS")


if [[ $count1 -ne $count2 ]]; then
echo "STRATEGY_INDICES and NEW_MULTIPLIERS have different numbers of elements:"
echo "STRATEGY_INDICES: $STRATEGY_INDICES"
echo "NEW_MULTIPLIERS: $NEW_MULTIPLIERS"
exit 1
fi


if [ -z "$MULTISIG" ]; then
echo "MULTISIG env var is not set"
exit 1
fi
if [ "$MULTISIG" = false ]; then
if [ -z "$PRIVATE_KEY" ]; then
echo "PRIVATE_KEY env var is not set"
exit 1
fi
if [ -z "$RPC_URL" ]; then
echo "RPC_URL env var is not set"
exit 1
fi
if [ -z "$OUTPUT_PATH" ]; then
echo "OUTPUT_PATH env var is not set"
exit 1
fi
STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")
fi


## Using in this cast call:

# /**
# * @notice This function is used for modifying the weights of strategies that are already in the
# * mapping strategyParams for a specific
# * @param quorumNumber is the quorum number to change the strategy for
# * @param strategyIndices are the indices of the strategies to change
# * @param newMultipliers are the new multipliers for the strategies
# */
# function modifyStrategyParams(
# uint8 quorumNumber,
# uint256[] calldata strategyIndices,
# uint96[] calldata newMultipliers
# ) external;

QUORUM_NUMBER=0 #Aligned has only 1 quorum for now

data=$(cast calldata "modifyStrategyParams(uint8, uint256[], uint96[])()" $QUORUM_NUMBER $STRATEGY_INDICES $NEW_MULTIPLIERS)

if [ "$MULTISIG" = false ]; then
echo "Executing modify strategy params transaction"

cast send $STAKE_REGISTRY $data \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY
else
echo "You can propose the modify strategy params transaction with the multisig using this calldata:"
echo $data
fi
39 changes: 39 additions & 0 deletions docs/0_internal/6_a_modify_strategies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Modify Strategy Weight Multipliers Contracts
This doc contains a guide on how to use the modify the strategy weight multipliers on Aligned.
PatStiles marked this conversation as resolved.
Show resolved Hide resolved

To run the make targets specified in this guide, you must first have the relevant following env vars under `contracts/scripts/.env`:
```
RPC_URL=<rpc_url>
ALIGNED_SERVICE_MANAGER=<aligned_contract_address>
PRIVATE_KEY=<private_key>
OUTPUT_PATH=<deployment_output_path>
```

##

To view some relevant information you can:

### Get all available strategies:

```
make strategies_get_addresses
```

### Get weight multiplier of a specific strategy:

```
make strategies_get_weight STRATEGY_INDEX=<strategy_index>
```

### Update the weight of any amount of stratefies

```
make strategies_update_weight STRATEGY_INDICES=[0,1,...,n] NEW_MULTIPLIERS=[0,1,...,n]
```

### Remove a strategy

```
make strategies_remove INDICES_TO_REMOVE=[0,1,...,n]
```