Helpers

Git Source

Inherits:Variables, ConstantVariables, Events, Error

Fluid vault protocol helper methods. Mostly used for operate() and liquidate() methods of CoreModule.

Functions

updateExchangePrices

Calculates new vault exchange prices. Does not update values in storage.

function updateExchangePrices(uint256 vaultVariables2_)
    public
    view
    returns (
        uint256 liqSupplyExPrice_,
        uint256 liqBorrowExPrice_,
        uint256 vaultSupplyExPrice_,
        uint256 vaultBorrowExPrice_
    );

Parameters

NameTypeDescription
vaultVariables2_uint256exactly same as vaultVariables2 from storage

Returns

NameTypeDescription
liqSupplyExPrice_uint256latest liquidity's supply token supply exchange price
liqBorrowExPrice_uint256latest liquidity's borrow token borrow exchange price
vaultSupplyExPrice_uint256latest vault's supply token exchange price
vaultBorrowExPrice_uint256latest vault's borrow token exchange price

updateExchangePricesOnStorage

note admin module is also calling this function self call

updating exchange price on storage. Only need to update on storage when changing supply or borrow magnifier

function updateExchangePricesOnStorage()
    public
    returns (
        uint256 liqSupplyExPrice_,
        uint256 liqBorrowExPrice_,
        uint256 vaultSupplyExPrice_,
        uint256 vaultBorrowExPrice_
    );

fetchLatestPosition

fetches new user's position after liquidation. The new liquidated position's debt is decreased by 0.01% to make sure that branch's liquidity never becomes 0 as if it would have gotten 0 then there will be multiple cases that we would need to tackle.

function fetchLatestPosition(int256 positionTick_, uint256 positionTickId_, uint256 positionRawDebt_, uint256 tickData_)
    public
    view
    returns (int256, uint256, uint256 positionRawCol_, uint256 branchId_, uint256 branchData_);

Parameters

NameTypeDescription
positionTick_int256position's tick when it was last updated through operate
positionTickId_uint256position's tick Id. This stores the debt factor and branch to make the first connection
positionRawDebt_uint256position's raw debt when it was last updated through operate
tickData_uint256position's tick's tickData just for minor comparison to know if data is moved to tick Id or is still in tick data

Returns

NameTypeDescription
<none>int256final tick position after all the liquidation
<none>uint256final debt of position after all the liquidation
positionRawCol_uint256final collateral of position after all the liquidation
branchId_uint256final branch's ID where the position is at currently
branchData_uint256final branch's data where the position is at currently

_updateTickHasDebt

sets tick_ as having debt or no debt in storage tickHasDebt depending on addOrRemove_

function _updateTickHasDebt(int256 tick_, bool addOrRemove_) internal;

Parameters

NameTypeDescription
tick_int256tick to add or remove from tickHasDebt
addOrRemove_boolif true then add else remove

_fetchNextTopTick

gets next perfect top tick (tick which is not liquidated)

function _fetchNextTopTick(int256 topTick_) internal view returns (int256 nextTick_);

Parameters

NameTypeDescription
topTick_int256current top tick which will no longer be top tick

Returns

NameTypeDescription
nextTick_int256next top tick which will become the new top tick

_addDebtToTickWrite

adding debt to a particular tick

function _addDebtToTickWrite(uint256 totalColRaw_, uint256 netDebtRaw_)
    internal
    returns (int256 tick_, uint256 tickId_, uint256 userRawDebt_, uint256 rawDust_);

Parameters

NameTypeDescription
totalColRaw_uint256total raw collateral of position
netDebtRaw_uint256net raw debt (total debt - dust debt)

Returns

NameTypeDescription
tick_int256tick where the debt is being added
tickId_uint256tick current id
userRawDebt_uint256user's total raw debt
rawDust_uint256dust debt used for adjustment

_setNewTopTick

sets new top tick. If it comes to this function then that means current top tick is perfect tick. if next top tick is liquidated then unitializes the current non liquidated branch and make the liquidated branch as current branch

function _setNewTopTick(int256 topTick_, uint256 vaultVariables_)
    internal
    returns (uint256 newVaultVariables_, int256 newTopTick_);

Parameters

NameTypeDescription
topTick_int256current top tick
vaultVariables_uint256vaultVariables of storage but with newer updates

Returns

NameTypeDescription
newVaultVariables_uint256newVaultVariables_ updated vault variable internally to this function
newTopTick_int256new top tick

constructor

constructor(ConstantViews memory constants_) ConstantVariables(constants_);