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

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.
package/lib/types.d.ts CHANGED
@@ -149,6 +149,9 @@ export declare class OracleSource {
149
149
  static readonly PYTH_STABLE_COIN: {
150
150
  pythStableCoin: {};
151
151
  };
152
+ static readonly Prelaunch: {
153
+ prelaunch: {};
154
+ };
152
155
  }
153
156
  export declare class OrderType {
154
157
  static readonly LIMIT: {
@@ -1084,6 +1087,14 @@ export type OracleGuardRails = {
1084
1087
  tooVolatileRatio: BN;
1085
1088
  };
1086
1089
  };
1090
+ export type PrelaunchOracle = {
1091
+ price: BN;
1092
+ maxPrice: BN;
1093
+ confidence: BN;
1094
+ ammLastUpdateSlot: BN;
1095
+ lastUpdateSlot: BN;
1096
+ perpMarketIndex: number;
1097
+ };
1087
1098
  export type MarginCategory = 'Initial' | 'Maintenance';
1088
1099
  export type InsuranceFundStake = {
1089
1100
  costBasis: BN;
package/lib/types.js CHANGED
@@ -98,6 +98,7 @@ OracleSource.PYTH_1M = { pyth1M: {} };
98
98
  // static readonly SWITCHBOARD = { switchboard: {} };
99
99
  OracleSource.QUOTE_ASSET = { quoteAsset: {} };
100
100
  OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
101
+ OracleSource.Prelaunch = { prelaunch: {} };
101
102
  class OrderType {
102
103
  }
103
104
  exports.OrderType = OrderType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.71.0-beta.0",
3
+ "version": "2.71.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -257,7 +257,8 @@ export class PollingDriftClientAccountSubscriber
257
257
  async addOracleToAccountLoader(oracleToPoll: OraclesToPoll): Promise<void> {
258
258
  const oracleClient = this.oracleClientCache.get(
259
259
  oracleToPoll.source,
260
- this.program.provider.connection
260
+ this.program.provider.connection,
261
+ this.program
261
262
  );
262
263
 
263
264
  oracleToPoll.callbackId = await this.accountLoader.addAccount(
@@ -316,7 +317,8 @@ export class PollingDriftClientAccountSubscriber
316
317
  if (buffer) {
317
318
  const oracleClient = this.oracleClientCache.get(
318
319
  oracleToPoll.source,
319
- this.program.provider.connection
320
+ this.program.provider.connection,
321
+ this.program
320
322
  );
321
323
  const oraclePriceData =
322
324
  oracleClient.getOraclePriceDataFromBuffer(buffer);
@@ -204,7 +204,8 @@ export class WebSocketDriftClientAccountSubscriber
204
204
  async subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean> {
205
205
  const client = this.oracleClientCache.get(
206
206
  oracleInfo.source,
207
- this.program.provider.connection
207
+ this.program.provider.connection,
208
+ this.program
208
209
  );
209
210
  const accountSubscriber = new WebSocketAccountSubscriber<OraclePriceData>(
210
211
  'oracle',
@@ -223,3 +223,16 @@ export function getProtocolIfSharesTransferConfigPublicKey(
223
223
  programId
224
224
  )[0];
225
225
  }
226
+
227
+ export function getPrelaunchOraclePublicKey(
228
+ programId: PublicKey,
229
+ marketIndex: number
230
+ ): PublicKey {
231
+ return PublicKey.findProgramAddressSync(
232
+ [
233
+ Buffer.from(anchor.utils.bytes.utf8.encode('prelaunch_oracle')),
234
+ new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
235
+ ],
236
+ programId
237
+ )[0];
238
+ }
@@ -26,6 +26,7 @@ import {
26
26
  getSerumFulfillmentConfigPublicKey,
27
27
  getPhoenixFulfillmentConfigPublicKey,
28
28
  getProtocolIfSharesTransferConfigPublicKey,
29
+ getPrelaunchOraclePublicKey,
29
30
  } from './addresses/pda';
30
31
  import { squareRootBN } from './math/utils';
31
32
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
@@ -1794,4 +1795,50 @@ export class AdminClient extends DriftClient {
1794
1795
  }
1795
1796
  );
1796
1797
  }
1798
+
1799
+ public async initializePrelaunchOracle(
1800
+ perpMarketIndex: number,
1801
+ price?: BN,
1802
+ maxPrice?: BN
1803
+ ): Promise<TransactionSignature> {
1804
+ const params = {
1805
+ perpMarketIndex,
1806
+ price: price || null,
1807
+ maxPrice: maxPrice || null,
1808
+ };
1809
+ return await this.program.rpc.initializePrelaunchOracle(params, {
1810
+ accounts: {
1811
+ admin: this.wallet.publicKey,
1812
+ state: await this.getStatePublicKey(),
1813
+ prelaunchOracle: await getPrelaunchOraclePublicKey(
1814
+ this.program.programId,
1815
+ perpMarketIndex
1816
+ ),
1817
+ rent: SYSVAR_RENT_PUBKEY,
1818
+ systemProgram: anchor.web3.SystemProgram.programId,
1819
+ },
1820
+ });
1821
+ }
1822
+
1823
+ public async updatePrelaunchOracleParams(
1824
+ perpMarketIndex: number,
1825
+ price?: BN,
1826
+ maxPrice?: BN
1827
+ ): Promise<TransactionSignature> {
1828
+ const params = {
1829
+ perpMarketIndex,
1830
+ price: price || null,
1831
+ maxPrice: maxPrice || null,
1832
+ };
1833
+ return await this.program.rpc.updatePrelaunchOracleParams(params, {
1834
+ accounts: {
1835
+ admin: this.wallet.publicKey,
1836
+ state: await this.getStatePublicKey(),
1837
+ prelaunchOracle: await getPrelaunchOraclePublicKey(
1838
+ this.program.programId,
1839
+ perpMarketIndex
1840
+ ),
1841
+ },
1842
+ });
1843
+ }
1797
1844
  }
@@ -244,16 +244,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
244
244
  launchTs: 1704209558000,
245
245
  oracleSource: OracleSource.PYTH,
246
246
  },
247
- // {
248
- // fullName: 'WIF',
249
- // category: ['Meme', 'Dog'],
250
- // symbol: 'WIF-PERP',
251
- // baseAssetSymbol: 'WIF',
252
- // marketIndex: 23,
253
- // oracle: new PublicKey('5i1sz2QQjCQt9PnhuPvqbiYUAYCgjdRnza1JbiH2qRCo'),
254
- // launchTs: 1706219971000,
255
- // oracleSource: OracleSource.PYTH,
256
- // },
247
+ {
248
+ fullName: 'Wormhole',
249
+ category: ['Bridge'],
250
+ symbol: 'W-PERP',
251
+ baseAssetSymbol: 'W',
252
+ marketIndex: 23,
253
+ oracle: new PublicKey('BM2UWqREbt7ktsPCA438dqAVqhU7UZFVg11CQyPXFr49'),
254
+ launchTs: 1709852537000,
255
+ oracleSource: OracleSource.Prelaunch,
256
+ },
257
257
  ];
258
258
 
259
259
  export const MainnetPerpMarkets: PerpMarketConfig[] = [
@@ -1566,10 +1566,12 @@ export class DriftClient {
1566
1566
  isSigner: false,
1567
1567
  isWritable: writable,
1568
1568
  });
1569
+ const oracleWritable =
1570
+ writable && isVariant(perpMarketAccount.amm.oracleSource, 'prelaunch');
1569
1571
  oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
1570
1572
  pubkey: perpMarketAccount.amm.oracle,
1571
1573
  isSigner: false,
1572
- isWritable: false,
1574
+ isWritable: oracleWritable,
1573
1575
  });
1574
1576
  this.addSpotMarketToRemainingAccountMaps(
1575
1577
  perpMarketAccount.quoteSpotMarketIndex,
@@ -5787,6 +5789,39 @@ export class DriftClient {
5787
5789
  });
5788
5790
  }
5789
5791
 
5792
+ public async updatePrelaunchOracle(
5793
+ perpMarketIndex: number,
5794
+ txParams?: TxParams
5795
+ ): Promise<TransactionSignature> {
5796
+ const { txSig } = await this.sendTransaction(
5797
+ await this.buildTransaction(
5798
+ await this.getUpdatePrelaunchOracleIx(perpMarketIndex),
5799
+ txParams
5800
+ ),
5801
+ [],
5802
+ this.opts
5803
+ );
5804
+ return txSig;
5805
+ }
5806
+
5807
+ public async getUpdatePrelaunchOracleIx(
5808
+ perpMarketIndex: number
5809
+ ): Promise<TransactionInstruction> {
5810
+ const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
5811
+
5812
+ if (!isVariant(perpMarket.amm.oracleSource, 'prelaunch')) {
5813
+ throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
5814
+ }
5815
+
5816
+ return await this.program.instruction.updatePrelaunchOracle({
5817
+ accounts: {
5818
+ state: await this.getStatePublicKey(),
5819
+ perpMarket: perpMarket.pubkey,
5820
+ oracle: perpMarket.amm.oracle,
5821
+ },
5822
+ });
5823
+ }
5824
+
5790
5825
  public async updatePerpBidAskTwap(
5791
5826
  perpMarketIndex: number,
5792
5827
  makers: [PublicKey, PublicKey][],
@@ -4,11 +4,13 @@ import { OracleClient } from '../oracles/types';
4
4
  import { PythClient } from '../oracles/pythClient';
5
5
  // import { SwitchboardClient } from '../oracles/switchboardClient';
6
6
  import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
7
- import { BN } from '@coral-xyz/anchor';
7
+ import { BN, Program } from '@coral-xyz/anchor';
8
+ import { PrelaunchOracleClient } from '../oracles/prelaunchOracleClient';
8
9
 
9
10
  export function getOracleClient(
10
11
  oracleSource: OracleSource,
11
- connection: Connection
12
+ connection: Connection,
13
+ program: Program
12
14
  ): OracleClient {
13
15
  if (isVariant(oracleSource, 'pyth')) {
14
16
  return new PythClient(connection);
@@ -30,6 +32,10 @@ export function getOracleClient(
30
32
  // return new SwitchboardClient(connection);
31
33
  // }
32
34
 
35
+ if (isVariant(oracleSource, 'prelaunch')) {
36
+ return new PrelaunchOracleClient(connection, program);
37
+ }
38
+
33
39
  if (isVariant(oracleSource, 'quoteAsset')) {
34
40
  return new QuoteAssetOracleClient();
35
41
  }