Skip to content

FluidDexT1PerfectOperationsAndSwapOut ​

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

constructor ​

solidity
constructor(struct Structs.ConstantViews constantViews_) public

_onlyDelegateCall ​

solidity
modifier _onlyDelegateCall()

SwapOutExtras ​

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

_swapOut ​

solidity
function _swapOut(bool swap0to1_, uint256 amountOut_, struct FluidDexT1PerfectOperationsAndSwapOut.SwapOutExtras extras_) internal returns (uint256 amountIn_)

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

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_struct FluidDexT1PerfectOperationsAndSwapOut.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

Return Values ​

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

swapOut ​

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

Swap tokens with perfect amount out

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* == ADDRESSDEAD then function will revert with amountIn

Return Values ​

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

swapOutWithCallback ​

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

Swap tokens with perfect amount out and callback functionality

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* == ADDRESSDEAD then function will revert with amountIn

Return Values ​

NameTypeDescription
amountIn_uint256The amount of input tokens used for the swap

depositPerfect ​

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

Deposit tokens in equal proportion to the current pool ratio

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

Return Values ​

NameTypeDescription
token0Amt_uint256Amount of token0 deposited
token1Amt_uint256Amount of token1 deposited

withdrawPerfect ​

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

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

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* == ADDRESSDEAD then function will revert with token0Amt & token1Amt_

Return Values ​

NameTypeDescription
token0Amt_uint256The amount of token0 withdrawn
token1Amt_uint256The amount of token1 withdrawn

borrowPerfect ​

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

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

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* == ADDRESSDEAD then function will revert with token0Amt & token1Amt_

Return Values ​

NameTypeDescription
token0Amt_uint256Amount of token0 borrowed
token1Amt_uint256Amount of token1 borrowed

paybackPerfect ​

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

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

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

Return Values ​

NameTypeDescription
token0Amt_uint256Amount of token0 paid back
token1Amt_uint256Amount of token1 paid back