Skip to content

Commit da2f9d0

Browse files
committed
feat: .sh scripts to interact with strategies
1 parent 5a24c5e commit da2f9d0

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
if [ -z "$OUTPUT_PATH" ]; then
4+
echo "OUTPUT_PATH env var is not set"
5+
exit 1
6+
fi
7+
8+
if [ -z "$RPC_URL" ]; then
9+
echo "RPC_URL env var is not set"
10+
exit 1
11+
fi
12+
13+
STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")
14+
15+
## Using in this cast call:
16+
17+
# struct StrategyParams {
18+
# IStrategy strategy; (iface -> address)
19+
# uint96 multiplier;
20+
# }
21+
22+
# /// @notice Returns the strategy and weight multiplier for the `index`'th strategy in the quorum `quorumNumber`
23+
# function strategyParamsByIndex(
24+
# uint8 quorumNumber,
25+
# uint256 index
26+
# ) public view returns (StrategyParams memory)
27+
#
28+
29+
QUORUM_NUMER=0x0 #Aligned has only 1 quorum for now
30+
INDEX=$1
31+
32+
echo $STAKE_REGISTRY
33+
34+
cast call $STAKE_REGISTRY "strategyParamsByIndex(uint8,uint256)((address,uint96))" $QUORUM_NUMER $INDEX #--rpc-url $RPC_URL
35+
36+
# Expected output:
37+
# (strategy_address, multiplier)
38+
# example:
39+
# (0xc5a5C42992dECbae36851359345FE25997F5C42d, 1000000000000000000 [1e18])
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
if [ -z "$OUTPUT_PATH" ]; then
4+
echo "OUTPUT_PATH env var is not set"
5+
exit 1
6+
fi
7+
8+
if [ -z "$RPC_URL" ]; then
9+
echo "RPC_URL env var is not set"
10+
exit 1
11+
fi
12+
13+
if [ -z "$PRIVATE_KEY" ]; then
14+
echo "PRIVATE_KEY env var is not set"
15+
exit 1
16+
fi
17+
18+
if [ -z "$INDICES_TO_REMOVE" ]; then
19+
echo "INDICES_TO_REMOVE env var is not set"
20+
exit 1
21+
fi
22+
if [[ ! "$INDICES_TO_REMOVE" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
23+
echo "The INDICES_TO_REMOVE doesn't match the required format: [0,1,...,n]"
24+
exit 1
25+
fi
26+
27+
STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")
28+
29+
## Using in this cast call:
30+
31+
# /**
32+
# * @notice This function is used for removing strategies and their associated weights from the
33+
# * mapping strategyParams for a specific @param quorumNumber.
34+
# * @dev higher indices should be *first* in the list of @param indicesToRemove, since otherwise
35+
# * the removal of lower index entries will cause a shift in the indices of the other strategiesToRemove
36+
# */
37+
# function removeStrategies(uint8 quorumNumber, uint256[] calldata indicesToRemove) external;
38+
39+
QUORUM_NUMBER=0 #Aligned has only 1 quorum for now
40+
41+
cast send $STAKE_REGISTRY "removeStrategies(uint8, uint256[])()" $QUORUM_NUMBER $INDICES_TO_REMOVE --private-key $PRIVATE_KEY --rpc-url $RPC_URL
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
if [ -z "$OUTPUT_PATH" ]; then
4+
echo "OUTPUT_PATH env var is not set"
5+
exit 1
6+
fi
7+
8+
if [ -z "$RPC_URL" ]; then
9+
echo "RPC_URL env var is not set"
10+
exit 1
11+
fi
12+
13+
if [ -z "$PRIVATE_KEY" ]; then
14+
echo "PRIVATE_KEY env var is not set"
15+
exit 1
16+
fi
17+
18+
if [ -z "$STRATEGY_INDICES" ]; then
19+
echo "STRATEGY_INDICES env var is not set"
20+
exit 1
21+
fi
22+
if [[ ! "$STRATEGY_INDICES" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
23+
echo "The STRATEGY_INDICES doesn't match the required format: [0,1,...,n]"
24+
exit 1
25+
fi
26+
27+
if [ -z "$NEW_MULTIPLIERS" ]; then
28+
echo "NEW_MULTIPLIERS env var is not set"
29+
exit 1
30+
fi
31+
if [[ ! "$NEW_MULTIPLIERS" =~ ^\[[0-9]+(,[0-9]+)*\]$ ]]; then
32+
echo "The NEW_MULTIPLIERS doesn't match the required format: [0,1,...,n]"
33+
exit 1
34+
fi
35+
36+
count_elements() {
37+
local var="$1"
38+
# Remove brackets and count elements by splitting on commas
39+
echo "$var" | sed 's/[\[\]]//g' | awk -F',' '{print NF}'
40+
}
41+
count1=$(count_elements "$STRATEGY_INDICES")
42+
count2=$(count_elements "$NEW_MULTIPLIERS")
43+
44+
45+
if [[ $count1 -ne $count2 ]]; then
46+
echo "STRATEGY_INDICES and NEW_MULTIPLIERS have different numbers of elements:"
47+
echo "STRATEGY_INDICES: $STRATEGY_INDICES"
48+
echo "NEW_MULTIPLIERS: $NEW_MULTIPLIERS"
49+
exit 1
50+
fi
51+
52+
STAKE_REGISTRY=$(jq -r '.addresses.stakeRegistry' "$OUTPUT_PATH")
53+
54+
## Using in this cast call:
55+
56+
# /**
57+
# * @notice This function is used for modifying the weights of strategies that are already in the
58+
# * mapping strategyParams for a specific
59+
# * @param quorumNumber is the quorum number to change the strategy for
60+
# * @param strategyIndices are the indices of the strategies to change
61+
# * @param newMultipliers are the new multipliers for the strategies
62+
# */
63+
# function modifyStrategyParams(
64+
# uint8 quorumNumber,
65+
# uint256[] calldata strategyIndices,
66+
# uint96[] calldata newMultipliers
67+
# ) external;
68+
69+
QUORUM_NUMBER=0 #Aligned has only 1 quorum for now
70+
71+
echo $QUORUM_NUMBER
72+
73+
echo $STAKE_REGISTRY
74+
75+
cast send $STAKE_REGISTRY "modifyStrategyParams(uint8, uint256[], uint96[])()" $QUORUM_NUMBER $STRATEGY_INDICES $NEW_MULTIPLIERS --private-key $PRIVATE_KEY --rpc-url $RPC_URL

0 commit comments

Comments
 (0)