@drift-labs/sdk 2.86.0-beta.25 → 2.86.0-beta.26

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.86.0-beta.25
1
+ 2.86.0-beta.26
@@ -17,6 +17,7 @@ export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market
17
17
  export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
18
18
  export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
19
19
  export declare function getPhoenixFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
20
+ export declare function getOpenbookV2FulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
20
21
  export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameBuffer: number[]): PublicKey;
21
22
  export declare function getProtocolIfSharesTransferConfigPublicKey(programId: PublicKey): PublicKey;
22
23
  export declare function getPrelaunchOraclePublicKey(programId: PublicKey, marketIndex: number): PublicKey;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  async function getDriftStateAccountPublicKeyAndNonce(programId) {
@@ -126,6 +126,13 @@ function getPhoenixFulfillmentConfigPublicKey(programId, market) {
126
126
  ], programId)[0];
127
127
  }
128
128
  exports.getPhoenixFulfillmentConfigPublicKey = getPhoenixFulfillmentConfigPublicKey;
129
+ function getOpenbookV2FulfillmentConfigPublicKey(programId, market) {
130
+ return web3_js_1.PublicKey.findProgramAddressSync([
131
+ Buffer.from(anchor.utils.bytes.utf8.encode('openbook_v2_fulfillment_config')),
132
+ market.toBuffer(),
133
+ ], programId)[0];
134
+ }
135
+ exports.getOpenbookV2FulfillmentConfigPublicKey = getOpenbookV2FulfillmentConfigPublicKey;
129
136
  function getReferrerNamePublicKeySync(programId, nameBuffer) {
130
137
  return web3_js_1.PublicKey.findProgramAddressSync([
131
138
  Buffer.from(anchor.utils.bytes.utf8.encode('referrer_name')),
@@ -17,6 +17,8 @@ export declare class AdminClient extends DriftClient {
17
17
  getInitializeSerumFulfillmentConfigIx(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionInstruction>;
18
18
  initializePhoenixFulfillmentConfig(marketIndex: number, phoenixMarket: PublicKey): Promise<TransactionSignature>;
19
19
  getInitializePhoenixFulfillmentConfigIx(marketIndex: number, phoenixMarket: PublicKey): Promise<TransactionInstruction>;
20
+ initializeOpenbookV2FulfillmentConfig(marketIndex: number, openbookMarket: PublicKey): Promise<TransactionSignature>;
21
+ getInitializeOpenbookV2FulfillmentConfigIx(marketIndex: number, openbookMarket: PublicKey): Promise<TransactionInstruction>;
20
22
  initializePerpMarket(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, contractTier?: ContractTier, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, ifLiquidatorFee?: number, imfFactor?: number, activeStatus?: boolean, baseSpread?: number, maxSpread?: number, maxOpenInterest?: BN, maxRevenueWithdrawPerPeriod?: BN, quoteMaxInsurance?: BN, orderStepSize?: BN, orderTickSize?: BN, minOrderSize?: BN, concentrationCoefScale?: BN, curveUpdateIntensity?: number, ammJitIntensity?: number, name?: string): Promise<TransactionSignature>;
21
23
  getInitializePerpMarketIx(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, contractTier?: ContractTier, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, ifLiquidatorFee?: number, imfFactor?: number, activeStatus?: boolean, baseSpread?: number, maxSpread?: number, maxOpenInterest?: BN, maxRevenueWithdrawPerPeriod?: BN, quoteMaxInsurance?: BN, orderStepSize?: BN, orderTickSize?: BN, minOrderSize?: BN, concentrationCoefScale?: BN, curveUpdateIntensity?: number, ammJitIntensity?: number, name?: string): Promise<TransactionInstruction>;
22
24
  deleteInitializedPerpMarket(marketIndex: number): Promise<TransactionSignature>;
@@ -39,6 +39,7 @@ const amm_1 = require("./math/amm");
39
39
  const phoenix_sdk_1 = require("@ellipsis-labs/phoenix-sdk");
40
40
  const config_1 = require("./config");
41
41
  const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
42
+ const OPENBOOK_PROGRAM_ID = new web3_js_1.PublicKey('opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb');
42
43
  class AdminClient extends driftClient_1.DriftClient {
43
44
  async initialize(usdcMint, _adminControlsPrices) {
44
45
  const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
@@ -177,6 +178,31 @@ class AdminClient extends driftClient_1.DriftClient {
177
178
  },
178
179
  });
179
180
  }
181
+ async initializeOpenbookV2FulfillmentConfig(marketIndex, openbookMarket) {
182
+ const initializeIx = await this.getInitializeOpenbookV2FulfillmentConfigIx(marketIndex, openbookMarket);
183
+ const tx = await this.buildTransaction(initializeIx);
184
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
185
+ return txSig;
186
+ }
187
+ async getInitializeOpenbookV2FulfillmentConfigIx(marketIndex, openbookMarket) {
188
+ const openbookFulfillmentConfig = (0, pda_1.getOpenbookV2FulfillmentConfigPublicKey)(this.program.programId, openbookMarket);
189
+ return this.program.instruction.initializeOpenbookV2FulfillmentConfig(marketIndex, {
190
+ accounts: {
191
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
192
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
193
+ state: await this.getStatePublicKey(),
194
+ openbookV2Program: OPENBOOK_PROGRAM_ID,
195
+ openbookV2Market: openbookMarket,
196
+ driftSigner: this.getSignerPublicKey(),
197
+ openbookV2FulfillmentConfig: openbookFulfillmentConfig,
198
+ admin: this.isSubscribed
199
+ ? this.getStateAccount().admin
200
+ : this.wallet.publicKey,
201
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
202
+ systemProgram: anchor.web3.SystemProgram.programId,
203
+ },
204
+ });
205
+ }
180
206
  async initializePerpMarket(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, contractTier = types_1.ContractTier.SPECULATIVE, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, ifLiquidatorFee = 10000, imfFactor = 0, activeStatus = true, baseSpread = 0, maxSpread = 142500, maxOpenInterest = numericConstants_1.ZERO, maxRevenueWithdrawPerPeriod = numericConstants_1.ZERO, quoteMaxInsurance = numericConstants_1.ZERO, orderStepSize = numericConstants_1.BASE_PRECISION.divn(10000), orderTickSize = numericConstants_1.PRICE_PRECISION.divn(100000), minOrderSize = numericConstants_1.BASE_PRECISION.divn(10000), concentrationCoefScale = numericConstants_1.ONE, curveUpdateIntensity = 0, ammJitIntensity = 0, name = userName_1.DEFAULT_MARKET_NAME) {
181
207
  const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
182
208
  const initializeMarketIx = await this.getInitializePerpMarketIx(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, contractTier, marginRatioInitial, marginRatioMaintenance, liquidatorFee, ifLiquidatorFee, imfFactor, activeStatus, baseSpread, maxSpread, maxOpenInterest, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, orderStepSize, orderTickSize, minOrderSize, concentrationCoefScale, curveUpdateIntensity, ammJitIntensity, name);
@@ -2,7 +2,7 @@
2
2
  /// <reference types="bn.js" />
3
3
  /// <reference types="node" />
4
4
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
5
- import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord } from './types';
5
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord, OpenbookV2FulfillmentConfigAccount } from './types';
6
6
  import * as anchor from '@coral-xyz/anchor';
7
7
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
8
8
  import { TokenFaucet } from './tokenFaucet';
@@ -107,6 +107,8 @@ export declare class DriftClient {
107
107
  getSerumV3FulfillmentConfigs(): Promise<SerumV3FulfillmentConfigAccount[]>;
108
108
  getPhoenixV1FulfillmentConfig(phoenixMarket: PublicKey): Promise<PhoenixV1FulfillmentConfigAccount>;
109
109
  getPhoenixV1FulfillmentConfigs(): Promise<PhoenixV1FulfillmentConfigAccount[]>;
110
+ getOpenbookV2FulfillmentConfig(openbookMarket: PublicKey): Promise<OpenbookV2FulfillmentConfigAccount>;
111
+ getOpenbookV2FulfillmentConfigs(): Promise<OpenbookV2FulfillmentConfigAccount[]>;
110
112
  fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
111
113
  /**
112
114
  * Update the wallet to use for drift transactions and linked user account
@@ -357,11 +359,12 @@ export declare class DriftClient {
357
359
  placeSpotOrderTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
358
360
  }>;
359
361
  getPlaceSpotOrderIx(orderParams: OptionalOrderParams, subAccountId?: number): Promise<TransactionInstruction>;
360
- fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
361
- getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
362
- addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount): void;
362
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
363
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
364
+ addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount): void;
363
365
  addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
364
366
  addPhoenixRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount): void;
367
+ addOpenbookRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: OpenbookV2FulfillmentConfigAccount): void;
365
368
  /**
366
369
  * Swap tokens in drift account using jupiter
367
370
  * @param jupiterClient jupiter client to find routes and jupiter instructions
@@ -324,6 +324,14 @@ class DriftClient {
324
324
  const accounts = await this.program.account.phoenixV1FulfillmentConfig.all();
325
325
  return accounts.map((account) => account.account);
326
326
  }
327
+ async getOpenbookV2FulfillmentConfig(openbookMarket) {
328
+ const address = (0, pda_1.getOpenbookV2FulfillmentConfigPublicKey)(this.program.programId, openbookMarket);
329
+ return (await this.program.account.openbookV2FulfillmentConfig.fetch(address));
330
+ }
331
+ async getOpenbookV2FulfillmentConfigs() {
332
+ const accounts = await this.program.account.openbookV2FulfillmentConfig.all();
333
+ return accounts.map((account) => account.account);
334
+ }
327
335
  async fetchMarketLookupTableAccount() {
328
336
  if (this.lookupTableAccount)
329
337
  return this.lookupTableAccount;
@@ -2010,6 +2018,9 @@ class DriftClient {
2010
2018
  else if ('phoenixProgramId' in fulfillmentConfig) {
2011
2019
  this.addPhoenixRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
2012
2020
  }
2021
+ else if ('openbookV2ProgramId' in fulfillmentConfig) {
2022
+ this.addOpenbookRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig);
2023
+ }
2013
2024
  else {
2014
2025
  throw Error('Invalid fulfillment config type');
2015
2026
  }
@@ -2161,6 +2172,97 @@ class DriftClient {
2161
2172
  isSigner: false,
2162
2173
  });
2163
2174
  }
2175
+ addOpenbookRemainingAccounts(marketIndex, remainingAccounts, fulfillmentConfig) {
2176
+ remainingAccounts.push({
2177
+ pubkey: fulfillmentConfig.pubkey,
2178
+ isWritable: false,
2179
+ isSigner: false,
2180
+ });
2181
+ remainingAccounts.push({
2182
+ pubkey: this.getSignerPublicKey(),
2183
+ isWritable: true,
2184
+ isSigner: false,
2185
+ });
2186
+ remainingAccounts.push({
2187
+ pubkey: fulfillmentConfig.openbookV2ProgramId,
2188
+ isWritable: false,
2189
+ isSigner: false,
2190
+ });
2191
+ remainingAccounts.push({
2192
+ pubkey: fulfillmentConfig.openbookV2Market,
2193
+ isWritable: true,
2194
+ isSigner: false,
2195
+ });
2196
+ remainingAccounts.push({
2197
+ pubkey: fulfillmentConfig.openbookV2MarketAuthority,
2198
+ isWritable: false,
2199
+ isSigner: false,
2200
+ });
2201
+ remainingAccounts.push({
2202
+ pubkey: fulfillmentConfig.openbookV2EventHeap,
2203
+ isWritable: true,
2204
+ isSigner: false,
2205
+ });
2206
+ remainingAccounts.push({
2207
+ pubkey: fulfillmentConfig.openbookV2Bids,
2208
+ isWritable: true,
2209
+ isSigner: false,
2210
+ });
2211
+ remainingAccounts.push({
2212
+ pubkey: fulfillmentConfig.openbookV2Asks,
2213
+ isWritable: true,
2214
+ isSigner: false,
2215
+ });
2216
+ remainingAccounts.push({
2217
+ pubkey: fulfillmentConfig.openbookV2BaseVault,
2218
+ isWritable: true,
2219
+ isSigner: false,
2220
+ });
2221
+ remainingAccounts.push({
2222
+ pubkey: fulfillmentConfig.openbookV2QuoteVault,
2223
+ isWritable: true,
2224
+ isSigner: false,
2225
+ });
2226
+ remainingAccounts.push({
2227
+ pubkey: this.getSpotMarketAccount(marketIndex).vault,
2228
+ isWritable: true,
2229
+ isSigner: false,
2230
+ });
2231
+ remainingAccounts.push({
2232
+ pubkey: this.getQuoteSpotMarketAccount().vault,
2233
+ isWritable: true,
2234
+ isSigner: false,
2235
+ });
2236
+ remainingAccounts.push({
2237
+ pubkey: spl_token_1.TOKEN_PROGRAM_ID,
2238
+ isWritable: false,
2239
+ isSigner: false,
2240
+ });
2241
+ remainingAccounts.push({
2242
+ pubkey: web3_js_1.SystemProgram.programId,
2243
+ isWritable: false,
2244
+ isSigner: false,
2245
+ });
2246
+ remainingAccounts.push({
2247
+ pubkey: this.getSpotMarketAccount(marketIndex).pubkey,
2248
+ isWritable: true,
2249
+ isSigner: false,
2250
+ });
2251
+ remainingAccounts.push({
2252
+ pubkey: this.getQuoteSpotMarketAccount().pubkey,
2253
+ isWritable: true,
2254
+ isSigner: false,
2255
+ });
2256
+ if (fulfillmentConfig.remainingAccounts) {
2257
+ for (const remainingAccount of fulfillmentConfig.remainingAccounts) {
2258
+ remainingAccounts.push({
2259
+ pubkey: remainingAccount,
2260
+ isWritable: true,
2261
+ isSigner: false,
2262
+ });
2263
+ }
2264
+ }
2265
+ }
2164
2266
  /**
2165
2267
  * Swap tokens in drift account using jupiter
2166
2268
  * @param jupiterClient jupiter client to find routes and jupiter instructions
@@ -3017,6 +3017,95 @@
3017
3017
  }
3018
3018
  ]
3019
3019
  },
3020
+ {
3021
+ "name": "initializeOpenbookV2FulfillmentConfig",
3022
+ "accounts": [
3023
+ {
3024
+ "name": "baseSpotMarket",
3025
+ "isMut": false,
3026
+ "isSigner": false
3027
+ },
3028
+ {
3029
+ "name": "quoteSpotMarket",
3030
+ "isMut": false,
3031
+ "isSigner": false
3032
+ },
3033
+ {
3034
+ "name": "state",
3035
+ "isMut": true,
3036
+ "isSigner": false
3037
+ },
3038
+ {
3039
+ "name": "openbookV2Program",
3040
+ "isMut": false,
3041
+ "isSigner": false
3042
+ },
3043
+ {
3044
+ "name": "openbookV2Market",
3045
+ "isMut": false,
3046
+ "isSigner": false
3047
+ },
3048
+ {
3049
+ "name": "driftSigner",
3050
+ "isMut": false,
3051
+ "isSigner": false
3052
+ },
3053
+ {
3054
+ "name": "openbookV2FulfillmentConfig",
3055
+ "isMut": true,
3056
+ "isSigner": false
3057
+ },
3058
+ {
3059
+ "name": "admin",
3060
+ "isMut": true,
3061
+ "isSigner": true
3062
+ },
3063
+ {
3064
+ "name": "rent",
3065
+ "isMut": false,
3066
+ "isSigner": false
3067
+ },
3068
+ {
3069
+ "name": "systemProgram",
3070
+ "isMut": false,
3071
+ "isSigner": false
3072
+ }
3073
+ ],
3074
+ "args": [
3075
+ {
3076
+ "name": "marketIndex",
3077
+ "type": "u16"
3078
+ }
3079
+ ]
3080
+ },
3081
+ {
3082
+ "name": "openbookV2FulfillmentConfigStatus",
3083
+ "accounts": [
3084
+ {
3085
+ "name": "state",
3086
+ "isMut": false,
3087
+ "isSigner": false
3088
+ },
3089
+ {
3090
+ "name": "openbookV2FulfillmentConfig",
3091
+ "isMut": true,
3092
+ "isSigner": false
3093
+ },
3094
+ {
3095
+ "name": "admin",
3096
+ "isMut": true,
3097
+ "isSigner": true
3098
+ }
3099
+ ],
3100
+ "args": [
3101
+ {
3102
+ "name": "status",
3103
+ "type": {
3104
+ "defined": "SpotFulfillmentConfigStatus"
3105
+ }
3106
+ }
3107
+ ]
3108
+ },
3020
3109
  {
3021
3110
  "name": "initializePhoenixFulfillmentConfig",
3022
3111
  "accounts": [
@@ -5631,6 +5720,75 @@
5631
5720
  }
5632
5721
  ],
5633
5722
  "accounts": [
5723
+ {
5724
+ "name": "OpenbookV2FulfillmentConfig",
5725
+ "type": {
5726
+ "kind": "struct",
5727
+ "fields": [
5728
+ {
5729
+ "name": "pubkey",
5730
+ "type": "publicKey"
5731
+ },
5732
+ {
5733
+ "name": "openbookV2ProgramId",
5734
+ "type": "publicKey"
5735
+ },
5736
+ {
5737
+ "name": "openbookV2Market",
5738
+ "type": "publicKey"
5739
+ },
5740
+ {
5741
+ "name": "openbookV2MarketAuthority",
5742
+ "type": "publicKey"
5743
+ },
5744
+ {
5745
+ "name": "openbookV2EventHeap",
5746
+ "type": "publicKey"
5747
+ },
5748
+ {
5749
+ "name": "openbookV2Bids",
5750
+ "type": "publicKey"
5751
+ },
5752
+ {
5753
+ "name": "openbookV2Asks",
5754
+ "type": "publicKey"
5755
+ },
5756
+ {
5757
+ "name": "openbookV2BaseVault",
5758
+ "type": "publicKey"
5759
+ },
5760
+ {
5761
+ "name": "openbookV2QuoteVault",
5762
+ "type": "publicKey"
5763
+ },
5764
+ {
5765
+ "name": "marketIndex",
5766
+ "type": "u16"
5767
+ },
5768
+ {
5769
+ "name": "fulfillmentType",
5770
+ "type": {
5771
+ "defined": "SpotFulfillmentType"
5772
+ }
5773
+ },
5774
+ {
5775
+ "name": "status",
5776
+ "type": {
5777
+ "defined": "SpotFulfillmentConfigStatus"
5778
+ }
5779
+ },
5780
+ {
5781
+ "name": "padding",
5782
+ "type": {
5783
+ "array": [
5784
+ "u8",
5785
+ 4
5786
+ ]
5787
+ }
5788
+ }
5789
+ ]
5790
+ }
5791
+ },
5634
5792
  {
5635
5793
  "name": "PhoenixV1FulfillmentConfig",
5636
5794
  "type": {
@@ -9269,6 +9427,9 @@
9269
9427
  },
9270
9428
  {
9271
9429
  "name": "PhoenixV1"
9430
+ },
9431
+ {
9432
+ "name": "OpenbookV2"
9272
9433
  }
9273
9434
  ]
9274
9435
  }
@@ -9540,6 +9701,9 @@
9540
9701
  },
9541
9702
  {
9542
9703
  "name": "DeriskLp"
9704
+ },
9705
+ {
9706
+ "name": "OrderFilledWithOpenbookV2"
9543
9707
  }
9544
9708
  ]
9545
9709
  }
@@ -12553,6 +12717,21 @@
12553
12717
  "code": 6278,
12554
12718
  "name": "OracleBadRemainingAccountPublicKey",
12555
12719
  "msg": "Remaining account passed is not a valid pda"
12720
+ },
12721
+ {
12722
+ "code": 6279,
12723
+ "name": "FailedOpenbookV2CPI",
12724
+ "msg": "FailedOpenbookV2CPI"
12725
+ },
12726
+ {
12727
+ "code": 6280,
12728
+ "name": "InvalidOpenbookV2Program",
12729
+ "msg": "InvalidOpenbookV2Program"
12730
+ },
12731
+ {
12732
+ "code": 6281,
12733
+ "name": "InvalidOpenbookV2Market",
12734
+ "msg": "InvalidOpenbookV2Market"
12556
12735
  }
12557
12736
  ],
12558
12737
  "metadata": {
package/lib/types.d.ts CHANGED
@@ -1202,6 +1202,21 @@ export type PhoenixV1FulfillmentConfigAccount = {
1202
1202
  fulfillmentType: SpotFulfillmentType;
1203
1203
  status: SpotFulfillmentStatus;
1204
1204
  };
1205
+ export type OpenbookV2FulfillmentConfigAccount = {
1206
+ pubkey: PublicKey;
1207
+ openbookV2ProgramId: PublicKey;
1208
+ openbookV2Market: PublicKey;
1209
+ openbookV2MarketAuthority: PublicKey;
1210
+ openbookV2EventHeap: PublicKey;
1211
+ openbookV2Bids: PublicKey;
1212
+ openbookV2Asks: PublicKey;
1213
+ openbookV2BaseVault: PublicKey;
1214
+ openbookV2QuoteVault: PublicKey;
1215
+ marketIndex: number;
1216
+ fulfillmentType: SpotFulfillmentType;
1217
+ status: SpotFulfillmentStatus;
1218
+ remainingAccounts?: PublicKey[];
1219
+ };
1205
1220
  export type ReferrerNameAccount = {
1206
1221
  name: number[];
1207
1222
  user: PublicKey;
package/lib/user.js CHANGED
@@ -592,7 +592,7 @@ class User {
592
592
  // todo: get real time ifStakedGovTokenAmount using ifStakeAccount
593
593
  if (userStats.ifStakedGovTokenAmount.gt(numericConstants_1.ZERO)) {
594
594
  const spotMarketAccount = this.driftClient.getSpotMarketAccount(numericConstants_1.GOV_SPOT_MARKET_INDEX);
595
- const fuelBonusNumeratorUserStats = now.sub(_1.BN.max(new _1.BN(userStats.lastFuelIfBonusUpdateTs), numericConstants_1.FUEL_START_TS));
595
+ const fuelBonusNumeratorUserStats = _1.BN.max(now.sub(_1.BN.max(new _1.BN(userStats.lastFuelIfBonusUpdateTs), numericConstants_1.FUEL_START_TS)), numericConstants_1.ZERO);
596
596
  result.insuranceFuel = result.insuranceFuel.add((0, fuel_1.calculateInsuranceFuelBonus)(spotMarketAccount, userStats.ifStakedGovTokenAmount, fuelBonusNumeratorUserStats));
597
597
  }
598
598
  if (userStats.ifStakedQuoteAssetAmount.gt(numericConstants_1.ZERO)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.86.0-beta.25",
3
+ "version": "2.86.0-beta.26",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -202,6 +202,21 @@ export function getPhoenixFulfillmentConfigPublicKey(
202
202
  )[0];
203
203
  }
204
204
 
205
+ export function getOpenbookV2FulfillmentConfigPublicKey(
206
+ programId: PublicKey,
207
+ market: PublicKey
208
+ ): PublicKey {
209
+ return PublicKey.findProgramAddressSync(
210
+ [
211
+ Buffer.from(
212
+ anchor.utils.bytes.utf8.encode('openbook_v2_fulfillment_config')
213
+ ),
214
+ market.toBuffer(),
215
+ ],
216
+ programId
217
+ )[0];
218
+ }
219
+
205
220
  export function getReferrerNamePublicKeySync(
206
221
  programId: PublicKey,
207
222
  nameBuffer: number[]
@@ -29,6 +29,7 @@ import {
29
29
  getPhoenixFulfillmentConfigPublicKey,
30
30
  getProtocolIfSharesTransferConfigPublicKey,
31
31
  getPrelaunchOraclePublicKey,
32
+ getOpenbookV2FulfillmentConfigPublicKey,
32
33
  getPythPullOraclePublicKey,
33
34
  getUserStatsAccountPublicKey,
34
35
  } from './addresses/pda';
@@ -49,6 +50,10 @@ import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
49
50
  import { DRIFT_ORACLE_RECEIVER_ID } from './config';
50
51
  import { getFeedIdUint8Array } from './util/pythPullOracleUtils';
51
52
 
53
+ const OPENBOOK_PROGRAM_ID = new PublicKey(
54
+ 'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb'
55
+ );
56
+
52
57
  export class AdminClient extends DriftClient {
53
58
  public async initialize(
54
59
  usdcMint: PublicKey,
@@ -386,6 +391,52 @@ export class AdminClient extends DriftClient {
386
391
  );
387
392
  }
388
393
 
394
+ public async initializeOpenbookV2FulfillmentConfig(
395
+ marketIndex: number,
396
+ openbookMarket: PublicKey
397
+ ): Promise<TransactionSignature> {
398
+ const initializeIx = await this.getInitializeOpenbookV2FulfillmentConfigIx(
399
+ marketIndex,
400
+ openbookMarket
401
+ );
402
+
403
+ const tx = await this.buildTransaction(initializeIx);
404
+
405
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
406
+
407
+ return txSig;
408
+ }
409
+
410
+ public async getInitializeOpenbookV2FulfillmentConfigIx(
411
+ marketIndex: number,
412
+ openbookMarket: PublicKey
413
+ ): Promise<TransactionInstruction> {
414
+ const openbookFulfillmentConfig = getOpenbookV2FulfillmentConfigPublicKey(
415
+ this.program.programId,
416
+ openbookMarket
417
+ );
418
+
419
+ return this.program.instruction.initializeOpenbookV2FulfillmentConfig(
420
+ marketIndex,
421
+ {
422
+ accounts: {
423
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
424
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
425
+ state: await this.getStatePublicKey(),
426
+ openbookV2Program: OPENBOOK_PROGRAM_ID,
427
+ openbookV2Market: openbookMarket,
428
+ driftSigner: this.getSignerPublicKey(),
429
+ openbookV2FulfillmentConfig: openbookFulfillmentConfig,
430
+ admin: this.isSubscribed
431
+ ? this.getStateAccount().admin
432
+ : this.wallet.publicKey,
433
+ rent: SYSVAR_RENT_PUBKEY,
434
+ systemProgram: anchor.web3.SystemProgram.programId,
435
+ },
436
+ }
437
+ );
438
+ }
439
+
389
440
  public async initializePerpMarket(
390
441
  marketIndex: number,
391
442
  priceOracle: PublicKey,