@streamflow/common 8.0.0 → 8.0.1-alpha.p287.54fe41f

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.
@@ -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);
@@ -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,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,IAA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C,CAAA;AACxD,EAAA,OAAO,OAAQ,CAAA,GAAA,CAAI,IAAIA,mBAAA,CAAG,GAAG,CAAC,CAAA;AAChC;AAQa,IAAA,eAAA,GAAkB,CAAC,KAAA,EAAW,QACzC,KAAA,KAAA,CAAM,EAAG,CAAA,IAAIA,mBAAG,CAAA,CAAA,IAAK,EAAK,GAAA,CAAC,CAAC,CAAA,GAAI,MAAM,GAAI,CAAA,IAAIA,mBAAG,CAAA,EAAA,IAAM,QAAQ,CAAC,CAAE,CAAA,QAAA,EAAa,GAAA,KAAA,CAAM,QAAS,EAAA,GAAI,EAAM,IAAA;AAQ1G,eAAsB,mBAAA,CACpB,MACA,QACY,EAAA;AACZ,EAAI,IAAA;AACF,IAAA,OAAO,MAAM,IAAK,EAAA;AAAA,WAEX,GAAU,EAAA;AACjB,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,MAAM,IAAI,aAAA,CAAc,GAAK,EAAA,QAAA,CAAS,GAAG,CAAC,CAAA;AAAA;AAE5C,MAAM,MAAA,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.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); // 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
+ {"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,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,O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I,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 prefix = "~";
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__) prefix = false;
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 = prefix ? prefix + event : event;
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(prefix ? name.slice(1) : name);
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 = prefix ? prefix + event : event, handlers = this._events[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 = prefix ? prefix + event : event, listeners = this._events[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 = prefix ? prefix + event : event;
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 = prefix ? prefix + event : event;
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 = prefix ? prefix + event : event;
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 = prefix;
210
+ EventEmitter2.prefixed = prefix2;
210
211
  EventEmitter2.EventEmitter = EventEmitter2;
211
212
  if ("undefined" !== typeof module) {
212
213
  module.exports = EventEmitter2;
@@ -244,9 +245,6 @@ var prepareWrappedAccount = async (connection, senderAddress, amount) => {
244
245
  splToken.createSyncNativeInstruction(tokenAccount)
245
246
  ];
246
247
  };
247
- var pk = (address) => {
248
- return typeof address === "string" ? new web3_js.PublicKey(address) : address;
249
- };
250
248
 
251
249
  // solana/types.ts
252
250
  var TransactionFailedError = class _TransactionFailedError extends Error {
@@ -711,6 +709,17 @@ function sleep(ms) {
711
709
  return new Promise((resolve) => setTimeout(resolve, ms));
712
710
  }
713
711
 
712
+ // lib/assertions.ts
713
+ var prefix = "Assertion failed";
714
+ var invariant = (condition, message) => {
715
+ if (condition) {
716
+ return;
717
+ }
718
+ const provided = typeof message === "function" ? message() : message;
719
+ const value = provided ? `${prefix}: ${provided}` : prefix;
720
+ throw new Error(value);
721
+ };
722
+
714
723
  // solana/utils.ts
715
724
  var SIMULATE_TRIES = 3;
716
725
  var buildSendThrottler = (sendRate, sendInterval = 1e3) => {
@@ -738,20 +747,30 @@ function isSignerKeypair(walletOrKeypair) {
738
747
  function isTransactionVersioned(tx) {
739
748
  return "message" in tx;
740
749
  }
741
- async function prepareTransaction(connection, ixs, payer, commitment, ...partialSigners) {
750
+ async function prepareTransaction(connection, ixs, payer, commitment, partialSigners) {
742
751
  if (!payer) {
743
752
  throw new Error("Payer public key is not provided!");
744
753
  }
745
754
  const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
755
+ return {
756
+ tx: createVersionedTransaction(ixs, payer, hash.blockhash, partialSigners),
757
+ hash,
758
+ context
759
+ };
760
+ }
761
+ function createVersionedTransaction(ixs, payer, recentBlockhash, partialSigners) {
762
+ invariant(payer, "Payer public key is not provided!");
746
763
  const messageV0 = new web3_js.TransactionMessage({
747
764
  payerKey: payer,
748
- recentBlockhash: hash.blockhash,
765
+ recentBlockhash,
749
766
  instructions: ixs
750
767
  }).compileToV0Message();
751
768
  const tx = new web3_js.VersionedTransaction(messageV0);
752
- const signers = partialSigners.filter((item) => !!item);
753
- tx.sign(signers);
754
- return { tx, context, hash };
769
+ const signers = partialSigners?.filter((item) => !!item) ?? void 0;
770
+ if (signers) {
771
+ tx.sign(signers);
772
+ }
773
+ return tx;
755
774
  }
756
775
  async function signTransaction(invoker, tx) {
757
776
  let signedTx;
@@ -767,16 +786,18 @@ async function signTransaction(invoker, tx) {
767
786
  }
768
787
  return signedTx;
769
788
  }
770
- async function signAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
789
+ async function signAndExecuteTransaction(connection, invoker, tx, confirmationParams, transactionExecutionParams) {
771
790
  const signedTx = await signTransaction(invoker, tx);
772
- return executeTransaction(connection, signedTx, confirmationParams, throttleParams);
791
+ return executeTransaction(connection, signedTx, confirmationParams, transactionExecutionParams);
773
792
  }
774
- async function executeTransaction(connection, tx, confirmationParams, throttleParams) {
793
+ async function executeTransaction(connection, tx, confirmationParams, transactionExecutionParams) {
775
794
  if (tx.signatures.length === 0) {
776
795
  throw Error("Error with transaction parameters.");
777
796
  }
778
- await simulateTransaction(connection, tx);
779
- return sendAndConfirmTransaction(connection, tx, confirmationParams, throttleParams);
797
+ if (!transactionExecutionParams.skipSimulation) {
798
+ await simulateTransaction(connection, tx);
799
+ }
800
+ return sendAndConfirmTransaction(connection, tx, confirmationParams, transactionExecutionParams);
780
801
  }
781
802
  async function executeMultipleTransactions(connection, txs, confirmationParams, { sendRate = 1, sendThrottler, ...throttlingParams }) {
782
803
  if (!sendThrottler) {
@@ -943,13 +964,7 @@ async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitme
943
964
  })
944
965
  );
945
966
  const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
946
- const messageV0 = new web3_js.TransactionMessage({
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 };
967
+ return { tx: createVersionedTransaction(ixs, payer, hash.blockhash), hash, context };
953
968
  }
954
969
  async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
955
970
  const { tx, hash, context } = await generateCreateAtaBatchTx(
@@ -979,10 +994,10 @@ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programI
979
994
  }
980
995
  function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
981
996
  const ixs = [];
982
- if (computePrice) {
997
+ if (computePrice && typeof computePrice !== "function") {
983
998
  ixs.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
984
999
  }
985
- if (computeLimit) {
1000
+ if (computeLimit && typeof computeLimit === "number") {
986
1001
  ixs.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
987
1002
  }
988
1003
  return ixs;
@@ -1008,6 +1023,102 @@ async function getMultipleAccountsInfoBatched(connection, pubKeys, commitment) {
1008
1023
  const results = await Promise.all(batches);
1009
1024
  return results.flat();
1010
1025
  }
1026
+ function deserializeRawTransaction(serializedTx) {
1027
+ const txBuffer = buffer.Buffer.from(serializedTx, "base64");
1028
+ try {
1029
+ const tx = web3_js.Transaction.from(txBuffer);
1030
+ return resolveTransactionAccounts(tx);
1031
+ } catch (error) {
1032
+ try {
1033
+ const vtx = web3_js.VersionedTransaction.deserialize(txBuffer);
1034
+ return resolveTransactionAccounts(vtx);
1035
+ } catch (vError) {
1036
+ throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
1037
+ cause: vError
1038
+ });
1039
+ }
1040
+ }
1041
+ }
1042
+ var resolveTransactionAccounts = (tx) => {
1043
+ if (tx instanceof web3_js.Transaction) {
1044
+ const message2 = tx.compileMessage();
1045
+ const accounts2 = message2.accountKeys;
1046
+ const writableAccounts2 = accounts2.filter((_, idx) => message2.isAccountWritable(idx));
1047
+ return {
1048
+ type: "legacy",
1049
+ transaction: tx,
1050
+ accounts: accounts2,
1051
+ writableAccounts: writableAccounts2
1052
+ };
1053
+ }
1054
+ const message = tx.message;
1055
+ const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
1056
+ const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
1057
+ return {
1058
+ type: "versioned",
1059
+ transaction: tx,
1060
+ accounts,
1061
+ writableAccounts
1062
+ };
1063
+ };
1064
+ var pk = (address) => {
1065
+ return typeof address === "string" ? new web3_js.PublicKey(address) : address;
1066
+ };
1067
+
1068
+ // solana/lib/estimate.ts
1069
+ var createTestTransaction = (ixs, payer, recentBlockhash, partialSigners) => {
1070
+ return createVersionedTransaction(ixs, payer, "11111111111111111111111111111111", partialSigners);
1071
+ };
1072
+ async function estimateComputeUnitPrice(estimate, testTx) {
1073
+ return estimate(resolveTransactionAccounts(testTx).writableAccounts);
1074
+ }
1075
+ async function createAndEstimateTransaction(createFn, extParams, select) {
1076
+ select = select ?? ((value) => value);
1077
+ const createResult = await createFn(extParams);
1078
+ const prepareIxs = select(createResult);
1079
+ const { computePrice, computeLimit } = extParams;
1080
+ const invoker = extParams.invoker.publicKey;
1081
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
1082
+ const testTx = createTestTransaction(prepareIxs, pk(invoker), void 0, void 0);
1083
+ const estimatedComputeLimit = typeof computeLimit === "function" ? await computeLimit(testTx) : computeLimit;
1084
+ if (typeof computePrice !== "function") {
1085
+ if (typeof computeLimit !== "function") {
1086
+ return createResult;
1087
+ }
1088
+ return createFn({
1089
+ ...extParams,
1090
+ computeLimit: estimatedComputeLimit
1091
+ });
1092
+ }
1093
+ const estimatedComputeUnitPrice = typeof computePrice === "function" ? await estimateComputeUnitPrice(computePrice, testTx) : (
1094
+ // unachievable because we don't execute estimation for constant or undefined priority fee
1095
+ computePrice
1096
+ );
1097
+ return createFn({
1098
+ ...extParams,
1099
+ computePrice: estimatedComputeUnitPrice,
1100
+ computeLimit: estimatedComputeLimit
1101
+ });
1102
+ }
1103
+
1104
+ // solana/rpc/consume-limit-estimate/estimate.ts
1105
+ var estimateConsumeLimit = async (connection, tx, options = {}) => {
1106
+ const { multiplierPercent = 0.05 } = options;
1107
+ const simulationResults = await connection.simulateTransaction(tx, {
1108
+ sigVerify: false,
1109
+ replaceRecentBlockhash: true
1110
+ });
1111
+ return {
1112
+ unitsConsumed: simulationResults.value.unitsConsumed ? Math.ceil(simulationResults.value.unitsConsumed * (1 + multiplierPercent)) : simulationResults.value.unitsConsumed,
1113
+ data: simulationResults
1114
+ };
1115
+ };
1116
+
1117
+ // solana/lib/unwrap-auto-simulate-ext.ts
1118
+ var unwrapExecutionParams = ({ computeLimit, ...rest }, connection) => {
1119
+ const consumeLimitFn = computeLimit === "autoSimulate" ? (tx) => estimateConsumeLimit(connection, tx).then((limit) => limit.unitsConsumed ?? 0) : computeLimit;
1120
+ return { ...rest, computeLimit: consumeLimitFn, skipSimulation: computeLimit === "autoSimulate" };
1121
+ };
1011
1122
 
1012
1123
  exports.TransactionFailedError = TransactionFailedError;
1013
1124
  exports.ata = ata;
@@ -1015,8 +1126,12 @@ exports.ataBatchExist = ataBatchExist;
1015
1126
  exports.buildSendThrottler = buildSendThrottler;
1016
1127
  exports.checkOrCreateAtaBatch = checkOrCreateAtaBatch;
1017
1128
  exports.confirmAndEnsureTransaction = confirmAndEnsureTransaction;
1129
+ exports.createAndEstimateTransaction = createAndEstimateTransaction;
1018
1130
  exports.createAtaBatch = createAtaBatch;
1131
+ exports.createVersionedTransaction = createVersionedTransaction;
1132
+ exports.deserializeRawTransaction = deserializeRawTransaction;
1019
1133
  exports.enrichAtaParams = enrichAtaParams;
1134
+ exports.estimateComputeUnitPrice = estimateComputeUnitPrice;
1020
1135
  exports.executeMultipleTransactions = executeMultipleTransactions;
1021
1136
  exports.executeTransaction = executeTransaction;
1022
1137
  exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
@@ -1031,9 +1146,11 @@ exports.pk = pk;
1031
1146
  exports.prepareBaseInstructions = prepareBaseInstructions;
1032
1147
  exports.prepareTransaction = prepareTransaction;
1033
1148
  exports.prepareWrappedAccount = prepareWrappedAccount;
1149
+ exports.resolveTransactionAccounts = resolveTransactionAccounts;
1034
1150
  exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
1035
1151
  exports.signAndExecuteTransaction = signAndExecuteTransaction;
1036
1152
  exports.signTransaction = signTransaction;
1037
1153
  exports.simulateTransaction = simulateTransaction;
1154
+ exports.unwrapExecutionParams = unwrapExecutionParams;
1038
1155
  //# sourceMappingURL=index.cjs.map
1039
1156
  //# sourceMappingURL=index.cjs.map