lido
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    4
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Direct-like Deposits proposal for a 3rd-party Vault ## Overview With the increase in the share of the SimpleDVT module and the demand for more targeted allocation of stake into the module, the question arises about the existence of a mechanism ensuring the deposit of user ETH into a specific staking module of the protocol. However, the current protocol lacks a mechanism to facilitate this because all incoming stake is automatically allocated across modules according to the [MinFirstAllocationStrategy](https://docs.lido.fi/contracts/staking-router#allocation-algorithm). This means that new stake will be directed to the module with the smallest share of allocated stake until a certain module has the smallest share. Additionally, it's important to note that ETH from the buffer can be used to [fulfill withdrawal requests](https://docs.lido.fi/contracts/staking-router#stake-allocation) (also check the code of [`Lido.getDepositableEther()`](https://github.com/lidofinance/lido-dao/blob/master/contracts/0.4.24/Lido.sol#L682-L686)) One possible solution to the problem at hand, without making changes to the Lido core protocol smart contracts, is simply to wait for an opportune moment when there are no outstanding withdrawals in the protocol. Subsequently, one can sequentially call the [`submit`](https://docs.lido.fi/contracts/lido#submit) method (to place ETH in the buffer) and the [`deposit`](https://docs.lido.fi/contracts/lido#deposit) method (to allocate stake to the module). Thus, as long as the module's share of allocated stake remains minimal, it can be asserted that newly staked Ether will be allocated to this module. The technical implementation of this approach involves using an external smart contract, capable of submitting Ether and simultaneously depositing it within a single transaction. However, this approach will also require adjustments to off-chain tooling, particularly minor changes to the [logic of the depositor bot](https://docs.lido.fi/contracts/staking-router#deposit) to ensure conditions for optimal timing and the invocation of methods on the external contract. ## On-chain implemenatation's interface #### External vault design assumptions - The external vault collects user-submitted ether on the owned balance - The external vaults allow users redeeming back their positions nominated in wstETH #### Description As stated in the [deposit process flow](https://docs.lido.fi/contracts/staking-router#deposit), the depositor bot must gather guardian messages and other parameters to pass them to the invoked [`depositBufferedEther`](https://docs.lido.fi/contracts/deposit-security-module#depositbufferedether) method in the [`DSM contract`](https://docs.lido.fi/contracts/deposit-security-module). Because the method in the DSM contract is _permissionless_, any caller with a full set of parameters can invoke it. Therefore, when implementing the combined method in the third patry contract, it must also accept these parameters for subsequent passing to the DSM contract. Additionally, it can be assumed that the external contract will target only a specific staking module. Therefore, it can define the module ID it is intended for, excluding the need to transmit this parameter as redundant. (In case of SimpleDVT module this id would be `SIMPLE_DVT_MODULE_ID=2`) #### Suggested interface for 3rd-party deposit method ```solidity function stakingModuleId() external view returns(uint256); function submitAndDeposit( // the name of the method can be changed by agreement uint256 blockNumber, bytes32 blockHash, bytes32 depositRoot, uint256 nonce, bytes calldata depositCalldata, IDepositSecurityModule.Signature[] calldata sortedGuardianSignatures ) external; ``` The `stakingModuleId()` value must be passed to call [`DSM.depositBufferedEther(...)`](https://docs.lido.fi/contracts/deposit-security-module#depositbufferedether) #### Suggested flow and checks inside the method (to be executed in a single tx) - check that `lido_buffered_eth >= lido_withdrawal_demand_eth` - calculate total depositable ETH as `lido_buffered_eth + vault_avail_eth - lido_withdrawal_demand_eth` - check depositable amount of ETH that could be deposited to the module - submit depositable amount of ETH to lido getting wstETH minted in return - call DSM deposit method (passing through guardian messages) ## Deposit mechanism Now let's describe the current logic of the depositor bot and the proposed changes. #### Tl;dr In brief, the following changes are made to the bot logic: - when iterating over Lido staking modules (Curated and SimpleDVT modules as of now), a condition is added that if the module `id` matches the `stakingModuleId()` value from the 3rd-party contract (e.g., contract behind [Distributed Validator Vault](https://research.lido.fi/t/discussion-the-decentralized-validator-vault/7729)), then in addition to the Lido buffer, the bot will take the `balanceOf` ether of the external vault holding deposited ether - if the total amount of available ether results in increse of the number of the to be deposited keys, and the externally available new ether on the vault wouldn't be used to fulfill the Lido withdrawal queue, then the vault-related deposit method is called, otherwise vanila DSM deposit is used. #### Current Lido off-chain deposit algorithm: ``` 1. Every new block Depositor bot wakes up 2. Get modules list from Staking Router 3. Checks the status of each module and prepares a ordering by smallest stake list of modules to deposit 4. Iterates over every module from the list 4.1. Gathers guardian messages for this module 4.2. Checks if there is enough ETH in the buffer and gas price is good for deposit taking into account the withdrawal demand 4.3. If so, calls the `depositBufferedEther` methond on DSM contract ``` #### Deposit off-chain algorithm using Distributed Validator Vault (DVV) contract: ``` 1. With every new block the Depositor bot wakes up 2. Gets modules list from Staking Router 3. Checks the status of each module and prepares a ordering by smallest stake list of modules to deposit 4. Iterates over every module from the list 4.1. Gathers guardian messages for this module 4.2. Compares the ID of the current module with the value of `stakingModuleId()` via the external contract 4.3. If ID matches 4.3.1 Checks if there is enough ETH in the buffer and gas price is good for deposit taking into account the withdrawal demand (calling `WQ.unfinalizedStETH()`), 4.3.2 Takes into account the amount of ETH on the DVV contract, which will potentially increase the buffer at the time of calling the `submit` method just before calling `depositBufferedEther` 4.3.3 Calls `submitAndDeposit` method of the 3rd-party DVV contract 4.4. If ID DOESN'T match 4.4.1 The previous logic is used: checks if there is enough ETH in the buffer and gas price is good for deposit taking into account the withdrawal demand 4.4.2 If able to deposit, calls the `depositBufferedEther` methond on DSM contract ``` ## Off-chain implementation The above-described approach to modifying the depositor bot can be implemented by any third party. However, to minimize resources and time spent, it would be logical for the modification and maintenance of the offchain bot to be carried out by Lido contributors. ## Security considerations The proposed approach has the following limitations and risks: - This method of direct-like deposits will only work for the module with the smallest stake in the protocol. Appending a new staking module (CSM) would result in altering stake distribution (see Deposit algorithm, step 3) - Deposits may be stuck indefinitely if there is a large withdrawal queue in the protocol. This means the external vault participants will bear opportunity costs for idling ether till the moment of deposit or withdrawing from the external vault - Making deposits in this way will increase transaction costs for depositor bot's operator. - The DSM contract address may change in the future, requiring monitoring and corresponding changes in third-party contracts

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully