fix feed-walkthrough example

This commit is contained in:
Conner Gallagher 2023-03-01 14:22:34 -07:00
parent 9fdfbbe0db
commit 037d74bdb9
8 changed files with 7219 additions and 456 deletions

View File

@ -0,0 +1,3 @@
{
"extends": "@switchboard-xyz"
}

File diff suppressed because it is too large Load Diff

View File

@ -16,23 +16,28 @@
"start:devnet": "ts-node src/devnet",
"start:simulate": "ts-node src/simulate",
"build": "rimraf dist && ./esbuild.js -inline-sourcemap",
"test": "echo \"No test script for @switchboard-xyz/v2-feed-walkthrough\" && exit 0"
"test": "echo \"No test script for @switchboard-xyz/v2-feed-walkthrough\" && exit 0",
"lint": "gts lint ./src",
"fix": "gts fix ./src"
},
"dependencies": {
"@solana/spl-token-v2": "npm:@solana/spl-token@^0.2.0",
"@solana/web3.js": "^1.73.3",
"@switchboard-xyz/common": "^2.1.31",
"@switchboard-xyz/oracle": "^2.1.4",
"@switchboard-xyz/common": "^2.1.33",
"@switchboard-xyz/oracle": "^2.1.6",
"@switchboard-xyz/solana.js": "file:../solana.js",
"chalk": "^4.1.2",
"dotenv": "^16.0.1",
"readline-sync": "^1.4.10"
},
"devDependencies": {
"@switchboard-xyz/eslint-config": "^0.1.2",
"@types/node": "^18.7.18",
"@types/readline-sync": "^1.4.4",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"esbuild-node-externals": "^1.4.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"estrella": "^1.4.1",
"gts": "^3.1.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.8.3"

View File

@ -10,6 +10,9 @@
* - call open round on the feed and await the result
*/
import OracleJobJson from "./oracle-job.json";
import { getKeypair, toAccountString } from "./utils";
import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
import { OracleJob } from "@switchboard-xyz/common";
import {
@ -22,8 +25,6 @@ import chalk from "chalk";
import dotenv from "dotenv";
import os from "os";
import path from "path";
import { myOracleJob } from "./oracle-job";
import { getKeypair, toAccountString } from "./utils";
dotenv.config();
@ -96,7 +97,9 @@ async function main() {
jobs: [
{
weight: 2,
data: OracleJob.encodeDelimited(myOracleJob).finish(),
data: OracleJob.encodeDelimited(
OracleJob.fromObject(OracleJobJson)
).finish(),
},
],
});

View File

@ -1,7 +0,0 @@
import { OracleJob } from "@switchboard-xyz/common";
import fs from "fs";
import path from "path";
export const myOracleJob = OracleJob.fromObject(
fs.readFileSync(path.join(path.dirname(__filename), "oracle-job.json"))
);

View File

@ -8,6 +8,9 @@
* - call open round on the feed and await the result
*/
import OracleJobJson from "./oracle-job.json";
import { getKeypair, toAccountString } from "./utils";
import { clusterApiUrl, Connection } from "@solana/web3.js";
import { OracleJob, sleep } from "@switchboard-xyz/common";
import { NodeOracle } from "@switchboard-xyz/oracle";
@ -20,8 +23,6 @@ import chalk from "chalk";
import dotenv from "dotenv";
import os from "os";
import path from "path";
import { myOracleJob } from "./oracle-job";
import { getKeypair, toAccountString } from "./utils";
dotenv.config();
@ -40,7 +41,7 @@ async function main() {
const authority = getKeypair(payerKeypairPath);
if ((process.env.CLUSTER ?? "").startsWith("mainnet")) {
throw new Error(`This script should not be used on mainnet`);
throw new Error("This script should not be used on mainnet");
}
// get cluster
@ -107,7 +108,9 @@ async function main() {
jobs: [
{
weight: 2,
data: OracleJob.encodeDelimited(myOracleJob).finish(),
data: OracleJob.encodeDelimited(
OracleJob.fromObject(OracleJobJson)
).finish(),
},
],
});
@ -132,7 +135,8 @@ async function main() {
await oracle.startAndAwait();
let retryCount = 5;
while (retryCount) {
if (queueAccount.isReady()) {
const activeOracles = await queueAccount.loadActiveOracleAccounts();
if (activeOracles.length > 0) {
retryCount = 0;
break;
}

View File

@ -1,9 +1,13 @@
import { simulateOracleJobs } from "@switchboard-xyz/common";
import OracleJobJson from "./oracle-job.json";
import { OracleJob, simulateOracleJobs } from "@switchboard-xyz/common";
import chalk from "chalk";
import { myOracleJob } from "./oracle-job";
async function main() {
const response = await simulateOracleJobs([myOracleJob], "devnet");
const response = await simulateOracleJobs(
[OracleJob.fromObject(OracleJobJson)],
"devnet"
);
console.log(
chalk.blue(`\u2139 TaskRunner Version: ${response.taskRunnerVersion}`)

View File

@ -2,32 +2,35 @@
"ts-node": {
// It is faster to skip typechecking.
// Remove if you want ts-node to do typechecking.
"transpileOnly": true,
"files": true,
// "transpileOnly": true,
// "files": true,
"compilerOptions": {
// compilerOptions specified here will override those declared below,
// but *only* in ts-node. Useful if you want ts-node and tsc to use
// different options with a single tsconfig.json.
"module": "commonjs"
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true
}
},
"compilerOptions": {
"target": "ES2019",
"lib": ["es2019", "dom"],
"module": "es2022",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "dist",
"rootDir": "src",
"paths": {
"@switchboard-xyz/switchboard-v2": ["../switchboard-v2"],
"@solana/spl-token": ["./node_modules/@solana/spl-token"]
"@switchboard-xyz/solana.js": ["../solana.js"]
}
},
"include": ["src/**/*"],
"exclude": ["esbuild.js", "dist"],
"references": [{ "path": "../switchboard-v2" }],
"references": [{ "path": "../solana.js" }],
"files": ["src/private-queue.ts"]
}