FyToken

Introduction

An fyToken is an instantiation of a Hifi zero-coupon bond, with a specific configuration. It is pegged to a unique Erc20 collateral type, Erc20 underlying type and expiration time. The FyToken contract is itself an Erc20.

Gas Costs

Gas usage is not deterministic due to requisite calls to third-party Erc20 tokens. We provide the table below for guidance only:

Action

Typical Gas Cost

Borrow

<130K

Liquidate Borrow

<100K

Repay Borrow

<80K

Repay Borrow Behalf

<80K

Erc20 Functions

All Erc20 functions are implemented: allowance(), balanceOf(), decimals(), name(), symbol(), totalSupply(), approve(), transfer()and transferFrom().

Erc2612 Functions

All Erc2612 functions are implemented: permit(), nonces() and DOMAIN_SEPARATOR(). Erc2612 allows users to permit another account (or contract) to use their funds using a signed message. This enables gas-less transactions and single approval/transfer transactions.

Storage Properties

Balance Sheet

The address of the BalanceSheet contract, the global debt registry of Hifi.

Collateral

The Erc20 asset that backs the borrows of this fyToken.

Collateral Precision Scalar

The ratio between mantissa precision (1e18) and the collateral precision.

Expiration Time

Unix timestamp in seconds for when this token expires.

Fintroller

The unique Fintroller associated with this contract.

Redemption Pool

The unique Redemption Pool associated with this contract.

Underlying

The Erc20 underlying, or target, asset for this fyToken.

Underlying Precision Scalar

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

Constant Functions

Is Matured

Checks if the bond matured.

  • RETURN: true = bond matured, otherwise it didn't.

Solidity

Ethers.js

Non-Constant Functions

Borrow

Increases the debt of the caller and mints new fyToken. Emits a "Borrow" event.

  • borrowAmount: The amount of fyTokens to borrow and print into existence.

  • RETURN: true = success, otherwise it reverts.

Solidity

Ethers.js

Burn

Destroys burnAmount tokens from holder, reducing the token supply. Emits a "Burn" event.

  • holder: The account whose fyTokens to burn.

  • burnAmount: The amount of fyTokens to burn.

  • RETURN: true = success, otherwise it reverts.

We didn't write code snippets for this function because it is not meant to be called directly. Only the "RedemptionPool" contract is allowed to call "burn".

Liquidate Borrow

Repays the debt of the borrower and rewards the liquidator with a surplus of collateral. Emits a "LiquidateBorrow" event.

  • borrower: The account to liquidate.

  • repayAmount: The amount of fyTokens to repay.

  • RETURN: true = success, otherwise it reverts.

Solidity

Ethers.js

Mint

Prints new tokens into existence and assigns them to beneficiary, increasing the total supply. Emits a "Mint" event.

  • beneficiary: The borrower account for which to mint the tokens.

  • mintAmount: The amount of fyTokens to print into existence.

  • RETURN: true = success, otherwise it reverts.

We didn't write code snippets for this function because it is not meant to be called directly. Only the "RedemptionPool" contract is allowed to call "burn".

Repay Borrow

Deletes the borrower account's debt from the registry and take the fyTokens out of circulation. Emits a "RepayBorrow" event.

  • repayAmount : The amount of fyTokens to repay.

  • RETURN

    • true = success, otherwise it reverts.

Solidity

Ethers.js

Repay Borrow Behalf

Clears the borrower account's debt from the registry and take the fyTokens out of circulation. Emits a "RepayBorrow" event.

  • borrower: The borrower account for which to repay the borrow.

  • repayAmount: The amount of fyTokens to repay.

  • RETURN: true = success, otherwise it reverts.

Solidity

Ethers.js

Set Fintroller

Updates the Fintroller contract's address saved in storage. Emits a "SetFintroller" event.

  • newFintroller: The address of the new Fintroller contract.

  • RETURN: true = success, otherwise it reverts.

We didn't write code snippets for this function because it is not meant to be called by end users. Only the protocol admin is allowed to call "setFintroller".

Last updated

Was this helpful?