Skip to content

Commit e708444

Browse files
Improve docs, simplify variant handling (#57)
* Simplify variant detection * Handle depositing stake with first validator joining * Implement and document getAdditionalSteps() * Divide code into sections, rename functions * Increment major version number * Fix unintended renaming * Fix accidential renamings
1 parent d243a7d commit e708444

28 files changed

+1094
-847
lines changed

README.md

+38-30
Large diffs are not rendered by default.

claim.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ block=$(cast rpc eth_blockNumber)
2020
block_num=$(echo $block | tr -d '"' | cast to-dec --base-in 16)
2121

2222
echo rewardsAfterClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num | sed 's/\[[^]]*\]//g')
23-
if [[ "$variant" == "ILiquidDelegation" ]]; then
23+
if [[ "$variant" == "LiquidStaking" ]]; then
2424
echo taxedRewardsAfterClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num | sed 's/\[[^]]*\]//g')
2525
fi
2626

@@ -44,7 +44,7 @@ block_num=$((block_num-1))
4444
block=$(echo $block_num | cast to-hex --base-in 10)
4545

4646
echo rewardsBeforeClaiming = $(cast call $1 "getRewards()(uint256)" --block $block_num | sed 's/\[[^]]*\]//g')
47-
if [[ "$variant" == "ILiquidDelegation" ]]; then
47+
if [[ "$variant" == "LiquidStaking" ]]; then
4848
echo taxedRewardsBeforeClaiming = $(cast call $1 "getTaxedRewards()(uint256)" --block $block_num | sed 's/\[[^]]*\]//g')
4949
fi
5050

e2e_liquid.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ join_one() {
5151
else
5252
echo "🔴 setControlAddress($1, $(cast wallet address $2))"
5353
fi
54-
status=$(cast send --legacy --json --private-key $OWNER_KEY $CONTRACT_ADDRESS "join(bytes,address)" $1 $(cast wallet address $2) | jq '.status') 1>/dev/null
54+
status=$(cast send --legacy --json --private-key $OWNER_KEY $CONTRACT_ADDRESS "joinPool(bytes,address)" $1 $(cast wallet address $2) | jq '.status') 1>/dev/null
5555
if [[ "$status" == "\"0x1\"" ]]; then
56-
echo "🟢 join($1, $(cast wallet address $2))"
56+
echo "🟢 joinPool($1, $(cast wallet address $2))"
5757
else
58-
echo "🔴 join($1, $(cast wallet address $2))"
58+
echo "🔴 joinPool($1, $(cast wallet address $2))"
5959
fi
6060
echo -n "🟢 validators: " && cast call $CONTRACT_ADDRESS "validators()((bytes,uint256,bool,bool,bool,bool)[])" | sed 's/ \[[0-9]e[0-9][0-9]\]//g' | sed 's/, true//g' | sed 's/, false//g' | sed 's/0x[0-9a-f]*,//g' | sed 's/( //g' | sed 's/)//g'
6161
echo "🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼"
@@ -74,11 +74,11 @@ leave_one() {
7474
echo -n "🟢 pending withdrawals: " && echo $pending
7575

7676
while [[ "$pending" == "true" ]]; do
77-
status=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1 | jq '.status') 1>/dev/null
77+
status=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1 | jq '.status') 1>/dev/null
7878
if [[ "$status" == "\"0x1\"" ]]; then
79-
echo "🟢 leave($1)"
79+
echo "🟢 leavePool($1)"
8080
else
81-
echo "🔴 leave($1)"
81+
echo "🔴 leavePool($1)"
8282
fi
8383

8484
echo "############################### UNBONDING ##############################"
@@ -96,13 +96,13 @@ leave_one() {
9696

9797
count=$(cast call $CONTRACT_ADDRESS "validators()((bytes,uint256,bool,bool,bool,bool)[])" | grep -c -o "$1")
9898
if [[ $count -gt 0 ]]; then
99-
temp=$(cast send --legacy --gas-limit 1000000 --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1)
100-
#temp=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1)
99+
temp=$(cast send --legacy --gas-limit 1000000 --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1)
100+
#temp=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1)
101101
status=$(echo $temp | jq '.status')
102102
if [[ "$status" == "\"0x1\"" ]]; then
103-
echo "🟢 leave($1) $(echo $temp | jq '.transactionHash')"
103+
echo "🟢 leavePool($1) $(echo $temp | jq '.transactionHash')"
104104
else
105-
echo "🔴 leave($1) $(echo $temp | jq '.transactionHash')"
105+
echo "🔴 leavePool($1) $(echo $temp | jq '.transactionHash')"
106106
fi
107107
fi
108108

e2e_non-liquid.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ join_one() {
5151
else
5252
echo "🔴 setControlAddress($1, $(cast wallet address $2))"
5353
fi
54-
status=$(cast send --legacy --json --private-key $OWNER_KEY $CONTRACT_ADDRESS "join(bytes,address)" $1 $(cast wallet address $2) | jq '.status') 1>/dev/null
54+
status=$(cast send --legacy --json --private-key $OWNER_KEY $CONTRACT_ADDRESS "joinPool(bytes,address)" $1 $(cast wallet address $2) | jq '.status') 1>/dev/null
5555
if [[ "$status" == "\"0x1\"" ]]; then
56-
echo "🟢 join($1, $(cast wallet address $2))"
56+
echo "🟢 joinPool($1, $(cast wallet address $2))"
5757
else
58-
echo "🔴 join($1, $(cast wallet address $2))"
58+
echo "🔴 joinPool($1, $(cast wallet address $2))"
5959
fi
6060
echo -n "🟢 validators: " && cast call $CONTRACT_ADDRESS "validators()((bytes,uint256,bool,bool,bool,bool)[])" | sed 's/ \[[0-9]e[0-9][0-9]\]//g' | sed 's/, true//g' | sed 's/, false//g' | sed 's/0x[0-9a-f]*,//g' | sed 's/( //g' | sed 's/)//g'
6161
echo "🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼🔼"
@@ -74,11 +74,11 @@ leave_one() {
7474
echo -n "🟢 pending withdrawals: " && echo $pending
7575

7676
while [[ "$pending" == "true" ]]; do
77-
status=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1 | jq '.status') 1>/dev/null
77+
status=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1 | jq '.status') 1>/dev/null
7878
if [[ "$status" == "\"0x1\"" ]]; then
79-
echo "🟢 leave($1)"
79+
echo "🟢 leavePool($1)"
8080
else
81-
echo "🔴 leave($1)"
81+
echo "🔴 leavePool($1)"
8282
fi
8383

8484
echo "############################### UNBONDING ##############################"
@@ -96,13 +96,13 @@ leave_one() {
9696

9797
count=$(cast call $CONTRACT_ADDRESS "validators()((bytes,uint256,bool,bool,bool,bool)[])" | grep -c -o "$1")
9898
if [[ $count -gt 0 ]]; then
99-
temp=$(cast send --legacy --gas-limit 1000000 --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1)
100-
#temp=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leave(bytes)" $1)
99+
temp=$(cast send --legacy --gas-limit 1000000 --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1)
100+
#temp=$(cast send --legacy --json --private-key $2 $CONTRACT_ADDRESS "leavePool(bytes)" $1)
101101
status=$(echo $temp | jq '.status')
102102
if [[ "$status" == "\"0x1\"" ]]; then
103-
echo "🟢 leave($1) $(echo $temp | jq '.transactionHash')"
103+
echo "🟢 leavePool($1) $(echo $temp | jq '.transactionHash')"
104104
else
105-
echo "🔴 leave($1) $(echo $temp | jq '.transactionHash')"
105+
echo "🔴 leavePool($1) $(echo $temp | jq '.transactionHash')"
106106
fi
107107
fi
108108

script/CheckVariant.s.sol

+26-11
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ pragma solidity ^0.8.26;
33

44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
6-
import {ILiquidDelegation} from "src/LiquidDelegation.sol";
7-
import {INonLiquidDelegation} from "src/NonLiquidDelegation.sol";
8-
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
9-
import {Console} from "script/Console.sol";
6+
import {BaseDelegation} from "src/BaseDelegation.sol";
7+
import {LIQUID_VARIANT} from "src/LiquidDelegation.sol";
8+
import {NONLIQUID_VARIANT} from "src/NonLiquidDelegation.sol";
9+
import {Console} from "script/Console.s.sol";
10+
11+
function variant(address proxy) view returns(bytes32) {
12+
BaseDelegation delegation = BaseDelegation(payable(proxy));
13+
uint64 version = delegation.version();
14+
if (version < delegation.encodeVersion(0, 5, 2)) {
15+
(bool success, bytes memory result) = proxy.staticcall(abi.encodeWithSignature("interfaceId()"));
16+
if (!success)
17+
return 0;
18+
bytes4 interfaceId = abi.decode(result, (bytes4));
19+
if (interfaceId == 0x88826e8e)
20+
return LIQUID_VARIANT;
21+
else if (interfaceId == 0xa2adf26a)
22+
return NONLIQUID_VARIANT;
23+
else
24+
return 0;
25+
} else
26+
return delegation.variant();
27+
}
1028

1129
contract CheckVariant is Script {
12-
using ERC165Checker for address;
1330

1431
function run(address proxy) external view {
1532

16-
if (proxy.supportsInterface(type(ILiquidDelegation).interfaceId))
17-
Console.log("ILiquidDelegation");
18-
19-
if (proxy.supportsInterface(type(INonLiquidDelegation).interfaceId))
20-
Console.log("INonLiquidDelegation");
21-
33+
if (variant(proxy) == LIQUID_VARIANT)
34+
Console.log("LiquidStaking");
35+
else if (variant(proxy) == NONLIQUID_VARIANT)
36+
Console.log("NonLiquidStaking");
2237
}
2338
}

script/CheckVersion.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.26;
44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
66
import {BaseDelegation} from "src/BaseDelegation.sol";
7-
import {Console} from "script/Console.sol";
7+
import {Console} from "script/Console.s.sol";
88

99
contract CheckVersion is Script {
1010

script/Claim.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.26;
44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
66
import {BaseDelegation} from "src/BaseDelegation.sol";
7-
import {Console} from "script/Console.sol";
7+
import {Console} from "script/Console.s.sol";
88

99
contract Claim is Script {
1010
function run(address payable proxy) external {

script/CollectCommission.s.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pragma solidity ^0.8.26;
44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
66
import {BaseDelegation} from "src/BaseDelegation.sol";
7-
import {Console} from "script/Console.sol";
7+
import {Console} from "script/Console.s.sol";
88
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
9-
import {Console} from "script/Console.sol";
9+
import {Console} from "script/Console.s.sol";
1010

1111
contract CollectCommission is Script {
1212
using Strings for string;

script/Configure.s.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pragma solidity ^0.8.26;
44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
66
import {BaseDelegation} from "src/BaseDelegation.sol";
7-
import {Console} from "script/Console.sol";
7+
import {Console} from "script/Console.s.sol";
88
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
9-
import {Console} from "script/Console.sol";
9+
import {Console} from "script/Console.s.sol";
1010

1111
contract Configure is Script {
1212
using Strings for string;

script/Console.sol script/Console.s.sol

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.26;
33

44
/* solhint-disable no-console */
5+
import {Script} from "forge-std/Script.sol";
56
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
67
import {console} from "forge-std/console.sol";
78
import {console2} from "forge-std/console2.sol";
@@ -121,4 +122,8 @@ library Console {
121122
return console.log(first);
122123
}
123124

124-
}
125+
}
126+
127+
contract Test is Script {
128+
function run() external {}
129+
}

script/Deploy.s.sol

+20-59
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,12 @@ import {LiquidDelegation} from "src/LiquidDelegation.sol";
88
import {NonLiquidDelegation} from "src/NonLiquidDelegation.sol";
99
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
1010
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
11-
import {Console} from "script/Console.sol";
11+
import {Console} from "script/Console.s.sol";
1212

1313
contract Deploy is Script {
1414
using Strings for string;
1515

16-
function liquidDelegation(string calldata name, string calldata symbol) external {
17-
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
18-
address owner = vm.addr(deployerPrivateKey);
19-
Console.log("Signer is %s", owner);
20-
21-
vm.startBroadcast(deployerPrivateKey);
22-
23-
address implementation;
24-
bytes memory initializerCall;
25-
26-
27-
implementation = address(new LiquidDelegation());
28-
initializerCall = abi.encodeWithSignature(
29-
"initialize(address,string,string)",
30-
owner,
31-
name,
32-
symbol
33-
);
34-
16+
function _run(address implementation, bytes memory initializerCall) internal {
3517
address payable proxy = payable(
3618
new ERC1967Proxy(implementation, initializerCall)
3719
);
@@ -66,62 +48,41 @@ contract Deploy is Script {
6648
uint256(minor),
6749
uint256(patch)
6850
);
69-
70-
vm.stopBroadcast();
71-
7251
}
7352

74-
function nonLiquidDelegation() external {
53+
function liquidDelegation(string calldata name, string calldata symbol) external {
7554
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
7655
address owner = vm.addr(deployerPrivateKey);
7756
Console.log("Signer is %s", owner);
7857

7958
vm.startBroadcast(deployerPrivateKey);
8059

81-
address implementation;
82-
bytes memory initializerCall;
83-
84-
85-
implementation = address(new NonLiquidDelegation());
86-
initializerCall = abi.encodeWithSignature(
87-
"initialize(address)",
88-
owner
60+
bytes memory initializerCall = abi.encodeWithSignature(
61+
"initialize(address,string,string)",
62+
owner,
63+
name,
64+
symbol
8965
);
9066

91-
address payable proxy = payable(
92-
new ERC1967Proxy(implementation, initializerCall)
93-
);
67+
_run(address(new LiquidDelegation()), initializerCall);
9468

95-
Console.log(
96-
"Proxy deployed: %s \r\n Implementation deployed: %s",
97-
proxy,
98-
implementation
99-
);
69+
vm.stopBroadcast();
10070

101-
BaseDelegation delegation = BaseDelegation(
102-
proxy
103-
);
71+
}
10472

105-
Console.log("Owner is %s",
106-
delegation.owner()
107-
);
73+
function nonLiquidDelegation() external {
74+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
75+
address owner = vm.addr(deployerPrivateKey);
76+
Console.log("Signer is %s", owner);
10877

109-
bytes memory reinitializerCall = abi.encodeWithSignature(
110-
"reinitialize(uint64)",
111-
1
112-
);
78+
vm.startBroadcast(deployerPrivateKey);
11379

114-
delegation.upgradeToAndCall(
115-
implementation,
116-
reinitializerCall
80+
bytes memory initializerCall = abi.encodeWithSignature(
81+
"initialize(address)",
82+
owner
11783
);
11884

119-
(uint24 major, uint24 minor, uint24 patch) = delegation.decodedVersion();
120-
Console.log("Upgraded to version: %s.%s.%s",
121-
uint256(major),
122-
uint256(minor),
123-
uint256(patch)
124-
);
85+
_run(address(new NonLiquidDelegation()), initializerCall);
12586

12687
vm.stopBroadcast();
12788
}

script/Stake.s.sol

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ pragma solidity ^0.8.26;
55
import {Script} from "forge-std/Script.sol";
66
import {NonRebasingLST} from "src/NonRebasingLST.sol";
77
import {BaseDelegation} from "src/BaseDelegation.sol";
8-
import {ILiquidDelegation, LiquidDelegation} from "src/LiquidDelegation.sol";
9-
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
10-
import {Console} from "script/Console.sol";
8+
import {LiquidDelegation, LIQUID_VARIANT} from "src/LiquidDelegation.sol";
9+
import {variant} from "script/CheckVariant.s.sol";
10+
import {Console} from "script/Console.s.sol";
1111

1212
contract Stake is Script {
13-
using ERC165Checker for address;
1413

1514
function run(address payable proxy, uint256 amount) external {
1615
address staker = msg.sender;
@@ -31,7 +30,7 @@ contract Stake is Script {
3130
delegation.getRewards()
3231
);
3332

34-
if (address(delegation).supportsInterface(type(ILiquidDelegation).interfaceId)) {
33+
if (variant(proxy) == LIQUID_VARIANT) {
3534
NonRebasingLST lst = NonRebasingLST(LiquidDelegation(payable(address(delegation))).getLST());
3635
Console.log("LST address: %s",
3736
address(lst)
@@ -54,7 +53,7 @@ contract Stake is Script {
5453
value: amount
5554
}();
5655

57-
if (address(delegation).supportsInterface(type(ILiquidDelegation).interfaceId)) {
56+
if (variant(proxy) == LIQUID_VARIANT) {
5857
NonRebasingLST lst = NonRebasingLST(LiquidDelegation(payable(address(delegation))).getLST());
5958
Console.log("Staker balance after: %s wei %s %s",
6059
staker.balance,

script/StakeRewards.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.26;
44
/* solhint-disable no-console */
55
import {Script} from "forge-std/Script.sol";
66
import {BaseDelegation} from "src/BaseDelegation.sol";
7-
import {Console} from "script/Console.sol";
7+
import {Console} from "script/Console.s.sol";
88

99
contract StakeRewards is Script {
1010

0 commit comments

Comments
 (0)