sbv2-solana/website/docs/developers/queue.mdx

152 lines
3.1 KiB
Plaintext
Raw Normal View History

---
sidebar_position: 10
title: Oracle Queue
---
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
## Create an Oracle Queue
- `oracleQueueInit`
<Tabs>
<TabItem value="Typescript" label="Typescript" default>
```ts
2022-06-07 23:47:49 -07:00
import * as anchor from "@project-serum/anchor";
import * as spl from "@solana/spl-token";
import { OracleQueueAccount } from "@switchboard-xyz/switchboard-v2";
const queueAccount = await OracleQueueAccount.create(program, {
name: Buffer.from("Queue-1"),
mint: spl.NATIVE_MINT,
slashingEnabled: false,
reward: new anchor.BN(0), // no token account needed
minStake: new anchor.BN(0),
authority: authority.publicKey,
});
```
</TabItem>
<TabItem value="CLI" label="CLI">
```bash
2022-06-07 23:47:49 -07:00
sbv2 queue create \
--name "My Queue" \
--keypair "path/to/payer/keypair.json" \
--authority "path/to/authority/keypair.json" \
--minStake 0 \
--reward 0 \
--crankSize 0 \
--oracleTimeout 300 \
--numOracles 0 \
--queueSize 25 \
--outputFile "My_Switchboard_Queue.json" \
--verbose
```
</TabItem>
</Tabs>
## Assign Queue Permissions
- `permissionSet`
<Tabs>
<TabItem value="Typescript" label="Typescript" default>
```ts
2022-06-07 23:47:49 -07:00
import * as anchor from "@project-serum/anchor";
import { Keypair } from "@solana/web3.js";
import {
loadSwitchboardProgram,
OracleAccount,
OracleQueueAccount
PermissionAccount,
} from "@switchboard-xyz/switchboard-v2";
let payer: Keypair;
let authority: Keypair;
const program = await loadSwitchboardProgram("devnet", undefined, payer);
const queueAccount = new OracleQueueAccount({
program,
publicKey: queuePubkey,
});
const oracleAccount = new OracleAccount({
program,
publicKey: oraclePubkey,
});
// Create permission
const permissionAccount = await PermissionAccount.create(program, {
authority: authority.publicKey,
granter: queueAccount.publicKey,
grantee: oracleAccount.publicKey,
});
// Set permission
await oraclePermission.set({
authority,
permission: SwitchboardPermission.PERMIT_ORACLE_HEARTBEAT,
enable: true,
});
```
</TabItem>
<TabItem value="CLI" label="CLI">
```bash
2022-06-07 23:47:49 -07:00
sbv2 permission set PERMISSIONKEY \
--keypair "payer-keypair.json" \
--authority "queue-authority.json"
```
</TabItem>
</Tabs>
## Create a Crank
- `crankInit`
<Tabs>
<TabItem value="Typescript" label="Typescript" default>
```ts
2022-06-07 23:47:49 -07:00
import * as anchor from "@project-serum/anchor";
import { Keypair } from "@solana/web3.js";
import {
CrankAccount,
loadSwitchboardProgram,
OracleQueueAccount,
} from "@switchboard-xyz/switchboard-v2";
let payer: Keypair; // also the authority
const program = await loadSwitchboardProgram("devnet", undefined, payer);
const queueAccount = new OracleQueueAccount({
program,
publicKey: queuePubkey,
});
const crankAccount = await CrankAccount.create(program, {
name: Buffer.from("My Crank"),
maxRows: 1000,
queueAccount,
});
```
</TabItem>
<TabItem value="CLI" label="CLI">
```bash
2022-06-07 23:47:49 -07:00
sbv2 crank create QUEUEKEY \
--name "My Crank" \
--keypair "payer-keypair.json" \
--authority "queue-authority.json" \
--maxRows 1000 \
--verbose
```
</TabItem>
</Tabs>