IFluidDexT1 ​
FluidDexError ​
error FluidDexError(uint256 errorId)
FluidDexSwapResult ​
error FluidDexSwapResult(uint256 amountOut)
used to simulate swap to find the output amount
FluidDexPerfectLiquidityOutput ​
error FluidDexPerfectLiquidityOutput(uint256 token0Amt, uint256 token1Amt)
FluidDexSingleTokenOutput ​
error FluidDexSingleTokenOutput(uint256 tokenAmt)
FluidDexLiquidityOutput ​
error FluidDexLiquidityOutput(uint256 shares)
FluidDexPricesAndExchangeRates ​
error FluidDexPricesAndExchangeRates(struct IFluidDexT1.PricesAndExchangePrice pex_)
DEX_ID ​
function DEX_ID() external view returns (uint256)
returns the dex id
readFromStorage ​
function readFromStorage(bytes32 slot_) external view returns (uint256 result_)
reads uint256 data result_
from storage at a bytes32 storage slot_
key.
Implementations ​
struct Implementations {
address shift;
address admin;
address colOperations;
address debtOperations;
address perfectOperationsAndOracle;
}
ConstantViews ​
struct ConstantViews {
uint256 dexId;
address liquidity;
address factory;
struct IFluidDexT1.Implementations implementations;
address deployerContract;
address token0;
address token1;
bytes32 supplyToken0Slot;
bytes32 borrowToken0Slot;
bytes32 supplyToken1Slot;
bytes32 borrowToken1Slot;
bytes32 exchangePriceToken0Slot;
bytes32 exchangePriceToken1Slot;
uint256 oracleMapping;
}
ConstantViews2 ​
struct ConstantViews2 {
uint256 token0NumeratorPrecision;
uint256 token0DenominatorPrecision;
uint256 token1NumeratorPrecision;
uint256 token1DenominatorPrecision;
}
PricesAndExchangePrice ​
struct PricesAndExchangePrice {
uint256 lastStoredPrice;
uint256 centerPrice;
uint256 upperRange;
uint256 lowerRange;
uint256 geometricMean;
uint256 supplyToken0ExchangePrice;
uint256 borrowToken0ExchangePrice;
uint256 supplyToken1ExchangePrice;
uint256 borrowToken1ExchangePrice;
}
CollateralReserves ​
struct CollateralReserves {
uint256 token0RealReserves;
uint256 token1RealReserves;
uint256 token0ImaginaryReserves;
uint256 token1ImaginaryReserves;
}
DebtReserves ​
struct DebtReserves {
uint256 token0Debt;
uint256 token1Debt;
uint256 token0RealReserves;
uint256 token1RealReserves;
uint256 token0ImaginaryReserves;
uint256 token1ImaginaryReserves;
}
getCollateralReserves ​
function getCollateralReserves(uint256 geometricMean_, uint256 upperRange_, uint256 lowerRange_, uint256 token0SupplyExchangePrice_, uint256 token1SupplyExchangePrice_) external view returns (struct IFluidDexT1.CollateralReserves c_)
getDebtReserves ​
function getDebtReserves(uint256 geometricMean_, uint256 upperRange_, uint256 lowerRange_, uint256 token0BorrowExchangePrice_, uint256 token1BorrowExchangePrice_) external view returns (struct IFluidDexT1.DebtReserves d_)
getPricesAndExchangePrices ​
function getPricesAndExchangePrices() external
constantsView ​
function constantsView() external view returns (struct IFluidDexT1.ConstantViews constantsView_)
constantsView2 ​
function constantsView2() external view returns (struct IFluidDexT1.ConstantViews2 constantsView2_)
Oracle ​
struct Oracle {
uint256 twap1by0;
uint256 lowestPrice1by0;
uint256 highestPrice1by0;
uint256 twap0by1;
uint256 lowestPrice0by1;
uint256 highestPrice0by1;
}
swapIn ​
function swapIn(bool swap0to1_, uint256 amountIn_, uint256 amountOutMin_, address to_) external payable returns (uint256 amountOut_)
This function allows users to swap a specific amount of input tokens for output tokens
Parameters ​
Name | Type | Description |
---|---|---|
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 |
to_ | address | 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 |
Return Values ​
Name | Type | Description |
---|---|---|
amountOut_ | uint256 | The amount of output tokens received from the swap |
swapOut ​
function swapOut(bool swap0to1_, uint256 amountOut_, uint256 amountInMax_, address to_) external payable returns (uint256 amountIn_)
Swap tokens with perfect amount out
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* == ADDRESSDEAD then function will revert with amountIn |
Return Values ​
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The amount of input tokens used for the swap |
depositPerfect ​
function depositPerfect(uint256 shares_, uint256 maxToken0Deposit_, uint256 maxToken1Deposit_, bool estimate_) external payable returns (uint256 token0Amt_, uint256 token1Amt_)
Deposit tokens in equal proportion to the current pool ratio
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 |
Return Values ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 deposited |
token1Amt_ | uint256 | Amount of token1 deposited |
withdrawPerfect ​
function withdrawPerfect(uint256 shares_, uint256 minToken0Withdraw_, uint256 minToken1Withdraw_, address to_) external returns (uint256 token0Amt_, uint256 token1Amt_)
This function allows users to withdraw a perfect amount of collateral liquidity
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* == ADDRESSDEAD then function will revert with token0Amt & token1Amt_ |
Return Values ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 withdrawn |
token1Amt_ | uint256 | The amount of token1 withdrawn |
borrowPerfect ​
function borrowPerfect(uint256 shares_, uint256 minToken0Borrow_, uint256 minToken1Borrow_, address to_) external returns (uint256 token0Amt_, uint256 token1Amt_)
This function allows users to borrow tokens in equal proportion to the current debt pool ratio
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* == ADDRESSDEAD then function will revert with token0Amt & token1Amt_ |
Return Values ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 borrowed |
token1Amt_ | uint256 | Amount of token1 borrowed |
paybackPerfect ​
function paybackPerfect(uint256 shares_, uint256 maxToken0Payback_, uint256 maxToken1Payback_, bool estimate_) external 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 ​
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 |
Return Values ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | Amount of token0 paid back |
token1Amt_ | uint256 | Amount of token1 paid back |
deposit ​
function deposit(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, bool estimate_) external payable returns (uint256 shares_)
This function allows users to deposit tokens in any proportion into the col pool
Parameters ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to deposit |
token1Amt_ | uint256 | The amount of token1 to deposit |
minSharesAmt_ | uint256 | The minimum amount of shares the user expects to receive |
estimate_ | bool | If true, function will revert with estimated shares without executing the deposit |
Return Values ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The amount of shares minted for the deposit |
withdraw ​
function withdraw(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_) external returns (uint256 shares_)
This function allows users to withdraw tokens in any proportion from the col pool
Parameters ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to withdraw |
token1Amt_ | uint256 | The amount of token1 to withdraw |
maxSharesAmt_ | uint256 | The maximum number of shares the user is willing to burn |
to_ | address | 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 shares |
Return Values ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares burned for the withdrawal |
borrow ​
function borrow(uint256 token0Amt_, uint256 token1Amt_, uint256 maxSharesAmt_, address to_) external returns (uint256 shares_)
This function allows users to borrow tokens in any proportion from the debt pool
Parameters ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to borrow |
token1Amt_ | uint256 | The amount of token1 to borrow |
maxSharesAmt_ | uint256 | The maximum amount of shares the user is willing to receive |
to_ | address | 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 shares |
Return Values ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The amount of borrow shares minted to represent the borrowed amount |
payback ​
function payback(uint256 token0Amt_, uint256 token1Amt_, uint256 minSharesAmt_, bool estimate_) external payable returns (uint256 shares_)
This function allows users to payback tokens in any proportion to the debt pool
Parameters ​
Name | Type | Description |
---|---|---|
token0Amt_ | uint256 | The amount of token0 to payback |
token1Amt_ | uint256 | The amount of token1 to payback |
minSharesAmt_ | uint256 | The minimum amount of shares the user expects to burn |
estimate_ | bool | If true, function will revert with estimated shares without executing the payback |
Return Values ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The amount of borrow shares burned for the payback |
withdrawPerfectInOneToken ​
function withdrawPerfectInOneToken(uint256 shares_, uint256 minToken0_, uint256 minToken1_, address to_) external returns (uint256 withdrawAmt_)
This function allows users to withdraw their collateral with perfect shares in one token
Parameters ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to burn for withdrawal |
minToken0_ | uint256 | The minimum amount of token0 the user expects to receive (set to 0 if withdrawing in token1) |
minToken1_ | uint256 | The minimum amount of token1 the user expects to receive (set to 0 if withdrawing in token0) |
to_ | address | 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 withdrawAmt |
Return Values ​
Name | Type | Description |
---|---|---|
withdrawAmt_ | uint256 | The amount of tokens withdrawn in the chosen token |
paybackPerfectInOneToken ​
function paybackPerfectInOneToken(uint256 shares_, uint256 maxToken0_, uint256 maxToken1_, bool estimate_) external payable returns (uint256 paybackAmt_)
This function allows users to payback their debt with perfect shares in one token
Parameters ​
Name | Type | Description |
---|---|---|
shares_ | uint256 | The number of shares to burn for payback |
maxToken0_ | uint256 | The maximum amount of token0 the user is willing to pay (set to 0 if paying back in token1) |
maxToken1_ | uint256 | The maximum amount of token1 the user is willing to pay (set to 0 if paying back in token0) |
estimate_ | bool | If true, the function will revert with the estimated payback amount without executing the payback |
Return Values ​
Name | Type | Description |
---|---|---|
paybackAmt_ | uint256 | The amount of tokens paid back in the chosen token |
oraclePrice ​
function oraclePrice(uint256[] secondsAgos_) external view returns (struct IFluidDexT1.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 ​
Name | Type | Description |
---|---|---|
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 ​
Name | Type | Description |
---|---|---|
twaps_ | struct IFluidDexT1.Oracle[] | twap price, lowest price (aka minima) & highest price (aka maxima) between secondsAgo checkpoints |
currentPrice_ | uint256 | price of pool after the most recent swap |