@streamflow/common 8.0.1 → 8.0.2-alpha.p287.a3616ff
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 +149 -32
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +75 -17
- package/dist/cjs/solana/rpc/index.cjs +137 -0
- package/dist/cjs/solana/rpc/index.cjs.map +1 -0
- package/dist/cjs/solana/rpc/index.d.cts +113 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +75 -17
- package/dist/esm/solana/index.js +145 -34
- package/dist/esm/solana/index.js.map +1 -1
- package/dist/esm/solana/rpc/index.d.ts +113 -0
- package/dist/esm/solana/rpc/index.js +133 -0
- package/dist/esm/solana/rpc/index.js.map +1 -0
- package/package.json +11 -3
|
@@ -0,0 +1,133 @@
|
|
|
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/consume-limit-estimate/estimate.ts
|
|
11
|
+
var estimateConsumeLimit = async (connection, tx, options = {}) => {
|
|
12
|
+
const { increaseFactor = 0.05 } = options;
|
|
13
|
+
const simulationResults = await connection.simulateTransaction(tx, {
|
|
14
|
+
sigVerify: false,
|
|
15
|
+
replaceRecentBlockhash: true
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
unitsConsumed: simulationResults.value.unitsConsumed ? Math.ceil(simulationResults.value.unitsConsumed * (1 + increaseFactor)) : simulationResults.value.unitsConsumed,
|
|
19
|
+
data: simulationResults
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
24
|
+
var percentile_exports = {};
|
|
25
|
+
__export(percentile_exports, {
|
|
26
|
+
getPriorityFeeEstimate: () => getPriorityFeeEstimate,
|
|
27
|
+
getRecentPrioritizationFee: () => getRecentPrioritizationFee
|
|
28
|
+
});
|
|
29
|
+
function deserializeRawTransaction(serializedTx) {
|
|
30
|
+
const txBuffer = Buffer.from(serializedTx, "base64");
|
|
31
|
+
try {
|
|
32
|
+
const tx = Transaction.from(txBuffer);
|
|
33
|
+
return resolveTransactionAccounts(tx);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
const vtx = VersionedTransaction.deserialize(txBuffer);
|
|
37
|
+
return resolveTransactionAccounts(vtx);
|
|
38
|
+
} catch (vError) {
|
|
39
|
+
throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
|
|
40
|
+
cause: vError
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var resolveTransactionAccounts = (tx) => {
|
|
46
|
+
if (tx instanceof Transaction) {
|
|
47
|
+
const message2 = tx.compileMessage();
|
|
48
|
+
const accounts2 = message2.accountKeys;
|
|
49
|
+
const writableAccounts2 = accounts2.filter((_, idx) => message2.isAccountWritable(idx));
|
|
50
|
+
return {
|
|
51
|
+
type: "legacy",
|
|
52
|
+
transaction: tx,
|
|
53
|
+
accounts: accounts2,
|
|
54
|
+
writableAccounts: writableAccounts2
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const message = tx.message;
|
|
58
|
+
const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
|
|
59
|
+
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
60
|
+
return {
|
|
61
|
+
type: "versioned",
|
|
62
|
+
transaction: tx,
|
|
63
|
+
accounts,
|
|
64
|
+
writableAccounts
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// solana/rpc/priority-fee-estimate/calc-fee.ts
|
|
69
|
+
var resolveMedian = (values) => {
|
|
70
|
+
if (values.length < 2) {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
const sortedRates = [...values].sort((a, b) => a - b);
|
|
74
|
+
const medianIndex = Math.floor(sortedRates.length / 2);
|
|
75
|
+
const medianArrValue = sortedRates[medianIndex];
|
|
76
|
+
const medianPrevValue = sortedRates[medianIndex - 1];
|
|
77
|
+
if (medianPrevValue === void 0 || medianArrValue === void 0) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;
|
|
81
|
+
return medianValue;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
85
|
+
var getPriorityFeeEstimate = async (connection, options) => {
|
|
86
|
+
const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);
|
|
87
|
+
const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));
|
|
88
|
+
return { median: Math.ceil(median * (1 + (options.increaseFactor ?? 0.05))), data: recentPrioritizationFee };
|
|
89
|
+
};
|
|
90
|
+
var getRecentPrioritizationFee = async (connection, options) => {
|
|
91
|
+
const { accountsOrTx, percentile = 5e3 } = options;
|
|
92
|
+
return connection._rpcRequest(
|
|
93
|
+
"getRecentPrioritizationFees",
|
|
94
|
+
buildArgs(accountsOrTx, percentile)
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
var buildArgs = (accountsOrTx, percentile) => {
|
|
98
|
+
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map((a) => a.toString()) : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());
|
|
99
|
+
return [
|
|
100
|
+
accountsArray,
|
|
101
|
+
{
|
|
102
|
+
percentile
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// solana/rpc/priority-fee-estimate/general.ts
|
|
108
|
+
var general_exports = {};
|
|
109
|
+
__export(general_exports, {
|
|
110
|
+
getPriorityFeeEstimate: () => getPriorityFeeEstimate2,
|
|
111
|
+
getRecentPrioritizationFee: () => getRecentPrioritizationFee2
|
|
112
|
+
});
|
|
113
|
+
var pk = (address) => {
|
|
114
|
+
return typeof address === "string" ? new PublicKey(address) : address;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// solana/rpc/priority-fee-estimate/general.ts
|
|
118
|
+
var getPriorityFeeEstimate2 = async (connection, options) => {
|
|
119
|
+
const recentPrioritizationFee = await getRecentPrioritizationFee2(connection, options);
|
|
120
|
+
const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));
|
|
121
|
+
return { median: Math.ceil(median * (1 + (options.increaseFactor ?? 0.05))), data: recentPrioritizationFee };
|
|
122
|
+
};
|
|
123
|
+
var getRecentPrioritizationFee2 = async (connection, options) => {
|
|
124
|
+
return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs2(options.accountsOrTx)[0] });
|
|
125
|
+
};
|
|
126
|
+
var buildArgs2 = (accountsOrTx) => {
|
|
127
|
+
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;
|
|
128
|
+
return [accountsArray];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export { estimateConsumeLimit, general_exports as priorityFeeEstimation, percentile_exports as priorityFeeEstimationPercentile };
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../solana/rpc/consume-limit-estimate/estimate.ts","../../../../solana/rpc/priority-fee-estimate/percentile.ts","../../../../solana/lib/deserialize-raw-transaction.ts","../../../../solana/rpc/priority-fee-estimate/calc-fee.ts","../../../../solana/rpc/priority-fee-estimate/general.ts","../../../../solana/lib/public-key.ts"],"names":["Buffer","message","accounts","writableAccounts","getPriorityFeeEstimate","getRecentPrioritizationFee","buildArgs"],"mappings":";;;;;;;;;;AAWO,IAAM,uBAAuB,OAClC,UAAA,EACA,EACA,EAAA,OAAA,GAA0C,EACvC,KAAA;AACH,EAAM,MAAA,EAAE,cAAiB,GAAA,IAAA,EAAS,GAAA,OAAA;AAClC,EAAA,MAAM,iBAAoB,GAAA,MAAM,UAAW,CAAA,mBAAA,CAAoB,EAAI,EAAA;AAAA,IACjE,SAAW,EAAA,KAAA;AAAA,IACX,sBAAwB,EAAA;AAAA,GACzB,CAAA;AACD,EAAO,OAAA;AAAA,IACL,aAAe,EAAA,iBAAA,CAAkB,KAAM,CAAA,aAAA,GACnC,IAAK,CAAA,IAAA,CAAK,iBAAkB,CAAA,KAAA,CAAM,aAAiB,IAAA,CAAA,GAAI,cAAe,CAAA,CAAA,GACtE,kBAAkB,KAAM,CAAA,aAAA;AAAA,IAC5B,IAAM,EAAA;AAAA,GACR;AACF;;;AC3BA,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,IAAA,OAAO,2BAA2B,EAAE,CAAA;AAAA,WAC7B,KAAO,EAAA;AACd,IAAI,IAAA;AACF,MAAM,MAAA,GAAA,GAAM,oBAAqB,CAAA,WAAA,CAAY,QAAQ,CAAA;AACrD,MAAA,OAAO,2BAA2B,G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AAA;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 { VersionedTransaction, Connection } from \"@solana/web3.js\";\n\nimport type { GetConsumeLimitEstimateOptions } from \"../types.js\";\n\n/**\n * Estimate the consume limit of a transaction based on the simulation results of the transaction.\n * @param connection - The connection to the RPC\n * @param tx - The transaction to estimate the consume limit for\n * @param options - The options for the estimate\n * @returns The consume limit estimate multiplied by a multiplier percent or undefined and the native simulation results\n */\nexport const estimateConsumeLimit = async (\n connection: Connection,\n tx: VersionedTransaction,\n options: GetConsumeLimitEstimateOptions = {},\n) => {\n const { increaseFactor = 0.05 } = options;\n const simulationResults = await connection.simulateTransaction(tx, {\n sigVerify: false,\n replaceRecentBlockhash: true,\n });\n return {\n unitsConsumed: simulationResults.value.unitsConsumed\n ? Math.ceil(simulationResults.value.unitsConsumed * (1 + increaseFactor))\n : simulationResults.value.unitsConsumed,\n data: simulationResults,\n };\n};\n","import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../lib/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.ceil(median * (1 + (options.increaseFactor ?? 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 return resolveTransactionAccounts(tx);\n } catch (error) {\n try {\n const vtx = VersionedTransaction.deserialize(txBuffer);\n return resolveTransactionAccounts(vtx);\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\nexport const resolveTransactionAccounts = (tx: VersionedTransaction | Transaction) => {\n if (tx instanceof Transaction) {\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 }\n\n const message = tx.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: tx,\n accounts,\n writableAccounts,\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 \"../../lib/deserialize-raw-transaction.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\nimport { pk } from \"../../lib/public-key.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.ceil(median * (1 + (options.increaseFactor ?? 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2-alpha.p287.a3616ff",
|
|
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": "2f1f50c04b56417ba0b30529e5163cbc20c05cdd",
|
|
39
47
|
"devDependencies": {
|
|
40
|
-
"@streamflow/eslint-config": "8.0.
|
|
48
|
+
"@streamflow/eslint-config": "8.0.2-alpha.p287.a3616ff",
|
|
41
49
|
"@types/bn.js": "5.1.1",
|
|
42
50
|
"typescript": "^5.6.3"
|
|
43
51
|
},
|