Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pull monorepo changes #117

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/functions/01_basic_oracle/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ basic_oracle = "APWppEwwfddbooTUijn3oAVnQH6jkLDxW4JrTMbBoQXJ"
[provider]
# cluster = "Localnet"
# wallet = "~/.config/solana/id.json"
cluster = "https://api.devnet.solana.com"
wallet = "~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
# cluster = "https://api.devnet.solana.com"
# wallet = "~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
cluster = "https://api.mainnet-beta.solana.com"
wallet = "~/switchboard_environments_v2/mainnet/upgrade_authority/upgrade_authority.json"

[scripts]
test = "pnpm exec ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
Expand Down
4 changes: 4 additions & 0 deletions examples/functions/01_basic_oracle/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/functions/01_basic_oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
# switchboard-solana = "0.28.4"
switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" }
bytemuck = "^1"
switchboard-solana = "0.28.4"
# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" }
bytemuck = "^1"
32 changes: 4 additions & 28 deletions examples/functions/01_basic_oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,12 @@

![Switchboard Logo](https://github.com/switchboard-xyz/sbv2-core/raw/main/website/static/img/icons/switchboard/avatar.png)

# anchor-vrf-lite-parser

> An example program written in Anchor demonstrating how to integrate Switchboard Functions and verify attestation on-chain.

[![Anchor Test Status](https://github.com/switchboard-xyz/sbv2-solana/actions/workflows/anchor-test.yml/badge.svg)](https://github.com/switchboard-xyz/sbv2-solana/actions/workflows/anchor-test.yml)

</div>

<!-- install -->

<!-- installstop -->

## Usage

Build the example program
Deploy function:

```bash
anchor build
```
sb solana function create "CkvizjVnm2zA5Wuwan34NhVT3zFc7vqUyGnA6tuEF5aE" --container ${CONTAINER_NAME} --cluster devnet --schedule "15 * * * * *" --containerRegistry dockerhub --keypair /Users/mgild/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json --mrEnclave 0x63ba8df478b4a74795a79a73b8f0a6f792f88e95f9ed6202289091e6e1b65fa1 --fundAmount 0.25

Get your program ID and update `Anchor.toml` and `src/lib.rs` with your pubkey

```bash
export ANCHOR_VRF_LITE_PARSER_PUBKEY=$(solana-keygen pubkey target/deploy/anchor_vrf_lite_parser-keypair.json)
sed -i '' s/5Hhm5xKDiThfidbpqjJpKmMJEcKmjj5tEUNFpi2DzSvb/"$ANCHOR_VRF_LITE_PARSER_PUBKEY"/g Anchor.toml
sed -i '' s/5Hhm5xKDiThfidbpqjJpKmMJEcKmjj5tEUNFpi2DzSvb/"$ANCHOR_VRF_LITE_PARSER_PUBKEY"/g src/lib.rs
```

Then run Anchor test

```bash
anchor test
```
sb solana function create "2ie3JZfKcvsRLsJaP5fSo43gUo1vsurnUAtAgUdUAiDG" --container ${CONTAINER_NAME} --schedule "30 * * * * *" --containerRegistry dockerhub --keypair /Users/mgild/switchboard_environments_v2/mainnet/upgrade_authority/upgrade_authority.json --mainnetBeta --mrEnclave 0x63ba8df478b4a74795a79a73b8f0a6f792f88e95f9ed6202289091e6e1b65fa1 --fundAmount 0.25
```
5 changes: 2 additions & 3 deletions examples/functions/01_basic_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@coral-xyz/anchor": "^0.28.0",
"@solana/spl-token": "^0.3.6",
"@solana/web3.js": "^1.78.0",
"@switchboard-xyz/common": "^2.3.0",
"@switchboard-xyz/solana.js": "^2.5.0"
"@switchboard-xyz/solana.js": "^"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
Expand All @@ -27,4 +26,4 @@
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0"
}
}
}
62 changes: 62 additions & 0 deletions examples/functions/01_basic_oracle/scripts/fnCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { BasicOracle } from "../target/types/basic_oracle";

import * as anchor from "@coral-xyz/anchor";
import { Connection, PublicKey } from "@solana/web3.js";
import * as sb from "@switchboard-xyz/solana.js";

const rpcUrl =
"https://api.devnet.solana.com";
const kp = sb.loadKeypair(
"~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
);
const DEFAULT_DEVNET_QUEUE = "CkvizjVnm2zA5Wuwan34NhVT3zFc7vqUyGnA6tuEF5aE";
const DEFAULT_MAINNET_QUEUE = "2ie3JZfKcvsRLsJaP5fSo43gUo1vsurnUAtAgUdUAiDG";

async function main() {
const con = new Connection(rpcUrl);
const switchboardProgram = await sb.SwitchboardProgram.load(
"mainnet-beta",
con,
kp
);
const attestationProgram = await sb.SwitchboardProgram.loadAnchorProgram(
"mainnet-beta",
con,
kp,
switchboardProgram.attestationProgramId
);

console.log(`ProgramID: ${switchboardProgram}`);

const recentSlot = (
await con.getLatestBlockhashAndContext({
commitment: "finalized",
})
).context.slot;
console.log(recentSlot);
const [fn, tx] = await sb.FunctionAccount.create(switchboardProgram, {
container: "t1",
recentSlot: recentSlot,
attestationQueue: new sb.AttestationQueueAccount(
switchboardProgram,
new PublicKey(DEFAULT_DEVNET_QUEUE)
),
mrEnclave: Buffer.from(
"63ba8df478b4a74795a79a73b8f0a6f792f88e95f9ed6202289091e6e1b65fa1",
"hex"
),
requestsDisabled: false,
requestsRequireAuthorization: false,
requestsDefaultSlotsUntilExpiration: new anchor.BN("0"),
requestsFee: 0,
});

// console.log("Your transaction signature", tx);

console.log("Your transaction signature", tx);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
6 changes: 3 additions & 3 deletions examples/functions/01_basic_oracle/sgx-function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tokio = "^1"
futures = "0.3"
serde = "^1"
serde_json = "^1"
# switchboard-solana = "0.28.4"
switchboard-utils = "0.8.0"
switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" }
# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" }
switchboard-solana = "0.28.4"
# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" }
# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" }
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ async fn main() {
// Finally, emit the signed quote and partially signed transaction to the functionRunner oracle
// The functionRunner oracle will use the last outputted word to stdout as the serialized result. This is what gets executed on-chain.
runner.emit(ixs).await.unwrap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ impl SetFunction<'_> {
program.function = ctx.accounts.function.key();
Ok(())
}
}
}
4 changes: 2 additions & 2 deletions examples/functions/01_basic_oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use model::*;
pub mod utils;
pub use utils::*;

declare_id!("APWppEwwfddbooTUijn3oAVnQH6jkLDxW4JrTMbBoQXJ");
declare_id!("EF68PJkRqQu2VthTSy19kg6TWynMtRmLpxcMDKEdLC8t");

pub const PROGRAM_SEED: &[u8] = b"BASICORACLE";

Expand Down Expand Up @@ -53,4 +53,4 @@ pub mod basic_oracle {
) -> anchor_lang::Result<()> {
TriggerFunction::actuate(&ctx, &params)
}
}
}
13 changes: 2 additions & 11 deletions examples/functions/01_basic_oracle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
"./node_modules/@types"
],
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"esModuleInterop": true,
"strict": false,
"strictNullChecks": false,
"target": "es6",
"paths": {
"@switchboard-xyz/solana.js": [
"../../../../../javascript/solana.js"
]
}
"target": "es6"
},
"include": [
"tests/**/*",
Expand All @@ -32,10 +28,5 @@
"exclude": [
"target",
"lib"
],
"references": [
{
"path": "../../../../../javascript/solana.js"
}
]
}
5 changes: 3 additions & 2 deletions examples/functions/03_candles_oracle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"directory": "examples/functions/01_basic_oracle"
},
"scripts": {
"build:anchor": "anchor build",
"clean": "pnpm exec rimraf node_modules .anchor lib .turbo"
"build:cargo": "anchor build",
"fix": "cargo fmt && pnpm exec prettier ./tests/*.ts -w",
"clean": "pnpm exec rimraf node_modules .anchor .turbo"
},
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
Expand Down
5 changes: 3 additions & 2 deletions examples/functions/05_raffle_program/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "solana-raffle-program",
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
"build:cargo": "anchor build",
"fix": "cargo fmt && pnpm exec prettier ./tests/*.ts -w",
"clean": "pnpm exec rimraf node_modules .anchor .turbo"
},
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
Expand Down
5 changes: 2 additions & 3 deletions javascript/solana.js/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint node/no-unpublished-require: 0 */
/* eslint no-unused-vars: 0 */

import * as utils from "@switchboard-xyz/common/esm-utils";
import { execSync } from "child_process";
import { build } from "esbuild";
import fs from "fs";
Expand Down Expand Up @@ -146,9 +147,7 @@ async function main() {
execSync(`${tscPath} --outDir lib-cjs -p tsconfig.cjs.json`, {
encoding: "utf-8",
});
execSync(`tsx scripts/move-cjs-to-lib`, {
encoding: "utf-8",
});
utils.moveCjsFiles("lib-cjs", "lib");
fs.rmSync("lib-cjs", { recursive: true });

console.log(`Generating entrypoints ...`);
Expand Down
48 changes: 33 additions & 15 deletions javascript/solana.js/idl/attestation-devnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -1810,12 +1810,16 @@
"type": "bool"
},
{
"name": "requestsDefaultSlotsUntilExpiration",
"name": "reserved1",
"docs": [
"The number of slots after a request has been verified before allowing a non-authority account to close the account.",
"Useful if you want to submit multiple txns in your custom function and need the account to be kept alive for multiple slots."
"DEPRECATED."
],
"type": "u64"
"type": {
"array": [
"u8",
8
]
}
},
{
"name": "requestsFee",
Expand Down Expand Up @@ -2340,10 +2344,6 @@
"name": "requestsRequireAuthorization",
"type": "bool"
},
{
"name": "requestsDefaultSlotsUntilExpiration",
"type": "u64"
},
{
"name": "requestsFee",
"type": "u64"
Expand Down Expand Up @@ -2442,12 +2442,6 @@
"option": "bool"
}
},
{
"name": "requestsDefaultSlotsUntilExpiration",
"type": {
"option": "u64"
}
},
{
"name": "requestsFee",
"type": {
Expand Down Expand Up @@ -2654,6 +2648,12 @@
"type": {
"option": "u64"
}
},
{
"name": "validAfterSlot",
"type": {
"option": "u64"
}
}
]
}
Expand Down Expand Up @@ -2690,6 +2690,12 @@
"type": {
"option": "u64"
}
},
{
"name": "validAfterSlot",
"type": {
"option": "u64"
}
}
]
}
Expand Down Expand Up @@ -2909,6 +2915,13 @@
],
"type": "publicKey"
},
{
"name": "validAfterSlot",
"docs": [
"The slot when the request can first be executed."
],
"type": "u64"
},
{
"name": "ebuf",
"docs": [
Expand All @@ -2917,7 +2930,7 @@
"type": {
"array": [
"u8",
64
56
]
}
}
Expand Down Expand Up @@ -3724,6 +3737,11 @@
{
"code": 6040,
"name": "AccountCloseNotReady"
},
{
"code": 6041,
"name": "FunctionRequestNotReady",
"msg": "The FunctionRequestAccount is not ready to be verified"
}
]
}
2 changes: 1 addition & 1 deletion javascript/solana.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@switchboard-xyz/solana.js",
"version": "2.5.0",
"version": "2.5.4",
"author": "",
"license": "MIT",
"description": "A Typescript client to interact with Switchboard on Solana.",
Expand Down
Loading
Loading