DexActionEstimates ​
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
Name | Type | Description |
---|---|---|
t | uint256 | total amount in |
x | uint256 | imaginary reserves of token out of collateral |
y | uint256 | imaginary reserves of token in of collateral |
x2 | uint256 | imaginary reserves of token out of debt |
y2 | uint256 | imaginary reserves of token in of debt |
Returns
Name | Type | Description |
---|---|---|
a_ | int256 | how 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
Name | Type | Description |
---|---|---|
t | uint256 | total amount out |
x | uint256 | imaginary reserves of token in of collateral |
y | uint256 | imaginary reserves of token out of collateral |
x2 | uint256 | imaginary reserves of token in of debt |
y2 | uint256 | imaginary reserves of token out of debt |
Returns
Name | Type | Description |
---|---|---|
a_ | int256 | how 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
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The amount of input asset. |
iReserveIn_ | uint256 | Imaginary token reserve with input amount. |
iReserveOut_ | uint256 | Imaginary 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
Name | Type | Description |
---|---|---|
amountOut_ | uint256 | Desired output amount of the asset. |
iReserveIn_ | uint256 | Imaginary token reserve of input amount. |
iReserveOut_ | uint256 | Imaginary 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
Name | Type | Description |
---|---|---|
dex_ | address | Dex pool |
swap0to1_ | bool | Direction of swap. If true, swaps token0 for token1; if false, swaps token1 for token0 |
amountIn_ | uint256 | The exact amount of input tokens to swap |
amountOutMin_ | uint256 | The minimum amount of output tokens the user is willing to accept |
Returns
Name | Type | Description |
---|---|---|
amountOut_ | uint256 | The 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
Name | Type | Description |
---|---|---|
dex_ | address | Dex pool |
swap0to1_ | bool | Direction of swap. If true, swaps token0 for token1; if false, swaps token1 for token0 |
amountOut_ | uint256 | The exact amount of tokens to receive after swap |
amountInMax_ | uint256 | Maximum amount of tokens to swap in |
Returns
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The 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;
}