@drift-labs/sdk 2.10.0-beta.5 → 2.11.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +0,0 @@
1
- /// <reference types="node" />
2
- import { Connection, PublicKey } from '@solana/web3.js';
3
- import { Program } from '@project-serum/anchor';
4
- import { OracleClient, OraclePriceData } from './types';
5
- export declare class SwitchboardClient implements OracleClient {
6
- connection: Connection;
7
- constructor(connection: Connection);
8
- getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
9
- getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
10
- getProgram(): Program;
11
- }
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SwitchboardClient = void 0;
7
- const web3_js_1 = require("@solana/web3.js");
8
- const anchor_1 = require("@project-serum/anchor");
9
- const numericConstants_1 = require("../constants/numericConstants");
10
- const wallet_1 = require("../wallet");
11
- const switchboard_v2_json_1 = __importDefault(require("../idl/switchboard_v2.json"));
12
- let program;
13
- class SwitchboardClient {
14
- constructor(connection) {
15
- this.connection = connection;
16
- }
17
- async getOraclePriceData(pricePublicKey) {
18
- const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
19
- return this.getOraclePriceDataFromBuffer(accountInfo.data);
20
- }
21
- getOraclePriceDataFromBuffer(buffer) {
22
- const program = this.getProgram();
23
- const aggregatorAccountData = program.account.aggregatorAccountData.coder.accounts.decode('AggregatorAccountData', buffer);
24
- const price = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound.result);
25
- const confidence = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound
26
- .stdDeviation);
27
- const hasSufficientNumberOfDataPoints = aggregatorAccountData.latestConfirmedRound.numSuccess >=
28
- aggregatorAccountData.minOracleResults;
29
- const slot = aggregatorAccountData.latestConfirmedRound.roundOpenSlot;
30
- return {
31
- price,
32
- slot,
33
- confidence,
34
- hasSufficientNumberOfDataPoints,
35
- };
36
- }
37
- getProgram() {
38
- if (program) {
39
- return program;
40
- }
41
- program = getSwitchboardProgram(this.connection);
42
- return program;
43
- }
44
- }
45
- exports.SwitchboardClient = SwitchboardClient;
46
- function getSwitchboardProgram(connection) {
47
- const DEFAULT_KEYPAIR = web3_js_1.Keypair.fromSeed(new Uint8Array(32).fill(1));
48
- const programId = web3_js_1.PublicKey.default;
49
- const wallet = new wallet_1.Wallet(DEFAULT_KEYPAIR);
50
- const provider = new anchor_1.AnchorProvider(connection, wallet, {});
51
- return new anchor_1.Program(switchboard_v2_json_1.default, programId, provider);
52
- }
53
- function convertSwitchboardDecimal(switchboardDecimal) {
54
- const switchboardPrecision = numericConstants_1.TEN.pow(new anchor_1.BN(switchboardDecimal.scale));
55
- return switchboardDecimal.mantissa
56
- .mul(numericConstants_1.PRICE_PRECISION)
57
- .div(switchboardPrecision);
58
- }