-
Notifications
You must be signed in to change notification settings - Fork 150
added totalStake and totalValidatorStake along with unit tests #3624
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
fbf54b1
8917d51
64b8070
64d1597
df862a2
cd7137f
aec1da7
de503ab
5d20e65
d80a4dc
3cced67
cb7ad4c
290099e
9998536
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+2 −2 | .github/workflows/test.yml | |
+2,079 −2,101 | Cargo.lock | |
+11 −9 | Cargo.toml | |
+2 −7 | diff-test/Cargo.toml | |
+48 −28 | diff-test/src/lib.rs | |
+18 −135 | diff-test/src/main.rs | |
+120 −35 | flake.lock | |
+39 −38 | flake.nix | |
+1 −5 | justfile | |
+108 −35 | src/BN254.sol | |
+35 −0 | src/Utils.sol | |
+15 −151 | test/BN254.t.sol |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,11 @@ import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; | |
/// | ||
/// 8. The commission rate for validators can be updated with the `updateCommission` function. | ||
/// | ||
/// 9. The `totalValidatorStake` and `totalStake` functions are added to allow governance to | ||
/// track the total stake in the contract. The totalValidatorStake is the total stake in active | ||
/// validators and the totalStake is the total stake in all states (active + exiting + | ||
/// pendingWithdrawal). | ||
/// | ||
/// @notice The StakeTableV2 contract ABI is a superset of the original ABI. Consumers of the | ||
/// contract can use the V2 ABI, even if they would like to maintain backwards compatibility. | ||
contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeable { | ||
|
@@ -84,6 +89,12 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
/// @notice Maximum commission increase allowed per increase (in basis points) | ||
uint16 public maxCommissionIncrease; | ||
|
||
/// @notice Total stake in active (not marked for exit) validators in the contract | ||
uint256 public totalValidatorStake; | ||
|
||
|
||
/// @notice Total stake in all states (active + exiting + pendingWithdrawal) in the contract | ||
uint256 public totalStake; | ||
|
||
/// @notice Commission tracking for each validator | ||
mapping(address validator => CommissionTracking tracking) public commissionTracking; | ||
|
||
|
@@ -254,6 +265,9 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
// it's only decremented during withdrawal | ||
validators[validator].delegatedAmount -= amount; | ||
|
||
// finally, update the total stake as the balance was withdrawn | ||
totalStake -= amount; | ||
|
||
SafeTransferLib.safeTransfer(token, delegator, amount); | ||
|
||
emit Withdrawal(delegator, amount); | ||
|
@@ -263,7 +277,26 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
/// @param validator The validator to withdraw from | ||
/// @dev This function is overridden to add pausable functionality | ||
function claimWithdrawal(address validator) public virtual override whenNotPaused { | ||
super.claimWithdrawal(validator); | ||
address delegator = msg.sender; | ||
// If entries are missing at any of the levels of the mapping this will return zero | ||
uint256 amount = undelegations[validator][delegator].amount; | ||
if (amount == 0) { | ||
revert NothingToWithdraw(); | ||
} | ||
|
||
if (block.timestamp < undelegations[validator][delegator].unlocksAt) { | ||
revert PrematureWithdrawal(); | ||
} | ||
|
||
// Mark funds as spent | ||
delete undelegations[validator][delegator]; | ||
|
||
// update the total stake managed by the contract | ||
totalStake -= amount; | ||
|
||
SafeTransferLib.safeTransfer(token, delegator, amount); | ||
|
||
emit Withdrawal(delegator, amount); | ||
} | ||
|
||
/// @notice Delegate funds to a validator | ||
|
@@ -272,6 +305,9 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
/// @dev This function is overridden to add pausable functionality | ||
function delegate(address validator, uint256 amount) public virtual override whenNotPaused { | ||
super.delegate(validator, amount); | ||
|
||
totalStake += amount; | ||
totalValidatorStake += amount; | ||
} | ||
|
||
/// @notice Undelegate funds from a validator | ||
|
@@ -280,6 +316,7 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
/// @dev This function is overridden to add pausable functionality | ||
function undelegate(address validator, uint256 amount) public virtual override whenNotPaused { | ||
super.undelegate(validator, amount); | ||
totalValidatorStake -= amount; | ||
} | ||
|
||
/// @notice Deregister a validator | ||
|
@@ -295,6 +332,7 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab | |
validatorExits[validator] = block.timestamp + exitEscrowPeriod; | ||
// in v2, the delegatedAmount is not updated until withdrawal | ||
|
||
totalValidatorStake -= validators[validator].delegatedAmount; | ||
emit ValidatorExit(validator); | ||
} | ||
|
||
|
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.
This looks like an accidental submodule downgrade. Probably missing a
git submodule update
after pulling main.