@streamflow/common 8.0.0-alpha.p284.726ba98 → 8.0.0-alpha.p287.84ff30f
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/solana/index.cjs +105 -23
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +23 -42
- package/dist/cjs/solana/rpc/index.cjs +117 -0
- package/dist/cjs/solana/rpc/index.cjs.map +1 -0
- package/dist/cjs/solana/rpc/index.d.cts +40 -0
- package/dist/cjs/types-DGCX8JLm.d.cts +73 -0
- package/dist/esm/solana/index.d.ts +23 -42
- package/dist/esm/solana/index.js +103 -25
- package/dist/esm/solana/index.js.map +1 -1
- package/dist/esm/solana/rpc/index.d.ts +40 -0
- package/dist/esm/solana/rpc/index.js +114 -0
- package/dist/esm/solana/rpc/index.js.map +1 -0
- package/dist/esm/types-DGCX8JLm.d.ts +73 -0
- package/package.json +11 -3
|
@@ -0,0 +1 @@
|
|
|
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,MAAA,sBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACOO,SAAS,0BAA0B,YAAsB,EAAA;AAC9D,EAAA,MAAM,QAAWA,GAAAA,MAAAA,CAAO,IAAK,CAAA,YAAA,EAAc,QAAQ,CAAA;AACnD,EAAI,IAAA;AACF,IAAM,MAAA,EAAA,GAAK,WAAY,CAAA,IAAA,CAAK,QAAQ,CAAA;AACpC,IAAM,MAAA,OAAA,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A,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>;\ninterface RecentPrioritizationFee {\n result: Array<{ prioritizationFee: number; slot: number }>;\n}\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: 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\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: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };\n};\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"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PublicKey, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment } from '@solana/web3.js';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
3
|
+
|
|
4
|
+
type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
|
|
5
|
+
interface ITransactionSolanaExt {
|
|
6
|
+
computePrice?: number | ComputePriceEstimate;
|
|
7
|
+
computeLimit?: number;
|
|
8
|
+
}
|
|
9
|
+
interface IInteractSolanaExt extends ITransactionSolanaExt {
|
|
10
|
+
invoker: {
|
|
11
|
+
publicKey: string | PublicKey | null;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface Account {
|
|
15
|
+
pubkey: PublicKey;
|
|
16
|
+
account: AccountInfo<Buffer>;
|
|
17
|
+
}
|
|
18
|
+
interface CheckAssociatedTokenAccountsData {
|
|
19
|
+
sender: PublicKey;
|
|
20
|
+
recipient: PublicKey;
|
|
21
|
+
partner: PublicKey;
|
|
22
|
+
streamflowTreasury: PublicKey;
|
|
23
|
+
mint: PublicKey;
|
|
24
|
+
}
|
|
25
|
+
interface AtaParams {
|
|
26
|
+
mint: PublicKey;
|
|
27
|
+
owner: PublicKey;
|
|
28
|
+
programId?: PublicKey;
|
|
29
|
+
}
|
|
30
|
+
interface ConfirmationParams {
|
|
31
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
32
|
+
context: Context;
|
|
33
|
+
commitment?: Commitment;
|
|
34
|
+
}
|
|
35
|
+
interface ThrottleParams {
|
|
36
|
+
sendRate?: number;
|
|
37
|
+
sendThrottler?: PQueue;
|
|
38
|
+
waitBeforeConfirming?: number | undefined;
|
|
39
|
+
}
|
|
40
|
+
interface IProgramAccount<T> {
|
|
41
|
+
publicKey: PublicKey;
|
|
42
|
+
account: T;
|
|
43
|
+
}
|
|
44
|
+
declare class TransactionFailedError extends Error {
|
|
45
|
+
constructor(m: string);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @interface GetPriorityFeeEstimateOptions - The options for the priority fee estimate
|
|
49
|
+
* @property accountsOrTx - The accounts or transaction to get the priority fee estimate for.
|
|
50
|
+
* @property percentile - The percentile of the priority fee estimate to return.
|
|
51
|
+
* @property safeAreaIncrease - The safe area increase to apply to the priority fee estimate.
|
|
52
|
+
*/
|
|
53
|
+
interface GetPriorityFeeEstimateOptions {
|
|
54
|
+
/**
|
|
55
|
+
* The accounts or transaction to get the priority fee estimate for.
|
|
56
|
+
* String is a serialized base64 transaction.
|
|
57
|
+
* Array is interpreted as an array of public keys in string format or as PublicKey instances.
|
|
58
|
+
*/
|
|
59
|
+
accountsOrTx: (string | PublicKey)[] | string;
|
|
60
|
+
/**
|
|
61
|
+
* The percentile of the priority fee estimate to return.
|
|
62
|
+
* [0, 10000] for Triton RPC signature
|
|
63
|
+
* Default: 5000
|
|
64
|
+
*/
|
|
65
|
+
percentile?: number;
|
|
66
|
+
/**
|
|
67
|
+
* The safe area increase to apply to the priority fee estimate.
|
|
68
|
+
* Default: 0.05 = 5%
|
|
69
|
+
*/
|
|
70
|
+
safeAreaIncrease?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { type Account as A, type ConfirmationParams as C, type GetPriorityFeeEstimateOptions as G, type ITransactionSolanaExt as I, type ThrottleParams as T, type AtaParams as a, type ComputePriceEstimate as b, type IInteractSolanaExt as c, type CheckAssociatedTokenAccountsData as d, type IProgramAccount as e, TransactionFailedError as f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.p287.84ff30f",
|
|
4
4
|
"description": "Common utilities and types used by streamflow packages.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
"import": "./dist/esm/solana/index.js",
|
|
25
25
|
"require": "./dist/cjs/solana/index.cjs"
|
|
26
26
|
},
|
|
27
|
+
"./solana/rpc": {
|
|
28
|
+
"types": {
|
|
29
|
+
"import": "./dist/esm/solana/rpc/index.d.ts",
|
|
30
|
+
"require": "./dist/cjs/solana/rpc/index.d.cts"
|
|
31
|
+
},
|
|
32
|
+
"import": "./dist/esm/solana/rpc/index.js",
|
|
33
|
+
"require": "./dist/cjs/solana/rpc/index.cjs"
|
|
34
|
+
},
|
|
27
35
|
"./package.json": "./package.json"
|
|
28
36
|
},
|
|
29
37
|
"scripts": {
|
|
@@ -35,9 +43,9 @@
|
|
|
35
43
|
"lint-config": "eslint --print-config",
|
|
36
44
|
"prepublishOnly": "pnpm run lint && pnpm run build"
|
|
37
45
|
},
|
|
38
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "02c7181d9a9197123500a2ac2ce9292a9962d342",
|
|
39
47
|
"devDependencies": {
|
|
40
|
-
"@streamflow/eslint-config": "8.0.0-alpha.
|
|
48
|
+
"@streamflow/eslint-config": "8.0.0-alpha.p287.84ff30f",
|
|
41
49
|
"@types/bn.js": "5.1.1",
|
|
42
50
|
"typescript": "^5.6.3"
|
|
43
51
|
},
|