Skip to content

IDexCallback ​

dexCallback ​

solidity
function dexCallback(address token_, uint256 amount_) external

FluidDexT1 ​

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

SwapInExtras ​

solidity
struct SwapInExtras {
  address to;
  uint256 amountOutMin;
  bool isCallback;
}

_swapIn ​

solidity
function _swapIn(bool swap0to1_, uint256 amountIn_, struct FluidDexT1.SwapInExtras extras_) internal returns (uint256 amountOut_)

This function allows users to swap a specific amount of input tokens for output tokens

Parameters ​

NameTypeDescription
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
extras_struct FluidDexT1.SwapInExtrasAdditional parameters for the swap: - to: Recipient of swapped tokens. If to* == address(0) then out tokens will be sent to msg.sender. If to* == ADDRESSDEAD then function will revert with amountOut - amountOutMin: The minimum amount of output tokens the user expects to receive - isCallback: If true, indicates that the input tokens should be transferred via a callback

Return Values ​

NameTypeDescription
amountOut_uint256The amount of output tokens received from the swap

swapIn ​

solidity
function swapIn(bool swap0to1_, uint256 amountIn_, uint256 amountOutMin_, address to_) public payable returns (uint256 amountOut_)

Swap tokens with perfect amount in

Parameters ​

NameTypeDescription
swap0to1_boolDirection of swap. If true, swaps token0 for token1; if false, swaps token1 for token0
amountIn_uint256The exact amount of tokens to swap in
amountOutMin_uint256The minimum amount of tokens to receive after swap
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 amountOut

Return Values ​

NameTypeDescription
amountOut_uint256The amount of output tokens received from the swap

swapInWithCallback ​

solidity
function swapInWithCallback(bool swap0to1_, uint256 amountIn_, uint256 amountOutMin_, address to_) public payable returns (uint256 amountOut_)

Swap tokens with perfect amount in and callback functionality

Parameters ​

NameTypeDescription
swap0to1_boolDirection of swap. If true, swaps token0 for token1; if false, swaps token1 for token0
amountIn_uint256The exact amount of tokens to swap in
amountOutMin_uint256The minimum amount of tokens to receive after swap
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 amountOut

Return Values ​

NameTypeDescription
amountOut_uint256The amount of output tokens received from 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 withdrawn 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 borrowed 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

deposit ​

solidity
function deposit(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, bool estimate_) public payable returns (uint256 shares_)

This function allows users to deposit tokens in any proportion into the col pool

Parameters ​

NameTypeDescription
token0Amt_uint256The amount of token0 to deposit
token1Amt_uint256The amount of token1 to deposit
minSharesAmt_uint256The minimum amount of shares the user expects to receive
estimate_boolIf true, function will revert with estimated shares without executing the deposit

Return Values ​

NameTypeDescription
shares_uint256The amount of shares minted for the deposit

withdraw ​

solidity
function withdraw(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_) public returns (uint256 shares_)

This function allows users to withdraw tokens in any proportion from the col pool

Parameters ​

NameTypeDescription
token0Amt_uint256The amount of token0 to withdraw
token1Amt_uint256The amount of token1 to withdraw
maxSharesAmt_uint256The maximum number of shares the user is willing to burn
to_addressRecipient of withdrawn tokens. If to* == address(0) then out tokens will be sent to msg.sender. If to* == ADDRESSDEAD then function will revert with shares

Return Values ​

NameTypeDescription
shares_uint256The number of shares burned for the withdrawal

borrow ​

solidity
function borrow(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_) public returns (uint256 shares_)

This function allows users to borrow tokens in any proportion from the debt pool

Parameters ​

NameTypeDescription
token0Amt_uint256The amount of token0 to borrow
token1Amt_uint256The amount of token1 to borrow
maxSharesAmt_uint256The maximum amount of shares the user is willing to receive
to_addressRecipient of borrowed tokens. If to* == address(0) then out tokens will be sent to msg.sender. If to* == ADDRESSDEAD then function will revert with shares

Return Values ​

NameTypeDescription
shares_uint256The amount of borrow shares minted to represent the borrowed amount

payback ​

solidity
function payback(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, bool estimate_) public payable returns (uint256 shares_)

This function allows users to payback tokens in any proportion to the debt pool

Parameters ​

NameTypeDescription
token0Amt_uint256The amount of token0 to payback
token1Amt_uint256The amount of token1 to payback
minSharesAmt_uint256The minimum amount of shares the user expects to burn
estimate_boolIf true, function will revert with estimated shares without executing the payback

Return Values ​

NameTypeDescription
shares_uint256The amount of borrow shares burned for the payback

withdrawPerfectInOneToken ​

solidity
function withdrawPerfectInOneToken(uint256 shares_, uint256 minToken0_, uint256 minToken1_, address to_) public returns (uint256 withdrawAmt_)

This function allows users to withdraw their collateral with perfect shares in one token

Parameters ​

NameTypeDescription
shares_uint256The number of shares to burn for withdrawal
minToken0_uint256The minimum amount of token0 the user expects to receive (set to 0 if withdrawing in token1)
minToken1_uint256The minimum amount of token1 the user expects to receive (set to 0 if withdrawing in token0)
to_addressRecipient of withdrawn tokens. If to* == address(0) then out tokens will be sent to msg.sender. If to* == ADDRESSDEAD then function will revert with withdrawAmt

Return Values ​

NameTypeDescription
withdrawAmt_uint256The amount of tokens withdrawn in the chosen token

paybackPerfectInOneToken ​

solidity
function paybackPerfectInOneToken(uint256 shares_, uint256 maxToken0_, uint256 maxToken1_, bool estimate_) public payable returns (uint256 paybackAmt_)

This function allows users to payback their debt with perfect shares in one token

Parameters ​

NameTypeDescription
shares_uint256The number of shares to burn for payback
maxToken0_uint256The maximum amount of token0 the user is willing to pay (set to 0 if paying back in token1)
maxToken1_uint256The maximum amount of token1 the user is willing to pay (set to 0 if paying back in token0)
estimate_boolIf true, the function will revert with the estimated payback amount without executing the payback

Return Values ​

NameTypeDescription
paybackAmt_uint256The amount of tokens paid back in the chosen token

liquidityCallback ​

solidity
function liquidityCallback(address token_, uint256 amount_, bytes data_) external

liquidity callback for cheaper token transfers in case of deposit or payback. only callable by Liquidity during an operation.

oraclePrice ​

solidity
function oraclePrice(uint256[] secondsAgos_) external view returns (struct Structs.Oracle[] twaps_, uint256 currentPrice_)

the oracle assumes last set price of pool till the next swap happens. There's a possibility that during that time some interest is generated hence the last stored price is not the 100% correct price for the whole duration but the difference due to interest will be super low so this difference is ignored For example 2 swaps happened 10min (600 seconds) apart and 1 token has 10% higher interest than other. then that token will accrue about 10% * 600 / secondsInAYear = ~0.0002%

Parameters ​

NameTypeDescription
secondsAgos_uint256[]array of seconds ago for which TWAP is needed. If user sends [10, 30, 60] then twaps_ will return [10-0, 30-10, 60-30]

Return Values ​

NameTypeDescription
twaps_struct Structs.Oracle[]twap price, lowest price (aka minima) & highest price (aka maxima) between secondsAgo checkpoints
currentPrice_uint256price of pool after the most recent swap

getPricesAndExchangePrices ​

solidity
function getPricesAndExchangePrices() public

fallback ​

solidity
fallback() external payable

receive ​

solidity
receive() external payable

constantsView ​

solidity
function constantsView() external view returns (struct Structs.ConstantViews constantsView_)

returns all Vault constants

constantsView2 ​

solidity
function constantsView2() external view returns (struct Structs.ConstantViews2 constantsView2_)

returns all Vault constants

getCollateralReserves ​

solidity
function getCollateralReserves(uint256 geometricMean_, uint256 upperRange_, uint256 lowerRange_, uint256 token0SupplyExchangePrice_, uint256 token1SupplyExchangePrice_) public view returns (struct Structs.CollateralReserves c_)

Calculates the real and imaginary reserves for collateral tokens

This function retrieves the supply of both tokens from the liquidity layer, adjusts them based on exchange prices, and calculates imaginary reserves based on the geometric mean and price range

Parameters ​

NameTypeDescription
geometricMean_uint256The geometric mean of the token prices
upperRange_uint256The upper price range
lowerRange_uint256The lower price range
token0SupplyExchangePrice_uint256The exchange price for token0 from liquidity layer
token1SupplyExchangePrice_uint256The exchange price for token1 from liquidity layer

Return Values ​

NameTypeDescription
c_struct Structs.CollateralReservesA struct containing the calculated real and imaginary reserves for both tokens: - token0RealReserves: The real reserves of token0 - token1RealReserves: The real reserves of token1 - token0ImaginaryReserves: The imaginary reserves of token0 - token1ImaginaryReserves: The imaginary reserves of token1

getDebtReserves ​

solidity
function getDebtReserves(uint256 geometricMean_, uint256 upperRange_, uint256 lowerRange_, uint256 token0BorrowExchangePrice_, uint256 token1BorrowExchangePrice_) public view returns (struct Structs.DebtReserves d_)

Calculates the debt reserves for both tokens

Parameters ​

NameTypeDescription
geometricMean_uint256The geometric mean of the upper and lower price ranges
upperRange_uint256The upper price range
lowerRange_uint256The lower price range
token0BorrowExchangePrice_uint256The exchange price of token0 from liquidity layer
token1BorrowExchangePrice_uint256The exchange price of token1 from liquidity layer

Return Values ​

NameTypeDescription
d_struct Structs.DebtReservesThe calculated debt reserves for both tokens, containing: - token0Debt: The debt amount of token0 - token1Debt: The debt amount of token1 - token0RealReserves: The real reserves of token0 derived from token1 debt - token1RealReserves: The real reserves of token1 derived from token0 debt - token0ImaginaryReserves: The imaginary debt reserves of token0 - token1ImaginaryReserves: The imaginary debt reserves of token1