@streamflow/common 8.0.0-alpha.p287.5172056 → 8.0.0
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/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/solana/index.cjs +23 -105
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +4 -27
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +4 -27
- package/dist/esm/solana/index.js +25 -103
- package/dist/esm/solana/index.js.map +1 -1
- package/package.json +3 -11
- package/dist/cjs/solana/rpc/index.cjs +0 -117
- package/dist/cjs/solana/rpc/index.cjs.map +0 -1
- package/dist/cjs/solana/rpc/index.d.cts +0 -89
- package/dist/esm/solana/rpc/index.d.ts +0 -89
- package/dist/esm/solana/rpc/index.js +0 -114
- package/dist/esm/solana/rpc/index.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../solana/rpc/priority-fee-estimate/percentile.ts","../../../../solana/deserialize-raw-transaction.ts","../../../../solana/rpc/priority-fee-estimate/calc-fee.ts","../../../../solana/rpc/priority-fee-estimate/general.ts","../../../../solana/public-key.ts"],"names":["Buffer","Transaction","VersionedTransaction","getPriorityFeeEstimate","getRecentPrioritizationFee","PublicKey","buildArgs"],"mappings":";;;;;;;;;;;;AAAA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACOO,SAAS,0BAA0B,YAAsB,EAAA;AAC9D,EAAA,MAAM,QAAWA,GAAAA,aAAAA,CAAO,IAAK,CAAA,YAAA,EAAc,QAAQ,CAAA;AACnD,EAAI,IAAA;AACF,IAAM,MAAA,EAAA,GAAKC,mBAAY,CAAA,IAAA,CAAK,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,UAAAA,GAAY,CAAC,YAAkD,KAAA;AACnE,EAAM,MAAA,aAAA,GACJ,wBAAwB,KAAQ,GAAA,YAAA,CAAa,IAAI,EAAE,CAAA,GAAI,yBAA0B,CAAA,YAAY,CAAE,CAAA,gBAAA;AACjG,EAAA,OAAO,CAAC,aAAa,CAAA;AACvB,CAAA","file":"index.cjs","sourcesContent":["import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\ntype RpcRequest = (methodName: string, args: Array<any> | ReadonlyArray<any>) => Promise<any>;\n\n/**\n * @category GetPriorityFeeEstimateOptions\n * @interface RecentPrioritizationFee\n * @property result - The result of the recent prioritization fees.\n * @property result.prioritizationFee - The prioritization fee.\n * @property result.slot - The slot of the prioritization fee.\n */\ninterface RecentPrioritizationFee {\n result: Array<{ prioritizationFee: number; slot: number }>;\n}\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));\n return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };\n};\n\n/**\n * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\" | \"percentile\">,\n): Promise<RecentPrioritizationFee> => {\n const { accountsOrTx, percentile = 5000 } = options;\n\n return (connection as unknown as { _rpcRequest: RpcRequest })._rpcRequest(\n \"getRecentPrioritizationFees\",\n buildArgs(accountsOrTx, percentile),\n ) as Promise<RecentPrioritizationFee>;\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string, percentile: number) => {\n const accountsArray =\n accountsOrTx instanceof Array\n ? accountsOrTx.map((a) => a.toString())\n : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());\n return [\n accountsArray,\n {\n percentile,\n },\n ] as const;\n};\n","import { Transaction, VersionedTransaction, type PublicKey } from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\ninterface TransactionAccountsProvider {\n accountKeys: PublicKey[];\n}\n\nexport function deserializeRawTransaction(serializedTx: string) {\n const txBuffer = Buffer.from(serializedTx, \"base64\");\n try {\n const tx = Transaction.from(txBuffer);\n const message = tx.compileMessage();\n const accounts = message.accountKeys;\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"legacy\",\n transaction: tx,\n accounts,\n writableAccounts,\n };\n } catch (error) {\n try {\n const vtx = VersionedTransaction.deserialize(txBuffer);\n const message = vtx.message;\n const accounts =\n \"staticAccountKeys\" in message\n ? message.staticAccountKeys\n : (message as unknown as TransactionAccountsProvider).accountKeys;\n\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"versioned\",\n transaction: vtx,\n accounts,\n writableAccounts,\n };\n } catch (vError) {\n throw new Error(\"Failed to deserialize transaction: \" + (vError instanceof Error ? vError.message : vError), {\n cause: vError,\n });\n }\n }\n}\n","export const resolveMedian = (values: number[]) => {\n if (values.length < 2) {\n return 0;\n }\n\n const sortedRates = [...values].sort((a, b) => a - b);\n const medianIndex = Math.floor(sortedRates.length / 2);\n const medianArrValue = sortedRates[medianIndex];\n const medianPrevValue = sortedRates[medianIndex - 1];\n\n if (medianPrevValue === undefined || medianArrValue === undefined) {\n return 0;\n }\n\n const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;\n\n return medianValue;\n};\n","import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport { pk } from \"../../public-key.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)\n * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));\n return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };\n};\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)\n * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\">,\n) => {\n return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs(options.accountsOrTx)[0] });\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string) => {\n const accountsArray =\n accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;\n return [accountsArray] as const;\n};\n","import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Converts a string or PublicKey to a PublicKey object.\n * @param address - The input address as a string or PublicKey.\n * @returns The PublicKey object.\n */\nexport const pk = (address: string | PublicKey): PublicKey => {\n return typeof address === \"string\" ? new PublicKey(address) : address;\n};\n"]}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as _solana_web3_js from '@solana/web3.js';
|
|
2
|
-
import { PublicKey, Connection } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @interface GetPriorityFeeEstimateOptions - The options for the priority fee estimate
|
|
6
|
-
*/
|
|
7
|
-
interface GetPriorityFeeEstimateOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The accounts or transaction to get the priority fee estimate for.
|
|
10
|
-
* `string` is a serialized base64 transaction.
|
|
11
|
-
* `array` is interpreted as an array of public keys in string format or as PublicKey instances (writable accounts).
|
|
12
|
-
*/
|
|
13
|
-
accountsOrTx: (string | PublicKey)[] | string;
|
|
14
|
-
/**
|
|
15
|
-
* The percentile of the priority fee estimate to return.
|
|
16
|
-
*
|
|
17
|
-
* examples: Triton RPC - [0, 10000]
|
|
18
|
-
* @default 5000
|
|
19
|
-
*/
|
|
20
|
-
percentile?: number;
|
|
21
|
-
/**
|
|
22
|
-
* The safe area increase to apply to the priority fee estimate.
|
|
23
|
-
* @default 0.05 = 5%
|
|
24
|
-
*/
|
|
25
|
-
safeAreaIncrease?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @category GetPriorityFeeEstimateOptions
|
|
30
|
-
* @interface RecentPrioritizationFee
|
|
31
|
-
* @property result - The result of the recent prioritization fees.
|
|
32
|
-
* @property result.prioritizationFee - The prioritization fee.
|
|
33
|
-
* @property result.slot - The slot of the prioritization fee.
|
|
34
|
-
*/
|
|
35
|
-
interface RecentPrioritizationFee {
|
|
36
|
-
result: Array<{
|
|
37
|
-
prioritizationFee: number;
|
|
38
|
-
slot: number;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]
|
|
43
|
-
* @param connection - The connection to the RPC
|
|
44
|
-
* @param options - The options for the RPC
|
|
45
|
-
* @returns The priority fee estimate
|
|
46
|
-
*/
|
|
47
|
-
declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
48
|
-
median: number;
|
|
49
|
-
data: RecentPrioritizationFee;
|
|
50
|
-
}>;
|
|
51
|
-
/**
|
|
52
|
-
* If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}
|
|
53
|
-
* @param connection - The connection to the RPC
|
|
54
|
-
* @param options - The options for the RPC
|
|
55
|
-
* @returns The priority fee estimate
|
|
56
|
-
*/
|
|
57
|
-
declare const getRecentPrioritizationFee$1: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx" | "percentile">) => Promise<RecentPrioritizationFee>;
|
|
58
|
-
|
|
59
|
-
declare namespace percentile {
|
|
60
|
-
export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
65
|
-
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
66
|
-
* @param connection - The connection to the RPC
|
|
67
|
-
* @param options - The options for the RPC
|
|
68
|
-
* @returns The priority fee estimate
|
|
69
|
-
*/
|
|
70
|
-
declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
71
|
-
median: number;
|
|
72
|
-
data: _solana_web3_js.RecentPrioritizationFees[];
|
|
73
|
-
}>;
|
|
74
|
-
/**
|
|
75
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
76
|
-
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
77
|
-
* @param connection - The connection to the RPC
|
|
78
|
-
* @param options - The options for the RPC
|
|
79
|
-
* @returns The priority fee estimate
|
|
80
|
-
*/
|
|
81
|
-
declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
|
|
82
|
-
|
|
83
|
-
declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
|
|
84
|
-
declare const general_getRecentPrioritizationFee: typeof getRecentPrioritizationFee;
|
|
85
|
-
declare namespace general {
|
|
86
|
-
export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { type GetPriorityFeeEstimateOptions, general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as _solana_web3_js from '@solana/web3.js';
|
|
2
|
-
import { PublicKey, Connection } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @interface GetPriorityFeeEstimateOptions - The options for the priority fee estimate
|
|
6
|
-
*/
|
|
7
|
-
interface GetPriorityFeeEstimateOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The accounts or transaction to get the priority fee estimate for.
|
|
10
|
-
* `string` is a serialized base64 transaction.
|
|
11
|
-
* `array` is interpreted as an array of public keys in string format or as PublicKey instances (writable accounts).
|
|
12
|
-
*/
|
|
13
|
-
accountsOrTx: (string | PublicKey)[] | string;
|
|
14
|
-
/**
|
|
15
|
-
* The percentile of the priority fee estimate to return.
|
|
16
|
-
*
|
|
17
|
-
* examples: Triton RPC - [0, 10000]
|
|
18
|
-
* @default 5000
|
|
19
|
-
*/
|
|
20
|
-
percentile?: number;
|
|
21
|
-
/**
|
|
22
|
-
* The safe area increase to apply to the priority fee estimate.
|
|
23
|
-
* @default 0.05 = 5%
|
|
24
|
-
*/
|
|
25
|
-
safeAreaIncrease?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @category GetPriorityFeeEstimateOptions
|
|
30
|
-
* @interface RecentPrioritizationFee
|
|
31
|
-
* @property result - The result of the recent prioritization fees.
|
|
32
|
-
* @property result.prioritizationFee - The prioritization fee.
|
|
33
|
-
* @property result.slot - The slot of the prioritization fee.
|
|
34
|
-
*/
|
|
35
|
-
interface RecentPrioritizationFee {
|
|
36
|
-
result: Array<{
|
|
37
|
-
prioritizationFee: number;
|
|
38
|
-
slot: number;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]
|
|
43
|
-
* @param connection - The connection to the RPC
|
|
44
|
-
* @param options - The options for the RPC
|
|
45
|
-
* @returns The priority fee estimate
|
|
46
|
-
*/
|
|
47
|
-
declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
48
|
-
median: number;
|
|
49
|
-
data: RecentPrioritizationFee;
|
|
50
|
-
}>;
|
|
51
|
-
/**
|
|
52
|
-
* If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}
|
|
53
|
-
* @param connection - The connection to the RPC
|
|
54
|
-
* @param options - The options for the RPC
|
|
55
|
-
* @returns The priority fee estimate
|
|
56
|
-
*/
|
|
57
|
-
declare const getRecentPrioritizationFee$1: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx" | "percentile">) => Promise<RecentPrioritizationFee>;
|
|
58
|
-
|
|
59
|
-
declare namespace percentile {
|
|
60
|
-
export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
65
|
-
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
66
|
-
* @param connection - The connection to the RPC
|
|
67
|
-
* @param options - The options for the RPC
|
|
68
|
-
* @returns The priority fee estimate
|
|
69
|
-
*/
|
|
70
|
-
declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
71
|
-
median: number;
|
|
72
|
-
data: _solana_web3_js.RecentPrioritizationFees[];
|
|
73
|
-
}>;
|
|
74
|
-
/**
|
|
75
|
-
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
76
|
-
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
77
|
-
* @param connection - The connection to the RPC
|
|
78
|
-
* @param options - The options for the RPC
|
|
79
|
-
* @returns The priority fee estimate
|
|
80
|
-
*/
|
|
81
|
-
declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
|
|
82
|
-
|
|
83
|
-
declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
|
|
84
|
-
declare const general_getRecentPrioritizationFee: typeof getRecentPrioritizationFee;
|
|
85
|
-
declare namespace general {
|
|
86
|
-
export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export { type GetPriorityFeeEstimateOptions, general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Transaction, VersionedTransaction, PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
11
|
-
var percentile_exports = {};
|
|
12
|
-
__export(percentile_exports, {
|
|
13
|
-
getPriorityFeeEstimate: () => getPriorityFeeEstimate,
|
|
14
|
-
getRecentPrioritizationFee: () => getRecentPrioritizationFee
|
|
15
|
-
});
|
|
16
|
-
function deserializeRawTransaction(serializedTx) {
|
|
17
|
-
const txBuffer = Buffer.from(serializedTx, "base64");
|
|
18
|
-
try {
|
|
19
|
-
const tx = Transaction.from(txBuffer);
|
|
20
|
-
const message = tx.compileMessage();
|
|
21
|
-
const accounts = message.accountKeys;
|
|
22
|
-
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
23
|
-
return {
|
|
24
|
-
type: "legacy",
|
|
25
|
-
transaction: tx,
|
|
26
|
-
accounts,
|
|
27
|
-
writableAccounts
|
|
28
|
-
};
|
|
29
|
-
} catch (error) {
|
|
30
|
-
try {
|
|
31
|
-
const vtx = VersionedTransaction.deserialize(txBuffer);
|
|
32
|
-
const message = vtx.message;
|
|
33
|
-
const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
|
|
34
|
-
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
35
|
-
return {
|
|
36
|
-
type: "versioned",
|
|
37
|
-
transaction: vtx,
|
|
38
|
-
accounts,
|
|
39
|
-
writableAccounts
|
|
40
|
-
};
|
|
41
|
-
} catch (vError) {
|
|
42
|
-
throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
|
|
43
|
-
cause: vError
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// solana/rpc/priority-fee-estimate/calc-fee.ts
|
|
50
|
-
var resolveMedian = (values) => {
|
|
51
|
-
if (values.length < 2) {
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
const sortedRates = [...values].sort((a, b) => a - b);
|
|
55
|
-
const medianIndex = Math.floor(sortedRates.length / 2);
|
|
56
|
-
const medianArrValue = sortedRates[medianIndex];
|
|
57
|
-
const medianPrevValue = sortedRates[medianIndex - 1];
|
|
58
|
-
if (medianPrevValue === void 0 || medianArrValue === void 0) {
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;
|
|
62
|
-
return medianValue;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
66
|
-
var getPriorityFeeEstimate = async (connection, options) => {
|
|
67
|
-
const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);
|
|
68
|
-
const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));
|
|
69
|
-
return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };
|
|
70
|
-
};
|
|
71
|
-
var getRecentPrioritizationFee = async (connection, options) => {
|
|
72
|
-
const { accountsOrTx, percentile = 5e3 } = options;
|
|
73
|
-
return connection._rpcRequest(
|
|
74
|
-
"getRecentPrioritizationFees",
|
|
75
|
-
buildArgs(accountsOrTx, percentile)
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
var buildArgs = (accountsOrTx, percentile) => {
|
|
79
|
-
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map((a) => a.toString()) : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());
|
|
80
|
-
return [
|
|
81
|
-
accountsArray,
|
|
82
|
-
{
|
|
83
|
-
percentile
|
|
84
|
-
}
|
|
85
|
-
];
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// solana/rpc/priority-fee-estimate/general.ts
|
|
89
|
-
var general_exports = {};
|
|
90
|
-
__export(general_exports, {
|
|
91
|
-
getPriorityFeeEstimate: () => getPriorityFeeEstimate2,
|
|
92
|
-
getRecentPrioritizationFee: () => getRecentPrioritizationFee2
|
|
93
|
-
});
|
|
94
|
-
var pk = (address) => {
|
|
95
|
-
return typeof address === "string" ? new PublicKey(address) : address;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// solana/rpc/priority-fee-estimate/general.ts
|
|
99
|
-
var getPriorityFeeEstimate2 = async (connection, options) => {
|
|
100
|
-
const recentPrioritizationFee = await getRecentPrioritizationFee2(connection, options);
|
|
101
|
-
const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));
|
|
102
|
-
return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };
|
|
103
|
-
};
|
|
104
|
-
var getRecentPrioritizationFee2 = async (connection, options) => {
|
|
105
|
-
return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs2(options.accountsOrTx)[0] });
|
|
106
|
-
};
|
|
107
|
-
var buildArgs2 = (accountsOrTx) => {
|
|
108
|
-
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;
|
|
109
|
-
return [accountsArray];
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export { general_exports as priorityFeeEstimation, percentile_exports as priorityFeeEstimationPercentile };
|
|
113
|
-
//# sourceMappingURL=index.js.map
|
|
114
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../solana/rpc/priority-fee-estimate/percentile.ts","../../../../solana/deserialize-raw-transaction.ts","../../../../solana/rpc/priority-fee-estimate/calc-fee.ts","../../../../solana/rpc/priority-fee-estimate/general.ts","../../../../solana/public-key.ts"],"names":["Buffer","getPriorityFeeEstimate","getRecentPrioritizationFee","buildArgs"],"mappings":";;;;;;;;;;AAAA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,sBAAA,EAAA,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IAAA,EAAM,uBAAwB,EAAA;AAChH,CAAA;AASO,IAAMA,2BAAAA,GAA6B,OACxC,UAAA,EACA,OACG,KAAA;AACH,EAAO,OAAA,UAAA,CAAW,2BAA4B,CAAA,EAAE,sBAAwBC,EAAAA,UAAAA,CAAU,QAAQ,YAAY,CAAA,CAAE,CAAC,CAAA,EAAG,CAAA;AAC9G,CAAA;AAEA,IAAMA,UAAAA,GAAY,CAAC,YAAkD,KAAA;AACnE,EAAM,MAAA,aAAA,GACJ,wBAAwB,KAAQ,GAAA,YAAA,CAAa,IAAI,EAAE,CAAA,GAAI,yBAA0B,CAAA,YAAY,CAAE,CAAA,gBAAA;AACjG,EAAA,OAAO,CAAC,aAAa,CAAA;AACvB,CAAA","file":"index.js","sourcesContent":["import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\ntype RpcRequest = (methodName: string, args: Array<any> | ReadonlyArray<any>) => Promise<any>;\n\n/**\n * @category GetPriorityFeeEstimateOptions\n * @interface RecentPrioritizationFee\n * @property result - The result of the recent prioritization fees.\n * @property result.prioritizationFee - The prioritization fee.\n * @property result.slot - The slot of the prioritization fee.\n */\ninterface RecentPrioritizationFee {\n result: Array<{ prioritizationFee: number; slot: number }>;\n}\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));\n return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };\n};\n\n/**\n * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\" | \"percentile\">,\n): Promise<RecentPrioritizationFee> => {\n const { accountsOrTx, percentile = 5000 } = options;\n\n return (connection as unknown as { _rpcRequest: RpcRequest })._rpcRequest(\n \"getRecentPrioritizationFees\",\n buildArgs(accountsOrTx, percentile),\n ) as Promise<RecentPrioritizationFee>;\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string, percentile: number) => {\n const accountsArray =\n accountsOrTx instanceof Array\n ? accountsOrTx.map((a) => a.toString())\n : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());\n return [\n accountsArray,\n {\n percentile,\n },\n ] as const;\n};\n","import { Transaction, VersionedTransaction, type PublicKey } from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\ninterface TransactionAccountsProvider {\n accountKeys: PublicKey[];\n}\n\nexport function deserializeRawTransaction(serializedTx: string) {\n const txBuffer = Buffer.from(serializedTx, \"base64\");\n try {\n const tx = Transaction.from(txBuffer);\n const message = tx.compileMessage();\n const accounts = message.accountKeys;\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"legacy\",\n transaction: tx,\n accounts,\n writableAccounts,\n };\n } catch (error) {\n try {\n const vtx = VersionedTransaction.deserialize(txBuffer);\n const message = vtx.message;\n const accounts =\n \"staticAccountKeys\" in message\n ? message.staticAccountKeys\n : (message as unknown as TransactionAccountsProvider).accountKeys;\n\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"versioned\",\n transaction: vtx,\n accounts,\n writableAccounts,\n };\n } catch (vError) {\n throw new Error(\"Failed to deserialize transaction: \" + (vError instanceof Error ? vError.message : vError), {\n cause: vError,\n });\n }\n }\n}\n","export const resolveMedian = (values: number[]) => {\n if (values.length < 2) {\n return 0;\n }\n\n const sortedRates = [...values].sort((a, b) => a - b);\n const medianIndex = Math.floor(sortedRates.length / 2);\n const medianArrValue = sortedRates[medianIndex];\n const medianPrevValue = sortedRates[medianIndex - 1];\n\n if (medianPrevValue === undefined || medianArrValue === undefined) {\n return 0;\n }\n\n const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;\n\n return medianValue;\n};\n","import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport { pk } from \"../../public-key.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)\n * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));\n return { median: Math.trunc(median * (1 + (options.safeAreaIncrease ?? 0.05))), data: recentPrioritizationFee };\n};\n\n/**\n * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)\n * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\">,\n) => {\n return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs(options.accountsOrTx)[0] });\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string) => {\n const accountsArray =\n accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;\n return [accountsArray] as const;\n};\n","import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Converts a string or PublicKey to a PublicKey object.\n * @param address - The input address as a string or PublicKey.\n * @returns The PublicKey object.\n */\nexport const pk = (address: string | PublicKey): PublicKey => {\n return typeof address === \"string\" ? new PublicKey(address) : address;\n};\n"]}
|