Skip to content

bgraokmush/swap

Repository files navigation


Solana Swap Smart Contract

🚀 A decentralized swap program built on the Solana blockchain using Anchor.
Report Bug · Request Feature

🔰 About The Project

This project demonstrates a swap mechanism on the Solana blockchain using an Anchor-based smart contract. Users can create and fulfill swap offers between two tokens. The contract provides methods to make and take swap offers securely by utilizing Solana's token program and on-chain accounts.

(back to top)

🛠 Built With

(back to top)

🚀 Getting Started

To get a local copy up and running, follow these steps.

Prerequisites

  • Install Solana CLI:
    sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
  • Install Anchor Framework:
    cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
    avm install latest
    avm use latest
  • Ensure Rust is installed:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Installation

  1. Clone the repository:
    git clone https://github.com/username/solana-swap.git
  2. Navigate to the project directory:
    cd solana-swap
  3. Build the smart contract:
    anchor build
  4. Deploy the program to the Solana devnet:
    anchor deploy

(back to top)

🔃 Usage

The Solana Swap smart contract provides two main methods:

  1. make_offer: Creates a swap offer by specifying the amount of token A being offered and the amount of token B wanted.

    pub fn make_offer(
        context: Context<MakeOffer>,
        id: u64,
        token_a_offered_amount: u64,
        token_b_wanted_amount: u64,
    ) -> Result<()>
  2. take_offer: Accepts an existing swap offer by transferring the requested token B to the maker and withdrawing token A from the vault.

    pub fn take_offer(context: Context<TakeOffer>) -> Result<()>

For detailed examples, please refer to the Documentation.

(back to top)

🔠 Swap Workflow Diagram

Below is a high-level diagram explaining the swap mechanism:

graph TD
    A[Maker creates an offer] -->|Send Token A to Vault| B[Offer saved on-chain]
    B --> C[Taker accepts the offer]
    C -->|Send Token B to Maker| D[Vault releases Token A to Taker]
Loading

(back to top)

🛏️ Roadmap

  • Implement basic swap functionality
  • Deploy contract to Solana devnet
  • Add comprehensive unit tests
  • Integrate front-end application for user interaction
  • Audit smart contract for security

See the open issues for a full list of proposed features and known issues.

(back to top)

💡 Contributing

Contributions are what make the open-source community amazing! Follow these steps to contribute:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

📝 License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

📧 Contact

Twitter - @bgraokmush

(back to top)

🙏 Acknowledgments

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published