@drift-labs/sdk 2.31.1-beta.1 → 2.31.1-beta.11

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.
Files changed (42) hide show
  1. package/VERSION +1 -1
  2. package/lib/accounts/mockUserAccountSubscriber.d.ts +23 -0
  3. package/lib/accounts/mockUserAccountSubscriber.js +31 -0
  4. package/lib/constants/perpMarkets.js +20 -0
  5. package/lib/driftClient.d.ts +12 -1
  6. package/lib/driftClient.js +92 -21
  7. package/lib/driftClientConfig.d.ts +4 -9
  8. package/lib/idl/drift.json +1 -1
  9. package/lib/index.d.ts +1 -0
  10. package/lib/index.js +1 -0
  11. package/lib/marinade/index.d.ts +11 -0
  12. package/lib/marinade/index.js +36 -0
  13. package/lib/marinade/types.d.ts +1963 -0
  14. package/lib/marinade/types.js +1965 -0
  15. package/lib/math/tiers.d.ts +4 -0
  16. package/lib/math/tiers.js +52 -0
  17. package/lib/tx/retryTxSender.d.ts +14 -3
  18. package/lib/tx/retryTxSender.js +27 -22
  19. package/lib/tx/types.d.ts +3 -2
  20. package/lib/user.d.ts +10 -1
  21. package/lib/user.js +39 -8
  22. package/lib/userConfig.d.ts +4 -0
  23. package/lib/userStats.js +4 -1
  24. package/lib/userStatsConfig.d.ts +2 -0
  25. package/package.json +1 -1
  26. package/src/accounts/mockUserAccountSubscriber.ts +53 -0
  27. package/src/config.ts +2 -2
  28. package/src/constants/perpMarkets.ts +20 -0
  29. package/src/driftClient.ts +134 -21
  30. package/src/driftClientConfig.ts +4 -9
  31. package/src/idl/drift.json +1 -1
  32. package/src/index.ts +1 -0
  33. package/src/marinade/idl/idl.json +1962 -0
  34. package/src/marinade/index.ts +64 -0
  35. package/src/marinade/types.ts +3925 -0
  36. package/src/math/tiers.ts +44 -0
  37. package/src/tx/retryTxSender.ts +46 -36
  38. package/src/tx/types.ts +4 -2
  39. package/src/user.ts +63 -12
  40. package/src/userConfig.ts +5 -0
  41. package/src/userStats.ts +4 -0
  42. package/src/userStatsConfig.ts +3 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.31.1-beta.1
1
+ 2.31.1-beta.11
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import { DataAndSlot, UserAccountEvents, UserAccountSubscriber } from './types';
3
+ import { PublicKey } from '@solana/web3.js';
4
+ import StrictEventEmitter from 'strict-event-emitter-types';
5
+ import { EventEmitter } from 'events';
6
+ import { UserAccount } from '../types';
7
+ export declare class MockUserAccountSubscriber implements UserAccountSubscriber {
8
+ isSubscribed: boolean;
9
+ eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
10
+ userAccountPublicKey: PublicKey;
11
+ callbackId?: string;
12
+ errorCallbackId?: string;
13
+ user: DataAndSlot<UserAccount>;
14
+ constructor(userAccountPublicKey: PublicKey, data: UserAccount, slot: number);
15
+ subscribe(_userAccount?: UserAccount): Promise<boolean>;
16
+ addToAccountLoader(): Promise<void>;
17
+ fetch(): Promise<void>;
18
+ doesAccountExist(): boolean;
19
+ unsubscribe(): Promise<void>;
20
+ assertIsSubscribed(): void;
21
+ getUserAccountAndSlot(): DataAndSlot<UserAccount>;
22
+ updateData(userAccount: UserAccount, slot: number): void;
23
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockUserAccountSubscriber = void 0;
4
+ const events_1 = require("events");
5
+ class MockUserAccountSubscriber {
6
+ constructor(userAccountPublicKey, data, slot) {
7
+ this.isSubscribed = true;
8
+ this.eventEmitter = new events_1.EventEmitter();
9
+ this.userAccountPublicKey = userAccountPublicKey;
10
+ this.user = { data, slot };
11
+ }
12
+ async subscribe(_userAccount) {
13
+ return true;
14
+ }
15
+ async addToAccountLoader() { }
16
+ async fetch() { }
17
+ doesAccountExist() {
18
+ return this.user !== undefined;
19
+ }
20
+ async unsubscribe() { }
21
+ assertIsSubscribed() { }
22
+ getUserAccountAndSlot() {
23
+ return this.user;
24
+ }
25
+ updateData(userAccount, slot) {
26
+ this.user = { data: userAccount, slot };
27
+ this.eventEmitter.emit('userAccountUpdate', userAccount);
28
+ this.eventEmitter.emit('update');
29
+ }
30
+ }
31
+ exports.MockUserAccountSubscriber = MockUserAccountSubscriber;
@@ -124,6 +124,16 @@ exports.DevnetPerpMarkets = [
124
124
  launchTs: 1683125906000,
125
125
  oracleSource: __1.OracleSource.PYTH,
126
126
  },
127
+ {
128
+ fullName: 'RNDR',
129
+ category: ['Infra'],
130
+ symbol: 'RNDR-PERP',
131
+ baseAssetSymbol: 'RNDR',
132
+ marketIndex: 12,
133
+ oracle: new web3_js_1.PublicKey('C2QvUPBiU3fViSyqA4nZgGyYqLgYf9PRpd8B8oLoo48w'),
134
+ launchTs: 1683125906000,
135
+ oracleSource: __1.OracleSource.PYTH,
136
+ },
127
137
  ];
128
138
  exports.MainnetPerpMarkets = [
129
139
  {
@@ -246,6 +256,16 @@ exports.MainnetPerpMarkets = [
246
256
  launchTs: 1683125906000,
247
257
  oracleSource: __1.OracleSource.PYTH,
248
258
  },
259
+ {
260
+ fullName: 'RNDR',
261
+ category: ['Infra'],
262
+ symbol: 'RNDR-PERP',
263
+ baseAssetSymbol: 'RNDR',
264
+ marketIndex: 12,
265
+ oracle: new web3_js_1.PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
266
+ launchTs: 1683125906000,
267
+ oracleSource: __1.OracleSource.PYTH,
268
+ },
249
269
  ];
250
270
  exports.PerpMarkets = {
251
271
  devnet: exports.DevnetPerpMarkets,
@@ -14,6 +14,7 @@ import { User } from './user';
14
14
  import { UserSubscriptionConfig } from './userConfig';
15
15
  import { UserStats } from './userStats';
16
16
  import { JupiterClient, Route, SwapMode } from './jupiter/jupiterClient';
17
+ import { UserStatsSubscriptionConfig } from './userStatsConfig';
17
18
  type RemainingAccountParams = {
18
19
  userAccounts: UserAccount[];
19
20
  writablePerpMarketIndexes?: number[];
@@ -36,6 +37,7 @@ export declare class DriftClient {
36
37
  userStats?: UserStats;
37
38
  activeSubAccountId: number;
38
39
  userAccountSubscriptionConfig: UserSubscriptionConfig;
40
+ userStatsAccountSubscriptionConfig: UserStatsSubscriptionConfig;
39
41
  accountSubscriber: DriftClientAccountSubscriber;
40
42
  eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
41
43
  _isSubscribed: boolean;
@@ -49,6 +51,7 @@ export declare class DriftClient {
49
51
  authoritySubAccountMap?: Map<string, number[]>;
50
52
  skipLoadUsers?: boolean;
51
53
  txVersion: TransactionVersion;
54
+ txParams: TxParams;
52
55
  get isSubscribed(): boolean;
53
56
  set isSubscribed(val: boolean);
54
57
  constructor(config: DriftClientConfig);
@@ -121,6 +124,7 @@ export declare class DriftClient {
121
124
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
122
125
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
123
126
  getUser(subAccountId?: number, authority?: PublicKey): User;
127
+ hasUser(subAccountId?: number, authority?: PublicKey): boolean;
124
128
  getUsers(): User[];
125
129
  getUserStats(): UserStats;
126
130
  fetchReferrerNameAccount(name: string): Promise<ReferrerNameAccount | undefined>;
@@ -188,7 +192,7 @@ export declare class DriftClient {
188
192
  private getWrappedSolAccountCreationIxs;
189
193
  getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
190
194
  /**
191
- * Creates the Clearing House User account for a user, and deposits some initial collateral
195
+ * Creates the User account for a user, and deposits some initial collateral
192
196
  * @param amount
193
197
  * @param userTokenAccount
194
198
  * @param marketIndex
@@ -228,6 +232,7 @@ export declare class DriftClient {
228
232
  getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
229
233
  addPerpLpShares(amount: BN, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
230
234
  getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
235
+ getQuoteValuePerLpShare(marketIndex: number): BN;
231
236
  /**
232
237
  * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
233
238
  */
@@ -323,6 +328,12 @@ export declare class DriftClient {
323
328
  beginSwapIx: TransactionInstruction;
324
329
  endSwapIx: TransactionInstruction;
325
330
  }>;
331
+ stakeForMSOL({ amount }: {
332
+ amount: BN;
333
+ }): Promise<TxSigAndSlot>;
334
+ getStakeForMSOLIx({ amount, }: {
335
+ amount: BN;
336
+ }): Promise<TransactionInstruction[]>;
326
337
  triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams): Promise<TransactionSignature>;
327
338
  getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
328
339
  forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
@@ -52,6 +52,7 @@ const market_1 = require("./math/market");
52
52
  const fetch_1 = require("./accounts/fetch");
53
53
  const spotMarket_1 = require("./math/spotMarket");
54
54
  const memcmp_1 = require("./memcmp");
55
+ const marinade_1 = require("./marinade");
55
56
  /**
56
57
  * # DriftClient
57
58
  * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
@@ -64,7 +65,7 @@ class DriftClient {
64
65
  this._isSubscribed = val;
65
66
  }
66
67
  constructor(config) {
67
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
68
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
68
69
  this.users = new Map();
69
70
  this._isSubscribed = false;
70
71
  this.perpMarketLastSlotCache = new Map();
@@ -78,6 +79,10 @@ class DriftClient {
78
79
  this.activeSubAccountId = (_c = config.activeSubAccountId) !== null && _c !== void 0 ? _c : 0;
79
80
  this.skipLoadUsers = (_d = config.skipLoadUsers) !== null && _d !== void 0 ? _d : false;
80
81
  this.txVersion = (_e = config.txVersion) !== null && _e !== void 0 ? _e : 'legacy';
82
+ this.txParams = {
83
+ computeUnits: (_g = (_f = config.txParams) === null || _f === void 0 ? void 0 : _f.computeUnits) !== null && _g !== void 0 ? _g : 600000,
84
+ computeUnitsPrice: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnitsPrice) !== null && _j !== void 0 ? _j : 0,
85
+ };
81
86
  if (config.includeDelegates && config.subAccountIds) {
82
87
  throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
83
88
  }
@@ -92,16 +97,25 @@ class DriftClient {
92
97
  : config.subAccountIds
93
98
  ? new Map([[this.authority.toString(), config.subAccountIds]])
94
99
  : new Map();
95
- this.includeDelegates = (_f = config.includeDelegates) !== null && _f !== void 0 ? _f : false;
96
- this.userAccountSubscriptionConfig =
97
- ((_g = config.accountSubscription) === null || _g === void 0 ? void 0 : _g.type) === 'polling'
98
- ? {
99
- type: 'polling',
100
- accountLoader: config.accountSubscription.accountLoader,
101
- }
102
- : {
103
- type: 'websocket',
104
- };
100
+ this.includeDelegates = (_k = config.includeDelegates) !== null && _k !== void 0 ? _k : false;
101
+ if (((_l = config.accountSubscription) === null || _l === void 0 ? void 0 : _l.type) === 'polling') {
102
+ this.userAccountSubscriptionConfig = {
103
+ type: 'polling',
104
+ accountLoader: config.accountSubscription.accountLoader,
105
+ };
106
+ this.userStatsAccountSubscriptionConfig = {
107
+ type: 'polling',
108
+ accountLoader: config.accountSubscription.accountLoader,
109
+ };
110
+ }
111
+ else {
112
+ this.userAccountSubscriptionConfig = {
113
+ type: 'websocket',
114
+ };
115
+ this.userStatsAccountSubscriptionConfig = {
116
+ type: 'websocket',
117
+ };
118
+ }
105
119
  if (config.userStats) {
106
120
  this.userStats = new userStats_1.UserStats({
107
121
  driftClient: this,
@@ -116,14 +130,19 @@ class DriftClient {
116
130
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
117
131
  config.spotMarketIndexes === undefined &&
118
132
  config.oracleInfos === undefined;
119
- if (((_h = config.accountSubscription) === null || _h === void 0 ? void 0 : _h.type) === 'polling') {
120
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_j = config.perpMarketIndexes) !== null && _j !== void 0 ? _j : [], (_k = config.spotMarketIndexes) !== null && _k !== void 0 ? _k : [], (_l = config.oracleInfos) !== null && _l !== void 0 ? _l : [], noMarketsAndOraclesSpecified);
133
+ if (((_m = config.accountSubscription) === null || _m === void 0 ? void 0 : _m.type) === 'polling') {
134
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_o = config.perpMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.spotMarketIndexes) !== null && _p !== void 0 ? _p : [], (_q = config.oracleInfos) !== null && _q !== void 0 ? _q : [], noMarketsAndOraclesSpecified);
121
135
  }
122
136
  else {
123
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_m = config.perpMarketIndexes) !== null && _m !== void 0 ? _m : [], (_o = config.spotMarketIndexes) !== null && _o !== void 0 ? _o : [], (_p = config.oracleInfos) !== null && _p !== void 0 ? _p : [], noMarketsAndOraclesSpecified);
137
+ this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_r = config.perpMarketIndexes) !== null && _r !== void 0 ? _r : [], (_s = config.spotMarketIndexes) !== null && _s !== void 0 ? _s : [], (_t = config.oracleInfos) !== null && _t !== void 0 ? _t : [], noMarketsAndOraclesSpecified);
124
138
  }
125
139
  this.eventEmitter = this.accountSubscriber.eventEmitter;
126
- this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_q = config.txSenderConfig) === null || _q === void 0 ? void 0 : _q.timeout, (_r = config.txSenderConfig) === null || _r === void 0 ? void 0 : _r.retrySleep, (_s = config.txSenderConfig) === null || _s === void 0 ? void 0 : _s.additionalConnections);
140
+ this.txSender =
141
+ (_u = config.txSender) !== null && _u !== void 0 ? _u : new retryTxSender_1.RetryTxSender({
142
+ connection: this.connection,
143
+ wallet: this.wallet,
144
+ opts: this.opts,
145
+ });
127
146
  }
128
147
  getUserMapKey(subAccountId, authority) {
129
148
  return `${subAccountId}_${authority.toString()}`;
@@ -274,7 +293,7 @@ class DriftClient {
274
293
  const newProgram = new anchor_1.Program(drift_json_1.default, this.program.programId, newProvider);
275
294
  this.skipLoadUsers = false;
276
295
  // Update provider for txSender with new wallet details
277
- this.txSender.provider = newProvider;
296
+ this.txSender.wallet = newWallet;
278
297
  this.wallet = newWallet;
279
298
  this.provider = newProvider;
280
299
  this.program = newProgram;
@@ -304,7 +323,7 @@ class DriftClient {
304
323
  this.userStats = new userStats_1.UserStats({
305
324
  driftClient: this,
306
325
  userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
307
- accountSubscription: this.userAccountSubscriptionConfig,
326
+ accountSubscription: this.userStatsAccountSubscriptionConfig,
308
327
  });
309
328
  await this.userStats.subscribe();
310
329
  }
@@ -606,10 +625,16 @@ class DriftClient {
606
625
  authority = authority !== null && authority !== void 0 ? authority : this.authority;
607
626
  const userMapKey = this.getUserMapKey(subAccountId, authority);
608
627
  if (!this.users.has(userMapKey)) {
609
- throw new Error(`Clearing House has no user for user id ${userMapKey}`);
628
+ throw new Error(`DriftClient has no user for user id ${userMapKey}`);
610
629
  }
611
630
  return this.users.get(userMapKey);
612
631
  }
632
+ hasUser(subAccountId, authority) {
633
+ subAccountId = subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId;
634
+ authority = authority !== null && authority !== void 0 ? authority : this.authority;
635
+ const userMapKey = this.getUserMapKey(subAccountId, authority);
636
+ return this.users.has(userMapKey);
637
+ }
613
638
  getUsers() {
614
639
  // delegate users get added to the end
615
640
  return [...this.users.values()]
@@ -1064,7 +1089,7 @@ class DriftClient {
1064
1089
  return (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, associatedTokenAddress, this.wallet.publicKey, tokenMintAddress);
1065
1090
  }
1066
1091
  /**
1067
- * Creates the Clearing House User account for a user, and deposits some initial collateral
1092
+ * Creates the User account for a user, and deposits some initial collateral
1068
1093
  * @param amount
1069
1094
  * @param userTokenAccount
1070
1095
  * @param marketIndex
@@ -1349,6 +1374,19 @@ class DriftClient {
1349
1374
  remainingAccounts: remainingAccounts,
1350
1375
  });
1351
1376
  }
1377
+ getQuoteValuePerLpShare(marketIndex) {
1378
+ const perpMarketAccount = this.getPerpMarketAccount(marketIndex);
1379
+ const openBids = anchor_1.BN.max(perpMarketAccount.amm.baseAssetReserve.sub(perpMarketAccount.amm.minBaseAssetReserve), numericConstants_1.ZERO);
1380
+ const openAsks = anchor_1.BN.max(perpMarketAccount.amm.maxBaseAssetReserve.sub(perpMarketAccount.amm.baseAssetReserve), numericConstants_1.ZERO);
1381
+ const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
1382
+ const maxOpenBidsAsks = anchor_1.BN.max(openBids, openAsks);
1383
+ const quoteValuePerLpShare = maxOpenBidsAsks
1384
+ .mul(oraclePriceData.price)
1385
+ .mul(numericConstants_1.QUOTE_PRECISION)
1386
+ .div(numericConstants_1.PRICE_PRECISION)
1387
+ .div(perpMarketAccount.amm.sqrtK);
1388
+ return quoteValuePerLpShare;
1389
+ }
1352
1390
  /**
1353
1391
  * @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
1354
1392
  */
@@ -2075,6 +2113,39 @@ class DriftClient {
2075
2113
  });
2076
2114
  return { beginSwapIx, endSwapIx };
2077
2115
  }
2116
+ async stakeForMSOL({ amount }) {
2117
+ const ixs = await this.getStakeForMSOLIx({ amount });
2118
+ const tx = await this.buildTransaction(ixs);
2119
+ return this.sendTransaction(tx);
2120
+ }
2121
+ async getStakeForMSOLIx({ amount, }) {
2122
+ const wSOLMint = this.getSpotMarketAccount(1).mint;
2123
+ const mSOLAccount = await this.getAssociatedTokenAccount(2);
2124
+ const wSOLAccount = await this.getAssociatedTokenAccount(1, false);
2125
+ const wSOLAccountExists = await this.checkIfAccountExists(wSOLAccount);
2126
+ const closeWSOLIx = (0, spl_token_1.createCloseAccountInstruction)(wSOLAccount, this.wallet.publicKey, this.wallet.publicKey);
2127
+ const createWSOLIx = await this.createAssociatedTokenAccountIdempotentInstruction(wSOLAccount, this.wallet.publicKey, this.wallet.publicKey, wSOLMint);
2128
+ const { beginSwapIx, endSwapIx } = await this.getSwapIx({
2129
+ inMarketIndex: 1,
2130
+ outMarketIndex: 2,
2131
+ amountIn: amount,
2132
+ inTokenAccount: wSOLAccount,
2133
+ outTokenAccount: mSOLAccount,
2134
+ });
2135
+ const program = (0, marinade_1.getMarinadeFinanceProgram)(this.provider);
2136
+ const depositIx = await (0, marinade_1.getMarinadeDepositIx)({
2137
+ program,
2138
+ mSOLAccount: mSOLAccount,
2139
+ transferFrom: this.wallet.publicKey,
2140
+ amount,
2141
+ });
2142
+ const ixs = [];
2143
+ if (!wSOLAccountExists) {
2144
+ ixs.push(createWSOLIx);
2145
+ }
2146
+ ixs.push(beginSwapIx, closeWSOLIx, depositIx, createWSOLIx, endSwapIx);
2147
+ return ixs;
2148
+ }
2078
2149
  async triggerOrder(userAccountPublicKey, user, order, txParams) {
2079
2150
  const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams), [], this.opts);
2080
2151
  return txSig;
@@ -3049,13 +3120,13 @@ class DriftClient {
3049
3120
  async buildTransaction(instructions, txParams, txVersion, lookupTables) {
3050
3121
  var _a, _b;
3051
3122
  const allIx = [];
3052
- const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000;
3123
+ const computeUnits = (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : this.txParams.computeUnits;
3053
3124
  if (computeUnits !== 200000) {
3054
3125
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
3055
3126
  units: computeUnits,
3056
3127
  }));
3057
3128
  }
3058
- const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : 0;
3129
+ const computeUnitsPrice = (_b = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) !== null && _b !== void 0 ? _b : this.txParams.computeUnitsPrice;
3059
3130
  if (computeUnitsPrice !== 0) {
3060
3131
  allIx.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
3061
3132
  microLamports: computeUnitsPrice,
@@ -1,8 +1,9 @@
1
1
  import { ConfirmOptions, Connection, PublicKey, TransactionVersion } from '@solana/web3.js';
2
- import { IWallet } from './types';
2
+ import { IWallet, TxParams } from './types';
3
3
  import { OracleInfo } from './oracles/types';
4
4
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
5
5
  import { DriftEnv } from './config';
6
+ import { TxSender } from './tx/types';
6
7
  export type DriftClientConfig = {
7
8
  connection: Connection;
8
9
  wallet: IWallet;
@@ -10,7 +11,7 @@ export type DriftClientConfig = {
10
11
  programID?: PublicKey;
11
12
  accountSubscription?: DriftClientSubscriptionConfig;
12
13
  opts?: ConfirmOptions;
13
- txSenderConfig?: TxSenderConfig;
14
+ txSender?: TxSender;
14
15
  subAccountIds?: number[];
15
16
  activeSubAccountId?: number;
16
17
  perpMarketIndexes?: number[];
@@ -23,6 +24,7 @@ export type DriftClientConfig = {
23
24
  authoritySubAccountMap?: Map<string, number[]>;
24
25
  skipLoadUsers?: boolean;
25
26
  txVersion?: TransactionVersion;
27
+ txParams?: TxParams;
26
28
  };
27
29
  export type DriftClientSubscriptionConfig = {
28
30
  type: 'websocket';
@@ -30,10 +32,3 @@ export type DriftClientSubscriptionConfig = {
30
32
  type: 'polling';
31
33
  accountLoader: BulkAccountLoader;
32
34
  };
33
- type TxSenderConfig = {
34
- type: 'retry';
35
- timeout?: number;
36
- retrySleep?: number;
37
- additionalConnections?: Connection[];
38
- };
39
- export {};
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.31.1-beta.0",
2
+ "version": "2.31.1-beta.10",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export * from './math/orders';
45
45
  export * from './math/repeg';
46
46
  export * from './math/margin';
47
47
  export * from './math/insurance';
48
+ export * from './marinade';
48
49
  export * from './orderParams';
49
50
  export * from './slot/SlotSubscriber';
50
51
  export * from './wallet';
package/lib/index.js CHANGED
@@ -68,6 +68,7 @@ __exportStar(require("./math/orders"), exports);
68
68
  __exportStar(require("./math/repeg"), exports);
69
69
  __exportStar(require("./math/margin"), exports);
70
70
  __exportStar(require("./math/insurance"), exports);
71
+ __exportStar(require("./marinade"), exports);
71
72
  __exportStar(require("./orderParams"), exports);
72
73
  __exportStar(require("./slot/SlotSubscriber"), exports);
73
74
  __exportStar(require("./wallet"), exports);
@@ -0,0 +1,11 @@
1
+ import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
2
+ import { MarinadeFinance } from './types';
3
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
4
+ export declare function getMarinadeFinanceProgram(provider: AnchorProvider): Program<MarinadeFinance>;
5
+ export declare function getMarinadeDepositIx({ program, amount, mSOLAccount, transferFrom, }: {
6
+ amount: BN;
7
+ mSOLAccount: PublicKey;
8
+ transferFrom: PublicKey;
9
+ program: Program<MarinadeFinance>;
10
+ }): Promise<TransactionInstruction>;
11
+ export declare function getMarinadeMSolPrice(program: Program<MarinadeFinance>): Promise<number>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMarinadeMSolPrice = exports.getMarinadeDepositIx = exports.getMarinadeFinanceProgram = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const types_1 = require("./types");
6
+ const web3_js_1 = require("@solana/web3.js");
7
+ const spl_token_1 = require("@solana/spl-token");
8
+ const marinadeFinanceProgramId = new web3_js_1.PublicKey('MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD');
9
+ function getMarinadeFinanceProgram(provider) {
10
+ return new anchor_1.Program(types_1.IDL, marinadeFinanceProgramId, provider);
11
+ }
12
+ exports.getMarinadeFinanceProgram = getMarinadeFinanceProgram;
13
+ function getMarinadeDepositIx({ program, amount, mSOLAccount, transferFrom, }) {
14
+ return program.methods
15
+ .deposit(amount)
16
+ .accountsStrict({
17
+ reservePda: new web3_js_1.PublicKey('Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN'),
18
+ state: new web3_js_1.PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'),
19
+ msolMint: new web3_js_1.PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'),
20
+ msolMintAuthority: new web3_js_1.PublicKey('3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM'),
21
+ liqPoolMsolLegAuthority: new web3_js_1.PublicKey('EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL'),
22
+ liqPoolMsolLeg: new web3_js_1.PublicKey('7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE'),
23
+ liqPoolSolLegPda: new web3_js_1.PublicKey('UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q'),
24
+ mintTo: mSOLAccount,
25
+ transferFrom,
26
+ systemProgram: web3_js_1.SystemProgram.programId,
27
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
28
+ })
29
+ .instruction();
30
+ }
31
+ exports.getMarinadeDepositIx = getMarinadeDepositIx;
32
+ async function getMarinadeMSolPrice(program) {
33
+ const state = await program.account.state.fetch(new web3_js_1.PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'));
34
+ return state.msolPrice.toNumber() / 4294967296;
35
+ }
36
+ exports.getMarinadeMSolPrice = getMarinadeMSolPrice;