SecondaryHelpers ​
Inherits:CoreHelpers
Functions ​
constructor ​
constructor(ConstantViews memory constantViews_) CoreHelpers(constantViews_);_getSwapAndDeposit ​
function _getSwapAndDeposit(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 i_)
internal
pure
returns (uint256 shares_);Parameters
| Name | Type | Description |
|---|---|---|
c_ | uint256 | tokenA amount to swap and deposit |
d_ | uint256 | tokenB imaginary reserves |
e_ | uint256 | tokenA imaginary reserves |
f_ | uint256 | tokenA real reserves |
i_ | uint256 | tokenB real reserves |
_getUpdatedColReserves ​
Updates collateral reserves based on minting or burning of shares
function _getUpdatedColReserves(
uint256 newShares_,
uint256 totalOldShares_,
CollateralReserves memory c_,
bool mintOrBurn_ // true if mint, false if burn
) internal pure returns (CollateralReserves memory c2_);Parameters
| Name | Type | Description |
|---|---|---|
newShares_ | uint256 | The number of new shares being minted or burned |
totalOldShares_ | uint256 | The total number of shares before the operation |
c_ | CollateralReserves | The current collateral reserves |
mintOrBurn_ | bool | True if minting shares, false if burning shares |
Returns
| Name | Type | Description |
|---|---|---|
c2_ | CollateralReserves | The updated collateral reserves after the operation |
_getWithdrawAndSwap ​
function _getWithdrawAndSwap(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
internal
pure
returns (uint256 shares_);Parameters
| Name | Type | Description |
|---|---|---|
c_ | uint256 | tokenA current real reserves (aka reserves before withdraw & swap) |
d_ | uint256 | tokenB current real reserves (aka reserves before withdraw & swap) |
e_ | uint256 | tokenA: final imaginary reserves - real reserves (aka reserves outside range after withdraw & swap) |
f_ | uint256 | tokenB: final imaginary reserves - real reserves (aka reserves outside range after withdraw & swap) |
g_ | uint256 | tokenA perfect amount to withdraw |
_getBorrowAndSwap ​
function _getBorrowAndSwap(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
internal
pure
returns (uint256 shares_);Parameters
| Name | Type | Description |
|---|---|---|
c_ | uint256 | tokenA current debt before swap (aka debt before borrow & swap) |
d_ | uint256 | tokenB current debt before swap (aka debt before borrow & swap) |
e_ | uint256 | tokenA final imaginary reserves (reserves after borrow & swap) |
f_ | uint256 | tokenB final imaginary reserves (reserves after borrow & swap) |
g_ | uint256 | tokenA 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.
function _getUpdateDebtReserves(
uint256 shares_,
uint256 totalShares_,
DebtReserves memory d_,
bool mintOrBurn_ // true if mint, false if burn
)
internal
pure
returns (DebtReserves memory d2_);Parameters
| Name | Type | Description |
|---|---|---|
shares_ | uint256 | The number of shares to mint or burn |
totalShares_ | uint256 | The total number of shares before the operation |
d_ | DebtReserves | The current debt and reserves |
mintOrBurn_ | bool | True if minting, false if burning |
Returns
| Name | Type | Description |
|---|---|---|
d2_ | DebtReserves | The updated debt and reserves |
_getSwapAndPaybackOneTokenPerfectShares ​
function _getSwapAndPaybackOneTokenPerfectShares(
uint256 a_,
uint256 b_,
uint256 c_,
uint256 d_,
uint256 i_,
uint256 j_
) internal pure returns (uint256 tokenAmt_);Parameters
| Name | Type | Description |
|---|---|---|
a_ | uint256 | tokenA new imaginary reserves (imaginary reserves after perfect payback but not swap yet) |
b_ | uint256 | tokenB new imaginary reserves (imaginary reserves after perfect payback but not swap yet) |
c_ | uint256 | tokenA current debt |
d_ | uint256 | tokenB current debt & final debt (tokenB current & final debt remains same) |
i_ | uint256 | tokenA new reserves (reserves after perfect payback but not swap yet) |
j_ | uint256 | tokenB new reserves (reserves after perfect payback but not swap yet) |
_getSwapAndPayback ​
function _getSwapAndPayback(uint256 c_, uint256 d_, uint256 e_, uint256 f_, uint256 g_)
internal
pure
returns (uint256 shares_);Parameters
| Name | Type | Description |
|---|---|---|
c_ | uint256 | tokenA debt before swap & payback |
d_ | uint256 | tokenB debt before swap & payback |
e_ | uint256 | tokenA imaginary reserves before swap & payback |
f_ | uint256 | tokenB imaginary reserves before swap & payback |
g_ | uint256 | tokenA 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
function _arbitrage(uint256 dexVariables_, uint256 dexVariables2_, PricesAndExchangePrice memory pex_) internal;Parameters
| Name | Type | Description |
|---|---|---|
dexVariables_ | uint256 | The current state of dex variables |
dexVariables2_ | uint256 | Additional dex variables |
pex_ | PricesAndExchangePrice | Struct containing prices and exchange rates |
_onlyDelegateCall ​
modifier _onlyDelegateCall() ;_enforceDelegateCall ​
Checks that the current call is via delegatecall and not a direct call. Used as a helper for _onlyDelegateCall modifier above.
function _enforceDelegateCall() internal view;_verifyMint ​
function _verifyMint(uint256 amt_, uint256 totalAmt_) internal pure;_verifyRedeem ​
function _verifyRedeem(uint256 amt_, uint256 totalAmt_) internal pure;_getExchangePrices ​
function _getExchangePrices() internal view returns (ExchangePrices memory ex_);_updatingUserSupplyDataOnStorage ​
function _updatingUserSupplyDataOnStorage(uint256 userSupplyData_, uint256 userSupply_, uint256 newWithdrawalLimit_)
internal;_updatingUserBorrowDataOnStorage ​
function _updatingUserBorrowDataOnStorage(uint256 userBorrowData_, uint256 userBorrow_, uint256 newBorrowLimit_)
internal;_depositOrPaybackInLiquidity ​
Deposits or pays back in liquidity
function _depositOrPaybackInLiquidity(address token_, uint256 depositAmt_, uint256 paybackAmt_) internal;Parameters
| Name | Type | Description |
|---|---|---|
token_ | address | The token to deposit or pay back |
depositAmt_ | uint256 | The amount to deposit |
paybackAmt_ | uint256 | The amount to pay back |

