Beanstalk icon indicating copy to clipboard operation
Beanstalk copied to clipboard

BIP-X: BDV Decrease

Open nickkatsios opened this issue 1 year ago • 0 comments

Summary

Implemented a new Convert type that allows any user to decrease a Deposit’s BDV if the Recorded BDV (the BDV stored on-chain with the Deposit) is greater than the Current BDV (the number of tokens in the Deposit * the current BDV of that token).

Problem:

Currently, the Recorded BDV of a given Deposit is asynchronous with its Current BDV. For example, if a user Deposits BEANETH into the Silo and the USD price of ETH falls significantly (and thus the BDV of BEANETH decreases), the Recorded BDV does not decrease, i.e., the user “locked in” the greater BDV at the time of Deposit. In practice, this may mean Beanstalk is over crediting BDV to Deposits relative to their value to the system.

Beanstalk only supports Convert types that do not decrease the BDV of the Deposit.

Solution

  • Implemented a new Convert type ANTI_LAMBDA_LAMBDA , callable by anyone, that Converts on behalf of a user.
  • Added an additional parameter account in LibConvert.convert(…) , corresponding to the account to decrease the deposit of.
  • Created a new decoder antiLambdaConvert(bytes memory self) function that additionally decodes the account parameter.
  • Replaced msg.sender in ConvertFacet .convert() ,. _withdrawTokens() , . _depositTokensForConvert() functions and all needed places with account.
  • Challenged the new functionallity with tests in test/Convert.test.js
  • Added mock bdv selectors in MockSiloFacet to artificially manipulate the bdv of a deposit in tests.

nickkatsios avatar Dec 29 '23 08:12 nickkatsios