# Aggregating Pools

## Quick Links

* [Contract Addresses](https://wiki.shellprotocol.io/getting-started/overview/contract-addresses)
* [Native Primitives](https://wiki.shellprotocol.io/getting-started/integrations/shell-native-primitives)
* [Example of sending a swap through the Ocean](https://github.com/Shell-Protocol/Shell-Protocol/blob/bfbba01472200a4a34ace4cb131f775018cf47c2/test/Interaction.js#L346)
* [Shell Protocol GitHub](https://github.com/Shell-Protocol/Shell-Protocol/)

## Swap through Shell-native fractal pools

<figure><img src="https://3510525662-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcJAAgnAk36Ru4lEnsmj%2Fuploads%2FiHimoXgMZ0B1q13ofFe6%2Ftelegram-cloud-photo-size-1-5100640334404233897-y.jpg?alt=media&#x26;token=b1887324-d133-4e0d-9805-0ec4ee75ea74" alt=""><figcaption><p>You can swap any ERC-20s by creating a path through this graph.</p></figcaption></figure>

You can use Shell pools to swap any ERC-20 (or ERC-721 or ERC-1155) tokens, as long as there exists a viable path of AMMs.

Fractal pools can serve as a stepping stone in swapping between ERC-20 tokens. A fractal pool uses LP tokens as one or both of its reserve assets. For example:

* The two reserve assets of <mark style="background-color:green;">**`Stablepool`**</mark> are <mark style="background-color:orange;">**`DAI+USDC`**</mark> LP token and `USDT+USDC` LP token.
* The two reserve assets for <mark style="background-color:purple;">**`ETH+USD`**</mark> pool are <mark style="background-color:blue;">**`shETH`**</mark> and <mark style="background-color:green;">**`Stablepool`**</mark> LP token.

Let's swap <mark style="background-color:yellow;">**`shDAI`**</mark> to <mark style="background-color:blue;">**`shETH`**</mark>. You must deposit <mark style="background-color:yellow;">**`shDAI`**</mark> into the <mark style="background-color:orange;">**`DAI+USDC`**</mark> pool to get the <mark style="background-color:orange;">**`DAI+USDC`**</mark> LP token, then take that LP token and deposit it into <mark style="background-color:green;">**`Stablepool`**</mark> to get the <mark style="background-color:green;">**`Stablepool`**</mark> LP token, then swap that LP token to <mark style="background-color:blue;">**`shETH`**</mark> using the fractal pool (<mark style="background-color:purple;">**`ETH+USD`**</mark>).

{% hint style="info" %}
**Tip:** Depositing or withdrawing from a pool is functionally the same as swapping. You call `computeOutputAmount` but with the LP token ID as the output token instead of a wrapped token.
{% endhint %}

Remember in Shell Protocol, ERC-20 (or 721 or 1155) tokens are wrapped onto a shared ERC-1155 ledger ([the Ocean](https://wiki.shellprotocol.io/how-shell-works/the-ocean-accounting-hub)). Shell pools always use the Shell-wrapped ERC-1155 version of these tokens.

Shell LP tokens are also ERC-1155. They each have their own Ocean IDs, just as the Shell-wrapped ERC-20s do.

{% hint style="info" %}
**Tip:** You can get the LP token ID from the LP pool contract. There is a read function called `lpTokenId`.
{% endhint %}

Whenever you swap from one ERC-20 token to another through Shell pools, there will be a wrap and unwrap in that transaction. For example, trading <mark style="color:yellow;">**`DAI`**</mark> for <mark style="color:blue;">**`ETH`**</mark> would look like this:

1. wrap <mark style="color:yellow;">**`DAI`**</mark> -> <mark style="background-color:yellow;">**`shDAI`**</mark>
2. deposit <mark style="background-color:yellow;">**`shDAI`**</mark> -> <mark style="background-color:orange;">**`DAI+USDC`**</mark> LP
3. deposit <mark style="background-color:orange;">**`DAI+USDC`**</mark> LP -> <mark style="background-color:green;">**`Stablepool`**</mark> LP
4. swap <mark style="background-color:green;">**`Stablepool`**</mark> LP -> <mark style="background-color:blue;">**`shETH`**</mark> (through <mark style="background-color:purple;">**`ETH+USD`**</mark> pool)
5. unwrap <mark style="background-color:blue;">**`shETH`**</mark> -> <mark style="color:blue;">**`ETH`**</mark>

{% hint style="info" %}
**Tip:** All of this can be done in one function call with `doMultipleInteractions`.
{% endhint %}

The fractal design makes querying the prices of token pairs somewhat complicated.

{% hint style="info" %}
**Coming soon:** Sample code for finding the price between two tokens.
{% endhint %}


---

# 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://wiki.shellprotocol.io/getting-started/developers/aggregating-pools.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.
