Skip to content

Commit c8b6ec9

Browse files
gallynautCopybara
andauthored
Project import generated by Copybara. (#117)
GitOrigin-RevId: 2b76139229beb79bca032660b3c9faa05ca71091 Co-authored-by: Copybara <[email protected]>
1 parent 1dae1ce commit c8b6ec9

38 files changed

+241
-129
lines changed

examples/functions/01_basic_oracle/Anchor.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ basic_oracle = "APWppEwwfddbooTUijn3oAVnQH6jkLDxW4JrTMbBoQXJ"
1414
[provider]
1515
# cluster = "Localnet"
1616
# wallet = "~/.config/solana/id.json"
17-
cluster = "https://api.devnet.solana.com"
18-
wallet = "~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
17+
# cluster = "https://api.devnet.solana.com"
18+
# wallet = "~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
19+
cluster = "https://api.mainnet-beta.solana.com"
20+
wallet = "~/switchboard_environments_v2/mainnet/upgrade_authority/upgrade_authority.json"
1921

2022
[scripts]
2123
test = "pnpm exec ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

examples/functions/01_basic_oracle/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/functions/01_basic_oracle/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ cpi = ["no-entrypoint"]
1919
default = []
2020

2121
[dependencies]
22-
# switchboard-solana = "0.28.4"
23-
switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" }
24-
bytemuck = "^1"
22+
switchboard-solana = "0.28.4"
23+
# switchboard-solana = { version = "0.28.4", path = "../../../rust/switchboard-solana" }
24+
bytemuck = "^1"

examples/functions/01_basic_oracle/README.md

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,12 @@
22

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

5-
# anchor-vrf-lite-parser
6-
7-
> An example program written in Anchor demonstrating how to integrate Switchboard Functions and verify attestation on-chain.
8-
9-
[![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)
10-
11-
</div>
12-
13-
<!-- install -->
14-
15-
<!-- installstop -->
16-
175
## Usage
186

19-
Build the example program
7+
Deploy function:
208

219
```bash
22-
anchor build
23-
```
10+
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
2411

25-
Get your program ID and update `Anchor.toml` and `src/lib.rs` with your pubkey
26-
27-
```bash
28-
export ANCHOR_VRF_LITE_PARSER_PUBKEY=$(solana-keygen pubkey target/deploy/anchor_vrf_lite_parser-keypair.json)
29-
sed -i '' s/5Hhm5xKDiThfidbpqjJpKmMJEcKmjj5tEUNFpi2DzSvb/"$ANCHOR_VRF_LITE_PARSER_PUBKEY"/g Anchor.toml
30-
sed -i '' s/5Hhm5xKDiThfidbpqjJpKmMJEcKmjj5tEUNFpi2DzSvb/"$ANCHOR_VRF_LITE_PARSER_PUBKEY"/g src/lib.rs
31-
```
32-
33-
Then run Anchor test
34-
35-
```bash
36-
anchor test
37-
```
12+
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
13+
```

examples/functions/01_basic_oracle/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"@coral-xyz/anchor": "^0.28.0",
1616
"@solana/spl-token": "^0.3.6",
1717
"@solana/web3.js": "^1.78.0",
18-
"@switchboard-xyz/common": "^2.3.0",
19-
"@switchboard-xyz/solana.js": "^2.5.0"
18+
"@switchboard-xyz/solana.js": "^"
2019
},
2120
"devDependencies": {
2221
"@types/bn.js": "^5.1.0",
@@ -27,4 +26,4 @@
2726
"mocha": "^9.0.3",
2827
"ts-mocha": "^10.0.0"
2928
}
30-
}
29+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import type { BasicOracle } from "../target/types/basic_oracle";
2+
3+
import * as anchor from "@coral-xyz/anchor";
4+
import { Connection, PublicKey } from "@solana/web3.js";
5+
import * as sb from "@switchboard-xyz/solana.js";
6+
7+
const rpcUrl =
8+
"https://api.devnet.solana.com";
9+
const kp = sb.loadKeypair(
10+
"~/switchboard_environments_v2/devnet/upgrade_authority/upgrade_authority.json"
11+
);
12+
const DEFAULT_DEVNET_QUEUE = "CkvizjVnm2zA5Wuwan34NhVT3zFc7vqUyGnA6tuEF5aE";
13+
const DEFAULT_MAINNET_QUEUE = "2ie3JZfKcvsRLsJaP5fSo43gUo1vsurnUAtAgUdUAiDG";
14+
15+
async function main() {
16+
const con = new Connection(rpcUrl);
17+
const switchboardProgram = await sb.SwitchboardProgram.load(
18+
"mainnet-beta",
19+
con,
20+
kp
21+
);
22+
const attestationProgram = await sb.SwitchboardProgram.loadAnchorProgram(
23+
"mainnet-beta",
24+
con,
25+
kp,
26+
switchboardProgram.attestationProgramId
27+
);
28+
29+
console.log(`ProgramID: ${switchboardProgram}`);
30+
31+
const recentSlot = (
32+
await con.getLatestBlockhashAndContext({
33+
commitment: "finalized",
34+
})
35+
).context.slot;
36+
console.log(recentSlot);
37+
const [fn, tx] = await sb.FunctionAccount.create(switchboardProgram, {
38+
container: "t1",
39+
recentSlot: recentSlot,
40+
attestationQueue: new sb.AttestationQueueAccount(
41+
switchboardProgram,
42+
new PublicKey(DEFAULT_DEVNET_QUEUE)
43+
),
44+
mrEnclave: Buffer.from(
45+
"63ba8df478b4a74795a79a73b8f0a6f792f88e95f9ed6202289091e6e1b65fa1",
46+
"hex"
47+
),
48+
requestsDisabled: false,
49+
requestsRequireAuthorization: false,
50+
requestsDefaultSlotsUntilExpiration: new anchor.BN("0"),
51+
requestsFee: 0,
52+
});
53+
54+
// console.log("Your transaction signature", tx);
55+
56+
console.log("Your transaction signature", tx);
57+
}
58+
59+
main().catch((err) => {
60+
console.error(err);
61+
process.exit(1);
62+
});

examples/functions/01_basic_oracle/sgx-function/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tokio = "^1"
1515
futures = "0.3"
1616
serde = "^1"
1717
serde_json = "^1"
18-
# switchboard-solana = "0.28.4"
1918
switchboard-utils = "0.8.0"
20-
switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" }
21-
# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" }
19+
switchboard-solana = "0.28.4"
20+
# switchboard-solana = { version = "0.28.4", path = "../../../../rust/switchboard-solana" }
21+
# switchboard-utils = { version = "0.8.0", path = "../../../../../../rust/switchboard-utils" }

examples/functions/01_basic_oracle/sgx-function/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ async fn main() {
2525
// Finally, emit the signed quote and partially signed transaction to the functionRunner oracle
2626
// The functionRunner oracle will use the last outputted word to stdout as the serialized result. This is what gets executed on-chain.
2727
runner.emit(ixs).await.unwrap();
28-
}
28+
}

examples/functions/01_basic_oracle/src/actions/set_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ impl SetFunction<'_> {
3333
program.function = ctx.accounts.function.key();
3434
Ok(())
3535
}
36-
}
36+
}

examples/functions/01_basic_oracle/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use model::*;
1212
pub mod utils;
1313
pub use utils::*;
1414

15-
declare_id!("APWppEwwfddbooTUijn3oAVnQH6jkLDxW4JrTMbBoQXJ");
15+
declare_id!("EF68PJkRqQu2VthTSy19kg6TWynMtRmLpxcMDKEdLC8t");
1616

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

@@ -53,4 +53,4 @@ pub mod basic_oracle {
5353
) -> anchor_lang::Result<()> {
5454
TriggerFunction::actuate(&ctx, &params)
5555
}
56-
}
56+
}

0 commit comments

Comments
 (0)