solana-program-library/token-swap
dependabot[bot] f236d6ec7f
build(deps-dev): bump flow-bin from 0.160.2 to 0.161.0 in /token-swap/js (#2471)
Bumps [flow-bin](https://github.com/flowtype/flow-bin) from 0.160.2 to 0.161.0.
- [Release notes](https://github.com/flowtype/flow-bin/releases)
- [Commits](https://github.com/flowtype/flow-bin/commits)

---
updated-dependencies:
- dependency-name: flow-bin
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-30 10:38:12 +00:00
..
js build(deps-dev): bump flow-bin from 0.160.2 to 0.161.0 in /token-swap/js (#2471) 2021-09-30 10:38:12 +00:00
program token-swap: Use `find_program_address` on-chain during init (#2363) 2021-08-31 23:09:42 +02:00
proposals Add pausable proposal (#1506) 2021-03-25 16:38:36 -05:00
README.md token-swap: Document owner address in README (#1368) 2021-03-04 20:24:43 +01:00

README.md

Token Swap Program

A Uniswap-like exchange for the Token program on the Solana blockchain, deployed to SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8 on all networks.

Full documentation is available at https://spl.solana.com/token-swap

JavaScript bindings are available in the ./js directory.

Building

To build a development version of the Token Swap program, you can use the normal build command for Solana programs:

cargo build-bpf

For production versions, the Token Swap Program contains a production feature to fix constraints on fees and fee account owner. A developer can deploy the program, allow others to create pools, and earn a "protocol fee" on all activity.

Since Solana programs cannot contain any modifiable state, we must hard-code all constraints into the program. SwapConstraints in program/src/constraints.rs contains all hard-coded fields for fees. Additionally the SWAP_PROGRAM_OWNER_FEE_ADDRESS environment variable specifies the public key that must own all fee accounts.

You can build the production version of Token Swap running on devnet, testnet, and mainnet-beta using the following command:

SWAP_PROGRAM_OWNER_FEE_ADDRESS=HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN cargo build-bpf --features=production

Testing

Unit tests

Run unit tests from ./program/ using:

cargo test

Fuzz tests

Using the Rust version of honggfuzz, we "fuzz" the Token Swap program every night. Install honggfuzz with:

cargo install honggfuzz

From there, run fuzzing from ./program/fuzz with:

cargo hfuzz run token-swap-instructions

If the program crashes or errors, honggfuzz dumps a .fuzz file in the workspace, so you can debug the failing input using:

cargo hfuzz run-debug token-swap-instructions hfuzz_workspace/token-swap-instructions/*fuzz

This command attaches a debugger to the test, allowing you to easily see the exact problem.

Integration tests

You can test the JavaScript bindings and on-chain interactions using solana-test-validator, included in the Solana Tool Suite. See the CLI installation instructions.

From ./js, install the required modules:

npm i

Then run all tests:

npm run start-with-test-validator

If you are testing a production build, use:

SWAP_PROGRAM_OWNER_FEE_ADDRESS="HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN" npm run start-with-test-validator