@haven-fi/solauto-sdk 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/solautoConstants.d.ts +0 -3
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +7 -4
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +10 -5
- package/dist/utils/jitoUtils.d.ts +0 -14
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +169 -106
- package/package.json +1 -2
- package/src/constants/solautoConstants.ts +6 -6
- package/src/transactions/transactionsManager.ts +10 -9
- package/src/utils/jitoUtils.ts +188 -188
@@ -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;
|
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.
|
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
|
-
|
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
|
-
|
16
|
-
|
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;
|
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;CA8HX"}
|
@@ -10,7 +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
|
-
|
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.
|
194
|
-
|
195
|
-
|
196
|
-
|
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":"
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":""}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -1,107 +1,170 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
+
// }
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@haven-fi/solauto-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
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
|
-
|
31
|
-
|
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.
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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);
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
} from "../constants/solautoConstants";
|
10
|
-
import {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
} from "@metaplex-foundation/umi";
|
15
|
-
import {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
} from "./solanaUtils";
|
21
|
-
import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
|
22
|
-
import {
|
23
|
-
|
24
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
|
35
|
-
export async function getRandomTipAccount(): Promise<PublicKey> {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
export async function waitUntilJitoNextLeader(
|
42
|
-
|
43
|
-
) {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
55
|
-
|
56
|
-
async function getTipInstruction(
|
57
|
-
|
58
|
-
|
59
|
-
): Promise<WrappedInstruction> {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
async function simulateJitoBundle(
|
68
|
-
|
69
|
-
): Promise<SimulatedBundleTransactionResult[]> {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}
|
87
|
-
|
88
|
-
async function umiToVersionedTransactions(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
): Promise<VersionedTransaction[]> {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
async function sendJitoBundle(bundle: Bundle): Promise<BundleResult> {
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
interface JitoTransactionsResult {
|
142
|
-
|
143
|
-
|
144
|
-
}
|
145
|
-
|
146
|
-
export async function sendJitoBundledTransactions(
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
): Promise<JitoTransactionsResult | undefined> {
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
+
// }
|