# sDF Design Document [TOC] --- ## Overview sDF is a token, similar functionality to [xSushi](https://docs.sushi.com/products/yield-farming/the-sushibar), that you receive in exchange of staking DF tokens. While holding sDF token, it will appreciate in value, as incomes from dForce eco-applictions such as lending, trading, POO, etc. The sDF token is always worth more than a regular DF token, the exchange rate will increase by a fix reward rate or periodic DF inject from profit distribution(directly inject to sDF contract to increase sDF exchange rate, therefor all sDF holders will benifit from it). ## Algorithm In this section, we will introduce basic algotithm and functions in detail. * ### Exchange Rate Exchange rate is the rate of total amount of `DF` and `sDF` $$ ExchangeRate = \frac {DF.UserDeposited + FixedRateReward + EcosystemProfit }{sDF.TotalSupply} $$ The reward consists of two parts: 1. #### fixed rate reward This is the $TotalUnexecutedReward$ distributed by `rewardRate` per block set by owner and the actual tokens are stored in a `RewardVault` contract, which can be executed when `sDF`'s `DF` balance is insufficient. $$ TotalUnexecutedReward = TotalDistributed - TotalExecuted $$ - $TotalDistributed$ is the sum of the reward of all phases. `setRewardRate` starts a new phase with a fixed reward rate. $$ TotalDistributed = \sum rewardRate_i \times BlockDelta_i $$ In implementation, a `startBlock` is used to indicate the start block of current phase, therefore $TotalDistributed$ looks like: ``` totalDistributed = totalDistributedSettled + rewardRate * (currentBlock - startBlock) ``` The `totalDistributedSettled` is the settled total distributed reward from the very beginning to current `startBlock`. Each `setRewardRate` triggers a settlement of the `totalDistributedSettled`, and set the `startBlock` to current one. - $TotalExecuted$ is the sum of the reward executed from `RewardVault`. It accumulates when user leaving with `DF` and the the current `DF` balance is insuffient. 2. #### ecosystem profit This is the profit from the dForce lending system, which will be swap into `DF` and directly transfer into the `sDF` contract from time to time. In implementation,the `ecosystem profit` is automatically included in `sDF`'s DF balance, so the `ExchangeRate` calculation looks like: ``` exchangeRate = (DF.balanceOf(address(this)) + fixedRateReward) / sDF.totalSupply ``` * ### Stake User deposits DF and get the wrapped sDF in return, the amount is based on the current `ExchangeRate`. $$ sDF = \frac {DF} {ExchangeRate} $$ * ### Unstake User can also burn their vDF to redeem DF back. $$ DF = {sDF} \times {ExchangeRate} $$ Since the `FixedRateReward` is stored in the `RewardVault` contract, there are chances that the remaining `DF` balance is insufficient to payback. In this case, a execution from `RewardVault` will be triggered.