Liquidity Pool
Module Info
Name:
yuzuswap::liquidity_pool
Description: This module contains the core logic for the liquidity pool of the
yuzuswap
contract. This module only works with fungible assets. If you want to use coins, please check therouter
module, which contains functions to work with coins.
Public Functions
Swap releated functions
The liquidity_pool
uses the "Hot potato"
pattern for swapping feature.
Swap Functions
Swaps tokens in the liquidity pool. This function returns a SwapReciept
object and requires to pay back in the same transaction to complete ("Hot potato"
pattern).
Function arguments
trade
&signer
The trader’s signer.
pool
Object
The liquidity pool.
zero_for_one
bool
Direction of the swap. true
for token 0 to token 1, false
for token 1 to token 0.
is_exact_in
bool
Whether the specified amount is the exact input amount.
specified_amount
u64
The specified amount for the swap.
sqrt_price_limit
u128
The sqrt price limit for the swap.
Returns
FungibleAsset
The swapped fungible asset
SwapReciept
The swap receipt.
SwapReciept
pool
Object
The liquidity pool of the swap.
token_metadata
Object
The metadata of the token in of the swap.
amount_in
u64
The amount of token in needs to be paid for the swap.
Get swap receipt amount
Gets the amount from a SwapReciept
.
Function arguments
swap_receipt
&SwapReciept
The swap receipt.
Returns
u64
The amount in the receipt.
Get swap receipt token metadata
Gets the token metadata from a SwapReciept
.
Function arguments
swap_receipt
&SwapReciept
&SwapReciept
Returns
Object
The token metadata in the receipt.
Pay swap
Pays the swap using the provided token and receipt.
Function arguments
token_in
FungibleAsset
The input fungible asset.
receipt
SwapReciept
The swap receipt.
Quote swap
Quotes a swap in the liquidity pool without executing it.
Function arguments
trader
address
The trader’s address.
pool
Object
The liquidity pool.
zero_for_one
bool
Direction of the swap. true
for token 0 to token 1, false
for token 1 to token 0.
is_exact_in
bool
Whether the specified amount is the exact input amount.
specified_amount
u64
The specified amount for the swap.
sqrt_price_limit
u128
The sqrt price limit for the swap.
Returns
u64
The amount of token in.
u64
The amount of token out.
u64
The fee amount for the swap.
Last updated