# Aquarius Soroban Functions

### Contract Address

The [Aquarius Smart Contract](https://github.com/AquaToken/soroban-amm/tree/master/liquidity_pool_router) serving as an entry point for all the AMM functionality is [CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK](https://stellar.expert/explorer/public/contract/CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK)

### Available Functions

#### **Deposit**

The [deposit](https://github.com/AquaToken/soroban-amm/blob/master/liquidity_pool_router/src/pool_interface.rs#L25) function is used to increase pool liquidity by exchanging tokens for pool share tokens:

```rust
fn deposit(
  e: Env,
  user: Address,
  tokens: Vec<Address>,
  pool_index: BytesN<32>,
  desired_amounts: Vec<u128>,
  min_shares: u128,
) -> (Vec<u128>, u128);
```

Parameters:\
\- `user`:  The address of the user executing withdraw\
\- `tokens`: Ordered tokens vector\
\- `pool_index`: Pool hash (see get pools list section)\
\- `desired_amounts`: Vector of desired amounts to deposit\
\- `min_shares`: Minimum amount of shares to receive on deposit

The function returns the actual amounts of deposited tokens and minted shares amount.

#### **Withdraw**

The [withdraw](https://github.com/AquaToken/soroban-amm/blob/master/liquidity_pool_router/src/pool_interface.rs#L65) function is used to remove liquidity from pool, by exchanging pool shares for pool tokens:

```rust
fn withdraw(
  e: Env,
  user: Address,
  tokens: Vec<Address>,
  pool_index: BytesN<32>,
  share_amount: u128,
  min_amounts: Vec<u128>,
) -> Vec<u128>;

```

Parameters:\
\- `user`: The address of the user executing withdraw.\
\- `tokens`: Ordered tokens vector\
\- `pool_index`: Pool hash (see get pools list section)\
\- `share_amount`: Amount of shares to withdraw\
\- `min_amounts`: Vector of minimum amounts to withdraw

The function returns the actual amounts of withdrawn tokens.

#### **Swap Chained**

The [swap\_chained](https://github.com/AquaToken/soroban-amm/blob/master/liquidity_pool_router/src/pool_interface.rs#L291) function in the Soroban Rust smart contract is used to execute a chain of token swaps to exchange an input token for an output token. The function signature is as follows:<br>

```rust
fn swap_chained(
    e: Env,
    user: Address,
    swaps_chain: Vec<(Vec<Address>, BytesN<32>, Address)>,
    token_in: Address,
    in_amount: u128,
    out_min: u128,
) -> u128
```

Parameters:\
\- `user`: The address of the user executing the swaps.\
\- `swaps_chain`: The series of swaps to be executed. (No need to generate swap chain manually, since this is available in find-path response as SCVal XDR encoded value). Each element in swap chain is represented by a tuple containing:

* > * A vector of token addresses liquidity pool belongs to
* > * Pool index hash
* > * The token to obtain

\- `token_in`: The address of the input token to be swapped.\
\- `in_amount`: The amount of the input token to be swapped.\
\- `out_min`: The minimum amount of the output token to be received.

The function returns the amount of the output token received after all swaps have been executed.<br>

Limitations:

* Up to 4 pools are allowed currently due to Soroban limitations. No contract validation error shall be raised, but transaction won’t pass simulation and fail with BudgetExceed error.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aqua.network/developers/aquarius-soroban-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
