@streamflow/common 7.5.3 → 8.0.0-alpha.p284.726ba98

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.
Files changed (38) hide show
  1. package/dist/cjs/index.cjs +90 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs/index.d.cts +66 -0
  4. package/dist/cjs/solana/index.cjs +1039 -0
  5. package/dist/cjs/solana/index.cjs.map +1 -0
  6. package/dist/{esm/solana/utils.d.ts → cjs/solana/index.d.cts} +79 -27
  7. package/dist/esm/index.d.ts +66 -3
  8. package/dist/esm/index.js +76 -3
  9. package/dist/esm/index.js.map +1 -0
  10. package/dist/esm/solana/index.d.ts +239 -5
  11. package/dist/esm/solana/index.js +1008 -5
  12. package/dist/esm/solana/index.js.map +1 -0
  13. package/package.json +25 -15
  14. package/dist/cjs/index.js +0 -19
  15. package/dist/cjs/lib/assertions.js +0 -13
  16. package/dist/cjs/lib/utils.js +0 -62
  17. package/dist/cjs/solana/account-filters.js +0 -19
  18. package/dist/cjs/solana/index.js +0 -21
  19. package/dist/cjs/solana/instructions.js +0 -22
  20. package/dist/cjs/solana/public-key.js +0 -13
  21. package/dist/cjs/solana/types.js +0 -11
  22. package/dist/cjs/solana/utils.js +0 -478
  23. package/dist/cjs/types.js +0 -40
  24. package/dist/esm/lib/assertions.d.ts +0 -1
  25. package/dist/esm/lib/assertions.js +0 -9
  26. package/dist/esm/lib/utils.d.ts +0 -28
  27. package/dist/esm/lib/utils.js +0 -51
  28. package/dist/esm/solana/account-filters.d.ts +0 -2
  29. package/dist/esm/solana/account-filters.js +0 -15
  30. package/dist/esm/solana/instructions.d.ts +0 -3
  31. package/dist/esm/solana/instructions.js +0 -18
  32. package/dist/esm/solana/public-key.d.ts +0 -7
  33. package/dist/esm/solana/public-key.js +0 -9
  34. package/dist/esm/solana/types.d.ts +0 -39
  35. package/dist/esm/solana/types.js +0 -7
  36. package/dist/esm/solana/utils.js +0 -450
  37. package/dist/esm/types.d.ts +0 -32
  38. package/dist/esm/types.js +0 -38
@@ -1,39 +0,0 @@
1
- import { AccountInfo, BlockhashWithExpiryBlockHeight, Commitment, Context, PublicKey } from "@solana/web3.js";
2
- import PQueue from "p-queue";
3
- export interface ITransactionSolanaExt {
4
- computePrice?: number;
5
- computeLimit?: number;
6
- }
7
- export interface Account {
8
- pubkey: PublicKey;
9
- account: AccountInfo<Buffer>;
10
- }
11
- export interface CheckAssociatedTokenAccountsData {
12
- sender: PublicKey;
13
- recipient: PublicKey;
14
- partner: PublicKey;
15
- streamflowTreasury: PublicKey;
16
- mint: PublicKey;
17
- }
18
- export interface AtaParams {
19
- mint: PublicKey;
20
- owner: PublicKey;
21
- programId?: PublicKey;
22
- }
23
- export interface ConfirmationParams {
24
- hash: BlockhashWithExpiryBlockHeight;
25
- context: Context;
26
- commitment?: Commitment;
27
- }
28
- export interface ThrottleParams {
29
- sendRate?: number;
30
- sendThrottler?: PQueue;
31
- waitBeforeConfirming?: number | undefined;
32
- }
33
- export interface IProgramAccount<T> {
34
- publicKey: PublicKey;
35
- account: T;
36
- }
37
- export declare class TransactionFailedError extends Error {
38
- constructor(m: string);
39
- }
@@ -1,7 +0,0 @@
1
- export class TransactionFailedError extends Error {
2
- constructor(m) {
3
- super(m);
4
- Object.setPrototypeOf(this, TransactionFailedError.prototype);
5
- this.name = "TransactionFailedError";
6
- }
7
- }
@@ -1,450 +0,0 @@
1
- import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddress, unpackMint, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, } from "@solana/spl-token";
2
- import { ComputeBudgetProgram, Keypair, TransactionMessage, VersionedTransaction, SendTransactionError, } from "@solana/web3.js";
3
- import bs58 from "bs58";
4
- import PQueue from "p-queue";
5
- import { TransactionFailedError, } from "./types.js";
6
- import { sleep } from "../lib/utils.js";
7
- const SIMULATE_TRIES = 3;
8
- export const buildSendThrottler = (sendRate, sendInterval = 1000) => {
9
- return new PQueue({ concurrency: sendRate, intervalCap: 1, interval: sendInterval });
10
- };
11
- /**
12
- * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
13
- * @param {Connection} connection - Solana web3 connection object.
14
- * @param {PublicKey} wallet - PublicKey to compare against.
15
- * @param {number} offset - Offset of bits of the PublicKey in the account binary.
16
- * @param {PublicKey} programId - Solana program ID.
17
- * @return {Promise<Account[]>} - Array of resulting accounts.
18
- */
19
- export async function getProgramAccounts(connection, wallet, offset, programId) {
20
- const programAccounts = await connection?.getProgramAccounts(programId, {
21
- filters: [
22
- {
23
- memcmp: {
24
- offset,
25
- bytes: wallet.toBase58(),
26
- },
27
- },
28
- ],
29
- });
30
- return [...programAccounts];
31
- }
32
- /**
33
- * Utility function to check if the transaction initiator is a Wallet object
34
- * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
35
- * @return {boolean} - Returns true if parameter is a Wallet.
36
- */
37
- export function isSignerWallet(walletOrKeypair) {
38
- return walletOrKeypair.signTransaction !== undefined;
39
- }
40
- /**
41
- * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
42
- * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
43
- * @returns {boolean} - Returns true if parameter is a Keypair.
44
- */
45
- export function isSignerKeypair(walletOrKeypair) {
46
- return (walletOrKeypair instanceof Keypair ||
47
- walletOrKeypair.constructor === Keypair ||
48
- walletOrKeypair.constructor.name === Keypair.prototype.constructor.name);
49
- }
50
- /**
51
- * Utility function to check whether given transaction is Versioned
52
- * @param tx {Transaction | VersionedTransaction} - Transaction to check
53
- * @returns {boolean} - Returns true if transaction is Versioned.
54
- */
55
- export function isTransactionVersioned(tx) {
56
- return "message" in tx;
57
- }
58
- /**
59
- * Creates a Transaction with given instructions and optionally signs it.
60
- * @param connection - Solana client connection
61
- * @param ixs - Instructions to add to the Transaction
62
- * @param payer - PublicKey of payer
63
- * @param commitment - optional Commitment that will be used to fetch latest blockhash
64
- * @param partialSigners - optional signers that will be used to partially sign a Transaction
65
- * @returns Transaction and Blockhash
66
- */
67
- export async function prepareTransaction(connection, ixs, payer, commitment, ...partialSigners) {
68
- if (!payer) {
69
- throw new Error("Payer public key is not provided!");
70
- }
71
- const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
72
- const messageV0 = new TransactionMessage({
73
- payerKey: payer,
74
- recentBlockhash: hash.blockhash,
75
- instructions: ixs,
76
- }).compileToV0Message();
77
- const tx = new VersionedTransaction(messageV0);
78
- const signers = partialSigners.filter((item) => !!item);
79
- tx.sign(signers);
80
- return { tx, context, hash };
81
- }
82
- export async function signTransaction(invoker, tx) {
83
- let signedTx;
84
- if (isSignerWallet(invoker)) {
85
- signedTx = await invoker.signTransaction(tx);
86
- }
87
- else {
88
- if (isTransactionVersioned(tx)) {
89
- tx.sign([invoker]);
90
- }
91
- else {
92
- tx.partialSign(invoker);
93
- }
94
- signedTx = tx;
95
- }
96
- return signedTx;
97
- }
98
- /**
99
- * Signs, sends and confirms Transaction
100
- * @param connection - Solana client connection
101
- * @param invoker - Keypair used as signer
102
- * @param tx - Transaction instance
103
- * @param confirmationParams - Confirmation Params that will be used for execution
104
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
105
- * @returns Transaction signature
106
- */
107
- export async function signAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
108
- const signedTx = await signTransaction(invoker, tx);
109
- return executeTransaction(connection, signedTx, confirmationParams, throttleParams);
110
- }
111
- /**
112
- * Sends and confirms Transaction
113
- * Uses custom confirmation logic that:
114
- * - simulates tx before sending separately
115
- * - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
116
- * - rebroadcasts a tx every 500 ms
117
- * - after broadcasting check whether tx has executed once
118
- * - catch errors for every actionable item, throw only the ones that signal that tx has failed
119
- * - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
120
- * @param connection - Solana client connection
121
- * @param tx - Transaction instance
122
- * @param confirmationParams - Confirmation Params that will be used for execution
123
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
124
- * @returns Transaction signature
125
- */
126
- export async function executeTransaction(connection, tx, confirmationParams, throttleParams) {
127
- if (tx.signatures.length === 0) {
128
- throw Error("Error with transaction parameters.");
129
- }
130
- await simulateTransaction(connection, tx);
131
- return sendAndConfirmTransaction(connection, tx, confirmationParams, throttleParams);
132
- }
133
- /**
134
- * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
135
- * @param connection - Solana client connection
136
- * @param txs - Transactions
137
- * @param confirmationParams - Confirmation Params that will be used for execution
138
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
139
- * @param throttleParams.sendRate - rate
140
- * @param throttleParams.sendThrottler - throttler instance
141
- * @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
142
- */
143
- export async function executeMultipleTransactions(connection, txs, confirmationParams, { sendRate = 1, sendThrottler, ...throttlingParams }) {
144
- if (!sendThrottler) {
145
- sendThrottler = buildSendThrottler(sendRate);
146
- }
147
- return Promise.allSettled(txs.map((tx) => executeTransaction(connection, tx, confirmationParams, {
148
- ...throttlingParams,
149
- sendRate: sendRate,
150
- sendThrottler: sendThrottler,
151
- })));
152
- }
153
- /**
154
- * Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
155
- * - we add additional 30 bocks to account for validators in an PRC pool divergence
156
- * @param connection - Solana client connection
157
- * @param tx - Transaction instance
158
- * @param confirmationParams - Confirmation Params that will be used for execution
159
- * @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
160
- * @param confirmationParams.context - context at which blockhash has been retrieve
161
- * @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
162
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
163
- * @param throttleParams.sendRate - rate
164
- * @param throttleParams.sendThrottler - throttler instance
165
- */
166
- export async function sendAndConfirmTransaction(connection, tx, { hash, context, commitment }, { sendRate = 1, sendThrottler, waitBeforeConfirming }) {
167
- const isVersioned = isTransactionVersioned(tx);
168
- let signature;
169
- if (isVersioned) {
170
- signature = bs58.encode(tx.signatures[0]);
171
- }
172
- else {
173
- signature = bs58.encode(tx.signature);
174
- }
175
- if (!sendThrottler) {
176
- sendThrottler = buildSendThrottler(sendRate);
177
- }
178
- let blockheight = await connection.getBlockHeight(commitment);
179
- let transactionSent = false;
180
- const rawTransaction = tx.serialize();
181
- while (blockheight < hash.lastValidBlockHeight + 15) {
182
- try {
183
- if (blockheight < hash.lastValidBlockHeight || !transactionSent) {
184
- await sendThrottler.add(async () => connection.sendRawTransaction(rawTransaction, {
185
- maxRetries: 0,
186
- minContextSlot: context.slot,
187
- preflightCommitment: commitment,
188
- skipPreflight: true,
189
- }));
190
- transactionSent = true;
191
- }
192
- }
193
- catch (e) {
194
- if (transactionSent ||
195
- (e instanceof SendTransactionError && e.message.includes("Minimum context slot has not been reached"))) {
196
- await sleep(500);
197
- continue;
198
- }
199
- throw e;
200
- }
201
- // Wait at least 5 slots (~400ms before confirming)
202
- await sleep(waitBeforeConfirming ?? 2000);
203
- try {
204
- const value = await confirmAndEnsureTransaction(connection, signature);
205
- if (value) {
206
- return signature;
207
- }
208
- }
209
- catch (e) {
210
- if (e instanceof TransactionFailedError) {
211
- throw e;
212
- }
213
- await sleep(500);
214
- }
215
- try {
216
- blockheight = await connection.getBlockHeight(commitment);
217
- }
218
- catch (_e) {
219
- await sleep(500);
220
- }
221
- }
222
- throw new Error(`Transaction ${signature} expired.`);
223
- }
224
- export async function simulateTransaction(connection, tx) {
225
- let res;
226
- for (let i = 0; i < SIMULATE_TRIES; i++) {
227
- if (isTransactionVersioned(tx)) {
228
- res = await connection.simulateTransaction(tx);
229
- }
230
- else {
231
- res = await connection.simulateTransaction(tx);
232
- }
233
- if (res.value.err) {
234
- const errMessage = JSON.stringify(res.value.err);
235
- if (!errMessage.includes("BlockhashNotFound") || i === SIMULATE_TRIES - 1) {
236
- throw new SendTransactionError({
237
- action: "simulate",
238
- signature: "",
239
- transactionMessage: `failed to simulate transaction: ${typeof res.value.err === "string" ? res.value.err : errMessage}`,
240
- logs: res.value.logs ?? undefined,
241
- });
242
- }
243
- continue;
244
- }
245
- return res;
246
- }
247
- throw new SendTransactionError({
248
- action: "simulate",
249
- signature: "",
250
- transactionMessage: "failed to simulate transaction",
251
- });
252
- }
253
- /**
254
- * Confirms and validates transaction success once
255
- * @param connection - Solana client connection
256
- * @param signature - Transaction signature
257
- * @param ignoreError - return status even if tx failed
258
- * @returns Transaction Status
259
- */
260
- export async function confirmAndEnsureTransaction(connection, signature, ignoreError) {
261
- const response = await connection.getSignatureStatuses([signature]);
262
- if (!response || response.value.length === 0 || response.value[0] === null) {
263
- return null;
264
- }
265
- const value = response.value[0];
266
- if (!value) {
267
- return null;
268
- }
269
- if (!ignoreError && value.err) {
270
- // That's how solana-web3js does it, `err` here is an object that won't really be handled
271
- throw new TransactionFailedError(`Raw transaction ${signature} failed (${JSON.stringify({ err: value.err })})`);
272
- }
273
- switch (connection.commitment) {
274
- case "confirmed":
275
- case "single":
276
- case "singleGossip": {
277
- if (value.confirmationStatus === "processed") {
278
- return null;
279
- }
280
- break;
281
- }
282
- case "finalized":
283
- case "max":
284
- case "root": {
285
- if (value.confirmationStatus === "processed" || value.confirmationStatus === "confirmed") {
286
- return null;
287
- }
288
- break;
289
- }
290
- // exhaust enums to ensure full coverage
291
- case "processed":
292
- case "recent":
293
- }
294
- return value;
295
- }
296
- /**
297
- * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
298
- * @param {PublicKey} mint - SPL token Mint address.
299
- * @param {PublicKey} owner - Owner of the Associated Token Address
300
- * @param {PublicKey} programId - Program ID of the mint
301
- * @return {Promise<PublicKey>} - Associated Token Address
302
- */
303
- export function ata(mint, owner, programId) {
304
- return getAssociatedTokenAddress(mint, owner, true, programId);
305
- }
306
- /**
307
- * Function that checks whether ATA exists for each provided owner
308
- * @param connection - Solana client connection
309
- * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
310
- * @returns Array of boolean where each member corresponds to an owner
311
- */
312
- export async function ataBatchExist(connection, paramsBatch) {
313
- const tokenAccounts = await Promise.all(paramsBatch.map(async ({ mint, owner, programId }) => {
314
- return ata(mint, owner, programId);
315
- }));
316
- const response = await connection.getMultipleAccountsInfo(tokenAccounts);
317
- return response.map((accInfo) => !!accInfo);
318
- }
319
- export async function enrichAtaParams(connection, paramsBatch) {
320
- const programIdByMint = {};
321
- return Promise.all(paramsBatch.map(async (params) => {
322
- if (params.programId) {
323
- return params;
324
- }
325
- const mintStr = params.mint.toString();
326
- if (!(mintStr in programIdByMint)) {
327
- const { tokenProgramId } = await getMintAndProgram(connection, params.mint);
328
- programIdByMint[mintStr] = tokenProgramId;
329
- }
330
- params.programId = programIdByMint[mintStr];
331
- return params;
332
- }));
333
- }
334
- /**
335
- * Generates a Transaction to create ATA for an array of owners
336
- * @param connection - Solana client connection
337
- * @param payer - Transaction invoker, should be a signer
338
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
339
- * @param commitment - optional commitment that will be used to fetch Blockhash
340
- * @returns Unsigned Transaction with create ATA instructions
341
- */
342
- export async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitment) {
343
- paramsBatch = await enrichAtaParams(connection, paramsBatch);
344
- const ixs = await Promise.all(paramsBatch.map(async ({ mint, owner, programId }) => {
345
- return createAssociatedTokenAccountInstruction(payer, await ata(mint, owner), owner, mint, programId);
346
- }));
347
- const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
348
- const messageV0 = new TransactionMessage({
349
- payerKey: payer,
350
- recentBlockhash: hash.blockhash,
351
- instructions: ixs,
352
- }).compileToV0Message();
353
- const tx = new VersionedTransaction(messageV0);
354
- return { tx, hash, context };
355
- }
356
- /**
357
- * Creates ATA for an array of owners
358
- * @param connection - Solana client connection
359
- * @param invoker - Transaction invoker and payer
360
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
361
- * @param commitment - optional commitment that will be used to fetch Blockhash
362
- * @param rate - throttle rate for tx sending
363
- * @returns Transaction signature
364
- */
365
- export async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
366
- const { tx, hash, context } = await generateCreateAtaBatchTx(connection, invoker.publicKey, await enrichAtaParams(connection, paramsBatch), commitment);
367
- return signAndExecuteTransaction(connection, invoker, tx, { hash, context, commitment }, { sendRate: rate });
368
- }
369
- /**
370
- * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
371
- * @param connection - Solana client connection
372
- * @param owners - Array of ATA owners
373
- * @param mint - Mint for which ATA will be checked
374
- * @param invoker - Transaction invoker and payer
375
- * @param programId - Program ID of the Mint
376
- * @returns Array of Transaction Instructions that should be added to a transaction
377
- */
378
- export async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId) {
379
- const ixs = [];
380
- if (!programId) {
381
- programId = (await getMintAndProgram(connection, mint)).tokenProgramId;
382
- }
383
- // TODO: optimize fetching and maps/arrays
384
- const atas = [];
385
- for (const owner of owners) {
386
- atas.push(await ata(mint, owner, programId));
387
- }
388
- const response = await connection.getMultipleAccountsInfo(atas);
389
- for (let i = 0; i < response.length; i++) {
390
- if (!response[i]) {
391
- ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey, atas[i], owners[i], mint, programId));
392
- }
393
- }
394
- return ixs;
395
- }
396
- /**
397
- * Create Base instructions for Solana
398
- * - sets compute price if `computePrice` is provided
399
- * - sets compute limit if `computeLimit` is provided
400
- */
401
- export function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
402
- const ixs = [];
403
- if (computePrice) {
404
- ixs.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
405
- }
406
- if (computeLimit) {
407
- ixs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
408
- }
409
- return ixs;
410
- }
411
- /**
412
- * Retrieve information about a mint and its program ID, support all Token Programs.
413
- *
414
- * @param connection Connection to use
415
- * @param address Mint account
416
- * @param commitment Desired level of commitment for querying the state
417
- *
418
- * @return Mint information
419
- */
420
- export async function getMintAndProgram(connection, address, commitment) {
421
- const accountInfo = await connection.getAccountInfo(address, commitment);
422
- let programId = accountInfo?.owner;
423
- if (!programId?.equals(TOKEN_PROGRAM_ID) && !programId?.equals(TOKEN_2022_PROGRAM_ID)) {
424
- programId = TOKEN_PROGRAM_ID;
425
- }
426
- return {
427
- mint: unpackMint(address, accountInfo, programId),
428
- tokenProgramId: programId,
429
- };
430
- }
431
- /**
432
- * Split fetching of Multiple Accounts Info into batches of 100
433
- * as the maximum number of accounts that can be fetched in a single call is 100
434
- *
435
- * @param connection Connection to use
436
- * @param pubKeys Array of public keys to fetch account info for
437
- * @param commitment Desired level of commitment for querying the state
438
- *
439
- * @return Array of AccountInfo objects
440
- */
441
- export async function getMultipleAccountsInfoBatched(connection, pubKeys, commitment) {
442
- const batchSize = 99;
443
- const batches = [];
444
- for (let i = 0; i < pubKeys.length; i += batchSize) {
445
- const batch = pubKeys.slice(i, i + batchSize);
446
- batches.push(connection.getMultipleAccountsInfo(batch, commitment));
447
- }
448
- const results = await Promise.all(batches);
449
- return results.flat();
450
- }
@@ -1,32 +0,0 @@
1
- import { TransactionInstruction } from "@solana/web3.js";
2
- export interface ITransactionResult {
3
- ixs: TransactionInstruction[];
4
- txId: string;
5
- }
6
- export declare enum ICluster {
7
- Mainnet = "mainnet",
8
- Devnet = "devnet",
9
- Testnet = "testnet",
10
- Local = "local"
11
- }
12
- export declare enum IChain {
13
- Solana = "Solana",
14
- Aptos = "Aptos",
15
- Ethereum = "Ethereum",
16
- BNB = "BNB",
17
- Polygon = "Polygon",
18
- Sui = "Sui"
19
- }
20
- /**
21
- * Error wrapper for calls made to the contract on chain
22
- */
23
- export declare class ContractError extends Error {
24
- contractErrorCode: string | null;
25
- description: string | null;
26
- /**
27
- * Constructs the Error Wrapper
28
- * @param error Original error raised probably by the chain SDK
29
- * @param code extracted code from the error if managed to parse it
30
- */
31
- constructor(error: Error, code?: string | null, description?: string | null);
32
- }
package/dist/esm/types.js DELETED
@@ -1,38 +0,0 @@
1
- // Utility types
2
- export var ICluster;
3
- (function (ICluster) {
4
- ICluster["Mainnet"] = "mainnet";
5
- ICluster["Devnet"] = "devnet";
6
- ICluster["Testnet"] = "testnet";
7
- ICluster["Local"] = "local";
8
- })(ICluster || (ICluster = {}));
9
- export var IChain;
10
- (function (IChain) {
11
- IChain["Solana"] = "Solana";
12
- IChain["Aptos"] = "Aptos";
13
- IChain["Ethereum"] = "Ethereum";
14
- IChain["BNB"] = "BNB";
15
- IChain["Polygon"] = "Polygon";
16
- IChain["Sui"] = "Sui";
17
- })(IChain || (IChain = {}));
18
- /**
19
- * Error wrapper for calls made to the contract on chain
20
- */
21
- export class ContractError extends Error {
22
- contractErrorCode;
23
- description;
24
- /**
25
- * Constructs the Error Wrapper
26
- * @param error Original error raised probably by the chain SDK
27
- * @param code extracted code from the error if managed to parse it
28
- */
29
- constructor(error, code, description) {
30
- super(error.message); // Call the base class constructor with the error message
31
- this.contractErrorCode = code ?? null;
32
- this.description = description ?? null;
33
- // Copy properties from the original error
34
- Object.setPrototypeOf(this, ContractError.prototype);
35
- this.name = "ContractError"; // Set the name property
36
- this.stack = error.stack;
37
- }
38
- }