@haven-fi/solauto-sdk 1.0.372 → 1.0.373

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":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA2LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAoH7B;AA2LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAkDzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA2H5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EA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 async function convertReferralFeesToDestination(referralManager, tokenAccount, d
439
439
  .add(swapIx);
440
440
  return { tx, lookupTableAddresses };
441
441
  }
442
+ function parseJitoErrorMessage(message) {
443
+ const regex = /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
444
+ const match = message.match(regex);
445
+ if (match) {
446
+ const instructionIndex = parseInt(match[1], 10);
447
+ let errorCode;
448
+ if (match[2].toLowerCase().startsWith("0x")) {
449
+ errorCode = parseInt(match[2], 16);
450
+ }
451
+ else {
452
+ errorCode = parseInt(match[2], 10);
453
+ }
454
+ return {
455
+ instructionIndex,
456
+ errorCode,
457
+ };
458
+ }
459
+ else {
460
+ return null;
461
+ }
462
+ }
442
463
  function getErrorInfo(umi, tx, error, simulationSuccessful) {
443
464
  let canBeIgnored = false;
444
465
  let errorName = undefined;
@@ -449,7 +470,10 @@ function getErrorInfo(umi, tx, error, simulationSuccessful) {
449
470
  const err = error["InstructionError"];
450
471
  const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
451
472
  const errIxIdx = err[0] - computeIxs;
452
- (0, generalUtils_1.consoleLog)("Transaction instructions:", tx.getInstructions().map(x => x.programId.toString()).join(","));
473
+ (0, generalUtils_1.consoleLog)("Transaction instructions:", tx
474
+ .getInstructions()
475
+ .map((x) => x.programId.toString())
476
+ .join(","));
453
477
  (0, generalUtils_1.consoleLog)("Error instruction index:", errIxIdx);
454
478
  const errIx = tx.getInstructions()[Math.max(0, errIxIdx)];
455
479
  const errCode = typeof err[1] === "object" && "Custom" in err[1]
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;A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AAkB,GAAE,kBAA2C,EAC/D,UAAU,GAAE,OAAe,EAC3B,aAAa,CAAC,EAAE,aAAa,YAAA,EAC7B,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAY;YAQpB,uBAAuB;IAwCrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;YAoBb,SAAS;IAiBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA+FzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA4BxB,6BAA6B;YAuH7B,qBAAqB;YA2CrB,cAAc;YAqCd,eAAe;CA0D9B"}
@@ -319,10 +319,6 @@ class TransactionsManager {
319
319
  const itemSets = await this.assembleTransactionSets(items);
320
320
  this.updateStatusForSets(itemSets, TransactionStatus.Queued, 0);
321
321
  this.txHandler.log("Initial item sets:", itemSets.length);
322
- if (this.txType === "only-simulate" && itemSets.length > 1) {
323
- this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
324
- return [];
325
- }
326
322
  if (itemSets.length > 1 && this.atomically) {
327
323
  await this.processTransactionsAtomically(itemSets);
328
324
  }
@@ -337,6 +333,7 @@ class TransactionsManager {
337
333
  }
338
334
  async processTransactionsAtomically(itemSets) {
339
335
  let num = 0;
336
+ let transactions = [];
340
337
  await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
341
338
  num = attemptNum;
342
339
  if (attemptNum > 0) {
@@ -345,7 +342,7 @@ class TransactionsManager {
345
342
  }
346
343
  itemSets = await this.assembleTransactionSets(itemSets.flatMap((x) => x.items));
347
344
  }
348
- let transactions = [];
345
+ transactions = [];
349
346
  for (const set of itemSets) {
350
347
  transactions.push(await set.getSingleTransaction());
351
348
  }
@@ -358,19 +355,30 @@ class TransactionsManager {
358
355
  let txSigs;
359
356
  let error;
360
357
  try {
361
- txSigs = await (0, jitoUtils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, transactions, this.txType, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), () => this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum, undefined, true));
358
+ txSigs = await (0, jitoUtils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.signer, transactions, this.txType, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), () => this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum, undefined, true));
362
359
  }
363
360
  catch (e) {
364
361
  error = e;
365
362
  }
366
- if (error || !Boolean(txSigs) || txSigs?.length === 0) {
363
+ if (error ||
364
+ (this.txType !== "only-simulate" &&
365
+ (!Boolean(txSigs) || txSigs?.length === 0))) {
367
366
  this.updateStatusForSets(itemSets, TransactionStatus.Failed, attemptNum, txSigs, undefined, error?.message);
368
367
  throw error ? error : new Error("Unknown error");
369
368
  }
370
369
  this.updateStatusForSets(itemSets, TransactionStatus.Successful, attemptNum, txSigs);
371
370
  }, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
372
- this.updateStatusForSets(itemSets, TransactionStatus.Failed, num, undefined, undefined, e.message);
373
- throw e;
371
+ this.txHandler.log("Capturing error info...");
372
+ const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, (0, umi_1.transactionBuilder)().add(transactions), e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length);
373
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
374
+ this.updateStatusForSets(itemSets, errorDetails.canBeIgnored
375
+ ? TransactionStatus.Skipped
376
+ : TransactionStatus.Failed, num, undefined, undefined, errorDetails.errorName || errorDetails.errorInfo
377
+ ? errorString
378
+ : e.message);
379
+ if (!errorDetails.canBeIgnored) {
380
+ throw e;
381
+ }
374
382
  });
375
383
  }
376
384
  async processTransactionSet(itemSets, currentIndex) {
@@ -391,12 +399,7 @@ class TransactionsManager {
391
399
  await this.debugAccounts(itemSet, tx);
392
400
  await this.sendTransaction(tx, itemSet.name(), attemptNum, this.getUpdatedPriorityFeeSetting(prevError, attemptNum));
393
401
  }
394
- }, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
395
- if (itemSet) {
396
- this.updateStatus(itemSet.name(), TransactionStatus.Failed, num, undefined, undefined, e.message);
397
- }
398
- throw e;
399
- });
402
+ }, this.retries, this.retryDelay, this.errorsToThrow);
400
403
  }
401
404
  async refreshItemSet(itemSets, currentIndex, attemptNum) {
402
405
  const itemSet = itemSets[currentIndex];
@@ -423,8 +426,8 @@ class TransactionsManager {
423
426
  this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
424
427
  }
425
428
  catch (e) {
426
- this.txHandler.log("Caputring error info...");
427
- const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, tx, e, this.statuses.find(x => x.name === txName)?.simulationSuccessful);
429
+ this.txHandler.log("Capturing error info...");
430
+ const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, tx, e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful);
428
431
  const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
429
432
  this.updateStatus(txName, errorDetails.canBeIgnored
430
433
  ? TransactionStatus.Skipped
@@ -1,6 +1,6 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
1
+ import { PublicKey } from "@solana/web3.js";
2
2
  import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
3
3
  import { PriorityFeeSetting, TransactionRunType } from "../types";
4
4
  export declare function getRandomTipAccount(): Promise<PublicKey>;
5
- export declare function sendJitoBundledTransactions(umi: Umi, connection: Connection, signer: Signer, txs: TransactionBuilder[], txType?: TransactionRunType, priorityFeeSetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<string[] | undefined>;
5
+ export declare function sendJitoBundledTransactions(umi: Umi, signer: Signer, txs: TransactionBuilder[], txType?: TransactionRunType, priorityFeeSetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<string[] | undefined>;
6
6
  //# sourceMappingURL=jitoUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAoE,MAAM,iBAAiB,CAAC;AAG1H,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AASlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAyHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA+D/B"}
1
+ {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AA2KD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAyD/B"}
@@ -13,7 +13,6 @@ const generalUtils_1 = require("./generalUtils");
13
13
  const types_1 = require("../types");
14
14
  const axios_1 = __importDefault(require("axios"));
15
15
  const bs58_1 = __importDefault(require("bs58"));
16
- const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
17
16
  async function getRandomTipAccount() {
18
17
  const tipAccounts = [
19
18
  "96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
@@ -31,28 +30,62 @@ async function getRandomTipAccount() {
31
30
  async function getTipInstruction(signer, tipLamports) {
32
31
  return (0, solanaUtils_1.systemTransferUmiIx)(signer, await getRandomTipAccount(), BigInt(tipLamports));
33
32
  }
34
- // TODO: fix
35
- // async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
36
- // const simulationResult = await axios.post(
37
- // `${JITO_BLOCK_ENGINE}/api/v1/bundles`,
38
- // {
39
- // method: "simulateBundle",
40
- // id: 1,
41
- // jsonrpc: "2.0",
42
- // params: [
43
- // {
44
- // encodedTransactions: txs.map((x) => bs58.encode(x.serialize())),
45
- // preExecutionAccountsConfigs: txs.map((_) => ""),
46
- // postExecutionAccountsConfigs: txs.map((_) => ""),
47
- // skipSigVerify: true,
48
- // },
49
- // ],
50
- // }
51
- // );
52
- // }
53
- async function umiToVersionedTransactions(umi, signer, txs, sign, feeEstimates, computeUnitLimits) {
33
+ async function simulateJitoBundle(umi, txs) {
34
+ const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
35
+ // const resp = await umi.rpc.call("simulateBundle", [
36
+ // {
37
+ // encodedTransactions: txs.map((x) =>
38
+ // Buffer.from(x.serialize()).toString("base64")
39
+ // ),
40
+ // },
41
+ // {
42
+ // preExecutionAccountsConfigs: txs.map((_) => ""),
43
+ // postExecutionAccountsConfigs: txs.map((_) => ""),
44
+ // skipSigVerify: true,
45
+ // },
46
+ // ]);
47
+ const resp = await axios_1.default.post(umi.rpc.getEndpoint(), {
48
+ jsonrpc: "2.0",
49
+ id: 1,
50
+ method: "simulateBundle",
51
+ params: [
52
+ {
53
+ encodedTransactions: txs.map((x) => Buffer.from(x.serialize()).toString("base64")),
54
+ },
55
+ {
56
+ encoding: "base64",
57
+ commitment: "confirmed",
58
+ preExecutionAccountsConfigs: txs.map((_) => { }),
59
+ postExecutionAccountsConfigs: txs.map((_) => { }),
60
+ skipSigVerify: true,
61
+ },
62
+ ],
63
+ }, {
64
+ headers: {
65
+ "Content-Type": "application/json",
66
+ },
67
+ });
68
+ const res = resp.data.result.value;
69
+ if (res && res.summary.failed) {
70
+ const transactionResults = res.transactionResults;
71
+ transactionResults.forEach((x) => {
72
+ x.logs?.forEach((y) => {
73
+ (0, generalUtils_1.consoleLog)(y);
74
+ });
75
+ });
76
+ const txFailure = res.summary.failed.error.TransactionFailure;
77
+ throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
78
+ }
79
+ return res;
80
+ });
81
+ const transactionResults = simulationResult.transactionResults;
82
+ return transactionResults;
83
+ }
84
+ async function umiToVersionedTransactions(umi, blockhash, signer, txs, sign, feeEstimates, computeUnitLimits) {
54
85
  let builtTxs = await Promise.all(txs.map(async (tx, i) => {
55
- return (await (0, solanaUtils_1.assembleFinalTransaction)(signer, tx, feeEstimates ? feeEstimates[i] : undefined, computeUnitLimits ? computeUnitLimits[i] : undefined).setLatestBlockhash(umi)).build(umi);
86
+ return (0, solanaUtils_1.assembleFinalTransaction)(signer, tx, feeEstimates ? feeEstimates[i] : undefined, computeUnitLimits ? computeUnitLimits[i] : undefined)
87
+ .setBlockhash(blockhash)
88
+ .build(umi);
56
89
  }));
57
90
  if (sign) {
58
91
  builtTxs = await signer.signAllTransactions(builtTxs);
@@ -109,11 +142,7 @@ async function sendJitoBundle(transactions) {
109
142
  (0, generalUtils_1.consoleLog)("Bundle ID:", bundleId);
110
143
  return bundleId ? await pollBundleStatus(bundleId) : [];
111
144
  }
112
- async function sendJitoBundledTransactions(umi, connection, signer, txs, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, onAwaitingSign) {
113
- if (txs.length === 1) {
114
- const res = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(umi, connection, txs[0], txType, priorityFeeSetting);
115
- return res ? [bytes_1.bs58.encode(res)] : undefined;
116
- }
145
+ async function sendJitoBundledTransactions(umi, signer, txs, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, onAwaitingSign) {
117
146
  (0, generalUtils_1.consoleLog)("Sending Jito bundle...");
118
147
  (0, generalUtils_1.consoleLog)("Transactions: ", txs.length);
119
148
  (0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
@@ -122,19 +151,13 @@ async function sendJitoBundledTransactions(umi, connection, signer, txs, txType,
122
151
  ? await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting)) ??
123
152
  1000000))
124
153
  : undefined;
125
- let builtTxs = await umiToVersionedTransactions(umi, signer, txs, true, // false if simulating first and rebuilding later
126
- feeEstimates);
127
- // const simulationResults = await simulateJitoBundle(umi, builtTxs);
154
+ const latestBlockhash = (await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })).blockhash;
155
+ let builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, signer, txs, false, feeEstimates);
156
+ const simulationResults = await simulateJitoBundle(umi, builtTxs);
128
157
  if (txType !== "only-simulate") {
129
- // let builtTxs = await umiToVersionedTransactions(
130
- // client.signer,
131
- // txs,
132
- // true,
133
- // feeEstimates,
134
- // simulationResults.map((x) => x.unitsConsumed! * 1.15)
135
- // );
158
+ builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, signer, txs, true, feeEstimates, simulationResults.map((x) => x.unitsConsumed * 1.15));
136
159
  const serializedTxs = builtTxs.map((x) => x.serialize());
137
- if (serializedTxs.find(x => x.length > 1232)) {
160
+ if (serializedTxs.find((x) => x.length > 1232)) {
138
161
  throw new Error("A transaction is too large");
139
162
  }
140
163
  onAwaitingSign?.();
@@ -179,7 +179,7 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
179
179
  feeEstimate = Math.round(resp.priorityFeeEstimate);
180
180
  }
181
181
  catch (e) {
182
- console.error(e);
182
+ // console.error(e);
183
183
  }
184
184
  }
185
185
  return feeEstimate;
@@ -230,7 +230,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, prior
230
230
  const blockhash = await connection.getLatestBlockhash("confirmed");
231
231
  let computeUnitLimit = undefined;
232
232
  if (txType !== "skip-simulation") {
233
- const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, await assembleFinalTransaction(umi.identity, tx, undefined, 1400000).setBlockhash(blockhash)), 3);
233
+ const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(umi, connection, assembleFinalTransaction(umi.identity, tx, undefined, 1400000).setBlockhash(blockhash)), 3);
234
234
  simulationResult.value.err;
235
235
  computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
236
236
  (0, generalUtils_1.consoleLog)("Compute unit limit: ", computeUnitLimit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.372",
3
+ "version": "1.0.373",
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",
@@ -637,7 +637,10 @@ export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
637
637
  client.livePositionUpdates.debtAdjustment === BigInt(0) &&
638
638
  utilizationRateDiff >= 10
639
639
  ) {
640
- client.log("Choosing to refresh before rebalance. Utilization rate diff:", utilizationRateDiff);
640
+ client.log(
641
+ "Choosing to refresh before rebalance. Utilization rate diff:",
642
+ utilizationRateDiff
643
+ );
641
644
  return true;
642
645
  }
643
646
  }
@@ -821,7 +824,36 @@ export async function convertReferralFeesToDestination(
821
824
  return { tx, lookupTableAddresses };
822
825
  }
823
826
 
824
- export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any, simulationSuccessful?: boolean) {
827
+ function parseJitoErrorMessage(message: string) {
828
+ const regex =
829
+ /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
830
+ const match = message.match(regex);
831
+
832
+ if (match) {
833
+ const instructionIndex = parseInt(match[1], 10);
834
+
835
+ let errorCode: number;
836
+ if (match[2].toLowerCase().startsWith("0x")) {
837
+ errorCode = parseInt(match[2], 16);
838
+ } else {
839
+ errorCode = parseInt(match[2], 10);
840
+ }
841
+
842
+ return {
843
+ instructionIndex,
844
+ errorCode,
845
+ };
846
+ } else {
847
+ return null;
848
+ }
849
+ }
850
+
851
+ export function getErrorInfo(
852
+ umi: Umi,
853
+ tx: TransactionBuilder,
854
+ error: any,
855
+ simulationSuccessful?: boolean
856
+ ) {
825
857
  let canBeIgnored = false;
826
858
  let errorName: string | undefined = undefined;
827
859
  let errorInfo: string | undefined = undefined;
@@ -835,7 +867,13 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any, simul
835
867
  const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
836
868
  const errIxIdx = err[0] - computeIxs;
837
869
 
838
- consoleLog("Transaction instructions:", tx.getInstructions().map(x => x.programId.toString()).join(","));
870
+ consoleLog(
871
+ "Transaction instructions:",
872
+ tx
873
+ .getInstructions()
874
+ .map((x) => x.programId.toString())
875
+ .join(",")
876
+ );
839
877
  consoleLog("Error instruction index:", errIxIdx);
840
878
 
841
879
  const errIx = tx.getInstructions()[Math.max(0, errIxIdx)];
@@ -510,13 +510,6 @@ export class TransactionsManager {
510
510
  this.updateStatusForSets(itemSets, TransactionStatus.Queued, 0);
511
511
  this.txHandler.log("Initial item sets:", itemSets.length);
512
512
 
513
- if (this.txType === "only-simulate" && itemSets.length > 1) {
514
- this.txHandler.log(
515
- "Only simulate and more than 1 transaction. Skipping..."
516
- );
517
- return [];
518
- }
519
-
520
513
  if (itemSets.length > 1 && this.atomically) {
521
514
  await this.processTransactionsAtomically(itemSets);
522
515
  } else {
@@ -532,6 +525,7 @@ export class TransactionsManager {
532
525
 
533
526
  private async processTransactionsAtomically(itemSets: TransactionSet[]) {
534
527
  let num = 0;
528
+ let transactions: TransactionBuilder[] = [];
535
529
 
536
530
  await retryWithExponentialBackoff(
537
531
  async (attemptNum, prevError) => {
@@ -546,7 +540,7 @@ export class TransactionsManager {
546
540
  );
547
541
  }
548
542
 
549
- let transactions = [];
543
+ transactions = [];
550
544
  for (const set of itemSets) {
551
545
  transactions.push(await set.getSingleTransaction());
552
546
  }
@@ -573,7 +567,6 @@ export class TransactionsManager {
573
567
  try {
574
568
  txSigs = await sendJitoBundledTransactions(
575
569
  this.txHandler.umi,
576
- this.txHandler.connection,
577
570
  this.txHandler.signer,
578
571
  transactions,
579
572
  this.txType,
@@ -591,7 +584,11 @@ export class TransactionsManager {
591
584
  error = e as Error;
592
585
  }
593
586
 
594
- if (error || !Boolean(txSigs) || txSigs?.length === 0) {
587
+ if (
588
+ error ||
589
+ (this.txType !== "only-simulate" &&
590
+ (!Boolean(txSigs) || txSigs?.length === 0))
591
+ ) {
595
592
  this.updateStatusForSets(
596
593
  itemSets,
597
594
  TransactionStatus.Failed,
@@ -614,15 +611,34 @@ export class TransactionsManager {
614
611
  this.retryDelay,
615
612
  this.errorsToThrow
616
613
  ).catch((e: Error) => {
614
+ this.txHandler.log("Capturing error info...");
615
+ const errorDetails = getErrorInfo(
616
+ this.txHandler.umi,
617
+ transactionBuilder().add(transactions),
618
+ e,
619
+ itemSets.filter(
620
+ (x) =>
621
+ this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful
622
+ ).length === itemSets.length
623
+ );
624
+
625
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
617
626
  this.updateStatusForSets(
618
627
  itemSets,
619
- TransactionStatus.Failed,
628
+ errorDetails.canBeIgnored
629
+ ? TransactionStatus.Skipped
630
+ : TransactionStatus.Failed,
620
631
  num,
621
632
  undefined,
622
633
  undefined,
623
- e.message
634
+ errorDetails.errorName || errorDetails.errorInfo
635
+ ? errorString
636
+ : e.message
624
637
  );
625
- throw e;
638
+
639
+ if (!errorDetails.canBeIgnored) {
640
+ throw e;
641
+ }
626
642
  });
627
643
  }
628
644
 
@@ -666,19 +682,7 @@ export class TransactionsManager {
666
682
  this.retries,
667
683
  this.retryDelay,
668
684
  this.errorsToThrow
669
- ).catch((e: Error) => {
670
- if (itemSet) {
671
- this.updateStatus(
672
- itemSet.name(),
673
- TransactionStatus.Failed,
674
- num,
675
- undefined,
676
- undefined,
677
- e.message
678
- );
679
- }
680
- throw e;
681
- });
685
+ );
682
686
  }
683
687
 
684
688
  private async refreshItemSet(
@@ -749,8 +753,13 @@ export class TransactionsManager {
749
753
  txSig ? bs58.encode(txSig) : undefined
750
754
  );
751
755
  } catch (e: any) {
752
- this.txHandler.log("Caputring error info...");
753
- const errorDetails = getErrorInfo(this.txHandler.umi, tx, e, this.statuses.find(x => x.name === txName)?.simulationSuccessful);
756
+ this.txHandler.log("Capturing error info...");
757
+ const errorDetails = getErrorInfo(
758
+ this.txHandler.umi,
759
+ tx,
760
+ e,
761
+ this.statuses.find((x) => x.name === txName)?.simulationSuccessful
762
+ );
754
763
 
755
764
  const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
756
765
  this.updateStatus(
@@ -1,4 +1,9 @@
1
- import { Connection, PublicKey, TransactionExpiredBlockheightExceededError, VersionedTransaction } from "@solana/web3.js";
1
+ import {
2
+ PublicKey,
3
+ SimulatedTransactionResponse,
4
+ TransactionExpiredBlockheightExceededError,
5
+ VersionedTransaction,
6
+ } from "@solana/web3.js";
2
7
  import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
3
8
  import { JITO_BLOCK_ENGINE } from "../constants/solautoConstants";
4
9
  import {
@@ -9,16 +14,13 @@ import {
9
14
  } from "@metaplex-foundation/umi";
10
15
  import {
11
16
  assembleFinalTransaction,
12
- buildIronforgeApiUrl,
13
17
  getComputeUnitPriceEstimate,
14
- sendSingleOptimizedTransaction,
15
18
  systemTransferUmiIx,
16
19
  } from "./solanaUtils";
17
- import { consoleLog } from "./generalUtils";
20
+ import { consoleLog, retryWithExponentialBackoff } from "./generalUtils";
18
21
  import { PriorityFeeSetting, TransactionRunType } from "../types";
19
22
  import axios from "axios";
20
23
  import base58 from "bs58";
21
- import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
22
24
 
23
25
  export async function getRandomTipAccount(): Promise<PublicKey> {
24
26
  const tipAccounts = [
@@ -46,28 +48,76 @@ async function getTipInstruction(
46
48
  );
47
49
  }
48
50
 
49
- // TODO: fix
50
- // async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
51
- // const simulationResult = await axios.post(
52
- // `${JITO_BLOCK_ENGINE}/api/v1/bundles`,
53
- // {
54
- // method: "simulateBundle",
55
- // id: 1,
56
- // jsonrpc: "2.0",
57
- // params: [
58
- // {
59
- // encodedTransactions: txs.map((x) => bs58.encode(x.serialize())),
60
- // preExecutionAccountsConfigs: txs.map((_) => ""),
61
- // postExecutionAccountsConfigs: txs.map((_) => ""),
62
- // skipSigVerify: true,
63
- // },
64
- // ],
65
- // }
66
- // );
67
- // }
51
+ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
52
+ const simulationResult = await retryWithExponentialBackoff(async () => {
53
+ // const resp = await umi.rpc.call("simulateBundle", [
54
+ // {
55
+ // encodedTransactions: txs.map((x) =>
56
+ // Buffer.from(x.serialize()).toString("base64")
57
+ // ),
58
+ // },
59
+ // {
60
+ // preExecutionAccountsConfigs: txs.map((_) => ""),
61
+ // postExecutionAccountsConfigs: txs.map((_) => ""),
62
+ // skipSigVerify: true,
63
+ // },
64
+ // ]);
65
+
66
+ const resp = await axios.post(
67
+ umi.rpc.getEndpoint(),
68
+ {
69
+ jsonrpc: "2.0",
70
+ id: 1,
71
+ method: "simulateBundle",
72
+ params: [
73
+ {
74
+ encodedTransactions: txs.map((x) =>
75
+ Buffer.from(x.serialize()).toString("base64")
76
+ ),
77
+ },
78
+ {
79
+ encoding: "base64",
80
+ commitment: "confirmed",
81
+ preExecutionAccountsConfigs: txs.map((_) => {}),
82
+ postExecutionAccountsConfigs: txs.map((_) => {}),
83
+ skipSigVerify: true,
84
+ },
85
+ ],
86
+ },
87
+ {
88
+ headers: {
89
+ "Content-Type": "application/json",
90
+ },
91
+ }
92
+ );
93
+
94
+ const res = resp.data.result.value as any;
95
+
96
+ if (res && res.summary.failed) {
97
+ const transactionResults =
98
+ res.transactionResults as SimulatedTransactionResponse[];
99
+ transactionResults.forEach((x) => {
100
+ x.logs?.forEach((y) => {
101
+ consoleLog(y);
102
+ });
103
+ });
104
+
105
+ const txFailure = res.summary.failed.error.TransactionFailure;
106
+ throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
107
+ }
108
+
109
+ return res;
110
+ });
111
+
112
+ const transactionResults =
113
+ simulationResult.transactionResults as SimulatedTransactionResponse[];
114
+
115
+ return transactionResults;
116
+ }
68
117
 
69
118
  async function umiToVersionedTransactions(
70
119
  umi: Umi,
120
+ blockhash: string,
71
121
  signer: Signer,
72
122
  txs: TransactionBuilder[],
73
123
  sign: boolean,
@@ -76,14 +126,14 @@ async function umiToVersionedTransactions(
76
126
  ): Promise<VersionedTransaction[]> {
77
127
  let builtTxs = await Promise.all(
78
128
  txs.map(async (tx, i) => {
79
- return (
80
- await assembleFinalTransaction(
81
- signer,
82
- tx,
83
- feeEstimates ? feeEstimates[i] : undefined,
84
- computeUnitLimits ? computeUnitLimits[i] : undefined
85
- ).setLatestBlockhash(umi)
86
- ).build(umi);
129
+ return assembleFinalTransaction(
130
+ signer,
131
+ tx,
132
+ feeEstimates ? feeEstimates[i] : undefined,
133
+ computeUnitLimits ? computeUnitLimits[i] : undefined
134
+ )
135
+ .setBlockhash(blockhash)
136
+ .build(umi);
87
137
  })
88
138
  );
89
139
 
@@ -125,7 +175,9 @@ async function pollBundleStatus(
125
175
  }
126
176
  }
127
177
  }
128
- throw new TransactionExpiredBlockheightExceededError("Unable to confirm transaction. Try a higher priority fee.");
178
+ throw new TransactionExpiredBlockheightExceededError(
179
+ "Unable to confirm transaction. Try a higher priority fee."
180
+ );
129
181
  }
130
182
 
131
183
  async function sendJitoBundle(transactions: string[]): Promise<string[]> {
@@ -156,24 +208,12 @@ async function sendJitoBundle(transactions: string[]): Promise<string[]> {
156
208
 
157
209
  export async function sendJitoBundledTransactions(
158
210
  umi: Umi,
159
- connection: Connection,
160
211
  signer: Signer,
161
212
  txs: TransactionBuilder[],
162
213
  txType?: TransactionRunType,
163
214
  priorityFeeSetting: PriorityFeeSetting = PriorityFeeSetting.Min,
164
215
  onAwaitingSign?: () => void
165
216
  ): Promise<string[] | undefined> {
166
- if (txs.length === 1) {
167
- const res = await sendSingleOptimizedTransaction(
168
- umi,
169
- connection,
170
- txs[0],
171
- txType,
172
- priorityFeeSetting
173
- );
174
- return res ? [bs58.encode(res)] : undefined;
175
- }
176
-
177
217
  consoleLog("Sending Jito bundle...");
178
218
  consoleLog("Transactions: ", txs.length);
179
219
  consoleLog(
@@ -193,27 +233,32 @@ export async function sendJitoBundledTransactions(
193
233
  )
194
234
  : undefined;
195
235
 
236
+ const latestBlockhash = (
237
+ await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })
238
+ ).blockhash;
196
239
  let builtTxs = await umiToVersionedTransactions(
197
240
  umi,
241
+ latestBlockhash,
198
242
  signer,
199
243
  txs,
200
- true, // false if simulating first and rebuilding later
244
+ false,
201
245
  feeEstimates
202
246
  );
203
-
204
- // const simulationResults = await simulateJitoBundle(umi, builtTxs);
247
+ const simulationResults = await simulateJitoBundle(umi, builtTxs);
205
248
 
206
249
  if (txType !== "only-simulate") {
207
- // let builtTxs = await umiToVersionedTransactions(
208
- // client.signer,
209
- // txs,
210
- // true,
211
- // feeEstimates,
212
- // simulationResults.map((x) => x.unitsConsumed! * 1.15)
213
- // );
250
+ builtTxs = await umiToVersionedTransactions(
251
+ umi,
252
+ latestBlockhash,
253
+ signer,
254
+ txs,
255
+ true,
256
+ feeEstimates,
257
+ simulationResults.map((x) => x.unitsConsumed! * 1.15)
258
+ );
214
259
 
215
260
  const serializedTxs = builtTxs.map((x) => x.serialize());
216
- if (serializedTxs.find(x => x.length > 1232)) {
261
+ if (serializedTxs.find((x) => x.length > 1232)) {
217
262
  throw new Error("A transaction is too large");
218
263
  }
219
264
 
@@ -319,7 +319,7 @@ export async function getComputeUnitPriceEstimate(
319
319
  ]);
320
320
  feeEstimate = Math.round((resp as any).priorityFeeEstimate as number);
321
321
  } catch (e) {
322
- console.error(e);
322
+ // console.error(e);
323
323
  }
324
324
  }
325
325
 
@@ -402,7 +402,7 @@ export async function sendSingleOptimizedTransaction(
402
402
  await simulateTransaction(
403
403
  umi,
404
404
  connection,
405
- await assembleFinalTransaction(
405
+ assembleFinalTransaction(
406
406
  umi.identity,
407
407
  tx,
408
408
  undefined,
@@ -1,9 +1,5 @@
1
1
  import { describe, it } from "mocha";
2
- import {
3
- none,
4
- publicKey,
5
- some,
6
- } from "@metaplex-foundation/umi";
2
+ import { none, publicKey, some } from "@metaplex-foundation/umi";
7
3
  import { setupTest } from "../shared";
8
4
  import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
9
5
  import {
@@ -29,23 +25,21 @@ import {
29
25
  SOLAUTO_TEST_PROGRAM,
30
26
  USDC,
31
27
  } from "../../src/constants";
32
- import {
33
- buildHeliusApiUrl,
34
- getSolautoManagedPositions,
35
- } from "../../src/utils";
28
+ import { buildHeliusApiUrl, getSolautoManagedPositions } from "../../src/utils";
36
29
  import { PriorityFeeSetting } from "../../src/types";
30
+ import { buildIronforgeApiUrl, TransactionManagerStatuses } from "../../dist";
37
31
 
38
32
  describe("Solauto Marginfi tests", async () => {
39
- // const signer = setupTest();
40
- const signer = setupTest("solauto-manager");
33
+ const signer = setupTest();
34
+ // const signer = setupTest("solauto-manager");
41
35
 
42
36
  const payForTransactions = false;
43
- const testProgram = false;
37
+ const testProgram = true;
44
38
  const positionId = 1;
45
39
 
46
40
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
47
41
  const client = new SolautoMarginfiClient(
48
- buildHeliusApiUrl(process.env.HELIUS_API_KEY!),
42
+ buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
49
43
  true,
50
44
  testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM
51
45
  );
@@ -54,20 +48,20 @@ describe("Solauto Marginfi tests", async () => {
54
48
  const supplyDecimals = 6;
55
49
  const debtDecimals = 6;
56
50
 
57
- // await client.initialize({
58
- // signer,
59
- // positionId,
60
- // authority: new PublicKey("5FALSVLRjuRZHSmQVdT2RUZC6KadCuDmxY7gaQFWFBxf"),
61
- // // new: true,
62
- // // marginfiAccount: new PublicKey(
63
- // // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
64
- // // ),
65
- // // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
66
- // // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
67
- // // debtMint: new PublicKey(USDC),
68
- // });
69
-
70
- console.log(await getSolautoManagedPositions(client.umi));
51
+ await client.initialize({
52
+ signer,
53
+ positionId,
54
+ authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
55
+ // new: true,
56
+ // marginfiAccount: new PublicKey(
57
+ // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
58
+ // ),
59
+ // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
60
+ // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
61
+ // debtMint: new PublicKey(USDC),
62
+ });
63
+
64
+ // console.log(await getSolautoManagedPositions(client.umi));
71
65
 
72
66
  const transactionItems: TransactionItem[] = [];
73
67
  // const settingParams: SolautoSettingsParametersInpArgs = {
@@ -100,7 +94,17 @@ describe("Solauto Marginfi tests", async () => {
100
94
  // // const [supplyPrice] = await fetchTokenPrices([supply]);
101
95
  // return {
102
96
  // tx: client.protocolInteraction(
103
- // solautoAction("Deposit", [toBaseUnit(300, supplyDecimals)])
97
+ // solautoAction("Deposit", [toBaseUnit(0.05, supplyDecimals)])
98
+ // ),
99
+ // };
100
+ // }, "deposit")
101
+ // );
102
+ // transactionItems.push(
103
+ // new TransactionItem(async () => {
104
+ // // const [supplyPrice] = await fetchTokenPrices([supply]);
105
+ // return {
106
+ // tx: client.protocolInteraction(
107
+ // solautoAction("Deposit", [toBaseUnit(0.05, supplyDecimals)])
104
108
  // ),
105
109
  // };
106
110
  // }, "deposit")
@@ -127,13 +131,13 @@ describe("Solauto Marginfi tests", async () => {
127
131
  // )
128
132
  // );
129
133
 
130
- transactionItems.push(
131
- new TransactionItem(
132
- async (attemptNum) =>
133
- await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
134
- "rebalance"
135
- )
136
- );
134
+ // transactionItems.push(
135
+ // new TransactionItem(
136
+ // async (attemptNum) =>
137
+ // await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
138
+ // "rebalance"
139
+ // )
140
+ // );
137
141
 
138
142
  // transactionItems.push(
139
143
  // new TransactionItem(
@@ -147,13 +151,34 @@ describe("Solauto Marginfi tests", async () => {
147
151
  // new TransactionItem(
148
152
  // async () => ({
149
153
  // tx: client.protocolInteraction(
150
- // solautoAction("Withdraw", [{ __kind: "All" }])
154
+ // solautoAction("Withdraw", [{ __kind: "Some", fields: [toBaseUnit(0.03, 9)] }])
155
+ // ),
156
+ // }),
157
+ // "withdraw"
158
+ // )
159
+ // );
160
+ // transactionItems.push(
161
+ // new TransactionItem(
162
+ // async () => ({
163
+ // tx: client.protocolInteraction(
164
+ // solautoAction("Withdraw", [{ __kind: "Some", fields: [toBaseUnit(0.03, 9)] }])
151
165
  // ),
152
166
  // }),
153
167
  // "withdraw"
154
168
  // )
155
169
  // );
156
170
 
171
+ transactionItems.push(
172
+ new TransactionItem(
173
+ async () => ({
174
+ tx: client.protocolInteraction(
175
+ solautoAction("Withdraw", [{ __kind: "Some", fields: [toBaseUnit(300, 9)] }])
176
+ ),
177
+ }),
178
+ "withdraw"
179
+ )
180
+ );
181
+
157
182
  // transactionItems.push(
158
183
  // new TransactionItem(
159
184
  // async () => ({
@@ -163,14 +188,16 @@ describe("Solauto Marginfi tests", async () => {
163
188
  // )
164
189
  // );
165
190
 
166
- // const statuses = await new TransactionsManager(
167
- // client,
168
- // undefined,
169
- // !payForTransactions ? "only-simulate" : "normal",
170
- // PriorityFeeSetting.Low,
171
- // true
172
- // ).clientSend(transactionItems);
191
+ const temp = (statuses: TransactionManagerStatuses) => console.log(statuses);
192
+
193
+ const statuses = await new TransactionsManager(
194
+ client,
195
+ temp,
196
+ !payForTransactions ? "only-simulate" : "normal",
197
+ PriorityFeeSetting.Low,
198
+ true
199
+ ).clientSend(transactionItems);
173
200
 
174
- // console.log(statuses);
201
+ console.log(statuses);
175
202
  });
176
203
  });