Scripts
Module info
Name:
yuzuswap::scripts
Description: This module contains entry functions for users 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.
public entry fun create_pool(
creator: &signer,
token_0: Object<Metadata>,
token_1: Object<Metadata>,
fee: u64,
sqrt_price: u128,****
)
Function arguments
sender
&signer
The sender’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.
public entry fun create_pool_one_coin<Token0>(
creator: &signer,
token_1: Object<Metadata>,
fee: u64,
sqrt_price: u128,
)
Function type arguments
Token0
The coin’s type
Function arguments
sender
&signer
The sender’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.
public entry fun create_pool_both_coins<Coin0, Coin1>(
creator: &signer,
fee: u64,
sqrt_price: u128,
)
Function type arguments
Token1
The coin’s type of the token 0
Token0
The coin’s type of the token 1
Function arguments
sender
&signer
The sender’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.
public entry fun add_liquidity(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
tick_lower: u32,
tick_upper: u32,
amount_0: u64,
amount_1: u64,
amount_0_min: u64,
amount_1_min: u64,
)
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.
amount_0
u64
The amount of token 0 to add to the liquidity.
amount_1
u64
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.
Add liquidity to a pool with one coin and one fungible asset
Adds liquidity to a pool with one coin and one fungible asset.
public entry fun add_liquidity_one_coin<CoinType>(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
tick_lower: u32,
tick_upper: u32,
amount_0: u64,
amount_1: u64,
amount_0_min: u64,
amount_1_min: u64,
)
Function type arguments
CoinType
The coin’s type
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.
amount_0
u64
The amount of token 0 to add to the liquidity.
amount_1
u64
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.
Add liquidity to a pool with two coins
Adds liquidity to a pool with two coins.
public entry fun add_liquidity_both_coins<Coin0, Coin1>(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
tick_lower: u32,
tick_upper: u32,
amount_0: u64,
amount_1: u64,
amount_0_min: u64,
amount_1_min: u64,
)
Function type arguments
Coin0
The coin’s type of the token 0
Coin1
The coin’s type of the token 1
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.
amount_0
u64
The amount of token 0 to add to the liquidity.
amount_1
u64
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.
Remove liquidity |
Remove liquidity from a pool
Removes liquidity from a pool.
public entry fun remove_liquidity(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
liquidity: u128,
amount_0_min: u64,
amount_1_min: u64,
)
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.
Burn position
Burns a position.
public entry fun burn_position(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
)
Function arguments
user
&signer
The user’s signer.
pool
Object
The liquidity pool.
position_id
u64
The position ID to burn.
Collect fee
Collects fee from a position.
public entry fun collect_fee(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
amount_0_requested: u64,
amount_1_requested: u64,
recipient: address,
)
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.
recipient
address
The recipient address.
Collect reward
Collects reward from a position.
public entry fun collect_reward(
user: &signer,
pool: Object<LiquidityPool>,
position_id: u64,
reward_index: u64,
amount_requested: u64,
recipient: address,
)
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.
recipient
address
The recipient address.
Swap functions
Swap exact fungible asset for fungible asset
Swaps an exact amount of fungible asset for another fungible asset.
public entry fun swap_exact_fa_for_fa(
trader: &signer,
pool: Object<LiquidityPool>,
token_in: Object<Metadata>,
amount_in: u64,
amount_out_min: u64,
sqrt_price_limit: u128,
recipient: address,
)
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Object
The input token metadata.
amount_in
u64
The amount of input token.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
recipient
address
The recipient address.
Swap exact coin for fungible asset
Swaps an exact amount of coin for a fungible asset.
public entry fun swap_exact_coin_for_fa<CoinType>(
trader: &signer,
pool: Object<LiquidityPool>,
amount_in: u64,
amount_out_min: u64,
sqrt_price_limit: u128,
recipient: address,
)
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
amount_in
u64
The amount of input coin.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
recipient
address
The recipient address.
Swap fungible asset for exact fungible asset
Swaps a fungible asset for an exact amount of another fungible asset.
public entry fun swap_fa_for_exact_fa(
trader: &signer,
pool: Object<LiquidityPool>,
token_in: Object<Metadata>,
amount_in: u64,
amount_out_min: u64,
sqrt_price_limit: u128,
recipient: address,
)
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
token_in
Object
The input token metadata.
amount_in
u64
The amount of input token.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
recipient
address
The recipient address.
Swap coin for exact fungible asset
Swaps a coin for an exact amount of a fungible asset.
public entry fun swap_coin_for_exact_fa<CoinType>(
trader: &signer,
pool: Object<LiquidityPool>,
amount_in: u64,
amount_out_min: u64,
sqrt_price_limit: u128,
recipient: address,
)
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pool
Object
The liquidity pool.
amount_in
u64
The amount of input coin.
amount_out_min
u64
The minimum amount of output token.
sqrt_price_limit
u128
The sqrt price limit.
recipient
address
The recipient address.
Swap exact fungible asset for fungible asset with multiple hops
Swaps an exact amount of fungible asset for another fungible asset with multiple hops.
public entry fun swap_exact_fa_for_fa_multi_hops(
trader: &signer,
pools: vector<Object<LiquidityPool>>,
token_in: Object<Metadata>,
amount_in: u64,
amount_out_min: u64,
recipient: address,
)
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
Object
The input token metadata.
amount_in
u64
The amount of input token.
amount_out_min
u64
The minimum amount of output token.
recipient
address
The recipient address.
Swap exact coin for fungible asset with multiple hops
Swaps an exact amount of coin for a fungible asset with multiple hops.
public entry fun swap_exact_coin_for_fa_multi_hops<CoinType>(
trader: &signer,
pools: vector<Object<LiquidityPool>>,
amount_in: u64,
amount_out_min: u64,
recipient: address,
)
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
amount_in
u64
The amount of input coin.
amount_out_min
u64
The minimum amount of output token.
recipient
address
The recipient address.
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.
public entry fun swap_fa_for_exact_fa_multi_hops(
trader: &signer,
pools: vector<Object<LiquidityPool>>,
token_in: Object<Metadata>,
amount_in_max: u64,
amount_out_desired: u64,
recipient: address,
)
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
token_in
Object
The input token metadata.
amount_in_max
u64
The maximum amount of input token.
amount_out_desired
u64
The desired amount of output token.
recipient
address
The recipient address.
Swap coin for exact fungible asset with multiple hops
Swaps a coin for an exact amount of a fungible asset with multiple hops.
public entry fun swap_coin_for_exact_fa_multi_hops<CoinType>(
trader: &signer,
pools: vector<Object<LiquidityPool>>,
amount_in_max: u64,
amount_out_desired: u64,
recipient: address,
)
Function type arguments
CoinType
The coin’s type
Function arguments
trader
&signer
The trader’s signer.
pools
vector<Object>
The liquidity pools.
amount_in_max
u64
The maximum amount of input coin.
amount_out_desired
u64
The desired amount of output token.
recipient
address
The recipient address.
Last updated