case video fallback
Case Study

Lido: decentralized
staking platform

Mad Devs assisted Lido - a liquid staking solution - to improve their
product and simplify and secure staking for your digital assets.

The Lido is a platform that solves the issues with Ethereum staking by facilitating participation with any amount of ETH. It is supported by a consortium of industry leaders.

Liquid Ethereum Staging

Lido lets you stake ETH to earn daily rewards. Stake any amount and grow your balance with DeFi.

Total staking assets

$6,7B

Stakers

+143K

Total rewards paid

$167M

Visit Lido website to see actual information

Lido’s goal is to let all users stake assets, use them as collateral for other projects and get daily rewards. No minimum amount of tokens is required to stake. In the DeFi ecosystem, clients' assets can be used for multiple purposes, such as yield farming, lending, and more.

When the users stake ETH on the Ethereum beacon chain, they will receive a token called stETH, which represents ETH on the chain on a 1:1 basis. This bridge allows people to earn rewards from both the old and new ETH blockchains.

Lido works with Ethereum, Solana, Kusama, Polkadot, and Polygon networks. As of August 2022, these are supported blockchains.

Despite the competition from other platforms, such as Stkr and Rocketpool, the team at Lido has maintained its dominant position.

Eth liquid staking balances (time series)

The graphic is current as of July 2022. Visit the website for complete up-to-date statistics

Moreover, Andreessen Horowitz , a private American venture capital firm, invested in Lido and described it as “an effective, decentralized staking platform. It offers one of the easiest ways to stake ETH and other PoS assets today while striving for decentralization through the DAO’s governance. Lido democratizes staking.”

The story behind the project

This project came about as a result of a perfect match between the clients' desires and Mad Devs' capabilities. The client lacked the time and resources necessary to accelerate the rollout of new integrations, such as conducting research, comparing two codebases, and developing a plan for task scoping.

  • Blockchain is not a typical technological advance. You cannot immediately turn around a server and production.

    Blockchain is not a typical technological advance. You cannot immediately turn around a server and production.

  • Lido has a request; Mad Devs has capacity. That was an ideal way to initiate collaboration.

    Lido has a request; Mad Devs has capacity. That was an ideal way to initiate collaboration.

  • Our collaboration is composed of two phases.

    Our collaboration is composed of two phases.

Project goals and how we resolved them

Icon

Goal 1:

Allow customers to receive an additional reward in addition to the stacking rewards if they contribute tokens to the liquidity pool.

Icon

Goal 2:

The bridge that was in use at the time was sunsetting, so another bridge was required to keep the platform operational.

Icon anchor

Before proceeding, we advise that you review the terminology presented here.

First Challenge: Integration with the liquidity pool

Liquidity pool - a contract that stores tokenized liquidity attracted from users, in tokens. In exchange, users receive liquidity pool tokens and rewards.

After conducting analysis and research, we determined that 1inch has a an integrated rewards manager to which we could connect the rewards contract. But we had to adapt it.

The user provides Ether via stake.lido.fi to the Ethereum pool, receiving an equivalent amount of stETH tokens in return.

Project visibility
Stake Ether

The user buys some amount of DAI on stocks or from exchangers (Metamask allows to do this). Liquidity provider selects liquidity pool for 1inch . In our case, it will be a pair of DAI-stETH.

Project visibility
1inch

It then gives access to its stETH tokens. A liquid staked Ether (stETH) contact is made through DelegateProxy. This allows the liquidity pool contract (Mooniswap, it is unique for each pair, it will be new) to use the entire balance of stETH tokens belonging to the user.

Project visibility
1inch

The user then transfers tokens into the liquidity pool. Mooniswap is the deposit method of the liquidity pool contract. This operation transfers stETH tokens from the user's balance to the liquidity pool contract's balance. In exchange, the liquidity pool transfers LP tokens to the user. The LP tokens contract for each liquidity pool is unique.

The user then loads his LP tokens into the farming.

The user can withdraw his reward for farming stETH and DAI, withdraw all uploaded tokens (Withdraw), or exit farming entirely (Exit).

Project visibility
1inch

In Withdraw method, all tokens loaded into the pool are transferred back to the user.
During co-investment, when users request a reward, LDO and 1INCH tokens are also transferred to them.

github logo

The process of integration with liquidity pool

Github icon View on Github

Here’s visual flow:

Also, 100% test coverage was a prerequisite, as well as a test that would pass the entire Smart Contract procedure.

checkbox-circle logo

Testing process and how we solved it

Github icon View on Github

Second challenge: Integration with cross-chain bridge

The bETH token is a derisively-native asset used in the Anchor Protocol. Its integration was carried out through the Shuttle bridge , which transfers it between Terra and Ethereum. In order to preserve its resilience, a decision was made to migrate to Wormhole bridge.

The migration plan is:

  1. Disable Lido bETH UI & Shuttle bETH bridging UI.
  2. Disable AnchorVault smart contract, to prevent users from minting and bridging bETH while the migration is in progress.
  3. Discontinue bETH support on Shuttle.
  4. Migrate the Ethereum bETH liquidity from the Shuttle bridge vault through the Wormhole to bETH-webETH converter contract on Terra.
  5. Enable AnchorVault smart contract setting bridge connector delegate to BridgeConnectorWormhole.
  6. Enable the updated Lido bETH UI.
wormhole logo

The migration to Wormhole bridge

Github icon View on Github

Important insight to remember:

Mad Devs successfully completed the migration, passing all the tests and audits. Nonetheless, the work of both the Lido team and the Mad Devs team uncovered an intriguing pattern that deserves everyone's attention.

The smart contract work with the frontend, which will also pack bytes. For the old bridge, it was packed from right to left, but for us, it should be packed from left to right. The chain tests revealed that everything was working in order. However, when the users arrived, the most crucial detail was uncovered. If the users did not reload the page during the migration, they became stuck during the operation.

Total stuck in the bridge - 450 ETH (1 million 200 thousand at that rate by then).

Moral: Not only is it important to make tests "green," but also to evaluate the entire system - the user should know if the Smart contract has been modified (it is vital to reloading the page).

Project planning and management

To perform client tasks, the most qualified programmers were recruited. The project's first phase involved 4 people, while the second phase involved 3 developers.

Work on both objectives occurred in several phases:

  • [object Object]

    Research and Development

  • [object Object]

    Checklists and collaborative markdown files filling

  • [object Object]

    Implementation

  • [object Object]

    Integration tests

  • [object Object]

    Control tests

  • [object Object]

    Audits*

  • [object Object]

    Review of work

*IMPORTANT: Lido ensures that external companies always audit smart contracts because it is a matter of security and the right functionality.

Results

After collaborating with the Lido team, both goals were accomplished and are now operating efficiently.

The second phase of the work was completed in January 2022. Since February, the Lido service has grown and received positive feedback:

Project visibility
TVL Rankings

Source: DeFI

Our joint work helped to strengthen and improve the service, which had a positive impact on the overall statistics of its work:

Technology stack

  • Brownie

    Brownie

  • Python

    Python

  • PyTest

    PyTest

  • Ganache

    Ganache

  • Solidity

    Solidity

  • Infura

    Infura

  • 1INCH

    1INCH

  • Vyper

    Vyper

  • Lido protocol

    Lido protocol

  • Wormhole

    Wormhole

  • Anchor protocol

    Anchor protocol

  • Terra chain

    Terra chain

Meet the team

  • Pavel Zverev

    Pavel Zverev

    Backend Tech Lead

  • Emir Sabyrkulov

    Emir Sabyrkulov

    Delivery Manager

  • Gleb Ershov

    Gleb Ershov

    Backend Developer

  • Pavel Isayenko

    Pavel Isayenko

    Backend Developer

Terminology

  • Ethereum staking, ether stacking is the act of depositing 32 ETH to activate validator software. The user uploads 32 ethers and becomes a validator. If he does not have 32 ethers or does not want to be a validator, he can join the staking pool.

  • Staking pool is a tool that becomes an ether validator and stacker, but uses the ether raised from users to do so, distributing the income from stacking among them and taking a small commission.

  • stETH is the token that Lido's stacking pool users get when they stack their ether.

  • DAI is a token, a stable coin, pegged to the U.S. dollar.

  • Liquidity pool is a contract that stores liquidity raised from users, in tokens. Users are rewarded for this. Example: Curve. 1inch is an aggregator of liquidity pools.

  • Liquidity provider (LP) is a user who deposits the liquidity to the liquidity pool and gets rewarded for that.

  • LP token is a token that LP receives as confirmation of its share in the liquidity pool.

  • LDO is an Ethereum token granting governance rights in the Lido DAO. This token can be bought through any exchanger or (in our case) it is received by liquidity providers through a reward manager.

  • Incentivization is additional reward of LP for some specific pool in some specific tokens. In our case, we want to reward LP of stETH - DAI pool with LDO and INCH.

  • Co-incentivization is incentivization from two sides with two tokens. In our case, Lido and 1inch co-incentivize LP of stETH - DAI pool with LDO and INCH.