Skip to main content

HToken

Zero-coupon bond that tracks an ERC-20 underlying asset.

Constant Functions

balanceSheet

function balanceSheet() external returns (contract IBalanceSheetV2)

Returns the BalanceSheet contract this HToken is connected to.

getDepositorBalance

function getDepositorBalance(
address depositor
) external returns (uint256 amount)

Returns the balance of the given depositor.

Parameters

NameType
depositoraddress

fintroller

function fintroller() external returns (contract IFintroller)

Returns the Fintroller contract this HToken is connected to.

isMatured

function isMatured() external returns (bool)

Checks if the bond matured.

Return Values

NameTypeDescription
[0]boolbool true = bond matured, otherwise it didn't.

maturity

function maturity() external returns (uint256)

Unix timestamp in seconds for when this HToken matures.

totalUnderlyingReserve

function totalUnderlyingReserve() external returns (uint256)

The amount of underlying redeemable after maturation.

underlying

function underlying() external returns (contract IErc20)

The Erc20 underlying asset for this HToken.

underlyingPrecisionScalar

function underlyingPrecisionScalar() external returns (uint256)

The ratio between normalized precision (1e18) and the underlying precision.

Non-Constant Functions

burn

function burn(
address holder,
uint256 burnAmount
) external

Destroys burnAmount tokens from holder, reducing the token supply.

Emits a {Burn} and a {Transfer} event.

Requirements:

  • Can only be called by the BalanceSheet contract.

Parameters

NameTypeDescription
holderaddressThe account whose hTokens to burn.
burnAmountuint256The amount of hTokens to burn.

depositUnderlying

function depositUnderlying(
uint256 underlyingAmount
) external

Deposits underlying in exchange for an equivalent amount of hTokens.

Emits a {DepositUnderlying} event.

Requirements:

  • The Fintroller must allow this action to be performed.
  • The underlying amount to deposit cannot be zero.
  • The caller must have allowed this contract to spend underlyingAmount tokens.

Parameters

NameTypeDescription
underlyingAmountuint256The amount of underlying to deposit.

mint

function mint(
address beneficiary,
uint256 mintAmount
) external

Prints new tokens into existence and assigns them to beneficiary, increasing the total supply.

Emits a {Mint} and a {Transfer} event.

Requirements:

  • Can only be called by the BalanceSheet contract.

Parameters

NameTypeDescription
beneficiaryaddressThe account to mint the hTokens for.
mintAmountuint256The amount of hTokens to print into existence.

redeem

function redeem(
uint256 underlyingAmount
) external

Pays the token holder the face value after maturation.

Emits a {Redeem} event.

Requirements:

  • Can only be called after maturation.
  • The amount of underlying to redeem cannot be zero.
  • There must be enough liquidity in the contract.

Parameters

NameTypeDescription
underlyingAmountuint256The amount of underlying to redeem.

_setBalanceSheet

function _setBalanceSheet(
contract IBalanceSheetV2 newBalanceSheet
) external

Updates the BalanceSheet contract this HToken is connected to.

Throws a {SetBalanceSheet} event.

Requirements:

  • The caller must be the owner.

Parameters

NameTypeDescription
newBalanceSheetcontract IBalanceSheetV2The address of the new BalanceSheet contract.

withdrawUnderlying

function withdrawUnderlying(
uint256 underlyingAmount
) external

Withdraws underlying in exchange for hTokens.

Emits a {WithdrawUnderlying} event.

Requirements:

  • The underlying amount to withdraw cannot be zero.
  • Can only be called before maturation.

Parameters

NameTypeDescription
underlyingAmountuint256The amount of underlying to withdraw.

Events

Burn

event Burn(
address holder,
uint256 burnAmount
)

Emitted when tokens are burnt.

Parameters

NameTypeDescription
holderaddressThe address of the holder.
burnAmountuint256The amount of burnt tokens.

DepositUnderlying

event DepositUnderlying(
address depositor,
uint256 depositUnderlyingAmount,
uint256 hTokenAmount
)

Emitted when underlying is deposited in exchange for an equivalent amount of hTokens.

Parameters

NameTypeDescription
depositoraddressThe address of the depositor.
depositUnderlyingAmountuint256The amount of deposited underlying.
hTokenAmountuint256The amount of minted hTokens.

Mint

event Mint(
address beneficiary,
uint256 mintAmount
)

Emitted when tokens are minted.

Parameters

NameTypeDescription
beneficiaryaddressThe address of the holder.
mintAmountuint256The amount of minted tokens.

Redeem

event Redeem(
address account,
uint256 underlyingAmount,
uint256 hTokenAmount
)

Emitted when underlying is redeemed.

Parameters

NameTypeDescription
accountaddressThe account redeeming the underlying.
underlyingAmountuint256The amount of redeemed underlying.
hTokenAmountuint256The amount of provided hTokens.

SetBalanceSheet

event SetBalanceSheet(
address owner,
contract IBalanceSheetV2 oldBalanceSheet,
contract IBalanceSheetV2 newBalanceSheet
)

Emitted when the BalanceSheet is set.

Parameters

NameTypeDescription
owneraddressThe address of the owner.
oldBalanceSheetcontract IBalanceSheetV2The address of the old BalanceSheet.
newBalanceSheetcontract IBalanceSheetV2The address of the new BalanceSheet.

WithdrawUnderlying

event WithdrawUnderlying(
address depositor,
uint256 underlyingAmount,
uint256 hTokenAmount
)

Emitted when a depositor withdraws previously deposited underlying.

Parameters

NameTypeDescription
depositoraddressThe address of the depositor.
underlyingAmountuint256The amount of withdrawn underlying.
hTokenAmountuint256The amount of minted hTokens.

Custom Errors

HToken__BondMatured

error HToken__BondMatured(uint256 now, uint256 maturity)

Emitted when the bond matured.

HToken__BondNotMatured

error HToken__BondNotMatured(uint256 now, uint256 maturity)

Emitted when the bond did not mature.

HToken__BurnNotAuthorized

error HToken__BurnNotAuthorized(address caller)

Emitted when burning hTokens and the caller is not the BalanceSheet contract.

HToken__DepositUnderlyingNotAllowed

error HToken__DepositUnderlyingNotAllowed()

Emitted when underlying deposits are not allowed by the Fintroller contract.

HToken__DepositUnderlyingZero

error HToken__DepositUnderlyingZero()

Emitted when depositing a zero amount of underlying.

HToken__MaturityPassed

error HToken__MaturityPassed(uint256 now, uint256 maturity)

Emitted when the maturity is in the past.

HToken__MintNotAuthorized

error HToken__MintNotAuthorized(address caller)

Emitted when minting hTokens and the caller is not the BalanceSheet contract.

HToken__RedeemInsufficientLiquidity

error HToken__RedeemInsufficientLiquidity(uint256 underlyingAmount, uint256 totalUnderlyingReserve)

Emitted when redeeming more underlying that there is in the reserve.

HToken__RedeemZero

error HToken__RedeemZero()

Emitted when redeeming a zero amount of underlying.

HToken__UnderlyingDecimalsOverflow

error HToken__UnderlyingDecimalsOverflow(uint256 decimals)

Emitted when constructing the contract and the underlying has more than 18 decimals.

HToken__UnderlyingDecimalsZero

error HToken__UnderlyingDecimalsZero()

Emitted when constructing the contract and the underlying has zero decimals.

HToken__WithdrawUnderlyingUnderflow

error HToken__WithdrawUnderlyingUnderflow(address depositor, uint256 availableAmount, uint256 underlyingAmount)

Emitted when withdrawing more underlying than there is available.

HToken__WithdrawUnderlyingZero

error HToken__WithdrawUnderlyingZero()

Emitted when withdrawing a zero amount of underlying.