@haven-fi/solauto-sdk 1.0.816 → 1.0.818

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"}
@@ -112,7 +112,12 @@ function prependTx(tx, txsToAdd) {
112
112
  const keccakIdx = instructions.findIndex((x) => x.programId.toString() === "KeccakSecp256k11111111111111111111111111111");
113
113
  if (keccakIdx !== -1) {
114
114
  const [beforeKeccak, afterKeccak] = tx.splitByIndex(keccakIdx + 1);
115
- let finalTx = (0, umi_1.transactionBuilder)().add(beforeKeccak);
115
+ // IMPORTANT: Preserve lookup tables from original transaction
116
+ const lookupTables = tx.options.addressLookupTables ?? [];
117
+ (0, generalUtils_1.consoleLog)(`[prependTx] Keccak branch - preserving ${lookupTables.length} lookup tables`);
118
+ let finalTx = (0, umi_1.transactionBuilder)()
119
+ .setAddressLookupTables(lookupTables)
120
+ .add(beforeKeccak);
116
121
  for (const txToAdd of txsToAdd) {
117
122
  finalTx = finalTx.append(txToAdd);
118
123
  }
@@ -142,11 +147,12 @@ function getActualTxSize(umi, tx) {
142
147
  const web3Tx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(builtTx);
143
148
  // Actually serialize to get the real size
144
149
  const serialized = web3Tx.serialize();
150
+ (0, generalUtils_1.consoleLog)("[getActualTxSize] Serialization successful, size:", serialized.length);
145
151
  return serialized.length;
146
152
  }
147
153
  catch (e) {
148
154
  // Serialization failed - transaction is too large or malformed
149
- (0, generalUtils_1.consoleLog)("Transaction serialization check failed:", e);
155
+ (0, generalUtils_1.consoleLog)("[getActualTxSize] Serialization FAILED:", e?.message || e);
150
156
  return undefined;
151
157
  }
152
158
  }
@@ -155,13 +161,19 @@ function getActualTxSize(umi, tx) {
155
161
  * More accurate than getTransactionSize() estimation.
156
162
  */
157
163
  function canSerializeTransaction(umi, tx, buffer = 0) {
164
+ (0, generalUtils_1.consoleLog)("[canSerializeTransaction] Checking with buffer:", buffer);
158
165
  const size = getActualTxSize(umi, tx);
159
166
  if (size === undefined) {
167
+ (0, generalUtils_1.consoleLog)("[canSerializeTransaction] Failed - size undefined");
160
168
  return false;
161
169
  }
162
- return size + buffer <= MAX_TX_SIZE;
170
+ const fits = size + buffer <= MAX_TX_SIZE;
171
+ (0, generalUtils_1.consoleLog)(`[canSerializeTransaction] Size: ${size}, buffer: ${buffer}, max: ${MAX_TX_SIZE}, fits: ${fits}`);
172
+ return fits;
163
173
  }
164
174
  function addTxOptimizations(umi, tx, computeUnitPrice, computeUnitLimit) {
175
+ (0, generalUtils_1.consoleLog)(`[addTxOptimizations] Called with price=${computeUnitPrice}, limit=${computeUnitLimit}`);
176
+ (0, generalUtils_1.consoleLog)(`[addTxOptimizations] Input tx estimated size: ${tx.getTransactionSize(umi)}`);
165
177
  const computePriceIx = computeUnitPrice !== undefined
166
178
  ? setComputeUnitPriceUmiIx(umi.identity, computeUnitPrice)
167
179
  : (0, umi_1.transactionBuilder)();
@@ -171,22 +183,31 @@ function addTxOptimizations(umi, tx, computeUnitPrice, computeUnitLimit) {
171
183
  const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
172
184
  const withCuPrice = tx.prepend(computePriceIx);
173
185
  const withCuLimit = tx.prepend(computeLimitIx);
186
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if all optimizations fit...");
174
187
  // Use actual serialization check instead of estimate
175
188
  if (canSerializeTransaction(umi, allOptimizations)) {
189
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] All optimizations fit, adding both");
176
190
  return prependTx(tx, [computePriceIx, computeLimitIx]);
177
191
  }
178
- else if (canSerializeTransaction(umi, withCuPrice)) {
192
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if just CU price fits...");
193
+ if (canSerializeTransaction(umi, withCuPrice)) {
194
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Only CU price fits, adding it");
179
195
  return prependTx(tx, [computePriceIx]);
180
196
  }
181
- else if (canSerializeTransaction(umi, withCuLimit)) {
197
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Checking if just CU limit fits...");
198
+ if (canSerializeTransaction(umi, withCuLimit)) {
199
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Only CU limit fits, adding it");
182
200
  return prependTx(tx, [computeLimitIx]);
183
201
  }
184
- else {
185
- return tx;
186
- }
202
+ (0, generalUtils_1.consoleLog)("[addTxOptimizations] Nothing fits, returning original tx");
203
+ return tx;
187
204
  }
188
205
  function assembleFinalTransaction(umi, transaction, computeUnitPrice, computeUnitLimit) {
206
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Input tx instructions: ${transaction.getInstructions().length}`);
207
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Input tx estimated size: ${transaction.getTransactionSize(umi)}`);
189
208
  const tx = addTxOptimizations(umi, transaction, computeUnitPrice, computeUnitLimit);
209
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] After optimizations, instructions: ${tx.getInstructions().length}`);
210
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] After optimizations, estimated size: ${tx.getTransactionSize(umi)}`);
190
211
  const marginfiStartFlSerializer = (0, marginfi_1.getLendingAccountStartFlashloanInstructionDataSerializer)();
191
212
  const marginfiStartFlDiscriminator = marginfiStartFlSerializer
192
213
  .serialize({
@@ -220,10 +241,46 @@ function assembleFinalTransaction(umi, transaction, computeUnitPrice, computeUni
220
241
  }
221
242
  catch { }
222
243
  }
244
+ (0, generalUtils_1.consoleLog)(`[assembleFinalTransaction] Final tx estimated size: ${tx.getTransactionSize(umi)}`);
223
245
  return tx;
224
246
  }
225
247
  async function simulateTransaction(umi, connection, transaction) {
226
- const simulationResult = await connection.simulateTransaction((0, umi_web3js_adapters_1.toWeb3JsTransaction)(transaction.build(umi)), {
248
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Building transaction...");
249
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Estimated size:", transaction.getTransactionSize(umi));
250
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Instructions:", transaction.getInstructions().length);
251
+ let builtTx;
252
+ try {
253
+ builtTx = transaction.build(umi);
254
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Built UMI transaction successfully");
255
+ }
256
+ catch (e) {
257
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Failed to build UMI transaction:", e);
258
+ throw e;
259
+ }
260
+ let web3Tx;
261
+ try {
262
+ web3Tx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(builtTx);
263
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Converted to web3.js transaction");
264
+ }
265
+ catch (e) {
266
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Failed to convert to web3.js:", e);
267
+ throw e;
268
+ }
269
+ // Try to serialize before simulation to catch the error with better context
270
+ try {
271
+ const serialized = web3Tx.serialize();
272
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Pre-serialization successful, size:", serialized.length);
273
+ }
274
+ catch (e) {
275
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Pre-serialization FAILED:", e);
276
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Message accounts:", web3Tx.message.staticAccountKeys.length);
277
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Message instructions:", web3Tx.message.compiledInstructions.length);
278
+ if ("addressTableLookups" in web3Tx.message) {
279
+ (0, generalUtils_1.consoleLog)("[simulateTransaction] Address table lookups:", web3Tx.message.addressTableLookups?.length ?? 0);
280
+ }
281
+ throw new Error(`Transaction serialization failed before simulation: ${e.message || e}`);
282
+ }
283
+ const simulationResult = await connection.simulateTransaction(web3Tx, {
227
284
  sigVerify: false,
228
285
  commitment: "confirmed",
229
286
  });
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.818",
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";
@@ -220,7 +220,14 @@ export function prependTx(
220
220
  );
221
221
  if (keccakIdx !== -1) {
222
222
  const [beforeKeccak, afterKeccak] = tx.splitByIndex(keccakIdx + 1);
223
- let finalTx = transactionBuilder().add(beforeKeccak);
223
+ // IMPORTANT: Preserve lookup tables from original transaction
224
+ const lookupTables = tx.options.addressLookupTables ?? [];
225
+ consoleLog(
226
+ `[prependTx] Keccak branch - preserving ${lookupTables.length} lookup tables`
227
+ );
228
+ let finalTx = transactionBuilder()
229
+ .setAddressLookupTables(lookupTables)
230
+ .add(beforeKeccak);
224
231
  for (const txToAdd of txsToAdd) {
225
232
  finalTx = finalTx.append(txToAdd);
226
233
  }
@@ -255,10 +262,11 @@ export function getActualTxSize(
255
262
  const web3Tx = toWeb3JsTransaction(builtTx);
256
263
  // Actually serialize to get the real size
257
264
  const serialized = web3Tx.serialize();
265
+ consoleLog("[getActualTxSize] Serialization successful, size:", serialized.length);
258
266
  return serialized.length;
259
- } catch (e) {
267
+ } catch (e: any) {
260
268
  // Serialization failed - transaction is too large or malformed
261
- consoleLog("Transaction serialization check failed:", e);
269
+ consoleLog("[getActualTxSize] Serialization FAILED:", e?.message || e);
262
270
  return undefined;
263
271
  }
264
272
  }
@@ -272,11 +280,17 @@ export function canSerializeTransaction(
272
280
  tx: TransactionBuilder,
273
281
  buffer: number = 0
274
282
  ): boolean {
283
+ consoleLog("[canSerializeTransaction] Checking with buffer:", buffer);
275
284
  const size = getActualTxSize(umi, tx);
276
285
  if (size === undefined) {
286
+ consoleLog("[canSerializeTransaction] Failed - size undefined");
277
287
  return false;
278
288
  }
279
- return size + buffer <= MAX_TX_SIZE;
289
+ const fits = size + buffer <= MAX_TX_SIZE;
290
+ consoleLog(
291
+ `[canSerializeTransaction] Size: ${size}, buffer: ${buffer}, max: ${MAX_TX_SIZE}, fits: ${fits}`
292
+ );
293
+ return fits;
280
294
  }
281
295
 
282
296
  export function addTxOptimizations(
@@ -285,6 +299,13 @@ export function addTxOptimizations(
285
299
  computeUnitPrice?: number,
286
300
  computeUnitLimit?: number
287
301
  ) {
302
+ consoleLog(
303
+ `[addTxOptimizations] Called with price=${computeUnitPrice}, limit=${computeUnitLimit}`
304
+ );
305
+ consoleLog(
306
+ `[addTxOptimizations] Input tx estimated size: ${tx.getTransactionSize(umi)}`
307
+ );
308
+
288
309
  const computePriceIx =
289
310
  computeUnitPrice !== undefined
290
311
  ? setComputeUnitPriceUmiIx(umi.identity, computeUnitPrice)
@@ -296,17 +317,25 @@ export function addTxOptimizations(
296
317
  const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
297
318
  const withCuPrice = tx.prepend(computePriceIx);
298
319
  const withCuLimit = tx.prepend(computeLimitIx);
299
-
320
+
321
+ consoleLog("[addTxOptimizations] Checking if all optimizations fit...");
300
322
  // Use actual serialization check instead of estimate
301
323
  if (canSerializeTransaction(umi, allOptimizations)) {
324
+ consoleLog("[addTxOptimizations] All optimizations fit, adding both");
302
325
  return prependTx(tx, [computePriceIx, computeLimitIx]);
303
- } else if (canSerializeTransaction(umi, withCuPrice)) {
326
+ }
327
+ consoleLog("[addTxOptimizations] Checking if just CU price fits...");
328
+ if (canSerializeTransaction(umi, withCuPrice)) {
329
+ consoleLog("[addTxOptimizations] Only CU price fits, adding it");
304
330
  return prependTx(tx, [computePriceIx]);
305
- } else if (canSerializeTransaction(umi, withCuLimit)) {
331
+ }
332
+ consoleLog("[addTxOptimizations] Checking if just CU limit fits...");
333
+ if (canSerializeTransaction(umi, withCuLimit)) {
334
+ consoleLog("[addTxOptimizations] Only CU limit fits, adding it");
306
335
  return prependTx(tx, [computeLimitIx]);
307
- } else {
308
- return tx;
309
336
  }
337
+ consoleLog("[addTxOptimizations] Nothing fits, returning original tx");
338
+ return tx;
310
339
  }
311
340
 
312
341
  export function assembleFinalTransaction(
@@ -315,6 +344,13 @@ export function assembleFinalTransaction(
315
344
  computeUnitPrice?: number,
316
345
  computeUnitLimit?: number
317
346
  ) {
347
+ consoleLog(
348
+ `[assembleFinalTransaction] Input tx instructions: ${transaction.getInstructions().length}`
349
+ );
350
+ consoleLog(
351
+ `[assembleFinalTransaction] Input tx estimated size: ${transaction.getTransactionSize(umi)}`
352
+ );
353
+
318
354
  const tx = addTxOptimizations(
319
355
  umi,
320
356
  transaction,
@@ -322,6 +358,13 @@ export function assembleFinalTransaction(
322
358
  computeUnitLimit
323
359
  );
324
360
 
361
+ consoleLog(
362
+ `[assembleFinalTransaction] After optimizations, instructions: ${tx.getInstructions().length}`
363
+ );
364
+ consoleLog(
365
+ `[assembleFinalTransaction] After optimizations, estimated size: ${tx.getTransactionSize(umi)}`
366
+ );
367
+
325
368
  const marginfiStartFlSerializer =
326
369
  getLendingAccountStartFlashloanInstructionDataSerializer();
327
370
  const marginfiStartFlDiscriminator = marginfiStartFlSerializer
@@ -371,6 +414,9 @@ export function assembleFinalTransaction(
371
414
  } catch {}
372
415
  }
373
416
 
417
+ consoleLog(
418
+ `[assembleFinalTransaction] Final tx estimated size: ${tx.getTransactionSize(umi)}`
419
+ );
374
420
  return tx;
375
421
  }
376
422
 
@@ -379,13 +425,66 @@ async function simulateTransaction(
379
425
  connection: Connection,
380
426
  transaction: TransactionBuilder
381
427
  ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
382
- const simulationResult = await connection.simulateTransaction(
383
- toWeb3JsTransaction(transaction.build(umi)),
384
- {
385
- sigVerify: false,
386
- commitment: "confirmed",
387
- }
428
+ consoleLog("[simulateTransaction] Building transaction...");
429
+ consoleLog(
430
+ "[simulateTransaction] Estimated size:",
431
+ transaction.getTransactionSize(umi)
388
432
  );
433
+ consoleLog(
434
+ "[simulateTransaction] Instructions:",
435
+ transaction.getInstructions().length
436
+ );
437
+
438
+ let builtTx;
439
+ try {
440
+ builtTx = transaction.build(umi);
441
+ consoleLog("[simulateTransaction] Built UMI transaction successfully");
442
+ } catch (e: any) {
443
+ consoleLog("[simulateTransaction] Failed to build UMI transaction:", e);
444
+ throw e;
445
+ }
446
+
447
+ let web3Tx;
448
+ try {
449
+ web3Tx = toWeb3JsTransaction(builtTx);
450
+ consoleLog("[simulateTransaction] Converted to web3.js transaction");
451
+ } catch (e: any) {
452
+ consoleLog("[simulateTransaction] Failed to convert to web3.js:", e);
453
+ throw e;
454
+ }
455
+
456
+ // Try to serialize before simulation to catch the error with better context
457
+ try {
458
+ const serialized = web3Tx.serialize();
459
+ consoleLog(
460
+ "[simulateTransaction] Pre-serialization successful, size:",
461
+ serialized.length
462
+ );
463
+ } catch (e: any) {
464
+ consoleLog("[simulateTransaction] Pre-serialization FAILED:", e);
465
+ consoleLog(
466
+ "[simulateTransaction] Message accounts:",
467
+ web3Tx.message.staticAccountKeys.length
468
+ );
469
+ consoleLog(
470
+ "[simulateTransaction] Message instructions:",
471
+ web3Tx.message.compiledInstructions.length
472
+ );
473
+ if ("addressTableLookups" in web3Tx.message) {
474
+ consoleLog(
475
+ "[simulateTransaction] Address table lookups:",
476
+ (web3Tx.message as any).addressTableLookups?.length ?? 0
477
+ );
478
+ }
479
+ throw new Error(
480
+ `Transaction serialization failed before simulation: ${e.message || e}`
481
+ );
482
+ }
483
+
484
+ const simulationResult = await connection.simulateTransaction(web3Tx, {
485
+ sigVerify: false,
486
+ commitment: "confirmed",
487
+ });
389
488
  if (simulationResult.value.err) {
390
489
  simulationResult.value.logs?.forEach((x: any) => {
391
490
  consoleLog(x);