@streamflow/common 8.0.0-alpha.p287.84ff30f → 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.
@@ -1,21 +1,73 @@
1
- import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, Keypair, Transaction, VersionedTransaction, Commitment, BlockhashWithExpiryBlockHeight, Context, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus, AccountInfo } from '@solana/web3.js';
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
- import { A as Account, C as ConfirmationParams, T as ThrottleParams, a as AtaParams, I as ITransactionSolanaExt, b as ComputePriceEstimate, c as IInteractSolanaExt } from '../types-DGCX8JLm.cjs';
4
- export { d as CheckAssociatedTokenAccountsData, G as GetPriorityFeeEstimateOptions, e as IProgramAccount, f as TransactionFailedError } from '../types-DGCX8JLm.cjs';
4
+ import PQueue from 'p-queue';
5
5
  import { Mint } from '@solana/spl-token';
6
6
  import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
7
- import PQueue from 'p-queue';
8
7
 
9
8
  declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
10
9
 
11
10
  declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
12
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
+ }
13
18
  /**
14
- * Converts a string or PublicKey to a PublicKey object.
15
- * @param address - The input address as a string or PublicKey.
16
- * @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.
17
21
  */
18
- declare const pk: (address: string | PublicKey) => PublicKey;
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
+ };
34
+ }
35
+ interface Account {
36
+ pubkey: PublicKey;
37
+ account: AccountInfo<Buffer>;
38
+ }
39
+ interface CheckAssociatedTokenAccountsData {
40
+ sender: PublicKey;
41
+ recipient: PublicKey;
42
+ partner: PublicKey;
43
+ streamflowTreasury: PublicKey;
44
+ mint: PublicKey;
45
+ }
46
+ interface AtaParams {
47
+ mint: PublicKey;
48
+ owner: PublicKey;
49
+ programId?: PublicKey;
50
+ }
51
+ interface ConfirmationParams {
52
+ hash: BlockhashWithExpiryBlockHeight;
53
+ context: Context;
54
+ commitment?: Commitment;
55
+ }
56
+ interface ThrottleParams {
57
+ sendRate?: number;
58
+ sendThrottler?: PQueue;
59
+ waitBeforeConfirming?: number | undefined;
60
+ }
61
+ interface TransactionExecutionParams extends ThrottleParams {
62
+ skipSimulation?: boolean;
63
+ }
64
+ interface IProgramAccount<T> {
65
+ publicKey: PublicKey;
66
+ account: T;
67
+ }
68
+ declare class TransactionFailedError extends Error {
69
+ constructor(m: string);
70
+ }
19
71
 
20
72
  declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
21
73
  /**
@@ -67,10 +119,10 @@ declare function signTransaction<T extends Transaction | VersionedTransaction>(i
67
119
  * @param invoker - Keypair used as signer
68
120
  * @param tx - Transaction instance
69
121
  * @param confirmationParams - Confirmation Params that will be used for execution
70
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
122
+ * @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
71
123
  * @returns Transaction signature
72
124
  */
73
- declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
125
+ declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
74
126
  /**
75
127
  * Sends and confirms Transaction
76
128
  * Uses custom confirmation logic that:
@@ -83,10 +135,10 @@ declare function signAndExecuteTransaction(connection: Connection, invoker: Keyp
83
135
  * @param connection - Solana client connection
84
136
  * @param tx - Transaction instance
85
137
  * @param confirmationParams - Confirmation Params that will be used for execution
86
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
138
+ * @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
87
139
  * @returns Transaction signature
88
140
  */
89
- declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
141
+ declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
90
142
  /**
91
143
  * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
92
144
  * @param connection - Solana client connection
@@ -172,8 +224,8 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
172
224
  declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
173
225
  /**
174
226
  * Create Base instructions for Solana
175
- * - sets compute price if `computePrice` is provided
176
- * - 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).
177
229
  */
178
230
  declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
179
231
  /**
@@ -201,10 +253,6 @@ declare function getMintAndProgram(connection: Connection, address: PublicKey, c
201
253
  */
202
254
  declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
203
255
 
204
- declare function estimateComputeUnitPrice(estimate: ComputePriceEstimate, ixs: Parameters<typeof createVersionedTransaction>[0], payer: Parameters<typeof createVersionedTransaction>[1], recentBlockhash?: Parameters<typeof createVersionedTransaction>[2], partialSigners?: Parameters<typeof createVersionedTransaction>[3]): Promise<number>;
205
- declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<TransactionInstruction[]>>(createFn: CreateFn, extParams: IInteractSolanaExt): Promise<Awaited<ReturnType<CreateFn>>>;
206
- declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<any>>(createFn: CreateFn, extParams: IInteractSolanaExt, select: (result: Awaited<ReturnType<CreateFn>>) => TransactionInstruction[]): Promise<Awaited<ReturnType<CreateFn>>>;
207
-
208
256
  declare function deserializeRawTransaction(serializedTx: string): {
209
257
  type: string;
210
258
  transaction: Transaction;
@@ -216,5 +264,34 @@ declare function deserializeRawTransaction(serializedTx: string): {
216
264
  accounts: PublicKey[];
217
265
  writableAccounts: PublicKey[];
218
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>;
219
296
 
220
- export { Account, AtaParams, ComputePriceEstimate, ConfirmationParams, IInteractSolanaExt, ITransactionSolanaExt, ThrottleParams, 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, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction };
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 };
@@ -9,6 +9,19 @@ var __export = (target, all) => {
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
11
 
12
+ // solana/rpc/consume-limit-estimate/estimate.ts
13
+ var estimateConsumeLimit = async (connection, tx, options = {}) => {
14
+ const { multiplierPercent = 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 + multiplierPercent)) : simulationResults.value.unitsConsumed,
21
+ data: simulationResults
22
+ };
23
+ };
24
+
12
25
  // solana/rpc/priority-fee-estimate/percentile.ts
13
26
  var percentile_exports = {};
14
27
  __export(percentile_exports, {
@@ -19,27 +32,11 @@ function deserializeRawTransaction(serializedTx) {
19
32
  const txBuffer = buffer.Buffer.from(serializedTx, "base64");
20
33
  try {
21
34
  const tx = web3_js.Transaction.from(txBuffer);
22
- const message = tx.compileMessage();
23
- const accounts = message.accountKeys;
24
- const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
25
- return {
26
- type: "legacy",
27
- transaction: tx,
28
- accounts,
29
- writableAccounts
30
- };
35
+ return resolveTransactionAccounts(tx);
31
36
  } catch (error) {
32
37
  try {
33
38
  const vtx = web3_js.VersionedTransaction.deserialize(txBuffer);
34
- const message = vtx.message;
35
- const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
36
- const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
37
- return {
38
- type: "versioned",
39
- transaction: vtx,
40
- accounts,
41
- writableAccounts
42
- };
39
+ return resolveTransactionAccounts(vtx);
43
40
  } catch (vError) {
44
41
  throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
45
42
  cause: vError
@@ -47,6 +44,28 @@ function deserializeRawTransaction(serializedTx) {
47
44
  }
48
45
  }
49
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
+ };
50
69
 
51
70
  // solana/rpc/priority-fee-estimate/calc-fee.ts
52
71
  var resolveMedian = (values) => {
@@ -68,7 +87,7 @@ var resolveMedian = (values) => {
68
87
  var getPriorityFeeEstimate = async (connection, options) => {
69
88
  const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);
70
89
  const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));
71
- return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };
90
+ return { median: Math.ceil(median * (1 + (options.multiplierPercent ?? 0.05))), data: recentPrioritizationFee };
72
91
  };
73
92
  var getRecentPrioritizationFee = async (connection, options) => {
74
93
  const { accountsOrTx, percentile = 5e3 } = options;
@@ -101,7 +120,7 @@ var pk = (address) => {
101
120
  var getPriorityFeeEstimate2 = async (connection, options) => {
102
121
  const recentPrioritizationFee = await getRecentPrioritizationFee2(connection, options);
103
122
  const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));
104
- return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };
123
+ return { median: Math.ceil(median * (1 + (options.multiplierPercent ?? 0.05))), data: recentPrioritizationFee };
105
124
  };
106
125
  var getRecentPrioritizationFee2 = async (connection, options) => {
107
126
  return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs2(options.accountsOrTx)[0] });
@@ -111,6 +130,7 @@ var buildArgs2 = (accountsOrTx) => {
111
130
  return [accountsArray];
112
131
  };
113
132
 
133
+ exports.estimateConsumeLimit = estimateConsumeLimit;
114
134
  exports.priorityFeeEstimation = general_exports;
115
135
  exports.priorityFeeEstimationPercentile = percentile_exports;
116
136
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../solana/rpc/priority-fee-estimate/percentile.ts","../../../../solana/deserialize-raw-transaction.ts","../../../../solana/rpc/priority-fee-estimate/calc-fee.ts","../../../../solana/rpc/priority-fee-estimate/general.ts","../../../../solana/public-key.ts"],"names":["Buffer","Transaction","VersionedTransaction","getPriorityFeeEstimate","getRecentPrioritizationFee","PublicKey","buildArgs"],"mappings":";;;;;;;;;;;;AAAA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACOO,SAAS,0BAA0B,YAAsB,EAAA;AAC9D,EAAA,MAAM,QAAWA,GAAAA,aAAAA,CAAO,IAAK,CAAA,YAAA,EAAc,QAAQ,CAAA;AACnD,EAAI,IAAA;AACF,IAAM,MAAA,EAAA,GAAKC,mBAAY,CAAA,IAAA,CAAK,QAAQ,CAAA;AACpC,IAAM,MAAA,OAAA,GAAU,GAAG,cAAe,EAAA;AAClC,IAAA,MAAM,WAAW,OAAQ,CAAA,WAAA;AACzB,IAAM,MAAA,gBAAA,GAAmB,SAAS,MAAO,CAAA,CAAC,GAAG,GAAQ,KAAA,OAAA,CAAQ,iBAAkB,CAAA,GAAG,CAAC,CAAA;AACnF,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,QAAA;AAAA,MACN,WAAa,EAAA,EAAA;AAAA,MACb,QAAA;AAAA,MACA;AAAA,KACF;AAAA,WACO,KAAO,EAAA;AACd,IAAI,IAAA;AACF,MAAM,MAAA,GAAA,GAAMC,4BAAqB,CAAA,WAAA,CAAY,QAAQ,CAAA;AACrD,MAAA,MAAM,UAAU,GAAI,CAAA,OAAA;AACpB,MAAA,MAAM,QACJ,GAAA,mBAAA,IAAuB,OACnB,GAAA,OAAA,CAAQ,oBACP,OAAmD,CAAA,WAAA;AAE1D,MAAM,MAAA,gBAAA,GAAmB,SAAS,MAAO,CAAA,CAAC,GAAG,GAAQ,KAAA,OAAA,CAAQ,iBAAkB,CAAA,GAAG,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,MAAA,GAAS,cAAc,uBAAwB,CAAA,GAAA,CAAI,CAAC,CAAM,KAAA,CAAA,CAAE,iBAAiB,CAAC,CAAA;AACpF,EAAO,OAAA,EAAE,QAAQ,MAAU,IAAA,CAAA,IAAK,QAAQ,gBAAoB,IAAA,IAAA,CAAA,CAAA,EAAQ,MAAM,uBAAwB,EAAA;AACpG,CAAA;AAEO,IAAMA,2BAAAA,GAA6B,OACxC,UAAA,EACA,OACG,KAAA;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 { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\ntype RpcRequest = (methodName: string, args: Array<any> | ReadonlyArray<any>) => Promise<any>;\ninterface RecentPrioritizationFee {\n result: Array<{ prioritizationFee: number; slot: number }>;\n}\n\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));\n return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };\n};\n\n/**\n * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\" | \"percentile\">,\n): Promise<RecentPrioritizationFee> => {\n const { accountsOrTx, percentile = 5000 } = options;\n\n return (connection as unknown as { _rpcRequest: RpcRequest })._rpcRequest(\n \"getRecentPrioritizationFees\",\n buildArgs(accountsOrTx, percentile),\n ) as Promise<RecentPrioritizationFee>;\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string, percentile: number) => {\n const accountsArray =\n accountsOrTx instanceof Array\n ? accountsOrTx.map((a) => a.toString())\n : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());\n return [\n accountsArray,\n {\n percentile,\n },\n ] as const;\n};\n","import { Transaction, VersionedTransaction, type PublicKey } from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\ninterface TransactionAccountsProvider {\n accountKeys: PublicKey[];\n}\n\nexport function deserializeRawTransaction(serializedTx: string) {\n const txBuffer = Buffer.from(serializedTx, \"base64\");\n try {\n const tx = Transaction.from(txBuffer);\n const message = tx.compileMessage();\n const accounts = message.accountKeys;\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"legacy\",\n transaction: tx,\n accounts,\n writableAccounts,\n };\n } catch (error) {\n try {\n const vtx = VersionedTransaction.deserialize(txBuffer);\n const message = vtx.message;\n const accounts =\n \"staticAccountKeys\" in message\n ? message.staticAccountKeys\n : (message as unknown as TransactionAccountsProvider).accountKeys;\n\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"versioned\",\n transaction: vtx,\n accounts,\n writableAccounts,\n };\n } catch (vError) {\n throw new Error(\"Failed to deserialize transaction: \" + (vError instanceof Error ? vError.message : vError), {\n cause: vError,\n });\n }\n }\n}\n","export const resolveMedian = (values: number[]) => {\n if (values.length < 2) {\n return 0;\n }\n\n const sortedRates = [...values].sort((a, b) => a - b);\n const medianIndex = Math.floor(sortedRates.length / 2);\n const medianArrValue = sortedRates[medianIndex];\n const medianPrevValue = sortedRates[medianIndex - 1];\n\n if (medianPrevValue === undefined || medianArrValue === undefined) {\n return 0;\n }\n\n const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;\n\n return medianValue;\n};\n","import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport { pk } from \"../../public-key.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));\n return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };\n};\n\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\">,\n) => {\n return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs(options.accountsOrTx)[0] });\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string) => {\n const accountsArray =\n accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;\n return [accountsArray] as const;\n};\n","import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Converts a string or PublicKey to a PublicKey object.\n * @param address - The input address as a string or PublicKey.\n * @returns The PublicKey object.\n */\nexport const pk = (address: string | PublicKey): PublicKey => {\n return typeof address === \"string\" ? new PublicKey(address) : address;\n};\n"]}
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,iBAAoB,GAAA,IAAA,EAAS,GAAA,OAAA;AACrC,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,iBAAkB,CAAA,CAAA,GACzE,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,EAAA;AACd,IAAI,IAAA;AACF,MAAM,MAAA,GAAA,GAAMC,4BAAqB,CAAA,WAAA,CAAY,QAAQ,CAAA;AACrD,MAAA,OAAO,2BAA2B,GAAG,CAA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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 { multiplierPercent = 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 + multiplierPercent))\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.multiplierPercent ?? 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.multiplierPercent ?? 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"]}
@@ -1,14 +1,73 @@
1
1
  import * as _solana_web3_js from '@solana/web3.js';
2
- import { Connection } from '@solana/web3.js';
3
- import { G as GetPriorityFeeEstimateOptions } from '../../types-DGCX8JLm.cjs';
4
- import 'p-queue';
2
+ import { PublicKey, Connection, VersionedTransaction } from '@solana/web3.js';
5
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 + multiplierPercent.
24
+ * @default 0.05 = 5%
25
+ */
26
+ multiplierPercent?: 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 + multiplierPercent.
35
+ * @default 0.05 = 5%
36
+ */
37
+ multiplierPercent?: 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
+ */
6
59
  interface RecentPrioritizationFee {
7
60
  result: Array<{
8
61
  prioritizationFee: number;
9
62
  slot: number;
10
63
  }>;
11
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
+ */
12
71
  declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
13
72
  median: number;
14
73
  data: RecentPrioritizationFee;
@@ -25,10 +84,24 @@ declare namespace percentile {
25
84
  export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
26
85
  }
27
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
+ */
28
94
  declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
29
95
  median: number;
30
96
  data: _solana_web3_js.RecentPrioritizationFees[];
31
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
+ */
32
105
  declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
33
106
 
34
107
  declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
@@ -37,4 +110,4 @@ declare namespace general {
37
110
  export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
38
111
  }
39
112
 
40
- export { general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
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);
@@ -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,MAAM,OAAO,CAAA;AACnB,IAAA,IAAA,CAAK,oBAAoB,IAAQ,IAAA,IAAA;AACjC,IAAA,IAAA,CAAK,cAAc,WAAe,IAAA,IAAA;AAElC,IAAO,MAAA,CAAA,cAAA,CAAe,IAAM,EAAA,cAAA,CAAc,SAAS,CAAA;AACnD,IAAA,IAAA,CAAK,IAAO,GAAA,eAAA;AACZ,IAAA,IAAA,CAAK,QAAQ,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AQ,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.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); // 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"],"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,KAAM,CAAA,OAAA,EAAS,EAAE,KAAA,EAAO,OAAO,CAAA;AACrC,IAAA,IAAA,CAAK,oBAAoB,IAAQ,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AA;AAChC;AAQa,IAAA,eAAA,GAAkB,CAAC,KAAA,EAAW,QACzC,KAAA,KAAA,CAAM,EAAG,CAAA,IAAI,EAAG,CAAA,CAAA,IAAK,EAAK,GAAA,CAAC,CAAC,CAAA,GAAI,MAAM,GAAI,CAAA,IAAI,EAAG,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.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"]}