Skip to main content

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

ArgumentTypeDescription
user&signerAccount performing the liquidity addition
poolObject<Pool>Target pool to add liquidity to
amountsvector<u64>Vector of token amounts to deposit
min_lp_amountu64Minimum 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

ArgumentTypeDescription
user&signerAccount performing the liquidity addition
poolObject<Pool>Target pool to add liquidity to
amountsvector<u64>Vector of token amounts to deposit
min_lp_amountu64Minimum 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

ArgumentTypeDescription
user&signerThe signer of the user account removing liquidity
poolObject<Pool>The pool object to remove liquidity from
lp_tokenObject<Metadata>LP token metadata object
lp_amountu64Amount of LP tokens to burn
min_amountsvector<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

ArgumentTypeDescription
user&signerAccount creating the pool
metadata_objectsvector<address>Addresses of metadata for each token in the pool (sorted in ascending order)
initial_amountsvector<u64>Initial deposit amounts for each token
swap_fee_bpsu64Trading 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_factoru64Amplification 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

ArgumentTypeDescription
user&signerAccount creating the pool
metadata_objectsvector<address>Addresses of metadata for each token in the pool(sorted in ascending order)
initial_amountsvector<u64>Initial deposit amounts for each token
weightsvector<u64>Weight for each token in the pool
swap_fee_bpsu64Trading 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

ArgumentTypeDescription
user&signerAccount performing the swap
poolObject<Pool>Pool to execute swap in
input_faObject<Metadata>Input token metadata
input_amountu64Exact amount to swap in
output_faObject<Metadata>Output token metadata
min_output_amountu64Minimum 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

ArgumentTypeDescription
signer&signerAccount performing the swap
poolObject<Pool>Pool to execute swap in
input_faObject<Metadata>Input token metadata
input_amountu64Exact amount to swap in
output_faObject<Metadata>Output token metadata
min_output_amountu64Minimum 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

ArgumentTypeDescription
signer&signerAccount performing the swap
poolObject<Pool>Pool to execute swap in
input_faObject<Metadata>Input token metadata
max_input_amountu64Maximum input tokens willing to pay
output_faObject<Metadata>Output token metadata
output_amountu64Exact 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

ArgumentTypeDescription
signer&signerAccount performing the swap
poolObject<Pool>Pool to execute swap in
input_faObject<Metadata>Input token metadata
max_input_amountu64Maximum input tokens willing to pay
output_faObject<Metadata>Output token metadata
output_amountu64Exact 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

CodeNameDescription
100EINVALID_AMOUNTInvalid amount of tokens
101EBALANCE_TOO_LOWInsufficient balance
102EINVALID_VECTOR_LENGTHInvalid vector length
103EINSUFFICIENT_OUTPUT_AMOUNTInsufficient output amount
104EINVALID_COIN_VERSIONInvalid output coin version