Public Functions and Their Integration
1. Pool Registration
- Function:
register_pool<X, Y, Curve>(account: &signer) - Purpose: This function allows the registration of new pools dynamically.
- Integration:
Provide parameters
(X, Y, Curve)during the contract’s deployment or via an admin function.
2. Add Liquidity
-
Function:
add_liquidity<X, Y, Curve>(user: address, coin_x: Coin<X>, min_coin_x_val: u64, coin_y: Coin<Y>, min_coin_y_val: u64) -
Purpose: Adds liquidity to an existing pool with specified minimum amounts for
XandY. Returns any leftover coins and minted LP tokens. -
Integration:
- Used by liquidity providers to contribute to a pool.
- Ensure inputs
(coin_x, coin_y)match the pool’s requirements. - Calculate optimal amounts and validate user inputs before calling.
3. Remove Liquidity
- Function:
remove_liquidity<X, Y, Curve>(user: address, lp_coins: Coin<LP<X, Y, Curve>>, min_x_out_val: u64, min_y_out_val: u64) - Purpose: Burns LP tokens to retrieve the underlying assets (
XandY) while enforcing minimum output amounts.
4. Swap Exact Coin for Coin
- Function:
swap_exact_coin_for_coin<X, Y, Curve>(user: address, coin_in: Coin<X>, coin_out_min_val: u64) - Purpose: Swaps an exact amount of input coins (
X) for output coins (Y), ensuring the output is above a minimum threshold.
5. Swap Coin for Exact Coin
- Function:
swap_coin_for_exact_coin<X, Y, Curve>(user: address, coin_max_in: Coin<X>, coin_out_val: u64) - Purpose: Swaps a portion of input coins (X) to get an exact amount of output coins (Y), ensuring the input does not exceed a specified maximum.
- Integration:
- Typically used for trades where the output amount is critical (e.g., paying an exact bill).
- Users should be informed about potential slippage.