Skip to content

Commit

Permalink
read_aggregator history script
Browse files Browse the repository at this point in the history
  • Loading branch information
dutch committed Sep 20, 2022
1 parent 693c0c5 commit c5768fb
Show file tree
Hide file tree
Showing 5 changed files with 702 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target
node_modules

Cargo.lock
out.csv
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@project-serum/anchor": "^0.24.2",
"@solana/spl-token": "^0.2.0",
"@solana/web3.js": "^1.44.0",
"@switchboard-xyz/switchboard-v2": "^0.0.133",
"@vyper-protocol/rust-decimal-wrapper": "^0.1.3"
},
"devDependencies": {
Expand Down
29 changes: 29 additions & 0 deletions scripts/rate_switchboard/read_aggregator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as anchor from "@project-serum/anchor";
import { Program, Wallet } from "@project-serum/anchor";
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { AggregatorAccount, loadSwitchboardProgram } from "@switchboard-xyz/switchboard-v2";
import { RustDecimalWrapper } from "@vyper-protocol/rust-decimal-wrapper";
import { IDL } from "../../target/types/rate_switchboard";

import * as fs from "fs";

const AGGREGATOR = new PublicKey("GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR");

const main = async () => {
const connection = new Connection("https://api.devnet.solana.com");

const program = await loadSwitchboardProgram("devnet", connection);

const aggregatorAccount = new AggregatorAccount({
program,
publicKey: AGGREGATOR,
});

const history = await aggregatorAccount.loadHistory();

history.forEach((c) =>
fs.appendFileSync("./out.csv", `${new Date(c.timestamp.toNumber() * 1000)};${c.value.toNumber()}\n`)
);
};

main();
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"types": ["node", "mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
Expand Down
Loading

0 comments on commit c5768fb

Please sign in to comment.