@streamflow/common 8.0.0-alpha.p284.726ba98 → 8.0.0-alpha.p287.5172056
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 +105 -23
- package/dist/cjs/solana/index.cjs.map +1 -1
- package/dist/cjs/solana/index.d.cts +27 -4
- 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 +89 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solana/index.d.ts +27 -4
- 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 +89 -0
- package/dist/esm/solana/rpc/index.js +114 -0
- package/dist/esm/solana/rpc/index.js.map +1 -0
- package/package.json +11 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var ContractError = class _ContractError extends Error {
|
|
|
31
31
|
* @param code extracted code from the error if managed to parse it
|
|
32
32
|
*/
|
|
33
33
|
constructor(error, code, description) {
|
|
34
|
-
super(error.message);
|
|
34
|
+
super(error.message, { cause: error });
|
|
35
35
|
this.contractErrorCode = code ?? null;
|
|
36
36
|
this.description = description ?? null;
|
|
37
37
|
Object.setPrototypeOf(this, _ContractError.prototype);
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../types.ts","../../lib/assertions.ts","../../lib/utils.ts"],"names":["ICluster","IChain","BN"],"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,SAA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AAW,EAAA,CAAA,KAAsB,CAAI,GAAA,CAAA,IAAK,CAAI,GAAA,CAAA,GAAI,MAAO,CAAA,CAAC,CAAI,GAAA,MAAA,CAAO,CAAC,CAAA","file":"index.cjs","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"]}
|
|
@@ -4,6 +4,7 @@ var splToken = require('@solana/spl-token');
|
|
|
4
4
|
var web3_js = require('@solana/web3.js');
|
|
5
5
|
var bs58 = require('bs58');
|
|
6
6
|
require('bn.js');
|
|
7
|
+
var buffer = require('buffer');
|
|
7
8
|
|
|
8
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
|
|
@@ -57,12 +58,12 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
57
58
|
var require_eventemitter3 = __commonJS({
|
|
58
59
|
"../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
|
|
59
60
|
var has = Object.prototype.hasOwnProperty;
|
|
60
|
-
var
|
|
61
|
+
var prefix2 = "~";
|
|
61
62
|
function Events() {
|
|
62
63
|
}
|
|
63
64
|
if (Object.create) {
|
|
64
65
|
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
65
|
-
if (!new Events().__proto__)
|
|
66
|
+
if (!new Events().__proto__) prefix2 = false;
|
|
66
67
|
}
|
|
67
68
|
function EE(fn, context, once) {
|
|
68
69
|
this.fn = fn;
|
|
@@ -73,7 +74,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
73
74
|
if (typeof fn !== "function") {
|
|
74
75
|
throw new TypeError("The listener must be a function");
|
|
75
76
|
}
|
|
76
|
-
var listener = new EE(fn, context || emitter, once), evt =
|
|
77
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix2 ? prefix2 + event : event;
|
|
77
78
|
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
78
79
|
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
79
80
|
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
@@ -91,7 +92,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
91
92
|
var names = [], events, name;
|
|
92
93
|
if (this._eventsCount === 0) return names;
|
|
93
94
|
for (name in events = this._events) {
|
|
94
|
-
if (has.call(events, name)) names.push(
|
|
95
|
+
if (has.call(events, name)) names.push(prefix2 ? name.slice(1) : name);
|
|
95
96
|
}
|
|
96
97
|
if (Object.getOwnPropertySymbols) {
|
|
97
98
|
return names.concat(Object.getOwnPropertySymbols(events));
|
|
@@ -99,7 +100,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
99
100
|
return names;
|
|
100
101
|
};
|
|
101
102
|
EventEmitter2.prototype.listeners = function listeners(event) {
|
|
102
|
-
var evt =
|
|
103
|
+
var evt = prefix2 ? prefix2 + event : event, handlers = this._events[evt];
|
|
103
104
|
if (!handlers) return [];
|
|
104
105
|
if (handlers.fn) return [handlers.fn];
|
|
105
106
|
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
@@ -108,13 +109,13 @@ var require_eventemitter3 = __commonJS({
|
|
|
108
109
|
return ee;
|
|
109
110
|
};
|
|
110
111
|
EventEmitter2.prototype.listenerCount = function listenerCount(event) {
|
|
111
|
-
var evt =
|
|
112
|
+
var evt = prefix2 ? prefix2 + event : event, listeners = this._events[evt];
|
|
112
113
|
if (!listeners) return 0;
|
|
113
114
|
if (listeners.fn) return 1;
|
|
114
115
|
return listeners.length;
|
|
115
116
|
};
|
|
116
117
|
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
117
|
-
var evt =
|
|
118
|
+
var evt = prefix2 ? prefix2 + event : event;
|
|
118
119
|
if (!this._events[evt]) return false;
|
|
119
120
|
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
120
121
|
if (listeners.fn) {
|
|
@@ -171,7 +172,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
171
172
|
return addListener(this, event, fn, context, true);
|
|
172
173
|
};
|
|
173
174
|
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
174
|
-
var evt =
|
|
175
|
+
var evt = prefix2 ? prefix2 + event : event;
|
|
175
176
|
if (!this._events[evt]) return this;
|
|
176
177
|
if (!fn) {
|
|
177
178
|
clearEvent(this, evt);
|
|
@@ -196,7 +197,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
196
197
|
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
197
198
|
var evt;
|
|
198
199
|
if (event) {
|
|
199
|
-
evt =
|
|
200
|
+
evt = prefix2 ? prefix2 + event : event;
|
|
200
201
|
if (this._events[evt]) clearEvent(this, evt);
|
|
201
202
|
} else {
|
|
202
203
|
this._events = new Events();
|
|
@@ -206,7 +207,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
206
207
|
};
|
|
207
208
|
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
|
|
208
209
|
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
|
|
209
|
-
EventEmitter2.prefixed =
|
|
210
|
+
EventEmitter2.prefixed = prefix2;
|
|
210
211
|
EventEmitter2.EventEmitter = EventEmitter2;
|
|
211
212
|
if ("undefined" !== typeof module) {
|
|
212
213
|
module.exports = EventEmitter2;
|
|
@@ -711,6 +712,17 @@ function sleep(ms) {
|
|
|
711
712
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
712
713
|
}
|
|
713
714
|
|
|
715
|
+
// lib/assertions.ts
|
|
716
|
+
var prefix = "Assertion failed";
|
|
717
|
+
var invariant = (condition, message) => {
|
|
718
|
+
if (condition) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
const provided = typeof message === "function" ? message() : message;
|
|
722
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
723
|
+
throw new Error(value);
|
|
724
|
+
};
|
|
725
|
+
|
|
714
726
|
// solana/utils.ts
|
|
715
727
|
var SIMULATE_TRIES = 3;
|
|
716
728
|
var buildSendThrottler = (sendRate, sendInterval = 1e3) => {
|
|
@@ -738,20 +750,30 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
738
750
|
function isTransactionVersioned(tx) {
|
|
739
751
|
return "message" in tx;
|
|
740
752
|
}
|
|
741
|
-
async function prepareTransaction(connection, ixs, payer, commitment,
|
|
753
|
+
async function prepareTransaction(connection, ixs, payer, commitment, partialSigners) {
|
|
742
754
|
if (!payer) {
|
|
743
755
|
throw new Error("Payer public key is not provided!");
|
|
744
756
|
}
|
|
745
757
|
const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
|
|
758
|
+
return {
|
|
759
|
+
tx: createVersionedTransaction(ixs, payer, hash.blockhash, partialSigners),
|
|
760
|
+
hash,
|
|
761
|
+
context
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function createVersionedTransaction(ixs, payer, recentBlockhash, partialSigners) {
|
|
765
|
+
invariant(payer, "Payer public key is not provided!");
|
|
746
766
|
const messageV0 = new web3_js.TransactionMessage({
|
|
747
767
|
payerKey: payer,
|
|
748
|
-
recentBlockhash
|
|
768
|
+
recentBlockhash,
|
|
749
769
|
instructions: ixs
|
|
750
770
|
}).compileToV0Message();
|
|
751
771
|
const tx = new web3_js.VersionedTransaction(messageV0);
|
|
752
|
-
const signers = partialSigners
|
|
753
|
-
|
|
754
|
-
|
|
772
|
+
const signers = partialSigners?.filter((item) => !!item) ?? void 0;
|
|
773
|
+
if (signers) {
|
|
774
|
+
tx.sign(signers);
|
|
775
|
+
}
|
|
776
|
+
return tx;
|
|
755
777
|
}
|
|
756
778
|
async function signTransaction(invoker, tx) {
|
|
757
779
|
let signedTx;
|
|
@@ -943,13 +965,7 @@ async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitme
|
|
|
943
965
|
})
|
|
944
966
|
);
|
|
945
967
|
const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
|
|
946
|
-
|
|
947
|
-
payerKey: payer,
|
|
948
|
-
recentBlockhash: hash.blockhash,
|
|
949
|
-
instructions: ixs
|
|
950
|
-
}).compileToV0Message();
|
|
951
|
-
const tx = new web3_js.VersionedTransaction(messageV0);
|
|
952
|
-
return { tx, hash, context };
|
|
968
|
+
return { tx: createVersionedTransaction(ixs, payer, hash.blockhash), hash, context };
|
|
953
969
|
}
|
|
954
970
|
async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
|
|
955
971
|
const { tx, hash, context } = await generateCreateAtaBatchTx(
|
|
@@ -979,7 +995,7 @@ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programI
|
|
|
979
995
|
}
|
|
980
996
|
function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
|
|
981
997
|
const ixs = [];
|
|
982
|
-
if (computePrice) {
|
|
998
|
+
if (computePrice && typeof computePrice !== "function") {
|
|
983
999
|
ixs.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
|
|
984
1000
|
}
|
|
985
1001
|
if (computeLimit) {
|
|
@@ -1009,14 +1025,80 @@ async function getMultipleAccountsInfoBatched(connection, pubKeys, commitment) {
|
|
|
1009
1025
|
return results.flat();
|
|
1010
1026
|
}
|
|
1011
1027
|
|
|
1028
|
+
// solana/lib/estimate.ts
|
|
1029
|
+
async function estimateComputeUnitPrice(estimate, ixs, payer, recentBlockhash, partialSigners) {
|
|
1030
|
+
const tx = createVersionedTransaction(
|
|
1031
|
+
ixs,
|
|
1032
|
+
payer,
|
|
1033
|
+
recentBlockhash ?? "11111111111111111111111111111111",
|
|
1034
|
+
partialSigners
|
|
1035
|
+
);
|
|
1036
|
+
return estimate(Buffer.from(tx.serialize()).toString("base64"));
|
|
1037
|
+
}
|
|
1038
|
+
async function createAndEstimateTransaction(createFn, extParams, select) {
|
|
1039
|
+
select = select ?? ((value) => value);
|
|
1040
|
+
const createResult = await createFn(extParams);
|
|
1041
|
+
const prepareIxs = select(createResult);
|
|
1042
|
+
const priorityFee = extParams.computePrice;
|
|
1043
|
+
if (priorityFee === void 0 || typeof priorityFee === "number") {
|
|
1044
|
+
return createResult;
|
|
1045
|
+
}
|
|
1046
|
+
const invoker = extParams.invoker.publicKey;
|
|
1047
|
+
invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
1048
|
+
const estimatedComputeUnitPrice = typeof priorityFee === "function" ? await estimateComputeUnitPrice(priorityFee, prepareIxs, pk(invoker)) : (
|
|
1049
|
+
// unachievable because we don't execute estimation for constant or undefined priority fee
|
|
1050
|
+
priorityFee
|
|
1051
|
+
);
|
|
1052
|
+
return createFn({
|
|
1053
|
+
...extParams,
|
|
1054
|
+
computePrice: estimatedComputeUnitPrice
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
function deserializeRawTransaction(serializedTx) {
|
|
1058
|
+
const txBuffer = buffer.Buffer.from(serializedTx, "base64");
|
|
1059
|
+
try {
|
|
1060
|
+
const tx = web3_js.Transaction.from(txBuffer);
|
|
1061
|
+
const message = tx.compileMessage();
|
|
1062
|
+
const accounts = message.accountKeys;
|
|
1063
|
+
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
1064
|
+
return {
|
|
1065
|
+
type: "legacy",
|
|
1066
|
+
transaction: tx,
|
|
1067
|
+
accounts,
|
|
1068
|
+
writableAccounts
|
|
1069
|
+
};
|
|
1070
|
+
} catch (error) {
|
|
1071
|
+
try {
|
|
1072
|
+
const vtx = web3_js.VersionedTransaction.deserialize(txBuffer);
|
|
1073
|
+
const message = vtx.message;
|
|
1074
|
+
const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
|
|
1075
|
+
const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
|
|
1076
|
+
return {
|
|
1077
|
+
type: "versioned",
|
|
1078
|
+
transaction: vtx,
|
|
1079
|
+
accounts,
|
|
1080
|
+
writableAccounts
|
|
1081
|
+
};
|
|
1082
|
+
} catch (vError) {
|
|
1083
|
+
throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
|
|
1084
|
+
cause: vError
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1012
1090
|
exports.TransactionFailedError = TransactionFailedError;
|
|
1013
1091
|
exports.ata = ata;
|
|
1014
1092
|
exports.ataBatchExist = ataBatchExist;
|
|
1015
1093
|
exports.buildSendThrottler = buildSendThrottler;
|
|
1016
1094
|
exports.checkOrCreateAtaBatch = checkOrCreateAtaBatch;
|
|
1017
1095
|
exports.confirmAndEnsureTransaction = confirmAndEnsureTransaction;
|
|
1096
|
+
exports.createAndEstimateTransaction = createAndEstimateTransaction;
|
|
1018
1097
|
exports.createAtaBatch = createAtaBatch;
|
|
1098
|
+
exports.createVersionedTransaction = createVersionedTransaction;
|
|
1099
|
+
exports.deserializeRawTransaction = deserializeRawTransaction;
|
|
1019
1100
|
exports.enrichAtaParams = enrichAtaParams;
|
|
1101
|
+
exports.estimateComputeUnitPrice = estimateComputeUnitPrice;
|
|
1020
1102
|
exports.executeMultipleTransactions = executeMultipleTransactions;
|
|
1021
1103
|
exports.executeTransaction = executeTransaction;
|
|
1022
1104
|
exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|