@drift-labs/sdk 2.77.0-beta.1 → 2.77.0-beta.3

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.77.0-beta.1
1
+ 2.77.0-beta.3
@@ -6,7 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchDriftPriorityFee = void 0;
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
8
  async function fetchDriftPriorityFee(url, marketTypes, marketIndexs) {
9
- const response = await (0, node_fetch_1.default)(`${url}/batchPriorityFees?marketType=${marketTypes.join(',')}&marketIndex=${marketIndexs.join(',')}`);
10
- return await response.json();
9
+ try {
10
+ const response = await (0, node_fetch_1.default)(`${url}/batchPriorityFees?marketType=${marketTypes.join(',')}&marketIndex=${marketIndexs.join(',')}`);
11
+ if (!response.ok) {
12
+ throw new Error(`HTTP error! status: ${response.status}`);
13
+ }
14
+ return await response.json();
15
+ }
16
+ catch (err) {
17
+ if (err instanceof Error) {
18
+ console.error('Error fetching priority fees:', err.message);
19
+ }
20
+ else {
21
+ console.error('Unknown error fetching priority fees:', err);
22
+ }
23
+ }
24
+ return [];
11
25
  }
12
26
  exports.fetchDriftPriorityFee = fetchDriftPriorityFee;
@@ -17,24 +17,30 @@ var HeliusPriorityLevel;
17
17
  /// Fetches the priority fee from the Helius API
18
18
  /// https://docs.helius.dev/solana-rpc-nodes/alpha-priority-fee-api
19
19
  async function fetchHeliusPriorityFee(heliusRpcUrl, lookbackDistance, addresses) {
20
- const response = await (0, node_fetch_1.default)(heliusRpcUrl, {
21
- method: 'POST',
22
- headers: { 'Content-Type': 'application/json' },
23
- body: JSON.stringify({
24
- jsonrpc: '2.0',
25
- id: '1',
26
- method: 'getPriorityFeeEstimate',
27
- params: [
28
- {
29
- accountKeys: addresses,
30
- options: {
31
- includeAllPriorityFeeLevels: true,
32
- lookbackSlots: lookbackDistance,
20
+ try {
21
+ const response = await (0, node_fetch_1.default)(heliusRpcUrl, {
22
+ method: 'POST',
23
+ headers: { 'Content-Type': 'application/json' },
24
+ body: JSON.stringify({
25
+ jsonrpc: '2.0',
26
+ id: '1',
27
+ method: 'getPriorityFeeEstimate',
28
+ params: [
29
+ {
30
+ accountKeys: addresses,
31
+ options: {
32
+ includeAllPriorityFeeLevels: true,
33
+ lookbackSlots: lookbackDistance,
34
+ },
33
35
  },
34
- },
35
- ],
36
- }),
37
- });
38
- return await response.json();
36
+ ],
37
+ }),
38
+ });
39
+ return await response.json();
40
+ }
41
+ catch (err) {
42
+ console.error(err);
43
+ }
44
+ return undefined;
39
45
  }
40
46
  exports.fetchHeliusPriorityFee = fetchHeliusPriorityFee;
@@ -67,12 +67,14 @@ class PriorityFeeSubscriber {
67
67
  }
68
68
  async loadForSolana() {
69
69
  const samples = await (0, solanaPriorityFeeMethod_1.fetchSolanaPriorityFee)(this.connection, this.lookbackDistance, this.addresses);
70
- this.latestPriorityFee = samples[0].prioritizationFee;
71
- this.lastSlotSeen = samples[0].slot;
72
- this.lastAvgStrategyResult = this.averageStrategy.calculate(samples);
73
- this.lastMaxStrategyResult = this.maxStrategy.calculate(samples);
74
- if (this.customStrategy) {
75
- this.lastCustomStrategyResult = this.customStrategy.calculate(samples);
70
+ if (samples.length > 0) {
71
+ this.latestPriorityFee = samples[0].prioritizationFee;
72
+ this.lastSlotSeen = samples[0].slot;
73
+ this.lastAvgStrategyResult = this.averageStrategy.calculate(samples);
74
+ this.lastMaxStrategyResult = this.maxStrategy.calculate(samples);
75
+ if (this.customStrategy) {
76
+ this.lastCustomStrategyResult = this.customStrategy.calculate(samples);
77
+ }
76
78
  }
77
79
  }
78
80
  async loadForHelius() {
@@ -2,14 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchSolanaPriorityFee = void 0;
4
4
  async function fetchSolanaPriorityFee(connection, lookbackDistance, addresses) {
5
- // @ts-ignore
6
- const rpcJSONResponse = await connection._rpcRequest('getRecentPrioritizationFees', [addresses]);
7
- const results = rpcJSONResponse === null || rpcJSONResponse === void 0 ? void 0 : rpcJSONResponse.result;
8
- if (!results.length)
9
- return;
10
- // Sort and filter results based on the slot lookback setting
11
- const descResults = results.sort((a, b) => b.slot - a.slot);
12
- const cutoffSlot = descResults[0].slot - lookbackDistance;
13
- return descResults.filter((result) => result.slot >= cutoffSlot);
5
+ try {
6
+ // @ts-ignore
7
+ const rpcJSONResponse = await connection._rpcRequest('getRecentPrioritizationFees', [addresses]);
8
+ const results = rpcJSONResponse === null || rpcJSONResponse === void 0 ? void 0 : rpcJSONResponse.result;
9
+ if (!results.length)
10
+ return;
11
+ // Sort and filter results based on the slot lookback setting
12
+ const descResults = results.sort((a, b) => b.slot - a.slot);
13
+ const cutoffSlot = descResults[0].slot - lookbackDistance;
14
+ return descResults.filter((result) => result.slot >= cutoffSlot);
15
+ }
16
+ catch (err) {
17
+ console.error(err);
18
+ }
19
+ return [];
14
20
  }
15
21
  exports.fetchSolanaPriorityFee = fetchSolanaPriorityFee;
@@ -28,7 +28,7 @@ export declare class WhileValidTxSender extends BaseTxSender {
28
28
  });
29
29
  sleep(reference: ResolveReference): Promise<void>;
30
30
  prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions, preSigned?: boolean): Promise<Transaction>;
31
- getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], _additionalSigners?: Array<Signer>, _opts?: ConfirmOptions): Promise<VersionedTransaction>;
31
+ getVersionedTransaction(ixs: TransactionInstruction[], lookupTableAccounts: AddressLookupTableAccount[], _additionalSigners?: Array<Signer>, _opts?: ConfirmOptions, blockhash?: string): Promise<VersionedTransaction>;
32
32
  sendVersionedTransaction(tx: VersionedTransaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean, extraConfirmationOptions?: ExtraConfirmationOptions): Promise<TxSigAndSlot>;
33
33
  sendRawTransaction(rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions): Promise<TxSigAndSlot>;
34
34
  }
@@ -9,6 +9,7 @@ const anchor_1 = require("@coral-xyz/anchor");
9
9
  const baseTxSender_1 = require("./baseTxSender");
10
10
  const bs58_1 = __importDefault(require("bs58"));
11
11
  const DEFAULT_RETRY = 2000;
12
+ const PLACEHOLDER_BLOCKHASH = 'Fdum64WVeej6DeL85REV9NvfSxEJNPZ74DBk7A8kTrKP';
12
13
  class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
13
14
  constructor({ connection, wallet, opts = { ...anchor_1.AnchorProvider.defaultOptions(), maxRetries: 0 }, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), additionalTxSenderCallbacks = [], }) {
14
15
  super({
@@ -48,10 +49,10 @@ class WhileValidTxSender extends baseTxSender_1.BaseTxSender {
48
49
  this.untilValid.set(txSig, latestBlockhash);
49
50
  return signedTx;
50
51
  }
51
- async getVersionedTransaction(ixs, lookupTableAccounts, _additionalSigners, _opts) {
52
+ async getVersionedTransaction(ixs, lookupTableAccounts, _additionalSigners, _opts, blockhash) {
52
53
  const message = new web3_js_1.TransactionMessage({
53
54
  payerKey: this.wallet.publicKey,
54
- recentBlockhash: '',
55
+ recentBlockhash: blockhash !== null && blockhash !== void 0 ? blockhash : PLACEHOLDER_BLOCKHASH,
55
56
  instructions: ixs,
56
57
  }).compileToV0Message(lookupTableAccounts);
57
58
  const tx = new web3_js_1.VersionedTransaction(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.77.0-beta.1",
3
+ "version": "2.77.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -8,10 +8,23 @@ export async function fetchDriftPriorityFee(
8
8
  marketTypes: string[],
9
9
  marketIndexs: number[]
10
10
  ): Promise<DriftPriorityFeeResponse> {
11
- const response = await fetch(
12
- `${url}/batchPriorityFees?marketType=${marketTypes.join(
13
- ','
14
- )}&marketIndex=${marketIndexs.join(',')}`
15
- );
16
- return await response.json();
11
+ try {
12
+ const response = await fetch(
13
+ `${url}/batchPriorityFees?marketType=${marketTypes.join(
14
+ ','
15
+ )}&marketIndex=${marketIndexs.join(',')}`
16
+ );
17
+ if (!response.ok) {
18
+ throw new Error(`HTTP error! status: ${response.status}`);
19
+ }
20
+ return await response.json();
21
+ } catch (err) {
22
+ if (err instanceof Error) {
23
+ console.error('Error fetching priority fees:', err.message);
24
+ } else {
25
+ console.error('Unknown error fetching priority fees:', err);
26
+ }
27
+ }
28
+
29
+ return [];
17
30
  }
@@ -29,23 +29,29 @@ export async function fetchHeliusPriorityFee(
29
29
  lookbackDistance: number,
30
30
  addresses: string[]
31
31
  ): Promise<HeliusPriorityFeeResponse> {
32
- const response = await fetch(heliusRpcUrl, {
33
- method: 'POST',
34
- headers: { 'Content-Type': 'application/json' },
35
- body: JSON.stringify({
36
- jsonrpc: '2.0',
37
- id: '1',
38
- method: 'getPriorityFeeEstimate',
39
- params: [
40
- {
41
- accountKeys: addresses,
42
- options: {
43
- includeAllPriorityFeeLevels: true,
44
- lookbackSlots: lookbackDistance,
32
+ try {
33
+ const response = await fetch(heliusRpcUrl, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ body: JSON.stringify({
37
+ jsonrpc: '2.0',
38
+ id: '1',
39
+ method: 'getPriorityFeeEstimate',
40
+ params: [
41
+ {
42
+ accountKeys: addresses,
43
+ options: {
44
+ includeAllPriorityFeeLevels: true,
45
+ lookbackSlots: lookbackDistance,
46
+ },
45
47
  },
46
- },
47
- ],
48
- }),
49
- });
50
- return await response.json();
48
+ ],
49
+ }),
50
+ });
51
+ return await response.json();
52
+ } catch (err) {
53
+ console.error(err);
54
+ }
55
+
56
+ return undefined;
51
57
  }
@@ -106,13 +106,15 @@ export class PriorityFeeSubscriber {
106
106
  this.lookbackDistance,
107
107
  this.addresses
108
108
  );
109
- this.latestPriorityFee = samples[0].prioritizationFee;
110
- this.lastSlotSeen = samples[0].slot;
109
+ if (samples.length > 0) {
110
+ this.latestPriorityFee = samples[0].prioritizationFee;
111
+ this.lastSlotSeen = samples[0].slot;
111
112
 
112
- this.lastAvgStrategyResult = this.averageStrategy.calculate(samples);
113
- this.lastMaxStrategyResult = this.maxStrategy.calculate(samples);
114
- if (this.customStrategy) {
115
- this.lastCustomStrategyResult = this.customStrategy.calculate(samples);
113
+ this.lastAvgStrategyResult = this.averageStrategy.calculate(samples);
114
+ this.lastMaxStrategyResult = this.maxStrategy.calculate(samples);
115
+ if (this.customStrategy) {
116
+ this.lastCustomStrategyResult = this.customStrategy.calculate(samples);
117
+ }
116
118
  }
117
119
  }
118
120
 
@@ -10,19 +10,25 @@ export async function fetchSolanaPriorityFee(
10
10
  lookbackDistance: number,
11
11
  addresses: string[]
12
12
  ): Promise<SolanaPriorityFeeResponse[]> {
13
- // @ts-ignore
14
- const rpcJSONResponse: any = await connection._rpcRequest(
15
- 'getRecentPrioritizationFees',
16
- [addresses]
17
- );
13
+ try {
14
+ // @ts-ignore
15
+ const rpcJSONResponse: any = await connection._rpcRequest(
16
+ 'getRecentPrioritizationFees',
17
+ [addresses]
18
+ );
18
19
 
19
- const results: SolanaPriorityFeeResponse[] = rpcJSONResponse?.result;
20
+ const results: SolanaPriorityFeeResponse[] = rpcJSONResponse?.result;
20
21
 
21
- if (!results.length) return;
22
+ if (!results.length) return;
22
23
 
23
- // Sort and filter results based on the slot lookback setting
24
- const descResults = results.sort((a, b) => b.slot - a.slot);
25
- const cutoffSlot = descResults[0].slot - lookbackDistance;
24
+ // Sort and filter results based on the slot lookback setting
25
+ const descResults = results.sort((a, b) => b.slot - a.slot);
26
+ const cutoffSlot = descResults[0].slot - lookbackDistance;
26
27
 
27
- return descResults.filter((result) => result.slot >= cutoffSlot);
28
+ return descResults.filter((result) => result.slot >= cutoffSlot);
29
+ } catch (err) {
30
+ console.error(err);
31
+ }
32
+
33
+ return [];
28
34
  }
@@ -15,6 +15,7 @@ import { BaseTxSender } from './baseTxSender';
15
15
  import bs58 from 'bs58';
16
16
 
17
17
  const DEFAULT_RETRY = 2000;
18
+ const PLACEHOLDER_BLOCKHASH = 'Fdum64WVeej6DeL85REV9NvfSxEJNPZ74DBk7A8kTrKP';
18
19
 
19
20
  type ResolveReference = {
20
21
  resolve?: () => void;
@@ -103,11 +104,12 @@ export class WhileValidTxSender extends BaseTxSender {
103
104
  ixs: TransactionInstruction[],
104
105
  lookupTableAccounts: AddressLookupTableAccount[],
105
106
  _additionalSigners?: Array<Signer>,
106
- _opts?: ConfirmOptions
107
+ _opts?: ConfirmOptions,
108
+ blockhash?: string
107
109
  ): Promise<VersionedTransaction> {
108
110
  const message = new TransactionMessage({
109
111
  payerKey: this.wallet.publicKey,
110
- recentBlockhash: '', // set blank and reset in sendVersionTransaction
112
+ recentBlockhash: blockhash ?? PLACEHOLDER_BLOCKHASH, // set blank and reset in sendVersionTransaction
111
113
  instructions: ixs,
112
114
  }).compileToV0Message(lookupTableAccounts);
113
115