Skip to content

FluidDexT1PerfectOperationsAndSwapOut ​

Git Source

Inherits:UserHelpers

Implements core logics for Fluid Dex protocol. Note Token transfers happen directly from user to Liquidity contract and vice-versa.

Functions ​

constructor ​

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

_onlyDelegateCall ​

solidity
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

solidity
function _swapOut(bool swap0to1_, uint256 amountOut_, SwapOutExtras memory extras_)
    internal
    _onlyDelegateCall
    returns (uint256 amountIn_);

Parameters

NameTypeDescription
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
extras_SwapOutExtrasAdditional 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

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

swapOut ​

Swap tokens with perfect amount out

solidity
function swapOut(bool swap0to1_, uint256 amountOut_, uint256 amountInMax_, address to_)
    public
    payable
    _onlyDelegateCall
    returns (uint256 amountIn_);

Parameters

NameTypeDescription
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
to_addressRecipient 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

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

swapOutWithCallback ​

Swap tokens with perfect amount out and callback functionality

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

Parameters

NameTypeDescription
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
to_addressRecipient 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

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

depositPerfect ​

Deposit tokens in equal proportion to the current pool ratio

solidity
function depositPerfect(uint256 shares_, uint256 maxToken0Deposit_, uint256 maxToken1Deposit_, bool estimate_)
    public
    payable
    _onlyDelegateCall
    returns (uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to mint
maxToken0Deposit_uint256Maximum amount of token0 to deposit
maxToken1Deposit_uint256Maximum amount of token1 to deposit
estimate_boolIf true, function will revert with estimated deposit amounts without executing the deposit

Returns

NameTypeDescription
token0Amt_uint256Amount of token0 deposited
token1Amt_uint256Amount of token1 deposited

withdrawPerfect ​

This function allows users to withdraw a perfect amount of collateral liquidity

solidity
function withdrawPerfect(uint256 shares_, uint256 minToken0Withdraw_, uint256 minToken1Withdraw_, address to_)
    public
    _onlyDelegateCall
    returns (uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to withdraw
minToken0Withdraw_uint256The minimum amount of token0 the user is willing to accept
minToken1Withdraw_uint256The minimum amount of token1 the user is willing to accept
to_addressRecipient 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

NameTypeDescription
token0Amt_uint256The amount of token0 withdrawn
token1Amt_uint256The amount of token1 withdrawn

borrowPerfect ​

This function allows users to borrow tokens in equal proportion to the current debt pool ratio

solidity
function borrowPerfect(uint256 shares_, uint256 minToken0Borrow_, uint256 minToken1Borrow_, address to_)
    public
    _onlyDelegateCall
    returns (uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to borrow
minToken0Borrow_uint256Minimum amount of token0 to borrow
minToken1Borrow_uint256Minimum amount of token1 to borrow
to_addressRecipient 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

NameTypeDescription
token0Amt_uint256Amount of token0 borrowed
token1Amt_uint256Amount of token1 borrowed

paybackPerfect ​

This function allows users to pay back borrowed tokens in equal proportion to the current debt pool ratio

solidity
function paybackPerfect(uint256 shares_, uint256 maxToken0Payback_, uint256 maxToken1Payback_, bool estimate_)
    public
    payable
    _onlyDelegateCall
    returns (uint256 token0Amt_, uint256 token1Amt_);

Parameters

NameTypeDescription
shares_uint256The number of shares to pay back
maxToken0Payback_uint256Maximum amount of token0 to pay back
maxToken1Payback_uint256Maximum amount of token1 to pay back
estimate_boolIf true, function will revert with estimated payback amounts without executing the payback

Returns

NameTypeDescription
token0Amt_uint256Amount of token0 paid back
token1Amt_uint256Amount of token1 paid back

Structs ​

SwapOutExtras ​

solidity
struct SwapOutExtras {
    address to;
    uint256 amountInMax;
    bool isCallback;
}