# Infinity - Technical

{% hint style="info" %}
Check out our blog post, [Sanctum's Infinity: The Ultimate Guide](https://blog.sanctum.so/inf-guide), for a friendlier introduction to Sanctum's Infinity.
{% endhint %}

Infinity is designed to provide a shared liquidity pool for swapping LSTs. It allows users to swap between different LSTs at prices determined by their intrinsic SOL valuations, which are read from the on-chain state of external liquid staking programs. The protocol also enables users to deposit any LST (or SOL) to receive LP tokens (INF) and later burn these INF tokens to withdraw a corresponding share of any LST or SOL.

Infinity is a powerful primitive that enables **frictionless, no-slippage swaps** with **predictable fees**, not just for trading LSTs but also as an **highly efficient liquidation engine** providing **instant SOL liquidity**.

Infinity supports all Sanctum LSTs. You may check the current on-chain reserves [here](https://solscan.io/account/AYhux5gJzCoeoc1PoJ1VxwPDe22RwcvpHviLDD1oCGvW#portfolio).

## Core Components

Infinity is built upon three main components:

* **S Controller**: This is the central component that manages LST reserves, continually updates their SOL valuation, and handles LST swaps as well as liquidity deposits and withdrawals. It uses the Pricing Program to calculate fees and the SOL Value Calculator Programs to determine LST intrinsic SOL values. The S Controller also includes mechanisms for synchronizing LST reserve values, rebalancing liquidity, and administering the pool (whitelisting or blacklisting LSTs). It supports pausing all pool operations in case of an incident.
* **Pricing Program**: This program calculates fees for LST swaps and for adding or removing liquidity. It operates with SOL-denominated values and returns output amounts as integers using Solana's CPI return value functionality.
  * **Flat Fee Pricing Program**: It applies input and output fees (in basis points) for swaps and a flat fee for removing liquidity. It does not charge fees for adding liquidity. Fees are split between the reserves (contributing to LP token appreciation) and protocol fee vaults. Current split is 90/10.
* **SOL Value Calculator Programs**: There is one such program for each supported LST (and SOL). These programs convert LST amounts to their intrinsic SOL value and vice-versa, by inspecting the on-chain state accounts of the external liquid staking protocol managing the respective LST and mirroring its internal pricing calculation, factoring in any fees. Examples include programs for Marinade (mSOL), Sanctum LSTs, non-Sanctum LSTs (e.g., jitoSOL, bSOL), and Wrapped SOL (wSOL).

## Relevant On-Chain Data and Accounts

**Program ID:** `5ocnV1qiCgaQR8Jb8xWnVbApfaygJ8tNoZfgPwsgx9kx`

The protocol maintains its state and parameters using various [Program Derived Addresses (PDAs)](https://solana.com/docs/core/pda) and [Associated Token Accounts (ATAs)](https://solana.com/developers/courses/token-extensions/token-extensions-in-the-client#associated-token-accounts-ata):

* **S Controller PDAs**:
  * **Pool State PDA**: This is the main state account of the protocol. It is derived from the seed `[b"state"]` and stores configuration parameters (protocol fee share, global pricing program address, LP token mint, protocol version), addresses of most authorities (admin, fee beneficiary, rebalance authority), and global state information (total SOL value of assets, pause status, rebalance status). It also acts as an authority for the LP token mint and pool reserves.
  * **LST State List PDA**: It is derived from the fixed seed `[b"lst-state-list"]`. It contains an entry for each LST, storing its mint, the address of its SOL value calculator program, the SOL value of its pool reserves, and its 'input disabled' status.
* **S Controller Token Accounts and Mints**:
  * **LST Reserve ATAs**: The reserves for each LST, derived from the Pool State PDA.
  * **LP Token Mint**: The mint account for the LP token (INF) users receive for providing liquidity, with minting and freezing authority set to the Pool State PDA.
* **Flat Fee Pricing Program PDAs**:
  * **Program State PDA**: Stores the program's manager and LP withdrawal fees.
  * **Fee Account PDA**: One for each LST, storing its input and output fees.

## Relevant Instructions

* `AddLiquidity`: Allows users to deposit a whitelisted LST (or SOL) into the pool and receive LP tokens (INF) in return.
* `RemoveLiquidity`: Enables users to burn their INF tokens to withdraw a corresponding share of any LST or SOL from the pool.
* `SwapExactIn`: Facilitates swaps where the user specifies the exact amount of an input LST they want to swap, and the protocol calculates the output amount of another LST.

## An Example Swap Flow

When a user swaps `amount_in` LST A for `amount_out` LST B via Infinity:

<figure><img src="/files/Tv6LzaWesUt9EtddKrIG" alt=""><figcaption><p>User swaps <code>amount_in</code> LST A for <code>amount_out</code> LST B via Infinity.</p></figcaption></figure>

## **Allocation Strategy**

If the SOL reserves of Infinity exceed the SOL target at the end of the epoch, then the excess SOL gets staked amongst Sanctum's top performing LSTs inside INF.\
\
However, if the SOL reserve is below the SOL target at epoch end, then the worst performing LSTs inside Infinity will be unstaked to replenish the SOL reserves up to the target.

## Fees

Trading fees vary depending on each LST and include both input and output fees.&#x20;

Withdrawing liquidity (withdrawing any of the assets in Infinity in exchange for INF) incurs a 20bps fee.

All fees are dynamically adjusted to maximise returns for liquidity providers.

## Security

The Infinity program has been thoroughly audited by three independent companies:

* Audit 1: [Neodyme](https://raw.githubusercontent.com/igneous-labs/sanctum-static/master/audits/infinity/Neodyme-INV-24-01.pdf)&#x20;
* Audit 2: [Ottersec](https://raw.githubusercontent.com/igneous-labs/sanctum-static/master/audits/infinity/Ottersec-sanctum_audit_final.pdf)
* Audit 3: [Sec3](https://raw.githubusercontent.com/igneous-labs/sanctum-static/master/audits/infinity/Sec3-Sanctum_S_final_report.pdf)


---

# 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://learn.sanctum.so/docs/technical-documentation/infinity.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.
