From 7eeab51398a67abe08999ddc5c6b5e693537c1cb Mon Sep 17 00:00:00 2001 From: gallynaut Date: Mon, 18 Sep 2023 08:31:59 -0600 Subject: [PATCH] chore: pull monorepo changes (#131) * Project import generated by Copybara. GitOrigin-RevId: 968ada589196194c2f24c4761a5d106b4eb18e03 * chore: manual import cleanup * chore: Update pnpm lockfile --------- Co-authored-by: Copybara Co-authored-by: gallynaut --- examples/functions/01_basic_oracle/Cargo.lock | 8 +- examples/functions/01_basic_oracle/Cargo.toml | 4 +- .../functions/01_basic_oracle/package.json | 2 +- .../.gitignore | 0 .../Cargo.lock | 0 .../Cargo.toml | 4 +- .../Dockerfile | 11 +- .../Dockerfile.dev | 17 +- .../Makefile | 9 +- .../package.json | 0 .../src/binance.rs | 0 .../src/main.rs | 0 .../functions/02_liquidity_oracle/Cargo.lock | 19 +- .../functions/02_liquidity_oracle/Cargo.toml | 4 +- .../sgx-function/Dockerfile.dev | 44 ---- .../src/actions/trigger_function.rs | 18 +- .../.gitignore | 0 .../Cargo.lock | 0 .../switchboard-function}/Cargo.toml | 4 +- .../Dockerfile | 8 +- .../switchboard-function}/Dockerfile.dev | 14 +- .../Makefile | 0 .../package.json | 0 .../src/binance.rs | 0 .../src/bitfinex.rs | 0 .../src/coinbase.rs | 0 .../src/kraken.rs | 0 .../src/main.rs | 0 .../functions/03_candles_oracle/Cargo.lock | 19 +- .../functions/03_candles_oracle/Cargo.toml | 4 +- .../src/actions/trigger_function.rs | 6 +- .../.gitignore | 0 .../Cargo.lock | 0 .../switchboard-function}/Cargo.toml | 6 +- .../Dockerfile | 8 +- .../switchboard-function/Dockerfile.dev | 52 ++++ .../Makefile | 0 .../package.json | 0 .../src/binance.rs | 0 .../src/bitfinex.rs | 0 .../src/coinbase.rs | 0 .../src/kraken.rs | 0 .../src/main.rs | 0 .../04_randomness_callback/Cargo.lock | 244 +----------------- .../04_randomness_callback/Cargo.toml | 4 +- .../04_randomness_callback/src/lib.rs | 2 + .../.dockerignore | 0 .../.gitignore | 0 .../Cargo.lock | 0 .../Cargo.toml | 4 +- .../Dockerfile | 2 +- .../Dockerfile.dev | 15 +- .../Makefile | 0 .../README.md | 0 .../package.json | 0 .../src/main.rs | 0 .../src/params.rs | 0 .../functions/05_raffle_program/Cargo.lock | 19 +- .../functions/05_raffle_program/Cargo.toml | 4 +- .../src/actions/start_round.rs | 20 +- .../.dockerignore | 0 .../Cargo.lock | 0 .../Cargo.toml | 4 +- .../Dockerfile | 0 .../Makefile | 0 .../README.md | 0 .../src/main.rs | 0 .../src/params.rs | 0 .../solana.js/idl/attestation-devnet.json | 19 +- javascript/solana.js/package.json | 2 +- .../src/accounts/switchboardWallet.ts | 37 ++- .../instructions/functionRequestClose.ts | 2 +- .../instructions/functionRequestInit.ts | 2 +- .../functionRequestInitAndTrigger.ts | 4 + .../instructions/walletWithdraw.ts | 2 +- javascript/solana.js/test/new_wallet.spec.ts | 144 +++++++++++ pnpm-lock.yaml | 27 +- rust/switchboard-solana/Cargo.lock | 2 +- rust/switchboard-solana/Cargo.toml | 2 +- .../accounts/attestation_state.rs | 8 + .../attestation_program/instructions/mod.rs | 3 + .../instructions/request_close.rs | 2 +- .../instructions/request_init.rs | 74 +++++- .../instructions/request_init_and_trigger.rs | 79 ++++++ .../instructions/wallet_withdraw.rs | 99 +++++++ .../src/client/function_runner.rs | 70 +++-- rust/switchboard-solana/src/instructions.rs | 2 +- rust/switchboard-solana/src/types.rs | 2 +- 88 files changed, 716 insertions(+), 445 deletions(-) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/.gitignore (100%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/Cargo.lock (100%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/Cargo.toml (71%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/Dockerfile (71%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/Dockerfile.dev (71%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/Makefile (86%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/package.json (100%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/src/binance.rs (100%) rename examples/functions/01_basic_oracle/{sgx-function => switchboard-function}/src/main.rs (100%) delete mode 100644 examples/functions/02_liquidity_oracle/sgx-function/Dockerfile.dev rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/.gitignore (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/Cargo.lock (100%) rename examples/functions/{03_candles_oracle/sgx-function => 02_liquidity_oracle/switchboard-function}/Cargo.toml (75%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/Dockerfile (71%) rename examples/functions/{03_candles_oracle/sgx-function => 02_liquidity_oracle/switchboard-function}/Dockerfile.dev (72%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/Makefile (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/package.json (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/src/binance.rs (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/src/bitfinex.rs (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/src/coinbase.rs (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/src/kraken.rs (100%) rename examples/functions/02_liquidity_oracle/{sgx-function => switchboard-function}/src/main.rs (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/.gitignore (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/Cargo.lock (100%) rename examples/functions/{02_liquidity_oracle/sgx-function => 03_candles_oracle/switchboard-function}/Cargo.toml (66%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/Dockerfile (71%) create mode 100644 examples/functions/03_candles_oracle/switchboard-function/Dockerfile.dev rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/Makefile (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/package.json (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/src/binance.rs (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/src/bitfinex.rs (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/src/coinbase.rs (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/src/kraken.rs (100%) rename examples/functions/03_candles_oracle/{sgx-function => switchboard-function}/src/main.rs (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/.dockerignore (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/.gitignore (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/Cargo.lock (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/Cargo.toml (60%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/Dockerfile (91%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/Dockerfile.dev (85%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/Makefile (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/README.md (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/package.json (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/src/main.rs (100%) rename examples/functions/04_randomness_callback/{sgx-function => switchboard-function}/src/params.rs (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/.dockerignore (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/Cargo.lock (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/Cargo.toml (64%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/Dockerfile (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/Makefile (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/README.md (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/src/main.rs (100%) rename examples/functions/05_raffle_program/{sgx-function => switchboard-function}/src/params.rs (100%) create mode 100644 javascript/solana.js/test/new_wallet.spec.ts create mode 100644 rust/switchboard-solana/src/attestation_program/instructions/wallet_withdraw.rs diff --git a/examples/functions/01_basic_oracle/Cargo.lock b/examples/functions/01_basic_oracle/Cargo.lock index 4a4d59ff2..8ca881c62 100644 --- a/examples/functions/01_basic_oracle/Cargo.lock +++ b/examples/functions/01_basic_oracle/Cargo.lock @@ -4225,9 +4225,9 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" [[package]] name = "switchboard-common" -version = "0.8.7" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83bfe6e728a1f2500bdbdddd3c17de1faf031f3d6c5f186a889ce66c80377e4" +checksum = "1c9e28848b864786d8b1835f1f0c4c7e65190d9c17b246e5e21cc2457a70b176" dependencies = [ "envy", "getrandom 0.2.10", @@ -4240,9 +4240,9 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.4" +version = "0.28.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dab64de18aaea4bde26fbaf931c7a02d7ede957c880626b8cdf029f98c086a80" +checksum = "0213e971a7eb8910e228a473219e5eee3c799a3365cb33cf2ad482d58044ec4c" dependencies = [ "anchor-client", "anchor-lang", diff --git a/examples/functions/01_basic_oracle/Cargo.toml b/examples/functions/01_basic_oracle/Cargo.toml index 4e345144f..9532b9a10 100644 --- a/examples/functions/01_basic_oracle/Cargo.toml +++ b/examples/functions/01_basic_oracle/Cargo.toml @@ -19,6 +19,6 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -switchboard-solana = { version = "=0.28.15", features = [ ] } -# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } +switchboard-solana = { version = "0.28.19", features = [] } +# switchboard-solana = { version = "0.28.19", path = "../../../rust/switchboard-solana" } bytemuck = "^1" diff --git a/examples/functions/01_basic_oracle/package.json b/examples/functions/01_basic_oracle/package.json index 6ce9909cc..9a555e3ad 100644 --- a/examples/functions/01_basic_oracle/package.json +++ b/examples/functions/01_basic_oracle/package.json @@ -15,7 +15,7 @@ "@coral-xyz/anchor": "^0.28.0", "@solana/spl-token": "^0.3.6", "@solana/web3.js": "^1.78.0", - "@switchboard-xyz/solana.js": "workspace:*" + "@switchboard-xyz/solana.js": "workspace:^" }, "devDependencies": { "@types/bn.js": "^5.1.0", diff --git a/examples/functions/01_basic_oracle/sgx-function/.gitignore b/examples/functions/01_basic_oracle/switchboard-function/.gitignore similarity index 100% rename from examples/functions/01_basic_oracle/sgx-function/.gitignore rename to examples/functions/01_basic_oracle/switchboard-function/.gitignore diff --git a/examples/functions/01_basic_oracle/sgx-function/Cargo.lock b/examples/functions/01_basic_oracle/switchboard-function/Cargo.lock similarity index 100% rename from examples/functions/01_basic_oracle/sgx-function/Cargo.lock rename to examples/functions/01_basic_oracle/switchboard-function/Cargo.lock diff --git a/examples/functions/01_basic_oracle/sgx-function/Cargo.toml b/examples/functions/01_basic_oracle/switchboard-function/Cargo.toml similarity index 71% rename from examples/functions/01_basic_oracle/sgx-function/Cargo.toml rename to examples/functions/01_basic_oracle/switchboard-function/Cargo.toml index 30ecce3a9..3c1f9564b 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Cargo.toml +++ b/examples/functions/01_basic_oracle/switchboard-function/Cargo.toml @@ -16,6 +16,6 @@ futures = "0.3" serde = "^1" serde_json = "^1" switchboard-utils = "0.8.0" -switchboard-solana = { version = "=0.28.15", features = [ "client" ] } -# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } +switchboard-solana = { version = "0.28.19" } +# switchboard-solana = { version = "0.28.19", path = "../../../../rust/switchboard-solana" } # switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" } diff --git a/examples/functions/01_basic_oracle/sgx-function/Dockerfile b/examples/functions/01_basic_oracle/switchboard-function/Dockerfile similarity index 71% rename from examples/functions/01_basic_oracle/sgx-function/Dockerfile rename to examples/functions/01_basic_oracle/switchboard-function/Dockerfile index aa7e3219f..abcb3bb4c 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Dockerfile +++ b/examples/functions/01_basic_oracle/switchboard-function/Dockerfile @@ -1,22 +1,19 @@ # syntax=docker/dockerfile:1.4 FROM switchboardlabs/sgx-function AS builder -ARG CARGO_NAME=switchboard-function -ENV CARGO_NAME=$CARGO_NAME - WORKDIR /home/root/switchboard-function COPY ./Cargo.lock ./Cargo.toml ./ COPY ./src ./src -WORKDIR /home/root/switchboard-function/sgx-function -COPY ./sgx-function/Cargo.lock ./sgx-function/Cargo.toml ./ -COPY ./sgx-function/src ./src +WORKDIR /home/root/switchboard-function/switchboard-function +COPY ./switchboard-function/Cargo.lock ./switchboard-function/Cargo.toml ./ +COPY ./switchboard-function/src ./src RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} \ --mount=type=cache,target=target,id=${TARGETPLATFORM} \ cargo build --release && \ cargo strip && \ - mv target/release/${CARGO_NAME} /sgx/app + mv target/release/basic-oracle-function /sgx/app FROM switchboardlabs/sgx-function diff --git a/examples/functions/01_basic_oracle/sgx-function/Dockerfile.dev b/examples/functions/01_basic_oracle/switchboard-function/Dockerfile.dev similarity index 71% rename from examples/functions/01_basic_oracle/sgx-function/Dockerfile.dev rename to examples/functions/01_basic_oracle/switchboard-function/Dockerfile.dev index dc5d689ef..11d49e3bf 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Dockerfile.dev +++ b/examples/functions/01_basic_oracle/switchboard-function/Dockerfile.dev @@ -1,9 +1,6 @@ # syntax=docker/dockerfile:1.4 FROM switchboardlabs/sgx-function AS builder -ARG CARGO_NAME=switchboard-function -ENV CARGO_NAME=$CARGO_NAME - WORKDIR /home/root/solana-sdk COPY ./rust/switchboard-common/Cargo.toml \ @@ -18,9 +15,9 @@ COPY ./chains/solana/examples/functions/01_basic_oracle/Cargo.toml \ ./chains/solana/examples/functions/01_basic_oracle/Cargo.lock \ ./chains/solana/examples/functions/01_basic_oracle/ -COPY ./chains/solana/examples/functions/01_basic_oracle/sgx-function/Cargo.toml \ - ./chains/solana/examples/functions/01_basic_oracle/sgx-function/Cargo.lock \ - ./chains/solana/examples/functions/01_basic_oracle/sgx-function/ +COPY ./chains/solana/examples/functions/01_basic_oracle/switchboard-function/Cargo.toml \ + ./chains/solana/examples/functions/01_basic_oracle/switchboard-function/Cargo.lock \ + ./chains/solana/examples/functions/01_basic_oracle/switchboard-function/ COPY ./rust/switchboard-common/src \ ./rust/switchboard-common/src/ @@ -31,15 +28,15 @@ COPY ./rust/switchboard-solana/src \ COPY ./chains/solana/examples/functions/01_basic_oracle/src \ ./chains/solana/examples/functions/01_basic_oracle/src/ -COPY ./chains/solana/examples/functions/01_basic_oracle/sgx-function/src \ - ./chains/solana/examples/functions/01_basic_oracle/sgx-function/src/ +COPY ./chains/solana/examples/functions/01_basic_oracle/switchboard-function/src \ + ./chains/solana/examples/functions/01_basic_oracle/switchboard-function/src/ -WORKDIR /home/root/solana-sdk/chains/solana/examples/functions/01_basic_oracle/sgx-function +WORKDIR /home/root/solana-sdk/chains/solana/examples/functions/01_basic_oracle/switchboard-function RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=target,id=${TARGETPLATFORM} \ cargo build --release && \ cargo strip && \ - mv target/release/${CARGO_NAME} /sgx/app + mv target/release/basic-oracle-function /sgx/app FROM switchboardlabs/sgx-function diff --git a/examples/functions/01_basic_oracle/sgx-function/Makefile b/examples/functions/01_basic_oracle/switchboard-function/Makefile similarity index 86% rename from examples/functions/01_basic_oracle/sgx-function/Makefile rename to examples/functions/01_basic_oracle/switchboard-function/Makefile index 84d91be01..f23cc6f0c 100644 --- a/examples/functions/01_basic_oracle/sgx-function/Makefile +++ b/examples/functions/01_basic_oracle/switchboard-function/Makefile @@ -1,22 +1,21 @@ .PHONY: build clean publish # Variables -CARGO_NAME=basic-oracle-function -DOCKER_IMAGE_NAME=${CONTAINER_NAME} +DOCKER_IMAGE_NAME ?= gallynaut/basic-oracle-function -DOCKER_BUILD_COMMAND=DOCKER_BUILDKIT=1 docker buildx build --platform linux/amd64 --build-arg CARGO_NAME=${CARGO_NAME} +DOCKER_BUILD_COMMAND=docker buildx build --platform linux/amd64 # Default make task all: build docker_build: - ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest --load ../ + ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest ../ docker_publish: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile -t ${DOCKER_IMAGE_NAME}:latest --push ../ dev_docker_build: - ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile.dev -t ${DOCKER_IMAGE_NAME}:latest --load ../../../../../../ + ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile.dev -t ${DOCKER_IMAGE_NAME}:latest ../../../../../../ dev_docker_publish: ${DOCKER_BUILD_COMMAND} --pull -f Dockerfile.dev -t ${DOCKER_IMAGE_NAME}:latest --push ../../../../../../ diff --git a/examples/functions/01_basic_oracle/sgx-function/package.json b/examples/functions/01_basic_oracle/switchboard-function/package.json similarity index 100% rename from examples/functions/01_basic_oracle/sgx-function/package.json rename to examples/functions/01_basic_oracle/switchboard-function/package.json diff --git a/examples/functions/01_basic_oracle/sgx-function/src/binance.rs b/examples/functions/01_basic_oracle/switchboard-function/src/binance.rs similarity index 100% rename from examples/functions/01_basic_oracle/sgx-function/src/binance.rs rename to examples/functions/01_basic_oracle/switchboard-function/src/binance.rs diff --git a/examples/functions/01_basic_oracle/sgx-function/src/main.rs b/examples/functions/01_basic_oracle/switchboard-function/src/main.rs similarity index 100% rename from examples/functions/01_basic_oracle/sgx-function/src/main.rs rename to examples/functions/01_basic_oracle/switchboard-function/src/main.rs diff --git a/examples/functions/02_liquidity_oracle/Cargo.lock b/examples/functions/02_liquidity_oracle/Cargo.lock index 60100f364..ca67977b8 100644 --- a/examples/functions/02_liquidity_oracle/Cargo.lock +++ b/examples/functions/02_liquidity_oracle/Cargo.lock @@ -1401,6 +1401,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "envy" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965" +dependencies = [ + "serde", +] + [[package]] name = "errno" version = "0.3.1" @@ -4216,8 +4225,11 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" [[package]] name = "switchboard-common" -version = "0.8.6" +version = "0.8.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9e28848b864786d8b1835f1f0c4c7e65190d9c17b246e5e21cc2457a70b176" dependencies = [ + "envy", "getrandom 0.2.10", "hex", "serde", @@ -4228,7 +4240,9 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.1" +version = "0.28.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0213e971a7eb8910e228a473219e5eee3c799a3365cb33cf2ad482d58044ec4c" dependencies = [ "anchor-client", "anchor-lang", @@ -4246,6 +4260,7 @@ dependencies = [ "superslice", "switchboard-common", "tokio", + "url", ] [[package]] diff --git a/examples/functions/02_liquidity_oracle/Cargo.toml b/examples/functions/02_liquidity_oracle/Cargo.toml index e67332777..07fdb542b 100644 --- a/examples/functions/02_liquidity_oracle/Cargo.toml +++ b/examples/functions/02_liquidity_oracle/Cargo.toml @@ -19,8 +19,8 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -switchboard-solana = "0.28.4" -# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../rust/switchboard-solana" } bytemuck = "^1" anchor-lang = { version = "0.28.0", features = [ "init-if-needed", diff --git a/examples/functions/02_liquidity_oracle/sgx-function/Dockerfile.dev b/examples/functions/02_liquidity_oracle/sgx-function/Dockerfile.dev deleted file mode 100644 index f9dfa814e..000000000 --- a/examples/functions/02_liquidity_oracle/sgx-function/Dockerfile.dev +++ /dev/null @@ -1,44 +0,0 @@ -# syntax=docker/dockerfile:1.4 -FROM switchboardlabs/sgx-function AS builder - -ARG CARGO_NAME=switchboard-function - -WORKDIR /home/root/solana-sdk - -COPY ./rust/switchboard-solana/Cargo.toml \ - ./rust/switchboard-solana/Cargo.lock \ - ./rust/switchboard-solana/ - -COPY ./examples/functions/01_basic_oracle/Cargo.toml \ - ./examples/functions/01_basic_oracle/Cargo.lock \ - ./examples/functions/01_basic_oracle/ - -COPY ./examples/functions/01_basic_oracle/sgx-function/Cargo.toml \ - ./examples/functions/01_basic_oracle/sgx-function/Cargo.lock \ - ./examples/functions/01_basic_oracle/sgx-function/ - -COPY ./rust/switchboard-solana/src \ - ./rust/switchboard-solana/src/ - -COPY ./examples/functions/01_basic_oracle/src \ - ./examples/functions/01_basic_oracle/src/ - -COPY ./examples/functions/01_basic_oracle/sgx-function/src \ - ./examples/functions/01_basic_oracle/sgx-function/src/ - -WORKDIR /home/root/solana-sdk/examples/functions/01_basic_oracle/sgx-function - -RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=target,id=${TARGETPLATFORM} \ - cargo build --release && \ - cargo strip && \ - mv /home/root/solana-sdk/examples/functions/01_basic_oracle/sgx-function/target/release/${CARGO_NAME} /sgx - -FROM switchboardlabs/sgx-function - -# Copy the binary -WORKDIR /sgx -COPY --from=builder /sgx/${CARGO_NAME} /sgx/app - -# Get the measurement from the enclave -RUN /get_measurement.sh -ENTRYPOINT ["bash", "/boot.sh"] diff --git a/examples/functions/02_liquidity_oracle/src/actions/trigger_function.rs b/examples/functions/02_liquidity_oracle/src/actions/trigger_function.rs index fdaec3e68..53c9b6cc7 100644 --- a/examples/functions/02_liquidity_oracle/src/actions/trigger_function.rs +++ b/examples/functions/02_liquidity_oracle/src/actions/trigger_function.rs @@ -21,7 +21,7 @@ pub struct TriggerFunction<'info> { } #[derive(Clone, AnchorSerialize, AnchorDeserialize)] -pub struct TriggerFunctionParams { } +pub struct TriggerFunctionParams {} impl TriggerFunction<'_> { pub fn validate( @@ -32,12 +32,16 @@ impl TriggerFunction<'_> { Ok(()) } - pub fn actuate(ctx: &Context, _params: &TriggerFunctionParams) -> anchor_lang::Result<()> { + pub fn actuate( + ctx: &Context, + _params: &TriggerFunctionParams, + ) -> anchor_lang::Result<()> { FunctionTrigger { - function: ctx.accounts.function.clone(), - authority: ctx.accounts.authority.clone(), - attestation_queue: ctx.accounts.attestation_queue.clone(), - }.invoke(ctx.accounts.attestation_program.clone())?; + function: ctx.accounts.function.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + attestation_queue: ctx.accounts.attestation_queue.to_account_info(), + } + .invoke(ctx.accounts.attestation_program.clone())?; Ok(()) } -} \ No newline at end of file +} diff --git a/examples/functions/02_liquidity_oracle/sgx-function/.gitignore b/examples/functions/02_liquidity_oracle/switchboard-function/.gitignore similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/.gitignore rename to examples/functions/02_liquidity_oracle/switchboard-function/.gitignore diff --git a/examples/functions/02_liquidity_oracle/sgx-function/Cargo.lock b/examples/functions/02_liquidity_oracle/switchboard-function/Cargo.lock similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/Cargo.lock rename to examples/functions/02_liquidity_oracle/switchboard-function/Cargo.lock diff --git a/examples/functions/03_candles_oracle/sgx-function/Cargo.toml b/examples/functions/02_liquidity_oracle/switchboard-function/Cargo.toml similarity index 75% rename from examples/functions/03_candles_oracle/sgx-function/Cargo.toml rename to examples/functions/02_liquidity_oracle/switchboard-function/Cargo.toml index 53335ed25..4b9e285ec 100644 --- a/examples/functions/03_candles_oracle/sgx-function/Cargo.toml +++ b/examples/functions/02_liquidity_oracle/switchboard-function/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3" serde = "^1" serde_json = "^1" switchboard-utils = { version = "0.8.0" } -switchboard-solana = "0.28.4" -# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../../rust/switchboard-solana" } bytemuck = "1.13.1" rust_decimal = "1.30.0" diff --git a/examples/functions/02_liquidity_oracle/sgx-function/Dockerfile b/examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile similarity index 71% rename from examples/functions/02_liquidity_oracle/sgx-function/Dockerfile rename to examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile index 679fd68ac..e2a3cc103 100644 --- a/examples/functions/02_liquidity_oracle/sgx-function/Dockerfile +++ b/examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile @@ -8,13 +8,13 @@ WORKDIR /home/root/switchboard-function COPY ./Anchor.toml ./Cargo.lock ./Cargo.toml ./ COPY ./src ./src -WORKDIR /home/root/switchboard-function/sgx-function -COPY ./sgx-function/Cargo.lock ./sgx-function/Cargo.toml ./ -COPY ./sgx-function/src ./src +WORKDIR /home/root/switchboard-function/switchboard-function +COPY ./switchboard-function/Cargo.lock ./switchboard-function/Cargo.toml ./ +COPY ./switchboard-function/src ./src RUN --mount=target=/home/root/.cargo/git,type=cache \ --mount=target=/home/root/.cargo/registry,type=cache \ - --mount=type=cache,target=/home/root/switchboard-function/sgx-function/target \ + --mount=type=cache,target=/home/root/switchboard-function/switchboard-function/target \ cargo build --release && \ cargo strip && \ mv target/release/basic-oracle-function /sgx/app diff --git a/examples/functions/03_candles_oracle/sgx-function/Dockerfile.dev b/examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile.dev similarity index 72% rename from examples/functions/03_candles_oracle/sgx-function/Dockerfile.dev rename to examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile.dev index f9dfa814e..cc51f0d98 100644 --- a/examples/functions/03_candles_oracle/sgx-function/Dockerfile.dev +++ b/examples/functions/02_liquidity_oracle/switchboard-function/Dockerfile.dev @@ -13,9 +13,9 @@ COPY ./examples/functions/01_basic_oracle/Cargo.toml \ ./examples/functions/01_basic_oracle/Cargo.lock \ ./examples/functions/01_basic_oracle/ -COPY ./examples/functions/01_basic_oracle/sgx-function/Cargo.toml \ - ./examples/functions/01_basic_oracle/sgx-function/Cargo.lock \ - ./examples/functions/01_basic_oracle/sgx-function/ +COPY ./examples/functions/01_basic_oracle/switchboard-function/Cargo.toml \ + ./examples/functions/01_basic_oracle/switchboard-function/Cargo.lock \ + ./examples/functions/01_basic_oracle/switchboard-function/ COPY ./rust/switchboard-solana/src \ ./rust/switchboard-solana/src/ @@ -23,15 +23,15 @@ COPY ./rust/switchboard-solana/src \ COPY ./examples/functions/01_basic_oracle/src \ ./examples/functions/01_basic_oracle/src/ -COPY ./examples/functions/01_basic_oracle/sgx-function/src \ - ./examples/functions/01_basic_oracle/sgx-function/src/ +COPY ./examples/functions/01_basic_oracle/switchboard-function/src \ + ./examples/functions/01_basic_oracle/switchboard-function/src/ -WORKDIR /home/root/solana-sdk/examples/functions/01_basic_oracle/sgx-function +WORKDIR /home/root/solana-sdk/examples/functions/01_basic_oracle/switchboard-function RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=target,id=${TARGETPLATFORM} \ cargo build --release && \ cargo strip && \ - mv /home/root/solana-sdk/examples/functions/01_basic_oracle/sgx-function/target/release/${CARGO_NAME} /sgx + mv /home/root/solana-sdk/examples/functions/01_basic_oracle/switchboard-function/target/release/${CARGO_NAME} /sgx FROM switchboardlabs/sgx-function diff --git a/examples/functions/02_liquidity_oracle/sgx-function/Makefile b/examples/functions/02_liquidity_oracle/switchboard-function/Makefile similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/Makefile rename to examples/functions/02_liquidity_oracle/switchboard-function/Makefile diff --git a/examples/functions/02_liquidity_oracle/sgx-function/package.json b/examples/functions/02_liquidity_oracle/switchboard-function/package.json similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/package.json rename to examples/functions/02_liquidity_oracle/switchboard-function/package.json diff --git a/examples/functions/02_liquidity_oracle/sgx-function/src/binance.rs b/examples/functions/02_liquidity_oracle/switchboard-function/src/binance.rs similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/src/binance.rs rename to examples/functions/02_liquidity_oracle/switchboard-function/src/binance.rs diff --git a/examples/functions/02_liquidity_oracle/sgx-function/src/bitfinex.rs b/examples/functions/02_liquidity_oracle/switchboard-function/src/bitfinex.rs similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/src/bitfinex.rs rename to examples/functions/02_liquidity_oracle/switchboard-function/src/bitfinex.rs diff --git a/examples/functions/02_liquidity_oracle/sgx-function/src/coinbase.rs b/examples/functions/02_liquidity_oracle/switchboard-function/src/coinbase.rs similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/src/coinbase.rs rename to examples/functions/02_liquidity_oracle/switchboard-function/src/coinbase.rs diff --git a/examples/functions/02_liquidity_oracle/sgx-function/src/kraken.rs b/examples/functions/02_liquidity_oracle/switchboard-function/src/kraken.rs similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/src/kraken.rs rename to examples/functions/02_liquidity_oracle/switchboard-function/src/kraken.rs diff --git a/examples/functions/02_liquidity_oracle/sgx-function/src/main.rs b/examples/functions/02_liquidity_oracle/switchboard-function/src/main.rs similarity index 100% rename from examples/functions/02_liquidity_oracle/sgx-function/src/main.rs rename to examples/functions/02_liquidity_oracle/switchboard-function/src/main.rs diff --git a/examples/functions/03_candles_oracle/Cargo.lock b/examples/functions/03_candles_oracle/Cargo.lock index 60100f364..ca67977b8 100644 --- a/examples/functions/03_candles_oracle/Cargo.lock +++ b/examples/functions/03_candles_oracle/Cargo.lock @@ -1401,6 +1401,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "envy" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965" +dependencies = [ + "serde", +] + [[package]] name = "errno" version = "0.3.1" @@ -4216,8 +4225,11 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" [[package]] name = "switchboard-common" -version = "0.8.6" +version = "0.8.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9e28848b864786d8b1835f1f0c4c7e65190d9c17b246e5e21cc2457a70b176" dependencies = [ + "envy", "getrandom 0.2.10", "hex", "serde", @@ -4228,7 +4240,9 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.1" +version = "0.28.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0213e971a7eb8910e228a473219e5eee3c799a3365cb33cf2ad482d58044ec4c" dependencies = [ "anchor-client", "anchor-lang", @@ -4246,6 +4260,7 @@ dependencies = [ "superslice", "switchboard-common", "tokio", + "url", ] [[package]] diff --git a/examples/functions/03_candles_oracle/Cargo.toml b/examples/functions/03_candles_oracle/Cargo.toml index e67332777..07fdb542b 100644 --- a/examples/functions/03_candles_oracle/Cargo.toml +++ b/examples/functions/03_candles_oracle/Cargo.toml @@ -19,8 +19,8 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -switchboard-solana = "0.28.4" -# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../rust/switchboard-solana" } bytemuck = "^1" anchor-lang = { version = "0.28.0", features = [ "init-if-needed", diff --git a/examples/functions/03_candles_oracle/src/actions/trigger_function.rs b/examples/functions/03_candles_oracle/src/actions/trigger_function.rs index e3f1e3b98..53c9b6cc7 100644 --- a/examples/functions/03_candles_oracle/src/actions/trigger_function.rs +++ b/examples/functions/03_candles_oracle/src/actions/trigger_function.rs @@ -37,9 +37,9 @@ impl TriggerFunction<'_> { _params: &TriggerFunctionParams, ) -> anchor_lang::Result<()> { FunctionTrigger { - function: ctx.accounts.function.clone(), - authority: ctx.accounts.authority.clone(), - attestation_queue: ctx.accounts.attestation_queue.clone(), + function: ctx.accounts.function.to_account_info(), + authority: ctx.accounts.authority.to_account_info(), + attestation_queue: ctx.accounts.attestation_queue.to_account_info(), } .invoke(ctx.accounts.attestation_program.clone())?; Ok(()) diff --git a/examples/functions/03_candles_oracle/sgx-function/.gitignore b/examples/functions/03_candles_oracle/switchboard-function/.gitignore similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/.gitignore rename to examples/functions/03_candles_oracle/switchboard-function/.gitignore diff --git a/examples/functions/03_candles_oracle/sgx-function/Cargo.lock b/examples/functions/03_candles_oracle/switchboard-function/Cargo.lock similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/Cargo.lock rename to examples/functions/03_candles_oracle/switchboard-function/Cargo.lock diff --git a/examples/functions/02_liquidity_oracle/sgx-function/Cargo.toml b/examples/functions/03_candles_oracle/switchboard-function/Cargo.toml similarity index 66% rename from examples/functions/02_liquidity_oracle/sgx-function/Cargo.toml rename to examples/functions/03_candles_oracle/switchboard-function/Cargo.toml index 53335ed25..0c7cc7d02 100644 --- a/examples/functions/02_liquidity_oracle/sgx-function/Cargo.toml +++ b/examples/functions/03_candles_oracle/switchboard-function/Cargo.toml @@ -15,8 +15,8 @@ tokio = "^1" futures = "0.3" serde = "^1" serde_json = "^1" -switchboard-utils = { version = "0.8.0" } -switchboard-solana = "0.28.4" -# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } +switchboard-utils = { version = "0.8" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../../rust/switchboard-solana" } bytemuck = "1.13.1" rust_decimal = "1.30.0" diff --git a/examples/functions/03_candles_oracle/sgx-function/Dockerfile b/examples/functions/03_candles_oracle/switchboard-function/Dockerfile similarity index 71% rename from examples/functions/03_candles_oracle/sgx-function/Dockerfile rename to examples/functions/03_candles_oracle/switchboard-function/Dockerfile index 679fd68ac..e2a3cc103 100644 --- a/examples/functions/03_candles_oracle/sgx-function/Dockerfile +++ b/examples/functions/03_candles_oracle/switchboard-function/Dockerfile @@ -8,13 +8,13 @@ WORKDIR /home/root/switchboard-function COPY ./Anchor.toml ./Cargo.lock ./Cargo.toml ./ COPY ./src ./src -WORKDIR /home/root/switchboard-function/sgx-function -COPY ./sgx-function/Cargo.lock ./sgx-function/Cargo.toml ./ -COPY ./sgx-function/src ./src +WORKDIR /home/root/switchboard-function/switchboard-function +COPY ./switchboard-function/Cargo.lock ./switchboard-function/Cargo.toml ./ +COPY ./switchboard-function/src ./src RUN --mount=target=/home/root/.cargo/git,type=cache \ --mount=target=/home/root/.cargo/registry,type=cache \ - --mount=type=cache,target=/home/root/switchboard-function/sgx-function/target \ + --mount=type=cache,target=/home/root/switchboard-function/switchboard-function/target \ cargo build --release && \ cargo strip && \ mv target/release/basic-oracle-function /sgx/app diff --git a/examples/functions/03_candles_oracle/switchboard-function/Dockerfile.dev b/examples/functions/03_candles_oracle/switchboard-function/Dockerfile.dev new file mode 100644 index 000000000..f3b405060 --- /dev/null +++ b/examples/functions/03_candles_oracle/switchboard-function/Dockerfile.dev @@ -0,0 +1,52 @@ +# syntax=docker/dockerfile:1.4 +FROM switchboardlabs/sgx-function AS builder + + +ARG CARGO_NAME=switchboard-function + +WORKDIR /home/root/solana-sdk + +COPY ./rust/switchboard-common/Cargo.toml \ + ./rust/switchboard-common/Cargo.lock \ + ./rust/switchboard-common/ + +COPY ./rust/switchboard-solana/Cargo.toml \ + ./rust/switchboard-solana/Cargo.lock \ + ./rust/switchboard-solana/ + +COPY ./examples/functions/03_candles_oracle/Cargo.toml \ + ./examples/functions/03_candles_oracle/Cargo.lock \ + ./examples/functions/03_candles_oracle/ + +COPY ./examples/functions/03_candles_oracle/switchboard-function/Cargo.toml \ + ./examples/functions/03_candles_oracle/switchboard-function/Cargo.lock \ + ./examples/functions/03_candles_oracle/switchboard-function/ + +COPY ./rust/switchboard-common/src \ + ./rust/switchboard-common/src/ + +COPY ./rust/switchboard-solana/src \ + ./rust/switchboard-solana/src/ + +COPY ./examples/functions/03_candles_oracle/src \ + ./examples/functions/03_candles_oracle/src/ + +COPY ./examples/functions/03_candles_oracle/switchboard-function/src \ + ./examples/functions/03_candles_oracle/switchboard-function/src/ + +WORKDIR /home/root/solana-sdk/examples/functions/03_candles_oracle/switchboard-function + +RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=target,id=${TARGETPLATFORM} \ + cargo build --release && \ + cargo strip && \ + mv /home/root/solana-sdk/examples/functions/03_candles_oracle/switchboard-function/target/release/${CARGO_NAME} /sgx + +FROM switchboardlabs/sgx-function + +# Copy the binary +WORKDIR /sgx +COPY --from=builder /sgx/${CARGO_NAME} /sgx/app + +# Get the measurement from the enclave +RUN /get_measurement.sh +ENTRYPOINT ["bash", "/boot.sh"] diff --git a/examples/functions/03_candles_oracle/sgx-function/Makefile b/examples/functions/03_candles_oracle/switchboard-function/Makefile similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/Makefile rename to examples/functions/03_candles_oracle/switchboard-function/Makefile diff --git a/examples/functions/03_candles_oracle/sgx-function/package.json b/examples/functions/03_candles_oracle/switchboard-function/package.json similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/package.json rename to examples/functions/03_candles_oracle/switchboard-function/package.json diff --git a/examples/functions/03_candles_oracle/sgx-function/src/binance.rs b/examples/functions/03_candles_oracle/switchboard-function/src/binance.rs similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/src/binance.rs rename to examples/functions/03_candles_oracle/switchboard-function/src/binance.rs diff --git a/examples/functions/03_candles_oracle/sgx-function/src/bitfinex.rs b/examples/functions/03_candles_oracle/switchboard-function/src/bitfinex.rs similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/src/bitfinex.rs rename to examples/functions/03_candles_oracle/switchboard-function/src/bitfinex.rs diff --git a/examples/functions/03_candles_oracle/sgx-function/src/coinbase.rs b/examples/functions/03_candles_oracle/switchboard-function/src/coinbase.rs similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/src/coinbase.rs rename to examples/functions/03_candles_oracle/switchboard-function/src/coinbase.rs diff --git a/examples/functions/03_candles_oracle/sgx-function/src/kraken.rs b/examples/functions/03_candles_oracle/switchboard-function/src/kraken.rs similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/src/kraken.rs rename to examples/functions/03_candles_oracle/switchboard-function/src/kraken.rs diff --git a/examples/functions/03_candles_oracle/sgx-function/src/main.rs b/examples/functions/03_candles_oracle/switchboard-function/src/main.rs similarity index 100% rename from examples/functions/03_candles_oracle/sgx-function/src/main.rs rename to examples/functions/03_candles_oracle/switchboard-function/src/main.rs diff --git a/examples/functions/04_randomness_callback/Cargo.lock b/examples/functions/04_randomness_callback/Cargo.lock index 8df62314f..e4512dc04 100644 --- a/examples/functions/04_randomness_callback/Cargo.lock +++ b/examples/functions/04_randomness_callback/Cargo.lock @@ -1008,12 +1008,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "const-oid" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" - [[package]] name = "const-oid" version = "0.7.1" @@ -1120,17 +1114,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83bd3bb4314701c568e340cd8cf78c975aa0ca79e03d3f6d1677d5b0c9c0c03" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -1224,23 +1207,13 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" -[[package]] -name = "der" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" -dependencies = [ - "const-oid 0.6.2", - "crypto-bigint", -] - [[package]] name = "der" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" dependencies = [ - "const-oid 0.7.1", + "const-oid", ] [[package]] @@ -1511,21 +1484,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1895,19 +1853,6 @@ dependencies = [ "tokio-rustls", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.57" @@ -2073,9 +2018,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "lexical-core" @@ -2096,12 +2038,6 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" -[[package]] -name = "libm" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" - [[package]] name = "libsecp256k1" version = "0.6.0" @@ -2260,24 +2196,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nix" version = "0.26.2" @@ -2358,23 +2276,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-bigint-dig" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9bc3e36fd683e004fd59c64a425e0e991616f5a8b617c3b9a933a93c168facc" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand 0.8.5", - "smallvec", - "zeroize", -] - [[package]] name = "num-complex" version = "0.2.4" @@ -2436,7 +2337,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -2518,50 +2418,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "openssl" -version = "0.10.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" -dependencies = [ - "bitflags 2.3.3", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2 1.0.66", - "quote 1.0.32", - "syn 2.0.28", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "os_str_bytes" version = "6.5.1" @@ -2649,15 +2511,6 @@ dependencies = [ "base64 0.13.1", ] -[[package]] -name = "pem-rfc7468" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84e93a3b1cc0510b03020f33f21e62acdde3dcaef432edc95bea377fbd4c2cd4" -dependencies = [ - "base64ct", -] - [[package]] name = "percent-encoding" version = "2.3.0" @@ -2685,38 +2538,14 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs1" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "116bee8279d783c0cf370efa1a94632f2108e5ef0bb32df31f051647810a4e2c" -dependencies = [ - "der 0.4.5", - "pem-rfc7468", - "zeroize", -] - -[[package]] -name = "pkcs8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" -dependencies = [ - "der 0.4.5", - "pem-rfc7468", - "pkcs1", - "spki 0.4.1", - "zeroize", -] - [[package]] name = "pkcs8" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" dependencies = [ - "der 0.5.1", - "spki 0.5.4", + "der", + "spki", "zeroize", ] @@ -3083,12 +2912,10 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", - "hyper-tls", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -3098,7 +2925,6 @@ dependencies = [ "serde_json", "serde_urlencoded", "tokio", - "tokio-native-tls", "tokio-rustls", "tokio-util", "tower-service", @@ -3164,26 +2990,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rsa" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c2603e2823634ab331437001b411b9ed11660fbc4066f3908c84a9439260d" -dependencies = [ - "byteorder", - "digest 0.9.0", - "lazy_static", - "num-bigint-dig", - "num-integer", - "num-iter", - "num-traits", - "pkcs1", - "pkcs8 0.7.6", - "rand 0.8.5", - "subtle", - "zeroize", -] - [[package]] name = "rtoolbox" version = "0.0.1" @@ -4151,7 +3957,7 @@ dependencies = [ "nix", "pem", "percentage", - "pkcs8 0.8.0", + "pkcs8", "quinn", "quinn-proto", "quinn-udp", @@ -4339,15 +4145,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spki" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" -dependencies = [ - "der 0.4.5", -] - [[package]] name = "spki" version = "0.5.4" @@ -4355,7 +4152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" dependencies = [ "base64ct", - "der 0.5.1", + "der", ] [[package]] @@ -4448,15 +4245,13 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" [[package]] name = "switchboard-common" -version = "0.8.15" +version = "0.8.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723a9a346c6d6eb3374ebe8ea3848e61d40d1f9f46635604137e19a1a4262c52" +checksum = "1c9e28848b864786d8b1835f1f0c4c7e65190d9c17b246e5e21cc2457a70b176" dependencies = [ "envy", "getrandom 0.2.10", "hex", - "rand 0.8.5", - "reqwest", "serde", "serde_json", "sgx-quote", @@ -4465,9 +4260,9 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.12" +version = "0.28.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa9c6634ad316592b84930a923efe0be920b1bd94d61237a90b596ebd926c40" +checksum = "0213e971a7eb8910e228a473219e5eee3c799a3365cb33cf2ad482d58044ec4c" dependencies = [ "anchor-client", "anchor-lang", @@ -4477,12 +4272,7 @@ dependencies = [ "chrono", "cron", "hex", - "rand 0.8.5", - "reqwest", - "rsa", "rust_decimal", - "serde", - "serde_json", "sgx-quote", "solana-address-lookup-table-program", "solana-client", @@ -4705,16 +4495,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.23.4" @@ -4968,12 +4748,6 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "vec_map" version = "0.8.2" diff --git a/examples/functions/04_randomness_callback/Cargo.toml b/examples/functions/04_randomness_callback/Cargo.toml index 082c897ba..0c5973d01 100644 --- a/examples/functions/04_randomness_callback/Cargo.toml +++ b/examples/functions/04_randomness_callback/Cargo.toml @@ -20,5 +20,5 @@ default = [] [dependencies] bytemuck = "^1" anchor-spl = "0.28.0" -switchboard-solana = "0.28.12" -# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../rust/switchboard-solana" } diff --git a/examples/functions/04_randomness_callback/src/lib.rs b/examples/functions/04_randomness_callback/src/lib.rs index 5df6f7a4a..caff1c934 100644 --- a/examples/functions/04_randomness_callback/src/lib.rs +++ b/examples/functions/04_randomness_callback/src/lib.rs @@ -89,7 +89,9 @@ pub mod custom_randomness_request { let request_init_ctx = FunctionRequestInitAndTrigger { request: ctx.accounts.request.clone(), + authority: ctx.accounts.user.to_account_info(), function: ctx.accounts.function.to_account_info(), + function_authority: None, escrow: ctx.accounts.request_escrow.clone(), mint: ctx.accounts.mint.to_account_info(), state: ctx.accounts.state.to_account_info(), diff --git a/examples/functions/04_randomness_callback/sgx-function/.dockerignore b/examples/functions/04_randomness_callback/switchboard-function/.dockerignore similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/.dockerignore rename to examples/functions/04_randomness_callback/switchboard-function/.dockerignore diff --git a/examples/functions/04_randomness_callback/sgx-function/.gitignore b/examples/functions/04_randomness_callback/switchboard-function/.gitignore similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/.gitignore rename to examples/functions/04_randomness_callback/switchboard-function/.gitignore diff --git a/examples/functions/04_randomness_callback/sgx-function/Cargo.lock b/examples/functions/04_randomness_callback/switchboard-function/Cargo.lock similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/Cargo.lock rename to examples/functions/04_randomness_callback/switchboard-function/Cargo.lock diff --git a/examples/functions/04_randomness_callback/sgx-function/Cargo.toml b/examples/functions/04_randomness_callback/switchboard-function/Cargo.toml similarity index 60% rename from examples/functions/04_randomness_callback/sgx-function/Cargo.toml rename to examples/functions/04_randomness_callback/switchboard-function/Cargo.toml index bef78dd35..1d082e1cb 100644 --- a/examples/functions/04_randomness_callback/sgx-function/Cargo.toml +++ b/examples/functions/04_randomness_callback/switchboard-function/Cargo.toml @@ -12,5 +12,5 @@ path = "src/main.rs" [dependencies] tokio = "^1" futures = "0.3" -switchboard-solana = "0.28.12" -# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } +# switchboard-solana = "0.28.19" +switchboard-solana = { version = "0.28.19", path = "../../../../rust/switchboard-solana" } diff --git a/examples/functions/04_randomness_callback/sgx-function/Dockerfile b/examples/functions/04_randomness_callback/switchboard-function/Dockerfile similarity index 91% rename from examples/functions/04_randomness_callback/sgx-function/Dockerfile rename to examples/functions/04_randomness_callback/switchboard-function/Dockerfile index e98234c19..803b38dba 100644 --- a/examples/functions/04_randomness_callback/sgx-function/Dockerfile +++ b/examples/functions/04_randomness_callback/switchboard-function/Dockerfile @@ -4,7 +4,7 @@ FROM switchboardlabs/sgx-function AS builder ARG CARGO_NAME=switchboard-function ENV CARGO_NAME=$CARGO_NAME -WORKDIR /home/root/switchboard-function/sgx-function +WORKDIR /home/root/switchboard-function/switchboard-function COPY ./Cargo.lock ./Cargo.toml ./ COPY ./src ./src diff --git a/examples/functions/04_randomness_callback/sgx-function/Dockerfile.dev b/examples/functions/04_randomness_callback/switchboard-function/Dockerfile.dev similarity index 85% rename from examples/functions/04_randomness_callback/sgx-function/Dockerfile.dev rename to examples/functions/04_randomness_callback/switchboard-function/Dockerfile.dev index d4639ff0e..73ca8bbc1 100644 --- a/examples/functions/04_randomness_callback/sgx-function/Dockerfile.dev +++ b/examples/functions/04_randomness_callback/switchboard-function/Dockerfile.dev @@ -1,6 +1,7 @@ # syntax=docker/dockerfile:1.4 FROM switchboardlabs/sgx-function:main AS builder +ENV CARGO_NAME ARG CARGO_NAME=switchboard-function WORKDIR /home/root/solana-sdk @@ -17,9 +18,9 @@ COPY ./rust/switchboard-solana/Cargo.toml \ ./rust/switchboard-solana/Cargo.lock \ ./rust/switchboard-solana/ -COPY ./chains/solana/examples/functions/04_randomness_callback/sgx-function/Cargo.toml \ - ./chains/solana/examples/functions/04_randomness_callback/sgx-function/Cargo.lock \ - ./chains/solana/examples/functions/04_randomness_callback/sgx-function/ +COPY ./chains/solana/examples/functions/04_randomness_callback/switchboard-function/Cargo.toml \ + ./chains/solana/examples/functions/04_randomness_callback/switchboard-function/Cargo.lock \ + ./chains/solana/examples/functions/04_randomness_callback/switchboard-function/ COPY ./rust/switchboard-common/src \ ./rust/switchboard-common/src/ @@ -30,15 +31,15 @@ COPY ./rust/switchboard-common/src \ COPY ./rust/switchboard-solana/src \ ./rust/switchboard-solana/src/ -COPY ./chains/solana/examples/functions/04_randomness_callback/sgx-function/src \ - ./chains/solana/examples/functions/04_randomness_callback/sgx-function/src/ +COPY ./chains/solana/examples/functions/04_randomness_callback/switchboard-function/src \ + ./chains/solana/examples/functions/04_randomness_callback/switchboard-function/src/ -WORKDIR /home/root/solana-sdk/chains/solana/examples/functions/04_randomness_callback/sgx-function +WORKDIR /home/root/solana-sdk/chains/solana/examples/functions/04_randomness_callback/switchboard-function RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} --mount=type=cache,target=target,id=${TARGETPLATFORM} \ cargo build --release && \ cargo strip && \ - mv /home/root/solana-sdk/chains/solana/examples/functions/04_randomness_callback/sgx-function/target/release/${CARGO_NAME} /sgx + mv /home/root/solana-sdk/chains/solana/examples/functions/04_randomness_callback/switchboard-function/target/release/${CARGO_NAME} /sgx FROM switchboardlabs/sgx-function:main diff --git a/examples/functions/04_randomness_callback/sgx-function/Makefile b/examples/functions/04_randomness_callback/switchboard-function/Makefile similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/Makefile rename to examples/functions/04_randomness_callback/switchboard-function/Makefile diff --git a/examples/functions/04_randomness_callback/sgx-function/README.md b/examples/functions/04_randomness_callback/switchboard-function/README.md similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/README.md rename to examples/functions/04_randomness_callback/switchboard-function/README.md diff --git a/examples/functions/04_randomness_callback/sgx-function/package.json b/examples/functions/04_randomness_callback/switchboard-function/package.json similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/package.json rename to examples/functions/04_randomness_callback/switchboard-function/package.json diff --git a/examples/functions/04_randomness_callback/sgx-function/src/main.rs b/examples/functions/04_randomness_callback/switchboard-function/src/main.rs similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/src/main.rs rename to examples/functions/04_randomness_callback/switchboard-function/src/main.rs diff --git a/examples/functions/04_randomness_callback/sgx-function/src/params.rs b/examples/functions/04_randomness_callback/switchboard-function/src/params.rs similarity index 100% rename from examples/functions/04_randomness_callback/sgx-function/src/params.rs rename to examples/functions/04_randomness_callback/switchboard-function/src/params.rs diff --git a/examples/functions/05_raffle_program/Cargo.lock b/examples/functions/05_raffle_program/Cargo.lock index 0beafe3b7..9cbc2b4dc 100644 --- a/examples/functions/05_raffle_program/Cargo.lock +++ b/examples/functions/05_raffle_program/Cargo.lock @@ -1405,6 +1405,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "envy" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965" +dependencies = [ + "serde", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -4233,8 +4242,11 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" [[package]] name = "switchboard-common" -version = "0.8.6" +version = "0.8.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c9e28848b864786d8b1835f1f0c4c7e65190d9c17b246e5e21cc2457a70b176" dependencies = [ + "envy", "getrandom 0.2.10", "hex", "serde", @@ -4245,7 +4257,9 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.2" +version = "0.28.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0213e971a7eb8910e228a473219e5eee3c799a3365cb33cf2ad482d58044ec4c" dependencies = [ "anchor-client", "anchor-lang", @@ -4263,6 +4277,7 @@ dependencies = [ "superslice", "switchboard-common", "tokio", + "url", ] [[package]] diff --git a/examples/functions/05_raffle_program/Cargo.toml b/examples/functions/05_raffle_program/Cargo.toml index c6f66a8ce..ad3a63f0e 100644 --- a/examples/functions/05_raffle_program/Cargo.toml +++ b/examples/functions/05_raffle_program/Cargo.toml @@ -28,5 +28,5 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -# switchboard-solana = "0.28.4" -switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" } +switchboard-solana = "0.28.19" +# switchboard-solana = { version = "0.28.19", path = "../../../rust/switchboard-solana" } diff --git a/examples/functions/05_raffle_program/src/actions/start_round.rs b/examples/functions/05_raffle_program/src/actions/start_round.rs index fe6493be2..ee0064f27 100644 --- a/examples/functions/05_raffle_program/src/actions/start_round.rs +++ b/examples/functions/05_raffle_program/src/actions/start_round.rs @@ -81,16 +81,16 @@ impl StartRound<'_> { ); let request_init_ctx = FunctionRequestInitAndTrigger { - request: ctx.accounts.request.clone(), - function: ctx.accounts.function.clone(), - escrow: ctx.accounts.request_escrow.clone(), - mint: ctx.accounts.mint.clone(), - state: ctx.accounts.state.clone(), - attestation_queue: ctx.accounts.attestation_queue.clone(), - payer: ctx.accounts.payer.clone(), - system_program: ctx.accounts.system_program.clone(), - token_program: ctx.accounts.token_program.clone(), - associated_token_program: ctx.accounts.associated_token_program.clone(), + request: ctx.accounts.request.to_account_info(), + function: ctx.accounts.function.to_account_info(), + escrow: ctx.accounts.request_escrow.to_account_info(), + mint: ctx.accounts.mint.to_account_info(), + state: ctx.accounts.state.to_account_info(), + attestation_queue: ctx.accounts.attestation_queue.to_account_info(), + payer: ctx.accounts.payer.to_account_info(), + system_program: ctx.accounts.system_program.to_account_info(), + token_program: ctx.accounts.token_program.to_account_info(), + associated_token_program: ctx.accounts.associated_token_program.to_account_info(), }; request_init_ctx.invoke( ctx.accounts.switchboard.clone(), diff --git a/examples/functions/05_raffle_program/sgx-function/.dockerignore b/examples/functions/05_raffle_program/switchboard-function/.dockerignore similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/.dockerignore rename to examples/functions/05_raffle_program/switchboard-function/.dockerignore diff --git a/examples/functions/05_raffle_program/sgx-function/Cargo.lock b/examples/functions/05_raffle_program/switchboard-function/Cargo.lock similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/Cargo.lock rename to examples/functions/05_raffle_program/switchboard-function/Cargo.lock diff --git a/examples/functions/05_raffle_program/sgx-function/Cargo.toml b/examples/functions/05_raffle_program/switchboard-function/Cargo.toml similarity index 64% rename from examples/functions/05_raffle_program/sgx-function/Cargo.toml rename to examples/functions/05_raffle_program/switchboard-function/Cargo.toml index f55ee3cfc..f7e15dc54 100644 --- a/examples/functions/05_raffle_program/sgx-function/Cargo.toml +++ b/examples/functions/05_raffle_program/switchboard-function/Cargo.toml @@ -8,6 +8,6 @@ edition = "2021" [dependencies] tokio = "^1" futures = "0.3" -# switchboard-solana = "0.28.4" -switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" } +# switchboard-solana = "0.28.19" +switchboard-solana = { version = "0.28.19", path = "../../../../rust/switchboard-solana" } switchboard-utils = { version = "0.8", path = "../../../../../../rust/switchboard-utils" } diff --git a/examples/functions/05_raffle_program/sgx-function/Dockerfile b/examples/functions/05_raffle_program/switchboard-function/Dockerfile similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/Dockerfile rename to examples/functions/05_raffle_program/switchboard-function/Dockerfile diff --git a/examples/functions/05_raffle_program/sgx-function/Makefile b/examples/functions/05_raffle_program/switchboard-function/Makefile similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/Makefile rename to examples/functions/05_raffle_program/switchboard-function/Makefile diff --git a/examples/functions/05_raffle_program/sgx-function/README.md b/examples/functions/05_raffle_program/switchboard-function/README.md similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/README.md rename to examples/functions/05_raffle_program/switchboard-function/README.md diff --git a/examples/functions/05_raffle_program/sgx-function/src/main.rs b/examples/functions/05_raffle_program/switchboard-function/src/main.rs similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/src/main.rs rename to examples/functions/05_raffle_program/switchboard-function/src/main.rs diff --git a/examples/functions/05_raffle_program/sgx-function/src/params.rs b/examples/functions/05_raffle_program/switchboard-function/src/params.rs similarity index 100% rename from examples/functions/05_raffle_program/sgx-function/src/params.rs rename to examples/functions/05_raffle_program/switchboard-function/src/params.rs diff --git a/javascript/solana.js/idl/attestation-devnet.json b/javascript/solana.js/idl/attestation-devnet.json index 1c13b0742..59dd6cb1b 100644 --- a/javascript/solana.js/idl/attestation-devnet.json +++ b/javascript/solana.js/idl/attestation-devnet.json @@ -178,7 +178,7 @@ { "name": "authority", "isMut": false, - "isSigner": false + "isSigner": true }, { "name": "attestationQueue", @@ -1111,8 +1111,8 @@ }, { "name": "functionAuthority", - "isMut": true, - "isSigner": false, + "isMut": false, + "isSigner": true, "isOptional": true }, { @@ -1254,11 +1254,22 @@ "isMut": true, "isSigner": true }, + { + "name": "authority", + "isMut": false, + "isSigner": false + }, { "name": "function", "isMut": true, "isSigner": false }, + { + "name": "functionAuthority", + "isMut": false, + "isSigner": true, + "isOptional": true + }, { "name": "escrow", "isMut": true, @@ -1408,7 +1419,7 @@ }, { "name": "solDest", - "isMut": false, + "isMut": true, "isSigner": false }, { diff --git a/javascript/solana.js/package.json b/javascript/solana.js/package.json index edadb8b12..757ae6abe 100644 --- a/javascript/solana.js/package.json +++ b/javascript/solana.js/package.json @@ -1,6 +1,6 @@ { "name": "@switchboard-xyz/solana.js", - "version": "2.6.2", + "version": "2.7.1", "author": "", "license": "MIT", "description": "A Typescript client to interact with Switchboard on Solana.", diff --git a/javascript/solana.js/src/accounts/switchboardWallet.ts b/javascript/solana.js/src/accounts/switchboardWallet.ts index 33113f9bb..810042226 100644 --- a/javascript/solana.js/src/accounts/switchboardWallet.ts +++ b/javascript/solana.js/src/accounts/switchboardWallet.ts @@ -1,5 +1,6 @@ import * as errors from "../errors.js"; import * as types from "../generated/attestation-program/index.js"; +import { Mint } from "../mint.js"; import { SB_ATTESTATION_PID, type SwitchboardProgram, @@ -437,10 +438,33 @@ export class SwitchboardWallet extends Account { options?: TransactionObjectOptions ): Promise { const walletState = await this.loadData(); + const mint = await Mint.load(this.program.provider, walletState.mint); - const destinationTokenWallet = - destinationWallet ?? - (await this.program.mint.getOrCreateAssociatedUser(payer)); + let createTokenWalletIxn: TransactionInstruction | undefined = undefined; + + // If the destination wallet doesnt exist, lets use the users associated token account + let destinationTokenWallet = destinationWallet; + if (!destinationTokenWallet) { + destinationTokenWallet = mint.getAssociatedAddress(payer); + + const tokenAccount = await mint.getAccount(destinationTokenWallet); + + if (!tokenAccount) { + createTokenWalletIxn = spl.createAssociatedTokenAccountInstruction( + payer, + destinationTokenWallet, + payer, + mint.address + ); + } + } else { + const tokenAccount = await mint.getAccount(destinationTokenWallet); + if (!tokenAccount) { + throw new Error( + `Destination wallet ${destinationTokenWallet.toBase58()} does not exist.` + ); + } + } const ixn = types.walletWithdraw( this.program, @@ -469,7 +493,12 @@ export class SwitchboardWallet extends Account { }) ); - return new TransactionObject(payer, [ixn], [], options); + return new TransactionObject( + payer, + createTokenWalletIxn ? [createTokenWalletIxn, ixn] : [ixn], + [], + options + ); } public async withdraw( diff --git a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestClose.ts b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestClose.ts index 1225a931a..03a96e76d 100644 --- a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestClose.ts +++ b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestClose.ts @@ -37,7 +37,7 @@ export function functionRequestClose( { pubkey: accounts.authority, isSigner: false, isWritable: false }, { pubkey: accounts.escrow, isSigner: false, isWritable: true }, { pubkey: accounts.function, isSigner: false, isWritable: true }, - { pubkey: accounts.solDest, isSigner: false, isWritable: false }, + { pubkey: accounts.solDest, isSigner: false, isWritable: true }, { pubkey: accounts.escrowDest, isSigner: false, isWritable: true }, { pubkey: accounts.state, isSigner: false, isWritable: false }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, diff --git a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInit.ts b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInit.ts index 61b92f68c..323235c9b 100644 --- a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInit.ts +++ b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInit.ts @@ -39,7 +39,7 @@ export function functionRequestInit( { pubkey: accounts.request, isSigner: true, isWritable: true }, { pubkey: accounts.authority, isSigner: false, isWritable: false }, { pubkey: accounts.function, isSigner: false, isWritable: true }, - { pubkey: accounts.functionAuthority, isSigner: false, isWritable: true }, + { pubkey: accounts.functionAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.escrow, isSigner: false, isWritable: true }, { pubkey: accounts.mint, isSigner: false, isWritable: false }, { pubkey: accounts.state, isSigner: false, isWritable: false }, diff --git a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInitAndTrigger.ts b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInitAndTrigger.ts index c81fb522f..5cf3354be 100644 --- a/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInitAndTrigger.ts +++ b/javascript/solana.js/src/generated/attestation-program/instructions/functionRequestInitAndTrigger.ts @@ -12,7 +12,9 @@ export interface FunctionRequestInitAndTriggerArgs { export interface FunctionRequestInitAndTriggerAccounts { request: PublicKey; + authority: PublicKey; function: PublicKey; + functionAuthority: PublicKey; escrow: PublicKey; mint: PublicKey; state: PublicKey; @@ -35,7 +37,9 @@ export function functionRequestInitAndTrigger( ) { const keys: Array = [ { pubkey: accounts.request, isSigner: true, isWritable: true }, + { pubkey: accounts.authority, isSigner: false, isWritable: false }, { pubkey: accounts.function, isSigner: false, isWritable: true }, + { pubkey: accounts.functionAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.escrow, isSigner: false, isWritable: true }, { pubkey: accounts.mint, isSigner: false, isWritable: false }, { pubkey: accounts.state, isSigner: false, isWritable: false }, diff --git a/javascript/solana.js/src/generated/attestation-program/instructions/walletWithdraw.ts b/javascript/solana.js/src/generated/attestation-program/instructions/walletWithdraw.ts index acea1b69f..ae47d5d50 100644 --- a/javascript/solana.js/src/generated/attestation-program/instructions/walletWithdraw.ts +++ b/javascript/solana.js/src/generated/attestation-program/instructions/walletWithdraw.ts @@ -34,7 +34,7 @@ export function walletWithdraw( const keys: Array = [ { pubkey: accounts.wallet, isSigner: false, isWritable: true }, { pubkey: accounts.mint, isSigner: false, isWritable: false }, - { pubkey: accounts.authority, isSigner: false, isWritable: false }, + { pubkey: accounts.authority, isSigner: true, isWritable: false }, { pubkey: accounts.attestationQueue, isSigner: false, isWritable: false }, { pubkey: accounts.tokenWallet, isSigner: false, isWritable: true }, { pubkey: accounts.destinationWallet, isSigner: false, isWritable: true }, diff --git a/javascript/solana.js/test/new_wallet.spec.ts b/javascript/solana.js/test/new_wallet.spec.ts new file mode 100644 index 000000000..f7858fafc --- /dev/null +++ b/javascript/solana.js/test/new_wallet.spec.ts @@ -0,0 +1,144 @@ +import "mocha"; + +import type { + BootstrappedAttestationQueue, + SwitchboardProgram, +} from "../src/index.js"; +import { + SwitchboardWallet, + TransactionMissingSignerError, +} from "../src/index.js"; +import { FunctionAccount } from "../src/index.js"; +import { + AttestationProgramStateAccount, + AttestationQueueAccount, + TransactionObject, +} from "../src/index.js"; + +import type { TestContext } from "./utils.js"; +import { printLogs, setupTest } from "./utils.js"; + +import { Keypair, LAMPORTS_PER_SOL, SystemProgram } from "@solana/web3.js"; +import { sleep } from "@switchboard-xyz/common"; +import assert from "assert"; + +const defaulWalletSeed = "DefaultSeed"; + +async function createNewPayer( + ctx: TestContext +): Promise<[SwitchboardProgram, Keypair]> { + const newPayer = Keypair.generate(); + await ctx.program.signAndSend( + new TransactionObject( + ctx.payer.publicKey, + [ + SystemProgram.transfer({ + fromPubkey: ctx.payer.publicKey, + toPubkey: newPayer.publicKey, + lamports: 2 * LAMPORTS_PER_SOL, + }), + ], + [] + ) + ); + const program = ctx.program.newWithPayer(newPayer); + return [program, newPayer]; +} + +describe("NEW Switchboard Wallet Tests", () => { + let ctx: TestContext; + + let switchboard: BootstrappedAttestationQueue; + + let switchboardWallet: SwitchboardWallet; + + before(async () => { + ctx = await setupTest(); + + switchboard = await AttestationQueueAccount.bootstrapNewQueue(ctx.program, { + // reward > 0 so we can ensure function initializes to OutOfFunds since + // reward is less than starting balance + reward: 1, + allowAuthorityOverrideAfter: 3600, + maxQuoteVerificationAge: 7200, + requireAuthorityHeartbeatPermission: false, + requireUsagePermissions: false, + verifierEnclave: "MadeUpEnclave", + }); + + await AttestationProgramStateAccount.getOrCreate(ctx.program); + }); + + it("Test", async () => { + // create new payer + const [program, newPayer] = await createNewPayer(ctx); + + const [functionAccount, tx] = await FunctionAccount.create( + program, + { + container: "", + schedule: "* * * * * *", + attestationQueue: switchboard.attestationQueue.account, + }, + undefined, + { skipPreflight: true } + ); + await printLogs(ctx.program.provider.connection, tx, false); + + let functionState = await functionAccount.loadData(); + assert(functionState.status.kind === "OutOfFunds"); + assert(functionState.authority.equals(newPayer.publicKey)); + + const wallet = await functionAccount.wallet; + let walletState = await wallet.loadData(); + let walletBalance = await wallet.getBalance(); + assert(walletBalance === 0); + assert(walletState.mint.equals(ctx.program.mint.address)); + assert( + walletState.attestationQueue.equals( + switchboard.attestationQueue.publicKey + ) + ); + assert(walletState.resourceCount === 1); + + // fund function + const wrapAmount = 0.005; + const fundTx = await wallet.fund({ wrapAmount }); + await printLogs(ctx.program.provider.connection, fundTx, false); + + walletState = await wallet.loadData(); + walletBalance = await wallet.getBalance(); + console.log(`Wallet Balance: ${walletBalance}`); + assert(walletBalance === wrapAmount); + + // check function stare was updated + functionState = await functionAccount.loadData(); + console.log(`Function Status: ${functionState.status.kind}`); + assert(functionState.status.kind === "Active"); + + // try to withdraw if im the authority + const withdrawAmount = 0.001; + const withdrawTx = await wallet.withdraw(withdrawAmount); + await printLogs(ctx.program.provider.connection, withdrawTx, false); + walletBalance = await wallet.getBalance(); + console.log(`Wallet Balance: ${walletBalance}`); + assert(walletBalance === wrapAmount - withdrawAmount); + + // try to withdraw if im not the authority + const [programWithWrongAuthority, newPayer2] = await createNewPayer(ctx); + const walletWithWrongAuthority = new SwitchboardWallet( + programWithWrongAuthority, + wallet.publicKey + ); + try { + await walletWithWrongAuthority.withdraw(withdrawAmount); + walletBalance = await wallet.getBalance(); + console.log(`Wallet Balance: ${walletBalance}`); + assert(walletBalance === wrapAmount - withdrawAmount); + } catch (error) { + if (!(error instanceof TransactionMissingSignerError)) { + throw error; + } + } + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecff5b10f..1fd5d367b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -149,7 +149,7 @@ importers: specifier: ^1.78.0 version: 1.78.3 '@switchboard-xyz/solana.js': - specifier: workspace:* + specifier: workspace:^ version: link:../../../javascript/solana.js devDependencies: '@types/bn.js': @@ -174,12 +174,6 @@ importers: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) - examples/functions/01_basic_oracle/sgx-function: - dependencies: - solana-basic-oracle: - specifier: latest - version: link:.. - examples/functions/02_liquidity_oracle: dependencies: '@coral-xyz/anchor': @@ -220,12 +214,6 @@ importers: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) - examples/functions/02_liquidity_oracle/sgx-function: - dependencies: - solana-liquidity-oracle: - specifier: latest - version: link:.. - examples/functions/03_candles_oracle: dependencies: '@coral-xyz/anchor': @@ -266,12 +254,6 @@ importers: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) - examples/functions/03_candles_oracle/sgx-function: - dependencies: - solana-candles-oracle-example: - specifier: latest - version: link:.. - examples/functions/04_randomness_callback: dependencies: '@coral-xyz/anchor': @@ -318,8 +300,6 @@ importers: specifier: ^10.0.0 version: 10.0.0(mocha@9.2.2) - examples/functions/04_randomness_callback/sgx-function: {} - examples/functions/05_raffle_program: dependencies: '@coral-xyz/anchor': @@ -5567,7 +5547,7 @@ packages: resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==} dependencies: dot-case: 3.0.4 - tslib: 2.5.0 + tslib: 2.6.0 /source-map-support@0.5.21: resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} @@ -6014,9 +5994,6 @@ packages: strip-bom: 3.0.0 dev: true - /tslib@2.5.0: - resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} - /tslib@2.6.0: resolution: {integrity: sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==} diff --git a/rust/switchboard-solana/Cargo.lock b/rust/switchboard-solana/Cargo.lock index 4b0e07493..5d7084deb 100644 --- a/rust/switchboard-solana/Cargo.lock +++ b/rust/switchboard-solana/Cargo.lock @@ -4452,7 +4452,7 @@ dependencies = [ [[package]] name = "switchboard-solana" -version = "0.28.18" +version = "0.28.19" dependencies = [ "anchor-client", "anchor-lang", diff --git a/rust/switchboard-solana/Cargo.toml b/rust/switchboard-solana/Cargo.toml index fd9496338..1e8660e6d 100644 --- a/rust/switchboard-solana/Cargo.toml +++ b/rust/switchboard-solana/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "switchboard-solana" -version = "0.28.18" +version = "0.28.19" edition = "2021" description = "A Rust library to interact with Switchboard accounts." readme = "README.md" diff --git a/rust/switchboard-solana/src/attestation_program/accounts/attestation_state.rs b/rust/switchboard-solana/src/attestation_program/accounts/attestation_state.rs index 0b5679824..df140f652 100644 --- a/rust/switchboard-solana/src/attestation_program/accounts/attestation_state.rs +++ b/rust/switchboard-solana/src/attestation_program/accounts/attestation_state.rs @@ -72,6 +72,14 @@ impl AttestationProgramState { pda_key } + pub fn get_program_pda(program_id: Option) -> Pubkey { + let (pda_key, _) = Pubkey::find_program_address( + &[STATE_SEED], + &program_id.unwrap_or(SWITCHBOARD_ATTESTATION_PROGRAM_ID), + ); + pda_key + } + pub fn verify_pda(expected: &Pubkey) -> Result<()> { let key = Self::get_pda(); if key != *expected { diff --git a/rust/switchboard-solana/src/attestation_program/instructions/mod.rs b/rust/switchboard-solana/src/attestation_program/instructions/mod.rs index 98ac3a823..efc2a0a1d 100644 --- a/rust/switchboard-solana/src/attestation_program/instructions/mod.rs +++ b/rust/switchboard-solana/src/attestation_program/instructions/mod.rs @@ -39,3 +39,6 @@ pub use wallet_init::*; pub mod wallet_fund; pub use wallet_fund::*; + +pub mod wallet_withdraw; +pub use wallet_withdraw::*; \ No newline at end of file diff --git a/rust/switchboard-solana/src/attestation_program/instructions/request_close.rs b/rust/switchboard-solana/src/attestation_program/instructions/request_close.rs index a9f007caa..df5f7cb3b 100644 --- a/rust/switchboard-solana/src/attestation_program/instructions/request_close.rs +++ b/rust/switchboard-solana/src/attestation_program/instructions/request_close.rs @@ -12,7 +12,7 @@ pub struct FunctionRequestClose<'info> { /// CHECK: we need to load_mut and remove_request #[account(mut)] pub function: AccountInfo<'info>, - /// CHECK: allow partial funds to be sent to the claimer only if request.garbage_collection_slot has elapsed + #[account(mut)] pub sol_dest: AccountInfo<'info>, #[account(mut)] pub escrow_dest: AccountInfo<'info>, diff --git a/rust/switchboard-solana/src/attestation_program/instructions/request_init.rs b/rust/switchboard-solana/src/attestation_program/instructions/request_init.rs index 21898a51d..115ac4baf 100644 --- a/rust/switchboard-solana/src/attestation_program/instructions/request_init.rs +++ b/rust/switchboard-solana/src/attestation_program/instructions/request_init.rs @@ -18,7 +18,7 @@ pub struct FunctionRequestInit<'info> { pub function: AccountInfo<'info>, /// CHECK: function authority required to permit new requests - #[account(mut)] + #[account(signer)] pub function_authority: Option>, #[account( @@ -65,7 +65,7 @@ impl<'info> FunctionRequestInit<'info> { pub fn get_instruction( &self, program_id: Pubkey, - params: &FunctionRequestInitParams, + params: FunctionRequestInitParams, ) -> anchor_lang::Result { let accounts = self.to_account_metas(None); @@ -77,24 +77,84 @@ impl<'info> FunctionRequestInit<'info> { Ok(instruction) } + /// Invokes the instruction using a signed authority. + /// + /// # Arguments + /// + /// * `program`: The Switchboard Attestation program AccountInfo. + /// + /// * `max_container_params_len`: The maximum length of the vector containing the container parameters. + /// - Default: 256 bytes. + /// - Example: `Some(512)`. + /// + /// * `container_params`: The parameters for the container. + /// - Default: Empty vector. + /// - Example: `Some(request_params.into_bytes())`. + /// + /// * `garbage_collection_slot`: The slot when the request can be closed by anyone and is considered expired. + /// - Default: None, meaning only the authority can close the request. + /// + /// # Returns + /// + /// * `ProgramResult`: Indicates the result of the instruction execution. pub fn invoke( &self, program: AccountInfo<'info>, - params: &FunctionRequestInitParams, + max_container_params_len: Option, + container_params: Option>, + garbage_collection_slot: Option, ) -> ProgramResult { - let instruction = self.get_instruction(*program.key, params)?; + let instruction = self.get_instruction( + *program.key, + FunctionRequestInitParams { + max_container_params_len, + container_params: container_params.unwrap_or_default(), + garbage_collection_slot, + }, + )?; let account_infos = self.to_account_infos(); invoke(&instruction, &account_infos[..]) } + /// Invokes the instruction using a signed authority. + /// + /// # Arguments + /// + /// * `program`: The Switchboard Attestation program AccountInfo. + /// + /// * `max_container_params_len`: The maximum length of the vector containing the container parameters. + /// - Default: 256 bytes. + /// - Example: `Some(512)`. + /// + /// * `container_params`: The parameters for the container. + /// - Default: Empty vector. + /// - Example: `Some(request_params.into_bytes())`. + /// + /// * `garbage_collection_slot`: The slot when the request can be closed by anyone and is considered expired. + /// - Default: None, meaning only the authority can close the request. + /// + /// * `signer_seeds`: Seeds used for signing. + /// + /// # Returns + /// + /// * `ProgramResult`: Indicates the result of the instruction execution. pub fn invoke_signed( &self, program: AccountInfo<'info>, - params: &FunctionRequestInitParams, + max_container_params_len: Option, + container_params: Option>, + garbage_collection_slot: Option, signer_seeds: &[&[&[u8]]], ) -> ProgramResult { - let instruction = self.get_instruction(*program.key, params)?; + let instruction = self.get_instruction( + *program.key, + FunctionRequestInitParams { + max_container_params_len, + container_params: container_params.unwrap_or_default(), + garbage_collection_slot, + }, + )?; let account_infos = self.to_account_infos(); invoke_signed(&instruction, &account_infos[..], signer_seeds) @@ -124,7 +184,7 @@ impl<'info> FunctionRequestInit<'info> { account_metas.extend(self.authority.to_account_metas(None)); account_metas.extend(self.function.to_account_metas(None)); if let Some(function_authority) = &self.function_authority { - account_metas.extend(function_authority.to_account_metas(None)); + account_metas.extend(function_authority.to_account_metas(Some(true))); } else { account_metas.push(AccountMeta::new_readonly( SWITCHBOARD_ATTESTATION_PROGRAM_ID, diff --git a/rust/switchboard-solana/src/attestation_program/instructions/request_init_and_trigger.rs b/rust/switchboard-solana/src/attestation_program/instructions/request_init_and_trigger.rs index ed39f529d..2025905be 100644 --- a/rust/switchboard-solana/src/attestation_program/instructions/request_init_and_trigger.rs +++ b/rust/switchboard-solana/src/attestation_program/instructions/request_init_and_trigger.rs @@ -11,9 +11,15 @@ pub struct FunctionRequestInitAndTrigger<'info> { )] pub request: AccountInfo<'info>, + pub authority: AccountInfo<'info>, + #[account(mut)] pub function: AccountInfo<'info>, + /// CHECK: function authority required to permit new requests + #[account(signer)] + pub function_authority: Option>, + #[account( mut, owner = system_program.key(), @@ -75,6 +81,36 @@ impl<'info> FunctionRequestInitAndTrigger<'info> { Ok(instruction) } + /// Invokes the instruction. + /// + /// # Arguments + /// + /// * `program`: The Switchboard Attestation program AccountInfo. + /// + /// * `max_container_params_len`: The maximum length of the vector containing the container parameters. + /// - Default: 256 bytes. + /// - Example: `Some(512)`. + /// + /// * `container_params`: The parameters for the container. + /// - Default: Empty vector. + /// - Example: `Some(request_params.into_bytes())`. + /// + /// * `garbage_collection_slot`: The slot when the request can be closed by anyone and is considered expired. + /// - Default: None, meaning only the authority can close the request. + /// + /// * `bounty`: An optional fee to reward oracles for priority processing. + /// - Default: 0 lamports. + /// + /// * `slots_until_expiration`: An optional specification for the max number of slots the request can be processed in. + /// - Default: 2250 slots (roughly 15 minutes at 400 ms/slot). + /// - Minimum: 150 slots (approximately 1 minute at 400 ms/slot). + /// + /// * `valid_after_slot`: Schedule when the request should be valid for processing. + /// - Default: 0 slots, meaning the request is valid immediately for oracles to process. + /// + /// # Returns + /// + /// * `ProgramResult`: Indicates the result of the instruction execution. pub fn invoke( &self, program: AccountInfo<'info>, @@ -101,6 +137,38 @@ impl<'info> FunctionRequestInitAndTrigger<'info> { invoke(&instruction, &account_infos[..]) } + /// Invokes the instruction using a signed authority. + /// + /// # Arguments + /// + /// * `program`: The Switchboard Attestation program AccountInfo. + /// + /// * `max_container_params_len`: The maximum length of the vector containing the container parameters. + /// - Default: 256 bytes. + /// - Example: `Some(512)`. + /// + /// * `container_params`: The parameters for the container. + /// - Default: Empty vector. + /// - Example: `Some(request_params.into_bytes())`. + /// + /// * `garbage_collection_slot`: The slot when the request can be closed by anyone and is considered expired. + /// - Default: None, meaning only the authority can close the request. + /// + /// * `bounty`: An optional fee to reward oracles for priority processing. + /// - Default: 0 lamports. + /// + /// * `slots_until_expiration`: An optional specification for the max number of slots the request can be processed in. + /// - Default: 2250 slots (roughly 15 minutes at 400 ms/slot). + /// - Minimum: 150 slots (approximately 1 minute at 400 ms/slot). + /// + /// * `valid_after_slot`: Schedule when the request should be valid for processing. + /// - Default: 0 slots, meaning the request is valid immediately for oracles to process. + /// + /// * `signer_seeds`: Seeds used for signing. + /// + /// # Returns + /// + /// * `ProgramResult`: Indicates the result of the instruction execution. pub fn invoke_signed( &self, program: AccountInfo<'info>, @@ -131,7 +199,9 @@ impl<'info> FunctionRequestInitAndTrigger<'info> { fn to_account_infos(&self) -> Vec> { let mut account_infos = Vec::new(); account_infos.extend(self.request.to_account_infos()); + account_infos.extend(self.authority.to_account_infos()); account_infos.extend(self.function.to_account_infos()); + account_infos.extend(self.function_authority.to_account_infos()); account_infos.extend(self.escrow.to_account_infos()); account_infos.extend(self.mint.to_account_infos()); account_infos.extend(self.state.to_account_infos()); @@ -147,7 +217,16 @@ impl<'info> FunctionRequestInitAndTrigger<'info> { fn to_account_metas(&self, is_signer: Option) -> Vec { let mut account_metas = Vec::new(); account_metas.extend(self.request.to_account_metas(Some(true))); + account_metas.extend(self.authority.to_account_metas(None)); account_metas.extend(self.function.to_account_metas(None)); + if let Some(function_authority) = &self.function_authority { + account_metas.extend(function_authority.to_account_metas(Some(true))); + } else { + account_metas.push(AccountMeta::new_readonly( + SWITCHBOARD_ATTESTATION_PROGRAM_ID, + false, + )); + } account_metas.extend(self.escrow.to_account_metas(None)); account_metas.extend(self.mint.to_account_metas(None)); account_metas.extend(self.state.to_account_metas(None)); diff --git a/rust/switchboard-solana/src/attestation_program/instructions/wallet_withdraw.rs b/rust/switchboard-solana/src/attestation_program/instructions/wallet_withdraw.rs new file mode 100644 index 000000000..2cb0cb875 --- /dev/null +++ b/rust/switchboard-solana/src/attestation_program/instructions/wallet_withdraw.rs @@ -0,0 +1,99 @@ +use crate::prelude::*; + +#[derive(Accounts)] +#[instruction(params:WalletWithdrawParams)] +pub struct WalletWithdraw<'info> { + #[account(mut)] + pub wallet: AccountInfo<'info>, // SwitchboardWallet + #[account(address = anchor_spl::token::spl_token::native_mint::ID)] + pub mint: AccountInfo<'info>, // TokenMint + /// CHECK: + #[account(signer)] + pub authority: AccountInfo<'info>, + pub attestation_queue: AccountInfo<'info>, // AttestationQueueAccountData + #[account(mut)] + pub token_wallet: AccountInfo<'info>, // TokenAccount + #[account(mut)] + pub destination_wallet: AccountInfo<'info>, // TokenAccount + pub state: AccountInfo<'info>, // AttestationProgramState + #[account(address = anchor_spl::token::ID)] + pub token_program: AccountInfo<'info>, +} + +#[derive(Clone, AnchorSerialize, AnchorDeserialize)] +pub struct WalletWithdrawParams { + pub amount: u64, +} + +impl InstructionData for WalletWithdrawParams {} + +impl Discriminator for WalletWithdrawParams { + const DISCRIMINATOR: [u8; 8] = [157, 251, 53, 205, 191, 139, 118, 213]; +} + +impl Discriminator for WalletWithdraw<'_> { + const DISCRIMINATOR: [u8; 8] = [157, 251, 53, 205, 191, 139, 118, 213]; +} + +impl<'info> WalletWithdraw<'info> { + pub fn get_instruction( + &self, + program_id: Pubkey, + amount: u64, + ) -> anchor_lang::Result { + let accounts = self.to_account_metas(None); + + let params = WalletWithdrawParams { amount }; + let mut data: Vec = WalletWithdraw::discriminator().try_to_vec()?; + data.append(&mut params.try_to_vec()?); + + let instruction = Instruction::new_with_bytes(program_id, &data, accounts); + Ok(instruction) + } + + pub fn invoke(&self, program: AccountInfo<'info>, amount: u64) -> ProgramResult { + let instruction = self.get_instruction(*program.key, amount)?; + let account_infos = self.to_account_infos(); + + invoke(&instruction, &account_infos[..]) + } + + pub fn invoke_signed( + &self, + program: AccountInfo<'info>, + amount: u64, + signer_seeds: &[&[&[u8]]], + ) -> ProgramResult { + let instruction = self.get_instruction(*program.key, amount)?; + let account_infos = self.to_account_infos(); + + invoke_signed(&instruction, &account_infos[..], signer_seeds) + } + + fn to_account_infos(&self) -> Vec> { + let mut account_infos = Vec::new(); + account_infos.extend(self.wallet.to_account_infos()); + account_infos.extend(self.mint.to_account_infos()); + account_infos.extend(self.authority.to_account_infos()); + account_infos.extend(self.attestation_queue.to_account_infos()); + account_infos.extend(self.token_wallet.to_account_infos()); + account_infos.extend(self.destination_wallet.to_account_infos()); + account_infos.extend(self.state.to_account_infos()); + account_infos.extend(self.token_program.to_account_infos()); + account_infos + } + + #[allow(unused_variables)] + fn to_account_metas(&self, is_signer: Option) -> Vec { + let mut account_metas = Vec::new(); + account_metas.extend(self.wallet.to_account_metas(None)); + account_metas.extend(self.mint.to_account_metas(None)); + account_metas.extend(self.authority.to_account_metas(None)); + account_metas.extend(self.attestation_queue.to_account_metas(None)); + account_metas.extend(self.token_wallet.to_account_metas(None)); + account_metas.extend(self.destination_wallet.to_account_metas(None)); + account_metas.extend(self.state.to_account_metas(None)); + account_metas.extend(self.token_program.to_account_metas(None)); + account_metas + } +} diff --git a/rust/switchboard-solana/src/client/function_runner.rs b/rust/switchboard-solana/src/client/function_runner.rs index 1bc68cfab..300030cd8 100644 --- a/rust/switchboard-solana/src/client/function_runner.rs +++ b/rust/switchboard-solana/src/client/function_runner.rs @@ -40,6 +40,11 @@ pub struct FunctionRunner { // only used for requests pub function_request_key: Option, pub function_request_data: Option>, + + // convienence for building ixns + pub attestation_queue: Option, + pub switchboard_state: Pubkey, + pub switchboard: Pubkey, } impl std::fmt::Display for FunctionRunner { @@ -68,24 +73,28 @@ impl FunctionRunner { let verifier = Pubkey::from_str(&env.verifier).unwrap(); let reward_receiver = Pubkey::from_str(&env.reward_receiver).unwrap(); + let mut attestation_queue: Option = None; + // can be manually populated from client if missing - let function_data: Option> = if let Some(function_data_encoded) = - env.function_data.as_ref() - { - match bytemuck::try_from_bytes(&hex::decode(function_data_encoded).unwrap_or_default()) - { - Ok(function_data) => { - if function_data != &FunctionAccountData::default() { - Some(Box::new(*function_data)) - } else { - None + let function_data: Option> = + if let Some(function_data_encoded) = env.function_data.as_ref() { + // match bytemuck::try_from_bytes(&) + match bytemuck::try_from_bytes::( + &hex::decode(function_data_encoded).unwrap_or_default(), + ) { + Ok(function_data) => { + attestation_queue = Some(function_data.attestation_queue); + if function_data != &FunctionAccountData::default() { + Some(Box::new(*function_data)) + } else { + None + } } + Err(_) => None, } - Err(_) => None, - } - } else { - None - }; + } else { + None + }; let verifier_enclave_signer: Option = if let Some(verifier_enclave_signer) = env.verifier_enclave_signer { match Pubkey::from_str(&verifier_enclave_signer) { @@ -137,13 +146,23 @@ impl FunctionRunner { match FunctionRequestAccountData::try_from_slice( &hex::decode(function_request_data_encoded).unwrap_or_default(), ) { - Ok(function_request_data) => Some(Box::new(function_request_data)), + Ok(function_request_data) => { + if attestation_queue.is_none() { + attestation_queue = Some(function_request_data.attestation_queue); + } + + Some(Box::new(function_request_data)) + } Err(_) => None, } } else { None }; + let switchboard: Pubkey = + load_env_pubkey("SWITCHBOARD").unwrap_or(SWITCHBOARD_ATTESTATION_PROGRAM_ID); + let switchboard_state = AttestationProgramState::get_program_pda(Some(switchboard)); + Ok(Self { client: Arc::new(client), signer_keypair, @@ -157,6 +176,9 @@ impl FunctionRunner { reward_receiver, verifier_enclave_signer, queue_authority, + attestation_queue, + switchboard, + switchboard_state, }) } @@ -213,6 +235,13 @@ impl FunctionRunner { } } + pub fn get_associated_token_address(owner: Pubkey, mint: Option) -> Pubkey { + anchor_spl::associated_token::get_associated_token_address( + &owner, + &mint.unwrap_or(anchor_spl::token::spl_token::native_mint::ID), + ) + } + /// Loads the oracle signing key provided by the VERIFIER_ENCLAVE_SIGNER /// environment variable async fn load_verifier_signer( @@ -306,11 +335,13 @@ impl FunctionRunner { } let function_data: FunctionAccountData = *bytemuck::try_from_bytes( - &hex::decode(std::env::var("FUNCTION_DATA").unwrap()).unwrap() - ).unwrap(); + &hex::decode(std::env::var("FUNCTION_DATA").unwrap()).unwrap(), + ) + .unwrap(); let queue_authority = Pubkey::from_str(&std::env::var("QUEUE_AUTHORITY").unwrap()).unwrap(); - let verifier_enclave_signer = Pubkey::from_str(&std::env::var("VERIFIER_ENCLAVE_SIGNER").unwrap()).unwrap(); + let verifier_enclave_signer = + Pubkey::from_str(&std::env::var("VERIFIER_ENCLAVE_SIGNER").unwrap()).unwrap(); let verifier_permission = AttestationPermissionAccountData::get_pda( &queue_authority, @@ -364,7 +395,6 @@ impl FunctionRunner { ))); } - // TODO: replace with variables let function_data = self.load_function_data().await?; let queue_authority = self diff --git a/rust/switchboard-solana/src/instructions.rs b/rust/switchboard-solana/src/instructions.rs index 34f368f74..feb6e214b 100644 --- a/rust/switchboard-solana/src/instructions.rs +++ b/rust/switchboard-solana/src/instructions.rs @@ -7,5 +7,5 @@ pub use crate::attestation_program::instructions::{ FunctionClose, FunctionInit, FunctionRequestClose, FunctionRequestInit, FunctionRequestInitAndTrigger, FunctionRequestSetConfig, FunctionRequestTrigger, FunctionRequestVerify, FunctionSetEscrow, FunctionTrigger, FunctionVerify, WalletFund, - WalletInit, + WalletInit, WalletWithdraw, }; diff --git a/rust/switchboard-solana/src/types.rs b/rust/switchboard-solana/src/types.rs index b806db46e..cc3d2c34d 100644 --- a/rust/switchboard-solana/src/types.rs +++ b/rust/switchboard-solana/src/types.rs @@ -16,7 +16,7 @@ pub use crate::attestation_program::{ FunctionRequestSetConfigParams, FunctionRequestTriggerRound, FunctionRequestVerifyParams, FunctionSetEscrowParams, FunctionStatus, FunctionTriggerParams, FunctionVerifyParams, MrEnclave, Quote, RequestStatus, SwitchboardAttestationPermission, VerificationStatus, - WalletFundParams, WalletInitParams, + WalletFundParams, WalletInitParams, WalletWithdrawParams, }; cfg_client! {