@haven-fi/solauto-sdk 1.0.816 → 1.0.817

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 +1 @@
1
- {"version":3,"file":"clientTransactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/clientTransactionsManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,qBAAa,yBAA0B,SAAQ,mBAAmB,CAAC,aAAa,CAAC;YACjE,SAAS;YAmBT,WAAW;IA4CZ,IAAI,CAAC,YAAY,EAAE,eAAe,EAAE;CAmClD"}
1
+ {"version":3,"file":"clientTransactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/clientTransactionsManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,qBAAa,yBAA0B,SAAQ,mBAAmB,CAAC,aAAa,CAAC;YACjE,SAAS;YAmBT,WAAW;IA4CZ,IAAI,CAAC,YAAY,EAAE,eAAe,EAAE;CAmClD"}
@@ -1 +1 @@
1
- {"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,UAAU,E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AG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,MAAW,GACvB,OAAO,CAAC,GAAG,CAAC,CAMd;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,EACnC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwC7B;AAiDD,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,eAAe,GAAE,kBAA2C,EAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,EAC3B,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAoEjC"}
@@ -142,11 +142,12 @@ function getActualTxSize(umi, tx) {
142
142
  const web3Tx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(builtTx);
143
143
  // Actually serialize to get the real size
144
144
  const serialized = web3Tx.serialize();
145
+ (0, generalUtils_1.consoleLog)("[getActualTxSize] Serialization successful, size:", serialized.length);
145
146
  return serialized.length;
146
147
  }
147
148
  catch (e) {
148
149
  // Serialization failed - transaction is too large or malformed
149
- (0, generalUtils_1.consoleLog)("Transaction serialization check failed:", e);
150
+ (0, generalUtils_1.consoleLog)("[getActualTxSize] Serialization FAILED:", e?.message || e);
150
151
  return undefined;
151
152
  }
152
153
  }
@@ -155,13 +156,19 @@ function getActualTxSize(umi, tx) {
155
156
  * More accurate than getTransactionSize() estimation.
156
157
  */
157
158
  function canSerializeTransaction(umi, tx, buffer = 0) {
159
+ (0, generalUtils_1.consoleLog)("[canSerializeTransaction] Checking with buffer:", buffer);
158
160
  const size = getActualTxSize(umi, tx);
159
161
  if (size === undefined) {
162
+ (0, generalUtils_1.consoleLog)("[canSerializeTransaction] Failed - size undefined");
160
163
  return false;
161
164
  }
162
- return size + buffer <= MAX_TX_SIZE;
165
+ const fits = size + buffer <= MAX_TX_SIZE;
166
+ (0, generalUtils_1.consoleLog)(`[canSerializeTransaction] Size: ${size}, buffer: ${buffer}, max: ${MAX_TX_SIZE}, fits: ${fits}`);
167
+ return fits;
163
168
  }
164
169
  function addTxOptimizations(umi, tx, computeUnitPrice, computeUnitLimit) {
170
+ (0, generalUtils_1.consoleLog)(`[addTxOptimizations] Called with price=${computeUnitPrice}, limit=${computeUnitLimit}`);
171
+ (0, generalUtils_1.consoleLog)(`[addTxOptimizations] Input tx estimated size: ${tx.getTransactionSize(umi)}`);
165
172
  const computePriceIx = computeUnitPrice !== undefined
166
173
  ? setComputeUnitPriceUmiIx(umi.identity, computeUnitPrice)
167
174
  : (0, umi_1.transactionBuilder)();
@@ -171,22 +178,31 @@ function addTxOptimizations(umi, tx, computeUnitPrice, computeUnitLimit) {
171
178
  const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
172
179
  const withCuPrice = tx.prepend(computePriceIx);
173
180
  const withCuLimit = tx.prepend(computeLimitIx);
181
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if all optimizations fit...");
174
182
  // Use actual serialization check instead of estimate
175
183
  if (canSerializeTransaction(umi, allOptimizations)) {
184
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] All optimizations fit, adding both");
176
185
  return prependTx(tx, [computePriceIx, computeLimitIx]);
177
186
  }
178
- else if (canSerializeTransaction(umi, withCuPrice)) {
187
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if just CU price fits...");
188
+ if (canSerializeTransaction(umi, withCuPrice)) {
189
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Only CU price fits, adding it");
179
190
  return prependTx(tx, [computePriceIx]);
180
191
  }
181
- else if (canSerializeTransaction(umi, withCuLimit)) {
192
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if just CU limit fits...");
193
+ if (canSerializeTransaction(umi, withCuLimit)) {
194
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Only CU limit fits, adding it");
182
195
  return prependTx(tx, [computeLimitIx]);
183
196
  }
184
- else {
185
- return tx;
186
- }
197
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Nothing fits, returning original tx");
198
+ return tx;
187
199
  }
188
200
  function assembleFinalTransaction(umi, transaction, computeUnitPrice, computeUnitLimit) {
201
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Input tx instructions: ${transaction.getInstructions().length}`);
202
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Input tx estimated size: ${transaction.getTransactionSize(umi)}`);
189
203
  const tx = addTxOptimizations(umi, transaction, computeUnitPrice, computeUnitLimit);
204
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] After optimizations, instructions: ${tx.getInstructions().length}`);
205
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] After optimizations, estimated size: ${tx.getTransactionSize(umi)}`);
190
206
  const marginfiStartFlSerializer = (0, marginfi_1.getLendingAccountStartFlashloanInstructionDataSerializer)();
191
207
  const marginfiStartFlDiscriminator = marginfiStartFlSerializer
192
208
  .serialize({
@@ -220,10 +236,46 @@ function assembleFinalTransaction(umi, transaction, computeUnitPrice, computeUni
220
236
  }
221
237
  catch { }
222
238
  }
239
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Final tx estimated size: ${tx.getTransactionSize(umi)}`);
223
240
  return tx;
224
241
  }
225
242
  async function simulateTransaction(umi, connection, transaction) {
226
- const simulationResult = await connection.simulateTransaction((0, umi_web3js_adapters_1.toWeb3JsTransaction)(transaction.build(umi)), {
243
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Building transaction...");
244
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Estimated size:", transaction.getTransactionSize(umi));
245
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Instructions:", transaction.getInstructions().length);
246
+ let builtTx;
247
+ try {
248
+ builtTx = transaction.build(umi);
249
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Built UMI transaction successfully");
250
+ }
251
+ catch (e) {
252
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Failed to build UMI transaction:", e);
253
+ throw e;
254
+ }
255
+ let web3Tx;
256
+ try {
257
+ web3Tx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(builtTx);
258
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Converted to web3.js transaction");
259
+ }
260
+ catch (e) {
261
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Failed to convert to web3.js:", e);
262
+ throw e;
263
+ }
264
+ // Try to serialize before simulation to catch the error with better context
265
+ try {
266
+ const serialized = web3Tx.serialize();
267
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Pre-serialization successful, size:", serialized.length);
268
+ }
269
+ catch (e) {
270
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Pre-serialization FAILED:", e);
271
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Message accounts:", web3Tx.message.staticAccountKeys.length);
272
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Message instructions:", web3Tx.message.compiledInstructions.length);
273
+ if ("addressTableLookups" in web3Tx.message) {
274
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Address table lookups:", web3Tx.message.addressTableLookups?.length ?? 0);
275
+ }
276
+ throw new Error(`Transaction serialization failed before simulation: ${e.message || e}`);
277
+ }
278
+ const simulationResult = await connection.simulateTransaction(web3Tx, {
227
279
  sigVerify: false,
228
280
  commitment: "confirmed",
229
281
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.816",
3
+ "version": "1.0.817",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -5,10 +5,6 @@ import {
5
5
  import { SolautoClient } from "../../solauto";
6
6
  import { TransactionsManager } from "./transactionsManager";
7
7
  import {
8
- addSwbOraclePullTxs,
9
- buildSwbSubmitResponseTx,
10
- getSwitchboardFeedData,
11
- isSwitchboardMint,
12
8
  retryWithExponentialBackoff,
13
9
  } from "../../../utils";
14
10
  import { TransactionItem } from "../types";
@@ -255,10 +255,11 @@ export function getActualTxSize(
255
255
  const web3Tx = toWeb3JsTransaction(builtTx);
256
256
  // Actually serialize to get the real size
257
257
  const serialized = web3Tx.serialize();
258
+ consoleLog("[getActualTxSize] Serialization successful, size:", serialized.length);
258
259
  return serialized.length;
259
- } catch (e) {
260
+ } catch (e: any) {
260
261
  // Serialization failed - transaction is too large or malformed
261
- consoleLog("Transaction serialization check failed:", e);
262
+ consoleLog("[getActualTxSize] Serialization FAILED:", e?.message || e);
262
263
  return undefined;
263
264
  }
264
265
  }
@@ -272,11 +273,17 @@ export function canSerializeTransaction(
272
273
  tx: TransactionBuilder,
273
274
  buffer: number = 0
274
275
  ): boolean {
276
+ consoleLog("[canSerializeTransaction] Checking with buffer:", buffer);
275
277
  const size = getActualTxSize(umi, tx);
276
278
  if (size === undefined) {
279
+ consoleLog("[canSerializeTransaction] Failed - size undefined");
277
280
  return false;
278
281
  }
279
- return size + buffer <= MAX_TX_SIZE;
282
+ const fits = size + buffer <= MAX_TX_SIZE;
283
+ consoleLog(
284
+ `[canSerializeTransaction] Size: ${size}, buffer: ${buffer}, max: ${MAX_TX_SIZE}, fits: ${fits}`
285
+ );
286
+ return fits;
280
287
  }
281
288
 
282
289
  export function addTxOptimizations(
@@ -285,6 +292,13 @@ export function addTxOptimizations(
285
292
  computeUnitPrice?: number,
286
293
  computeUnitLimit?: number
287
294
  ) {
295
+ consoleLog(
296
+ `[addTxOptimizations] Called with price=${computeUnitPrice}, limit=${computeUnitLimit}`
297
+ );
298
+ consoleLog(
299
+ `[addTxOptimizations] Input tx estimated size: ${tx.getTransactionSize(umi)}`
300
+ );
301
+
288
302
  const computePriceIx =
289
303
  computeUnitPrice !== undefined
290
304
  ? setComputeUnitPriceUmiIx(umi.identity, computeUnitPrice)
@@ -296,17 +310,25 @@ export function addTxOptimizations(
296
310
  const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
297
311
  const withCuPrice = tx.prepend(computePriceIx);
298
312
  const withCuLimit = tx.prepend(computeLimitIx);
299
-
313
+
314
+ consoleLog("[addTxOptimizations] Checking if all optimizations fit...");
300
315
  // Use actual serialization check instead of estimate
301
316
  if (canSerializeTransaction(umi, allOptimizations)) {
317
+ consoleLog("[addTxOptimizations] All optimizations fit, adding both");
302
318
  return prependTx(tx, [computePriceIx, computeLimitIx]);
303
- } else if (canSerializeTransaction(umi, withCuPrice)) {
319
+ }
320
+ consoleLog("[addTxOptimizations] Checking if just CU price fits...");
321
+ if (canSerializeTransaction(umi, withCuPrice)) {
322
+ consoleLog("[addTxOptimizations] Only CU price fits, adding it");
304
323
  return prependTx(tx, [computePriceIx]);
305
- } else if (canSerializeTransaction(umi, withCuLimit)) {
324
+ }
325
+ consoleLog("[addTxOptimizations] Checking if just CU limit fits...");
326
+ if (canSerializeTransaction(umi, withCuLimit)) {
327
+ consoleLog("[addTxOptimizations] Only CU limit fits, adding it");
306
328
  return prependTx(tx, [computeLimitIx]);
307
- } else {
308
- return tx;
309
329
  }
330
+ consoleLog("[addTxOptimizations] Nothing fits, returning original tx");
331
+ return tx;
310
332
  }
311
333
 
312
334
  export function assembleFinalTransaction(
@@ -315,6 +337,13 @@ export function assembleFinalTransaction(
315
337
  computeUnitPrice?: number,
316
338
  computeUnitLimit?: number
317
339
  ) {
340
+ consoleLog(
341
+ `[assembleFinalTransaction] Input tx instructions: ${transaction.getInstructions().length}`
342
+ );
343
+ consoleLog(
344
+ `[assembleFinalTransaction] Input tx estimated size: ${transaction.getTransactionSize(umi)}`
345
+ );
346
+
318
347
  const tx = addTxOptimizations(
319
348
  umi,
320
349
  transaction,
@@ -322,6 +351,13 @@ export function assembleFinalTransaction(
322
351
  computeUnitLimit
323
352
  );
324
353
 
354
+ consoleLog(
355
+ `[assembleFinalTransaction] After optimizations, instructions: ${tx.getInstructions().length}`
356
+ );
357
+ consoleLog(
358
+ `[assembleFinalTransaction] After optimizations, estimated size: ${tx.getTransactionSize(umi)}`
359
+ );
360
+
325
361
  const marginfiStartFlSerializer =
326
362
  getLendingAccountStartFlashloanInstructionDataSerializer();
327
363
  const marginfiStartFlDiscriminator = marginfiStartFlSerializer
@@ -371,6 +407,9 @@ export function assembleFinalTransaction(
371
407
  } catch {}
372
408
  }
373
409
 
410
+ consoleLog(
411
+ `[assembleFinalTransaction] Final tx estimated size: ${tx.getTransactionSize(umi)}`
412
+ );
374
413
  return tx;
375
414
  }
376
415
 
@@ -379,13 +418,66 @@ async function simulateTransaction(
379
418
  connection: Connection,
380
419
  transaction: TransactionBuilder
381
420
  ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
382
- const simulationResult = await connection.simulateTransaction(
383
- toWeb3JsTransaction(transaction.build(umi)),
384
- {
385
- sigVerify: false,
386
- commitment: "confirmed",
387
- }
421
+ consoleLog("[simulateTransaction] Building transaction...");
422
+ consoleLog(
423
+ "[simulateTransaction] Estimated size:",
424
+ transaction.getTransactionSize(umi)
388
425
  );
426
+ consoleLog(
427
+ "[simulateTransaction] Instructions:",
428
+ transaction.getInstructions().length
429
+ );
430
+
431
+ let builtTx;
432
+ try {
433
+ builtTx = transaction.build(umi);
434
+ consoleLog("[simulateTransaction] Built UMI transaction successfully");
435
+ } catch (e: any) {
436
+ consoleLog("[simulateTransaction] Failed to build UMI transaction:", e);
437
+ throw e;
438
+ }
439
+
440
+ let web3Tx;
441
+ try {
442
+ web3Tx = toWeb3JsTransaction(builtTx);
443
+ consoleLog("[simulateTransaction] Converted to web3.js transaction");
444
+ } catch (e: any) {
445
+ consoleLog("[simulateTransaction] Failed to convert to web3.js:", e);
446
+ throw e;
447
+ }
448
+
449
+ // Try to serialize before simulation to catch the error with better context
450
+ try {
451
+ const serialized = web3Tx.serialize();
452
+ consoleLog(
453
+ "[simulateTransaction] Pre-serialization successful, size:",
454
+ serialized.length
455
+ );
456
+ } catch (e: any) {
457
+ consoleLog("[simulateTransaction] Pre-serialization FAILED:", e);
458
+ consoleLog(
459
+ "[simulateTransaction] Message accounts:",
460
+ web3Tx.message.staticAccountKeys.length
461
+ );
462
+ consoleLog(
463
+ "[simulateTransaction] Message instructions:",
464
+ web3Tx.message.compiledInstructions.length
465
+ );
466
+ if ("addressTableLookups" in web3Tx.message) {
467
+ consoleLog(
468
+ "[simulateTransaction] Address table lookups:",
469
+ (web3Tx.message as any).addressTableLookups?.length ?? 0
470
+ );
471
+ }
472
+ throw new Error(
473
+ `Transaction serialization failed before simulation: ${e.message || e}`
474
+ );
475
+ }
476
+
477
+ const simulationResult = await connection.simulateTransaction(web3Tx, {
478
+ sigVerify: false,
479
+ commitment: "confirmed",
480
+ });
389
481
  if (simulationResult.value.err) {
390
482
  simulationResult.value.logs?.forEach((x: any) => {
391
483
  consoleLog(x);