diff --git a/.github/.env b/.github/.env index 7d18d807..d275c063 100644 --- a/.github/.env +++ b/.github/.env @@ -3,3 +3,5 @@ NODE_VERSION=20.x PROGRAMS=["program"] RUST_VERSION=1.78.0 SOLANA_VERSION=1.17.34 +VERIFY_BUILD_VERSION=0.2.11 + diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 41fd1ea0..2ca7f310 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @richardwu @samuelvanderwaal +* @richardwu @nftechie @leantOnSol diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 3b2c66ec..f8f6537f 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -5,7 +5,7 @@ # Programs. program_common: &program_common - - ".github/workflows/build-programs.yml" + - ".github/workflows/build-verify-programs.yml" - ".github/workflows/test-programs.yml" - ".github/workflows/main.yml" - ".github/file-filters.yml" diff --git a/.github/workflows/build-programs.yml b/.github/workflows/build-verify-programs.yml similarity index 62% rename from .github/workflows/build-programs.yml rename to .github/workflows/build-verify-programs.yml index 9d52bb42..b8eb4f0d 100644 --- a/.github/workflows/build-programs.yml +++ b/.github/workflows/build-verify-programs.yml @@ -1,4 +1,4 @@ -name: Build Programs +name: Build Verify Programs on: workflow_call: @@ -13,12 +13,12 @@ on: inputs: rust: description: Rust version - default: 1.78.0 + default: 1.75.0 required: true type: string solana: description: Solana version - default: 1.17.34 + default: 1.17.22 required: true type: string node: @@ -26,15 +26,20 @@ on: default: 20.x required: true type: string + verify: + description: Verify build version + default: 0.2.11 + required: true + type: string env: CACHE: true CARGO_NET_GIT_FETCH_WITH_CLI: "true" - ARTIFACTS_TOKEN: ${{ secrets.ARTIFACTS_TOKEN }} RPC: ${{ secrets.SOLANA_MAINNET_RPC_URL }} + ARTIFACTS_TOKEN: ${{ secrets.ARTIFACTS_TOKEN }} jobs: - build_programs: + build_verify_programs: name: Build runs-on: ubuntu-latest steps: @@ -42,12 +47,12 @@ jobs: uses: actions/checkout@v4 - name: Setup SSH agent - uses: tensor-foundation/actions/ssh-agent@v1 + uses: tensor-foundation/actions/ssh-agent@v2 with: key: | + ${{ secrets.ESCROW_KEY }} ${{ secrets.TOOLBOX_KEY }} ${{ secrets.WHITELIST_KEY }} - ${{ secrets.ESCROW_KEY }} - name: Load environment variables run: cat .github/.env >> $GITHUB_ENV @@ -58,7 +63,7 @@ jobs: toolchain: ${{ inputs.rust || env.RUST_VERSION }} - name: Install Solana - uses: tensor-foundation/actions/install-solana@v2.1 + uses: tensor-foundation/actions/install-solana@v3 with: version: ${{ inputs.solana || env.SOLANA_VERSION }} cache: ${{ env.CACHE }} @@ -76,10 +81,25 @@ jobs: with: folder: "." key: programs + + - name: Dump mainnet binaries + run: pnpm programs:dump_binaries:mainnet + + - name: Cache solana-verify + uses: actions/cache@v4 + id: cache-verify + with: + path: /home/runner/.cargo-install/solana-verify + key: solana-verify-${{ inputs.verify || env.VERIFY_BUILD_VERSION }}-${{ runner.os }} + + - name: Install verify build + if: steps.cache-verify.outputs.cache-hit != 'true' + run: cargo install solana-verify --force --root /home/runner/.cargo-install/solana-verify --version ${{ inputs.verify || env.VERIFY_BUILD_VERSION }} --locked - - name: Build programs + - name: Verify build program shell: bash - run: pnpm programs:build + run: | + /home/runner/.cargo-install/solana-verify/bin/solana-verify build --library-name amm_program | tee >(tail -n 1 > build_hash.txt) - name: Upload programs build uses: actions/upload-artifact@v4 @@ -88,5 +108,7 @@ jobs: # First wildcard ensures exported paths are consistently under the programs folder. path: | ./targe*/deploy/*.so + build_hash.txt ./targe*/deploy/*.json - if-no-files-found: error + !./targe*/deploy/*keypair*.json + if-no-files-found: error \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3013aef..5df8c9ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -137,11 +137,11 @@ jobs: command: clippy args: --all-targets --all-features --no-deps -- -D warnings - build_programs: + build_verify_programs: name: Programs if: ${{ needs.changes.outputs.any == 'true' }} needs: [changes, lint_js, lint_rust] - uses: ./.github/workflows/build-programs.yml + uses: ./.github/workflows/build-verify-programs.yml secrets: inherit test_programs: @@ -156,7 +156,7 @@ jobs: generate_clients: name: Generate Clients if: ${{ needs.changes.outputs.any == 'true' }} - needs: [changes, build_programs] + needs: [changes, build_verify_programs] runs-on: ubuntu-latest steps: - name: Git checkout diff --git a/.github/workflows/publish-js-client.yml b/.github/workflows/publish-js-client.yml index 3003de52..d7fca658 100644 --- a/.github/workflows/publish-js-client.yml +++ b/.github/workflows/publish-js-client.yml @@ -3,26 +3,13 @@ name: Publish JS Client on: workflow_dispatch: inputs: - bump: - description: Version bump - required: true - default: patch - type: choice - options: - - patch - - minor - - major - - prerelease - - prepatch - - preminor - - premajor tag: - description: NPM Tag (and preid for pre-releases) + description: NPM Tag required: true type: string default: latest - create_release: - description: Create a GitHub release + dry_run: + description: Dry run required: true type: boolean default: true @@ -31,19 +18,22 @@ env: CACHE: true jobs: - build_programs: + build_verify_programs: name: Programs - uses: ./.github/workflows/build-programs.yml + if: github.ref == 'refs/heads/main' || inputs.dry_run == true + uses: ./.github/workflows/build-verify-programs.yml secrets: inherit test_js: name: JS client - needs: build_programs + if: github.ref == 'refs/heads/main' || inputs.dry_run == true + needs: build_verify_programs uses: ./.github/workflows/test-js-client.yml secrets: inherit publish_js: name: JS client / Publish + if: github.ref == 'refs/heads/main' || inputs.dry_run == true runs-on: ubuntu-latest needs: test_js permissions: @@ -71,17 +61,11 @@ jobs: - name: Build working-directory: ./clients/js run: pnpm build - - - name: Bump - id: bump + + - name: Get version + id: get_version working-directory: ./clients/js - run: | - if [ "${{ startsWith(inputs.bump, 'pre') }}" == "true" ]; then - pnpm version ${{ inputs.bump }} --preid ${{ inputs.tag }} --no-git-tag-version - else - pnpm version ${{ inputs.bump }} --no-git-tag-version - fi - echo "new_version=$(pnpm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT + run: echo "version=$(pnpm pkg get version | sed 's/"//g')" >> $GITHUB_OUTPUT - name: Set publishing config run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" @@ -90,40 +74,4 @@ jobs: - name: Publish working-directory: ./clients/js - run: pnpm publish --no-git-checks --tag ${{ inputs.tag }} - - - name: Commit and tag new version - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Deploy JS client v${{ steps.bump.outputs.new_version }} - tagging_message: js@v${{ steps.bump.outputs.new_version }} - - - name: Create GitHub release - if: github.event.inputs.create_release == 'true' - uses: ncipollo/release-action@v1 - with: - tag: js@v${{ steps.bump.outputs.new_version }} - - deploy_js_docs: - name: JS client / Deploy docs - runs-on: ubuntu-latest - needs: publish_js - environment: - name: js-client-documentation - url: ${{ steps.deploy.outputs.url }} - steps: - - name: Git checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.ref }} - - - name: Load environment variables - run: cat .github/.env >> $GITHUB_ENV - - - name: Deploy to Vercel - id: deploy - env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - working-directory: ./clients/js - run: echo "url=$(vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }})" | tee $GITHUB_OUTPUT + run: pnpm publish --no-git-checks --tag ${{ inputs.tag }} ${{ inputs.dry_run && '--dry-run' || '' }} \ No newline at end of file diff --git a/.github/workflows/publish-rust-client.yml b/.github/workflows/publish-rust-client.yml index ff678f57..ceee50f1 100644 --- a/.github/workflows/publish-rust-client.yml +++ b/.github/workflows/publish-rust-client.yml @@ -31,9 +31,9 @@ env: CACHE: true jobs: - build_programs: + build_verify_programs: name: Programs - uses: ./.github/workflows/build-programs.yml + uses: ./.github/workflows/build-verify-programs.yml secrets: inherit build_rust_client: @@ -43,7 +43,7 @@ jobs: test_rust_client: name: Rust Client - needs: [build_programs, build_rust_client] + needs: [build_verify_programs, build_rust_client] uses: ./.github/workflows/test-rust-client.yml secrets: inherit diff --git a/Cargo.lock b/Cargo.lock index c7bde614..94208515 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,7 +85,7 @@ dependencies = [ "spl-token-metadata-interface", "static_assertions", "tensor-escrow", - "tensor-toolbox 0.8.0", + "tensor-toolbox 0.8.1", "tensor-vipers", "whitelist-program", ] @@ -1007,12 +1007,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "escrow-program" -version = "0.1.0" -source = "git+ssh://git@github.com/tensor-foundation/escrow#7b880e3ae0529a6d360f973bf5f95d4be4056925" +version = "1.0.0-beta.1" +source = "git+https://github.com/tensor-foundation/escrow.git#21fc10786e4bf538062f9a59d9e8f8b085ad3a6e" dependencies = [ "anchor-lang", "anchor-spl", - "tensor-toolbox 0.1.0", + "tensor-toolbox 0.4.0", "tensor-vipers", ] @@ -2585,30 +2585,14 @@ dependencies = [ [[package]] name = "tensor-toolbox" -version = "0.0.5" -source = "git+ssh://git@github.com/tensor-foundation/toolbox.git?rev=16d98bc#16d98bcf5098156a806aa2a318cfc73b0d021172" -dependencies = [ - "anchor-lang", - "anchor-spl", - "bytemuck", - "mpl-bubblegum", - "mpl-token-metadata", - "solana-program", - "spl-account-compression", - "spl-noop", - "spl-token-metadata-interface", - "vipers 2.0.6 (git+ssh://git@github.com/tensor-foundation/toolbox.git?rev=16d98bc)", -] - -[[package]] -name = "tensor-toolbox" -version = "0.1.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50bf6f3c07d2010b30018e6ab4240bcf30b4bb2bc83cb8a5eff1c1ee9929d55" +checksum = "86ad0af7b3655fac8e00f9baffa5a91026bb66858cd3a3c4208e8f523d306dbf" dependencies = [ "anchor-lang", "anchor-spl", "bytemuck", + "mpl-bubblegum", "mpl-token-metadata", "solana-program", "spl-account-compression", @@ -2619,9 +2603,9 @@ dependencies = [ [[package]] name = "tensor-toolbox" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "515659dd8e1a324f23ced4d99d6a150ac8fac4d78c2cc0252b5dd5c39213192b" +checksum = "43285c2352ece2be5389708c13ff2241f6c12cb046ff9ef8c8d9bc831cdb6d65" dependencies = [ "anchor-lang", "anchor-spl", @@ -2800,26 +2784,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "vipers" -version = "2.0.6" -source = "git+ssh://git@github.com/tensor-foundation/toolbox.git?rev=16d98bc#16d98bcf5098156a806aa2a318cfc73b0d021172" -dependencies = [ - "anchor-lang", - "anchor-spl", - "num-traits", -] - -[[package]] -name = "vipers" -version = "2.0.6" -source = "git+ssh://git@github.com/tensor-foundation/toolbox.git#1a50964f7e860d13d59b6ae654164824e9ad3e07" -dependencies = [ - "anchor-lang", - "anchor-spl", - "num-traits", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -2898,14 +2862,14 @@ dependencies = [ [[package]] name = "whitelist-program" -version = "0.0.0" -source = "git+ssh://git@github.com/tensor-foundation/whitelist.git?rev=346eac4#346eac46e4cc6dbc5462423ad1a7ee9c392aa112" +version = "0.2.3" +source = "git+https://github.com/tensor-foundation/whitelist.git#17ee287051181f28358ca7eeb883e20a1211d058" dependencies = [ "anchor-lang", "anchor-spl", "mpl-token-metadata", - "tensor-toolbox 0.0.5", - "vipers 2.0.6 (git+ssh://git@github.com/tensor-foundation/toolbox.git)", + "tensor-toolbox 0.4.0", + "tensor-vipers", ] [[package]] diff --git a/clients/js/test/pricingHelpers.test.ts b/clients/js/test/pricingHelpers.test.ts index 6e4454eb..455f0c0a 100644 --- a/clients/js/test/pricingHelpers.test.ts +++ b/clients/js/test/pricingHelpers.test.ts @@ -605,7 +605,13 @@ test('getAmountOfBids base case exponential', (t) => { mmFeeBps: 0, }; const amountOfBids = getAmountOfBids({ - pool: { config, priceOffset: 0, maxTakerSellCount: 0, sharedEscrow: null }, + pool: { + config, + priceOffset: 0, + maxTakerSellCount: 0, + sharedEscrow: null, + stats: { takerSellCount: 0, takerBuyCount: 0, accumulatedMmProfit: 0n }, + }, availableLamports: 1n * ONE_SOL, }); t.true(amountOfBids === 1); @@ -621,7 +627,13 @@ test('getAmountOfBids base case linear', (t) => { mmFeeBps: null, }; const amountOfBids = getAmountOfBids({ - pool: { config, priceOffset: 0, maxTakerSellCount: 0, sharedEscrow: null }, + pool: { + config, + priceOffset: 0, + maxTakerSellCount: 0, + sharedEscrow: null, + stats: { takerSellCount: 0, takerBuyCount: 0, accumulatedMmProfit: 0n }, + }, availableLamports: 1n * ONE_SOL, }); t.true(amountOfBids === 1); diff --git a/package.json b/package.json index 0c1004e5..4e6287d4 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "programs:build:artifacts": "zx ./scripts/program/build.mjs artifacts", "programs:build:devnet": "zx ./scripts/program/build.mjs devnet", "programs:build:mainnet": "zx ./scripts/program/build.mjs mainnet", + "programs:dump_binaries:devnet": "zx ./scripts/program/dump_devnet_external.mjs && zx ./scripts/program/dump_devnet_others.mjs", + "programs:dump_binaries:mainnet": "zx ./scripts/program/dump_mainnet_external.mjs && zx ./scripts/program/dump_mainnet_others.mjs", "programs:test": "zx ./scripts/program/test.mjs", "programs:clean": "zx ./scripts/program/clean.mjs", "programs:format": "zx ./scripts/program/format.mjs", diff --git a/program/Cargo.toml b/program/Cargo.toml index dc4320fc..32024fd8 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -47,7 +47,7 @@ cpi = ["no-entrypoint"] [dependencies] anchor-lang = { version = "0.29.0", features = ["init-if-needed"] } anchor-spl = { version = "0.29.0", features = ["default"] } -escrow-program = { version = "0.1.0", package = "escrow-program", git = "ssh://git@github.com/tensor-foundation/escrow", features = [ +escrow-program = { version = "1.0.0-beta.1", package = "escrow-program", git = "https://github.com/tensor-foundation/escrow.git", features = [ "cpi", ] } mpl-core = { package = "mpl-core", version = "0.7.2" } @@ -57,9 +57,9 @@ spl-math = { version = "0.1.0", features = ["no-entrypoint"] } spl-token-metadata-interface = "0.2.0" static_assertions = "1.1.0" tensor-escrow = { version = "0.1.1" } -tensor-toolbox = { version = "0.8.0", features = ["token-2022", "mpl-core"] } +tensor-toolbox = { version = "0.8.1", features = ["token-2022", "mpl-core"] } tensor-vipers = { version = "1.0.1" } -whitelist-program = { package = "whitelist-program", git = "ssh://git@github.com/tensor-foundation/whitelist.git", rev = "346eac4", features = [ +whitelist-program = { package = "whitelist-program", git = "https://github.com/tensor-foundation/whitelist.git", features = [ "cpi", ] } diff --git a/scripts/program/build.mjs b/scripts/program/build.mjs index eb9910ee..928600bb 100644 --- a/scripts/program/build.mjs +++ b/scripts/program/build.mjs @@ -5,12 +5,13 @@ import { workingDirectory, getProgramFolders } from "../utils.mjs"; const whereToFetchBinariesFrom = argv._.filter(a => a !== path.basename(__filename))[0]; // Save external programs binaries to the output directory. -import "./dump_mainnet_external.mjs"; +if(whereToFetchBinariesFrom === "artifacts" || whereToFetchBinariesFrom === "mainnet") await import("./dump_mainnet_external.mjs"); +else await import("./dump_devnet_external.mjs"); -// Fetch "Offchain"ProgramAddresse from artifacts/mainnet/devnet +// Fetch binaries (potentially offchain) from artifacts/mainnet/devnet if(whereToFetchBinariesFrom === "artifacts") await import("../fetch-external-binaries.mjs"); else if(whereToFetchBinariesFrom === "mainnet") await import("./dump_mainnet_others.mjs"); -else await import("./dump_devnet.mjs"); +else await import("./dump_devnet_others.mjs"); // Build the programs. for (const folder of getProgramFolders()) { diff --git a/scripts/program/dump_devnet_external.mjs b/scripts/program/dump_devnet_external.mjs new file mode 100644 index 00000000..f8b33295 --- /dev/null +++ b/scripts/program/dump_devnet_external.mjs @@ -0,0 +1,22 @@ +#!/usr/bin/env zx +import "zx/globals"; +import { + getExternalAccountAddresses, + getExternalProgramAddresses, + getExternalProgramOutputDir, +} from "../utils.mjs"; +import { dump } from "./dump.mjs"; + +// Get input from environment variables. +const rpc = "https://api.devnet.solana.com"; +const outputDir = getExternalProgramOutputDir(); +// Ensure we have some external programs/accounts to dump. +const programs = getExternalProgramAddresses(); +const accounts = getExternalAccountAddresses(); +const addresses = [ + ...programs.map((program) => `${program}.so`), + ...accounts.map((account) => `${account}.json`), +].flat(); + +echo(`Dumping external accounts to '${outputDir}':`); +await dump(rpc, outputDir, addresses); \ No newline at end of file diff --git a/scripts/program/dump_devnet.mjs b/scripts/program/dump_devnet_others.mjs similarity index 100% rename from scripts/program/dump_devnet.mjs rename to scripts/program/dump_devnet_others.mjs diff --git a/scripts/program/dump_mainnet_others.mjs b/scripts/program/dump_mainnet_others.mjs index d4850a30..29cc0a10 100644 --- a/scripts/program/dump_mainnet_others.mjs +++ b/scripts/program/dump_mainnet_others.mjs @@ -15,5 +15,5 @@ const addresses = [ ...programs.map((program) => `${program}.so`), ].flat(); -echo(`Dumping external accounts from devnet to '${outputDir}':`); +echo(`Dumping external accounts from mainnet to '${outputDir}':`); await dump(rpc, outputDir, addresses); \ No newline at end of file