https://github.com/immutal0/solana-meteora-dex-cpi
Swap tokens using meteora cpi call.
https://github.com/immutal0/solana-meteora-dex-cpi
cpi meteora solana swap token
Last synced: about 1 month ago
JSON representation
Swap tokens using meteora cpi call.
- Host: GitHub
- URL: https://github.com/immutal0/solana-meteora-dex-cpi
- Owner: Immutal0
- Created: 2025-02-12T11:53:50.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-13T17:09:30.000Z (3 months ago)
- Last Synced: 2025-04-09T00:47:36.610Z (about 1 month ago)
- Topics: cpi, meteora, solana, swap, token
- Language: TypeScript
- Homepage:
- Size: 128 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
Here's a professional GitHub README for your **Meteora Swap CPI Call** project that you can use:
---
# Meteora Swap CPI Call
This project implements a Solana-based smart contract using the **Anchor Framework** for calling the **Meteora Swap program** via a Cross-Program Invocation (CPI). It allows users to swap tokens on the **Meteora** decentralized exchange, with support for interacting with the **Meteora Program** and executing token swaps.
This project utilizes Solana's native smart contract architecture, the **Anchor Framework**, and **Solana Program Library (SPL)** tokens for seamless, secure, and efficient token swaps.
---
## Table of Contents
- [Project Overview](#project-overview)
- [Features](#features)
- [Tech Stack](#tech-stack)
- [Smart Contract](#smart-contract)
- [How to Set Up](#how-to-set-up)
- [How to Use](#how-to-use)
- [Contributing](#contributing)
- [License](#license)---
## Project Overview
The **Meteora Swap CPI Call** project is a Solana-based decentralized application (dApp) designed to interact with the **Meteora Program**, enabling users to swap two tokens using the cross-program invocation pattern.
### Key Features:
- **Token Swap:** Allows users to swap tokens on the Meteora decentralized exchange (DEX).
- **Meteora Program Integration:** Interacts with the Meteora Program for liquidity pool management.
- **Cross-Program Invocation (CPI):** Utilizes Solana's CPI for secure and efficient program interaction.
- **Vault Authority:** Provides a vault for managing token reserves and swap operations.
- **Token Reserve Management:** The contract supports managing token reserves for liquidity pools.---
## Features
- **Swap Tokens:** Users can swap tokens between two different pools (reserve_x and reserve_y).
- **User Token In/Out:** Users can provide one token as input and receive another as output.
- **CPI with Meteora:** The contract calls the Meteora Program via CPI to execute token swaps.
- **Mint Tokens:** The contract supports interacting with tokens like SPL tokens.
- **Rewards Mechanism:** Based on the amount swapped and the reserve pools.
- **Event Authority:** Tracks events and token swap transactions.---
## Tech Stack
- **Solana Blockchain**: The contract is deployed on the Solana blockchain.
- **Rust & Anchor Framework**: Written using the Anchor framework for Solana smart contracts.
- **Solana Program Library (SPL)**: Utilizes SPL tokens for handling token transactions.
- **Metaplex**: Optionally, you can integrate this with Metaplex NFTs for additional functionality.---
## Smart Contract
The **Meteora Swap CPI Call** smart contract allows users to swap tokens via the **Meteora Program** using a CPI. The contract interacts with various accounts such as reserves, token mints, and the user’s token balances. The logic is implemented in the **Rust programming language** using the **Anchor framework**.
### Key Components:
- **`token_swap` Function**: The main function that performs the token swap by invoking the Meteora Program.
- **`get_ix_data` Function**: Serializes the instruction data to be sent to the Meteora Program.
- **Vault and Reserve Management**: Includes vault authority management and reserve tokens handling.---
## How to Set Up
### Prerequisites:
Before you begin, ensure you have the following installed:- [Rust](https://www.rust-lang.org/): The Rust programming language for compiling the smart contract.
- [Solana CLI](https://docs.solana.com/cli/install-solana-cli-tools): The Solana command-line interface.
- [Anchor Framework](https://project-serum.github.io/anchor/getting-started/introduction.html): The framework for developing Solana smart contracts.
- [Phantom Wallet](https://phantom.app/): Solana wallet to interact with the dApp.### Step-by-Step Setup:
1. **Clone the Repository**:
```bash
git clone https://github.com/Immutal0/meteora-swap-cpi-call.git
cd meteora-swap-cpi-call
```2. **Install Dependencies**:
Make sure that you have **Rust** and **Anchor** installed. Install them if you haven't already:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```Install **Anchor**:
```bash
npm install -g @project-serum/anchor-cli
```3. **Build the Contract**:
Inside the project directory, run the following to build the contract:
```bash
anchor build
```4. **Deploy to Devnet**:
First, make sure to set your Solana CLI to devnet:
```bash
solana config set --url devnet
solana airdrop 2
```Deploy the contract using Anchor:
```bash
anchor deploy
```5. **Configure the Meteora Program Key**:
The **Meteora Program Key** is hardcoded as:
```rust
pub const METEORA_PROGRAM_KEY: &str = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo";
```
You can replace this key with the actual deployed program key of the Meteora DEX if needed.---
## How to Use
1. **Interact with the dApp:**
- Deploy the contract on Solana's devnet.
- Use the frontend to connect your wallet (e.g., Phantom).
- Stake/Swap tokens by providing input and output tokens.
2. **Perform a Token Swap:**
- Select the tokens you wish to swap (e.g., Token X and Token Y).
- Specify the amount of tokens to swap and the minimum amount of output tokens.
- Execute the swap through the contract.3. **Vault and Reserve:**
- Ensure you have sufficient reserves (Token X and Token Y) for the swap to occur.4. **Check Transactions and Events:**
- Transaction details and events are logged for monitoring swaps and liquidity operations.---
## Contributing
1. Fork the repository.
2. Create a new branch: `git checkout -b feature-branch`.
3. Make your changes.
4. Commit your changes: `git commit -am 'Add new feature'`.
5. Push to your forked repository: `git push origin feature-branch`.
6. Open a Pull Request for review.---
## Contact
For any questions or assistance, feel free to reach out:
- **Telegram:** [@Immutal0_](https://t.me/Immutal0_)
- **Twitter:** [@Immutal0](https://x.com/Immutal0)