Skip to content

Commit

Permalink
final checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gallynaut committed Jul 5, 2023
1 parent 672acf6 commit a100903
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
1 change: 1 addition & 0 deletions javascript/solana.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"./package.json": "./package.json"
},
"scripts": {
"close-functions": "tsx ./scripts/close-functions.ts",
"keypair:create": "shx find ~/.config/solana/id.json || solana-keygen new -s --no-bip39-passphrase --outfile ~/.config/solana/id.json",
"localnet:down": "kill -9 $(pgrep command solana-test-validator) || exit 0",
"localnet": "tsx ./scripts/localnet.ts",
Expand Down
80 changes: 80 additions & 0 deletions javascript/solana.js/scripts/close-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env tsx

// import { SwitchboardAttestationProgram } from "../../../../switchboard-core/switchboard_v2/target/types/switchboard_attestation_program";
import * as sbv2 from "../src";
import { AggregatorAccount, CrankAccount, QueueAccount } from "../src";

import {
Aggregator,
CHECK_ICON,
FAILED_ICON,
IAggregatorDefinition,
jsonReplacers,
PLUS_ICON,
setupOutputDir,
} from "./utils.js";

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

const VERBOSE = process.env.VERBOSE || false;

const fnDiscriminator = Buffer.from([76, 139, 47, 44, 240, 182, 148, 200]);

const enclaveDiscriminator = Buffer.from([90, 162, 39, 88, 77, 157, 156, 165]);

type FunctionAccountWithState = {
account: sbv2.FunctionAccount;
// state: sbv2.attestationTypes.FunctionAccountData;
};

async function main() {
const program = await sbv2.SwitchboardProgram.load(
"devnet",
new Connection(
"https://switchbo-switchbo-6225.devnet.rpcpool.com/f6fb9f02-0777-498b-b8f5-67cbb1fc0d14"
),
sbv2.loadKeypair("~/.config/solana/id.json")
);

const attestationProgramAccounts =
await program.connection.getProgramAccounts(sbv2.SB_ATTESTATION_PID);

const functionAccounts: FunctionAccountWithState[] = [];
const ixns: TransactionInstruction[] = [];

for (const { pubkey, account } of attestationProgramAccounts) {
const discriminator = account.data.slice(0, 8);
if (Buffer.compare(discriminator, enclaveDiscriminator) === 0) {
functionAccounts.push({
account: new sbv2.FunctionAccount(program, pubkey),
// state: sbv2.attestationTypes.FunctionAccountData.decode(account.data),
});

ixns.push(
sbv2.attestationTypes.functionOverrideClose(program, {
function: pubkey,
solDest: program.walletPubkey,
systemProgram: anchor.web3.SystemProgram.programId,
})
);
}
}

for (const account of functionAccounts) {
console.log(account.account.publicKey.toBase58());
}

console.log(`Found ${functionAccounts.length} enclaves`);

const txns = sbv2.TransactionObject.packIxns(program.walletPubkey, ixns);

console.log(`Sending ${txns.length} transactions`);

const signatures = await program.signAndSendAll(txns);
console.log(signatures);
}

main().catch((error) => {
console.error(error);
});
2 changes: 1 addition & 1 deletion rust/switchboard-solana/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust/switchboard-solana/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "switchboard-solana"
version = "0.8.1"
version = "0.8.2"
edition = "2021"
description = "A Rust library to interact with Switchboard accounts."
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ impl FunctionAccountData {
}

cfg_client! {
pub fn get_discriminator_filter() -> solana_client::rpc_filter::RpcFilterType {
solana_client::rpc_filter::RpcFilterType::Memcmp(solana_client::rpc_filter::Memcmp::new(
0,
solana_client::rpc_filter::MemcmpEncodedBytes::Bytes(FunctionAccountData::discriminator().to_vec()),
))
}

pub fn get_is_triggered_filter() -> solana_client::rpc_filter::RpcFilterType {
solana_client::rpc_filter::RpcFilterType::Memcmp(solana_client::rpc_filter::Memcmp::new(
9,
Expand Down Expand Up @@ -385,6 +392,7 @@ impl FunctionAccountData {

pub fn get_is_ready_filters(queue_pubkey: &Pubkey) -> Vec<solana_client::rpc_filter::RpcFilterType> {
vec![
FunctionAccountData::get_discriminator_filter(),
FunctionAccountData::get_is_triggered_filter(),
FunctionAccountData::get_is_scheduled_filter(),
FunctionAccountData::get_is_active_filter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ impl FunctionRequestAccountData {
}

cfg_client! {
pub fn get_discriminator_filter() -> solana_client::rpc_filter::RpcFilterType {
solana_client::rpc_filter::RpcFilterType::Memcmp(solana_client::rpc_filter::Memcmp::new(
0,
solana_client::rpc_filter::MemcmpEncodedBytes::Bytes(FunctionRequestAccountData::discriminator().to_vec()),
))
}

pub fn get_is_triggered_filter() -> solana_client::rpc_filter::RpcFilterType {
solana_client::rpc_filter::RpcFilterType::Memcmp(solana_client::rpc_filter::Memcmp::new(
8,
Expand All @@ -234,6 +241,7 @@ impl FunctionRequestAccountData {

pub fn get_is_ready_filters(queue_pubkey: &Pubkey) -> Vec<solana_client::rpc_filter::RpcFilterType> {
vec![
FunctionRequestAccountData::get_discriminator_filter(),
FunctionRequestAccountData::get_is_triggered_filter(),
FunctionRequestAccountData::get_is_active_filter(),
FunctionRequestAccountData::get_queue_filter(queue_pubkey),
Expand Down

0 comments on commit a100903

Please sign in to comment.