ReentrancyGuard
ReentrancyGuard based on OpenZeppelin implementation. https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.8/contracts/security/ReentrancyGuard.sol
REENTRANCY_NOT_ENTERED
uint8 REENTRANCY_NOT_ENTERED
REENTRANCY_ENTERED
uint8 REENTRANCY_ENTERED
constructor
constructor() internal
_checkReentrancy
function _checkReentrancy() internal
checks that no reentrancy occurs, reverts if so. Calling the method in the modifier reduces bytecode size as modifiers are inlined into bytecode
nonReentrant
modifier nonReentrant()
Prevents a contract from calling itself, directly or indirectly. See OpenZeppelin implementation for more info
fTokenCore
internal methods for fToken contracts
_getLiquidityExchangePrice
function _getLiquidityExchangePrice() internal view returns (uint256 supplyExchangePrice_)
Gets current (updated) Liquidity supply exchange price for the underyling asset
_getLiquidityBalance
function _getLiquidityBalance() internal view returns (uint256 balance_)
Gets current Liquidity supply balance of address(this)
for the underyling asset
_getLiquidityUnderlyingBalance
function _getLiquidityUnderlyingBalance() internal view virtual returns (uint256)
Gets current Liquidity underlying token balance
_getLiquidityWithdrawable
function _getLiquidityWithdrawable() internal view returns (uint256 withdrawalLimit_)
_Gets current withdrawable amount at Liquidity withdrawalLimit_
(withdrawal limit or balance)._
_calculateNewTokenExchangePrice
function _calculateNewTokenExchangePrice(uint256 newLiquidityExchangePrice_) internal view returns (uint256 newTokenExchangePrice_, bool rewardsEnded_)
_Calculates new token exchange price based on the current liquidity exchange price newLiquidityExchangePrice_
and rewards rate._
Parameters
Name | Type | Description |
---|---|---|
newLiquidityExchangePrice_ | uint256 | new (current) liquidity exchange price |
_updateRates
function _updateRates(uint256 liquidityExchangePrice_, bool forceUpdateStorage_) internal returns (uint256 tokenExchangePrice_)
calculates new exchange prices, updates values in storage and returns new tokenExchangePrice (with reward rates)
_splitSignature
function _splitSignature(bytes sig) internal pure returns (uint8 v, bytes32 r, bytes32 s)
splits a bytes signature sig
into v
, r
, s
.
Taken from https://docs.soliditylang.org/en/v0.8.17/solidity-by-example.html
_depositToLiquidity
function _depositToLiquidity(uint256 assets_, bytes liquidityCallbackData_) internal virtual returns (uint256 exchangePrice_)
_Deposit assets_
amount of tokens to Liquidity_
Parameters
Name | Type | Description |
---|---|---|
assets_ | uint256 | The amount of tokens to deposit |
liquidityCallbackData_ | bytes | callback data passed to Liquidity for liquidityCallback |
Return Values
Name | Type | Description |
---|---|---|
exchangePrice_ | uint256 | liquidity exchange price for token |
_withdrawFromLiquidity
function _withdrawFromLiquidity(uint256 assets_, address receiver_) internal virtual returns (uint256 exchangePrice_)
_Withdraw assets_
amount of tokens from Liquidity directly toreceiver*
*
Parameters
Name | Type | Description |
---|---|---|
assets_ | uint256 | The amount of tokens to withdraw |
receiver_ | address | the receiver address of withdraw amount |
Return Values
Name | Type | Description |
---|---|---|
exchangePrice_ | uint256 | liquidity exchange price for token |
_executeDeposit
function _executeDeposit(uint256 assets_, address receiver_, bytes liquidityCallbackData_) internal virtual returns (uint256 sharesMinted_)
_deposits assets_
into liquidity and mints shares forreceiver*
. Returns amount of sharesMinted*
._
_executeWithdraw
function _executeWithdraw(uint256 assets_, address receiver_, address owner_) internal virtual returns (uint256 sharesBurned_)
_withdraws assets_
from liquidity toreceiver*
and burns shares fromowner*
.
Returns amount of sharesBurned*
.
requires nonReentrant! modifier on calling method otherwise ERC777s could reenter!*
fTokenViews
fToken view methods. Implements view methods for ERC4626 compatibility
getData
function getData() public 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) |
asset
function asset() public view virtual returns (address)
_Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
- MUST be an ERC-20 token contract.
- MUST NOT revert._
totalAssets
function totalAssets() public view virtual returns (uint256)
_Returns the total amount of the underlying asset that is “managed” by Vault.
- SHOULD include any compounding that occurs from yield.
- MUST be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT revert._
convertToShares
function convertToShares(uint256 assets_) public view virtual returns (uint256)
_Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal scenario where all the conditions are met.
- MUST NOT be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT show any variations depending on the caller.
- MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
- MUST NOT revert.
NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and from._
convertToAssets
function convertToAssets(uint256 shares_) public view virtual returns (uint256)
_Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal scenario where all the conditions are met.
- MUST NOT be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT show any variations depending on the caller.
- MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
- MUST NOT revert.
NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and from._
previewDeposit
function previewDeposit(uint256 assets_) public view virtual returns (uint256)
returned amount might be slightly different from actual amount at execution.
_Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given current on-chain conditions.
- MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called in the same transaction.
- MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the deposit would be accepted, regardless if the user has enough tokens approved, etc.
- MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by depositing._
previewMint
function previewMint(uint256 shares_) public view virtual returns (uint256)
_Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given current on-chain conditions.
- MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the same transaction.
- MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint would be accepted, regardless if the user has enough tokens approved, etc.
- MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by minting._
previewWithdraw
function previewWithdraw(uint256 assets_) public view virtual returns (uint256)
_Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, given current on-chain conditions.
- MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if called in the same transaction.
- MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though the withdrawal would be accepted, regardless if the user has enough shares, etc.
- MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by depositing._
previewRedeem
function previewRedeem(uint256 shares_) public view virtual returns (uint256)
returned amount might be slightly different from actual amount at execution.
_Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, given current on-chain conditions.
- MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the same transaction.
- MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the redemption would be accepted, regardless if the user has enough shares, etc.
- MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by redeeming._
maxDeposit
function maxDeposit(address) public view virtual returns (uint256)
_Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, through a deposit call.
- MUST return a limited value if receiver is subject to some deposit limit.
- MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
- MUST NOT revert._
maxMint
function maxMint(address) public view virtual returns (uint256)
_Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
- MUST return a limited value if receiver is subject to some mint limit.
- MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
- MUST NOT revert._
maxWithdraw
function maxWithdraw(address owner_) public view virtual returns (uint256)
_Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the Vault, through a withdraw call.
- MUST return a limited value if owner is subject to some withdrawal limit or timelock.
- MUST NOT revert._
maxRedeem
function maxRedeem(address owner_) public view virtual returns (uint256)
_Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, through a redeem call.
- MUST return a limited value if owner is subject to some withdrawal limit or timelock.
- MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
- MUST NOT revert._
minDeposit
function minDeposit() public view returns (uint256)
returns minimum amount required for deposit (rounded up)
fTokenAdmin
fToken admin related methods. fToken admins are Lending Factory auths. Possible actions are updating rewards, funding rewards, and rescuing any stuck funds (fToken contract itself never holds any funds).
_checkIsLendingFactoryAuth
function _checkIsLendingFactoryAuth() internal view
checks if msg.sender
is an allowed auth at LendingFactory. internal method instead of modifier
to reduce bytecode size.
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 virtual 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 |
updateRebalancer
function updateRebalancer(address newRebalancer_) public
Updates the rebalancer address (ReserveContract). Only callable by LendingFactory auths.
updateRates
function updateRates() public 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 virtual
sends any potentially stuck funds to Liquidity contract. Only callable by LendingFactory auths.
fTokenActions
fToken public executable actions: deposit, mint, mithdraw and redeem. All actions are optionally also available with an additional param to limit the maximum slippage, e.g. maximum assets used for minting x amount of shares.
_revertIfBelowMinAmountOut
function _revertIfBelowMinAmountOut(uint256 amount_, uint256 minAmountOut_) internal pure
_reverts if amount_
is <minAmountOut*
. Used to reduce bytecode size.*
_revertIfAboveMaxAmount
function _revertIfAboveMaxAmount(uint256 amount_, uint256 maxAmount_) internal pure
_reverts if amount_
is >maxAmount*
. Used to reduce bytecode size.*
deposit
function deposit(uint256 assets_, address receiver_) public virtual returns (uint256 shares_)
If assets_
equals uint256.max then the whole balance of msg.sender
is deposited.
assets_
must at least be minDeposit()
amount; reverts fToken__DepositInsignificant()
if not.
Recommended to use deposit()
with a minAmountOut_
param instead to set acceptable limit.
_Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
- MUST emit the Deposit event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the deposit execution, and are accounted for during deposit.
- MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not approving enough underlying tokens to the Vault contract, etc).
NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token._
Return Values
Name | Type | Description |
---|---|---|
shares_ | uint256 | actually minted shares |
deposit
function deposit(uint256 assets_, address receiver_, uint256 minAmountOut_) external returns (uint256 shares_)
same as {fToken-deposit} but with an additional setting for minimum output amount.
reverts with fToken__MinAmountOut()
if minAmountOut_
of shares is not reached
mint
function mint(uint256 shares_, address receiver_) public virtual returns (uint256 assets_)
If shares_
equals uint256.max then the whole balance of msg.sender
is deposited.
shares_
must at least be minMint()
amount; reverts fToken__DepositInsignificant()
if not.
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.
Recommended to use mint()
with a minAmountOut_
param instead to set acceptable limit.
_Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
- MUST emit the Deposit event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint execution, and are accounted for during mint.
- MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not approving enough underlying tokens to the Vault contract, etc).
NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token._
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | deposited assets amount |
mint
function mint(uint256 shares_, address receiver_, uint256 maxAssets_) external returns (uint256 assets_)
same as {fToken-mint} but with an additional setting for maximum assets input amount.
reverts with fToken__MaxAmount()
if maxAssets_
of assets is surpassed to mint shares_
.
withdraw
function withdraw(uint256 assets_, address receiver_, address owner_) public virtual returns (uint256 shares_)
If assets_
equals uint256.max then the whole fToken balance of owner_
is withdrawn. This does not
consider withdrawal limit at Liquidity so best to check with maxWithdraw()
before.
Note there might be tiny inaccuracies between requested assets_
and actually received assets amount.
Recommended to use withdraw()
with a minAmountOut_
param instead to set acceptable limit.
_Burns shares from owner and sends exactly assets of underlying tokens to receiver.
- MUST emit the Withdraw event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the withdraw execution, and are accounted for during withdraw.
- MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner not having enough shares, etc).
Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. Those methods should be performed separately._
Return Values
Name | Type | Description |
---|---|---|
shares_ | uint256 | burned shares |
withdraw
function withdraw(uint256 assets_, address receiver_, address owner_, uint256 maxSharesBurn_) external returns (uint256 shares_)
same as {fToken-withdraw} but with an additional setting for maximum shares burned.
reverts with fToken__MaxAmount()
if maxSharesBurn_
of shares burned is surpassed.
redeem
function redeem(uint256 shares_, address receiver_, address owner_) public virtual returns (uint256 assets_)
If shares_
equals uint256.max then the whole balance of owner_
is withdrawn.This does not
consider withdrawal limit at Liquidity so best to check with maxRedeem()
before.
Recommended to use withdraw()
over redeem because it is more gas efficient and can set specific amount.
Recommended to use redeem()
with a minAmountOut_
param instead to set acceptable limit.
_Burns exactly shares from owner and sends assets of underlying tokens to receiver.
- MUST emit the Withdraw event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the redeem execution, and are accounted for during redeem.
- MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner not having enough shares, etc).
NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. Those methods should be performed separately._
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | withdrawn assets amount |
redeem
function redeem(uint256 shares_, address receiver_, address owner_, uint256 minAmountOut_) external returns (uint256 assets_)
same as {fToken-redeem} but with an additional setting for minimum output amount.
reverts with fToken__MinAmountOut()
if minAmountOut_
of assets is not reached.
fTokenEIP2612Withdrawals
fTokens support EIP-2612 permit approvals via signature so this contract implements withdrawals (withdraw / redeem) with signature used for approval of the fToken shares.
_allowViaPermitEIP2612
function _allowViaPermitEIP2612(address owner_, uint256 sharesToPermit_, uint256 deadline_, bytes signature_) internal
_creates sharesToPermit_
allowance forowner*
via EIP2612deadline*
andsignature*
*
withdrawWithSignature
function withdrawWithSignature(uint256 sharesToPermit_, uint256 assets_, address receiver_, address owner_, uint256 maxSharesBurn_, uint256 deadline_, bytes signature_) external virtual returns (uint256 shares_)
withdraw amount of assets_
with ERC-2612 permit signature for fToken approval.
owner_
signs ERC-2612 permit signature_
to give allowance of fTokens to msg.sender
.
Note there might be tiny inaccuracies between requested assets_
and actually received assets amount.
allowance via signature (sharesToPermit_
) should cover previewWithdraw(assets_)
plus a little buffer to avoid revert.
Inherent trust assumption that msg.sender
will set receiver_
and maxSharesBurn_
as owner_
intends
(which is always the case when giving allowance to some spender).
Parameters
Name | Type | Description |
---|---|---|
sharesToPermit_ | uint256 | shares amount to use for EIP2612 permit(). Should cover previewWithdraw(assets_) + small buffer. |
assets_ | uint256 | amount of assets to withdraw |
receiver_ | address | receiver of withdrawn assets |
owner_ | address | owner to withdraw from (must be signature signer) |
maxSharesBurn_ | uint256 | maximum accepted amount of shares burned |
deadline_ | uint256 | deadline for signature validity |
signature_ | bytes | packed signature of signing the EIP712 hash for ERC-2612 permit |
Return Values
Name | Type | Description |
---|---|---|
shares_ | uint256 | burned shares amount |
redeemWithSignature
function redeemWithSignature(uint256 shares_, address receiver_, address owner_, uint256 minAmountOut_, uint256 deadline_, bytes signature_) external virtual returns (uint256 assets_)
redeem amount of shares_
with ERC-2612 permit signature for fToken approval.
owner_
signs ERC-2612 permit signature_
to give allowance of fTokens to msg.sender
.
Note there might be tiny inaccuracies between requested shares_
to redeem and actually burned shares.
allowance via signature must cover shares_
plus a tiny buffer.
Inherent trust assumption that msg.sender
will set receiver_
and minAmountOut_
as owner_
intends
(which is always the case when giving allowance to some spender).
Recommended to use withdraw()
over redeem because it is more gas efficient and can set specific amount.
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | amount of shares to redeem |
receiver_ | address | receiver of withdrawn assets |
owner_ | address | owner to withdraw from (must be signature signer) |
minAmountOut_ | uint256 | minimum accepted amount of assets withdrawn |
deadline_ | uint256 | deadline for signature validity |
signature_ | bytes | packed signature of signing the EIP712 hash for ERC-2612 permit |
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | withdrawn assets amount |
fTokenEIP2612Deposits
implements fTokens support for deposit / mint via EIP-2612 permit.
methods revert if underlying asset does not support EIP-2612.
depositWithSignatureEIP2612
function depositWithSignatureEIP2612(uint256 assets_, address receiver_, uint256 minAmountOut_, uint256 deadline_, bytes signature_) external returns (uint256 shares_)
deposit assets_
amount with EIP-2612 Permit2 signature for underlying asset approval.
IMPORTANT: This will revert if the underlying asset()
does not support EIP-2612.
reverts with fToken__MinAmountOut()
if minAmountOut_
of shares is not reached.
assets_
must at least be minDeposit()
amount; reverts fToken__DepositInsignificant()
if not.
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 |
deadline_ | uint256 | deadline for signature validity |
signature_ | bytes | packed signature of signing the EIP712 hash for EIP-2612 Permit |
Return Values
Name | Type | Description |
---|---|---|
shares_ | uint256 | amount of minted shares |
mintWithSignatureEIP2612
function mintWithSignatureEIP2612(uint256 shares_, address receiver_, uint256 maxAssets_, uint256 deadline_, bytes signature_) external returns (uint256 assets_)
mint amount of shares_
with EIP-2612 Permit signature for underlying asset approval.
IMPORTANT: This will revert if the underlying asset()
does not support EIP-2612.
Signature should approve a little bit more than expected assets amount (previewMint()
) to avoid reverts.
shares_
must at least be minMint()
amount; reverts with fToken__DepositInsignificant()
if not.
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_ |
deadline_ | uint256 | deadline for signature validity |
signature_ | bytes | packed signature of signing the EIP712 hash for EIP-2612 Permit |
Return Values
Name | Type | Description |
---|---|---|
assets_ | uint256 | deposited assets amount |
fTokenPermit2Deposits
implements fTokens support for deposit / mint via Permit2 signature.
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 |
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).