Coin Entry Module
Module Info
- Package Name:
AtmosSwap
- Address:
atmos_swap=0xa4a4a31116e114bf3c4f4728914e6b43db73279a4421b0768993e07248fe2234
- Module:
atmos_swap::atmos_entry_coin
- This module provides a interface for interacting with Atmos Swap pools using both legacy coin types and fungible assets. It handles seamless coin-to-fungible asset conversions and manages pool operations through entry functions. Users can interact with pools using either coin types or fungible assets directly, with the module automatically handling the necessary conversions and compatibility layer between different asset formats.
Structs
Placeholder
struct Placeholder {}
Empty struct used as a placeholder for generic type parameters when fewer than maximum supported tokens are used.
Public Entry Functions
Liquidity Management
Add Liquidity (Stable Pool)
public entry fun add_liquidity_stable<T0, T1, T2, T3, T4, T5>(
user: &signer,
pool: object::Object<liquidity_pool::Pool>,
amounts: vector<u64>,
min_lp_amount: u64
)
Adds liquidity to a stable pool by converting and depositing multiple coins. Converts provided coin amounts to fungible assets and adds them to the pool. Mints and deposits LP tokens to the user's account.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | Account performing the liquidity addition |
pool | Object<Pool> | Target pool to add liquidity to |
amounts | vector<u64> | Vector of token amounts to deposit |
min_lp_amount | u64 | Minimum acceptable LP tokens to receive |
Aborts
- If received LP tokens are less than
min_lp_amount
- If user has insufficient balance for any token
Add Liquidity (Weighted Pool)
public entry fun add_liquidity_weighted<T0, T1, T2, T3>(
user: &signer,
pool: object::Object<liquidity_pool::Pool>,
amounts: vector<u64>,
min_lp_amount: u64
)
Adds liquidity to a weighted pool by converting and depositing multiple coins. Handles refund of excess tokens if optimal ratios aren't met. Mints and deposits LP tokens to the user's account.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | Account performing the liquidity addition |
pool | Object<Pool> | Target pool to add liquidity to |
amounts | vector<u64> | Vector of token amounts to deposit |
min_lp_amount | u64 | Minimum acceptable LP tokens to receive |
Aborts
- If received LP tokens are less than
min_lp_amount
- If user has insufficient balance for any token
Remove Liquidity
public entry fun remove_liquidity_entry<T0, T1, T2, T3>(
user: &signer,
pool: object::Object<liquidity_pool::Pool>,
lp_token: object::Object<fungible_asset::Metadata>,
lp_amount: u64,
min_amounts: vector<u64>
)
Remove liquidity from a pool by burning LP tokens and receiving underlying assets.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | The signer of the user account removing liquidity |
pool | Object<Pool> | The pool object to remove liquidity from |
lp_token | Object<Metadata> | LP token metadata object |
lp_amount | u64 | Amount of LP tokens to burn |
min_amounts | vector<u64> | Minimum amounts of tokens to receive |
Aborts
- If
lp_amount
is zero - If user has insufficient LP tokens
- If received amounts are less than minimum amounts
Pool Creation
Create Stable Pool
public entry fun create_pool_stable<T0, T1, T2, T3, T4, T5>(
user: &signer,
metadata_objects_a: vector<address>,
initial_amounts: vector<u64>,
swap_fee_bps: u64,
amp_factor: u64
)
Creates a new stable pool with the specified parameters and initial liquidity. Initial LP tokens are minted to the pool creator.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | Account creating the pool |
metadata_objects | vector<address> | Addresses of metadata for each token in the pool (sorted in ascending order) |
initial_amounts | vector<u64> | Initial deposit amounts for each token |
swap_fee_bps | u64 | Trading fee in basis points (1 bp = 0.01%) valid values for swap fee bs are - (1 (0.01%) , 5(0.05%), 10(0.1%), 30(0.3%), 100(1%)) |
amp_factor | u64 | Amplification coefficient for the stable pool |
Aborts
- If swap fee is invalid
- If amp factor is out of valid range
- If user has insufficient balance for initial deposits
Create Weighted Pool
public entry fun create_pool_weighted<T0, T1, T2, T3>(
user: &signer,
metadata_objects: vector<address>,
initial_amounts: vector<u64>,
weights: vector<u64>,
swap_fee_bps: u64
)
Creates a new weighted pool with the specified parameters and initial liquidity. Initial LP tokens are minted to the pool creator.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | Account creating the pool |
metadata_objects | vector<address> | Addresses of metadata for each token in the pool(sorted in ascending order) |
initial_amounts | vector<u64> | Initial deposit amounts for each token |
weights | vector<u64> | Weight for each token in the pool |
swap_fee_bps | u64 | Trading fee in basis points (1 bp = 0.01%) valid values for swap fee are - (1 (0.01%) , 5(0.05%), 10(0.1%), 30(0.3%), 100(1%)) |
Aborts
- If swap fee is invalid
- If weights don't sum to WEIGHT_SCALE
- If user has insufficient balance for initial deposits
Swap Functions
Exact Input Swaps
Stable Swap (Exact In)
public entry fun swap_exact_in_stable<CoinIn, CoinOut>(
user: &signer,
pool: object::Object<liquidity_pool::Pool>,
input_fa: object::Object<fungible_asset::Metadata>,
input_amount: u64,
output_fa: object::Object<fungible_asset::Metadata>,
min_output_amount: u64
)
Performs a stable swap with exact input amount. Deposits input tokens and withdraws output tokens.
Function Arguments
Argument | Type | Description |
---|---|---|
user | &signer | Account performing the swap |
pool | Object<Pool> | Pool to execute swap in |
input_fa | Object<Metadata> | Input token metadata |
input_amount | u64 | Exact amount to swap in |
output_fa | Object<Metadata> | Output token metadata |
min_output_amount | u64 | Minimum output tokens to receive |
Aborts
- If slippage exceeds minimum output amount
- If pool is paused or input amount is invalid
Weighted Swap (Exact In)
public entry fun swap_exact_in_weighted<CoinIn, CoinOut>(
signer: &signer,
pool: object::Object<liquidity_pool::Pool>,
input_fa: object::Object<fungible_asset::Metadata>,
input_amount: u64,
output_fa: object::Object<fungible_asset::Metadata>,
min_output_amount: u64
)
Performs a weighted swap with exact input amount. Deposits input tokens and withdraws output tokens.
Function Arguments
Argument | Type | Description |
---|---|---|
signer | &signer | Account performing the swap |
pool | Object<Pool> | Pool to execute swap in |
input_fa | Object<Metadata> | Input token metadata |
input_amount | u64 | Exact amount to swap in |
output_fa | Object<Metadata> | Output token metadata |
min_output_amount | u64 | Minimum output tokens to receive |
Aborts
- If slippage exceeds minimum output amount
- If pool is paused or input amount is invalid
Exact Output Swaps
Stable Swap (Exact Out)
public entry fun swap_exact_out_stable<CoinIn, CoinOut>(
signer: &signer,
pool: object::Object<liquidity_pool::Pool>,
input_fa: object::Object<fungible_asset::Metadata>,
max_input_amount: u64,
output_fa: object::Object<fungible_asset::Metadata>,
output_amount: u64
)
Performs a stable swap with exact output amount. Deposits input tokens and withdraws output tokens.
Function Arguments
Argument | Type | Description |
---|---|---|
signer | &signer | Account performing the swap |
pool | Object<Pool> | Pool to execute swap in |
input_fa | Object<Metadata> | Input token metadata |
max_input_amount | u64 | Maximum input tokens willing to pay |
output_fa | Object<Metadata> | Output token metadata |
output_amount | u64 | Exact amount of output tokens to receive |
Aborts
- If required input exceeds maximum input amount
- If pool is paused or output amount is invalid
Weighted Swap (Exact Out)
public entry fun swap_exact_out_weighted<CoinIn, CoinOut>(
signer: &signer,
pool: object::Object<liquidity_pool::Pool>,
input_fa: object::Object<fungible_asset::Metadata>,
max_input_amount: u64,
output_fa: object::Object<fungible_asset::Metadata>,
output_amount: u64
)
Performs a weighted swap with exact output amount. Deposits input tokens and withdraws output tokens.
Function Arguments
Argument | Type | Description |
---|---|---|
signer | &signer | Account performing the swap |
pool | Object<Pool> | Pool to execute swap in |
input_fa | Object<Metadata> | Input token metadata |
max_input_amount | u64 | Maximum input tokens willing to pay |
output_fa | Object<Metadata> | Output token metadata |
output_amount | u64 | Exact amount of output tokens to receive |
Aborts
- If required input exceeds maximum input amount
- If pool is paused or output amount is invalid
Error Codes
Code | Name | Description |
---|---|---|
100 | EINVALID_AMOUNT | Invalid amount of tokens |
101 | EBALANCE_TOO_LOW | Insufficient balance |
102 | EINVALID_VECTOR_LENGTH | Invalid vector length |
103 | EINSUFFICIENT_OUTPUT_AMOUNT | Insufficient output amount |
104 | EINVALID_COIN_VERSION | Invalid output coin version |