@hawksightco/hawk-sdk 1.3.265 → 1.3.267
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/addresses.d.ts +37 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +84 -0
- package/dist/anchor.d.ts +22 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +121 -0
- package/dist/classes/AltStorage.d.ts +29 -0
- package/dist/classes/AltStorage.d.ts.map +1 -0
- package/dist/classes/AltStorage.js +58 -0
- package/dist/classes/Atomicity.d.ts +34 -0
- package/dist/classes/Atomicity.d.ts.map +1 -0
- package/dist/classes/Atomicity.js +110 -0
- package/dist/classes/Client.d.ts +35 -0
- package/dist/classes/Client.d.ts.map +1 -0
- package/dist/classes/Client.js +66 -0
- package/dist/classes/CombineTransactions.d.ts +11 -0
- package/dist/classes/CombineTransactions.d.ts.map +1 -0
- package/dist/classes/CombineTransactions.js +58 -0
- package/dist/classes/CreateTxMetadata.d.ts +100 -0
- package/dist/classes/CreateTxMetadata.d.ts.map +1 -0
- package/dist/classes/CreateTxMetadata.js +415 -0
- package/dist/classes/General.d.ts +87 -0
- package/dist/classes/General.d.ts.map +1 -0
- package/dist/classes/General.js +176 -0
- package/dist/classes/GeneralUtility.d.ts +79 -0
- package/dist/classes/GeneralUtility.d.ts.map +1 -0
- package/dist/classes/GeneralUtility.js +121 -0
- package/dist/classes/HawkAPI.d.ts +122 -0
- package/dist/classes/HawkAPI.d.ts.map +1 -0
- package/dist/classes/HawkAPI.js +169 -0
- package/dist/classes/Health.d.ts +29 -0
- package/dist/classes/Health.d.ts.map +1 -0
- package/dist/classes/Health.js +48 -0
- package/dist/classes/JupiterAlts.d.ts +37 -0
- package/dist/classes/JupiterAlts.d.ts.map +1 -0
- package/dist/classes/JupiterAlts.js +114 -0
- package/dist/classes/JupiterSwap.d.ts +21 -0
- package/dist/classes/JupiterSwap.d.ts.map +1 -0
- package/dist/classes/JupiterSwap.js +40 -0
- package/dist/classes/Logging.d.ts +13 -0
- package/dist/classes/Logging.d.ts.map +1 -0
- package/dist/classes/Logging.js +50 -0
- package/dist/classes/MultiTransaction.d.ts +75 -0
- package/dist/classes/MultiTransaction.d.ts.map +1 -0
- package/dist/classes/MultiTransaction.js +296 -0
- package/dist/classes/RaydiumSDK.d.ts +67 -0
- package/dist/classes/RaydiumSDK.d.ts.map +1 -0
- package/dist/classes/RaydiumSDK.js +206 -0
- package/dist/classes/Search.d.ts +100 -0
- package/dist/classes/Search.d.ts.map +1 -0
- package/dist/classes/Search.js +216 -0
- package/dist/classes/SimpleIxGenerator.d.ts +57 -0
- package/dist/classes/SimpleIxGenerator.d.ts.map +1 -0
- package/dist/classes/SimpleIxGenerator.js +62 -0
- package/dist/classes/SimplePdaGenerator.d.ts +28 -0
- package/dist/classes/SimplePdaGenerator.d.ts.map +1 -0
- package/dist/classes/SimplePdaGenerator.js +33 -0
- package/dist/classes/Transaction.d.ts +229 -0
- package/dist/classes/Transaction.d.ts.map +1 -0
- package/dist/classes/Transaction.js +643 -0
- package/dist/classes/Transaction2.d.ts +107 -0
- package/dist/classes/Transaction2.d.ts.map +1 -0
- package/dist/classes/Transaction2.js +249 -0
- package/dist/classes/Transaction3.d.ts +165 -0
- package/dist/classes/Transaction3.d.ts.map +1 -0
- package/dist/classes/Transaction3.js +416 -0
- package/dist/classes/TransactionBatchExecute.d.ts +163 -0
- package/dist/classes/TransactionBatchExecute.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute.js +466 -0
- package/dist/classes/TransactionBatchExecute2.d.ts +99 -0
- package/dist/classes/TransactionBatchExecute2.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute2.js +357 -0
- package/dist/classes/Transactions.d.ts +586 -0
- package/dist/classes/Transactions.d.ts.map +1 -0
- package/dist/classes/Transactions.js +7667 -0
- package/dist/classes/TxGenerator.d.ts +350 -0
- package/dist/classes/TxGenerator.d.ts.map +1 -0
- package/dist/classes/TxGenerator.js +1957 -0
- package/dist/classes/TxGeneratorAutomations.d.ts +186 -0
- package/dist/classes/TxGeneratorAutomations.d.ts.map +1 -0
- package/dist/classes/TxGeneratorAutomations.js +897 -0
- package/dist/classes/Util.d.ts +87 -0
- package/dist/classes/Util.d.ts.map +1 -0
- package/dist/classes/Util.js +148 -0
- package/dist/classes/account-cache/AccountCache.d.ts +54 -0
- package/dist/classes/account-cache/AccountCache.d.ts.map +1 -0
- package/dist/classes/account-cache/AccountCache.js +143 -0
- package/dist/classes/account-cache/MintCache.d.ts +33 -0
- package/dist/classes/account-cache/MintCache.d.ts.map +1 -0
- package/dist/classes/account-cache/MintCache.js +47 -0
- package/dist/classes/account-cache/TokenCache.d.ts +33 -0
- package/dist/classes/account-cache/TokenCache.d.ts.map +1 -0
- package/dist/classes/account-cache/TokenCache.js +47 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +96 -0
- package/dist/functions.d.ts +514 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +1636 -0
- package/dist/hawksight.d.ts +53 -0
- package/dist/hawksight.d.ts.map +1 -0
- package/dist/hawksight.js +328 -0
- package/dist/hsToMeteora.d.ts +31 -0
- package/dist/hsToMeteora.d.ts.map +1 -0
- package/dist/hsToMeteora.js +3175 -0
- package/dist/idl/iyf-extension-idl.d.ts +14583 -0
- package/dist/idl/iyf-extension-idl.d.ts.map +1 -0
- package/dist/idl/iyf-extension-idl.js +14578 -0
- package/dist/idl/iyf-extension-wrapper.d.ts +112 -0
- package/dist/idl/iyf-extension-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-extension-wrapper.js +2 -0
- package/dist/idl/iyf-main-idl.d.ts +12078 -0
- package/dist/idl/iyf-main-idl.d.ts.map +1 -0
- package/dist/idl/iyf-main-idl.js +12073 -0
- package/dist/idl/iyf-main-wrapper.d.ts +112 -0
- package/dist/idl/iyf-main-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-main-wrapper.js +2 -0
- package/dist/idl/jupiter-idl.d.ts +3063 -0
- package/dist/idl/jupiter-idl.d.ts.map +1 -0
- package/dist/idl/jupiter-idl.js +3061 -0
- package/dist/idl/meteora-idl.d.ts +7371 -0
- package/dist/idl/meteora-idl.d.ts.map +1 -0
- package/dist/idl/meteora-idl.js +7372 -0
- package/dist/idl/orca-idl.d.ts +3833 -0
- package/dist/idl/orca-idl.d.ts.map +1 -0
- package/dist/idl/orca-idl.js +3834 -0
- package/dist/idl/raydium-idl.d.ts +3054 -0
- package/dist/idl/raydium-idl.d.ts.map +1 -0
- package/dist/idl/raydium-idl.js +3055 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts +126 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.js +467 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts +330 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfMainIxGenerator.js +1239 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts +685 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.js +3008 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts +119 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/OrcaIxGenerator.js +438 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts +99 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/RaydiumIxGenerator.js +558 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts +20 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/UtilIxGenerator.js +25 -0
- package/dist/meteora/index.d.ts +2 -0
- package/dist/meteora/index.d.ts.map +1 -0
- package/dist/meteora/index.js +17 -0
- package/dist/meteora/liquidityStrategy.d.ts +408 -0
- package/dist/meteora/liquidityStrategy.d.ts.map +1 -0
- package/dist/meteora/liquidityStrategy.js +1325 -0
- package/dist/meteora.d.ts +669 -0
- package/dist/meteora.d.ts.map +1 -0
- package/dist/meteora.js +1932 -0
- package/dist/orca.d.ts +57 -0
- package/dist/orca.d.ts.map +1 -0
- package/dist/orca.js +123 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts +29 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.js +75 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts +76 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.js +166 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts +23 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.js +68 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts +49 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.js +114 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts +8 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/UtilPdaGenerator.js +51 -0
- package/dist/types.d.ts +1104 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +95 -0
- package/package.json +6 -5
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.TransactionBatchExecute = void 0;
|
|
46
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
47
|
+
const Logging_1 = require("./Logging");
|
|
48
|
+
/**
|
|
49
|
+
* Executes transactions in batches
|
|
50
|
+
*/
|
|
51
|
+
class TransactionBatchExecute {
|
|
52
|
+
/**
|
|
53
|
+
* Creates an instance of TransactionExecute class
|
|
54
|
+
*
|
|
55
|
+
* @param lookupTableAddresses Address lookup table addresses to be used by batch of transactions
|
|
56
|
+
* @param instructions Array of instructions to be batched into transactions
|
|
57
|
+
* @param payer Payer that will pay for the batch of transactions
|
|
58
|
+
* @param connection Connection to mainnet
|
|
59
|
+
* @param signers Required signers to fulfill the transactions
|
|
60
|
+
*/
|
|
61
|
+
constructor(lookupTableAddresses, instructions, payer, connection, signers = [], jupiterAlts) {
|
|
62
|
+
this.lookupTableAddresses = lookupTableAddresses;
|
|
63
|
+
this.instructions = instructions;
|
|
64
|
+
this.payer = payer;
|
|
65
|
+
this.connection = connection;
|
|
66
|
+
this.signers = signers;
|
|
67
|
+
this.jupiterAlts = jupiterAlts;
|
|
68
|
+
this.MAX_SIZE = 1232;
|
|
69
|
+
/**
|
|
70
|
+
* Downloaded address lookup table accounts
|
|
71
|
+
*/
|
|
72
|
+
this.alts = [];
|
|
73
|
+
/**
|
|
74
|
+
* Map of public keys to address lookup table
|
|
75
|
+
*/
|
|
76
|
+
this.pubkeyToAlt = {};
|
|
77
|
+
}
|
|
78
|
+
;
|
|
79
|
+
/**
|
|
80
|
+
* Download all jupiter alts (overridable)
|
|
81
|
+
*/
|
|
82
|
+
jupiterDownloadAlts() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
if (this.jupiterAlts) {
|
|
85
|
+
yield this.jupiterAlts.downloadAlts();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error('Unexpected error: jupiterDownloadAlts not implemented!');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Find alt by pubkeys (overridable)
|
|
94
|
+
*/
|
|
95
|
+
jupiterFindAltByPubkeys(pubkeys) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
if (this.jupiterAlts) {
|
|
98
|
+
return this.jupiterAlts.findAltByPubkeys(pubkeys);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw new Error('Unexpected error: jupiterFindAltByPubkeys not implemented!');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Downoad address lookup table from given cluster
|
|
107
|
+
*/
|
|
108
|
+
downloadAlts() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
// Public keys across all instructions
|
|
111
|
+
const pubkeys = this.getPubkeyFromInstruction();
|
|
112
|
+
// Download jupiter alts first
|
|
113
|
+
yield this.jupiterDownloadAlts();
|
|
114
|
+
// Then find alts from pubkeys
|
|
115
|
+
const jupAlts = yield this.jupiterFindAltByPubkeys(pubkeys);
|
|
116
|
+
// Then append jupiter alts in the lookup table address
|
|
117
|
+
this.lookupTableAddresses.push(...jupAlts);
|
|
118
|
+
// Then make sure lookup table addresses are unique
|
|
119
|
+
this.filterLookupTables();
|
|
120
|
+
// Get list of lookup tables to download
|
|
121
|
+
const lookupTableAddresses = this.getListOfAltsToDownload();
|
|
122
|
+
// Download if address lookup table does not match with downloaded alts
|
|
123
|
+
yield this.downloadAlts2(lookupTableAddresses);
|
|
124
|
+
// Map public key to alt
|
|
125
|
+
const s0 = new Date().getTime() / 1000;
|
|
126
|
+
this.mapPubkeyToAlt(pubkeys);
|
|
127
|
+
(0, Logging_1.Log)(`TransactionBatchExecute::downloadAlts(): this.mapPubkeyToAlt benchmark: ${(new Date().getTime() / 1000) - s0}`);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Downoad address lookup table from given cluster
|
|
132
|
+
*/
|
|
133
|
+
downloadAlts2(lookupTableAddresses) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
for (const lookupTable of lookupTableAddresses) {
|
|
136
|
+
const alt = yield this.connection.getAddressLookupTable(lookupTable);
|
|
137
|
+
if (alt.value === null) {
|
|
138
|
+
throw new Error(`Address lookup table: ${lookupTable} does not exist on the blockchain.`);
|
|
139
|
+
}
|
|
140
|
+
this.alts.push(alt.value);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Map public key to alt
|
|
146
|
+
*
|
|
147
|
+
* @param pubkeys
|
|
148
|
+
*/
|
|
149
|
+
mapPubkeyToAlt(pubkeys) {
|
|
150
|
+
const addressesInAlt = [];
|
|
151
|
+
const map = {};
|
|
152
|
+
for (const alt of this.alts) {
|
|
153
|
+
const addresses = alt.state.addresses.map(p => p.toString());
|
|
154
|
+
addressesInAlt.push(...addresses);
|
|
155
|
+
map[alt.key.toString()] = [alt, addresses];
|
|
156
|
+
}
|
|
157
|
+
for (const pubkey of pubkeys) {
|
|
158
|
+
// If pubkey is not in alt, then skip
|
|
159
|
+
const inAlt = addressesInAlt.includes(pubkey.toString());
|
|
160
|
+
if (!inAlt)
|
|
161
|
+
continue;
|
|
162
|
+
// Find the alt where public key is included
|
|
163
|
+
for (const key in map) {
|
|
164
|
+
if (map[key][1].includes(pubkey.toString())) {
|
|
165
|
+
this.pubkeyToAlt[pubkey.toString()] = map[key][0];
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get list of lookup tables to download
|
|
173
|
+
*/
|
|
174
|
+
getListOfAltsToDownload() {
|
|
175
|
+
const alts = this.alts.map(alt => alt.key.toBase58());
|
|
176
|
+
const toDownload = [];
|
|
177
|
+
for (const alt of this.lookupTableAddresses) {
|
|
178
|
+
if (!alts.includes(alt.toBase58())) {
|
|
179
|
+
toDownload.push(alt);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return toDownload;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Filter lookup tables
|
|
186
|
+
*/
|
|
187
|
+
filterLookupTables() {
|
|
188
|
+
const map = {};
|
|
189
|
+
for (const alt of this.lookupTableAddresses) {
|
|
190
|
+
map[alt.toBase58()] = 1;
|
|
191
|
+
}
|
|
192
|
+
const filtered = [];
|
|
193
|
+
for (const alt in map) {
|
|
194
|
+
filtered.push(new web3.PublicKey(alt));
|
|
195
|
+
}
|
|
196
|
+
this.lookupTableAddresses = filtered;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get public keys from instruction
|
|
200
|
+
* @returns
|
|
201
|
+
*/
|
|
202
|
+
getPubkeyFromInstruction() {
|
|
203
|
+
const pubkeys = [];
|
|
204
|
+
this.instructions.map(ix => {
|
|
205
|
+
pubkeys.push(...ix.keys.map(meta => meta.pubkey));
|
|
206
|
+
});
|
|
207
|
+
return pubkeys;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Override signers (in case that signers are set to empty array)
|
|
211
|
+
*
|
|
212
|
+
* @param signers
|
|
213
|
+
*/
|
|
214
|
+
setSigners(signers) {
|
|
215
|
+
this.signers = signers;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Find missing signers
|
|
219
|
+
*/
|
|
220
|
+
findMissingSigners() {
|
|
221
|
+
const requiredSigners = this.findRequiredSigningPubkeys();
|
|
222
|
+
if (requiredSigners.length > this.signers.length) {
|
|
223
|
+
return requiredSigners;
|
|
224
|
+
}
|
|
225
|
+
const missingSigners = [];
|
|
226
|
+
for (const requiredSigner of requiredSigners) {
|
|
227
|
+
const match = this.signers.find(v => v.publicKey.toBase58() === requiredSigner.toBase58());
|
|
228
|
+
if (!!match)
|
|
229
|
+
continue;
|
|
230
|
+
missingSigners.push(requiredSigner);
|
|
231
|
+
}
|
|
232
|
+
return missingSigners;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Returns list of public keys that are required to sign the batch of transaction
|
|
236
|
+
*/
|
|
237
|
+
findRequiredSigningPubkeys() {
|
|
238
|
+
return this.findRequiredSignersFromIxs(this.instructions);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Generate dummy signers needed for simulation
|
|
242
|
+
*
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
generateDummySigners() {
|
|
246
|
+
const requiredSigners = this.findRequiredSigningPubkeys();
|
|
247
|
+
const dummySigners = {};
|
|
248
|
+
for (const signer of requiredSigners) {
|
|
249
|
+
dummySigners[signer.toString()] = web3.Keypair.generate();
|
|
250
|
+
}
|
|
251
|
+
return dummySigners;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Generate instruction that has modified signers for simulation purposes
|
|
255
|
+
*/
|
|
256
|
+
generateSimulationIxs() {
|
|
257
|
+
const dummySigners = this.generateDummySigners();
|
|
258
|
+
let simulationIxs = this.instructions;
|
|
259
|
+
for (const pubkey in dummySigners) {
|
|
260
|
+
simulationIxs = simulationIxs.map(ix => {
|
|
261
|
+
const keys = ix.keys.map(meta => {
|
|
262
|
+
if (meta.pubkey.toString() === pubkey && meta.isSigner) {
|
|
263
|
+
return Object.assign(Object.assign({}, meta), { pubkey: dummySigners[pubkey].publicKey });
|
|
264
|
+
}
|
|
265
|
+
return meta;
|
|
266
|
+
});
|
|
267
|
+
return Object.assign(Object.assign({}, ix), { keys });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return [simulationIxs, dummySigners];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Builds a batch of executable transaction instructions
|
|
274
|
+
*/
|
|
275
|
+
buildBatch() {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
// Download address lookup table from given cluster
|
|
278
|
+
yield this.downloadAlts();
|
|
279
|
+
// Generate dummy instructions for batch calculation
|
|
280
|
+
const [simulationIxs, dummySigners] = this.generateSimulationIxs();
|
|
281
|
+
// Split simulation ixs
|
|
282
|
+
const dummyBatches = yield this.splitToTransactions(simulationIxs, dummySigners);
|
|
283
|
+
// Batch of actual instructions
|
|
284
|
+
const batch = [];
|
|
285
|
+
let index = 0;
|
|
286
|
+
for (const dummyIxs of dummyBatches) {
|
|
287
|
+
const currentBatch = [];
|
|
288
|
+
for (const dummyIx of dummyIxs) {
|
|
289
|
+
currentBatch.push(this.instructions[index++]);
|
|
290
|
+
}
|
|
291
|
+
batch.push(currentBatch);
|
|
292
|
+
}
|
|
293
|
+
return batch;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Build versioned transactions from given batches of transactions
|
|
298
|
+
*
|
|
299
|
+
* @param batches
|
|
300
|
+
* @returns
|
|
301
|
+
*/
|
|
302
|
+
buildV0Transactions(batches) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
304
|
+
const latestBlockhash = yield this.connection.getLatestBlockhash();
|
|
305
|
+
const signedVersionedTxs = [];
|
|
306
|
+
for (const batch of batches) {
|
|
307
|
+
const alts = this.findRequiredAltsForBatch(batch);
|
|
308
|
+
const messageV0 = new web3.TransactionMessage({
|
|
309
|
+
payerKey: this.payer.publicKey,
|
|
310
|
+
instructions: batch,
|
|
311
|
+
recentBlockhash: latestBlockhash.blockhash,
|
|
312
|
+
}).compileToV0Message(alts);
|
|
313
|
+
const versionedTx = new web3.VersionedTransaction(messageV0);
|
|
314
|
+
const signers = this.findSigningKeypairFromIxs(batch);
|
|
315
|
+
versionedTx.sign(signers);
|
|
316
|
+
signedVersionedTxs.push(versionedTx);
|
|
317
|
+
}
|
|
318
|
+
return signedVersionedTxs;
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Split transactions
|
|
323
|
+
*
|
|
324
|
+
* @param simulationIxs
|
|
325
|
+
* @param dummySigners
|
|
326
|
+
* @returns
|
|
327
|
+
*/
|
|
328
|
+
splitToTransactions(simulationIxs, dummySigners) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
// Fetch latest blockhash required to calculate transaction size
|
|
331
|
+
const latestBlockhash = yield this.connection.getLatestBlockhash();
|
|
332
|
+
// Run simulation
|
|
333
|
+
let batch = [];
|
|
334
|
+
let result = [];
|
|
335
|
+
for (const ix of simulationIxs) {
|
|
336
|
+
// Include dummy ix to transaction
|
|
337
|
+
batch.push(ix);
|
|
338
|
+
// Calculate transaction size
|
|
339
|
+
const txSize = this.calculateTransactionSize(latestBlockhash, batch, dummySigners);
|
|
340
|
+
if (txSize > this.MAX_SIZE) {
|
|
341
|
+
batch.pop();
|
|
342
|
+
result.push(batch);
|
|
343
|
+
batch = [ix];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (batch.length > 0 && simulationIxs.length !== 0) {
|
|
347
|
+
result.push(batch);
|
|
348
|
+
}
|
|
349
|
+
return result;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Calculate transaction size
|
|
354
|
+
*
|
|
355
|
+
* @param batch
|
|
356
|
+
*/
|
|
357
|
+
calculateTransactionSize(latestBlockhash, batch, dummySigners) {
|
|
358
|
+
const alts = this.findRequiredAltsForBatch(batch);
|
|
359
|
+
const messageV0 = new web3.TransactionMessage({
|
|
360
|
+
payerKey: this.payer.publicKey,
|
|
361
|
+
instructions: batch,
|
|
362
|
+
recentBlockhash: latestBlockhash.blockhash,
|
|
363
|
+
}).compileToV0Message(alts);
|
|
364
|
+
const versionedTx = new web3.VersionedTransaction(messageV0);
|
|
365
|
+
const signers = this.findRequiredSignersFromBatch(batch, dummySigners);
|
|
366
|
+
versionedTx.sign(signers);
|
|
367
|
+
const bytes = versionedTx.serialize();
|
|
368
|
+
return bytes.length;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Find required signers from instructions
|
|
372
|
+
*
|
|
373
|
+
* @param ixs
|
|
374
|
+
* @param dummySigners
|
|
375
|
+
*/
|
|
376
|
+
findRequiredSignersFromIxs(ixs) {
|
|
377
|
+
const signers = [];
|
|
378
|
+
signers.push(this.payer.publicKey);
|
|
379
|
+
for (const instruction of ixs) {
|
|
380
|
+
const _signers = instruction.keys
|
|
381
|
+
.filter(meta => meta.isSigner)
|
|
382
|
+
.map(meta => meta.pubkey);
|
|
383
|
+
if (_signers.length > 0) {
|
|
384
|
+
signers.push(..._signers);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const uniqueSigners = {};
|
|
388
|
+
for (const signer of signers) {
|
|
389
|
+
uniqueSigners[signer.toBase58()] = signer;
|
|
390
|
+
}
|
|
391
|
+
const result = [];
|
|
392
|
+
for (const id in uniqueSigners) {
|
|
393
|
+
result.push(uniqueSigners[id]);
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Find required signers from batch
|
|
399
|
+
*
|
|
400
|
+
* @param ixs
|
|
401
|
+
* @param dummySigners
|
|
402
|
+
*/
|
|
403
|
+
findRequiredSignersFromBatch(batch, dummySigners) {
|
|
404
|
+
const signers = this.findRequiredSignersFromIxs(batch);
|
|
405
|
+
const result = [];
|
|
406
|
+
for (const key in dummySigners) {
|
|
407
|
+
const dummySigner = signers.find(signer => signer.toBase58() === dummySigners[key].publicKey.toBase58());
|
|
408
|
+
if (dummySigner === undefined) {
|
|
409
|
+
throw new Error('Unexpected error: Dummy signer not found (it should never happen)');
|
|
410
|
+
}
|
|
411
|
+
result.push(dummySigners[key]);
|
|
412
|
+
}
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Find signing keypairs from signers defined in instruction
|
|
417
|
+
*
|
|
418
|
+
* @param batch
|
|
419
|
+
* @returns
|
|
420
|
+
*/
|
|
421
|
+
findSigningKeypairFromIxs(batch) {
|
|
422
|
+
const signers = this.findRequiredSignersFromIxs(batch);
|
|
423
|
+
const result = [];
|
|
424
|
+
for (const signer of signers) {
|
|
425
|
+
const keypair = this.signers.find(keypair => keypair.publicKey.toBase58() === signer.toBase58());
|
|
426
|
+
if (keypair === undefined) {
|
|
427
|
+
throw new Error(`Keypair ${signer} cannot be found in $this.signers array. Perhaps you forgot to add it?`);
|
|
428
|
+
}
|
|
429
|
+
result.push(keypair);
|
|
430
|
+
}
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Find required address lookup table addresses for given batch of instructions
|
|
435
|
+
*
|
|
436
|
+
* @param batch
|
|
437
|
+
*/
|
|
438
|
+
findRequiredAltsForBatch(batch) {
|
|
439
|
+
const uniquePubkeys = {};
|
|
440
|
+
batch.map(ix => {
|
|
441
|
+
const pubkeys = ix.keys.map(meta => meta.pubkey);
|
|
442
|
+
for (const pubkey of pubkeys) {
|
|
443
|
+
uniquePubkeys[pubkey.toBase58()] = 1;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
const pubkeys = [];
|
|
447
|
+
for (const pubkey in uniquePubkeys) {
|
|
448
|
+
pubkeys.push(new web3.PublicKey(pubkey));
|
|
449
|
+
}
|
|
450
|
+
const alts = {};
|
|
451
|
+
for (const alt of this.alts) {
|
|
452
|
+
for (const pubkey of pubkeys) {
|
|
453
|
+
const match = alt.state.addresses.find(address => pubkey.toBase58() === address.toBase58());
|
|
454
|
+
if (!!match) {
|
|
455
|
+
alts[alt.key.toString()] = alt;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const result = [];
|
|
460
|
+
for (const key in alts) {
|
|
461
|
+
result.push(alts[key]);
|
|
462
|
+
}
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
exports.TransactionBatchExecute = TransactionBatchExecute;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as web3 from '@solana/web3.js';
|
|
2
|
+
import { TransactionBatchExecute, DummySigners } from './TransactionBatchExecute';
|
|
3
|
+
import { CreateTxMetadata } from './CreateTxMetadata';
|
|
4
|
+
import { InsertNonceAtOpt } from '../types';
|
|
5
|
+
import { GeneralUtility } from './GeneralUtility';
|
|
6
|
+
import { MultiTransaction } from './MultiTransaction';
|
|
7
|
+
/**
|
|
8
|
+
* Executes transactions in batches
|
|
9
|
+
*/
|
|
10
|
+
export declare class TransactionBatchExecute2 extends TransactionBatchExecute {
|
|
11
|
+
protected lookupTableAddresses: web3.PublicKey[];
|
|
12
|
+
protected instructions: web3.TransactionInstruction[];
|
|
13
|
+
protected connection: web3.Connection;
|
|
14
|
+
protected createTxMetadataInstance: CreateTxMetadata;
|
|
15
|
+
protected latestBlockhash: web3.BlockhashWithExpiryBlockHeight;
|
|
16
|
+
protected payerKey: web3.PublicKey;
|
|
17
|
+
private _insertNonceAt;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of TransactionExecute class
|
|
20
|
+
*
|
|
21
|
+
* @param lookupTableAddresses Address lookup table addresses to be used by batch of transactions
|
|
22
|
+
* @param instructions Array of instructions to be batched into transactions
|
|
23
|
+
* @param payer Payer that will pay for the batch of transactions
|
|
24
|
+
* @param connection Connection to mainnet
|
|
25
|
+
*/
|
|
26
|
+
constructor(lookupTableAddresses: web3.PublicKey[], instructions: web3.TransactionInstruction[], connection: web3.Connection, createTxMetadataInstance: CreateTxMetadata, latestBlockhash: web3.BlockhashWithExpiryBlockHeight, payerKey: web3.PublicKey);
|
|
27
|
+
/**
|
|
28
|
+
* Find alt by pubkeys (overridable)
|
|
29
|
+
*
|
|
30
|
+
* @param pubkeys
|
|
31
|
+
*/
|
|
32
|
+
static jupiterFindAltByPubkeysFn: (pubkeys: web3.PublicKey[]) => Promise<web3.PublicKey[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Download all jupiter alts (overridable)
|
|
35
|
+
*/
|
|
36
|
+
protected jupiterDownloadAlts(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Find alt by pubkeys (overridable)
|
|
39
|
+
*/
|
|
40
|
+
protected jupiterFindAltByPubkeys(pubkeys: web3.PublicKey[]): Promise<web3.PublicKey[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Downoad address lookup table from given cluster
|
|
43
|
+
*/
|
|
44
|
+
protected downloadAlts2(lookupTableAddresses: web3.PublicKey[]): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Option to include nonce advance instruction
|
|
47
|
+
*
|
|
48
|
+
* @param opt
|
|
49
|
+
*/
|
|
50
|
+
insertNonceAt(opt: InsertNonceAtOpt): void;
|
|
51
|
+
/**
|
|
52
|
+
* Builds a batch of executable transaction instructions
|
|
53
|
+
*/
|
|
54
|
+
buildBatch(): Promise<web3.TransactionInstruction[][]>;
|
|
55
|
+
/**
|
|
56
|
+
* Builds a batch of executable transaction instructions
|
|
57
|
+
*/
|
|
58
|
+
buildBatchWithAlts(description: string, generalUtility: GeneralUtility): Promise<MultiTransaction>;
|
|
59
|
+
/**
|
|
60
|
+
* Split transactions
|
|
61
|
+
*
|
|
62
|
+
* @param simulationIxs
|
|
63
|
+
* @param dummySigners
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
protected splitToTransactions(simulationIxs: web3.TransactionInstruction[], dummySigners: DummySigners): Promise<web3.TransactionInstruction[][]>;
|
|
67
|
+
/**
|
|
68
|
+
* Generate nonde advance instruction (dummy instruction)
|
|
69
|
+
*/
|
|
70
|
+
private generateNonceAdvanceIx;
|
|
71
|
+
private getEstimateSize;
|
|
72
|
+
/**
|
|
73
|
+
* Find required signers from instructions
|
|
74
|
+
*
|
|
75
|
+
* @param ixs
|
|
76
|
+
* @param dummySigners
|
|
77
|
+
*/
|
|
78
|
+
protected findRequiredSignersFromIxs(ixs: web3.TransactionInstruction[]): web3.PublicKey[];
|
|
79
|
+
/**
|
|
80
|
+
* Calculate transaction size
|
|
81
|
+
*
|
|
82
|
+
* @param batch
|
|
83
|
+
*/
|
|
84
|
+
protected calculateTransactionSize(latestBlockhash: web3.BlockhashWithExpiryBlockHeight, batch: web3.TransactionInstruction[], dummySigners: DummySigners): number;
|
|
85
|
+
/**
|
|
86
|
+
* Find required address lookup table addresses for given batch of instructions
|
|
87
|
+
*
|
|
88
|
+
* @param batch
|
|
89
|
+
*/
|
|
90
|
+
findRequiredAltsForBatch2(batch: web3.TransactionInstruction[]): web3.AddressLookupTableAccount[];
|
|
91
|
+
/**
|
|
92
|
+
* Find required signers from batch
|
|
93
|
+
*
|
|
94
|
+
* @param ixs
|
|
95
|
+
* @param dummySigners
|
|
96
|
+
*/
|
|
97
|
+
private findRequiredSignersFromBatch2;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=TransactionBatchExecute2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionBatchExecute2.d.ts","sourceRoot":"","sources":["../../src/classes/TransactionBatchExecute2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,uBAAuB;IAajE,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE;IAChD,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,sBAAsB,EAAE;IACrD,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IACrC,SAAS,CAAC,wBAAwB,EAAE,gBAAgB;IACpD,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,8BAA8B;IAC9D,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS;IAhBpC,OAAO,CAAC,cAAc,CAAwB;IAE9C;;;;;;;OAOG;gBAES,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE,EACtC,YAAY,EAAE,IAAI,CAAC,sBAAsB,EAAE,EAC3C,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,wBAAwB,EAAE,gBAAgB,EAC1C,eAAe,EAAE,IAAI,CAAC,8BAA8B,EACpD,QAAQ,EAAE,IAAI,CAAC,SAAS;IAWpC;;;;OAIG;IACH,MAAM,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAEzF;IAED;;OAEG;cACa,mBAAmB;IAEnC;;OAEG;cACa,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IAI7F;;OAEG;cACa,aAAa,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,EAAE;IAMpE;;;;OAIG;IACH,aAAa,CAAC,GAAG,EAAE,gBAAgB;IAInC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,CAAC;IAmC5D;;OAEG;IACG,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqCxG;;;;;;OAMG;cACa,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,sBAAsB,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,CAAC;IAgDvJ;;OAEG;YACW,sBAAsB;IAWpC,OAAO,CAAC,eAAe;IAqBvB;;;;;OAKG;IACH,SAAS,CAAC,0BAA0B,CAAC,GAAG,EAAE,IAAI,CAAC,sBAAsB,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE;IAsB1F;;;;OAIG;IACH,SAAS,CAAC,wBAAwB,CAAC,eAAe,EAAE,IAAI,CAAC,8BAA8B,EAAE,KAAK,EAAE,IAAI,CAAC,sBAAsB,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM;IAclK;;;;OAIG;IACI,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,sBAAsB,EAAE,GAAG,IAAI,CAAC,yBAAyB,EAAE;IAmBxG;;;;;OAKG;IACH,OAAO,CAAC,6BAA6B;CAStC"}
|