Debt Tokens 是在借款时 mint,还款时 burn 的计息代币,代表代币持有者所欠的债务。debt tokens 有两种类型:

  • Stable debt tokens,代表对协议的债务,债务利率稳定
  • Variable debt tokens,代表对协议的债务,债务利率浮动

源码:https://github.com/aave/protocol-v2/tree/ice/mainnet-deployment-03-12-2020/contracts/protocol/tokenization

EIP20 Methods

尽管 debt tokens 以 ERC/EIP20 标准为蓝本,但他们是不可转让的。因此,它们没有实现任何与 transfer()allowance()相关的 ERC20/EIP20 函数。

balanceOf()将始终返回用户最新的累积债务。

totalSupply()将始终返回所有协议用户为特定类型(稳定与可变)债务代币累积的最新总债务。

Shared Methods

UNDERLYING_ASSET_ADDRESS()

function UNDERLYING_ASSET_ADDRESS()

返回 debt 代币的底层资产。

POOL()

function POOL()

返回 debt 代币的关联 LendingPool 的地址

approveDelegtation()

function approveDelegation(address delegatee, uint256 amount)

设置delegatee借用的特定 debt token 的 allowance 数额amount

用于信用委托

参数名称 类型 描述
delegatee address 接收 allowance 的用户
amount uint256 给予用户的 allowance 金额amount

bollowAllowance()

function borrowAllowance(address fromUser, address toUser)

返回fromUsertoUser提供的 borrow allowance。

用于信用委托

参数名称 类似 描述
fromUser address 提供 allowance 的用户
toUser address 接收 allowance 的用户

返回特定 debt token 的当前toUser限额。

Stable Debt Methods

getSupplyData()

function getSupplyData()

返回 debt token 的供应/存储数据。

返回值

类型 描述
uint256 principal supply:本金供应量
uint256 total supply:总供应量
uint256 average borrow rate:平均借款利率
uint40 timestamp for last supply update:上次供应量更新的时间戳
  • 本金供应量(principal supply):指的是借款人借入的原始 token 数量,也就是用户借款时的初始债务,不包括利息部分。
  • 总供应量(total supply):指的是所有债务代币(debt tokens)的总数量,包括本金加上随着时间累积的利息。这个数值反映了用户的总债务余额(本金 + 利息),即当前实际的债务总量。

getTotalSupplyAndAvgRate()

function getTotalSupplyAndAvgRate()

返回 token 的总供应量和平均稳定利率债务的利率。

返回值

类型 描述
uint256 total supply
uint256 平均稳定利率债务的利率

principalBalanceOf()

function prinipalBalanceOf()

返回用户user 的本金债务余额

getUserLastUpdated()

function getUserLastUpdated()

uint256形式返回协议中所有稳定利率债务的平均利率。

getUserStableRate()

function getUserStableRate()

uint256形式返回 user 的稳定利率债务的利率。

Variable Debt Methods

scaledBalanceOf()

function scaledBalanceOf(address user)

返回用户user的本金债务余额。

scaledTotalSupply()

function scaledTotalSupply()

返回浮动利率 debt tokens 的缩放总供应量。

计算方法:img

getScaledUserBalanceAndSupply()

function getScaledUserBalanceAndSupply(address user)

返回用户user的本金金额和本金总供应量。

返回值

类型 描述
uint256 用户本金金额
uint256 本金总供应量

IStableDebtToken

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;

/**
 * @title IStableDebtToken
 * @notice Defines the interface for the stable debt token
 * @dev It does not inherit from IERC20 to save in code size
 * @author Aave
 **/

interface IStableDebtToken {
  /**
   * @dev Emitted when new stable debt is minted
   * @param user The address of the user who triggered the minting
   * @param onBehalfOf The recipient of stable debt tokens
   * @param amount The amount minted
   * @param currentBalance The current balance of the user
   * @param balanceIncrease The increase in balance since the last action of the user
   * @param newRate The rate of the debt after the minting
   * @param avgStableRate The new average stable rate after the minting
   * @param newTotalSupply The new total supply of the stable debt token after the action
   **/
  event Mint(
    address indexed user,
    address indexed onBehalfOf,
    uint256 amount,
    uint256 currentBalance,
    uint256 balanceIncrease,
    uint256 newRate,
    uint256 avgStableRate,
    uint256 newTotalSupply
  );

  /**
   * @dev Emitted when new stable debt is burned
   * @param user The address of the user
   * @param amount The amount being burned
   * @param currentBalance The current balance of the user
   * @param balanceIncrease The the increase in balance since the last action of the user
   * @param avgStableRate The new average stable rate after the burning
   * @param newTotalSupply The new total supply of the stable debt token after the action
   **/
  event Burn(
    address indexed user,
    uint256 amount,
    uint256 currentBalance,
    uint256 balanceIncrease,
    uint256 avgStableRate,
    uint256 newTotalSupply
  );
  
  /**
   * @dev delegates borrowing power to a user on the specific debt token
   * @param delegatee the address receiving the delegated borrowing power
   * @param amount the maximum amount being delegated. Delegation will still
   * respect the liquidation constraints (even if delegated, a delegatee cannot
   * force a delegator HF to go below 1)
   **/
  function approveDelegation(address delegatee, uint256 amount) external;
  
  /**
   * @dev returns the borrow allowance of the user
   * @param fromUser The user to giving allowance
   * @param toUser The user to give allowance to
   * @return the current allowance of toUser
   **/
  function borrowAllowance(address fromUser, address toUser) external view returns (uint256);

  /**
   * @dev Mints debt token to the `onBehalfOf` address.
   * - The resulting rate is the weighted average between the rate of the new debt
   * and the rate of the previous debt
   * @param user The address receiving the borrowed underlying, being the delegatee in case
   * of credit delegate, or same as `onBehalfOf` otherwise
   * @param onBehalfOf The address receiving the debt tokens
   * @param amount The amount of debt tokens to mint
   * @param rate The rate of the debt being minted
   **/
  function mint(
    address user,
    address onBehalfOf,
    uint256 amount,
    uint256 rate
  ) external returns (bool);

  /**
   * @dev Burns debt of `user`
   * - The resulting rate is the weighted average between the rate of the new debt
   * and the rate of the previous debt
   * @param user The address of the user getting his debt burned
   * @param amount The amount of debt tokens getting burned
   **/
  function burn(address user, uint256 amount) external;

  /**
   * @dev Returns the average rate of all the stable rate loans.
   * @return The average stable rate
   **/
  function getAverageStableRate() external view returns (uint256);

  /**
   * @dev Returns the stable rate of the user debt
   * @return The stable rate of the user
   **/
  function getUserStableRate(address user) external view returns (uint256);

  /**
   * @dev Returns the timestamp of the last update of the user
   * @return The timestamp
   **/
  function getUserLastUpdated(address user) external view returns (uint40);

  /**
   * @dev Returns the principal, the total supply and the average stable rate
   **/
  function getSupplyData()
    external
    view
    returns (
      uint256,
      uint256,
      uint256,
      uint40
    );

  /**
   * @dev Returns the timestamp of the last update of the total supply
   * @return The timestamp
   **/
  function getTotalSupplyLastUpdated() external view returns (uint40);

  /**
   * @dev Returns the total supply and the average stable rate
   **/
  function getTotalSupplyAndAvgRate() external view returns (uint256, uint256);

  /**
   * @dev Returns the principal debt balance of the user
   * @return The debt balance of the user since the last burn/mint action
   **/
  function principalBalanceOf(address user) external view returns (uint256);
}

IVariableDebtToken

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;

import {IScaledBalanceToken} from './IScaledBalanceToken.sol';

/**
 * @title IVariableDebtToken
 * @author Aave
 * @notice Defines the basic interface for a variable debt token.
 **/
interface IVariableDebtToken is IScaledBalanceToken {
  /**
   * @dev Emitted after the mint action
   * @param from The address performing the mint
   * @param onBehalfOf The address of the user on which behalf minting has been performed
   * @param value The amount to be minted
   * @param index The last index of the reserve
   **/
  event Mint(address indexed from, address indexed onBehalfOf, uint256 value, uint256 index);

 
  /**
   * @dev delegates borrowing power to a user on the specific debt token
   * @param delegatee the address receiving the delegated borrowing power
   * @param amount the maximum amount being delegated. Delegation will still
   * respect the liquidation constraints (even if delegated, a delegatee cannot
   * force a delegator HF to go below 1)
   **/
  function approveDelegation(address delegatee, uint256 amount) external;
  
  /**
   * @dev returns the borrow allowance of the user
   * @param fromUser The user to giving allowance
   * @param toUser The user to give allowance to
   * @return the current allowance of toUser
   **/
  function borrowAllowance(address fromUser, address toUser) external view returns (uint256);

  /**
   * @dev Mints debt token to the `onBehalfOf` address
   * @param user The address receiving the borrowed underlying, being the delegatee in case
   * of credit delegate, or same as `onBehalfOf` otherwise
   * @param onBehalfOf The address receiving the debt tokens
   * @param amount The amount of debt being minted
   * @param index The variable debt index of the reserve
   * @return `true` if the the previous balance of the user is 0
   **/
  function mint(
    address user,
    address onBehalfOf,
    uint256 amount,
    uint256 index
  ) external returns (bool);

  /**
   * @dev Emitted when variable debt is burnt
   * @param user The user which debt has been burned
   * @param amount The amount of debt being burned
   * @param index The index of the user
   **/
  event Burn(address indexed user, uint256 amount, uint256 index);

  /**
   * @dev Burns user variable debt
   * @param user The user which debt is burnt
   * @param index The variable debt index of the reserve
   **/
  function burn(
    address user,
    uint256 amount,
    uint256 index
  ) external;
}