@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 +1 -1
- package/lib/priorityFee/driftPriorityFeeMethod.js +16 -2
- package/lib/priorityFee/heliusPriorityFeeMethod.js +24 -18
- package/lib/priorityFee/priorityFeeSubscriber.js +8 -6
- package/lib/priorityFee/solanaPriorityFeeMethod.js +15 -9
- package/lib/tx/whileValidTxSender.d.ts +1 -1
- package/lib/tx/whileValidTxSender.js +3 -2
- package/package.json +1 -1
- package/src/priorityFee/driftPriorityFeeMethod.ts +19 -6
- package/src/priorityFee/heliusPriorityFeeMethod.ts +24 -18
- package/src/priorityFee/priorityFeeSubscriber.ts +8 -6
- package/src/priorityFee/solanaPriorityFeeMethod.ts +17 -11
- package/src/tx/whileValidTxSender.ts +4 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.77.0-beta.
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
@@ -8,10 +8,23 @@ export async function fetchDriftPriorityFee(
|
|
|
8
8
|
marketTypes: string[],
|
|
9
9
|
marketIndexs: number[]
|
|
10
10
|
): Promise<DriftPriorityFeeResponse> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
110
|
-
|
|
109
|
+
if (samples.length > 0) {
|
|
110
|
+
this.latestPriorityFee = samples[0].prioritizationFee;
|
|
111
|
+
this.lastSlotSeen = samples[0].slot;
|
|
111
112
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
try {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const rpcJSONResponse: any = await connection._rpcRequest(
|
|
16
|
+
'getRecentPrioritizationFees',
|
|
17
|
+
[addresses]
|
|
18
|
+
);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const results: SolanaPriorityFeeResponse[] = rpcJSONResponse?.result;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
if (!results.length) return;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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:
|
|
112
|
+
recentBlockhash: blockhash ?? PLACEHOLDER_BLOCKHASH, // set blank and reset in sendVersionTransaction
|
|
111
113
|
instructions: ixs,
|
|
112
114
|
}).compileToV0Message(lookupTableAccounts);
|
|
113
115
|
|