Skip to content
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

feat: Vaults #874

Draft
wants to merge 552 commits into
base: develop
Choose a base branch
from
Draft

feat: Vaults #874

wants to merge 552 commits into from

Conversation

tamtamchik
Copy link
Member

@tamtamchik tamtamchik commented Nov 17, 2024

❗ 🚧 Under construction 🚧 ❗

Staking Vaults

New way of isolated staking, through separate vaults, with optional stETH liquidity

  • Support minting external backed stETH in Lido contract
  • Extract protocol accounting to separate contract (two-step, better precision)
  • StakingVault + VaultHub
  • Dashboard and Delegation for Vaults
  • VaultFactory

loga4 and others added 30 commits November 7, 2024 09:42
…56k1-4.0.4

build(deps): bump secp256k1 from 4.0.3 to 4.0.4
feat: add separate step for vaults deployment
# Conflicts:
#	contracts/0.8.9/oracle/AccountingOracle.sol
#	contracts/0.8.9/sanity_checks/OracleReportSanityChecker.sol
#	lib/protocol/helpers/accounting.ts
#	lib/state-file.ts
#	package.json
#	scripts/scratch/steps/0090-deploy-non-aragon-contracts.ts
#	test/0.8.9/oracle/accountingOracle.submitReportExtraData.test.ts
#	test/0.8.9/sanityChecker/oracleReportSanityChecker.misc.test.ts
#	test/deploy/accountingOracle.ts
#	test/integration/protocol-happy-path.integration.ts
#	test/suite/index.ts
#	yarn.lock
// _getTPE is super wide used
uint256 externalShares = EXTERNAL_SHARES_POSITION.getStorageUint256();
uint256 internalShares = _getTotalShares() - externalShares;
return externalShares.mul(_internalEther).div(internalShares);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precision loss here can add up in getPooledEthForShares() and we get double loss on conversion.

Probably, worth to redesign conversion functions in StETH.sol to use internal ETH instead.

Comment on lines +295 to +304
function mintWstETH(
address _recipient,
uint256 _tokens
) external payable virtual onlyRole(DEFAULT_ADMIN_ROLE) fundAndProceed {
_mint(address(this), _tokens);

STETH.approve(address(WSTETH), _tokens);
uint256 wstETHAmount = WSTETH.wrap(_tokens);
WSTETH.transfer(_recipient, wstETHAmount);
}

Check warning

Code scanning / Slither

Unused return Medium

contracts/0.8.25/vaults/Delegation.sol Fixed Show fixed Hide fixed
Comment on lines +169 to +172
function valuation() public view returns (uint256) {
ERC7201Storage storage $ = _getStorage();
return uint256(int256(int128($.report.valuation) + $.inOutDelta - $.report.inOutDelta));
}

Check warning

Code scanning / Slither

Potential Arithmetic Overflow Medium

StakingVault.valuation() contains integer variables whose type is larger than the type of one of its intermediate expressions. Consider casting sub expressions explicitly as they might lead to unexpected overflow:
In [uint256(int256(int128($.report.valuation) + $.inOutDelta - $.report.inOutDelta))](contracts/0.8.25/vaults/StakingVault.sol#L171) intermidiate expressions returns type of lower order:
... + REF_1016 returns int128, but the type of the resulting expression is uint256.
tamtamchik and others added 8 commits December 24, 2024 16:06
Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.5 to 3.10.11.
- [Release notes](https://github.com/aio-libs/aiohttp/releases)
- [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst)
- [Commits](aio-libs/aiohttp@v3.10.5...v3.10.11)

---
updated-dependencies:
- dependency-name: aiohttp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [@eslint/plugin-kit](https://github.com/eslint/rewrite) from 0.2.0 to 0.2.4.
- [Release notes](https://github.com/eslint/rewrite/releases)
- [Changelog](https://github.com/eslint/rewrite/blob/main/release-please-config.json)
- [Commits](eslint/rewrite@core-v0.2.0...plugin-kit-v0.2.4)

---
updated-dependencies:
- dependency-name: "@eslint/plugin-kit"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
…lugin-kit-0.2.4' into feat/dependabot-updates
Copy link
Contributor

@TheDZhon TheDZhon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ™„

contract BeaconChainDepositLogistics {
uint256 internal constant PUBLIC_KEY_LENGTH = 48;
uint256 internal constant SIGNATURE_LENGTH = 96;
uint256 internal constant DEPOSIT_SIZE = 32 ether;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ maybe make it more Pectra-friendly

Comment on lines +23 to +25
* We cannot use the BeaconChainDepositor contract from the common library because
* it is using an older Solidity version. We also cannot have a common contract with a version
* range because that would break the verification of the old contracts using the 0.8.9 version of this contract.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't be relevant once non-32ETH deposits incorporated

Comment on lines +50 to +55
function _makeBeaconChainDeposits32ETH(
uint256 _keysCount,
bytes memory _withdrawalCredentials,
bytes memory _publicKeysBatch,
bytes memory _signaturesBatch
) internal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function _makeBeaconChainDeposits32ETH(
uint256 _keysCount,
bytes memory _withdrawalCredentials,
bytes memory _publicKeysBatch,
bytes memory _signaturesBatch
) internal {
function _makeBeaconChainDeposits(
uint256 _keysCount,
bytes memory _withdrawalCredentials,
bytes memory _publicKeysBatch,
bytes memory _signaturesBatch,
uint256[] memory _depositSizes
) internal {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 may check signatures using EIP-2537

Comment on lines +94 to +95
MemUtils.copyBytes(_signature, sigPart1, 0, 0, 64);
MemUtils.copyBytes(_signature, sigPart2, 64, 0, SIGNATURE_LENGTH - 64);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,514 @@
// SPDX-FileCopyrightText: 2024 Lido <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SPDX-FileCopyrightText: 2024 Lido <[email protected]>
// SPDX-FileCopyrightText: 2025 Lido <[email protected]>

Comment on lines +323 to +327
STETH.transfer(address(vaultHub), stETHAmount);

uint256 sharesAmount = STETH.getSharesByPooledEth(stETHAmount);

vaultHub.burnSharesBackedByVault(address(stakingVault), sharesAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's reuse _burn

* @param _permit data required for the stETH.permit() method to set the allowance
*/
function burnWithPermit(
uint256 _tokens,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint256 _tokens,
uint256 _amountOfShares,


/**
* @notice Burns stETH tokens from the sender backed by the vault using EIP-2612 Permit.
* @param _tokens Amount of stETH tokens to burn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

IERC20Permit(token).permit(
owner,
spender,
permitInput.value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ value != shares for stETH

Comment on lines +397 to +401
STETH.transfer(address(vaultHub), stETHAmount);

uint256 sharesAmount = STETH.getSharesByPooledEth(stETHAmount);

vaultHub.burnSharesBackedByVault(address(stakingVault), sharesAmount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's reuse _burn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-upgrade Things to pickup for the next protocol upgrade solidity issues/tasks related to smart contract code vaults
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants