🚀 A decentralized swap program built on the Solana blockchain using Anchor.
Report Bug
·
Request Feature
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.
To get a local copy up and running, follow these steps.
- 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
- Clone the repository:
git clone https://github.com/username/solana-swap.git
- Navigate to the project directory:
cd solana-swap
- Build the smart contract:
anchor build
- Deploy the program to the Solana devnet:
anchor deploy
The Solana Swap smart contract provides two main methods:
-
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<()>
-
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.
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]
- 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.
Contributions are what make the open-source community amazing! Follow these steps to contribute:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Twitter - @bgraokmush