FluidVaultT1
Inherits:Helpers
Fluid "VaultT1" (Vault Type 1). Fluid vault protocol main contract.
Fluid Vault protocol is a borrow / lending protocol, allowing users to create collateral / borrow positions.
All funds are deposited into / borrowed from Fluid Liquidity layer.
Positions are represented through NFTs minted by the VaultFactory.
Deployed by "VaultFactory" and linked together with VaultT1 AdminModule ADMIN_IMPLEMENTATION
and
FluidVaultT1Secondary (main2.sol) SECONDARY_IMPLEMENTATION
.
AdminModule & FluidVaultT1Secondary methods are delegateCalled, if the msg.sender has the required authorization.
This contract links to an Oracle, which is used to assess collateral / debt value. Oracles implement the
"FluidOracle" base contract and return the price in 1e27 precision.
For view methods / accessing data, use the "VaultResolver" periphery contract.
Functions
operate
Single function which handles supply, withdraw, borrow & payback
function operate(uint256 nftId_, int256 newCol_, int256 newDebt_, address to_)
public
payable
returns (uint256, int256, int256);
Parameters
Name | Type | Description |
---|---|---|
nftId_ | uint256 | NFT ID for interaction. If 0 then create new NFT/position. |
newCol_ | int256 | new collateral. If positive then deposit, if negative then withdraw, if 0 then do nohing |
newDebt_ | int256 | new debt. If positive then borrow, if negative then payback, if 0 then do nohing |
to_ | address | address where withdraw or borrow should go. If address(0) then msg.sender |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | nftId_ if 0 then this returns the newly created NFT Id else returns the same NFT ID |
<none> | int256 | newCol_ final supply amount. Mainly if max withdraw using type(int).min then this is useful to get perfect amount else remain same as newCol_ |
<none> | int256 | newDebt_ final borrow amount. Mainly if max payback using type(int).min then this is useful to get perfect amount else remain same as newDebt_ |
liquidate
allows to liquidate all bad debt of all users at once. Liquidator can also liquidate partially any amount they want.
function liquidate(uint256 debtAmt_, uint256 colPerUnitDebt_, address to_, bool absorb_)
public
payable
returns (uint256 actualDebtAmt_, uint256 actualColAmt_);
Parameters
Name | Type | Description |
---|---|---|
debtAmt_ | uint256 | total debt to liquidate (aka debt token to swap into collateral token) |
colPerUnitDebt_ | uint256 | minimum collateral token per unit of debt in 1e18 decimals |
to_ | address | address at which collateral token should go to. If dead address (0x000000000000000000000000000000000000dEaD) then reverts with custom error "FluidLiquidateResult" returning the actual collateral and actual debt liquidated. Useful to find max liquidatable amounts via try / catch. |
absorb_ | bool | if true then liquidate from absorbed first |
Returns
Name | Type | Description |
---|---|---|
actualDebtAmt_ | uint256 | if liquidator sends debtAmt_ more than debt remaining to liquidate then actualDebtAmt_ changes from debtAmt_ else remains same |
actualColAmt_ | uint256 | total liquidated collateral which liquidator will get |
absorb
absorb function absorbs the bad debt if the bad debt is above max limit. The main use of it is if the bad debt didn't got liquidated in time maybe due to sudden price drop or bad debt was extremely small to liquidate and the bad debt goes above 100% ratio then there's no incentive for anyone to liquidate now hence absorb functions absorbs that bad debt to allow newer bad debt to liquidate seamlessly if absorbing were to happen after this it's on governance on how to deal with it although it can still be removed through liquidate via liquidator if the price goes back up and liquidation becomes beneficial upon absorbed user position gets 100% liquidated.
function absorb() public;
rebalance
Checks total supply of vault's in Liquidity Layer & Vault contract and rebalance it accordingly if vault supply is more than Liquidity Layer then deposit difference through reserve/rebalance contract if vault supply is less than Liquidity Layer then withdraw difference to reserve/rebalance contract if vault borrow is more than Liquidity Layer then borrow difference to reserve/rebalance contract if vault borrow is less than Liquidity Layer then payback difference through reserve/rebalance contract
function rebalance() external payable returns (int256 supplyAmt_, int256 borrowAmt_);
liquidityCallback
liquidity callback for cheaper token transfers in case of deposit or payback. only callable by Liquidity during an operation.
function liquidityCallback(address token_, uint256 amount_, bytes calldata data_) external;
constructor
constructor(ConstantViews memory constants_) Helpers(constants_);
fallback
fallback() external;
_spell
function _spell(address target_, bytes memory data_) private returns (bytes memory response_);