📈The Euler Model
This page is for anyone interested in understanding how the Euler model can be implemented to efficiently distribute rewards paid in ETH to millions of users with negligble gas costs
Last updated
This page is for anyone interested in understanding how the Euler model can be implemented to efficiently distribute rewards paid in ETH to millions of users with negligble gas costs
Last updated
We explain the Euler model using the Ethervista LP pool as an example, but the model can be applied to any contract that implements staking or locking of assets and distributes ETH rewards based on the user's share of those assets
The Ethervista pair smart contract maintains a sequence of ascending numbers known as Euler amounts. These values are updated each time native ETH is transferred to the pair contract. Each Euler amount is determined by adding the previous Euler amount to the ratio of the fee to the current total supply of liquidity provider tokens (LP). The initial Euler amount is set to zero.
Mathematically, this update can be represented as:
With the corresponding sequence of rising numbers:
This sequence is particularly of interest to liquidity providers. Each provider is represented by a struct which stores the LP holdings of each user and a variable called euler0
which is suggestively named after the Euler amounts in our sequence.
This uint256
number represents the latest Euler amount in our sequence at the time the user adds liquidity, in which case we would have
Suppose the user decides to claim rewards a thousand swaps later. In that moment, the latest Euler amount is
The exact amount of rewards that this provider accumulated during these thousand swaps is:
This approach operates under the assumption that the LP balance remains constant throughout the period. Therefore, whenever a provider takes any action, such as adding/removing/transferring liquidity, the variable euler0
will be refreshed to reflect the latest Euler amount in our sequence. This measure prevents a liquidity provider from manipulating their own share of rewards.
As such, it is advisable for a liquidity provider to always claim rewards before adjusting their LP balance.
The Ethervista DEX uses the Euler model for:
Rewarding liquidity providers
Hardstaking: Users can stake their tokens and receive rewards paid in ETH from the protocol fees every transaction
Hardlocking: Creators/users can lock their LP tokens and still benefit from rewards, something which was not possible in other AMM standards
Three key components are needed to implement the Euler model in a smart contract
An updateStaker
function which update the user baseline Euler0 when there is a balance change (i.e a user stakes/un-stakes/transfers) or a reward claim
A updateEuler
function which updates the Euler-array when ETH is received by the smart contract
A payable function which calls updateEuler when receiving ETH
A viewShare
function which returns the reward share of each user