diff --git a/.github/workflows/anchor-idl.yml b/.github/workflows/anchor-idl.yml new file mode 100644 index 000000000..3ecd8d643 --- /dev/null +++ b/.github/workflows/anchor-idl.yml @@ -0,0 +1,33 @@ +name: Anchor IDL CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: "18.19.1" + - name: Npm install + run: npm ci + - name: Install Solana + run: | + sh -c "$(curl -sSfL https://release.solana.com/v1.18.16/install)" + echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH + - name: Install Anchor + working-directory: ./staking + run: npm i -g @coral-xyz/anchor-cli@0.30.1 + - name: Build IDL + working-directory: ./staking + run: anchor build + - name: Check commited idl is up to date + working-directory: ./staking + run: git diff -G".*" --exit-code target/* diff --git a/.github/workflows/anchor.yml b/.github/workflows/anchor.yml index 7fa2efb30..99fd1e744 100644 --- a/.github/workflows/anchor.yml +++ b/.github/workflows/anchor.yml @@ -22,10 +22,10 @@ jobs: run: | sh -c "$(curl -sSfL https://release.solana.com/v1.18.16/install)" echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH - - name: Install Anchor - working-directory: ./staking - run: npm i -g @coral-xyz/anchor-cli@0.30.1 - - name: Anchor tests + - name: Install Solana Verify CLI + run: | + cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 098551f + - name: Javascript tests working-directory: ./staking run: npm run test:ci # Remove debug folder to avoid hitting space limit in ci @@ -36,6 +36,3 @@ jobs: - name: Cargo tests working-directory: ./staking run: RUST_MIN_STACK=33554432 cargo test - - name: Check commited idl is up to date - working-directory: ./staking - run: git diff -G".*" --exit-code target/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..1b0018d83 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release + +on: + tags: + - v* + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: "18.19.1" + - name: Install Solana Verify CLI + run: | + cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 098551f + - name: Build + working-directory: ./staking + run: solana-verify build + - name: Publish program binaries + working-directory: ./staking + uses: svenstaro/upload-release-action@133984371c30d34e38222a64855679a414cb7575 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./target/deploy/*.so + tag: ${{ github.ref }} + file_glob: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 041646cde..3a8eb7c28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: end-of-file-fixer exclude: staking/target - id: check-added-large-files - exclude: package-lock.json + exclude: package-lock.json|staking/tests/programs # Hook to format many type of files in the repo - repo: https://github.com/pre-commit/mirrors-prettier rev: "v2.7.1" diff --git a/staking/Anchor.toml b/staking/Anchor.toml index 7f8d0bfd5..d3a0d0ea7 100644 --- a/staking/Anchor.toml +++ b/staking/Anchor.toml @@ -50,8 +50,8 @@ ledger_dir = "./.anchor/test-ledger" [path] idl_path = "./target/idl/staking.json" binary_path = "./target/deploy/staking.so" -governance_path = "./target/deploy/governance.so" -chat_path = "./target/deploy/chat.so" +governance_path = "./tests/programs/governance.so" # This is the version of governance with the extra instructions for testing, check PR 184 for more info +chat_path = "./tests/programs/chat.so" wallet_tester_path = "./target/deploy/wallet_tester.so" profile_path = "./target/deploy/profile.so" integrity_pool_path = "./target/deploy/integrity_pool.so" diff --git a/staking/Cargo.lock b/staking/Cargo.lock index 24b34e4a0..08a017346 100644 --- a/staking/Cargo.lock +++ b/staking/Cargo.lock @@ -3063,7 +3063,7 @@ dependencies = [ [[package]] name = "pyth-staking-program" -version = "1.2.0" +version = "2.0.0" dependencies = [ "ahash 0.8.11", "anchor-lang", diff --git a/staking/Dockerfile b/staking/Dockerfile deleted file mode 100644 index d75bce347..000000000 --- a/staking/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# -# Docker image to generate a deterministic build of the Pyth Staking Program -# program. This image extends projectserum/build which is based on backpackapp/build -# but with a specific version of the Solana CLI and Anchor CLI. -# - -FROM backpackapp/build:v0.30.1@sha256:c160fe32cba7c463981110b2aac2924de4833c06a0af6473a830ead880c4ef3b - -ARG TEST=false -ENV TEST_ENV=$TEST -WORKDIR /workspace - -COPY . . - -CMD ["bash", "-c", \ - "if [ \"$TEST_ENV\" = \"true\" ]; then anchor build -- --features mock-clock; else anchor build; fi && if [ \"$TEST_ENV\" = \"true\" ]; then chmod -R 777 target/; fi"] diff --git a/staking/clone_programs.sh b/staking/clone_programs.sh deleted file mode 100755 index 603f1f401..000000000 --- a/staking/clone_programs.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -if [ ! -f target/deploy/governance.so ] -then - # This is the real governance - # solana program dump -u mainnet-beta GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw ./target/deploy/governance.so - # This is the version of governance with the extra instructions for testing, check PR 184 for more info: - solana program dump -u devnet 2WFsTyAoD4Q9stTgSAyz1xZ38D4bmdLxGngvcr53jcK3 ./target/deploy/governance.so -fi -if [ ! -f target/deploy/chat.so ] -then - solana program dump -u devnet gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET ./target/deploy/chat.so -fi diff --git a/staking/package.json b/staking/package.json index fbf4b842e..0c930c5e6 100644 --- a/staking/package.json +++ b/staking/package.json @@ -44,11 +44,10 @@ "wasm-pack": "^0.10.2" }, "scripts": { - "test": "npm run build_wasm && anchor build -- --features mock-clock && npm run dump_governance && ts-mocha --parallel -p ./tsconfig.json -t 1000000", - "test:ci": "npm run build_wasm && ./scripts/build_verifiable_staking_program.sh -t && npm run dump_governance && ts-mocha --parallel -p ./tsconfig.json -t 1000000 tests/*.ts", + "test": "npm run build_wasm && anchor build -- --features mock-clock && ts-mocha --parallel -p ./tsconfig.json -t 1000000", + "test:ci": "npm run build_wasm && mkdir -p target/debug && solana-verify build -- --features mock-clock && ts-mocha --parallel -p ./tsconfig.json -t 1000000 tests/*.ts", "build": "npm run build_wasm && tsc -p tsconfig.api.json", "build_wasm": "./scripts/build_wasm.sh", - "localnet": "anchor build && npm run dump_governance && ts-node ./app/scripts/localnet.ts", - "dump_governance": "./clone_programs.sh" + "localnet": "anchor build && ts-node ./app/scripts/localnet.ts" } } diff --git a/staking/programs/staking/Cargo.toml b/staking/programs/staking/Cargo.toml index 15d7ec2e2..57c8dd660 100644 --- a/staking/programs/staking/Cargo.toml +++ b/staking/programs/staking/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyth-staking-program" -version = "1.2.0" +version = "2.0.0" description = "Created with Anchor" edition = "2018" diff --git a/staking/scripts/build_verifiable_staking_program.sh b/staking/scripts/build_verifiable_staking_program.sh deleted file mode 100755 index 5c8ee0ee4..000000000 --- a/staking/scripts/build_verifiable_staking_program.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Root of the repository -REPO_ROOT=$(git rev-parse --show-toplevel) - -# Default value for TEST -TEST=false - -# Parse command-line arguments -# -t: build the staking program for tests -while getopts "t" opt; do - case ${opt} in - t) - TEST=true - ;; - \?) - echo "Invalid option: -$OPTARG" 1>&2 - exit 1 - ;; - esac -done - -if [ "$TEST" = "true" ]; then - echo "Building the image for the staking program test" - docker build --platform linux/amd64 --build-arg TEST=true -t staking-build-test -f "$REPO_ROOT"/staking/Dockerfile "$REPO_ROOT"/staking -else - echo "Building the image for the staking program production" - docker build --platform linux/amd64 -t staking-build -f "$REPO_ROOT"/staking/Dockerfile "$REPO_ROOT"/staking -fi - -if [ "$TEST" = "true" ]; then - echo "Building the staking program test" - docker run --platform linux/amd64 --rm -v "$REPO_ROOT"/staking/target:/workspace/target staking-build-test -else - echo "Building the staking program" - docker run --platform linux/amd64 --rm -v "$REPO_ROOT"/staking/target:/workspace/target staking-build -fi - -echo "Successfully built the staking program." -echo "The artifacts are available at $REPO_ROOT/staking/target" - -CHECKSUM=$(sha256sum $REPO_ROOT/staking/target/deploy/staking.so | awk '{print $1}') -echo "sha256sum of the staking program: $CHECKSUM" diff --git a/staking/target/idl/staking.json b/staking/target/idl/staking.json index ffae4f43e..4c2c40476 100644 --- a/staking/target/idl/staking.json +++ b/staking/target/idl/staking.json @@ -2,7 +2,7 @@ "address": "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ", "metadata": { "name": "staking", - "version": "1.2.0", + "version": "2.0.0", "spec": "0.1.0", "description": "Created with Anchor" }, diff --git a/staking/target/types/staking.ts b/staking/target/types/staking.ts index f74469c85..a4c70c29a 100644 --- a/staking/target/types/staking.ts +++ b/staking/target/types/staking.ts @@ -8,7 +8,7 @@ export type Staking = { "address": "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ", "metadata": { "name": "staking", - "version": "1.2.0", + "version": "2.0.0", "spec": "0.1.0", "description": "Created with Anchor" }, diff --git a/staking/tests/programs/chat.so b/staking/tests/programs/chat.so new file mode 100644 index 000000000..2c1b25d65 Binary files /dev/null and b/staking/tests/programs/chat.so differ diff --git a/staking/tests/programs/governance.so b/staking/tests/programs/governance.so new file mode 100644 index 000000000..ed101371d Binary files /dev/null and b/staking/tests/programs/governance.so differ