Skip to content

Commit

Permalink
Merge branch 'feat/vaults' of github.com:lidofinance/core into predep…
Browse files Browse the repository at this point in the history
…osit-guardian
  • Loading branch information
DiRaiks committed Mar 2, 2025
2 parents d42777e + cac27de commit 118163c
Show file tree
Hide file tree
Showing 111 changed files with 8,479 additions and 1,908 deletions.
9 changes: 5 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ LOCAL_STAKING_VAULT_BEACON_ADDRESS=

# RPC URL for a separate, non Hardhat Network node (Anvil, Infura, Alchemy, etc.)
MAINNET_RPC_URL=http://localhost:8545

# RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing (Infura, Alchemy, etc.)
# https://hardhat.org/hardhat-network/docs/guides/forking-other-networks#forking-other-networks
FORK_RPC_URL=https://eth.drpc.org

# https://docs.lido.fi/deployed-contracts
MAINNET_LOCATOR_ADDRESS=0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb
MAINNET_AGENT_ADDRESS=0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c
Expand Down Expand Up @@ -54,10 +59,6 @@ MAINNET_STAKING_VAULT_BEACON_ADDRESS=
HOLESKY_RPC_URL=
SEPOLIA_RPC_URL=

# RPC URL for Hardhat Network forking, required for running tests on mainnet fork with tracing (Infura, Alchemy, etc.)
# https://hardhat.org/hardhat-network/docs/guides/forking-other-networks#forking-other-networks
HARDHAT_FORKING_URL=https://eth.drpc.org

# Scratch deployment via hardhat variables
DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
GENESIS_TIME=1639659600
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration-mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

services:
hardhat-node:
image: ghcr.io/lidofinance/hardhat-node:2.22.18
image: ghcr.io/lidofinance/hardhat-node:2.22.19
ports:
- 8545:8545
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-integration-scratch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
hardhat-node:
image: ghcr.io/lidofinance/hardhat-node:2.22.18-scratch
image: ghcr.io/lidofinance/hardhat-node:2.22.19-scratch
ports:
- 8555:8545

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib/abi/*.json
accounts.json
deployed-local.json
deployed-hardhat.json
deployed-local-devnet.json

# MacOS
.DS_Store
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
yarn lint-staged
yarn typecheck
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ integration tests follows the `*.integration.ts` postfix, for example, `myScenar
Foundry's Solidity tests are specifically used for fuzzing library contracts or functions that perform complex
calculations or byte manipulation. These Solidity tests are located under `/tests` and organized into appropriate
subdirectories. The naming conventions follow
Foundry's [documentation](https://book.getfoundry.sh/tutorials/best-practices#general-test-guidance):
Foundry's [documentation](https://book.getfoundry.sh/guides/best-practices#general-test-guidance):
- For tests, use the `.t.sol` postfix (e.g., `MyContract.t.sol`).
- For scripts, use the `.s.sol` postfix (e.g., `MyScript.s.sol`).
Expand Down Expand Up @@ -327,7 +327,7 @@ This is the most common method for running integration tests. It uses an instanc
mainnet environment, allowing you to run integration tests with trace logging.
> [!NOTE]
> Ensure that `HARDHAT_FORKING_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the
> Ensure that `FORK_RPC_URL` is set to Ethereum Mainnet RPC and `MAINNET_*` environment variables are set in the
> `.env` file (refer to `.env.example` for guidance). Otherwise, the tests will run against the Scratch deployment.
```bash
Expand Down
13 changes: 9 additions & 4 deletions contracts/0.4.24/Lido.sol
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,14 @@ contract Lido is Versioned, StETHPermit, AragonApp {
* @notice Mint shares backed by external ether sources
* @param _recipient Address to receive the minted shares
* @param _amountOfShares Amount of shares to mint
* @dev Can be called only by accounting (authentication in mintShares method).
* @dev Can be called only by VaultHub
* NB: Reverts if the the external balance limit is exceeded.
*/
function mintExternalShares(address _recipient, uint256 _amountOfShares) external {
require(_recipient != address(0), "MINT_RECEIVER_ZERO_ADDRESS");
require(_amountOfShares != 0, "MINT_ZERO_AMOUNT_OF_SHARES");
_auth(getLidoLocator().vaultHub());
_whenNotStopped();

uint256 newExternalShares = EXTERNAL_SHARES_POSITION.getStorageUint256().add(_amountOfShares);
uint256 maxMintableExternalShares = _getMaxMintableExternalShares();
Expand All @@ -628,7 +630,10 @@ contract Lido is Versioned, StETHPermit, AragonApp {

EXTERNAL_SHARES_POSITION.setStorageUint256(newExternalShares);

mintShares(_recipient, _amountOfShares);
_mintShares(_recipient, _amountOfShares);
// emit event after minting shares because we are always having the net new ether under the hood
// for vaults we have new locked ether and for fees we have a part of rewards
_emitTransferAfterMintingShares(_recipient, _amountOfShares);

emit ExternalSharesMinted(_recipient, _amountOfShares, getPooledEthByShares(_amountOfShares));
}
Expand All @@ -639,7 +644,7 @@ contract Lido is Versioned, StETHPermit, AragonApp {
*/
function burnExternalShares(uint256 _amountOfShares) external {
require(_amountOfShares != 0, "BURN_ZERO_AMOUNT_OF_SHARES");
_auth(getLidoLocator().accounting());
_auth(getLidoLocator().vaultHub());
_whenNotStopped();

uint256 externalShares = EXTERNAL_SHARES_POSITION.getStorageUint256();
Expand All @@ -663,7 +668,7 @@ contract Lido is Versioned, StETHPermit, AragonApp {
*/
function rebalanceExternalEtherToInternal() external payable {
require(msg.value != 0, "ZERO_VALUE");
_auth(getLidoLocator().accounting());
_auth(getLidoLocator().vaultHub());
_whenNotStopped();

uint256 shares = getSharesByPooledEth(msg.value);
Expand Down
55 changes: 29 additions & 26 deletions contracts/0.8.25/Accounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ import {ReportValues} from "contracts/common/interfaces/ReportValues.sol";
/// @notice contract is responsible for handling accounting oracle reports
/// calculating all the state changes that is required to apply the report
/// and distributing calculated values to relevant parts of the protocol
/// @dev accounting is inherited from VaultHub contract to reduce gas costs and
/// simplify the auth flows, but they are mostly independent
contract Accounting is VaultHub {
contract Accounting {
struct Contracts {
address accountingOracleAddress;
IOracleReportSanityChecker oracleReportSanityChecker;
IBurner burner;
IWithdrawalQueue withdrawalQueue;
IPostTokenRebaseReceiver postTokenRebaseReceiver;
IStakingRouter stakingRouter;
VaultHub vaultHub;
}

struct PreReportState {
Expand Down Expand Up @@ -83,20 +82,24 @@ contract Accounting is VaultHub {
uint256 precisionPoints;
}

error NotAuthorized(string operation, address addr);

/// @notice deposit size in wei (for pre-maxEB accounting)
uint256 private constant DEPOSIT_SIZE = 32 ether;

/// @notice Lido Locator contract
ILidoLocator public immutable LIDO_LOCATOR;
/// @notice Lido contract
ILido public immutable LIDO;

constructor(ILidoLocator _lidoLocator) VaultHub(_lidoLocator) {
LIDO = ILido(_lidoLocator.lido());
}

function initialize(address _admin) external initializer {
if (_admin == address(0)) revert ZeroArgument("_admin");

__VaultHub_init(_admin);
/// @param _lidoLocator Lido Locator contract
/// @param _lido Lido contract
constructor(
ILidoLocator _lidoLocator,
ILido _lido
) {
LIDO_LOCATOR = _lidoLocator;
LIDO = _lido;
}

/// @notice calculates all the state changes that is required to apply the report
Expand Down Expand Up @@ -220,17 +223,14 @@ 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.vaultsTreasuryFeeShares,
update.totalVaultsTreasuryFeeShares
) = _calculateVaultsRebase(
update.postTotalShares,
update.postTotalPooledEther,
_pre.totalShares,
_pre.totalPooledEther,
update.sharesToMintAsFees
);
(update.vaultsLockedEther, update.vaultsTreasuryFeeShares, update.totalVaultsTreasuryFeeShares) =
_contracts.vaultHub.calculateVaultsRebase(
update.postTotalShares,
update.postTotalPooledEther,
_pre.totalShares,
_pre.totalPooledEther,
update.sharesToMintAsFees
);

update.postTotalPooledEther +=
(update.totalVaultsTreasuryFeeShares * update.postTotalPooledEther) /
Expand Down Expand Up @@ -329,15 +329,16 @@ contract Accounting is VaultHub {
_update.etherToFinalizeWQ
);

_updateVaults(
// TODO: Remove this once decide on vaults reporting
_contracts.vaultHub.updateVaults(
_report.vaultValues,
_report.inOutDeltas,
_update.vaultsLockedEther,
_update.vaultsTreasuryFeeShares
);

if (_update.totalVaultsTreasuryFeeShares > 0) {
STETH.mintExternalShares(LIDO_LOCATOR.treasury(), _update.totalVaultsTreasuryFeeShares);
_contracts.vaultHub.mintVaultsTreasuryFeeShares(LIDO_LOCATOR.treasury(), _update.totalVaultsTreasuryFeeShares);
}

_notifyRebaseObserver(_contracts.postTokenRebaseReceiver, _report, _pre, _update);
Expand Down Expand Up @@ -457,7 +458,8 @@ contract Accounting is VaultHub {
address burner,
address withdrawalQueue,
address postTokenRebaseReceiver,
address stakingRouter
address stakingRouter,
address vaultHub
) = LIDO_LOCATOR.oracleReportComponents();

return
Expand All @@ -467,7 +469,8 @@ contract Accounting is VaultHub {
IBurner(burner),
IWithdrawalQueue(withdrawalQueue),
IPostTokenRebaseReceiver(postTokenRebaseReceiver),
IStakingRouter(stakingRouter)
IStakingRouter(stakingRouter),
VaultHub(vaultHub)
);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/0.8.25/interfaces/IStakingRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface IStakingRouter {
uint256 precisionPoints
);

function reportRewardsMinted(uint256[] memory _stakingModuleIds, uint256[] memory _totalShares) external;
function reportRewardsMinted(uint256[] calldata _stakingModuleIds, uint256[] calldata _totalShares) external;
}
Loading

0 comments on commit 118163c

Please sign in to comment.