Beanstalk
Beanstalk copied to clipboard
BIP-X: Soil Issuance Update
Summary
When $\Delta B_{\overline{t-1}} < 0$, change Soil issued at gm
to be the minimum of (1) $-\Delta B$ calculated using the instantaneous reserves from Multi Flow and (2) $-\Delta B_{\overline{t-1}}$.
Problem
Beanstalk occasionally overissues Soil at gm
because Soil issuance below peg is solely based on $-\Delta B_{\overline{t-1}}$.
Beanstalk can read inter-block MEV manipulation resistant instantaneous reserves for whitelisted Well LP tokens via Multi Flow, but does not yet use these values to determine Soil issuance below peg.
Context
Consider an example where Beanstalk is at -300k deltaB for the first 58 minutes of a Season. At the 58th minute, i.e., 10 blocks before the next gm
call, a Farmer buys and Sows 200k Beans, bringing the current deltaB to -100k.
Assuming no other trades in the final 2 minutes of the Season, the Soil issued at gm
will be slightly less than 300k, despite Beanstalk only needing 100k Beans to be bought to return to peg. Before Multi Flow, this was necessary for sufficient manipulation resistance.
Solution
- Introduced a new
setSoilBelowPeg()
function that queries the instantaneous deltaB from the bean:eth well, compares it with the precalculated twa deltaB from the start of the season and sets the soil to be the minimum of the inverse of the 2 . - Implemented
instantaneousDeltaB()
inLibWellMinting.sol
that calculates the deltaB using the instantaneous reserves from a given well. - Added tests to challenge the new deltaB calculation in
WellMinting.test.js
. - Added tests to challenge the soil update in
Sun.test.js
.