Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 0dcde0f2906af7561cc4171dadc695e3e5dad4c5
  • Loading branch information
Copybara authored and actions-user committed Feb 12, 2024
1 parent f113e1c commit ac35faf
Show file tree
Hide file tree
Showing 115 changed files with 17,382 additions and 2,435 deletions.
1,686 changes: 1,384 additions & 302 deletions cli/README.md

Large diffs are not rendered by default.

60 changes: 0 additions & 60 deletions cli/evm.sh

This file was deleted.

27 changes: 15 additions & 12 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@switchboard-xyz/cli",
"version": "3.3.12",
"version": "3.3.32",
"description": "command line tool to interact with switchboard",
"keywords": [
"oclif"
Expand Down Expand Up @@ -32,16 +32,16 @@
"lint": "pnpm exec eslint src/**/*.ts",
"prepack": "pnpm lint && pnpm build && pnpm exec oclif manifest && pnpm exec oclif readme",
"postpack": "pnpm exec shx rm -f oclif.manifest.json",
"test": "pnpm exec mocha --forbid-only \"test/**/*.test.ts\"",
"test:old": "pnpm exec mocha --forbid-only \"test/**/*.test.ts\"",
"uprev:sb": "pnpm add @switchboard-xyz/aptos.js@latest @switchboard-xyz/solana.js@latest",
"version": "pnpm exec oclif readme && git add README.md",
"watch": "pnpm exec tsc --watch"
},
"dependencies": {
"@aws-sdk/client-secrets-manager": "^3.154.0",
"@aws-sdk/credential-providers": "^3.157.0",
"@coral-xyz/anchor": "^0.28.0",
"@coral-xyz/borsh": "^0.28.0",
"@coral-xyz/anchor": "^0.29.0",
"@coral-xyz/borsh": "^0.29.0",
"@google-cloud/secret-manager": "^3.10.1",
"@ledgerhq/hw-app-solana": "^7.0.2",
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.5",
Expand All @@ -52,14 +52,15 @@
"@oclif/plugin-update": "^3.1.32",
"@oclif/plugin-version": "^1.3.8",
"@oclif/plugin-warn-if-update-available": "^2.0.48",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.3",
"@switchboard-xyz/common": "^2.3.9",
"@switchboard-xyz/solana.js": "^3.1.2",
"@switchboard-xyz/oracle": "^2.1.13",
"@switchboard-xyz/function-simulator": "^1.0.2",
"@switchboard-xyz/evm.js": "^3.12.36",
"@switchboard-xyz/aptos.js": "^2.6.11",
"@solana/spl-token": "^0.3.11",
"@solana/web3.js": "^1.89.0",
"@switchboard-xyz/aptos.js": "^",
"@switchboard-xyz/common": "^",
"@switchboard-xyz/evm.js": "^",
"@switchboard-xyz/function-simulator": "^",
"@switchboard-xyz/oracle": "^",
"@switchboard-xyz/solana.js": "^",
"@switchboard-xyz/starknet.js": "^",
"@terascope/fetch-github-release": "^0.8.7",
"aptos": "^1.11.0",
"async-csp": "^0.5.0",
Expand All @@ -78,7 +79,9 @@
"oclif": "^3.11.3",
"protobufjs": "^7.1.2",
"set-interval-async": "^3.0.3",
"starknet": "^5.24.3",
"toml": "^3.0.0",
"tweetnacl": "^1.0.3",
"winston": "^3.8.1",
"yaml": "^2.1.1"
},
Expand Down
4 changes: 0 additions & 4 deletions cli/sol_updates.sh

This file was deleted.

1 change: 1 addition & 0 deletions cli/src/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class CliBaseCommand extends Command {
verbose: Flags.boolean({
char: "v",
description: "log everything",
default: false,
}),
silent: Flags.boolean({
char: "s",
Expand Down
4 changes: 2 additions & 2 deletions cli/src/OutputFileBaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CliBaseCommand } from "./BaseCommand";
import * as anchor from "@coral-xyz/anchor";
import { Flags } from "@oclif/core";
import type { Input } from "@oclif/parser";
import { SwitchboardDecimal } from "@switchboard-xyz/common";
import { BN, SwitchboardDecimal } from "@switchboard-xyz/common";
import { Big } from "@switchboard-xyz/common";
import fs from "fs";
import path from "path";
Expand Down Expand Up @@ -89,7 +89,7 @@ export abstract class OutputFileBaseCommand extends CliBaseCommand {
return value.toString();
}

if (anchor.BN.isBN(value)) {
if (BN.isBN(value)) {
return value.toString(10);
}

Expand Down
45 changes: 25 additions & 20 deletions cli/src/commands/sol-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,38 @@ export default class SandboxCommand extends BaseCommand {
async run() {
const { args, flags } = await this.parse(SandboxCommand);

const [functionAccount, functionState] = await FunctionAccount.load(
this.program,
"33wNREhMu5vKrcx7qPtw8KHvndRv5d1UiwWkyi8DfyJS"
console.log(
"Attestation Program ID",
this.program.attestationProgramId.toBase58()
);

const functionAccountInfo =
await this.program.provider.connection.getAccountInfo(
functionAccount.publicKey
);
// const [functionAccount, functionState] = await FunctionAccount.load(
// this.program,
// "33wNREhMu5vKrcx7qPtw8KHvndRv5d1UiwWkyi8DfyJS"
// );

const functionAccountData = functionAccountInfo?.data ?? Buffer.from("");
// const functionAccountInfo =
// await this.program.provider.connection.getAccountInfo(
// functionAccount.publicKey
// );

console.log(`SIZE\n${functionAccountData.length}\n`);
// const functionAccountData = functionAccountInfo?.data ?? Buffer.from("");

console.log(
`FUNCTION ACCOUNT DATA\n[${new Uint8Array(functionAccountData)}]\n`
);
// console.log(`SIZE\n${functionAccountData.length}\n`);

console.log(
`FUNCTION ACCOUNT HEX\n0x${functionAccountData.toString("hex")}\n`
);
// console.log(
// `FUNCTION ACCOUNT DATA\n[${new Uint8Array(functionAccountData)}]\n`
// );

console.log(
`FUNCTION ACCOUNT HEX (NO DISC)\n0x${functionAccountData
.slice(8)
.toString("hex")}\n`
);
// console.log(
// `FUNCTION ACCOUNT HEX\n0x${functionAccountData.toString("hex")}\n`
// );

// console.log(
// `FUNCTION ACCOUNT HEX (NO DISC)\n0x${functionAccountData
// .slice(8)
// .toString("hex")}\n`
// );
}

async catch(error: any) {
Expand Down
153 changes: 153 additions & 0 deletions cli/src/commands/solana/attestation-queue/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { SolanaWithSignerBaseCommand as BaseCommand } from "../../../solana";
import { CHECK_ICON } from "../../../utils";

import { Flags } from "@oclif/core";
import { Keypair } from "@solana/web3.js";
import { sleep } from "@switchboard-xyz/common";
import { AttestationQueueAccount } from "@switchboard-xyz/solana.js";
import chalk from "chalk";

export default class AttestationQueueBootstrap extends BaseCommand {
static enableJsonFlag = true;

static description = "bootstrap an attestation queue";

static flags = {
...BaseCommand.flags,
// queue flags
authority: Flags.string({
char: "a",
description:
"alternate keypair that is the authority for the queue and is required to approve permissions",
}),
queueKeypair: Flags.string({
description:
"keypair to use for the attestation queue account. This will be the account's publicKey",
}),
reward: Flags.string({
description:
"the reward payed out to oracles for responding to an update request on-chain, Ex: A reward of 0.0000075 with a feed with a batchSize of 4 would deduct (4 * 0.0000075) wSOL from an aggregators lease each round.",
default: "0",
}),
allowAuthorityOverrideAfter: Flags.integer({
description:
"Allow authority to force add a node after X seconds with no heartbeat.",
default: 86_400, // 1 day
}),
maxQuoteVerificationAge: Flags.integer({
description:
"The maximum allowable time until a EnclaveAccount needs to be re-verified on-chain.",
default: 604_800, // 1 week
}),
nodeTimeout: Flags.integer({
description:
"The maximum allowable time until a node needs to send a heartbeat.",
default: 86_400, // 1 day
}),
requireAuthorityHeartbeatPermissions: Flags.boolean({
description:
"Even if a heartbeating machine quote verifies with proper measurement, require authority signoff.",
}),
requireUsagePermissions: Flags.boolean({
description:
"Require FunctionAccounts to have PermitQueueUsage before they are executed.",
}),
enclaveSigner: Flags.string({
description: "Signer used for the verifier oracle to verify quotes",
required: false,
}),
};

async run() {
const { flags } = await this.parse(AttestationQueueBootstrap);

if (this.network === "mainnet-beta") {
throw new Error(
`You should only bootstrap a queue on devnet or localnet`
);
}

let authority: Keypair | undefined;
if (flags.authority) {
authority = await this.loadAuthority(flags.authority);
}

let queueKeypair: Keypair = Keypair.generate();
if (flags.queueKeypair) {
queueKeypair = await this.loadKeypair(flags.queueKeypair);
}
await this.program.verifyNewKeypair(queueKeypair);

let enclaveSignerKeypair: Keypair = Keypair.generate();
if (flags.enclaveSigner) {
enclaveSignerKeypair = await this.loadKeypair(flags.enclaveSigner);
}
await this.program.verifyNewKeypair(enclaveSignerKeypair);

const bootstrappedQueue = await AttestationQueueAccount.bootstrapNewQueue(
this.program,
{
authority: authority,
reward: Number(flags.reward),
allowAuthorityOverrideAfter: flags.allowAuthorityOverrideAfter,
maxQuoteVerificationAge: flags.maxQuoteVerificationAge,
requireAuthorityHeartbeatPermission:
flags.requireAuthorityHeartbeatPermissions,
requireUsagePermissions: flags.requireUsagePermissions,
nodeTimeout: flags.nodeTimeout,
keypair: queueKeypair,

//
verifierEnclave: Buffer.from("DefaultMrEnclave"),
enclaveSigner: enclaveSignerKeypair,
}
);

const attestationQueueAccount = bootstrappedQueue.attestationQueue.account;
const verifierAccount = bootstrappedQueue.verifier.account;
const verifierPermissionAccount =
bootstrappedQueue.verifier.permissionAccount;

const signatures = bootstrappedQueue.signatures ?? [];

if (flags.json) {
await sleep(1000);
const attestationQueue = await attestationQueueAccount.loadData();
const verifierData = await verifierAccount.loadData();
return this.normalizeAccountData(attestationQueueAccount.publicKey, {
attestationQueue: attestationQueue,
verifier: verifierData,
});
}

if (this.silent) {
this.logger.info(signatures.map((s) => this.toUrl(s)).join("\n"));
return;
}

// handle nicer logging here
this.logger.info(
`${chalk.green(
CHECK_ICON,
"successfully created an attestation queue"
)} - ${attestationQueueAccount.publicKey}`
);

// handle nicer logging here
this.logger.info(
`${chalk.green(CHECK_ICON, "successfully created a verifier oracle")} - ${
verifierAccount.publicKey
}`
);

this.logger.info(
`Transaction Signature: ${signatures
.map((s) => this.toUrl(s))
.join("\n")}`
);
}

async catch(error: any) {
super.catch(error, "Failed to bootstrap attestation queue account");
}
}
Loading

0 comments on commit ac35faf

Please sign in to comment.