FluidVaultT1

Git Source

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

NameTypeDescription
nftId_uint256NFT ID for interaction. If 0 then create new NFT/position.
newCol_int256new collateral. If positive then deposit, if negative then withdraw, if 0 then do nohing
newDebt_int256new debt. If positive then borrow, if negative then payback, if 0 then do nohing
to_addressaddress where withdraw or borrow should go. If address(0) then msg.sender

Returns

NameTypeDescription
<none>uint256nftId_ if 0 then this returns the newly created NFT Id else returns the same NFT ID
<none>int256newCol_ 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>int256newDebt_ 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

NameTypeDescription
debtAmt_uint256total debt to liquidate (aka debt token to swap into collateral token)
colPerUnitDebt_uint256minimum collateral token per unit of debt in 1e18 decimals
to_addressaddress 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_boolif true then liquidate from absorbed first

Returns

NameTypeDescription
actualDebtAmt_uint256if liquidator sends debtAmt_ more than debt remaining to liquidate then actualDebtAmt_ changes from debtAmt_ else remains same
actualColAmt_uint256total 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_);