@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,137 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var web3_js = require('@solana/web3.js');
|
|
4
|
+
var buffer = require('buffer');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// solana/rpc/consume-limit-estimate/estimate.ts
|
|
13
|
+
var estimateConsumeLimit = async (connection, tx, options = {}) => {
|
|
14
|
+
const { increaseFactor = 0.05 } = options;
|
|
15
|
+
const simulationResults = await connection.simulateTransaction(tx, {
|
|
16
|
+
sigVerify: false,
|
|
17
|
+
replaceRecentBlockhash: true
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
unitsConsumed: simulationResults.value.unitsConsumed ? Math.ceil(simulationResults.value.unitsConsumed * (1 + increaseFactor)) : simulationResults.value.unitsConsumed,
|
|
21
|
+
data: simulationResults
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
26
|
+
var percentile_exports = {};
|
|
27
|
+
__export(percentile_exports, {
|
|
28
|
+
getPriorityFeeEstimate: () => getPriorityFeeEstimate,
|
|
29
|
+
getRecentPrioritizationFee: () => getRecentPrioritizationFee
|
|
30
|
+
});
|
|
31
|
+
function deserializeRawTransaction(serializedTx) {
|
|
32
|
+
const txBuffer = buffer.Buffer.from(serializedTx, "base64");
|
|
33
|
+
try {
|
|
34
|
+
const tx = web3_js.Transaction.from(txBuffer);
|
|
35
|
+
return resolveTransactionAccounts(tx);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
try {
|
|
38
|
+
const vtx = web3_js.VersionedTransaction.deserialize(txBuffer);
|
|
39
|
+
return resolveTransactionAccounts(vtx);
|
|
40
|
+
} catch (vError) {
|
|
41
|
+
throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
|
|
42
|
+
cause: vError
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
var resolveTransactionAccounts = (tx) => {
|
|
48
|
+
if (tx instanceof web3_js.Transaction) {
|
|
49
|
+
const message2 = tx.compileMessage();
|
|
50
|
+
const accounts2 = message2.accountKeys;
|
|
51
|
+
const writableAccounts2 = accounts2.filter((_, idx) => message2.isAccountWritable(idx));
|
|
52
|
+
return {
|
|
53
|
+
type: "legacy",
|
|
54
|
+
transaction: tx,
|
|
55
|
+
accounts: accounts2,
|
|
56
|
+
writableAccounts: writableAccounts2
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const message = tx.message;
|
|
60
|
+
const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
|
|
61
|
+
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
62
|
+
return {
|
|
63
|
+
type: "versioned",
|
|
64
|
+
transaction: tx,
|
|
65
|
+
accounts,
|
|
66
|
+
writableAccounts
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// solana/rpc/priority-fee-estimate/calc-fee.ts
|
|
71
|
+
var resolveMedian = (values) => {
|
|
72
|
+
if (values.length < 2) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
const sortedRates = [...values].sort((a, b) => a - b);
|
|
76
|
+
const medianIndex = Math.floor(sortedRates.length / 2);
|
|
77
|
+
const medianArrValue = sortedRates[medianIndex];
|
|
78
|
+
const medianPrevValue = sortedRates[medianIndex - 1];
|
|
79
|
+
if (medianPrevValue === void 0 || medianArrValue === void 0) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;
|
|
83
|
+
return medianValue;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// solana/rpc/priority-fee-estimate/percentile.ts
|
|
87
|
+
var getPriorityFeeEstimate = async (connection, options) => {
|
|
88
|
+
const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);
|
|
89
|
+
const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));
|
|
90
|
+
return { median: Math.ceil(median * (1 + (options.increaseFactor ?? 0.05))), data: recentPrioritizationFee };
|
|
91
|
+
};
|
|
92
|
+
var getRecentPrioritizationFee = async (connection, options) => {
|
|
93
|
+
const { accountsOrTx, percentile = 5e3 } = options;
|
|
94
|
+
return connection._rpcRequest(
|
|
95
|
+
"getRecentPrioritizationFees",
|
|
96
|
+
buildArgs(accountsOrTx, percentile)
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
var buildArgs = (accountsOrTx, percentile) => {
|
|
100
|
+
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map((a) => a.toString()) : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());
|
|
101
|
+
return [
|
|
102
|
+
accountsArray,
|
|
103
|
+
{
|
|
104
|
+
percentile
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// solana/rpc/priority-fee-estimate/general.ts
|
|
110
|
+
var general_exports = {};
|
|
111
|
+
__export(general_exports, {
|
|
112
|
+
getPriorityFeeEstimate: () => getPriorityFeeEstimate2,
|
|
113
|
+
getRecentPrioritizationFee: () => getRecentPrioritizationFee2
|
|
114
|
+
});
|
|
115
|
+
var pk = (address) => {
|
|
116
|
+
return typeof address === "string" ? new web3_js.PublicKey(address) : address;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// solana/rpc/priority-fee-estimate/general.ts
|
|
120
|
+
var getPriorityFeeEstimate2 = async (connection, options) => {
|
|
121
|
+
const recentPrioritizationFee = await getRecentPrioritizationFee2(connection, options);
|
|
122
|
+
const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));
|
|
123
|
+
return { median: Math.ceil(median * (1 + (options.increaseFactor ?? 0.05))), data: recentPrioritizationFee };
|
|
124
|
+
};
|
|
125
|
+
var getRecentPrioritizationFee2 = async (connection, options) => {
|
|
126
|
+
return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs2(options.accountsOrTx)[0] });
|
|
127
|
+
};
|
|
128
|
+
var buildArgs2 = (accountsOrTx) => {
|
|
129
|
+
const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;
|
|
130
|
+
return [accountsArray];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
exports.estimateConsumeLimit = estimateConsumeLimit;
|
|
134
|
+
exports.priorityFeeEstimation = general_exports;
|
|
135
|
+
exports.priorityFeeEstimationPercentile = percentile_exports;
|
|
136
|
+
//# sourceMappingURL=index.cjs.map
|
|
137
|
+
//# sourceMappingURL=index.cjs.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","Transaction","VersionedTransaction","message","accounts","writableAccounts","getPriorityFeeEstimate","getRecentPrioritizationFee","PublicKey","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,aAAAA,CAAO,IAAK,CAAA,YAAA,EAAc,QAAQ,CAAA;AACnD,EAAI,IAAA;AACF,IAAM,MAAA,EAAA,GAAKC,mBAAY,CAAA,IAAA,CAAK,QAAQ,CAAA;AACpC,IAAA,OAAO,2BAA2B,EAAE,CAAA;AAAA,WAC7B,KAAO,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AACH,EAAO,OAAA,UAAA,CAAW,2BAA4B,CAAA,EAAE,sBAAwBE,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.cjs","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"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as _solana_web3_js from '@solana/web3.js';
|
|
2
|
+
import { PublicKey, Connection, VersionedTransaction } 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 multiplier to apply to the priority fee estimate.
|
|
23
|
+
* The result is multiplied by 1 + increaseFactor.
|
|
24
|
+
* @default 0.05 = 5%
|
|
25
|
+
*/
|
|
26
|
+
increaseFactor?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @interface GetConsumeLimitEstimateOptions - The options for the consume limit estimate
|
|
30
|
+
*/
|
|
31
|
+
interface GetConsumeLimitEstimateOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The multiplier to apply to the consume limit estimate.
|
|
34
|
+
* The result is multiplied by 1 + increaseFactor.
|
|
35
|
+
* @default 0.05 = 5%
|
|
36
|
+
*/
|
|
37
|
+
increaseFactor?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Estimate the consume limit of a transaction based on the simulation results of the transaction.
|
|
42
|
+
* @param connection - The connection to the RPC
|
|
43
|
+
* @param tx - The transaction to estimate the consume limit for
|
|
44
|
+
* @param options - The options for the estimate
|
|
45
|
+
* @returns The consume limit estimate multiplied by a multiplier percent or undefined and the native simulation results
|
|
46
|
+
*/
|
|
47
|
+
declare const estimateConsumeLimit: (connection: Connection, tx: VersionedTransaction, options?: GetConsumeLimitEstimateOptions) => Promise<{
|
|
48
|
+
unitsConsumed: number | undefined;
|
|
49
|
+
data: _solana_web3_js.RpcResponseAndContext<_solana_web3_js.SimulatedTransactionResponse>;
|
|
50
|
+
}>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @category GetPriorityFeeEstimateOptions
|
|
54
|
+
* @interface RecentPrioritizationFee
|
|
55
|
+
* @property result - The result of the recent prioritization fees.
|
|
56
|
+
* @property result.prioritizationFee - The prioritization fee.
|
|
57
|
+
* @property result.slot - The slot of the prioritization fee.
|
|
58
|
+
*/
|
|
59
|
+
interface RecentPrioritizationFee {
|
|
60
|
+
result: Array<{
|
|
61
|
+
prioritizationFee: number;
|
|
62
|
+
slot: number;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]
|
|
67
|
+
* @param connection - The connection to the RPC
|
|
68
|
+
* @param options - The options for the RPC
|
|
69
|
+
* @returns The priority fee estimate
|
|
70
|
+
*/
|
|
71
|
+
declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
72
|
+
median: number;
|
|
73
|
+
data: RecentPrioritizationFee;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}
|
|
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$1: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx" | "percentile">) => Promise<RecentPrioritizationFee>;
|
|
82
|
+
|
|
83
|
+
declare namespace percentile {
|
|
84
|
+
export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
89
|
+
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
90
|
+
* @param connection - The connection to the RPC
|
|
91
|
+
* @param options - The options for the RPC
|
|
92
|
+
* @returns The priority fee estimate
|
|
93
|
+
*/
|
|
94
|
+
declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
|
|
95
|
+
median: number;
|
|
96
|
+
data: _solana_web3_js.RecentPrioritizationFees[];
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
|
|
100
|
+
* @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
|
|
101
|
+
* @param connection - The connection to the RPC
|
|
102
|
+
* @param options - The options for the RPC
|
|
103
|
+
* @returns The priority fee estimate
|
|
104
|
+
*/
|
|
105
|
+
declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
|
|
106
|
+
|
|
107
|
+
declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
|
|
108
|
+
declare const general_getRecentPrioritizationFee: typeof getRecentPrioritizationFee;
|
|
109
|
+
declare namespace general {
|
|
110
|
+
export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { type GetConsumeLimitEstimateOptions, type GetPriorityFeeEstimateOptions, estimateConsumeLimit, general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
|
package/dist/esm/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var ContractError = class _ContractError extends Error {
|
|
|
25
25
|
* @param code extracted code from the error if managed to parse it
|
|
26
26
|
*/
|
|
27
27
|
constructor(error, code, description) {
|
|
28
|
-
super(error.message);
|
|
28
|
+
super(error.message, { cause: error });
|
|
29
29
|
this.contractErrorCode = code ?? null;
|
|
30
30
|
this.description = description ?? null;
|
|
31
31
|
Object.setPrototypeOf(this, _ContractError.prototype);
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../types.ts","../../lib/assertions.ts","../../lib/utils.ts"],"names":["ICluster","IChain"],"mappings":";;;;AAQY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,OAAQ,CAAA,GAAA,OAAA;AAJE,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAOA,IAAA,MAAA,qBAAAC,OAAL,KAAA;AACL,EAAAA,QAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,QAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,QAAA,UAAW,CAAA,GAAA,UAAA;AACX,EAAAA,QAAA,KAAM,CAAA,GAAA,KAAA;AACN,EAAAA,QAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,QAAA,KAAM,CAAA,GAAA,KAAA;AANI,EAAAA,OAAAA,OAAAA;AAAA,CAAA,EAAA,MAAA,IAAA,EAAA;AAYC,IAAA,aAAA,GAAN,MAAM,cAAA,SAAsB,KAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUvC,WAAA,CAAY,KAAc,EAAA,IAAA,EAAsB,WAA6B,EAAA;AAC3E,IAAA,KAAA,CAAM,
|
|
1
|
+
{"version":3,"sources":["../../types.ts","../../lib/assertions.ts","../../lib/utils.ts"],"names":["ICluster","IChain"],"mappings":";;;;AAQY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,OAAQ,CAAA,GAAA,OAAA;AAJE,EAAAA,OAAAA,SAAAA;AA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AAA,IAAI,cAAc,GAAG,CAAA;AAAA;AAE7B,IAAM,MAAA,GAAA;AAAA;AAEV;AAMO,SAAS,MAAM,EAA2B,EAAA;AAC/C,EAAA,OAAO,IAAI,OAAQ,CAAA,CAAC,YAAY,UAAW,CAAA,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD;AAEO,IAAM,QAAW,GAAA,CAAC,CAAW,EAAA,CAAA,KAAsB,CAAI,GAAA,CAAA,IAAK,CAAI,GAAA,CAAA,GAAI,MAAO,CAAA,CAAC,CAAI,GAAA,MAAA,CAAO,CAAC,CAAA","file":"index.js","sourcesContent":["import { type TransactionInstruction } from \"@solana/web3.js\";\n\nexport interface ITransactionResult {\n ixs: TransactionInstruction[];\n txId: string;\n}\n\n// Utility types\nexport enum ICluster {\n Mainnet = \"mainnet\",\n Devnet = \"devnet\",\n Testnet = \"testnet\",\n Local = \"local\",\n}\n\nexport enum IChain {\n Solana = \"Solana\",\n Aptos = \"Aptos\",\n Ethereum = \"Ethereum\",\n BNB = \"BNB\",\n Polygon = \"Polygon\",\n Sui = \"Sui\",\n}\n\n/**\n * Error wrapper for calls made to the contract on chain\n */\nexport class ContractError extends Error {\n public contractErrorCode: string | null;\n\n public description: string | null;\n\n /**\n * Constructs the Error Wrapper\n * @param error Original error raised probably by the chain SDK\n * @param code extracted code from the error if managed to parse it\n */\n constructor(error: Error, code?: string | null, description?: string | null) {\n super(error.message, { cause: error }); // Call the base class constructor with the error message\n this.contractErrorCode = code ?? null;\n this.description = description ?? null;\n // Copy properties from the original error\n Object.setPrototypeOf(this, ContractError.prototype);\n this.name = \"ContractError\"; // Set the name property\n this.stack = error.stack;\n }\n}\n","const prefix = \"Assertion failed\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const invariant: (condition: any, message?: string | (() => string)) => asserts condition = (\n condition,\n message,\n) => {\n if (condition) {\n return;\n }\n const provided: string | undefined = typeof message === \"function\" ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n};\n","import BN from \"bn.js\";\n\nimport { ContractError } from \"../types.js\";\n\n/**\n * Used for conversion of token amounts to their Big Number representation.\n * Get Big Number representation in the smallest units from the same value in the highest units.\n * @param {number} value - Number of tokens you want to convert to its BN representation.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getBN = (value: number, decimals: number): BN => {\n const decimalPart = value - Math.trunc(value);\n const integerPart = new BN(Math.trunc(value));\n\n const decimalE = new BN(decimalPart * 1e9);\n\n const sum = integerPart.mul(new BN(1e9)).add(decimalE);\n const resultE = sum.mul(new BN(10).pow(new BN(decimals)));\n return resultE.div(new BN(1e9));\n};\n\n/**\n * Used for token amounts conversion from their Big Number representation to number.\n * Get value in the highest units from BN representation of the same value in the smallest units.\n * @param {BN} value - Big Number representation of value in the smallest units.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getNumberFromBN = (value: BN, decimals: number): number =>\n value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;\n\n/**\n * Used to make on chain calls to the contract and wrap raised errors if any\n * @param func function that interacts with the contract\n * @param callback callback that may be used to extract error code\n * @returns {T}\n */\nexport async function handleContractError<T>(\n func: () => Promise<T>,\n callback?: (err: Error) => string | null,\n): Promise<T> {\n try {\n return await func();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n if (err instanceof Error) {\n if (callback) {\n throw new ContractError(err, callback(err));\n }\n throw new ContractError(err);\n }\n throw err;\n }\n}\n\n/**\n * Pause async function execution for given amount of milliseconds\n * @param ms millisecond to sleep for\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport const divCeilN = (n: bigint, d: bigint): bigint => n / d + (n % d ? BigInt(1) : BigInt(0));\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _solana_web3_js from '@solana/web3.js';
|
|
2
|
+
import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, VersionedTransaction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
|
|
2
3
|
import BN from 'bn.js';
|
|
3
4
|
import PQueue from 'p-queue';
|
|
4
5
|
import { Mint } from '@solana/spl-token';
|
|
@@ -8,16 +9,28 @@ declare const getFilters: <T extends Record<string, number | PublicKey>>(criteri
|
|
|
8
9
|
|
|
9
10
|
declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
|
|
10
11
|
|
|
12
|
+
type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
|
|
13
|
+
type ComputeLimitEstimate = (tx: VersionedTransaction) => Promise<number>;
|
|
14
|
+
interface ITransactionSolanaExt {
|
|
15
|
+
computePrice?: number | ComputePriceEstimate;
|
|
16
|
+
computeLimit?: number | ComputeLimitEstimate | "autoSimulate";
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @returns The PublicKey object.
|
|
19
|
+
* Acceptable type with resolved values.
|
|
20
|
+
* Function types may be omitted if passed to destinations that do not support them.
|
|
15
21
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
type ITransactionSolanaExtResolvedValues = {
|
|
23
|
+
computePrice?: number | ComputePriceEstimate;
|
|
24
|
+
computeLimit?: number | ComputeLimitEstimate;
|
|
25
|
+
};
|
|
26
|
+
type KeysNotOfA<T, ToExclude> = Pick<T, Exclude<keyof T, keyof ToExclude>>;
|
|
27
|
+
type ITransactionSolanaExtResolved<T extends ITransactionSolanaExt = ITransactionSolanaExt> = {
|
|
28
|
+
[AK in keyof KeysNotOfA<T, ITransactionSolanaExt>]: T[AK];
|
|
29
|
+
} & ITransactionSolanaExtResolvedValues;
|
|
30
|
+
interface IInteractSolanaExt extends ITransactionSolanaExt {
|
|
31
|
+
invoker: {
|
|
32
|
+
publicKey: string | PublicKey | null;
|
|
33
|
+
};
|
|
21
34
|
}
|
|
22
35
|
interface Account {
|
|
23
36
|
pubkey: PublicKey;
|
|
@@ -45,6 +58,9 @@ interface ThrottleParams {
|
|
|
45
58
|
sendThrottler?: PQueue;
|
|
46
59
|
waitBeforeConfirming?: number | undefined;
|
|
47
60
|
}
|
|
61
|
+
interface TransactionExecutionParams extends ThrottleParams {
|
|
62
|
+
skipSimulation?: boolean;
|
|
63
|
+
}
|
|
48
64
|
interface IProgramAccount<T> {
|
|
49
65
|
publicKey: PublicKey;
|
|
50
66
|
account: T;
|
|
@@ -90,11 +106,12 @@ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction):
|
|
|
90
106
|
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
91
107
|
* @returns Transaction and Blockhash
|
|
92
108
|
*/
|
|
93
|
-
declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment,
|
|
109
|
+
declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
|
|
94
110
|
tx: VersionedTransaction;
|
|
95
111
|
hash: BlockhashWithExpiryBlockHeight;
|
|
96
112
|
context: Context;
|
|
97
113
|
}>;
|
|
114
|
+
declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
|
|
98
115
|
declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
|
|
99
116
|
/**
|
|
100
117
|
* Signs, sends and confirms Transaction
|
|
@@ -102,10 +119,10 @@ declare function signTransaction<T extends Transaction | VersionedTransaction>(i
|
|
|
102
119
|
* @param invoker - Keypair used as signer
|
|
103
120
|
* @param tx - Transaction instance
|
|
104
121
|
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
105
|
-
* @param
|
|
122
|
+
* @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
|
|
106
123
|
* @returns Transaction signature
|
|
107
124
|
*/
|
|
108
|
-
declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams,
|
|
125
|
+
declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
|
|
109
126
|
/**
|
|
110
127
|
* Sends and confirms Transaction
|
|
111
128
|
* Uses custom confirmation logic that:
|
|
@@ -118,10 +135,10 @@ declare function signAndExecuteTransaction(connection: Connection, invoker: Keyp
|
|
|
118
135
|
* @param connection - Solana client connection
|
|
119
136
|
* @param tx - Transaction instance
|
|
120
137
|
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
121
|
-
* @param
|
|
138
|
+
* @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
|
|
122
139
|
* @returns Transaction signature
|
|
123
140
|
*/
|
|
124
|
-
declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams,
|
|
141
|
+
declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
|
|
125
142
|
/**
|
|
126
143
|
* Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
|
|
127
144
|
* @param connection - Solana client connection
|
|
@@ -207,8 +224,8 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
|
|
|
207
224
|
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
|
|
208
225
|
/**
|
|
209
226
|
* Create Base instructions for Solana
|
|
210
|
-
* - sets compute price if `computePrice` is provided
|
|
211
|
-
* - sets compute limit if `computeLimit` is provided
|
|
227
|
+
* - sets compute price if `computePrice` is provided. If `computePrice` is a function, it will be ignored (the value must be resolved before calling this function).
|
|
228
|
+
* - sets compute limit if `computeLimit` is provided. If `computeLimit` is a function, it will be ignored (the value must be resolved before calling this function).
|
|
212
229
|
*/
|
|
213
230
|
declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
|
|
214
231
|
/**
|
|
@@ -236,4 +253,45 @@ declare function getMintAndProgram(connection: Connection, address: PublicKey, c
|
|
|
236
253
|
*/
|
|
237
254
|
declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
|
|
238
255
|
|
|
239
|
-
|
|
256
|
+
declare function deserializeRawTransaction(serializedTx: string): {
|
|
257
|
+
type: string;
|
|
258
|
+
transaction: Transaction;
|
|
259
|
+
accounts: PublicKey[];
|
|
260
|
+
writableAccounts: PublicKey[];
|
|
261
|
+
} | {
|
|
262
|
+
type: string;
|
|
263
|
+
transaction: VersionedTransaction;
|
|
264
|
+
accounts: PublicKey[];
|
|
265
|
+
writableAccounts: PublicKey[];
|
|
266
|
+
};
|
|
267
|
+
declare const resolveTransactionAccounts: (tx: VersionedTransaction | Transaction) => {
|
|
268
|
+
type: string;
|
|
269
|
+
transaction: Transaction;
|
|
270
|
+
accounts: PublicKey[];
|
|
271
|
+
writableAccounts: PublicKey[];
|
|
272
|
+
} | {
|
|
273
|
+
type: string;
|
|
274
|
+
transaction: VersionedTransaction;
|
|
275
|
+
accounts: PublicKey[];
|
|
276
|
+
writableAccounts: PublicKey[];
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
declare const createTestTransaction: (ixs: Parameters<typeof createVersionedTransaction>[0], payer: Parameters<typeof createVersionedTransaction>[1], recentBlockhash?: Parameters<typeof createVersionedTransaction>[2], partialSigners?: Parameters<typeof createVersionedTransaction>[3]) => _solana_web3_js.VersionedTransaction;
|
|
280
|
+
declare function estimateComputeUnitPrice(estimate: ComputePriceEstimate, testTx: ReturnType<typeof createTestTransaction>): Promise<number>;
|
|
281
|
+
declare function createAndEstimateTransaction<ParamsT extends ITransactionSolanaExtResolved<IInteractSolanaExt>, CreateFn extends (extParams: ParamsT) => Promise<TransactionInstruction[]>>(createFn: CreateFn, extParams: ParamsT): Promise<Awaited<ReturnType<CreateFn>>>;
|
|
282
|
+
declare function createAndEstimateTransaction<ParamsT extends ITransactionSolanaExtResolved<IInteractSolanaExt>, CreateFn extends (extParams: ParamsT) => Promise<any>>(createFn: CreateFn, extParams: ParamsT, select: (result: Awaited<ReturnType<CreateFn>>) => TransactionInstruction[]): Promise<Awaited<ReturnType<CreateFn>>>;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Converts a string or PublicKey to a PublicKey object.
|
|
286
|
+
* @param address - The input address as a string or PublicKey.
|
|
287
|
+
* @returns The PublicKey object.
|
|
288
|
+
*/
|
|
289
|
+
declare const pk: (address: string | PublicKey) => PublicKey;
|
|
290
|
+
|
|
291
|
+
type UnwrapAutoSimulate<T extends IInteractSolanaExt = IInteractSolanaExt> = Omit<T, "computeLimit"> & {
|
|
292
|
+
skipSimulation: boolean;
|
|
293
|
+
computeLimit?: ITransactionSolanaExtResolved["computeLimit"];
|
|
294
|
+
};
|
|
295
|
+
declare const unwrapExecutionParams: <T extends IInteractSolanaExt>({ computeLimit, ...rest }: T, connection: Connection) => UnwrapAutoSimulate<T>;
|
|
296
|
+
|
|
297
|
+
export { type Account, type AtaParams, type CheckAssociatedTokenAccountsData, type ComputeLimitEstimate, type ComputePriceEstimate, type ConfirmationParams, type IInteractSolanaExt, type IProgramAccount, type ITransactionSolanaExt, type ITransactionSolanaExtResolved, type ThrottleParams, type TransactionExecutionParams, TransactionFailedError, ata, ataBatchExist, buildSendThrottler, checkOrCreateAtaBatch, confirmAndEnsureTransaction, createAndEstimateTransaction, createAtaBatch, createVersionedTransaction, deserializeRawTransaction, enrichAtaParams, estimateComputeUnitPrice, executeMultipleTransactions, executeTransaction, generateCreateAtaBatchTx, getFilters, getMintAndProgram, getMultipleAccountsInfoBatched, getProgramAccounts, isSignerKeypair, isSignerWallet, isTransactionVersioned, pk, prepareBaseInstructions, prepareTransaction, prepareWrappedAccount, resolveTransactionAccounts, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction, unwrapExecutionParams };
|