Raft.fi code analysis
Opened this issue · 1 comments
dapp-whisperer commented
Liquity fork stablecoin, using LSDs as collateral. The code is out!
https://raft.fi/
https://github.com/raft-fi/contracts
Key features to examine:
- Their simplified price feed contract that still has the two oracle setup
- One-step leverage
- Flash loans
- How rewards / interest is processed
rayeaster commented
Following are some quick takeaways for Raft codebase:
PriceFeed
in Raft usestETH/USD
in ChainLink primarily and remove theStatus
(also the state machine) design to use simple booleans(isBrokenOrFrozen
&priceChangeAboveMax
) to denote the possible scenarios for primary(ChainLink) and secondary(Tellor) feeds. Basically, thefetchPrice()
logic in RaftPriceFeed
covers thecase 1
in eBTC with a straight-forward idea to use the least changed one if prices from both feeds don't match closelyOneStepLeverage
looks a bit like (though lacks clearly-defined operationstructs
) the combination ofBorrowerOperations
andLeverageMacroBase#doOperation()
in ebtc with anexternal
entry functionmanageLeveragedPosition()
but borrows(flashloan) ONLY debt token(its R stablecoin) for various position operations like adding collateral or repaying debt. In the meantime, Raft take some efforts to write specific codes for many popular DEX/aggregator integrations to facilitate the swap between collateral and debt though only one AMM could be set for each deployedOneStepLeverage
: Balancer/1inch/ParaswapRToken
inherits directly fromOpenZeppelin's ERC20FlashMint
with a customizedmaxFlashLoan()
using a hardcoded upper limit oftotalSupply() / 10
and its helper contractFlashMintLiquidator
utilize the flashmint feature directly for liquidation. Another out-of-the-box toolFlashLoanLiquidator
utilizeAave3
to flashloan collateral (added to position to mint R token for repayment during callback) for liquidation- PositionManager defines a
borrow rate
with hard upper limit5%
. The borrowing fee is calculated(not compound interest) and sent to fee recipient directly upon debt creation. Since Raft usewstETH
as collateral and itsPositionManager
doesn't support rebasing token likestETH
yet, there is no LSD staking-reward split feature at this moment in Raft.