Skip to content

Commit 5d3dd3c

Browse files
committed
chore: refactor the threshold calculation
1 parent 1c7abcb commit 5d3dd3c

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

contracts/0.8.25/Accounting.sol

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ contract Accounting is VaultHub {
6969
uint256 postTotalPooledEther;
7070
/// @notice amount of ether to be locked in the vaults
7171
uint256[] vaultsLockedEther;
72-
/// @notice amount of ether to be locked in the vaults
73-
uint256[] vaultsThresholdEther;
7472
/// @notice amount of shares to be minted as vault fees to the treasury
7573
uint256[] vaultsTreasuryFeeShares;
7674
/// @notice total amount of shares to be minted as vault fees to the treasury
@@ -227,12 +225,7 @@ contract Accounting is VaultHub {
227225

228226
// Calculate the amount of ether locked in the vaults to back external balance of stETH
229227
// and the amount of shares to mint as fees to the treasury for each vaults
230-
(
231-
update.vaultsLockedEther,
232-
update.vaultsThresholdEther,
233-
update.vaultsTreasuryFeeShares,
234-
update.totalVaultsTreasuryFeeShares
235-
) =
228+
(update.vaultsLockedEther, update.vaultsTreasuryFeeShares, update.totalVaultsTreasuryFeeShares) =
236229
_calculateVaultsRebase(
237230
update.postTotalShares,
238231
update.postTotalPooledEther,
@@ -346,8 +339,9 @@ contract Accounting is VaultHub {
346339
_report.vaultValues,
347340
_report.inOutDeltas,
348341
_update.vaultsLockedEther,
349-
_update.vaultsThresholdEther,
350-
_update.vaultsTreasuryFeeShares
342+
_update.vaultsTreasuryFeeShares,
343+
_update.postTotalPooledEther,
344+
_update.postTotalShares
351345
);
352346

353347
if (_update.totalVaultsTreasuryFeeShares > 0) {

contracts/0.8.25/vaults/VaultHub.sol

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
405405
uint256 _preTotalShares,
406406
uint256 _preTotalPooledEther,
407407
uint256 _sharesToMintAsFees
408-
) internal view returns (
409-
uint256[] memory lockedEther,
410-
uint256[] memory thresholdEther,
411-
uint256[] memory treasuryFeeShares,
412-
uint256 totalTreasuryFeeShares
413-
) {
408+
) internal view returns (uint256[] memory lockedEther, uint256[] memory treasuryFeeShares, uint256 totalTreasuryFeeShares) {
414409
/// HERE WILL BE ACCOUNTING DRAGON
415410

416411
// \||/
@@ -431,7 +426,6 @@ abstract contract VaultHub is PausableUntilWithRoles {
431426

432427
treasuryFeeShares = new uint256[](length);
433428
lockedEther = new uint256[](length);
434-
thresholdEther = new uint256[](length);
435429

436430
for (uint256 i = 0; i < length; ++i) {
437431
VaultSocket memory socket = $.sockets[i + 1];
@@ -452,9 +446,6 @@ abstract contract VaultHub is PausableUntilWithRoles {
452446
(mintedStETH * TOTAL_BASIS_POINTS) / (TOTAL_BASIS_POINTS - socket.reserveRatioBP),
453447
CONNECT_DEPOSIT
454448
);
455-
456-
// Minimum amount of ether that should be in the vault to avoid unbalanced state
457-
thresholdEther[i] = (mintedStETH * TOTAL_BASIS_POINTS) / (TOTAL_BASIS_POINTS - socket.reserveRatioThresholdBP);
458449
}
459450
}
460451
}
@@ -493,8 +484,9 @@ abstract contract VaultHub is PausableUntilWithRoles {
493484
uint256[] memory _valuations,
494485
int256[] memory _inOutDeltas,
495486
uint256[] memory _locked,
496-
uint256[] memory _thresholds,
497-
uint256[] memory _treasureFeeShares
487+
uint256[] memory _treasureFeeShares,
488+
uint256 _postTotalPooledEther,
489+
uint256 _postTotalShares
498490
) internal {
499491
VaultHubStorage storage $ = _getVaultHubStorage();
500492

@@ -508,7 +500,9 @@ abstract contract VaultHub is PausableUntilWithRoles {
508500
socket.sharesMinted += uint96(treasuryFeeShares);
509501
}
510502

511-
_epicrisis(_valuations[i], _thresholds[i], socket);
503+
uint256 mintedStETH = (socket.sharesMinted * _postTotalPooledEther) / _postTotalShares; //TODO: check rounding
504+
uint256 threshold = (mintedStETH * TOTAL_BASIS_POINTS) / (TOTAL_BASIS_POINTS - socket.reserveRatioThresholdBP);
505+
_epicrisis(_valuations[i], threshold, socket);
512506

513507

514508
IStakingVault(socket.vault).report(_valuations[i], _inOutDeltas[i], _locked[i]);

0 commit comments

Comments
 (0)