@drift-labs/sdk 2.76.0-beta.6 → 2.76.0-beta.8

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.76.0-beta.6
1
+ 2.76.0-beta.8
@@ -149,6 +149,8 @@ export declare class AdminClient extends DriftClient {
149
149
  getUpdatePerpMarketMaxImbalancesIx(perpMarketIndex: number, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionInstruction>;
150
150
  updatePerpMarketMaxOpenInterest(perpMarketIndex: number, maxOpenInterest: BN): Promise<TransactionSignature>;
151
151
  getUpdatePerpMarketMaxOpenInterestIx(perpMarketIndex: number, maxOpenInterest: BN): Promise<TransactionInstruction>;
152
+ updatePerpMarketNumberOfUser(perpMarketIndex: number, numberOfUsers?: number, numberOfUsersWithBase?: number): Promise<TransactionSignature>;
153
+ getUpdatePerpMarketNumberOfUsersIx(perpMarketIndex: number, numberOfUsers?: number, numberOfUsersWithBase?: number): Promise<TransactionInstruction>;
152
154
  updatePerpMarketFeeAdjustment(perpMarketIndex: number, feeAdjustment: number): Promise<TransactionSignature>;
153
155
  getUpdatePerpMarketFeeAdjustmentIx(perpMarketIndex: number, feeAdjustment: number): Promise<TransactionInstruction>;
154
156
  updateSpotMarketFeeAdjustment(perpMarketIndex: number, feeAdjustment: number): Promise<TransactionSignature>;
@@ -1340,6 +1340,23 @@ class AdminClient extends driftClient_1.DriftClient {
1340
1340
  },
1341
1341
  });
1342
1342
  }
1343
+ async updatePerpMarketNumberOfUser(perpMarketIndex, numberOfUsers, numberOfUsersWithBase) {
1344
+ const updatepPerpMarketFeeAdjustmentIx = await this.getUpdatePerpMarketNumberOfUsersIx(perpMarketIndex, numberOfUsers, numberOfUsersWithBase);
1345
+ const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);
1346
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1347
+ return txSig;
1348
+ }
1349
+ async getUpdatePerpMarketNumberOfUsersIx(perpMarketIndex, numberOfUsers, numberOfUsersWithBase) {
1350
+ return await this.program.instruction.updatePerpMarketNumberOfUsers(numberOfUsers, numberOfUsersWithBase, {
1351
+ accounts: {
1352
+ admin: this.isSubscribed
1353
+ ? this.getStateAccount().admin
1354
+ : this.wallet.publicKey,
1355
+ state: await this.getStatePublicKey(),
1356
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
1357
+ },
1358
+ });
1359
+ }
1343
1360
  async updatePerpMarketFeeAdjustment(perpMarketIndex, feeAdjustment) {
1344
1361
  const updatepPerpMarketFeeAdjustmentIx = await this.getUpdatePerpMarketFeeAdjustmentIx(perpMarketIndex, feeAdjustment);
1345
1362
  const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);
@@ -4758,6 +4758,40 @@
4758
4758
  }
4759
4759
  ]
4760
4760
  },
4761
+ {
4762
+ "name": "updatePerpMarketNumberOfUsers",
4763
+ "accounts": [
4764
+ {
4765
+ "name": "admin",
4766
+ "isMut": false,
4767
+ "isSigner": true
4768
+ },
4769
+ {
4770
+ "name": "state",
4771
+ "isMut": false,
4772
+ "isSigner": false
4773
+ },
4774
+ {
4775
+ "name": "perpMarket",
4776
+ "isMut": true,
4777
+ "isSigner": false
4778
+ }
4779
+ ],
4780
+ "args": [
4781
+ {
4782
+ "name": "numberOfUsers",
4783
+ "type": {
4784
+ "option": "u32"
4785
+ }
4786
+ },
4787
+ {
4788
+ "name": "numberOfUsersWithBase",
4789
+ "type": {
4790
+ "option": "u32"
4791
+ }
4792
+ }
4793
+ ]
4794
+ },
4761
4795
  {
4762
4796
  "name": "updatePerpMarketFeeAdjustment",
4763
4797
  "accounts": [
package/lib/index.d.ts CHANGED
@@ -75,6 +75,7 @@ export * from './tx/fastSingleTxSender';
75
75
  export * from './tx/retryTxSender';
76
76
  export * from './tx/whileValidTxSender';
77
77
  export * from './tx/priorityFeeCalculator';
78
+ export * from './tx/forwardOnlyTxSender';
78
79
  export * from './tx/types';
79
80
  export * from './util/computeUnits';
80
81
  export * from './util/tps';
package/lib/index.js CHANGED
@@ -98,6 +98,7 @@ __exportStar(require("./tx/fastSingleTxSender"), exports);
98
98
  __exportStar(require("./tx/retryTxSender"), exports);
99
99
  __exportStar(require("./tx/whileValidTxSender"), exports);
100
100
  __exportStar(require("./tx/priorityFeeCalculator"), exports);
101
+ __exportStar(require("./tx/forwardOnlyTxSender"), exports);
101
102
  __exportStar(require("./tx/types"), exports);
102
103
  __exportStar(require("./util/computeUnits"), exports);
103
104
  __exportStar(require("./util/tps"), exports);
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { ConfirmOptions, Connection } from '@solana/web3.js';
3
+ import { IWallet } from '../types';
4
+ import { BaseTxSender } from './baseTxSender';
5
+ import { ConfirmationStrategy, TxSigAndSlot } from './types';
6
+ type ResolveReference = {
7
+ resolve?: () => void;
8
+ };
9
+ export declare class ForwardOnlyTxSender extends BaseTxSender {
10
+ connection: Connection;
11
+ wallet: IWallet;
12
+ opts: ConfirmOptions;
13
+ timeout: number;
14
+ retrySleep: number;
15
+ additionalConnections: Connection[];
16
+ timoutCount: number;
17
+ constructor({ connection, wallet, opts, timeout, retrySleep, confirmationStrategy, additionalTxSenderCallbacks, }: {
18
+ connection: Connection;
19
+ wallet: IWallet;
20
+ opts?: ConfirmOptions;
21
+ timeout?: number;
22
+ retrySleep?: number;
23
+ confirmationStrategy?: ConfirmationStrategy;
24
+ additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
25
+ });
26
+ sleep(reference: ResolveReference): Promise<void>;
27
+ sendToAdditionalConnections(rawTx: Buffer | Uint8Array, _opts: ConfirmOptions): void;
28
+ sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
29
+ }
30
+ export {};
@@ -0,0 +1,84 @@
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.ForwardOnlyTxSender = void 0;
7
+ const anchor_1 = require("@coral-xyz/anchor");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const bs58_1 = __importDefault(require("bs58"));
10
+ const baseTxSender_1 = require("./baseTxSender");
11
+ const types_1 = require("./types");
12
+ const DEFAULT_TIMEOUT = 35000;
13
+ const DEFAULT_RETRY = 5000;
14
+ class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
15
+ constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], }) {
16
+ super({
17
+ connection,
18
+ wallet,
19
+ opts,
20
+ timeout,
21
+ additionalConnections: [],
22
+ confirmationStrategy,
23
+ additionalTxSenderCallbacks,
24
+ });
25
+ this.timoutCount = 0;
26
+ this.connection = connection;
27
+ this.wallet = wallet;
28
+ this.opts = opts;
29
+ this.timeout = timeout;
30
+ this.retrySleep = retrySleep;
31
+ this.additionalConnections = [];
32
+ }
33
+ async sleep(reference) {
34
+ return new Promise((resolve) => {
35
+ reference.resolve = resolve;
36
+ setTimeout(resolve, this.retrySleep);
37
+ });
38
+ }
39
+ sendToAdditionalConnections(rawTx, _opts) {
40
+ var _a;
41
+ (_a = this.additionalTxSenderCallbacks) === null || _a === void 0 ? void 0 : _a.map((callback) => {
42
+ callback(bs58_1.default.encode(rawTx));
43
+ });
44
+ }
45
+ async sendRawTransaction(rawTransaction, opts) {
46
+ const deserializedTx = web3_js_1.VersionedTransaction.deserialize(rawTransaction);
47
+ const txSig = deserializedTx.signatures[0];
48
+ const encodedTxSig = bs58_1.default.encode(txSig);
49
+ const startTime = this.getTimestamp();
50
+ this.sendToAdditionalConnections(rawTransaction, opts);
51
+ let done = false;
52
+ const resolveReference = {
53
+ resolve: undefined,
54
+ };
55
+ const stopWaiting = () => {
56
+ done = true;
57
+ if (resolveReference.resolve) {
58
+ resolveReference.resolve();
59
+ }
60
+ };
61
+ (async () => {
62
+ while (!done && this.getTimestamp() - startTime < this.timeout) {
63
+ await this.sleep(resolveReference);
64
+ if (!done) {
65
+ this.sendToAdditionalConnections(rawTransaction, opts);
66
+ }
67
+ }
68
+ })();
69
+ let slot;
70
+ try {
71
+ const result = await this.confirmTransaction(encodedTxSig, opts.commitment);
72
+ slot = result.context.slot;
73
+ // eslint-disable-next-line no-useless-catch
74
+ }
75
+ catch (e) {
76
+ throw e;
77
+ }
78
+ finally {
79
+ stopWaiting();
80
+ }
81
+ return { txSig: encodedTxSig, slot };
82
+ }
83
+ }
84
+ exports.ForwardOnlyTxSender = ForwardOnlyTxSender;
@@ -5,7 +5,7 @@ const types_1 = require("./types");
5
5
  const anchor_1 = require("@coral-xyz/anchor");
6
6
  const baseTxSender_1 = require("./baseTxSender");
7
7
  const DEFAULT_TIMEOUT = 35000;
8
- const DEFAULT_RETRY = 3000;
8
+ const DEFAULT_RETRY = 2000;
9
9
  class RetryTxSender extends baseTxSender_1.BaseTxSender {
10
10
  constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], }) {
11
11
  super({
@@ -8,7 +8,7 @@ const web3_js_1 = require("@solana/web3.js");
8
8
  const anchor_1 = require("@coral-xyz/anchor");
9
9
  const baseTxSender_1 = require("./baseTxSender");
10
10
  const bs58_1 = __importDefault(require("bs58"));
11
- const DEFAULT_RETRY = 3000;
11
+ const DEFAULT_RETRY = 2000;
12
12
  class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
13
13
  constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], }) {
14
14
  super({
@@ -44,7 +44,7 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
44
44
  signedTx = await this.wallet.signTransaction(tx);
45
45
  }
46
46
  // handle subclass-specific side effects
47
- const txSig = bs58_1.default.encode(((_a = tx.signatures[0]) === null || _a === void 0 ? void 0 : _a.signature) || tx.signatures[0]);
47
+ const txSig = bs58_1.default.encode(((_a = signedTx.signatures[0]) === null || _a === void 0 ? void 0 : _a.signature) || signedTx.signatures[0]);
48
48
  this.untilValid.set(txSig, latestBlockhash);
49
49
  return signedTx;
50
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.76.0-beta.6",
3
+ "version": "2.76.0-beta.8",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -2905,6 +2905,48 @@ export class AdminClient extends DriftClient {
2905
2905
  );
2906
2906
  }
2907
2907
 
2908
+ public async updatePerpMarketNumberOfUser(
2909
+ perpMarketIndex: number,
2910
+ numberOfUsers?: number,
2911
+ numberOfUsersWithBase?: number
2912
+ ): Promise<TransactionSignature> {
2913
+ const updatepPerpMarketFeeAdjustmentIx =
2914
+ await this.getUpdatePerpMarketNumberOfUsersIx(
2915
+ perpMarketIndex,
2916
+ numberOfUsers,
2917
+ numberOfUsersWithBase
2918
+ );
2919
+
2920
+ const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);
2921
+
2922
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2923
+
2924
+ return txSig;
2925
+ }
2926
+
2927
+ public async getUpdatePerpMarketNumberOfUsersIx(
2928
+ perpMarketIndex: number,
2929
+ numberOfUsers?: number,
2930
+ numberOfUsersWithBase?: number
2931
+ ): Promise<TransactionInstruction> {
2932
+ return await this.program.instruction.updatePerpMarketNumberOfUsers(
2933
+ numberOfUsers,
2934
+ numberOfUsersWithBase,
2935
+ {
2936
+ accounts: {
2937
+ admin: this.isSubscribed
2938
+ ? this.getStateAccount().admin
2939
+ : this.wallet.publicKey,
2940
+ state: await this.getStatePublicKey(),
2941
+ perpMarket: await getPerpMarketPublicKey(
2942
+ this.program.programId,
2943
+ perpMarketIndex
2944
+ ),
2945
+ },
2946
+ }
2947
+ );
2948
+ }
2949
+
2908
2950
  public async updatePerpMarketFeeAdjustment(
2909
2951
  perpMarketIndex: number,
2910
2952
  feeAdjustment: number
@@ -4758,6 +4758,40 @@
4758
4758
  }
4759
4759
  ]
4760
4760
  },
4761
+ {
4762
+ "name": "updatePerpMarketNumberOfUsers",
4763
+ "accounts": [
4764
+ {
4765
+ "name": "admin",
4766
+ "isMut": false,
4767
+ "isSigner": true
4768
+ },
4769
+ {
4770
+ "name": "state",
4771
+ "isMut": false,
4772
+ "isSigner": false
4773
+ },
4774
+ {
4775
+ "name": "perpMarket",
4776
+ "isMut": true,
4777
+ "isSigner": false
4778
+ }
4779
+ ],
4780
+ "args": [
4781
+ {
4782
+ "name": "numberOfUsers",
4783
+ "type": {
4784
+ "option": "u32"
4785
+ }
4786
+ },
4787
+ {
4788
+ "name": "numberOfUsersWithBase",
4789
+ "type": {
4790
+ "option": "u32"
4791
+ }
4792
+ }
4793
+ ]
4794
+ },
4761
4795
  {
4762
4796
  "name": "updatePerpMarketFeeAdjustment",
4763
4797
  "accounts": [
package/src/index.ts CHANGED
@@ -76,6 +76,7 @@ export * from './tx/fastSingleTxSender';
76
76
  export * from './tx/retryTxSender';
77
77
  export * from './tx/whileValidTxSender';
78
78
  export * from './tx/priorityFeeCalculator';
79
+ export * from './tx/forwardOnlyTxSender';
79
80
  export * from './tx/types';
80
81
  export * from './util/computeUnits';
81
82
  export * from './util/tps';
@@ -0,0 +1,127 @@
1
+ import { AnchorProvider } from '@coral-xyz/anchor';
2
+ import {
3
+ ConfirmOptions,
4
+ Connection,
5
+ VersionedTransaction,
6
+ } from '@solana/web3.js';
7
+ import bs58 from 'bs58';
8
+ import { IWallet } from '../types';
9
+ import { BaseTxSender } from './baseTxSender';
10
+ import { ConfirmationStrategy, TxSigAndSlot } from './types';
11
+
12
+ const DEFAULT_TIMEOUT = 35000;
13
+ const DEFAULT_RETRY = 5000;
14
+
15
+ type ResolveReference = {
16
+ resolve?: () => void;
17
+ };
18
+
19
+ export class ForwardOnlyTxSender extends BaseTxSender {
20
+ connection: Connection;
21
+ wallet: IWallet;
22
+ opts: ConfirmOptions;
23
+ timeout: number;
24
+ retrySleep: number;
25
+ additionalConnections: Connection[];
26
+ timoutCount = 0;
27
+
28
+ public constructor({
29
+ connection,
30
+ wallet,
31
+ opts = { ...AnchorProvider.defaultOptions(), maxRetries: 0 },
32
+ timeout = DEFAULT_TIMEOUT,
33
+ retrySleep = DEFAULT_RETRY,
34
+ confirmationStrategy = ConfirmationStrategy.Combo,
35
+ additionalTxSenderCallbacks = [],
36
+ }: {
37
+ connection: Connection;
38
+ wallet: IWallet;
39
+ opts?: ConfirmOptions;
40
+ timeout?: number;
41
+ retrySleep?: number;
42
+ confirmationStrategy?: ConfirmationStrategy;
43
+ additionalTxSenderCallbacks?: ((base58EncodedTx: string) => void)[];
44
+ }) {
45
+ super({
46
+ connection,
47
+ wallet,
48
+ opts,
49
+ timeout,
50
+ additionalConnections: [],
51
+ confirmationStrategy,
52
+ additionalTxSenderCallbacks,
53
+ });
54
+ this.connection = connection;
55
+ this.wallet = wallet;
56
+ this.opts = opts;
57
+ this.timeout = timeout;
58
+ this.retrySleep = retrySleep;
59
+ this.additionalConnections = [];
60
+ }
61
+
62
+ async sleep(reference: ResolveReference): Promise<void> {
63
+ return new Promise((resolve) => {
64
+ reference.resolve = resolve;
65
+ setTimeout(resolve, this.retrySleep);
66
+ });
67
+ }
68
+
69
+ sendToAdditionalConnections(
70
+ rawTx: Buffer | Uint8Array,
71
+ _opts: ConfirmOptions
72
+ ): void {
73
+ this.additionalTxSenderCallbacks?.map((callback) => {
74
+ callback(bs58.encode(rawTx));
75
+ });
76
+ }
77
+
78
+ async sendRawTransaction(
79
+ rawTransaction: Buffer | Uint8Array,
80
+ opts: ConfirmOptions
81
+ ): Promise<TxSigAndSlot> {
82
+ const deserializedTx = VersionedTransaction.deserialize(rawTransaction);
83
+
84
+ const txSig = deserializedTx.signatures[0];
85
+ const encodedTxSig = bs58.encode(txSig);
86
+
87
+ const startTime = this.getTimestamp();
88
+
89
+ this.sendToAdditionalConnections(rawTransaction, opts);
90
+
91
+ let done = false;
92
+ const resolveReference: ResolveReference = {
93
+ resolve: undefined,
94
+ };
95
+ const stopWaiting = () => {
96
+ done = true;
97
+ if (resolveReference.resolve) {
98
+ resolveReference.resolve();
99
+ }
100
+ };
101
+
102
+ (async () => {
103
+ while (!done && this.getTimestamp() - startTime < this.timeout) {
104
+ await this.sleep(resolveReference);
105
+ if (!done) {
106
+ this.sendToAdditionalConnections(rawTransaction, opts);
107
+ }
108
+ }
109
+ })();
110
+
111
+ let slot: number;
112
+ try {
113
+ const result = await this.confirmTransaction(
114
+ encodedTxSig,
115
+ opts.commitment
116
+ );
117
+ slot = result.context.slot;
118
+ // eslint-disable-next-line no-useless-catch
119
+ } catch (e) {
120
+ throw e;
121
+ } finally {
122
+ stopWaiting();
123
+ }
124
+
125
+ return { txSig: encodedTxSig, slot };
126
+ }
127
+ }
@@ -5,7 +5,7 @@ import { IWallet } from '../types';
5
5
  import { BaseTxSender } from './baseTxSender';
6
6
 
7
7
  const DEFAULT_TIMEOUT = 35000;
8
- const DEFAULT_RETRY = 3000;
8
+ const DEFAULT_RETRY = 2000;
9
9
 
10
10
  type ResolveReference = {
11
11
  resolve?: () => void;
@@ -14,7 +14,7 @@ import { IWallet } from '../types';
14
14
  import { BaseTxSender } from './baseTxSender';
15
15
  import bs58 from 'bs58';
16
16
 
17
- const DEFAULT_RETRY = 3000;
17
+ const DEFAULT_RETRY = 2000;
18
18
 
19
19
  type ResolveReference = {
20
20
  resolve?: () => void;
@@ -91,7 +91,9 @@ export class WhileValidTxSender extends BaseTxSender {
91
91
  }
92
92
 
93
93
  // handle subclass-specific side effects
94
- const txSig = bs58.encode(tx.signatures[0]?.signature || tx.signatures[0]);
94
+ const txSig = bs58.encode(
95
+ signedTx.signatures[0]?.signature || signedTx.signatures[0]
96
+ );
95
97
  this.untilValid.set(txSig, latestBlockhash);
96
98
 
97
99
  return signedTx;