|
| 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 | +}); |
0 commit comments