# Buying and Selling Baskets

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2FrWWAbzVF7zU9WDyooS1V%2FGqVBkchbIAAjg9_.jpeg?alt=media&#x26;token=cba69fee-9466-4fb5-8833-5bc9af86d9ba" alt=""><figcaption></figcaption></figure>

**Buying (Minting)**

* Your SOL is swapped into the basket’s component tokens via Raydium and Jupiter, according to target weights
* The tokens are locked in a vault
* You receive a newly minted basket token representing your position

**Selling (Redeeming)**

* Your basket token is burned
* The underlying tokens are unlocked
* They’re swapped back into SOL
* Your SOL is returned to your wallet

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2FMevYbWffsMZXX0M4hOjc%2FCleanShot%202025-05-14%20at%2021.17.27.mp4.gif?alt=media&#x26;token=15f9d28b-7707-4c4b-8047-e7ff4f6a72d7" alt=""><figcaption></figcaption></figure>

* Basket tokens are tradable assets with a dynamic supply.

### Key Technical Points

### 1. integrated Raydium and Jupiter for swapping

* We integrated Jupiter and Raydium for deep DEX liquidity, so **any token tradable onchain** can be included in a basket — whether it’s zBTC, JLP, memecoins, LSTs, or LRTs.

> We designed pie.fun to have zero limitations when it comes to basket creation.

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2Fsrh0bUEr4ftfIHRifsYt%2FCleanShot%202025-05-22%20at%2019.55.57%402x.png?alt=media&#x26;token=d9b65b2c-60c4-4791-bb95-df1c486fe7bb" alt=""><figcaption></figcaption></figure>

### 2. Atomic swap using Jito Bundles&#x20;

* Buying a basket involves multiple token swaps executed **atomically; all swaps either succeed toghether or fail toghether.**
* But Solana limits transaction size and compute, allowing only 2 swaps per transaction.
* We solve this with **Jito Bundles**, which let us group multiple transactions into a single atomic unit.

> 2 swaps × 5 bundled txs = 10 token swaps in one atomic flow

* This enables large, multi-token baskets — in one seamless user action.

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2FexGu0lsY57icwbhbF4J4%2FCleanShot%202025-05-22%20at%2019.51.41%402x.png?alt=media&#x26;token=f5218e0d-0860-4a95-b359-9df6caeff0fa" alt=""><figcaption><p>2 swaps in one transaction</p></figcaption></figure>

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2FDln3lUZT8tblQDjgilnY%2FCleanShot%202025-05-22%20at%2019.51.53%402x.png?alt=media&#x26;token=be1334df-49b8-4bab-a653-37882d7c5dcd" alt=""><figcaption><p>5 transactions bundled into one atomic transaction by jito bundles</p></figcaption></figure>

### 3. Basket Architecture

* pie.fun uses **on-demand minting**. When a user swaps into a basket, basket token is minted on the spot.
* This design ensures:
  * ✅ **100% collateralized** baskets
  * ✅ Infinite number of baskets without liquidity constraints
* Other index protocols often rely on:
  * ❌ **DEX-listed baskets** — each basket needs its own liquidity pool → limits the number of baskets and kills flexibility
  * ❌ **Synthetic baskets** — dependent on external oracles\
    → introduces risk and complexity

<figure><img src="https://1299511177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNMbjTy2wbG8wVsHCgT0%2Fuploads%2FOD8Ryx3jEfXx72vfMuBp%2FCleanShot%202025-05-22%20at%2020.03.35%402x.png?alt=media&#x26;token=f48bfdd7-642a-44dc-b453-d510883b0f05" alt=""><figcaption></figcaption></figure>
