solana-web3-on-steroids 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/client/SteroidClient.d.ts +1 -1
- package/dist/client/SteroidClient.js +5 -25
- package/dist/client/SteroidClient.js.map +1 -1
- package/dist/connection/SteroidConnection.d.ts +1 -2
- package/dist/connection/SteroidConnection.js +27 -43
- package/dist/connection/SteroidConnection.js.map +1 -1
- package/dist/transaction/SteroidTransaction.d.ts +1 -16
- package/dist/transaction/SteroidTransaction.js +61 -101
- package/dist/transaction/SteroidTransaction.js.map +1 -1
- package/dist/types/SteroidWalletTypes.d.ts +0 -5
- package/dist/types/SteroidWalletTypes.js +0 -9
- package/dist/types/SteroidWalletTypes.js.map +1 -1
- package/dist/utils/idUtils.d.ts +10 -0
- package/dist/utils/idUtils.js +15 -0
- package/dist/utils/idUtils.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +47 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mathUtils.d.ts +13 -0
- package/dist/utils/mathUtils.js +18 -0
- package/dist/utils/mathUtils.js.map +1 -0
- package/dist/utils/solanaUtils.d.ts +21 -0
- package/dist/utils/solanaUtils.js +50 -0
- package/dist/utils/solanaUtils.js.map +1 -0
- package/dist/utils/stateUtils.d.ts +13 -0
- package/dist/utils/stateUtils.js +19 -0
- package/dist/utils/stateUtils.js.map +1 -0
- package/dist/utils/timeUtils.d.ts +5 -0
- package/dist/utils/timeUtils.js +8 -0
- package/dist/utils/timeUtils.js.map +1 -0
- package/dist/utils/walletUtils.d.ts +11 -0
- package/dist/utils/walletUtils.js +47 -0
- package/dist/utils/walletUtils.js.map +1 -0
- package/dist/wallet/SteroidWallet.d.ts +1 -4
- package/dist/wallet/SteroidWallet.js +18 -58
- package/dist/wallet/SteroidWallet.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Connection,
|
|
1
|
+
import { Connection, } from '@solana/web3.js';
|
|
2
2
|
import { TransactionState, DEFAULT_CONFIG } from '../types/SteroidWalletTypes.js';
|
|
3
|
+
import { isLegacyTransaction, sleep, Logger, parseSimulationError, isBlockhashExpiredError, serializeTransaction, generateId, clearExpiredEntries } from '../utils/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Enhanced transaction handling with state management, automatic retries,
|
|
5
6
|
* blockhash refresh, and multi-node confirmation.
|
|
@@ -7,8 +8,10 @@ import { TransactionState, DEFAULT_CONFIG } from '../types/SteroidWalletTypes.js
|
|
|
7
8
|
export class SteroidTransaction {
|
|
8
9
|
connection;
|
|
9
10
|
transactionStates = new Map();
|
|
11
|
+
logger;
|
|
10
12
|
constructor(connection) {
|
|
11
13
|
this.connection = connection;
|
|
14
|
+
this.logger = new Logger('SteroidTransaction', false);
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
17
|
* Sends a transaction with continuous re-broadcasting and multi-node monitoring.
|
|
@@ -22,7 +25,10 @@ export class SteroidTransaction {
|
|
|
22
25
|
...options,
|
|
23
26
|
};
|
|
24
27
|
const { timeoutSeconds, retryInterval, skipPreflight, preflightCommitment, confirmationCommitment, maxBlockhashAge, enableLogging, confirmationNodes, } = mergedOptions;
|
|
25
|
-
const
|
|
28
|
+
const executionTimeout = timeoutSeconds * 1000;
|
|
29
|
+
// Update logger preference for this call
|
|
30
|
+
this.logger.setEnabled(enableLogging || false);
|
|
31
|
+
const stateId = generateId('tx');
|
|
26
32
|
const state = {
|
|
27
33
|
state: TransactionState.PENDING,
|
|
28
34
|
attempts: 0,
|
|
@@ -33,30 +39,31 @@ export class SteroidTransaction {
|
|
|
33
39
|
// 1. Simulation with detailed error parsing
|
|
34
40
|
if (!skipPreflight) {
|
|
35
41
|
this.updateState(stateId, TransactionState.PENDING);
|
|
36
|
-
await this.simulateTransaction(transaction, preflightCommitment
|
|
42
|
+
await this.simulateTransaction(transaction, preflightCommitment);
|
|
37
43
|
this.updateState(stateId, TransactionState.SIMULATED);
|
|
38
44
|
}
|
|
39
45
|
// 2. Initial blockhash setup if needed
|
|
40
46
|
let blockhashContext;
|
|
41
|
-
if (
|
|
42
|
-
blockhashContext = await this.getFreshBlockhash(
|
|
47
|
+
if (isLegacyTransaction(transaction)) {
|
|
48
|
+
blockhashContext = await this.getFreshBlockhash();
|
|
43
49
|
transaction.recentBlockhash = blockhashContext.blockhash;
|
|
44
50
|
transaction.lastValidBlockHeight = blockhashContext.lastValidBlockHeight;
|
|
45
51
|
}
|
|
46
|
-
const rawTransaction = this.serializeTransaction(transaction);
|
|
47
52
|
const startTime = Date.now();
|
|
48
53
|
let signature = '';
|
|
49
54
|
let lastBlockhashRefresh = Date.now();
|
|
55
|
+
let attempts = 0;
|
|
50
56
|
// 3. Send and retry loop with blockhash refresh
|
|
51
|
-
while (Date.now() - startTime <
|
|
57
|
+
while (Date.now() - startTime < executionTimeout) {
|
|
52
58
|
try {
|
|
53
|
-
|
|
59
|
+
attempts++;
|
|
60
|
+
state.attempts = attempts; // Update state attempts
|
|
54
61
|
state.lastAttemptTime = Date.now();
|
|
55
62
|
// Check if blockhash is too old and refresh if needed
|
|
56
63
|
const ageSeconds = (Date.now() - lastBlockhashRefresh) / 1000;
|
|
57
|
-
if (ageSeconds > maxBlockhashAge &&
|
|
58
|
-
this.
|
|
59
|
-
blockhashContext = await this.getFreshBlockhash(
|
|
64
|
+
if (ageSeconds > maxBlockhashAge && isLegacyTransaction(transaction)) {
|
|
65
|
+
this.logger.info(`Blockhash age ${ageSeconds.toFixed(1)}s exceeds max ${maxBlockhashAge}s, refreshing...`);
|
|
66
|
+
blockhashContext = await this.getFreshBlockhash();
|
|
60
67
|
transaction.recentBlockhash = blockhashContext.blockhash;
|
|
61
68
|
transaction.lastValidBlockHeight = blockhashContext.lastValidBlockHeight;
|
|
62
69
|
// Re-serialize with new blockhash
|
|
@@ -64,34 +71,48 @@ export class SteroidTransaction {
|
|
|
64
71
|
lastBlockhashRefresh = Date.now();
|
|
65
72
|
}
|
|
66
73
|
// Broadcast transaction
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
this.logger.info(`Sending transaction (Attempt ${attempts})...`);
|
|
75
|
+
try {
|
|
76
|
+
const rawTransaction = serializeTransaction(transaction);
|
|
77
|
+
signature = await this.connection.sendRawTransaction(rawTransaction, {
|
|
78
|
+
skipPreflight: true,
|
|
79
|
+
maxRetries: 0, // We handle retries ourselves
|
|
80
|
+
});
|
|
81
|
+
this.logger.info(`Transaction sent: ${signature}`);
|
|
82
|
+
}
|
|
83
|
+
catch (sendError) {
|
|
84
|
+
if (isBlockhashExpiredError(sendError)) {
|
|
85
|
+
this.logger.warn('Blockhash expired during send, refreshing...');
|
|
86
|
+
lastBlockhashRefresh = 0; // Force refresh on next iteration
|
|
87
|
+
continue; // Skip to next iteration to refresh blockhash
|
|
88
|
+
}
|
|
89
|
+
throw sendError; // Re-throw other errors
|
|
90
|
+
}
|
|
71
91
|
this.updateState(stateId, TransactionState.SENT, signature);
|
|
72
|
-
this.
|
|
92
|
+
this.logger.info(`Transaction sent: ${signature} (attempt ${state.attempts})`);
|
|
73
93
|
// 4. Multi-node confirmation check
|
|
74
|
-
|
|
94
|
+
this.logger.info(`Polling for confirmation on ${confirmationNodes} nodes...`);
|
|
95
|
+
const confirmed = await this.pollForConfirmation(signature, confirmationCommitment, confirmationNodes);
|
|
75
96
|
if (confirmed) {
|
|
76
97
|
this.updateState(stateId, TransactionState.CONFIRMED, signature);
|
|
77
98
|
state.confirmedAt = Date.now();
|
|
78
99
|
const duration = ((state.confirmedAt - state.startTime) / 1000).toFixed(2);
|
|
79
|
-
this.
|
|
100
|
+
this.logger.info(`Transaction confirmed in ${duration}s after ${state.attempts} attempts`);
|
|
80
101
|
return signature;
|
|
81
102
|
}
|
|
82
|
-
this.
|
|
103
|
+
this.logger.warn(`Transaction not yet confirmed, will retry in ${retryInterval}ms...`);
|
|
83
104
|
}
|
|
84
105
|
catch (error) {
|
|
85
106
|
// Handle blockhash expiration
|
|
86
|
-
if (
|
|
87
|
-
this.
|
|
107
|
+
if (isBlockhashExpiredError(error)) {
|
|
108
|
+
this.logger.warn('Blockhash expired or invalid, will refresh on next attempt');
|
|
88
109
|
lastBlockhashRefresh = 0; // Force refresh on next iteration
|
|
89
110
|
}
|
|
90
111
|
else {
|
|
91
|
-
this.
|
|
112
|
+
this.logger.warn(`Broadcast attempt failed: ${error.message}`);
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
|
-
await
|
|
115
|
+
await sleep(retryInterval);
|
|
95
116
|
}
|
|
96
117
|
// Timeout reached
|
|
97
118
|
const errorMsg = `Transaction not confirmed within ${timeoutSeconds}s after ${state.attempts} attempts`;
|
|
@@ -99,26 +120,31 @@ export class SteroidTransaction {
|
|
|
99
120
|
throw new Error(`[SteroidTransaction] ${errorMsg}. Last signature: ${signature || 'none'}`);
|
|
100
121
|
}
|
|
101
122
|
catch (error) {
|
|
123
|
+
this.logger.error('Transaction failed:', error.message);
|
|
102
124
|
this.updateState(stateId, TransactionState.FAILED, state.signature, error.message);
|
|
103
125
|
throw error;
|
|
104
126
|
}
|
|
127
|
+
finally {
|
|
128
|
+
this.logger.setEnabled(false); // Reset logger state
|
|
129
|
+
}
|
|
105
130
|
}
|
|
106
131
|
/**
|
|
107
132
|
* Simulates a transaction and provides detailed error information.
|
|
108
133
|
*/
|
|
109
|
-
async simulateTransaction(transaction, commitment
|
|
134
|
+
async simulateTransaction(transaction, commitment) {
|
|
110
135
|
try {
|
|
136
|
+
this.logger.info('Simulating transaction...');
|
|
111
137
|
const simulation = await this.connection.simulateTransaction(transaction, {
|
|
112
138
|
commitment,
|
|
113
139
|
replaceRecentBlockhash: true,
|
|
114
140
|
});
|
|
115
141
|
if (simulation.value.err) {
|
|
116
|
-
const errorDetails =
|
|
117
|
-
this.
|
|
142
|
+
const errorDetails = parseSimulationError(simulation.value);
|
|
143
|
+
this.logger.error(`Simulation failed: ${errorDetails}`);
|
|
118
144
|
throw new Error(`[SteroidTransaction] Simulation failed: ${errorDetails}`);
|
|
119
145
|
}
|
|
120
146
|
if (simulation.value.logs) {
|
|
121
|
-
this.
|
|
147
|
+
this.logger.info(`Simulation succeeded. Logs count: ${simulation.value.logs.length}`);
|
|
122
148
|
}
|
|
123
149
|
}
|
|
124
150
|
catch (error) {
|
|
@@ -130,10 +156,10 @@ export class SteroidTransaction {
|
|
|
130
156
|
/**
|
|
131
157
|
* Polls multiple RPC endpoints for signature status to bypass node lag.
|
|
132
158
|
*/
|
|
133
|
-
async pollForConfirmation(signature, commitment, nodesToCheck
|
|
159
|
+
async pollForConfirmation(signature, commitment, nodesToCheck) {
|
|
134
160
|
const endpoints = this.connection.getEndpoints();
|
|
135
161
|
const endpointsToCheck = endpoints.slice(0, Math.min(nodesToCheck, endpoints.length));
|
|
136
|
-
this.
|
|
162
|
+
this.logger.info(`Checking confirmation across ${endpointsToCheck.length} nodes...`);
|
|
137
163
|
const checks = endpointsToCheck.map(async (url) => {
|
|
138
164
|
try {
|
|
139
165
|
const tempConn = new Connection(url, { commitment });
|
|
@@ -144,13 +170,13 @@ export class SteroidTransaction {
|
|
|
144
170
|
const isConfirmed = status.value?.confirmationStatus === 'confirmed' ||
|
|
145
171
|
status.value?.confirmationStatus === 'finalized';
|
|
146
172
|
if (isConfirmed && status.value) {
|
|
147
|
-
this.
|
|
173
|
+
this.logger.info(`Transaction confirmed on ${url} (${status.value.confirmationStatus})`);
|
|
148
174
|
return true;
|
|
149
175
|
}
|
|
150
176
|
return false;
|
|
151
177
|
}
|
|
152
178
|
catch (error) {
|
|
153
|
-
this.
|
|
179
|
+
this.logger.warn(`Confirmation check failed for ${url}: ${error.message}`);
|
|
154
180
|
return false;
|
|
155
181
|
}
|
|
156
182
|
});
|
|
@@ -166,58 +192,17 @@ export class SteroidTransaction {
|
|
|
166
192
|
/**
|
|
167
193
|
* Get fresh blockhash with retry logic.
|
|
168
194
|
*/
|
|
169
|
-
async getFreshBlockhash(
|
|
195
|
+
async getFreshBlockhash() {
|
|
170
196
|
try {
|
|
197
|
+
this.logger.info('Fetching fresh blockhash...');
|
|
171
198
|
const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash('confirmed');
|
|
172
|
-
this.
|
|
199
|
+
this.logger.info(`Fetched fresh blockhash: ${blockhash.slice(0, 8)}...`);
|
|
173
200
|
return { blockhash, lastValidBlockHeight };
|
|
174
201
|
}
|
|
175
202
|
catch (error) {
|
|
176
203
|
throw new Error(`[SteroidTransaction] Failed to get blockhash: ${error.message}`);
|
|
177
204
|
}
|
|
178
205
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Parse simulation errors into human-readable format.
|
|
181
|
-
*/
|
|
182
|
-
parseSimulationError(simulationValue) {
|
|
183
|
-
const logs = simulationValue.logs || [];
|
|
184
|
-
const errorLog = logs.find((l) => l.includes('Error:') || l.includes('failed') || l.includes('custom program error'));
|
|
185
|
-
if (errorLog)
|
|
186
|
-
return errorLog;
|
|
187
|
-
if (simulationValue.err) {
|
|
188
|
-
if (typeof simulationValue.err === 'string')
|
|
189
|
-
return simulationValue.err;
|
|
190
|
-
if (simulationValue.err.InstructionError) {
|
|
191
|
-
const [index, error] = simulationValue.err.InstructionError;
|
|
192
|
-
return `Instruction ${index} failed: ${JSON.stringify(error)}`;
|
|
193
|
-
}
|
|
194
|
-
return JSON.stringify(simulationValue.err);
|
|
195
|
-
}
|
|
196
|
-
return 'Unknown simulation error';
|
|
197
|
-
}
|
|
198
|
-
isBlockhashExpiredError(error) {
|
|
199
|
-
return (error instanceof TransactionExpiredBlockheightExceededError ||
|
|
200
|
-
error.message?.includes('block height exceeded') ||
|
|
201
|
-
error.message?.includes('blockhash not found'));
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Type guard for legacy transactions.
|
|
205
|
-
*/
|
|
206
|
-
isLegacyTransaction(transaction) {
|
|
207
|
-
return 'recentBlockhash' in transaction;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Serialize transaction to bytes.
|
|
211
|
-
*/
|
|
212
|
-
serializeTransaction(transaction) {
|
|
213
|
-
if (this.isLegacyTransaction(transaction)) {
|
|
214
|
-
return transaction.serialize();
|
|
215
|
-
}
|
|
216
|
-
return Buffer.from(transaction.serialize());
|
|
217
|
-
}
|
|
218
|
-
generateStateId() {
|
|
219
|
-
return `tx_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
220
|
-
}
|
|
221
206
|
updateState(stateId, state, signature, error) {
|
|
222
207
|
const existing = this.transactionStates.get(stateId);
|
|
223
208
|
if (existing) {
|
|
@@ -228,26 +213,6 @@ export class SteroidTransaction {
|
|
|
228
213
|
existing.error = error;
|
|
229
214
|
}
|
|
230
215
|
}
|
|
231
|
-
log(level, message, enabled) {
|
|
232
|
-
if (!enabled)
|
|
233
|
-
return;
|
|
234
|
-
const prefix = '[SteroidTransaction]';
|
|
235
|
-
const formattedMessage = `${prefix} ${message}`;
|
|
236
|
-
switch (level) {
|
|
237
|
-
case 'info':
|
|
238
|
-
console.log(formattedMessage);
|
|
239
|
-
break;
|
|
240
|
-
case 'warn':
|
|
241
|
-
console.warn(formattedMessage);
|
|
242
|
-
break;
|
|
243
|
-
case 'error':
|
|
244
|
-
console.error(formattedMessage);
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
sleep(ms) {
|
|
249
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
250
|
-
}
|
|
251
216
|
/**
|
|
252
217
|
* Get the current state of a transaction.
|
|
253
218
|
*/
|
|
@@ -264,12 +229,7 @@ export class SteroidTransaction {
|
|
|
264
229
|
* Clear old transaction states (cleanup).
|
|
265
230
|
*/
|
|
266
231
|
clearOldStates(olderThanMs = 3600000) {
|
|
267
|
-
|
|
268
|
-
for (const [id, state] of this.transactionStates.entries()) {
|
|
269
|
-
if (now - state.startTime > olderThanMs) {
|
|
270
|
-
this.transactionStates.delete(id);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
232
|
+
clearExpiredEntries(this.transactionStates, olderThanMs);
|
|
273
233
|
}
|
|
274
234
|
}
|
|
275
235
|
//# sourceMappingURL=SteroidTransaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SteroidTransaction.js","sourceRoot":"","sources":["../../src/transaction/SteroidTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"SteroidTransaction.js","sourceRoot":"","sources":["../../src/transaction/SteroidTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAOX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAsB,gBAAgB,EAAwB,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAC5H,OAAO,EACL,mBAAmB,EACnB,KAAK,EACL,MAAM,EACN,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,UAAU,EACV,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACrB,UAAU,CAAoB;IAC9B,iBAAiB,GAAsC,IAAI,GAAG,EAAE,CAAC;IACjE,MAAM,CAAS;IAEvB,YAAY,UAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;IAGD;;;OAGG;IACH,KAAK,CAAC,cAAc,CAClB,WAA+C,EAC/C,UAA8B,EAAE;QAEhC,MAAM,aAAa,GAAG;YACpB,aAAa,EAAE,KAAK;YACpB,mBAAmB,EAAE,WAAyB;YAC9C,GAAG,cAAc,CAAC,WAAW;YAC7B,GAAG,OAAO;SACX,CAAC;QAEF,MAAM,EACJ,cAAc,EACd,aAAa,EACb,aAAa,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,mBAAmB,CAAC,OAAe;QACxC,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,cAAc,CAAC,cAAsB,OAAO;QACjD,mBAAmB,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -100,11 +100,6 @@ export type TransactionResult = {
|
|
|
100
100
|
};
|
|
101
101
|
export type ErrorHandler = (error: Error) => void | Promise<void>;
|
|
102
102
|
export type TransactionCallback = (signature: TransactionSignature, state: TransactionStateInfo) => void | Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Type guards
|
|
105
|
-
*/
|
|
106
|
-
export declare function isLegacyTransaction(transaction: AnyTransaction): transaction is Transaction;
|
|
107
|
-
export declare function isVersionedTransaction(transaction: AnyTransaction): transaction is VersionedTransaction;
|
|
108
103
|
/**
|
|
109
104
|
* Helper types for improved DX
|
|
110
105
|
*/
|
|
@@ -18,15 +18,6 @@ export var WalletErrorType;
|
|
|
18
18
|
WalletErrorType["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
19
19
|
WalletErrorType["UNKNOWN"] = "UNKNOWN";
|
|
20
20
|
})(WalletErrorType || (WalletErrorType = {}));
|
|
21
|
-
/**
|
|
22
|
-
* Type guards
|
|
23
|
-
*/
|
|
24
|
-
export function isLegacyTransaction(transaction) {
|
|
25
|
-
return 'recentBlockhash' in transaction;
|
|
26
|
-
}
|
|
27
|
-
export function isVersionedTransaction(transaction) {
|
|
28
|
-
return 'version' in transaction;
|
|
29
|
-
}
|
|
30
21
|
/**
|
|
31
22
|
* Constants
|
|
32
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SteroidWalletTypes.js","sourceRoot":"","sources":["../../src/types/SteroidWalletTypes.ts"],"names":[],"mappings":"AA2DA,MAAM,CAAN,IAAY,gBASX;AATD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,2CAAuB,CAAA;IACvB,qCAAiB,CAAA;IACjB,iCAAa,CAAA;IACb,2CAAuB,CAAA;IACvB,2CAAuB,CAAA;IACvB,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EATW,gBAAgB,KAAhB,gBAAgB,QAS3B;AAqBD,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,kDAA+B,CAAA;IAC/B,kDAA+B,CAAA;IAC/B,wDAAqC,CAAA;IACrC,oDAAiC,CAAA;IACjC,kEAA+C,CAAA;IAC/C,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;
|
|
1
|
+
{"version":3,"file":"SteroidWalletTypes.js","sourceRoot":"","sources":["../../src/types/SteroidWalletTypes.ts"],"names":[],"mappings":"AA2DA,MAAM,CAAN,IAAY,gBASX;AATD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,2CAAuB,CAAA;IACvB,qCAAiB,CAAA;IACjB,iCAAa,CAAA;IACb,2CAAuB,CAAA;IACvB,2CAAuB,CAAA;IACvB,qCAAiB,CAAA;IACjB,uCAAmB,CAAA;AACrB,CAAC,EATW,gBAAgB,KAAhB,gBAAgB,QAS3B;AAqBD,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,kDAA+B,CAAA;IAC/B,kDAA+B,CAAA;IAC/B,wDAAqC,CAAA;IACrC,oDAAiC,CAAA;IACjC,kEAA+C,CAAA;IAC/C,sCAAmB,CAAA;AACrB,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B;AAkFD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU,EAAE;QACV,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,GAAG;QACf,mBAAmB,EAAE,KAAK;QAC1B,cAAc,EAAE,KAAK;QACrB,aAAa,EAAE,KAAK;KACrB;IACD,WAAW,EAAE;QACX,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,IAAI;QACnB,sBAAsB,EAAE,WAAyB;QACjD,eAAe,EAAE,EAAE;QACnB,iBAAiB,EAAE,CAAC;QACpB,aAAa,EAAE,KAAK;KACrB;IACD,MAAM,EAAE;QACN,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,KAAK;QACpB,oBAAoB,EAAE,IAAI;QAC1B,eAAe,EAAE,EAAE;KACpB;CACO,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ID generation utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique, timestamped identifier with an optional prefix.
|
|
6
|
+
*
|
|
7
|
+
* @param prefix - Optional prefix for the ID
|
|
8
|
+
* @returns A unique string ID
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateId(prefix?: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ID generation utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generates a unique, timestamped identifier with an optional prefix.
|
|
6
|
+
*
|
|
7
|
+
* @param prefix - Optional prefix for the ID
|
|
8
|
+
* @returns A unique string ID
|
|
9
|
+
*/
|
|
10
|
+
export function generateId(prefix = '') {
|
|
11
|
+
const timestamp = Date.now();
|
|
12
|
+
const randomPart = Math.random().toString(36).substring(2, 11);
|
|
13
|
+
return prefix ? `${prefix}_${timestamp}_${randomPart}` : `${timestamp}_${randomPart}`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=idUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idUtils.js","sourceRoot":"","sources":["../../src/utils/idUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE;IAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,UAAU,EAAE,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './solanaUtils.js';
|
|
2
|
+
export * from './timeUtils.js';
|
|
3
|
+
export * from './logger.js';
|
|
4
|
+
export * from './mathUtils.js';
|
|
5
|
+
export * from './walletUtils.js';
|
|
6
|
+
export * from './idUtils.js';
|
|
7
|
+
export * from './stateUtils.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Logger utility to provide consistent prefixed logging.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Logger {
|
|
5
|
+
private prefix;
|
|
6
|
+
private enabled;
|
|
7
|
+
constructor(prefix: string, enabled?: boolean);
|
|
8
|
+
log(level: 'info' | 'warn' | 'error', ...args: any[]): void;
|
|
9
|
+
info(...args: any[]): void;
|
|
10
|
+
warn(...args: any[]): void;
|
|
11
|
+
error(...args: any[]): void;
|
|
12
|
+
setEnabled(enabled: boolean): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Logger utility to provide consistent prefixed logging.
|
|
3
|
+
*/
|
|
4
|
+
export class Logger {
|
|
5
|
+
prefix;
|
|
6
|
+
enabled;
|
|
7
|
+
constructor(prefix, enabled = false) {
|
|
8
|
+
this.prefix = prefix;
|
|
9
|
+
this.enabled = enabled;
|
|
10
|
+
}
|
|
11
|
+
log(level, ...args) {
|
|
12
|
+
if (!this.enabled)
|
|
13
|
+
return;
|
|
14
|
+
const formattedPrefix = `[${this.prefix}]`;
|
|
15
|
+
const finalArgs = [...args];
|
|
16
|
+
if (typeof finalArgs[0] === 'string') {
|
|
17
|
+
finalArgs[0] = `${formattedPrefix} ${finalArgs[0]}`;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
finalArgs.unshift(formattedPrefix);
|
|
21
|
+
}
|
|
22
|
+
switch (level) {
|
|
23
|
+
case 'info':
|
|
24
|
+
console.log(...finalArgs);
|
|
25
|
+
break;
|
|
26
|
+
case 'warn':
|
|
27
|
+
console.warn(...finalArgs);
|
|
28
|
+
break;
|
|
29
|
+
case 'error':
|
|
30
|
+
console.error(...finalArgs);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
info(...args) {
|
|
35
|
+
this.log('info', ...args);
|
|
36
|
+
}
|
|
37
|
+
warn(...args) {
|
|
38
|
+
this.log('warn', ...args);
|
|
39
|
+
}
|
|
40
|
+
error(...args) {
|
|
41
|
+
this.log('error', ...args);
|
|
42
|
+
}
|
|
43
|
+
setEnabled(enabled) {
|
|
44
|
+
this.enabled = enabled;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO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OAAgB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Math and calculation utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Calculates an exponential backoff delay with jitter.
|
|
6
|
+
*
|
|
7
|
+
* @param attempt - The current attempt number (starts at 1)
|
|
8
|
+
* @param baseDelay - The base delay in milliseconds
|
|
9
|
+
* @param maxDelay - The maximum allowed delay
|
|
10
|
+
* @param jitter - The optional jitter factor in milliseconds
|
|
11
|
+
* @returns The calculated delay in milliseconds
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateBackoff(attempt: number, baseDelay: number, maxDelay: number, jitter?: number): number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Math and calculation utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Calculates an exponential backoff delay with jitter.
|
|
6
|
+
*
|
|
7
|
+
* @param attempt - The current attempt number (starts at 1)
|
|
8
|
+
* @param baseDelay - The base delay in milliseconds
|
|
9
|
+
* @param maxDelay - The maximum allowed delay
|
|
10
|
+
* @param jitter - The optional jitter factor in milliseconds
|
|
11
|
+
* @returns The calculated delay in milliseconds
|
|
12
|
+
*/
|
|
13
|
+
export function calculateBackoff(attempt, baseDelay, maxDelay, jitter = 100) {
|
|
14
|
+
const exponentialDelay = baseDelay * Math.pow(2, attempt - 1);
|
|
15
|
+
const randomJitter = Math.random() * jitter;
|
|
16
|
+
return Math.min(exponentialDelay + randomJitter, maxDelay);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=mathUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mathUtils.js","sourceRoot":"","sources":["../../src/utils/mathUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAe,EACf,SAAiB,EACjB,QAAgB,EAChB,SAAiB,GAAG;IAEpB,MAAM,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;IAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,YAAY,EAAE,QAAQ,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for legacy transactions.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isLegacyTransaction(transaction: Transaction | VersionedTransaction): transaction is Transaction;
|
|
6
|
+
/**
|
|
7
|
+
* Type guard for versioned transactions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isVersionedTransaction(transaction: Transaction | VersionedTransaction): transaction is VersionedTransaction;
|
|
10
|
+
/**
|
|
11
|
+
* Parse simulation errors into a human-readable format.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseSimulationError(simulationValue: any): string;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if an error indicates a blockhash expiration.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isBlockhashExpiredError(error: any): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Serialize transaction to bytes consistently.
|
|
20
|
+
*/
|
|
21
|
+
export declare function serializeTransaction(transaction: Transaction | VersionedTransaction): Buffer;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TransactionExpiredBlockheightExceededError } from '@solana/web3.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for legacy transactions.
|
|
4
|
+
*/
|
|
5
|
+
export function isLegacyTransaction(transaction) {
|
|
6
|
+
return 'recentBlockhash' in transaction;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Type guard for versioned transactions.
|
|
10
|
+
*/
|
|
11
|
+
export function isVersionedTransaction(transaction) {
|
|
12
|
+
return 'version' in transaction;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse simulation errors into a human-readable format.
|
|
16
|
+
*/
|
|
17
|
+
export function parseSimulationError(simulationValue) {
|
|
18
|
+
const logs = simulationValue.logs || [];
|
|
19
|
+
const errorLog = logs.find((l) => l.includes('Error:') || l.includes('failed') || l.includes('custom program error'));
|
|
20
|
+
if (errorLog)
|
|
21
|
+
return errorLog;
|
|
22
|
+
if (simulationValue.err) {
|
|
23
|
+
if (typeof simulationValue.err === 'string')
|
|
24
|
+
return simulationValue.err;
|
|
25
|
+
if (simulationValue.err.InstructionError) {
|
|
26
|
+
const [index, error] = simulationValue.err.InstructionError;
|
|
27
|
+
return `Instruction ${index} failed: ${JSON.stringify(error)}`;
|
|
28
|
+
}
|
|
29
|
+
return JSON.stringify(simulationValue.err);
|
|
30
|
+
}
|
|
31
|
+
return 'Unknown simulation error';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if an error indicates a blockhash expiration.
|
|
35
|
+
*/
|
|
36
|
+
export function isBlockhashExpiredError(error) {
|
|
37
|
+
return (error instanceof TransactionExpiredBlockheightExceededError ||
|
|
38
|
+
error.message?.includes('block height exceeded') ||
|
|
39
|
+
error.message?.includes('blockhash not found'));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Serialize transaction to bytes consistently.
|
|
43
|
+
*/
|
|
44
|
+
export function serializeTransaction(transaction) {
|
|
45
|
+
if (isLegacyTransaction(transaction)) {
|
|
46
|
+
return transaction.serialize();
|
|
47
|
+
}
|
|
48
|
+
return Buffer.from(transaction.serialize());
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=solanaUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solanaUtils.js","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"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E,QAAQ,CAAC,uBAAuB,CAAC;QAChD,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAC/C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAA+C;IAClF,IAAI,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC;QACrC,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAE,WAAoC,CAAC,SAAS,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State and Map management utilities.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Clears entries from a Map that are older than a specified duration.
|
|
6
|
+
* Assumes the Map values have a 'startTime' property.
|
|
7
|
+
*
|
|
8
|
+
* @param map - The Map to clean up
|
|
9
|
+
* @param maxAgeMs - Maximum allowed age in milliseconds
|
|
10
|
+
*/
|
|
11
|
+
export declare function clearExpiredEntries<T extends {
|
|
12
|
+
startTime: number;
|
|
13
|
+
}>(map: Map<string, T>, maxAgeMs: number): void;
|