Skip to content

Immutal0/Solana-meteora-dex-cpi

Repository files navigation

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

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: The Rust programming language for compiling the smart contract.
  • Solana CLI: The Solana command-line interface.
  • Anchor Framework: The framework for developing Solana smart contracts.
  • Phantom Wallet: Solana wallet to interact with the dApp.

Step-by-Step Setup:

  1. Clone the Repository:

    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:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

    Install Anchor:

    npm install -g @project-serum/anchor-cli
  3. Build the Contract: Inside the project directory, run the following to build the contract:

    anchor build
  4. Deploy to Devnet: First, make sure to set your Solana CLI to devnet:

    solana config set --url devnet
    solana airdrop 2

    Deploy the contract using Anchor:

    anchor deploy
  5. Configure the Meteora Program Key: The Meteora Program Key is hardcoded as:

    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:

About

Swap tokens using meteora cpi call.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published