FluidDexT1PerfectOperationsAndSwapOut ​
Inherits:UserHelpers
Implements core logics for Fluid Dex protocol. Note Token transfers happen directly from user to Liquidity contract and vice-versa.
Functions ​
constructor ​
constructor(ConstantViews memory constantViews_) UserHelpers(constantViews_);
_onlyDelegateCall ​
modifier _onlyDelegateCall();
_swapOut ​
Swap tokens with perfect amount out. If NATIVE_TOKEN is sent then msg.value should be passed as amountInMax, amountInMax - amountIn of ETH are sent back to msg.sender
function _swapOut(bool swap0to1_, uint256 amountOut_, SwapOutExtras memory extras_)
internal
_onlyDelegateCall
returns (uint256 amountIn_);
Parameters
Name | Type | Description |
---|---|---|
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 |
extras_ | SwapOutExtras | Additional parameters for the swap: - to_: Recipient of swapped tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with amountIn_ - amountInMax: The maximum amount of input tokens the user is willing to swap - isCallback: If true, indicates that the output tokens should be transferred via a callback |
Returns
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The amount of input tokens used for the swap |
swapOut ​
Swap tokens with perfect amount out
function swapOut(bool swap0to1_, uint256 amountOut_, uint256 amountInMax_, address to_)
public
payable
_onlyDelegateCall
returns (uint256 amountIn_);
Parameters
Name | Type | Description |
---|---|---|
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 |
to_ | address | Recipient of swapped tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with amountIn_ |
Returns
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The amount of input tokens used for the swap |
swapOutWithCallback ​
Swap tokens with perfect amount out and callback functionality
function swapOutWithCallback(bool swap0to1_, uint256 amountOut_, uint256 amountInMax_, address to_)
public
payable
returns (uint256 amountIn_);
Parameters
Name | Type | Description |
---|---|---|
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 |
to_ | address | Recipient of swapped tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with amountIn_ |
Returns
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The amount of input tokens used for the swap |
depositPerfect ​
Deposit tokens in equal proportion to the current pool ratio
function depositPerfect(uint256 shares_, uint256 maxToken0Deposit_, uint256 maxToken1Deposit_, bool estimate_)
public
payable
_onlyDelegateCall
returns (uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to mint |
maxToken0Deposit_ | uint256 | Maximum amount of token0 to deposit |
maxToken1Deposit_ | uint256 | Maximum amount of token1 to deposit |
estimate_ | bool | If true, function will revert with estimated deposit amounts without executing the deposit |
Returns
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 deposited |
token1Amt_ | uint256 | Amount of token1 deposited |
withdrawPerfect ​
This function allows users to withdraw a perfect amount of collateral liquidity
function withdrawPerfect(uint256 shares_, uint256 minToken0Withdraw_, uint256 minToken1Withdraw_, address to_)
public
_onlyDelegateCall
returns (uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to withdraw |
minToken0Withdraw_ | uint256 | The minimum amount of token0 the user is willing to accept |
minToken1Withdraw_ | uint256 | The minimum amount of token1 the user is willing to accept |
to_ | address | Recipient of swapped tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with token0Amt_ & token1Amt_ |
Returns
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 withdrawn |
token1Amt_ | uint256 | The amount of token1 withdrawn |
borrowPerfect ​
This function allows users to borrow tokens in equal proportion to the current debt pool ratio
function borrowPerfect(uint256 shares_, uint256 minToken0Borrow_, uint256 minToken1Borrow_, address to_)
public
_onlyDelegateCall
returns (uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to borrow |
minToken0Borrow_ | uint256 | Minimum amount of token0 to borrow |
minToken1Borrow_ | uint256 | Minimum amount of token1 to borrow |
to_ | address | Recipient of swapped tokens. If to_ == address(0) then out tokens will be sent to msg.sender. If to_ == ADDRESS_DEAD then function will revert with token0Amt_ & token1Amt_ |
Returns
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 borrowed |
token1Amt_ | uint256 | Amount of token1 borrowed |
paybackPerfect ​
This function allows users to pay back borrowed tokens in equal proportion to the current debt pool ratio
function paybackPerfect(uint256 shares_, uint256 maxToken0Payback_, uint256 maxToken1Payback_, bool estimate_)
public
payable
_onlyDelegateCall
returns (uint256 token0Amt_, uint256 token1Amt_);
Parameters
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to pay back |
maxToken0Payback_ | uint256 | Maximum amount of token0 to pay back |
maxToken1Payback_ | uint256 | Maximum amount of token1 to pay back |
estimate_ | bool | If true, function will revert with estimated payback amounts without executing the payback |
Returns
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 paid back |
token1Amt_ | uint256 | Amount of token1 paid back |
Structs ​
SwapOutExtras ​
struct SwapOutExtras {
address to;
uint256 amountInMax;
bool isCallback;
}