# Swappers

On MAYAChain, users can swap their digital assets for other digital assets. The network aims to give users access to:

* A large variety of assets through cross-chain compatibility and simple asset listing
* Superior user experience through open finance protocols and permissionless access
* 1-transaction access to fast chains (Dash), smart chains (Ethereum, Kujira), and censorship-resistant chains (Bitcoin).

{% hint style="info" %}
See an [overview of Swapping in MAYAChain](https://gitlab.com/mayachain/docs/one-stop-shop/-/blob/main/maya-protocol-docs/how-it-works/understanding-mayachain.md#how-swapping-works)
{% endhint %}

## How Swaps Work

### Available Assets

Users can swap any assets which are on connected chains and which have been added to the network. Users can swap from any connected asset to any other connected asset. They can also swap from any connected asset to [CACAO](/introduction/readme/cacao.md).

{% hint style="info" %}
Learn more about how chains and assets get added to the network in [the Governance section](/deep-dive/how-it-works/governance.md).

To add an asset to MAYAChain, users simply deposit a new asset to put it in the queue for listing. Swaps can only be made on pools when they have been added to the network and have moved out of the bootstrap phase.
{% endhint %}

### Decentralisation

MAYAChain manages the swaps in accordance with the rules of the state machine - which is completely autonomous. Every swap that it observes is finalised, ordered and processed. Invalid swaps are refunded, valid swaps ordered in a transparent way that is resistant to front-running. Validators can not influence the order of trades, and are punished if they fail to observe a valid swap.

Swaps are completed as fast as they can be confirmed, which is around 5-10 seconds.

### Continuous Liquidity Pools

Swaps on MAYAChain are made possible by liquidity pools. These are pools of assets deposited by Liquidity providers, where each pool consists of 1 connected asset, for example Bitcoin, and MAYAChain's own asset, CACAO. They're called Continuous Liquidity Pools because CACAO, being in each pool, links all pools together in a single, continuous liquidity network.

When a user swaps 2 connected assets on MAYAChain, they swap between two pools:

1. Swap to CACAO in the first pool,
2. Move that CACAO into the second pool,
3. Swap to the desired asset in the second pool with the CACAO from (2)

The MAYAChain state machine handles this swap in one go, so the user never handles CACAO.

See [this example](#example) for further detail and the page below for broader detail on Continuous Liquidity Pools.

{% content-ref url="/pages/WTTLbzovbISGu8RA1BTc" %}
[Liquidity](/deep-dive/mayachain-finance/continuous-liquidity-pools.md)
{% endcontent-ref %}

{% content-ref url="/pages/dOwOKll8XdCPsjfDLlSy" %}
[Getting Started](/introduction/readme/getting-started.md)
{% endcontent-ref %}

### Calculating Swap Output

The output of a swap can be worked out using the formula

$$
y = \frac{ xYX} {(x+X)^2 }
$$

where

* x is input asset amount
* X is input asset balance
* y is output asset amount
* Y is output asset balance

#### Example

The BTC.CACAO pool has 100 BTC and 2.5 million CACAO. A user swaps 1 BTC into the pool. Calculate how much CACAO is output:

$$
\frac {1 \* 2500000 \* 100 } {(1 + 100)^2} = 24,507.40
$$

This user swaps 1 BTC for 24,507.40 CACAO.

### Costs

The cost of a swap is made up of two parts:

1. Outbound Fee
2. Price Slippage

All swaps are charged a network fee. The network fee is dynamic – it's calculated by averaging a set of recent gas prices. Learn more about [Network Fees](/deep-dive/how-it-works/fees.md#network-fee).

Note that users who force their swaps through quickly cause large slips and pay larger fees to liquidity providers.


---

# 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.mayaprotocol.com/introduction/readme/roles/swapping.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.
