Skip to content

Commit

Permalink
Add Solana implementation (#15)
Browse files Browse the repository at this point in the history
Adds Solana swap layer integrating with Jupiter V6
Adds e2e test demonstrating interaction between EVM and Solana implementations
Adds CI for pull requests
  • Loading branch information
a5-pickle authored Oct 29, 2024
1 parent ba1702a commit 9ffb125
Show file tree
Hide file tree
Showing 248 changed files with 43,904 additions and 13,399 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: e2e
on:
push:
branches:
- main
pull_request:

env:
ANCHOR_VERSION: 0.30.1
NODE_VERSION: 20.11.0
RUSTC_VERSION: 1.75.0
SOLANA_VERSION: 1.18.15
jobs:
test:
name: bash sh/run_test.sh
runs-on:
labels: ubuntu-latest-l
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Solana CLI tools
run: sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_VERSION }}/install)"
shell: bash
- name: Update PATH
run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- name: Install Anchor
run: npm i -g @coral-xyz/anchor-cli@${{ env.ANCHOR_VERSION }}
shell: bash
- name: make node_modules
run: make node_modules
- name: cd evm && make build
run: make build
working-directory: ./evm
- name: cd evm/ts-sdk && npm run build
run: npm run build
working-directory: ./evm/ts-sdk
- name: cd solana && make anchor-test-setup
run: make anchor-test-setup
working-directory: ./solana
- name: cd solana && anchor build -- --features integration-test
run: anchor build -- --features integration-test
working-directory: ./solana
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTC_VERSION }}
- name: cd e2e && bash sh/run_test.sh
run: bash sh/run_test.sh
working-directory: ./e2e
99 changes: 99 additions & 0 deletions .github/workflows/solana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: solana
on:
push:
branches:
- main
pull_request:

env:
ANCHOR_VERSION: 0.30.1
NODE_VERSION: 20.11.0
RUSTC_VERSION: 1.75.0
SOLANA_VERSION: 1.18.15
jobs:
make-cargo-test-all:
name: make cargo-test-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTC_VERSION }}
components: clippy, rustfmt
- name: make cargo-test-all
run: make cargo-test-all
working-directory: ./solana

make-lint:
name: make lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTC_VERSION }}
components: clippy, rustfmt
- name: make lint
run: make lint
working-directory: ./solana

make-anchor-test:
name: make anchor-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Solana CLI tools
run: sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_VERSION }}/install)"
shell: bash
- name: Update PATH
run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- name: Install Anchor
run: npm i -g @coral-xyz/anchor-cli@${{ env.ANCHOR_VERSION }}
shell: bash
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTC_VERSION }}
- name: make anchor-test
run: make anchor-test
working-directory: ./solana

make-check-build:
name: make check-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: metadaoproject/setup-anchor@v2
with:
node-version: "20.11.0"
solana-cli-version: "1.18.15"
anchor-version: "0.30.1"
- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUSTC_VERSION }}
- name: make check-build
run: make check-build
working-directory: ./solana
75 changes: 75 additions & 0 deletions .github/workflows/universal-rs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: universal-rs

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: test ${{ matrix.rust }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
rust: ["stable", "beta", "nightly", "1.75"] # MSRV
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- name: test
run: cargo test --all-features
working-directory: ./universal/rs

clippy:
name: clippy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy --all-targets --all-features
working-directory: ./universal/rs
env:
RUSTFLAGS: -Dwarnings

docs:
name: docs
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-docs
- run: cargo doc --no-deps --document-private-items
working-directory: ./universal/rs
env:
RUSTDOCFLAGS: "--cfg docsrs -D warnings"

fmt:
name: fmt
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --all --check
working-directory: ./universal/rs
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
node_modules
dist
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "lib/example-liquidity-layer"]
path = lib/example-liquidity-layer
url = https://github.com/wormhole-foundation/example-liquidity-layer.git
branch = v0.3.2
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

.PHONY: build
build: node_modules
cd evm && $(MAKE)
cd solana && $(MAKE) && $(MAKE) anchor-build-idl
npm run build

.PHONY: clean
clean: fast-transfer-clean
rm -rf e2e/node_modules
cd evm && $(MAKE) clean
cd solana && $(MAKE) clean
npm run clean
rm -rf node_modules

.PHONY: fast-transfer-sync
fast-transfer-sync:
git submodule update --init --checkout --recursive
git submodule sync --recursive

.PHONY: fast-transfer-clean
fast-transfer-clean:
rm -rf lib/example-liquidity-layer
$(MAKE) fast-transfer-sync

.PHONY: fast-transfer-setup
fast-transfer-setup: fast-transfer-sync
cd lib/example-liquidity-layer/solana && $(MAKE) anchor-test-setup
cd lib/example-liquidity-layer/evm && $(MAKE) build

.PHONY: fast-transfer-sdk
fast-transfer-sdk: fast-transfer-setup
cd lib/example-liquidity-layer \
&& $(MAKE) build \
&& npm run build -w solana -w evm \
&& npm pack -w universal/ts -w solana -w evm

node_modules: fast-transfer-sdk
npm install -w solana lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-*
npm install -w e2e lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-*
npm ci
6 changes: 6 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.anchor
.env
.private
.vscode
Anchor.toml
target
8 changes: 8 additions & 0 deletions e2e/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
node_modules
dist
build
test-ledger
15 changes: 15 additions & 0 deletions e2e/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"overrides": [
{
"files": "*.ts",
"options": {
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true
}
}
]
}
32 changes: 32 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "swap-layer-e2e",
"version": "1.0.0",
"description": "Swap Layer EVM <> Solana end-to-end test",
"main": "index.js",
"scripts": {
"test": "bash sh/run_test.sh"
},
"dependencies": {
"@solana/web3.js": "^1.91.6",
"@types/chai": "^4.3.16",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.13",
"@wormhole-foundation/example-liquidity-layer-definitions": "file:../lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-definitions-0.0.1.tgz",
"@wormhole-foundation/example-liquidity-layer-evm": "file:../lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-evm-0.0.1.tgz",
"@wormhole-foundation/example-liquidity-layer-solana": "file:../lib/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-solana-0.0.1.tgz",
"@wormhole-foundation/sdk-base": "^0.10.9",
"@wormhole-foundation/sdk-definitions": "^0.10.9",
"@wormhole-foundation/sdk-evm": "^0.10.9",
"@wormhole-foundation/sdk-solana": "^0.10.9",
"chai": "^4.3.4",
"dotenv": "^16.4.5",
"mocha": "^9.0.3",
"prettier": "^3.2.5",
"ts-mocha": "^10.0.0"
},
"devDependencies": {
"envfile": "^7.1.0",
"ethers": "^5.7.2",
"typechain": "^8.3.2"
}
}
28 changes: 28 additions & 0 deletions e2e/sh/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#/bin/bash

ROOT=$(realpath $(dirname $0)/../..)

rm -f Anchor.toml

sed 's/\= "ts\//\= "..\/solana\/ts\//' $ROOT/solana/Anchor.toml > Anchor.toml
sed -E -i 's/"programs\/swap-layer"/"..\/solana\/programs\/swap-layer"/' Anchor.toml
sed -E -i 's/^test \= ".+"/test = "npx ts-mocha -p .\/tsconfig.anchor-test.json -t 1000000 --bail --exit tests\/[0-9]*.ts"/' Anchor.toml

rm -rf target
cp -r $ROOT/solana/target $ROOT/e2e

# start anvil in the evm directory
cd $ROOT/evm
bash test/script/start_anvil.sh

echo "Anvil instances started successfully."

cd $ROOT/e2e

anchor test --skip-build

EXIT_CODE=$?

pkill anvil

exit $EXIT_CODE
Loading

0 comments on commit 9ffb125

Please sign in to comment.