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

Add core math packages (using wasm) & high-level typescript sdk #201

Merged
merged 13 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
104 changes: 45 additions & 59 deletions .github/actions/anchor/action.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,69 @@
name: 'Setup Anchor Development Environment'
description: 'Sets up the solana sdk using the specified version'
name: 'Setup Anchor'
description: 'Sets up an Anchor development environment.'

branding:
icon: anchor
color: blue

inputs:
anchor-version:
description: 'The version of anchor to use.'
required: false
default: 'v0.29.0'
rust-version:
description: 'The version of rust to use.'
required: false
default: '1.80'
solana-key:
description: 'The private key to use for the solana sdk.'
required: false
solana-cluster:
description: 'The cluster to use for the solana sdk.'
required: false
default: 'devnet'
run:
description: 'The command(s) to run.'
solana-key:
description: 'The private key to use for the solana sdk.'
required: false
rustc-version:
description: 'The version of rustc to use.'
default: 'v1.78.0'
node-version:
description: 'The version of node to use.'
default: 'v22.8.0'
solana-version:
description: 'The version of solana to use.'
default: 'v1.17.25'
anchor-version:
description: 'The version of anchor to use.'
default: 'v0.29.0'

runs:
using: "composite"
steps:
- name: Shell Setup
run: |
touch run
chmod +x run
echo "#!/bin/bash" >> run
echo "set -xeo pipefail" >> run
echo "export RUST_LOG=" >> run
shell: bash
- name: Install Dependencies
run: |
echo "yarn" >> run
shell: bash
- name: Update rustc
run: |
echo "rustup install ${{ inputs.rust-version }}" >> run
echo "rustup default ${{ inputs.rust-version }}" >> run
shell: bash
- name: Configure Solana
run: |
echo "solana config set --url ${{ inputs.solana-cluster }}" >> run
shell: bash
- name: Configure Solana Key
if: ${{ !inputs.solana-key }}
- name: Setup rustc
run: |
echo "solana-keygen new --no-bip39-passphrase" >> run
rust_version=${{ inputs.rustc-version }}
rustup toolchain install ${rust_version#v}
rustup default ${rust_version#v}
rustup component add rustfmt clippy
shell: bash
- name: Configure Solana Key
if: ${{ inputs.solana-key }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Install Solana CLI
run: |
echo "echo \"${{ inputs.solana-key }}\" > ~/.config/solana/id.json" >> run
wget -qO- "https://release.anza.xyz/${{ inputs.solana-version }}/solana-release-x86_64-unknown-linux-gnu.tar.bz2" | tar -xvj
echo "$PWD/solana-release/bin" >> $GITHUB_PATH
shell: bash
- name: Airdrop Solana
if: ${{ inputs.solana-key && inputs.solana-cluster == 'devnet' }}
- name: Install Anchor CLI
run: |
echo "solana airdrop 1 || true" >> run
anchor_version=${{ inputs.anchor-version }}
npm install -g @coral-xyz/anchor-cli@${anchor_version#v}
shell: bash
- name: Run Commands
- name: Configure Solana CLI
run: |
echo "${{ inputs.run }}" >> run
solana config set --url ${{ inputs.solana-cluster }}
if [ -z "${{ inputs.solana-key }}" ]; then
solana-keygen new --no-bip39-passphrase
else
echo "${{ inputs.solana-key }}" > ~/.config/solana/id.json
fi
solana airdrop 1 || true
shell: bash
- name: Log Commands
- name: Log Installed Tools
run: |
echo "---"
cat run
echo "---"
echo "rustc: $(rustc --version)"
echo "node: $(node --version)"
echo "solana: $(solana --version)"
echo "anchor: $(anchor --version)"
shell: bash
- name: Run Docker
run: |
docker run \
--entrypoint '/workdir/run' \
-v "$(pwd)":/workdir \
backpackapp/build:${{ inputs.anchor-version }}
shell: bash

29 changes: 16 additions & 13 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Checks

on:
pull_request:
branches: [main]
branches: "*"
sam0x17 marked this conversation as resolved.
Show resolved Hide resolved

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -15,30 +15,33 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build Packages
- name: Setup Anchor
uses: ./.github/actions/anchor
with:
run: |
yarn build --output-style static
- name: Install dependencies
run: yarn install
- name: Build packages
run: yarn build --output-style static

test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Tests
- name: Setup Anchor
uses: ./.github/actions/anchor
with:
run: |
yarn test --exclude legacy-sdk/whirlpool --output-style static
- name: Install dependencies
run: yarn install
- name: Run tests
run: yarn test --exclude legacy-sdk/whirlpool --output-style static

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Lint
- name: Setup Anchor
uses: ./.github/actions/anchor
with:
run: |
yarn lint --output-style static
- name: Install dependencies
run: yarn install
- name: Run Lint
run: yarn lint --output-style static
15 changes: 8 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Anchor
uses: ./.github/actions/anchor
- name: Setup Github Pages
uses: actions/configure-pages@v5
- name: Build Docs
uses: ./.github/actions/anchor
with:
run: |
yarn build docs/whirlpool --output-style static
- name: Upload Artifact
- name: Install dependencies
run: yarn install
- name: Build docs
run: yarn build docs/whirlpool --output-style static
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/whirlpool/dist
- name: Deploy Artifact
- name: Deploy artifact
id: deployment
uses: actions/deploy-pages@v4
41 changes: 23 additions & 18 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Anchor
uses: ./.github/actions/anchor
- name: Set Version
uses: ./.github/actions/version
with:
version: ${{ github.ref }}
manifest-file: ts-sdk/${{ matrix.package }}/package.json
- name: Deploy npm
uses: ./.github/actions/anchor
with:
run: |
npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} && yarn
yarn build ts-sdk/${{ matrix.package }} --output-style static
cd ts-sdk/${{ matrix.package }} && npm publish --access public
- name: Setup npm
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: yarn install
- name: Build package
run: yarn build ts-sdk/${{ matrix.package }} --output-style static
- name: Publish package
working-directory: ts-sdk/${{ matrix.package }}
run: npm publish --access public

cargo:
strategy:
Expand All @@ -44,18 +48,20 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Anchor
uses: ./.github/actions/anchor
- name: Set Version
uses: ./.github/actions/version
with:
version: ${{ github.ref }}
manifest-file: rust-sdk/${{ matrix.package }}/Cargo.toml
- name: Deploy cargo
uses: ./.github/actions/anchor
with:
run: |
export CARGO_REGISTRY_TOKEN=${{ secrets.CRATES_TOKEN }}
yarn build rust-sdk/${{ matrix.package }} --output-style static
cd rust-sdk/${{ matrix.package }} && cargo publish --allow-dirty
- name: Install dependencies
run: yarn install
- name: Build package
run: yarn build rust-sdk/${{ matrix.package }} --output-style static
- name: Publish package
working-directory: rust-sdk/${{ matrix.package }}
run: cargo publish --allow-dirty

idl:
runs-on: ubuntu-latest
Expand All @@ -64,11 +70,10 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build idl
- name: Setup Anchor
uses: ./.github/actions/anchor
with:
run: |
anchor build
- name: Build idl
run: anchor build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ generated
generated
.docusaurus
.cache-loader
.devcontainer
.devcontainer
**/Cargo.lock
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
# yarn lint-staged
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn ts-mocha --timeout 1000000 legacy-sdk/whirlpool/**/*.test.ts"
test = "yarn vitest run --test-timeout 1000000 --no-file-parallelism --globals legacy-sdk/whirlpool/tests"

[test.validator]
slots_per_epoch = "33"
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ The program has been audited several times by different security firms.

***The new whirlpool SDKs are still in development and are not recommended for production use yet. Please see [Legacy](#legacy)***

This repository contains several libraries that can be used to interact with the Whirlpools contract. For most purposes you can use the full library (`@orca-so/whirlpools` and `orca-whirlpools`).
This repository contains several libraries that can be used to interact with the Whirlpools contract. For most purposes you can use the full library (`@orca-so/whirlpools` and `orca_whirlpools`).

For specific use-cases you can opt for integrating with lower level packages such as:
* `@orca-so/whirlpools-client` & `orca-whirlpools-client` - auto-generated client for the Whirlpools program that contains account, instruction and error parsing.
* `@orca-so/whirlpools-quoting` & `orca-whirlpools-quoting` - math lib used to calculate a quote for a given trade or liquidity action.
* `@orca-so/whirlpools-composite` & `orca-whirlpools-composite` - helper package for compositing instructions together for executing common actions.
* `@orca-so/whirlpools-utils` & `orca-whirlpools-utils` - utility and math functions used by other packages.
* `@orca-so/whirlpools-client` & `orca_whirlpools_client` - auto-generated client for the Whirlpools program that contains account, instruction and error parsing.
* `@orca-so/whirlpools-core` & `orca_whirlpools_core` - utility, math and quoting functions used by other packages.

### Legacy

Expand Down Expand Up @@ -91,8 +89,6 @@ If you look closely, the commands just call individual commands specified in the

If you want to stream the logs of a specific command you can add the `--output-style stream` flag to the command. This allows you to view the logs of the command as they are being produced which can be useful for longer running tasks like integration tests.

---

# Support

### Questions
Expand Down
1 change: 1 addition & 0 deletions docs/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"clean": "rimraf dist"
},
"devDependencies": {
"@orca-so/whirlpools": "*",
"@orca-so/whirlpools-sdk": "*",
"typedoc": "^0.26.10",
"typescript": "^5.6.3"
Expand Down
1 change: 1 addition & 0 deletions docs/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"devDependencies": {
"@orca-so/whirlpools": "*",
"@orca-so/whirlpools-sdk": "*",
"typedoc": "^0.26.10",
"typescript": "^5.6.3"
}
Expand Down
3 changes: 2 additions & 1 deletion docs/whirlpool/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default {
docs: {
routeBasePath: "/",
sidebarPath: "./sidebars.js",
editUrl: "https://github.com/orca-so/whirlpools/tree/main/docs/whirlpool",
editUrl:
"https://github.com/orca-so/whirlpools/tree/main/docs/whirlpool",
},
theme: {
customCss: "./static/index.css",
Expand Down
1 change: 0 additions & 1 deletion legacy-sdk/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@solana/web3.js": "^1.95.2"
},
"devDependencies": {
"@types/mocha": "^10.0.9",
"@types/mz": "^2.7.3",
"mz": "^2.7.0",
"typescript": "^5.6.3"
Expand Down
2 changes: 2 additions & 0 deletions legacy-sdk/whirlpool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@orca-so/whirlpools-program": "*",
"@solana/spl-token": "^0.4.8",
"@solana/web3.js": "^1.90.0",
"@types/bn.js": "~5.1.6",
"@types/jest": "^29.5.13",
"decimal.js": "^10.4.3",
"typescript": "^5.6.3"
},
Expand Down
4 changes: 2 additions & 2 deletions legacy-sdk/whirlpool/src/utils/public/price-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ export class PriceMath {
.toDecimalPlaces(0);

const lowerBoundSqrtPrice = BN.min(
BN.max(new BN(lowerBoundSqrtPriceDecimal.toString()), MIN_SQRT_PRICE_BN),
BN.max(new BN(lowerBoundSqrtPriceDecimal.toFixed(0)), MIN_SQRT_PRICE_BN),
MAX_SQRT_PRICE_BN,
);
const upperBoundSqrtPrice = BN.min(
BN.max(new BN(upperBoundSqrtPriceDecimal.toString()), MIN_SQRT_PRICE_BN),
BN.max(new BN(upperBoundSqrtPriceDecimal.toFixed(0)), MIN_SQRT_PRICE_BN),
MAX_SQRT_PRICE_BN,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("close_bundled_position", () => {
let whirlpoolPda: PDA;
const funderKeypair = anchor.web3.Keypair.generate();

before(async () => {
beforeAll(async () => {
poolInitInfo = (await initTestPool(ctx, TickSpacing.Standard)).poolInitInfo;
whirlpoolPda = poolInitInfo.whirlpoolPda;
await systemTransferTx(
Expand Down
Loading