Skip to content

Commit 5d6ea07

Browse files
authored
[Feat] Add getPriorityFeeEstimate Method (#74)
* Add getPriorityFeeEstimate Method * Add getTokenAccounts Back In * Remove Whitespace
1 parent a145a68 commit 5d6ea07

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

src/RpcClient.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "@solana/web3.js";
1414
import axios from "axios";
1515
import { DAS } from "./types/das-types";
16+
import { GetPriorityFeeEstimateRequest, GetPriorityFeeEstimateResponse } from "./types";
1617

1718
export type SendAndConfirmTransactionResponse = {
1819
signature: TransactionSignature;
@@ -400,6 +401,31 @@ export class RpcClient {
400401
}
401402

402403
/**
404+
* Get priority fee estimate
405+
* @returns {Promise<GetPriorityFeeEstimateResponse>}
406+
* @throws {Error}
407+
*/
408+
async getPriorityFeeEstimate(
409+
params: GetPriorityFeeEstimateRequest
410+
): Promise<GetPriorityFeeEstimateResponse> {
411+
try {
412+
const url = `${this.connection.rpcEndpoint}`;
413+
const response = await axios.post(url, {
414+
jsonrpc: "2.0",
415+
id: this.id,
416+
method: "getPriorityFeeEstimate",
417+
params: [params],
418+
}, {
419+
headers: { "Content-Type": "application/json" },
420+
});
421+
422+
return response.data.result as GetPriorityFeeEstimateResponse;
423+
} catch (error) {
424+
throw new Error(`Error fetching priority fee estimate: ${error}`);
425+
}
426+
}
427+
428+
/**
403429
* Get information about all the edition NFTs for a specific master NFT
404430
* @returns {Promise<DAS.GetNftEditionsResponse>}
405431
* @throws {Error}
@@ -423,8 +449,8 @@ export class RpcClient {
423449
throw new Error(`Error in getNftEditions: ${error}`);
424450
}
425451
}
426-
427-
/**
452+
453+
/**
428454
* Get information about all token accounts for a specific mint or a specific owner
429455
* @returns {Promise<DAS.GetTokenAccountsResponse>}
430456
* @throws {Error}

src/types/enums.ts

+18
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,21 @@ export enum MintApiAuthority {
570570
MAINNET = "HnT5KVAywGgQDhmh6Usk4bxRg4RwKxCK4jmECyaDth5R",
571571
DEVNET = "2LbAtCJSaHqTnP9M5QSjvAMXk79RNLusFspFN5Ew67TC",
572572
}
573+
574+
export enum PriorityLevel {
575+
NONE = "NONE",
576+
LOW = "LOW",
577+
MEDIUM = "MEDIUM",
578+
HIGH = "HIGH",
579+
VERY_HIGH = "VERY_HIGH",
580+
UNSAFE_MAX = "UNSAFE_MAX",
581+
DEFAULT = "DEFAULT",
582+
}
583+
584+
export enum UiTransactionEncoding {
585+
Binary = "Binary",
586+
Base64 = "Base64",
587+
Base58 = "Base58",
588+
Json = "Json",
589+
JsonParsed = "JsonParsed",
590+
}

src/types/types.ts

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type {
99
TransactionContext,
1010
TxnStatus,
1111
AccountWebhookEncoding,
12+
PriorityLevel,
13+
UiTransactionEncoding,
1214
} from "./enums";
1315

1416
export type HeliusCluster = Omit<Cluster, "testnet">;
@@ -316,4 +318,31 @@ export interface FullRwaAccount {
316318
data_registry?: DataRegistryAccount;
317319
identity_registry?: IdentityRegistryAccount;
318320
policy_engine?: PolicyEngine;
321+
}
322+
323+
export interface GetPriorityFeeEstimateOptions {
324+
priorityLevel?: PriorityLevel;
325+
includeAllPriorityFeeLevels?: boolean;
326+
transactionEncoding?: UiTransactionEncoding;
327+
lookbackSlots?: number;
328+
}
329+
330+
export interface GetPriorityFeeEstimateRequest {
331+
transaction?: string;
332+
accountKeys?: string[];
333+
options?: GetPriorityFeeEstimateOptions;
334+
}
335+
336+
export interface MicroLamportPriorityFeeLevels {
337+
none: number;
338+
low: number;
339+
medium: number;
340+
high: number;
341+
veryHigh: number;
342+
unsafeMax: number;
343+
}
344+
345+
export interface GetPriorityFeeEstimateResponse {
346+
priorityFeeEstimate?: number;
347+
priorityFeeLevels?: MicroLamportPriorityFeeLevels;
319348
}

0 commit comments

Comments
 (0)