You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modify the cap reserves functionality in Multi Flow to have two separate caps:
A cap on the maximum change in exchange rate between any two tokens in the Pump
A cap on the maximum change in support of LP Tokens in a Well
This allows the Multi Flow Pump to independently control the maximum change in total tokens in a Well and the exchange rate between them.
Move all constants to Pump Data to allow customizability between Wells.
Motivation
When the BEAN:3CRV liquidity was migrated to BEAN:ETH, it took a significant time (~14 hours) for the Multi Flow capped reserves to catch up to the real balances (see EBIP-9). During this time, the ratio between the capped reserves did not change as they both increased by the max percent each Season. This introduced a problem where the exchange rates in Multi Flow Pump may not reflect the actual exchange rates in the pool. Multi Flow Pump needs a way to change the exchange rates even when the magnitude of the increase of reserves is capped.
Currently Multi Flow Pump's constants are stored in the Pump. However, different types of Wells (e.g., A Well with Stablecoins) may want to use different constants. Currently, this requires deploying different Pumps for each. By moving the constants to Pump Data, it will allow each Well to chose its own constants while using the same Pump.
where $\delta_{ij}$ is the maximum % increase in exchange rate of exchanging $j$ for $i$.
$\phi_+$, $\phi_-$ be the maximum % increase and decrease in k
$l$ be the timestamp that the Pump was last updated
$t$ be the current timestamp
$b$ be the block time in seconds
$w$ be the Well Data
$n$ be the number of tokens in the pool
Given Functions
calcLpTokenSupply - Gets the LP token supply given a list of reserves.
calcReserveAtRatioSwap - Calculates the $j$th reserve such that $\prod_{i | i != j}^n \frac{d x_j}{d x_i} = \prod_{i | i != j}^n \frac{r_j}{r_i}$ where $r$ is a list of input exchange ratios.
calcLPTokenUnderlying - Calculates the amount of each reserve token underlying a given amount of LP tokens.
calcRate - Calculates the exchange rate of exchange $j$ for $i$.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IWellFunction} from "src/interfaces/IWellFunction.sol";
/**
* @title IMultiFlowPumpWellFunction
* @dev A Well Function must implement IMultiFlowPumpWellFunction to be supported by
* the Multi Flow Pump.
*/
interface IMultiFlowPumpWellFunction is IWellFunction {
/**
* @notice Calculates the `j` reserve such that `π_{i | i != j} (d reserves_j / d reserves_i) = π_{i | i != j}(ratios_j / ratios_i)`.
* assumes that reserve_j is being swapped for other reserves in the Well.
* @dev used by Beanstalk to calculate the deltaB every Season
* @param reserves The reserves of the Well
* @param j The index of the reserve to solve for
* @param ratios The ratios of reserves to solve for
* @param data Well function data provided on every call
* @return reserve The resulting reserve at the jth index
*/
function calcReserveAtRatioSwap(
uint256[] calldata reserves,
uint256 j,
uint256[] calldata ratios,
bytes calldata data
) external view returns (uint256 reserve);
/**
* @notice Calculates the rate at which j can be exchanged for i.
* @param reserves The reserves of the Well
* @param i The index of the token for which the output is being calculated
* @param j The index of the token for which 1 token is being exchanged
* @param data Well function data provided on every call
* @return rate The rate at which j can be exchanged for i
*/
function calcRate(
uint256[] calldata reserves,
uint256 i,
uint256 j,
bytes calldata data
) external view returns (uint256 rate);
}
IBeanstalkWellFunction should now extend IMultiFlowPumpWellFunction
2. Implement IMultiFlowPump in ConstantProduct2
The only function that needs to be added is calcRate. calcRate should return the output of reserves[i] / reserves[j].
MultiFlowPump Modification:
1. Remove existing constants
LOG_MAX_INCREASE
LOG_MAX_DECREASE
ALPHA
2. Add new constants as Pump Data
Add constants:
ALPHA
MAX_LP_TOKENS_INCREASE
MAX_LP_TOKENS_DECREASE
MAX_PERCENT_PRICE_CHANGE
The text was updated successfully, but these errors were encountered:
RFC: Multi Flow v1.1.0
Author
Brendan Sanderson
Summary
Modify the cap reserves functionality in Multi Flow to have two separate caps:
This allows the Multi Flow Pump to independently control the maximum change in total tokens in a Well and the exchange rate between them.
Move all constants to Pump Data to allow customizability between Wells.
Motivation
When the BEAN:3CRV liquidity was migrated to BEAN:ETH, it took a significant time (~14 hours) for the Multi Flow capped reserves to catch up to the real balances (see EBIP-9). During this time, the ratio between the capped reserves did not change as they both increased by the max percent each Season. This introduced a problem where the exchange rates in Multi Flow Pump may not reflect the actual exchange rates in the pool. Multi Flow Pump needs a way to change the exchange rates even when the magnitude of the increase of reserves is capped.
Currently Multi Flow Pump's constants are stored in the Pump. However, different types of Wells (e.g., A Well with Stablecoins) may want to use different constants. Currently, this requires deploying different Pumps for each. By moving the constants to Pump Data, it will allow each Well to chose its own constants while using the same Pump.
Design Specification
Given Constants:
where$\delta_{ij}$ is the maximum % increase in exchange rate of exchanging $j$ for $i$ .
Given Functions
calcLpTokenSupply
- Gets the LP token supply given a list of reserves.calcReserveAtRatioSwap
- Calculates the $j$th reserve such thatcalcLPTokenUnderlying
- Calculates the amount of each reserve token underlying a given amount of LP tokens.calcRate
- Calculates the exchange rate of exchangeGiven Variables:
Solve For:
Step 1: Cap Change of Magnitude
Let:
Step 2: Cap Change of Rates
For each unique set of 2 tokens in the Well (order doesn’t matter):
Let$(i, j)$ be defined such that $x_{i,t}^{cap} > x_{j,t}^{cap}$
Let:
Technical Specification
Well Function Interface Augmentation:
1. Create a new interface
IMultiFlowPump.sol
IBeanstalkWellFunction
should now extendIMultiFlowPumpWellFunction
2. Implement
IMultiFlowPump
inConstantProduct2
The only function that needs to be added is
calcRate
.calcRate
should return the output ofreserves[i] / reserves[j]
.MultiFlowPump Modification:
1. Remove existing constants
LOG_MAX_INCREASE
LOG_MAX_DECREASE
ALPHA
2. Add new constants as Pump Data
ALPHA
MAX_LP_TOKENS_INCREASE
MAX_LP_TOKENS_DECREASE
MAX_PERCENT_PRICE_CHANGE
The text was updated successfully, but these errors were encountered: