Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Swap on the serum orderbook #224

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/swap/deps/serum-dex"]
path = examples/swap/deps/serum-dex
url = https://github.com/project-serum/serum-dex
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ cache: cargo
env:
global:
- NODE_VERSION="14.7.0"
git:
submodules: true

_defaults: &defaults
before_install:
Expand Down Expand Up @@ -65,6 +67,7 @@ jobs:
script:
- pushd examples/chat && yarn && anchor test && popd
- pushd examples/ido-pool && yarn && anchor test && popd
- pushd examples/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test && popd
- pushd examples/tutorial/basic-0 && anchor test && popd
- pushd examples/tutorial/basic-1 && anchor test && popd
- pushd examples/tutorial/basic-2 && anchor test && popd
Expand Down
113 changes: 102 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ members = [
"lang/syn",
"spl",
]
exclude = [
"examples/swap/deps/serum-dex"
]
6 changes: 6 additions & 0 deletions examples/swap/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[[test.genesis]]
address = "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
program = "./deps/serum-dex/dex/target/deploy/serum_dex.so"
7 changes: 7 additions & 0 deletions examples/swap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = [
"programs/*"
]
exclude = [
"deps/serum-dex"
]
34 changes: 34 additions & 0 deletions examples/swap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Swap

An example swap program that provides a convenient API to the Serum orderbook
for performing instantly settled token swaps.

## Usage

This example requires building the Serum DEX from source, which is done using
git submodules.

### Install Submodules

Pull the source

```
git submodule init
git submodule update
```

### Build the DEX

Build it

```
cd deps/serum-dex/dex/ && cargo build-bpf && cd ../../../
```

### Run the Test

Run the test

```
anchor test
```
1 change: 1 addition & 0 deletions examples/swap/deps/serum-dex
Submodule serum-dex added at 19c8e3
12 changes: 12 additions & 0 deletions examples/swap/migrations/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@project-serum/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);

// Add your deploy script here.
}
19 changes: 19 additions & 0 deletions examples/swap/programs/swap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "swap"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "swap"

[features]
no-entrypoint = []
no-idl = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { path = "../../../../lang" }
anchor-spl = { path = "../../../../spl" }
2 changes: 2 additions & 0 deletions examples/swap/programs/swap/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
Loading