Skip to content

DexActionEstimates ​

Git Source

Inherits:DexPublicViews, DexSwapLimits

State Variables ​

ADDRESS_DEAD ​

solidity
address private constant ADDRESS_DEAD = 0x000000000000000000000000000000000000dEaD;

Functions ​

_swapRoutingIn ​

solidity
function _swapRoutingIn(uint256 t, uint256 x, uint256 y, uint256 x2, uint256 y2) private pure returns (int256 a_);

Parameters

NameTypeDescription
tuint256total amount in
xuint256imaginary reserves of token out of collateral
yuint256imaginary reserves of token in of collateral
x2uint256imaginary reserves of token out of debt
y2uint256imaginary reserves of token in of debt

Returns

NameTypeDescription
a_int256how much swap should go through collateral pool. Remaining will go from debt note if a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool note if a > t then entire trade route through col pool and col pool arbitrage with debt pool note if a > 0 & a < t then swap will route through both pools

_swapRoutingOut ​

solidity
function _swapRoutingOut(uint256 t, uint256 x, uint256 y, uint256 x2, uint256 y2) private pure returns (int256 a_);

Parameters

NameTypeDescription
tuint256total amount out
xuint256imaginary reserves of token in of collateral
yuint256imaginary reserves of token out of collateral
x2uint256imaginary reserves of token in of debt
y2uint256imaginary reserves of token out of debt

Returns

NameTypeDescription
a_int256how much swap should go through collateral pool. Remaining will go from debt note if a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool note if a > t then entire trade route through col pool and col pool arbitrage with debt pool note if a > 0 & a < t then swap will route through both pools

_getAmountOut ​

Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset

solidity
function _getAmountOut(uint256 amountIn_, uint256 iReserveIn_, uint256 iReserveOut_)
    private
    pure
    returns (uint256 amountOut_);

Parameters

NameTypeDescription
amountIn_uint256The amount of input asset.
iReserveIn_uint256Imaginary token reserve with input amount.
iReserveOut_uint256Imaginary token reserve of output amount.

_getAmountIn ​

Given an output amount of asset and pair reserves, returns the input amount of the other asset

solidity
function _getAmountIn(uint256 amountOut_, uint256 iReserveIn_, uint256 iReserveOut_)
    private
    pure
    returns (uint256 amountIn_);

Parameters

NameTypeDescription
amountOut_uint256Desired output amount of the asset.
iReserveIn_uint256Imaginary token reserve of input amount.
iReserveOut_uint256Imaginary token reserve of output amount.

estimateSwapIn ​

estimates swap IN tokens execution

solidity
function estimateSwapIn(address dex_, bool swap0to1_, uint256 amountIn_, uint256 amountOutMin_)
    public
    payable
    returns (uint256 amountOut_);

Parameters

NameTypeDescription
dex_addressDex pool
swap0to1_boolDirection of swap. If true, swaps token0 for token1; if false, swaps token1 for token0
amountIn_uint256The exact amount of input tokens to swap
amountOutMin_uint256The minimum amount of output tokens the user is willing to accept

Returns

NameTypeDescription
amountOut_uint256The amount of output tokens received from the swap

estimateSwapOut ​

estimates swap OUT tokens execution

solidity
function estimateSwapOut(address dex_, bool swap0to1_, uint256 amountOut_, uint256 amountInMax_)
    public
    payable
    returns (uint256 amountIn_);

Parameters

NameTypeDescription
dex_addressDex pool
swap0to1_boolDirection of swap. If true, swaps token0 for token1; if false, swaps token1 for token0
amountOut_uint256The exact amount of tokens to receive after swap
amountInMax_uint256Maximum amount of tokens to swap in

Returns

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

_decodeLowLevelUint1x ​

solidity
function _decodeLowLevelUint1x(bytes memory lowLevelData_, bytes4 targetErrorSelector_)
    internal
    pure
    returns (uint256 value1_);

Structs ​

EstimateMemoryVars ​

solidity
struct EstimateMemoryVars {
    uint256 colTokenInImaginaryReserves;
    uint256 colTokenOutImaginaryReserves;
    uint256 debtTokenInImaginaryReserves;
    uint256 debtTokenOutImaginaryReserves;
    uint256 amountOutCollateralAdjusted;
    uint256 amountOutDebtAdjusted;
    uint256 amountInCollateralAdjusted;
    uint256 amountInDebtAdjusted;
}