Router
Module info
Name:
yuzuswap::router
Description: This module contains public functions for other modules/contracts to call and interact with the
yuzuswap
contract.
Public Functions
Create Pool
Create pool with two fungible assets
Creates a new liquidity pool for two fungible assets. Reverts if the pool already exists.
Function arguments
creator
&signer
The creator’s signer
token_0
Object
Fungible asset metadata of token 0
token_1
Object
Fungible asset metadata of token 1
fee
u64
Fee tier of the pool
sqrt_price
u128
Initial sqrt price of the pool
Create pool with one coin and one fungible asset
Creates a new liquidity pool with one coin (Token0
) and one fungible asset. Reverts if the pool already exists.
Function type arguments
Token0
The coin’s type.
Function arguments
creator
&signer
The creator’s signer
token_1
Object
Fungible asset metadata of token 1
fee
u64
Fee tier of the pool
sqrt_price
u128
Initial sqrt price of the pool
Create pool with two coins
Creates a new liquidity pool with two coins Token0
and Token1
. Reverts if the pool already exists.
Function type arguments
Coin0
The coin’s type of the token 0
Coin1
The coin’s type of the token 1
Function arguments
creator
&signer
The creator’s signer.
fee
u64
Fee tier of the pool.
sqrt_price
u128
Initial sqrt price of the pool.
Add liquidity
Add liquidity to a pool with two fungible assets
Adds liquidity to a pool with two fungible assets.
Function arguments
user
&signer
The user’s signer.
pool
Object
The liquidity pool to add liquidity to.
position_id
u64
The position ID of the liquidity. Leave it as 0 if you want to create a new position or you don’t have any position yet.
tick_lower
u32
The lower tick of the liquidity. Required in the case of creating a new position. Otherwise, leave it as 0.
tick_upper
u32
The upper tick of the liquidity. Required in the case of creating a new position. Otherwise, leave it as 0.
token_0
FungibleAsset
The amount of token 0 to add to the liquidity.
token_1
FungibleAsset
The amount of token 1 to add to the liquidity.
amount_0_min
u64
The minimum amount of token 0 to add to the liquidity.
amount_1_min
u64
The minimum amount of token 1 to add to the liquidity.
Returns
(FungibleAsset, FungibleAsset)
The added fungible assets.
Remove liquidity from a pool
Removes liquidity from a pool.
Function arguments
user
&signer
The user’s signer.
pool
Object
The liquidity pool to remove liquidity from.
position_id
u64
The position ID of the liquidity.
liquidity
u128
The amount of liquidity to remove.
amount_0_min
u64
The minimum amount of token 0 to get.
amount_1_min
u64
The minimum amount of token 1 to get.
Returns
FungibleAsset
The returned fungible assets of the token 0 after removing liquidity.
FungibleAsset
The returned fungible assets of the token 1 after removing liquidity.
Collect fee
Collects fee from a position.
Function arguments
user
&signer
The user’s signer.
pool
Object
The liquidity pool.
position_id
u64
The position ID.
amount_0_requested
u64
The amount of token 0 requested.
amount_1_requested
u64
The amount of token 1 requested.
Returns
FungibleAsset
The collected fee of the token 0.
FungibleAsset
The collected fee of the token 1.
Collect reward
Collects reward from a position.
Function arguments
user
&signer
The user’s signer.
pool
Object
The liquidity pool.
position_id
u64
The position ID.
reward_index
u64
The reward index.
amount_requested
u64
The amount of reward requested.
Returns
FungibleAsset
The collected reward.
Swap functions
Swap exact fungible asset for fungible asset
Swaps an exact amount of fungible asset for another fungible asset.
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
FungibleAsset
The input token.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
FungibleAsset
The swapped fungible asset.
Swap exact fungible asset for coin
Swaps an exact amount of fungible asset for a coin.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
FungibleAsset
The input token.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
Coin
The swapped coin.
Swap exact coin for fungible asset
Swaps an exact amount of coin for a fungible asset.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Coin
The input coin.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
FungibleAsset
The swapped fungible asset.
Swap exact coin for coin
Swaps an exact amount of coin for another coin.
Function type arguments
CoinIn
The input coin’s type
CoinOut
The output coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Coin
The input coin.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
Coin
The swapped coin.
Swap fungible asset for exact fungible asset
Swaps a fungible asset for an exact amount of another fungible asset.
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
FungibleAsset
The input token.
amount_out_desired
u64
The desired amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
FungibleAsset
The remaining fungible asset of the input token.
FungibleAsset
The swapped fungible asset of the output token.
Swap fungible asset for exact coin
Swaps a fungible asset for an exact amount of a coin.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
FungibleAsset
The input token.
amount_out_desired
u64
The desired amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
FungibleAsset
The remaining fungible asset of the input token.
Coin
The swapped coin of the output token.
Swap coin for exact fungible asset
Swaps a coin for an exact amount of a fungible asset.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Coin
The input coin.
amount_out_desired
u64
The desired amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
Coin
The remaining coin of the input token.
FungibleAsset
The swapped fungible asset of the output token.
Swap coin for exact coin
Swaps a coin for an exact amount of another coin.
Function type arguments
CoinIn
The input coin’s type
CoinOut
The output coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Coin
The input coin.
amount_out_desired
u64
The desired amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
Coin
The remaining coin of the input token.
Coin
The swapped coin of the output token.
Swap exact fungible asset for fungible asset with multiple hops
Swaps an exact amount of fungible asset for another fungible asset with multiple hops.
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
FungibleAsset
The input token.
amount_out_min
u64
The minimum amount of output token.
Returns
FungibleAsset
The swapped fungible asset.
Swap exact coin for fungible asset with multiple hops
Swaps an exact amount of coin for a fungible asset with multiple hops.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
Coin
The input coin.
amount_out_min
u64
The minimum amount of output token.
Returns
FungibleAsset
The swapped fungible asset.
Swap fungible asset for exact fungible asset with multiple hops
Swaps a fungible asset for an exact amount of another fungible asset with multiple hops.
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
FungibleAsset
The input token.
amount_out_desired
u64
The desired amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
Returns
FungibleAsset
The remaining fungible asset of the input token.
FungibleAsset
The swapped fungible asset of the output token.
Swap coin for exact fungible asset with multiple hops
Swaps a coin for an exact amount of a fungible asset with multiple hops.
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
Coin
The input coin.
amount_out_desired
u64
The desired amount of output token.
Returns
Coin
The remaining coin of the input token.
FungibleAsset
The swapped fungible asset of the output token.
Get pool functions
Get pool
Gets the liquidity pool for two fungible assets.
Function arguments
token_0
Object
Fungible asset metadata of token 0
token_1
Object
Fungible asset metadata of token 1
fee
u64
Fee tier of the pool
Returns
Object
The liquidity pool.
Get pool with one coin and one fungible asset
Gets the liquidity pool for one coin (CoinType
) and one fungible asset.
Function type arguments
CoinType
The coin’s type
Function arguments
token_1
Object
Fungible asset metadata of token 1
fee
u64
Fee tier of the pool
Returns
Object
The liquidity pool.
Get pool with two coins
Gets the liquidity pool for two coins Coin0
and Coin1
.
Function type arguments
Coin0
The coin’s type of the token 0
Coin1
The coin’s type of the token 1
Function arguments
fee
u64
Fee tier of the pool
Returns
Object
The liquidity pool.
Last updated