@haven-fi/solauto-sdk 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,9 @@
1
1
  import { Connection } from "@solana/web3.js";
2
- import { JitoRpcConnection } from "jito-ts";
3
2
  export declare const DEFAULT_RISK_AVERSION_BPS = 1500;
4
3
  export declare const DEFAULT_LIMIT_GAP_BPS = 1000;
5
4
  export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
6
5
  export declare const MAX_REPAY_GAP_BPS = 100;
7
6
  export declare const CONNECTION: Connection;
8
- export declare const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
9
- export declare const JITO_CONNECTION: JitoRpcConnection;
10
7
  export declare const UMI: import("@metaplex-foundation/umi").Umi;
11
8
  export declare const PRICES: {
12
9
  [key: string]: {
@@ -1 +1 @@
1
- {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,UAAU,EAEX,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAI5C,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,eAAO,MAAM,UAAU,YAGtB,CAAC;AAEF,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AACpE,eAAO,MAAM,eAAe,mBAG3B,CAAC;AACF,eAAO,MAAM,GAAG,wCAId,CAAC;AAEH,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
1
+ {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,UAAU,EAEX,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,eAAO,MAAM,UAAU,YAGtB,CAAC;AAOF,eAAO,MAAM,GAAG,wCAId,CAAC;AAEH,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.PRICES = exports.UMI = exports.JITO_CONNECTION = exports.JITO_BLOCK_ENGINE = exports.CONNECTION = exports.MAX_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.DEFAULT_RISK_AVERSION_BPS = void 0;
3
+ exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.PRICES = exports.UMI = exports.CONNECTION = exports.MAX_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.DEFAULT_RISK_AVERSION_BPS = void 0;
4
4
  const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const spl_token_1 = require("@solana/spl-token");
7
- const jito_ts_1 = require("jito-ts");
7
+ // import { JitoRpcConnection } from "jito-ts";
8
8
  const generated_1 = require("../generated");
9
9
  const generalAccounts_1 = require("./generalAccounts");
10
10
  exports.DEFAULT_RISK_AVERSION_BPS = 1500;
@@ -12,8 +12,11 @@ exports.DEFAULT_LIMIT_GAP_BPS = 1000;
12
12
  exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
13
13
  exports.MAX_REPAY_GAP_BPS = 100;
14
14
  exports.CONNECTION = new web3_js_1.Connection(`https://mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`, "finalized");
15
- exports.JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
16
- exports.JITO_CONNECTION = new jito_ts_1.JitoRpcConnection(`https://${exports.JITO_BLOCK_ENGINE}`, "finalized");
15
+ // export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
16
+ // export const JITO_CONNECTION = new JitoRpcConnection(
17
+ // `https://${JITO_BLOCK_ENGINE}`,
18
+ // "finalized"
19
+ // );
17
20
  exports.UMI = (0, umi_bundle_defaults_1.createUmi)(exports.CONNECTION).use({
18
21
  install(umi) {
19
22
  umi.programs.add((0, generated_1.createSolautoProgram)(), false);
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuCzD,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE;IACM,IAAI,CAAC;IATd,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE,EACM,IAAI,CAAC,oBAAQ;IAGhB,UAAU;IAIV,OAAO,CAAC,UAAU,EAAE,MAAM;CAKjC;AAsED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,YAAY,CAAC;IARvB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,eAAe,EAAE,EACxB,cAAc,CAAC,6CAA4C,IAAI,aAAA,EAC/D,YAAY,CAAC,qBAAS,EACtB,YAAY,CAAC,qBAAS;YAKlB,uBAAuB;IAsCrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAgB9D,IAAI;CA6HX"}
1
+ {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuCzD,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd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 +10,7 @@ const solanaUtils_1 = require("../utils/solanaUtils");
10
10
  const solautoConstants_1 = require("../constants/solautoConstants");
11
11
  const generalUtils_1 = require("../utils/generalUtils");
12
12
  const transactionUtils_1 = require("./transactionUtils");
13
- const jitoUtils_1 = require("../utils/jitoUtils");
13
+ // import { sendJitoBundledTransactions } from "../utils/jitoUtils";
14
14
  class LookupTables {
15
15
  constructor(client) {
16
16
  this.client = client;
@@ -190,10 +190,15 @@ class TransactionsManager {
190
190
  this.updateStatus(itemSet.name(), TransactionStatus.Queued);
191
191
  }
192
192
  if (this.mustBeAtomic && itemSets.length > 1) {
193
- itemSets.forEach((set) => {
194
- this.updateStatus(set.name(), TransactionStatus.Processing);
195
- });
196
- await (0, jitoUtils_1.sendJitoBundledTransactions)(this.client, await Promise.all(itemSets.map((x) => x.getSingleTransaction())), this.simulateOnly);
193
+ throw new Error(`${itemSets.length} transactions required but jito bundles are not currently supported`);
194
+ // itemSets.forEach((set) => {
195
+ // this.updateStatus(set.name(), TransactionStatus.Processing);
196
+ // });
197
+ // await sendJitoBundledTransactions(
198
+ // this.client,
199
+ // await Promise.all(itemSets.map((x) => x.getSingleTransaction())),
200
+ // this.simulateOnly
201
+ // );
197
202
  // TODO: check if successful or not
198
203
  // itemSets.forEach((set) => {
199
204
  // this.updateStatus(set.name(), TransactionStatus.Successful);
@@ -1,15 +1 @@
1
- import { SolautoClient } from "../clients/solautoClient";
2
- import { PublicKey } from "@solana/web3.js";
3
- import { TransactionBuilder } from "@metaplex-foundation/umi";
4
- import { SearcherClient } from "jito-ts/dist/sdk/block-engine/searcher";
5
- import { BundleResult } from "jito-ts/dist/gen/block-engine/bundle";
6
- export declare function getSearcherClient(): SearcherClient;
7
- export declare function getRandomTipAccount(): Promise<PublicKey>;
8
- export declare function waitUntilJitoNextLeader(distanceFromJitoSlot?: number): Promise<void>;
9
- interface JitoTransactionsResult {
10
- bundleResult: BundleResult;
11
- txSigs: Uint8Array[];
12
- }
13
- export declare function sendJitoBundledTransactions(client: SolautoClient, txs: TransactionBuilder[], simulateOnly?: boolean): Promise<JitoTransactionsResult | undefined>;
14
- export {};
15
1
  //# 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,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAW,SAAS,EAAwB,MAAM,iBAAiB,CAAC;AAQ3E,OAAO,EAEL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EACL,cAAc,EAEf,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAI9D;AAED,wBAAsB,uBAAuB,CAC3C,oBAAoB,GAAE,MAAU,iBAYjC;AAuFD,UAAU,sBAAsB;IAC9B,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,kBAAkB,EAAE,EACzB,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAsC7C"}
1
+ {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":""}
@@ -1,107 +1,170 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendJitoBundledTransactions = exports.waitUntilJitoNextLeader = exports.getRandomTipAccount = exports.getSearcherClient = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
6
- const solautoConstants_1 = require("../constants/solautoConstants");
7
- const solanaUtils_1 = require("./solanaUtils");
8
- const types_1 = require("jito-ts/dist/sdk/block-engine/types");
9
- const searcher_1 = require("jito-ts/dist/sdk/block-engine/searcher");
10
- function getSearcherClient() {
11
- return (0, searcher_1.searcherClient)(solautoConstants_1.JITO_BLOCK_ENGINE, web3_js_1.Keypair.fromSecretKey((0, solanaUtils_1.getSecretKey)("jito-bundles")));
12
- }
13
- exports.getSearcherClient = getSearcherClient;
14
- async function getRandomTipAccount() {
15
- const tipAccounts = await getSearcherClient().getTipAccounts();
16
- const randomInt = Math.floor(Math.random() * tipAccounts.length);
17
- return new web3_js_1.PublicKey(tipAccounts[randomInt]);
18
- }
19
- exports.getRandomTipAccount = getRandomTipAccount;
20
- async function waitUntilJitoNextLeader(distanceFromJitoSlot = 5) {
21
- let searcher = getSearcherClient();
22
- let isLeaderSlot = false;
23
- while (!isLeaderSlot) {
24
- const nextLeader = await searcher.getNextScheduledLeader();
25
- const numSlots = nextLeader.nextLeaderSlot - nextLeader.currentSlot;
26
- isLeaderSlot = numSlots <= distanceFromJitoSlot && numSlots > 1;
27
- console.log(`Next jito leader slot in ${numSlots} slots`);
28
- await new Promise((r) => setTimeout(r, 500));
29
- }
30
- }
31
- exports.waitUntilJitoNextLeader = waitUntilJitoNextLeader;
32
- async function getTipInstruction(client, tipLamports) {
33
- return (0, solanaUtils_1.systemTransferUmiIx)(client.signer, await getRandomTipAccount(), BigInt(tipLamports));
34
- }
35
- async function simulateJitoBundle(txs) {
36
- const simulationResult = await solautoConstants_1.JITO_CONNECTION.simulateBundle(txs, {
37
- preExecutionAccountsConfigs: txs.map((x) => null),
38
- postExecutionAccountsConfigs: txs.map((x) => null),
39
- skipSigVerify: true,
40
- });
41
- simulationResult.value.transactionResults.forEach((tx) => {
42
- if (tx.err) {
43
- tx.logs?.forEach((x) => {
44
- console.log(x);
45
- });
46
- throw tx.err;
47
- }
48
- });
49
- return simulationResult.value.transactionResults;
50
- }
51
- async function umiToVersionedTransactions(signer, txs, feeEstimates, computeUnitLimits) {
52
- return await Promise.all(txs.map(async (tx, i) => {
53
- const versionedTx = (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await (0, solanaUtils_1.assembleFinalTransaction)(signer, tx, feeEstimates[i], computeUnitLimits ? computeUnitLimits[i] : undefined).setLatestBlockhash(solautoConstants_1.UMI)).buildAndSign(solautoConstants_1.UMI));
54
- return versionedTx;
55
- }));
56
- }
57
- async function sendJitoBundle(bundle) {
58
- await waitUntilJitoNextLeader();
59
- let searcher = getSearcherClient();
60
- console.log("Sending bundle...");
61
- try {
62
- const resp = await searcher.sendBundle(bundle);
63
- console.log("Send bundle response:", resp);
64
- }
65
- catch (e) {
66
- console.error("Error sending bundle:", e);
67
- }
68
- return await new Promise((resolve, reject) => {
69
- searcher.onBundleResult((res) => {
70
- if (res.accepted || res.processed || res.finalized) {
71
- resolve(res);
72
- }
73
- else {
74
- console.log(res);
75
- return reject("Bundle not accepted");
76
- }
77
- }, (err) => {
78
- console.log("Error: ", err);
79
- return reject(err);
80
- });
81
- });
82
- }
83
- async function sendJitoBundledTransactions(client, txs, simulateOnly) {
84
- client.log("Sending Jito bundle...");
85
- client.log("Transactions: ", txs.length);
86
- client.log("Transaction sizes: ", txs.map((x) => x.getTransactionSize(solautoConstants_1.UMI)));
87
- txs[0] = txs[0].prepend(await getTipInstruction(client, 1000000));
88
- const feeEstimates = await Promise.all(txs.map(solanaUtils_1.getComputeUnitPriceEstimate));
89
- let builtTxs = await umiToVersionedTransactions(client.signer, txs, feeEstimates);
90
- // // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
91
- // const simulationResults = await simulateJitoBundle(builtTxs);
92
- if (!simulateOnly) {
93
- // let builtTxs = await umiToVersionedTransactions(
94
- // client.signer,
95
- // txs,
96
- // feeEstimates,
97
- // simulationResults.map((x) => x.unitsConsumed! * 1.15)
98
- // );
99
- const bundleResult = await sendJitoBundle(new types_1.Bundle(builtTxs, 100));
100
- return {
101
- bundleResult,
102
- txSigs: builtTxs.map((x) => x.signatures).flat(),
103
- };
104
- }
105
- return undefined;
106
- }
107
- exports.sendJitoBundledTransactions = sendJitoBundledTransactions;
2
+ // import { SolautoClient } from "../clients/solautoClient";
3
+ // import { Keypair, PublicKey, VersionedTransaction } from "@solana/web3.js";
4
+ // import { SimulatedBundleTransactionResult } from "jito-ts";
5
+ // import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
6
+ // import {
7
+ // JITO_BLOCK_ENGINE,
8
+ // JITO_CONNECTION,
9
+ // UMI,
10
+ // } from "../constants/solautoConstants";
11
+ // import {
12
+ // Signer,
13
+ // TransactionBuilder,
14
+ // WrappedInstruction,
15
+ // } from "@metaplex-foundation/umi";
16
+ // import {
17
+ // assembleFinalTransaction,
18
+ // getComputeUnitPriceEstimate,
19
+ // getSecretKey,
20
+ // systemTransferUmiIx,
21
+ // } from "./solanaUtils";
22
+ // import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
23
+ // import {
24
+ // SearcherClient,
25
+ // searcherClient,
26
+ // } from "jito-ts/dist/sdk/block-engine/searcher";
27
+ // import { BundleResult } from "jito-ts/dist/gen/block-engine/bundle";
28
+ // export function getSearcherClient(): SearcherClient {
29
+ // return searcherClient(
30
+ // JITO_BLOCK_ENGINE,
31
+ // Keypair.fromSecretKey(getSecretKey("jito-bundles"))
32
+ // );
33
+ // }
34
+ // export async function getRandomTipAccount(): Promise<PublicKey> {
35
+ // const tipAccounts = await getSearcherClient().getTipAccounts();
36
+ // const randomInt = Math.floor(Math.random() * tipAccounts.length);
37
+ // return new PublicKey(tipAccounts[randomInt]);
38
+ // }
39
+ // export async function waitUntilJitoNextLeader(
40
+ // distanceFromJitoSlot: number = 5
41
+ // ) {
42
+ // let searcher = getSearcherClient();
43
+ // let isLeaderSlot = false;
44
+ // while (!isLeaderSlot) {
45
+ // const nextLeader = await searcher.getNextScheduledLeader();
46
+ // const numSlots = nextLeader.nextLeaderSlot - nextLeader.currentSlot;
47
+ // isLeaderSlot = numSlots <= distanceFromJitoSlot && numSlots > 1;
48
+ // console.log(`Next jito leader slot in ${numSlots} slots`);
49
+ // await new Promise((r) => setTimeout(r, 500));
50
+ // }
51
+ // }
52
+ // async function getTipInstruction(
53
+ // client: SolautoClient,
54
+ // tipLamports: number
55
+ // ): Promise<WrappedInstruction> {
56
+ // return systemTransferUmiIx(
57
+ // client.signer,
58
+ // await getRandomTipAccount(),
59
+ // BigInt(tipLamports)
60
+ // );
61
+ // }
62
+ // async function simulateJitoBundle(
63
+ // txs: VersionedTransaction[]
64
+ // ): Promise<SimulatedBundleTransactionResult[]> {
65
+ // const simulationResult = await JITO_CONNECTION.simulateBundle(txs, {
66
+ // preExecutionAccountsConfigs: txs.map((x) => null),
67
+ // postExecutionAccountsConfigs: txs.map((x) => null),
68
+ // skipSigVerify: true,
69
+ // });
70
+ // simulationResult.value.transactionResults.forEach((tx) => {
71
+ // if (tx.err) {
72
+ // tx.logs?.forEach((x) => {
73
+ // console.log(x);
74
+ // });
75
+ // throw tx.err;
76
+ // }
77
+ // });
78
+ // return simulationResult.value.transactionResults;
79
+ // }
80
+ // async function umiToVersionedTransactions(
81
+ // signer: Signer,
82
+ // txs: TransactionBuilder[],
83
+ // feeEstimates: number[],
84
+ // computeUnitLimits?: number[]
85
+ // ): Promise<VersionedTransaction[]> {
86
+ // return await Promise.all(
87
+ // txs.map(async (tx, i) => {
88
+ // const versionedTx = toWeb3JsTransaction(
89
+ // await (
90
+ // await assembleFinalTransaction(
91
+ // signer,
92
+ // tx,
93
+ // feeEstimates[i],
94
+ // computeUnitLimits ? computeUnitLimits[i] : undefined
95
+ // ).setLatestBlockhash(UMI)
96
+ // ).buildAndSign(UMI)
97
+ // );
98
+ // return versionedTx;
99
+ // })
100
+ // );
101
+ // }
102
+ // async function sendJitoBundle(bundle: Bundle): Promise<BundleResult> {
103
+ // await waitUntilJitoNextLeader();
104
+ // let searcher = getSearcherClient();
105
+ // console.log("Sending bundle...");
106
+ // try {
107
+ // const resp = await searcher.sendBundle(bundle);
108
+ // console.log("Send bundle response:", resp);
109
+ // } catch (e) {
110
+ // console.error("Error sending bundle:", e);
111
+ // }
112
+ // return await new Promise((resolve, reject) => {
113
+ // searcher.onBundleResult(
114
+ // (res) => {
115
+ // if (res.accepted || res.processed || res.finalized) {
116
+ // resolve(res);
117
+ // } else {
118
+ // console.log(res);
119
+ // return reject("Bundle not accepted");
120
+ // }
121
+ // },
122
+ // (err) => {
123
+ // console.log("Error: ", err);
124
+ // return reject(err);
125
+ // }
126
+ // );
127
+ // });
128
+ // }
129
+ // interface JitoTransactionsResult {
130
+ // bundleResult: BundleResult;
131
+ // txSigs: Uint8Array[];
132
+ // }
133
+ // export async function sendJitoBundledTransactions(
134
+ // client: SolautoClient,
135
+ // txs: TransactionBuilder[],
136
+ // simulateOnly?: boolean
137
+ // ): Promise<JitoTransactionsResult | undefined> {
138
+ // client.log("Sending Jito bundle...");
139
+ // client.log("Transactions: ", txs.length);
140
+ // client.log(
141
+ // "Transaction sizes: ",
142
+ // txs.map((x) => x.getTransactionSize(UMI))
143
+ // );
144
+ // txs[0] = txs[0].prepend(await getTipInstruction(client, 1000000));
145
+ // const feeEstimates = await Promise.all(txs.map(getComputeUnitPriceEstimate));
146
+ // let builtTxs = await umiToVersionedTransactions(
147
+ // client.signer,
148
+ // txs,
149
+ // feeEstimates,
150
+ // // Array(txs.length).fill(1_400_000)
151
+ // );
152
+ // // // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
153
+ // // const simulationResults = await simulateJitoBundle(builtTxs);
154
+ // if (!simulateOnly) {
155
+ // // let builtTxs = await umiToVersionedTransactions(
156
+ // // client.signer,
157
+ // // txs,
158
+ // // feeEstimates,
159
+ // // simulationResults.map((x) => x.unitsConsumed! * 1.15)
160
+ // // );
161
+ // const bundleResult = await sendJitoBundle(
162
+ // new Bundle(builtTxs, 100)
163
+ // );
164
+ // return {
165
+ // bundleResult,
166
+ // txSigs: builtTxs.map((x) => x.signatures).flat(),
167
+ // };
168
+ // }
169
+ // return undefined;
170
+ // }
@@ -1 +1 @@
1
- {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAIpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CA4D7B"}
1
+ {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CA+D7B"}
@@ -5,7 +5,6 @@ const umi_1 = require("@metaplex-foundation/umi");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const solanaUtils_1 = require("./solanaUtils");
7
7
  const numberUtils_1 = require("./numberUtils");
8
- const console_1 = require("console");
9
8
  const api_1 = require("@jup-ag/api");
10
9
  const accountUtils_1 = require("./accountUtils");
11
10
  const jupApi = (0, api_1.createJupiterApiClient)();
@@ -47,7 +46,9 @@ async function getJupSwapTransaction(signer, swapDetails) {
47
46
  destinationTokenAccount: (0, accountUtils_1.getTokenAccount)(swapDetails.destinationWallet, swapDetails.outputMint).toString(),
48
47
  },
49
48
  });
50
- (0, console_1.assert)(instructions.swapInstruction !== undefined);
49
+ if (!instructions.swapInstruction) {
50
+ throw new Error("No swap instruction was returned by Jupiter");
51
+ }
51
52
  return {
52
53
  jupQuote: quoteResponse,
53
54
  lookupTableAddresses: instructions.addressLookupTableAddresses,
@@ -1 +1 @@
1
- {"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,kBAAkB,EAGnB,MAAM,0BAA0B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AkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,EACtB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,EACvB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,GACb,kBAAkB,CAKpB;AAED,wBAAsB,qBAAqB,CACzC,oBAAoB,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBpC;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,kBAAkB,EACtB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,sBA4D1B;AAiBD,wBAAsB,2BAA2B,CAC/C,EAAE,EAAE,kBAAkB,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,YAAY,CAAC,EAAE,OAAO,EACtB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAqDjC"}
@@ -152,7 +152,6 @@ async function getComputeUnitPriceEstimate(tx, attemptNum) {
152
152
  },
153
153
  ]);
154
154
  const feeEstimate = Math.round(resp.priorityFeeEstimate);
155
- console.log("Compute unit price: ", feeEstimate);
156
155
  return feeEstimate;
157
156
  }
158
157
  exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
@@ -161,9 +160,10 @@ async function sendSingleOptimizedTransaction(client, tx, simulateOnly, attemptN
161
160
  client.log("Instructions: ", tx.getInstructions().length);
162
161
  client.log("Serialized transaction size: ", tx.getTransactionSize(solautoConstants_1.UMI));
163
162
  const feeEstimate = await getComputeUnitPriceEstimate(tx, attemptNum);
163
+ client.log("Compute unit price: ", feeEstimate);
164
164
  const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction((0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(client.signer, tx, feeEstimate, 1400000).setLatestBlockhash(solautoConstants_1.UMI)).buildAndSign(solautoConstants_1.UMI))));
165
165
  const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.15);
166
- console.log("Compute unit limit: ", computeUnitLimit);
166
+ client.log("Compute unit limit: ", computeUnitLimit);
167
167
  if (!simulateOnly) {
168
168
  const result = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await assembleFinalTransaction(client.signer, tx, feeEstimate, computeUnitLimit).sendAndConfirm(solautoConstants_1.UMI, {
169
169
  send: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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",
@@ -24,7 +24,6 @@
24
24
  "@types/node": "^20.14.8",
25
25
  "bs58": "^5.0.0",
26
26
  "cross-fetch": "^4.0.0",
27
- "jito-ts": "^4.0.1",
28
27
  "rpc-websockets": "7.11.0"
29
28
  },
30
29
  "devDependencies": {
@@ -11,7 +11,7 @@ import {
11
11
  ASSOCIATED_TOKEN_PROGRAM_ID,
12
12
  TOKEN_PROGRAM_ID,
13
13
  } from "@solana/spl-token";
14
- import { JitoRpcConnection } from "jito-ts";
14
+ // import { JitoRpcConnection } from "jito-ts";
15
15
  import { createSolautoProgram, SOLAUTO_PROGRAM_ID } from "../generated";
16
16
  import { SOLAUTO_MANAGER } from "./generalAccounts";
17
17
 
@@ -25,11 +25,11 @@ export const CONNECTION = new Connection(
25
25
  "finalized"
26
26
  );
27
27
 
28
- export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
29
- export const JITO_CONNECTION = new JitoRpcConnection(
30
- `https://${JITO_BLOCK_ENGINE}`,
31
- "finalized"
32
- );
28
+ // export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
29
+ // export const JITO_CONNECTION = new JitoRpcConnection(
30
+ // `https://${JITO_BLOCK_ENGINE}`,
31
+ // "finalized"
32
+ // );
33
33
  export const UMI = createUmi(CONNECTION).use({
34
34
  install(umi) {
35
35
  umi.programs.add(createSolautoProgram(), false);
@@ -12,7 +12,7 @@ import {
12
12
  import { UMI } from "../constants/solautoConstants";
13
13
  import { retryWithExponentialBackoff } from "../utils/generalUtils";
14
14
  import { getTransactionChores } from "./transactionUtils";
15
- import { sendJitoBundledTransactions } from "../utils/jitoUtils";
15
+ // import { sendJitoBundledTransactions } from "../utils/jitoUtils";
16
16
 
17
17
  class LookupTables {
18
18
  defaultLuts: string[] = [];
@@ -264,14 +264,15 @@ export class TransactionsManager {
264
264
  }
265
265
 
266
266
  if (this.mustBeAtomic && itemSets.length > 1) {
267
- itemSets.forEach((set) => {
268
- this.updateStatus(set.name(), TransactionStatus.Processing);
269
- });
270
- await sendJitoBundledTransactions(
271
- this.client,
272
- await Promise.all(itemSets.map((x) => x.getSingleTransaction())),
273
- this.simulateOnly
274
- );
267
+ throw new Error(`${itemSets.length} transactions required but jito bundles are not currently supported`);
268
+ // itemSets.forEach((set) => {
269
+ // this.updateStatus(set.name(), TransactionStatus.Processing);
270
+ // });
271
+ // await sendJitoBundledTransactions(
272
+ // this.client,
273
+ // await Promise.all(itemSets.map((x) => x.getSingleTransaction())),
274
+ // this.simulateOnly
275
+ // );
275
276
  // TODO: check if successful or not
276
277
  // itemSets.forEach((set) => {
277
278
  // this.updateStatus(set.name(), TransactionStatus.Successful);
@@ -1,188 +1,188 @@
1
- import { SolautoClient } from "../clients/solautoClient";
2
- import { Keypair, PublicKey, VersionedTransaction } from "@solana/web3.js";
3
- import { SimulatedBundleTransactionResult } from "jito-ts";
4
- import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
5
- import {
6
- JITO_BLOCK_ENGINE,
7
- JITO_CONNECTION,
8
- UMI,
9
- } from "../constants/solautoConstants";
10
- import {
11
- Signer,
12
- TransactionBuilder,
13
- WrappedInstruction,
14
- } from "@metaplex-foundation/umi";
15
- import {
16
- assembleFinalTransaction,
17
- getComputeUnitPriceEstimate,
18
- getSecretKey,
19
- systemTransferUmiIx,
20
- } from "./solanaUtils";
21
- import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
22
- import {
23
- SearcherClient,
24
- searcherClient,
25
- } from "jito-ts/dist/sdk/block-engine/searcher";
26
- import { BundleResult } from "jito-ts/dist/gen/block-engine/bundle";
27
-
28
- export function getSearcherClient(): SearcherClient {
29
- return searcherClient(
30
- JITO_BLOCK_ENGINE,
31
- Keypair.fromSecretKey(getSecretKey("jito-bundles"))
32
- );
33
- }
34
-
35
- export async function getRandomTipAccount(): Promise<PublicKey> {
36
- const tipAccounts = await getSearcherClient().getTipAccounts();
37
- const randomInt = Math.floor(Math.random() * tipAccounts.length);
38
- return new PublicKey(tipAccounts[randomInt]);
39
- }
40
-
41
- export async function waitUntilJitoNextLeader(
42
- distanceFromJitoSlot: number = 5
43
- ) {
44
- let searcher = getSearcherClient();
45
- let isLeaderSlot = false;
46
-
47
- while (!isLeaderSlot) {
48
- const nextLeader = await searcher.getNextScheduledLeader();
49
- const numSlots = nextLeader.nextLeaderSlot - nextLeader.currentSlot;
50
- isLeaderSlot = numSlots <= distanceFromJitoSlot && numSlots > 1;
51
- console.log(`Next jito leader slot in ${numSlots} slots`);
52
- await new Promise((r) => setTimeout(r, 500));
53
- }
54
- }
55
-
56
- async function getTipInstruction(
57
- client: SolautoClient,
58
- tipLamports: number
59
- ): Promise<WrappedInstruction> {
60
- return systemTransferUmiIx(
61
- client.signer,
62
- await getRandomTipAccount(),
63
- BigInt(tipLamports)
64
- );
65
- }
66
-
67
- async function simulateJitoBundle(
68
- txs: VersionedTransaction[]
69
- ): Promise<SimulatedBundleTransactionResult[]> {
70
- const simulationResult = await JITO_CONNECTION.simulateBundle(txs, {
71
- preExecutionAccountsConfigs: txs.map((x) => null),
72
- postExecutionAccountsConfigs: txs.map((x) => null),
73
- skipSigVerify: true,
74
- });
75
-
76
- simulationResult.value.transactionResults.forEach((tx) => {
77
- if (tx.err) {
78
- tx.logs?.forEach((x) => {
79
- console.log(x);
80
- });
81
- throw tx.err;
82
- }
83
- });
84
-
85
- return simulationResult.value.transactionResults;
86
- }
87
-
88
- async function umiToVersionedTransactions(
89
- signer: Signer,
90
- txs: TransactionBuilder[],
91
- feeEstimates: number[],
92
- computeUnitLimits?: number[]
93
- ): Promise<VersionedTransaction[]> {
94
- return await Promise.all(
95
- txs.map(async (tx, i) => {
96
- const versionedTx = toWeb3JsTransaction(
97
- await (
98
- await assembleFinalTransaction(
99
- signer,
100
- tx,
101
- feeEstimates[i],
102
- computeUnitLimits ? computeUnitLimits[i] : undefined
103
- ).setLatestBlockhash(UMI)
104
- ).buildAndSign(UMI)
105
- );
106
- return versionedTx;
107
- })
108
- );
109
- }
110
-
111
- async function sendJitoBundle(bundle: Bundle): Promise<BundleResult> {
112
- await waitUntilJitoNextLeader();
113
- let searcher = getSearcherClient();
114
-
115
- console.log("Sending bundle...");
116
- try {
117
- const resp = await searcher.sendBundle(bundle);
118
- console.log("Send bundle response:", resp);
119
- } catch (e) {
120
- console.error("Error sending bundle:", e);
121
- }
122
-
123
- return await new Promise((resolve, reject) => {
124
- searcher.onBundleResult(
125
- (res) => {
126
- if (res.accepted || res.processed || res.finalized) {
127
- resolve(res);
128
- } else {
129
- console.log(res);
130
- return reject("Bundle not accepted");
131
- }
132
- },
133
- (err) => {
134
- console.log("Error: ", err);
135
- return reject(err);
136
- }
137
- );
138
- });
139
- }
140
-
141
- interface JitoTransactionsResult {
142
- bundleResult: BundleResult;
143
- txSigs: Uint8Array[];
144
- }
145
-
146
- export async function sendJitoBundledTransactions(
147
- client: SolautoClient,
148
- txs: TransactionBuilder[],
149
- simulateOnly?: boolean
150
- ): Promise<JitoTransactionsResult | undefined> {
151
- client.log("Sending Jito bundle...");
152
- client.log("Transactions: ", txs.length);
153
- client.log(
154
- "Transaction sizes: ",
155
- txs.map((x) => x.getTransactionSize(UMI))
156
- );
157
-
158
- txs[0] = txs[0].prepend(await getTipInstruction(client, 1000000));
159
- const feeEstimates = await Promise.all(txs.map(getComputeUnitPriceEstimate));
160
-
161
- let builtTxs = await umiToVersionedTransactions(
162
- client.signer,
163
- txs,
164
- feeEstimates,
165
- // Array(txs.length).fill(1_400_000)
166
- );
167
- // // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
168
- // const simulationResults = await simulateJitoBundle(builtTxs);
169
-
170
- if (!simulateOnly) {
171
- // let builtTxs = await umiToVersionedTransactions(
172
- // client.signer,
173
- // txs,
174
- // feeEstimates,
175
- // simulationResults.map((x) => x.unitsConsumed! * 1.15)
176
- // );
177
-
178
- const bundleResult = await sendJitoBundle(
179
- new Bundle(builtTxs, 100)
180
- );
181
- return {
182
- bundleResult,
183
- txSigs: builtTxs.map((x) => x.signatures).flat(),
184
- };
185
- }
186
-
187
- return undefined;
188
- }
1
+ // import { SolautoClient } from "../clients/solautoClient";
2
+ // import { Keypair, PublicKey, VersionedTransaction } from "@solana/web3.js";
3
+ // import { SimulatedBundleTransactionResult } from "jito-ts";
4
+ // import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
5
+ // import {
6
+ // JITO_BLOCK_ENGINE,
7
+ // JITO_CONNECTION,
8
+ // UMI,
9
+ // } from "../constants/solautoConstants";
10
+ // import {
11
+ // Signer,
12
+ // TransactionBuilder,
13
+ // WrappedInstruction,
14
+ // } from "@metaplex-foundation/umi";
15
+ // import {
16
+ // assembleFinalTransaction,
17
+ // getComputeUnitPriceEstimate,
18
+ // getSecretKey,
19
+ // systemTransferUmiIx,
20
+ // } from "./solanaUtils";
21
+ // import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
22
+ // import {
23
+ // SearcherClient,
24
+ // searcherClient,
25
+ // } from "jito-ts/dist/sdk/block-engine/searcher";
26
+ // import { BundleResult } from "jito-ts/dist/gen/block-engine/bundle";
27
+
28
+ // export function getSearcherClient(): SearcherClient {
29
+ // return searcherClient(
30
+ // JITO_BLOCK_ENGINE,
31
+ // Keypair.fromSecretKey(getSecretKey("jito-bundles"))
32
+ // );
33
+ // }
34
+
35
+ // export async function getRandomTipAccount(): Promise<PublicKey> {
36
+ // const tipAccounts = await getSearcherClient().getTipAccounts();
37
+ // const randomInt = Math.floor(Math.random() * tipAccounts.length);
38
+ // return new PublicKey(tipAccounts[randomInt]);
39
+ // }
40
+
41
+ // export async function waitUntilJitoNextLeader(
42
+ // distanceFromJitoSlot: number = 5
43
+ // ) {
44
+ // let searcher = getSearcherClient();
45
+ // let isLeaderSlot = false;
46
+
47
+ // while (!isLeaderSlot) {
48
+ // const nextLeader = await searcher.getNextScheduledLeader();
49
+ // const numSlots = nextLeader.nextLeaderSlot - nextLeader.currentSlot;
50
+ // isLeaderSlot = numSlots <= distanceFromJitoSlot && numSlots > 1;
51
+ // console.log(`Next jito leader slot in ${numSlots} slots`);
52
+ // await new Promise((r) => setTimeout(r, 500));
53
+ // }
54
+ // }
55
+
56
+ // async function getTipInstruction(
57
+ // client: SolautoClient,
58
+ // tipLamports: number
59
+ // ): Promise<WrappedInstruction> {
60
+ // return systemTransferUmiIx(
61
+ // client.signer,
62
+ // await getRandomTipAccount(),
63
+ // BigInt(tipLamports)
64
+ // );
65
+ // }
66
+
67
+ // async function simulateJitoBundle(
68
+ // txs: VersionedTransaction[]
69
+ // ): Promise<SimulatedBundleTransactionResult[]> {
70
+ // const simulationResult = await JITO_CONNECTION.simulateBundle(txs, {
71
+ // preExecutionAccountsConfigs: txs.map((x) => null),
72
+ // postExecutionAccountsConfigs: txs.map((x) => null),
73
+ // skipSigVerify: true,
74
+ // });
75
+
76
+ // simulationResult.value.transactionResults.forEach((tx) => {
77
+ // if (tx.err) {
78
+ // tx.logs?.forEach((x) => {
79
+ // console.log(x);
80
+ // });
81
+ // throw tx.err;
82
+ // }
83
+ // });
84
+
85
+ // return simulationResult.value.transactionResults;
86
+ // }
87
+
88
+ // async function umiToVersionedTransactions(
89
+ // signer: Signer,
90
+ // txs: TransactionBuilder[],
91
+ // feeEstimates: number[],
92
+ // computeUnitLimits?: number[]
93
+ // ): Promise<VersionedTransaction[]> {
94
+ // return await Promise.all(
95
+ // txs.map(async (tx, i) => {
96
+ // const versionedTx = toWeb3JsTransaction(
97
+ // await (
98
+ // await assembleFinalTransaction(
99
+ // signer,
100
+ // tx,
101
+ // feeEstimates[i],
102
+ // computeUnitLimits ? computeUnitLimits[i] : undefined
103
+ // ).setLatestBlockhash(UMI)
104
+ // ).buildAndSign(UMI)
105
+ // );
106
+ // return versionedTx;
107
+ // })
108
+ // );
109
+ // }
110
+
111
+ // async function sendJitoBundle(bundle: Bundle): Promise<BundleResult> {
112
+ // await waitUntilJitoNextLeader();
113
+ // let searcher = getSearcherClient();
114
+
115
+ // console.log("Sending bundle...");
116
+ // try {
117
+ // const resp = await searcher.sendBundle(bundle);
118
+ // console.log("Send bundle response:", resp);
119
+ // } catch (e) {
120
+ // console.error("Error sending bundle:", e);
121
+ // }
122
+
123
+ // return await new Promise((resolve, reject) => {
124
+ // searcher.onBundleResult(
125
+ // (res) => {
126
+ // if (res.accepted || res.processed || res.finalized) {
127
+ // resolve(res);
128
+ // } else {
129
+ // console.log(res);
130
+ // return reject("Bundle not accepted");
131
+ // }
132
+ // },
133
+ // (err) => {
134
+ // console.log("Error: ", err);
135
+ // return reject(err);
136
+ // }
137
+ // );
138
+ // });
139
+ // }
140
+
141
+ // interface JitoTransactionsResult {
142
+ // bundleResult: BundleResult;
143
+ // txSigs: Uint8Array[];
144
+ // }
145
+
146
+ // export async function sendJitoBundledTransactions(
147
+ // client: SolautoClient,
148
+ // txs: TransactionBuilder[],
149
+ // simulateOnly?: boolean
150
+ // ): Promise<JitoTransactionsResult | undefined> {
151
+ // client.log("Sending Jito bundle...");
152
+ // client.log("Transactions: ", txs.length);
153
+ // client.log(
154
+ // "Transaction sizes: ",
155
+ // txs.map((x) => x.getTransactionSize(UMI))
156
+ // );
157
+
158
+ // txs[0] = txs[0].prepend(await getTipInstruction(client, 1000000));
159
+ // const feeEstimates = await Promise.all(txs.map(getComputeUnitPriceEstimate));
160
+
161
+ // let builtTxs = await umiToVersionedTransactions(
162
+ // client.signer,
163
+ // txs,
164
+ // feeEstimates,
165
+ // // Array(txs.length).fill(1_400_000)
166
+ // );
167
+ // // // TODO: Skip over this for now, and instead don't specify a compute unit limit in the final bundle transactions
168
+ // // const simulationResults = await simulateJitoBundle(builtTxs);
169
+
170
+ // if (!simulateOnly) {
171
+ // // let builtTxs = await umiToVersionedTransactions(
172
+ // // client.signer,
173
+ // // txs,
174
+ // // feeEstimates,
175
+ // // simulationResults.map((x) => x.unitsConsumed! * 1.15)
176
+ // // );
177
+
178
+ // const bundleResult = await sendJitoBundle(
179
+ // new Bundle(builtTxs, 100)
180
+ // );
181
+ // return {
182
+ // bundleResult,
183
+ // txSigs: builtTxs.map((x) => x.signatures).flat(),
184
+ // };
185
+ // }
186
+
187
+ // return undefined;
188
+ // }
@@ -6,7 +6,6 @@ import {
6
6
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
7
7
  import { getWrappedInstruction } from "./solanaUtils";
8
8
  import { toBps } from "./numberUtils";
9
- import { assert } from "console";
10
9
  import {
11
10
  createJupiterApiClient,
12
11
  Instruction,
@@ -87,7 +86,10 @@ export async function getJupSwapTransaction(
87
86
  },
88
87
  });
89
88
 
90
- assert(instructions.swapInstruction !== undefined);
89
+ if (!instructions.swapInstruction) {
90
+ throw new Error("No swap instruction was returned by Jupiter");
91
+ }
92
+
91
93
  return {
92
94
  jupQuote: quoteResponse,
93
95
  lookupTableAddresses: instructions.addressLookupTableAddresses,
@@ -268,7 +268,6 @@ export async function getComputeUnitPriceEstimate(
268
268
  },
269
269
  ]);
270
270
  const feeEstimate = Math.round((resp as any).priorityFeeEstimate as number);
271
- console.log("Compute unit price: ", feeEstimate);
272
271
 
273
272
  return feeEstimate;
274
273
  }
@@ -284,6 +283,7 @@ export async function sendSingleOptimizedTransaction(
284
283
  client.log("Serialized transaction size: ", tx.getTransactionSize(UMI));
285
284
 
286
285
  const feeEstimate = await getComputeUnitPriceEstimate(tx, attemptNum);
286
+ client.log("Compute unit price: ", feeEstimate);
287
287
 
288
288
  const simulationResult = await retryWithExponentialBackoff(
289
289
  async () =>
@@ -304,7 +304,7 @@ export async function sendSingleOptimizedTransaction(
304
304
  const computeUnitLimit = Math.round(
305
305
  simulationResult.value.unitsConsumed! * 1.15
306
306
  );
307
- console.log("Compute unit limit: ", computeUnitLimit);
307
+ client.log("Compute unit limit: ", computeUnitLimit);
308
308
 
309
309
  if (!simulateOnly) {
310
310
  const result = await retryWithExponentialBackoff(