burn debt tokens

Overview

Previously, we established how much debt user was inclined repay and assigned its value to paybackAmount. Now we are going to burn the corresponding debt tokens to reflect a repayment in debt.

Burn

Depending on which kind of debt the user has, stable or variable, the burn function will be called on the corresponding debt token contract.

Burn stableDebtToken

  • See StableDebtToken: burn

Burn variableDebtToken

  • burn calls _burnScaled on VariableDebtToken.sol.

  • _burnScaled scales the burn amount against variableBorrowIndex and calls _burn passing the amountScaled.

  • _burn is defined on MintableIncentivizedERC20.sol:

    • reduces total supply

    • reduces user's balance

_burnScaled

  • scale burn amount against variableBorrowIndex

  • balanceIncrease: update user's variable debt balance to bring it in-line with latest index

  • additionalData contains the index at which the balance was last updated.

    • this is referenced to calculated balanceIncrease, then subsequently updated

  • call _burn, passing scaled amount

  • if balanceIncrease > amount :

    • interest accrued outweighs the burn amount

    • emit mint and transfer

  • Else amount > balanceIncrease :

    • burn amount outweighs interest accrued

    • emit burn and transfer

Note: InbalanceIncrease > amount, tokens are not actually minted. amountToMint is simply a representation of the remaining interest accrued, less the nominal burn amount.

Essentially, each unit of scaled token represents itself and the interest it has accrued as dictated by the index. Therefore, to account for the interest, the nominal amount is divided by the index to obtain amountScaled.

  • Index here refers to variableBorrowIndex

Example

Assume 100 DAI to be burnt:

  • amount = 100 DAI

  • variableBorrowIndex = 1.1

  • amountScaled = 100 / 1.1 = 90.90

With index at 1.1, each token has an interest premium of 10%. So 100 debtTokens is actually worth 110 DAI.

Therefore an estimate of 90.90 debtTokens account for 100 DAI worth of debt.

Note: the actual number of tokens being burnt is amountScaled. This is because debt tokens accrue interest in the same way that ATokens do; against an index.

_burn

  • reduce total supply by burn amount

  • get user's balance decrement it by burn amount

  • apply incentives if defined (.handleAction)

Last updated