Skip to content

SecondaryHelpers ​

Git Source

Inherits:UserHelpers

Functions ​

constructor ​

solidity
constructor(ConstantViews memory constantViews_) UserHelpers(constantViews_);

_getSwapAndDeposit ​

solidity
function _getSwapAndDeposit(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 i_)
    internal
    pure
    returns (uint256 shares_);

Parameters

NameTypeDescription
c_uint256tokenA amount to swap and deposit
d_uint256tokenB imaginary reserves
e_uint256tokenA imaginary reserves
f_uint256tokenA real reserves
i_uint256tokenB real reserves

_getUpdatedColReserves ​

Updates collateral reserves based on minting or burning of shares

solidity
function _getUpdatedColReserves(
    uint256 newShares_,
    uint256 totalOldShares_,
    CollateralReserves memory c_,
    bool mintOrBurn_
) internal pure returns (CollateralReserves memory c2_);

Parameters

NameTypeDescription
newShares_uint256The number of new shares being minted or burned
totalOldShares_uint256The total number of shares before the operation
c_CollateralReservesThe current collateral reserves
mintOrBurn_boolTrue if minting shares, false if burning shares

Returns

NameTypeDescription
c2_CollateralReservesThe updated collateral reserves after the operation

_getWithdrawAndSwap ​

solidity
function _getWithdrawAndSwap(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
    internal
    pure
    returns (uint256 shares_);

Parameters

NameTypeDescription
c_uint256tokenA current real reserves (aka reserves before withdraw & swap)
d_uint256tokenB current real reserves (aka reserves before withdraw & swap)
e_uint256tokenA: final imaginary reserves - real reserves (aka reserves outside range after withdraw & swap)
f_uint256tokenB: final imaginary reserves - real reserves (aka reserves outside range after withdraw & swap)
g_uint256tokenA perfect amount to withdraw

_getBorrowAndSwap ​

solidity
function _getBorrowAndSwap(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
    internal
    pure
    returns (uint256 shares_);

Parameters

NameTypeDescription
c_uint256tokenA current debt before swap (aka debt before borrow & swap)
d_uint256tokenB current debt before swap (aka debt before borrow & swap)
e_uint256tokenA final imaginary reserves (reserves after borrow & swap)
f_uint256tokenB final imaginary reserves (reserves after borrow & swap)
g_uint256tokenA perfect amount to borrow

_getUpdateDebtReserves ​

Updates debt and reserves based on minting or burning shares

This function calculates the new debt and reserves when minting or burning shares.

It updates the following for both tokens:

- Debt

- Real Reserves

- Imaginary Reserves

The calculation is done proportionally based on the ratio of shares to total shares.

For minting, it adds the proportional amount.

For burning, it subtracts the proportional amount.

solidity
function _getUpdateDebtReserves(uint256 shares_, uint256 totalShares_, DebtReserves memory d_, bool mintOrBurn_)
    internal
    pure
    returns (DebtReserves memory d2_);

Parameters

NameTypeDescription
shares_uint256The number of shares to mint or burn
totalShares_uint256The total number of shares before the operation
d_DebtReservesThe current debt and reserves
mintOrBurn_boolTrue if minting, false if burning

Returns

NameTypeDescription
d2_DebtReservesThe updated debt and reserves

_getSwapAndPaybackOneTokenPerfectShares ​

solidity
function _getSwapAndPaybackOneTokenPerfectShares(uint256 a_, uint256 b_, uint256 c_, uint256 d_, uint256 i_, uint256 j_)
    internal
    pure
    returns (uint256 tokenAmt_);

Parameters

NameTypeDescription
a_uint256tokenA new imaginary reserves (imaginary reserves after perfect payback but not swap yet)
b_uint256tokenB new imaginary reserves (imaginary reserves after perfect payback but not swap yet)
c_uint256tokenA current debt
d_uint256tokenB current debt & final debt (tokenB current & final debt remains same)
i_uint256tokenA new reserves (reserves after perfect payback but not swap yet)
j_uint256tokenB new reserves (reserves after perfect payback but not swap yet)

_getSwapAndPayback ​

solidity
function _getSwapAndPayback(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
    internal
    pure
    returns (uint256 shares_);

Parameters

NameTypeDescription
c_uint256tokenA debt before swap & payback
d_uint256tokenB debt before swap & payback
e_uint256tokenA imaginary reserves before swap & payback
f_uint256tokenB imaginary reserves before swap & payback
g_uint256tokenA perfect amount to payback

_arbitrage ​

This function is called after user operations to balance the pools

It swaps tokens between the collateral and debt pools to align their prices

The function updates the oracle price based on the arbitrage results

This function performs arbitrage between the collateral and debt pools

solidity
function _arbitrage(uint256 dexVariables_, uint256 dexVariables2_, PricesAndExchangePrice memory pex_) internal;

Parameters

NameTypeDescription
dexVariables_uint256The current state of dex variables
dexVariables2_uint256Additional dex variables
pex_PricesAndExchangePriceStruct containing prices and exchange rates