#token #swap #pool #anchor #reimplement #deposit #testing

gfx-swap

gfx-swap is an anchor re-implement of the token-swap program in solana-program-library

1 unstable release

0.1.0 Nov 16, 2021

#6 in #reimplement

22 downloads per month

MIT license

135KB
3K SLoC

GFX Swap Program build

This is a re-implement of the swap program in solana-program-library https://github.com/solana-labs/solana-program-library/tree/master/token-swap.

Audit

This repo is audited by Halborn. The auditing report is under audit/GooseFX_Swap_Program_Security_Audit_Report_Halborn_Final.pdf

Examples

For how to call this contract, please take a look at the examples and the tests.

Deploy and run gfx-swap

Prerequisites

Set the required environment variables to a .env file

RUST_BACKTRACE=1
RUST_LOG=gfx_swap=info

TOKEN_A=2uig6CL6aQNS8wPL9YmfRNUNcQMgq9purmXK53pzMaQ6
TOKEN_B=8FUPzLY58ojDaj5yh1MKwyJnGNhCDMbStbHNVkBQ9KjJ

ADMIN_WALLET="~/.config/solana/id.json"
USER_WALLET="~/.config/solana/id.json"

You might want to provide different addresses for TOKEN_A and TOKEN_B.

Generate a key for deploying the program

Run just keygen gfx-swap.

Deploy the program

Run just deploy gfx-swap --features ci.

Create a swap pool

Run just cli create_pool.

create_pool will create the associated token account (ATA) for USER_WALLET.

This command will print out a bunch of information, in which you need to write down the seed into .env. The seed is a unique identifier to the pool.

Pool monitor

Run just cli pool_status. This will print out a snapshot of the current pool status. You can combine it with the watch command, i.e. watch just cli pool_status to constantly monitor the pool.

Deposit tokens into the pool

Run just cli deposit2 --lp-amount <amount>. This basically askes the pool I'd like to get <amount> LP tokens and you can deduct some amount of token A and B from my wallet for that.

Withdraw tokens from the pool

Run just cli withdraw2 --lp-amount <amount>. This is the inverse operation to the deposit command.

Swap tokens

Run just cli swap --swap-in A --amount <amount>. This swaps in some token A for some token B.

Dependencies

~24–38MB
~625K SLoC