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 ​
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_ | struct FluidDexT1PerfectOperationsAndSwapOut.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 |
Return Values ​
Name | Type | Description |
---|---|---|
amountIn_ | uint256 | The 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 ​
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 |
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 ​
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 ​
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 ​
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 ​
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 ​
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 ​
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 ​
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 ​
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 ​
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 |