@drift-labs/sdk 2.71.0-beta.2 → 2.71.0-beta.4

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.
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { Connection, PublicKey } from '@solana/web3.js';
3
+ import { OracleClient, OraclePriceData } from './types';
4
+ import { BorshAccountsCoder } from '@coral-xyz/anchor';
5
+ export declare class SwitchboardClient implements OracleClient {
6
+ connection: Connection;
7
+ coder: BorshAccountsCoder;
8
+ constructor(connection: Connection);
9
+ getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
10
+ getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
11
+ }
@@ -0,0 +1,40 @@
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 numericConstants_1 = require("../constants/numericConstants");
8
+ const switchboard_json_1 = __importDefault(require("../idl/switchboard.json"));
9
+ const anchor_1 = require("@coral-xyz/anchor");
10
+ class SwitchboardClient {
11
+ constructor(connection) {
12
+ this.connection = connection;
13
+ this.coder = new anchor_1.BorshAccountsCoder(switchboard_json_1.default);
14
+ }
15
+ async getOraclePriceData(pricePublicKey) {
16
+ const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
17
+ return this.getOraclePriceDataFromBuffer(accountInfo.data);
18
+ }
19
+ getOraclePriceDataFromBuffer(buffer) {
20
+ const aggregatorAccountData = this.coder.decodeUnchecked('AggregatorAccountData', buffer);
21
+ const price = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound.result);
22
+ const confidence = anchor_1.BN.max(convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound.stdDeviation), price.divn(1000));
23
+ const hasSufficientNumberOfDataPoints = aggregatorAccountData.latestConfirmedRound.numSuccess >=
24
+ aggregatorAccountData.minOracleResults;
25
+ const slot = aggregatorAccountData.latestConfirmedRound.roundOpenSlot;
26
+ return {
27
+ price,
28
+ slot,
29
+ confidence,
30
+ hasSufficientNumberOfDataPoints,
31
+ };
32
+ }
33
+ }
34
+ exports.SwitchboardClient = SwitchboardClient;
35
+ function convertSwitchboardDecimal(switchboardDecimal) {
36
+ const switchboardPrecision = numericConstants_1.TEN.pow(new anchor_1.BN(switchboardDecimal.scale));
37
+ return switchboardDecimal.mantissa
38
+ .mul(numericConstants_1.PRICE_PRECISION)
39
+ .div(switchboardPrecision);
40
+ }
package/lib/types.d.ts CHANGED
@@ -143,6 +143,9 @@ export declare class OracleSource {
143
143
  static readonly PYTH_1M: {
144
144
  pyth1M: {};
145
145
  };
146
+ static readonly SWITCHBOARD: {
147
+ switchboard: {};
148
+ };
146
149
  static readonly QUOTE_ASSET: {
147
150
  quoteAsset: {};
148
151
  };
package/lib/types.js CHANGED
@@ -95,7 +95,7 @@ exports.OracleSource = OracleSource;
95
95
  OracleSource.PYTH = { pyth: {} };
96
96
  OracleSource.PYTH_1K = { pyth1K: {} };
97
97
  OracleSource.PYTH_1M = { pyth1M: {} };
98
- // static readonly SWITCHBOARD = { switchboard: {} };
98
+ OracleSource.SWITCHBOARD = { switchboard: {} };
99
99
  OracleSource.QUOTE_ASSET = { quoteAsset: {} };
100
100
  OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
101
101
  OracleSource.Prelaunch = { prelaunch: {} };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.71.0-beta.2",
3
+ "version": "2.71.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -650,6 +650,32 @@ export class AdminClient extends DriftClient {
650
650
  return txSig;
651
651
  }
652
652
 
653
+ public async updatePerpMarketFundingPeriod(
654
+ perpMarketIndex: number,
655
+ fundingPeriod: BN
656
+ ): Promise<TransactionSignature> {
657
+ const updatePerpMarketMarginRatioIx =
658
+ await this.program.instruction.updatePerpMarketFundingRate(
659
+ fundingPeriod,
660
+ {
661
+ accounts: {
662
+ admin: this.wallet.publicKey,
663
+ state: await this.getStatePublicKey(),
664
+ perpMarket: await getPerpMarketPublicKey(
665
+ this.program.programId,
666
+ perpMarketIndex
667
+ ),
668
+ },
669
+ }
670
+ );
671
+
672
+ const tx = await this.buildTransaction(updatePerpMarketMarginRatioIx);
673
+
674
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
675
+
676
+ return txSig;
677
+ }
678
+
653
679
  public async updatePerpMarketImfFactor(
654
680
  perpMarketIndex: number,
655
681
  imfFactor: number,
@@ -6,6 +6,7 @@ import { PythClient } from '../oracles/pythClient';
6
6
  import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
7
7
  import { BN, Program } from '@coral-xyz/anchor';
8
8
  import { PrelaunchOracleClient } from '../oracles/prelaunchOracleClient';
9
+ import { SwitchboardClient } from '../oracles/switchboardClient';
9
10
 
10
11
  export function getOracleClient(
11
12
  oracleSource: OracleSource,
@@ -28,9 +29,9 @@ export function getOracleClient(
28
29
  return new PythClient(connection, undefined, true);
29
30
  }
30
31
 
31
- // if (isVariant(oracleSource, 'switchboard')) {
32
- // return new SwitchboardClient(connection);
33
- // }
32
+ if (isVariant(oracleSource, 'switchboard')) {
33
+ return new SwitchboardClient(connection);
34
+ }
34
35
 
35
36
  if (isVariant(oracleSource, 'prelaunch')) {
36
37
  return new PrelaunchOracleClient(connection, program);
@@ -3336,6 +3336,32 @@
3336
3336
  }
3337
3337
  ]
3338
3338
  },
3339
+ {
3340
+ "name": "updatePerpMarketFundingPeriod",
3341
+ "accounts": [
3342
+ {
3343
+ "name": "admin",
3344
+ "isMut": false,
3345
+ "isSigner": true
3346
+ },
3347
+ {
3348
+ "name": "state",
3349
+ "isMut": false,
3350
+ "isSigner": false
3351
+ },
3352
+ {
3353
+ "name": "perpMarket",
3354
+ "isMut": true,
3355
+ "isSigner": false
3356
+ }
3357
+ ],
3358
+ "args": [
3359
+ {
3360
+ "name": "fundingPeriod",
3361
+ "type": "i64"
3362
+ }
3363
+ ]
3364
+ },
3339
3365
  {
3340
3366
  "name": "updatePerpMarketMaxImbalances",
3341
3367
  "accounts": [
@@ -8560,6 +8586,9 @@
8560
8586
  },
8561
8587
  {
8562
8588
  "name": "UpdateAMMCurve"
8589
+ },
8590
+ {
8591
+ "name": "OracleOrderPrice"
8563
8592
  }
8564
8593
  ]
8565
8594
  }