IFToken
minDeposit
function minDeposit() external view returns (uint256)
returns minimum amount required for deposit (rounded up)
getData
function getData() external view returns (contract IFluidLiquidity liquidity_, contract IFluidLendingFactory lendingFactory_, contract IFluidLendingRewardsRateModel lendingRewardsRateModel_, contract IAllowanceTransfer permit2_, address rebalancer_, bool rewardsActive_, uint256 liquidityBalance_, uint256 liquidityExchangePrice_, uint256 tokenExchangePrice_)
returns config, rewards and exchange prices data in a single view method.
Return Values
Name | Type | Description |
---|---|---|
liquidity_ | contract IFluidLiquidity | address of the Liquidity contract. |
lendingFactory_ | contract IFluidLendingFactory | address of the Lending factory contract. |
lendingRewardsRateModel_ | contract IFluidLendingRewardsRateModel | address of the rewards rate model contract. changeable by LendingFactory auths. |
permit2_ | contract IAllowanceTransfer | address of the Permit2 contract used for deposits / mint with signature |
rebalancer_ | address | address of the rebalancer allowed to execute rebalance() |
rewardsActive_ | bool | true if rewards are currently active |
liquidityBalance_ | uint256 | current Liquidity supply balance of address(this) for the underyling asset |
liquidityExchangePrice_ | uint256 | (updated) exchange price for the underlying assset in the liquidity protocol (without rewards) |
tokenExchangePrice_ | uint256 | (updated) exchange price between fToken and the underlying assset (with rewards) |
liquidityCallback
function liquidityCallback(address token_, uint256 amount_, bytes data_) external
transfers amount_
of token_
to liquidity. Only callable by liquidity contract.
this callback is used to optimize gas consumption (reducing necessary token transfers).
depositWithSignature
function depositWithSignature(uint256 assets_, address receiver_, uint256 minAmountOut_, struct IAllowanceTransfer.PermitSingle permit_, bytes signature_) external returns (uint256 shares_)
deposit assets_
amount with Permit2 signature for underlying asset approval.
reverts with fToken__MinAmountOut()
if minAmountOut_
of shares is not reached.
assets_
must at least be minDeposit()
amount; reverts otherwise.
Parameters
Name | Type | Description |
---|---|---|
assets_ | uint256 | amount of assets to deposit |
receiver_ | address | receiver of minted fToken shares |
minAmountOut_ | uint256 | minimum accepted amount of shares minted |
permit_ | struct IAllowanceTransfer.PermitSingle | Permit2 permit message |
signature_ | bytes | packed signature of signing the EIP712 hash of permit_ |
Return Values
Name | Type | Description |
---|---|---|
shares_ | uint256 | amount of minted shares |
mintWithSignature
function mintWithSignature(uint256 shares_, address receiver_, uint256 maxAssets_, struct IAllowanceTransfer.PermitSingle permit_, bytes signature_) external returns (uint256 assets_)
mint amount of shares_
with Permit2 signature for underlying asset approval.
Signature should approve a little bit more than expected assets amount (previewMint()
) to avoid reverts.
shares_
must at least be minMint()
amount; reverts otherwise.
Note there might be tiny inaccuracies between requested shares_
and actually received shares amount.
Recommended to use deposit()
over mint because it is more gas efficient and less likely to revert.
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | amount of shares to mint |
receiver_ | address | receiver of minted fToken shares |
maxAssets_ | uint256 | maximum accepted amount of assets used as input to mint shares_ |
permit_ | struct IAllowanceTransfer.PermitSingle | Permit2 permit message |
signature_ | bytes | packed signature of signing the EIP712 hash of permit_ |
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | deposited assets amount |
IFTokenAdmin
updateRewards
function updateRewards(contract IFluidLendingRewardsRateModel rewardsRateModel_) external
updates the rewards rate model contract. Only callable by LendingFactory auths.
Parameters
Name | Type | Description |
---|---|---|
rewardsRateModel_ | contract IFluidLendingRewardsRateModel | the new rewards rate model contract address. can be set to address(0) to set no rewards (to save gas) |
rebalance
function rebalance() external payable returns (uint256 assets_)
Balances out the difference between fToken supply at Liquidity vs totalAssets(). Deposits underlying from rebalancer address into Liquidity but doesn't mint any shares -> thus making deposit available as rewards. Only callable by rebalancer.
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | amount deposited to Liquidity |
updateRates
function updateRates() external returns (uint256 tokenExchangePrice_, uint256 liquidityExchangePrice_)
gets the liquidity exchange price of the underlying asset, calculates the updated exchange price (with reward rates) and writes those values to storage. Callable by anyone.
Return Values
Name | Type | Description |
---|---|---|
tokenExchangePrice_ | uint256 | exchange price of fToken share to underlying asset |
liquidityExchangePrice_ | uint256 | exchange price at Liquidity for the underlying asset |
rescueFunds
function rescueFunds(address token_) external
sends any potentially stuck funds to Liquidity contract. Only callable by LendingFactory auths.
updateRebalancer
function updateRebalancer(address rebalancer_) external
Updates the rebalancer address (ReserveContract). Only callable by LendingFactory auths.
fToken
fToken is a token that can be used to supply liquidity to the Fluid Liquidity pool and earn interest for doing so. The fToken is backed by the underlying balance and can be redeemed for the underlying token at any time. The interest is earned via Fluid Liquidity, e.g. because borrowers pay a borrow rate on it. In addition, fTokens may also have active rewards going on that count towards the earned yield for fToken holders.
The fToken implements the ERC20 and ERC4626 standard, which means it can be transferred, minted and burned. The fToken supports EIP-2612 permit approvals via signature. The fToken implements withdrawals via EIP-2612 permits and deposits with Permit2 or EIP-2612 (if underlying supports it) signatures. fTokens are not upgradeable. For view methods / accessing data, use the "LendingResolver" periphery contract.
constructor
constructor(contract IFluidLiquidity liquidity_, contract IFluidLendingFactory lendingFactory_, contract IERC20 asset_) public
Parameters
Name | Type | Description |
---|---|---|
liquidity_ | contract IFluidLiquidity | liquidity contract address |
lendingFactory_ | contract IFluidLendingFactory | lending factory contract address |
asset_ | contract IERC20 | underlying token address |
decimals
function decimals() public view virtual returns (uint8)
Returns the decimals places of the token.
liquidityCallback
function liquidityCallback(address token_, uint256 amount_, bytes data_) external virtual
transfers amount_
of token_
to liquidity. Only callable by liquidity contract.
this callback is used to optimize gas consumption (reducing necessary token transfers).
fTokenNativeUnderlying
Same as the {fToken} contract but with support for native token as underlying asset. Actual underlying asset is the wrapped native ERC20 version (e.g. WETH), which acts like any other fToken. But in addition the fTokenNativeUnderlying also has methods for doing all the same actions via the native token.
constructor
constructor(contract IFluidLiquidity liquidity_, contract IFluidLendingFactory lendingFactory_, contract IWETH9 weth_) public
Parameters
Name | Type | Description |
---|---|---|
liquidity_ | contract IFluidLiquidity | liquidity contract address |
lendingFactory_ | contract IFluidLendingFactory | lending factory contract address |
weth_ | contract IWETH9 | address of wrapped native token (e.g. WETH) |
liquidityCallback
function liquidityCallback(address, uint256, bytes) external virtual
transfers amount_
of token_
to liquidity. Only callable by liquidity contract.
this callback is used to optimize gas consumption (reducing necessary token transfers).
receive
receive() external payable
ErrorTypes
fToken__DepositInsignificant
| | fToken | |********__********
thrown when a deposit amount is too small to increase BigMath stored balance in Liquidity. precision of BigMath is 1e12, so if token holds 120_000_000_000 USDC, min amount to make a difference would be 0.1 USDC. i.e. user would send a very small deposit which mints no shares -> revert
uint256 internal constant fToken__DepositInsignificant = 20001;
fToken__MinAmountOut
thrown when minimum output amount is not reached, e.g. for minimum shares minted (deposit) or minimum assets received (redeem)
uint256 internal constant fToken__MinAmountOut = 20002;
fToken__MaxAmount
thrown when maximum amount is surpassed, e.g. for maximum shares burned (withdraw) or maximum assets input (mint)
uint256 internal constant fToken__MaxAmount = 20003;
fToken__InvalidParams
thrown when invalid params are sent to a method, e.g. zero address
uint256 internal constant fToken__InvalidParams = 20004;
fToken__Unauthorized
thrown when an unauthorized caller is trying to execute an auth-protected method
uint256 internal constant fToken__Unauthorized = 20005;
fToken__PermitFromOwnerCall
thrown when a with permit / signature method is called from msg.sender that is the owner. Should call the method without permit instead if msg.sender is the owner.
uint256 internal constant fToken__PermitFromOwnerCall = 20006;
fToken__Reentrancy
thrown when a reentrancy is detected.
uint256 internal constant fToken__Reentrancy = 20007;
fToken__ExchangePriceOverflow
thrown when _tokenExchangePrice overflows type(uint64).max
uint256 internal constant fToken__ExchangePriceOverflow = 20008;
fToken__NotRebalancer
thrown when msg.sender is not rebalancer
uint256 internal constant fToken__NotRebalancer = 20009;
fToken__NotNativeUnderlying
thrown when rebalance is called with msg.value > 0 for non NativeUnderlying fToken
uint256 internal constant fToken__NotNativeUnderlying = 20010;
fToken__LiquidityExchangePriceUnexpected
thrown when the received new liquidity exchange price is of unexpected value (< than the old one)
uint256 internal constant fToken__LiquidityExchangePriceUnexpected = 20011;
- IFToken
- IFTokenAdmin
- fToken
- fTokenNativeUnderlying
- constructor
- liquidityCallback
- receive
- fToken__DepositInsignificant
- fToken__MinAmountOut
- fToken__MaxAmount
- fToken__InvalidParams
- fToken__Unauthorized
- fToken__PermitFromOwnerCall
- fToken__Reentrancy
- fToken__ExchangePriceOverflow
- fToken__NotRebalancer
- fToken__NotNativeUnderlying
- fToken__LiquidityExchangePriceUnexpected