Skip to content

Commit

Permalink
chore: refactor the threshold calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Feb 6, 2025
1 parent 1c7abcb commit 5d3dd3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
14 changes: 4 additions & 10 deletions contracts/0.8.25/Accounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ contract Accounting is VaultHub {
uint256 postTotalPooledEther;
/// @notice amount of ether to be locked in the vaults
uint256[] vaultsLockedEther;
/// @notice amount of ether to be locked in the vaults
uint256[] vaultsThresholdEther;
/// @notice amount of shares to be minted as vault fees to the treasury
uint256[] vaultsTreasuryFeeShares;
/// @notice total amount of shares to be minted as vault fees to the treasury
Expand Down Expand Up @@ -227,12 +225,7 @@ contract Accounting is VaultHub {

// Calculate the amount of ether locked in the vaults to back external balance of stETH
// and the amount of shares to mint as fees to the treasury for each vaults
(
update.vaultsLockedEther,
update.vaultsThresholdEther,
update.vaultsTreasuryFeeShares,
update.totalVaultsTreasuryFeeShares
) =
(update.vaultsLockedEther, update.vaultsTreasuryFeeShares, update.totalVaultsTreasuryFeeShares) =
_calculateVaultsRebase(
update.postTotalShares,
update.postTotalPooledEther,
Expand Down Expand Up @@ -346,8 +339,9 @@ contract Accounting is VaultHub {
_report.vaultValues,
_report.inOutDeltas,
_update.vaultsLockedEther,
_update.vaultsThresholdEther,
_update.vaultsTreasuryFeeShares
_update.vaultsTreasuryFeeShares,
_update.postTotalPooledEther,
_update.postTotalShares
);

if (_update.totalVaultsTreasuryFeeShares > 0) {
Expand Down
20 changes: 7 additions & 13 deletions contracts/0.8.25/vaults/VaultHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,7 @@ abstract contract VaultHub is PausableUntilWithRoles {
uint256 _preTotalShares,
uint256 _preTotalPooledEther,
uint256 _sharesToMintAsFees
) internal view returns (
uint256[] memory lockedEther,
uint256[] memory thresholdEther,
uint256[] memory treasuryFeeShares,
uint256 totalTreasuryFeeShares
) {
) internal view returns (uint256[] memory lockedEther, uint256[] memory treasuryFeeShares, uint256 totalTreasuryFeeShares) {
/// HERE WILL BE ACCOUNTING DRAGON

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

treasuryFeeShares = new uint256[](length);
lockedEther = new uint256[](length);
thresholdEther = new uint256[](length);

for (uint256 i = 0; i < length; ++i) {
VaultSocket memory socket = $.sockets[i + 1];
Expand All @@ -452,9 +446,6 @@ abstract contract VaultHub is PausableUntilWithRoles {
(mintedStETH * TOTAL_BASIS_POINTS) / (TOTAL_BASIS_POINTS - socket.reserveRatioBP),
CONNECT_DEPOSIT
);

// Minimum amount of ether that should be in the vault to avoid unbalanced state
thresholdEther[i] = (mintedStETH * TOTAL_BASIS_POINTS) / (TOTAL_BASIS_POINTS - socket.reserveRatioThresholdBP);
}
}
}
Expand Down Expand Up @@ -493,8 +484,9 @@ abstract contract VaultHub is PausableUntilWithRoles {
uint256[] memory _valuations,
int256[] memory _inOutDeltas,
uint256[] memory _locked,
uint256[] memory _thresholds,
uint256[] memory _treasureFeeShares
uint256[] memory _treasureFeeShares,
uint256 _postTotalPooledEther,
uint256 _postTotalShares
) internal {
VaultHubStorage storage $ = _getVaultHubStorage();

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

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


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

0 comments on commit 5d3dd3c

Please sign in to comment.