@drift-labs/sdk 2.87.0-beta.2 → 2.87.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.
@@ -5,6 +5,7 @@ import { DriftClient } from '../driftClient';
5
5
  import { BN } from '@coral-xyz/anchor';
6
6
  import { User } from '../user';
7
7
  import { DepositRecord } from '../types';
8
+ import fetch from 'node-fetch';
8
9
  export type BSOL_STATS_API_RESPONSE = {
9
10
  success: boolean;
10
11
  stats?: {
@@ -27,8 +28,8 @@ export type BSOL_EMISSIONS_API_RESPONSE = {
27
28
  lend: number;
28
29
  };
29
30
  };
30
- export declare function fetchBSolMetrics(): Promise<any>;
31
- export declare function fetchBSolDriftEmissions(): Promise<any>;
31
+ export declare function fetchBSolMetrics(): Promise<fetch.Response>;
32
+ export declare function fetchBSolDriftEmissions(): Promise<fetch.Response>;
32
33
  export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClient, driftClient, userAccountPublicKey, price, forceMarinade, onlyDirectRoutes, jupiterQuote, }: {
33
34
  marketIndex: number;
34
35
  amount: BN;
@@ -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 as BorshAccountsCoder30 } from '@coral-xyz/anchor-30';
5
+ export declare class SwitchboardOnDemandClient implements OracleClient {
6
+ connection: Connection;
7
+ coder: BorshAccountsCoder30;
8
+ constructor(connection: Connection);
9
+ getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
10
+ getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
11
+ }
@@ -0,0 +1,32 @@
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.SwitchboardOnDemandClient = void 0;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ const switchboard_on_demand_30_json_1 = __importDefault(require("../idl/switchboard_on_demand_30.json"));
9
+ const numericConstants_1 = require("../constants/numericConstants");
10
+ const anchor_30_1 = require("@coral-xyz/anchor-30");
11
+ const SB_PRECISION_EXP = new anchor_1.BN(18);
12
+ const SB_PRECISION = new anchor_1.BN(10).pow(SB_PRECISION_EXP.sub(numericConstants_1.PRICE_PRECISION_EXP));
13
+ class SwitchboardOnDemandClient {
14
+ constructor(connection) {
15
+ this.connection = connection;
16
+ this.coder = new anchor_30_1.BorshAccountsCoder(switchboard_on_demand_30_json_1.default);
17
+ }
18
+ async getOraclePriceData(pricePublicKey) {
19
+ const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
20
+ return this.getOraclePriceDataFromBuffer(accountInfo.data);
21
+ }
22
+ getOraclePriceDataFromBuffer(buffer) {
23
+ const pullFeedAccountData = this.coder.decodeUnchecked('PullFeedAccountData', buffer);
24
+ return {
25
+ price: pullFeedAccountData.result.value.div(SB_PRECISION),
26
+ slot: pullFeedAccountData.result.slot,
27
+ confidence: pullFeedAccountData.result.range.div(SB_PRECISION),
28
+ hasSufficientNumberOfDataPoints: true,
29
+ };
30
+ }
31
+ }
32
+ exports.SwitchboardOnDemandClient = SwitchboardOnDemandClient;
package/lib/types.d.ts CHANGED
@@ -182,6 +182,9 @@ export declare class OracleSource {
182
182
  static readonly Prelaunch: {
183
183
  prelaunch: {};
184
184
  };
185
+ static readonly SWITCHBOARD_ON_DEMAND: {
186
+ switchboardOnDemand: {};
187
+ };
185
188
  }
186
189
  export declare class OrderType {
187
190
  static readonly LIMIT: {
package/lib/types.js CHANGED
@@ -114,6 +114,7 @@ OracleSource.QUOTE_ASSET = { quoteAsset: {} };
114
114
  OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
115
115
  OracleSource.PYTH_STABLE_COIN_PULL = { pythStableCoinPull: {} };
116
116
  OracleSource.Prelaunch = { prelaunch: {} };
117
+ OracleSource.SWITCHBOARD_ON_DEMAND = { switchboardOnDemand: {} };
117
118
  class OrderType {
118
119
  }
119
120
  exports.OrderType = OrderType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.87.0-beta.2",
3
+ "version": "2.87.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@coral-xyz/anchor": "0.28.0",
38
+ "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1",
38
39
  "@ellipsis-labs/phoenix-sdk": "^1.4.2",
39
40
  "@project-serum/serum": "^0.13.38",
40
41
  "@pythnetwork/client": "2.5.3",
@@ -42,6 +43,7 @@
42
43
  "@pythnetwork/pyth-solana-receiver": "^0.7.0",
43
44
  "@solana/spl-token": "0.3.7",
44
45
  "@solana/web3.js": "1.92.3",
46
+ "@switchboard-xyz/on-demand": "^1.2.1",
45
47
  "anchor-bankrun": "^0.3.0",
46
48
  "rpc-websockets": "7.5.1",
47
49
  "solana-bankrun": "^0.3.0",
@@ -1115,9 +1115,7 @@ export class AdminClient extends DriftClient {
1115
1115
  },
1116
1116
  {
1117
1117
  accounts: {
1118
- admin: this.isSubscribed
1119
- ? this.getStateAccount().admin
1120
- : this.wallet.publicKey,
1118
+ admin: this.wallet.publicKey,
1121
1119
  state: await this.getStatePublicKey(),
1122
1120
  perpMarket: await getPerpMarketPublicKey(
1123
1121
  this.program.programId,
@@ -5,6 +5,7 @@ import {
5
5
  Program,
6
6
  ProgramAccount,
7
7
  } from '@coral-xyz/anchor';
8
+ import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
8
9
  import bs58 from 'bs58';
9
10
  import {
10
11
  ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -147,6 +148,8 @@ import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/py
147
148
  import { getFeedIdUint8Array, trimFeedId } from './util/pythPullOracleUtils';
148
149
  import { isVersionedTransaction } from './tx/utils';
149
150
  import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
151
+ import { PullFeed } from '@switchboard-xyz/on-demand';
152
+ import switchboardOnDemandIdl from './idl/switchboard_on_demand_30.json';
150
153
 
151
154
  type RemainingAccountParams = {
152
155
  userAccounts: UserAccount[];
@@ -198,6 +201,8 @@ export class DriftClient {
198
201
 
199
202
  receiverProgram?: Program<PythSolanaReceiver>;
200
203
  wormholeProgram?: Program<WormholeCoreBridgeSolana>;
204
+ sbOnDemandProgram?: Program30<Idl30>;
205
+ sbProgramFeedConfigs?: Map<string, any>;
201
206
 
202
207
  public get isSubscribed() {
203
208
  return this._isSubscribed && this.accountSubscriber.isSubscribed;
@@ -7057,6 +7062,16 @@ export class DriftClient {
7057
7062
  return this.receiverProgram;
7058
7063
  }
7059
7064
 
7065
+ public getSwitchboardOnDemandProgram(): Program30<Idl30> {
7066
+ if (this.sbOnDemandProgram === undefined) {
7067
+ this.sbOnDemandProgram = new Program30(
7068
+ switchboardOnDemandIdl as Idl30,
7069
+ this.provider
7070
+ );
7071
+ }
7072
+ return this.sbOnDemandProgram;
7073
+ }
7074
+
7060
7075
  public async postPythPullOracleUpdateAtomic(
7061
7076
  vaaString: string,
7062
7077
  feedId: string
@@ -7270,6 +7285,48 @@ export class DriftClient {
7270
7285
  );
7271
7286
  }
7272
7287
 
7288
+ public async getPostSwitchboardOnDemandUpdateAtomicIx(
7289
+ feed: PublicKey,
7290
+ numSignatures = 3
7291
+ ): Promise<TransactionInstruction | undefined> {
7292
+ const program = this.getSwitchboardOnDemandProgram();
7293
+ const feedAccount = new PullFeed(program, feed);
7294
+ if (!this.sbProgramFeedConfigs) {
7295
+ this.sbProgramFeedConfigs = new Map();
7296
+ }
7297
+ if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
7298
+ const feedConfig = await feedAccount.loadConfigs();
7299
+ this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
7300
+ }
7301
+
7302
+ const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
7303
+ numSignatures,
7304
+ feedConfigs: this.sbProgramFeedConfigs.get(feed.toString()),
7305
+ });
7306
+ if (!success) {
7307
+ return undefined;
7308
+ }
7309
+ return pullIx;
7310
+ }
7311
+
7312
+ public async postSwitchboardOnDemandUpdate(
7313
+ feed: PublicKey,
7314
+ numSignatures = 3
7315
+ ): Promise<TransactionSignature> {
7316
+ const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(
7317
+ feed,
7318
+ numSignatures
7319
+ );
7320
+ if (!pullIx) {
7321
+ return undefined;
7322
+ }
7323
+ const tx = await this.buildTransaction(pullIx, undefined, 0, [
7324
+ await this.fetchMarketLookupTableAccount(),
7325
+ ]);
7326
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
7327
+ return txSig;
7328
+ }
7329
+
7273
7330
  private async getBuildEncodedVaaIxs(
7274
7331
  vaa: Buffer,
7275
7332
  guardianSet: PublicKey
@@ -8,6 +8,7 @@ import { BN, Program } from '@coral-xyz/anchor';
8
8
  import { PrelaunchOracleClient } from '../oracles/prelaunchOracleClient';
9
9
  import { SwitchboardClient } from '../oracles/switchboardClient';
10
10
  import { PythPullClient } from '../oracles/pythPullClient';
11
+ import { SwitchboardOnDemandClient } from '../oracles/switchboardOnDemandClient';
11
12
 
12
13
  export function getOracleClient(
13
14
  oracleSource: OracleSource,
@@ -58,5 +59,9 @@ export function getOracleClient(
58
59
  return new QuoteAssetOracleClient();
59
60
  }
60
61
 
62
+ if (isVariant(oracleSource, 'switchboardOnDemand')) {
63
+ return new SwitchboardOnDemandClient(connection);
64
+ }
65
+
61
66
  throw new Error(`Unknown oracle source ${oracleSource}`);
62
67
  }
@@ -9945,6 +9945,9 @@
9945
9945
  },
9946
9946
  {
9947
9947
  "name": "PythStableCoinPull"
9948
+ },
9949
+ {
9950
+ "name": "SwitchboardOnDemand"
9948
9951
  }
9949
9952
  ]
9950
9953
  }