@helium/spl-utils 0.2.20 → 0.2.22-next.33
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/package.json +9 -9
- package/lib/cjs/anchorError.js +0 -265
- package/lib/cjs/anchorError.js.map +0 -1
- package/lib/cjs/constants.js +0 -11
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/executeRemoteTxn.js +0 -109
- package/lib/cjs/executeRemoteTxn.js.map +0 -1
- package/lib/cjs/extendBorsh.js +0 -33
- package/lib/cjs/extendBorsh.js.map +0 -1
- package/lib/cjs/index.js +0 -32
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/mplAssetAPI.js +0 -146
- package/lib/cjs/mplAssetAPI.js.map +0 -1
- package/lib/cjs/proofArgsAndAccounts.js +0 -52
- package/lib/cjs/proofArgsAndAccounts.js.map +0 -1
- package/lib/cjs/token.js +0 -235
- package/lib/cjs/token.js.map +0 -1
- package/lib/cjs/transaction.js +0 -479
- package/lib/cjs/transaction.js.map +0 -1
- package/lib/cjs/utils.js +0 -116
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/src/anchorError.js +0 -262
- package/lib/esm/src/anchorError.js.map +0 -1
- package/lib/esm/src/constants.js +0 -8
- package/lib/esm/src/constants.js.map +0 -1
- package/lib/esm/src/executeRemoteTxn.js +0 -79
- package/lib/esm/src/executeRemoteTxn.js.map +0 -1
- package/lib/esm/src/extendBorsh.js +0 -26
- package/lib/esm/src/extendBorsh.js.map +0 -1
- package/lib/esm/src/index.js +0 -10
- package/lib/esm/src/index.js.map +0 -1
- package/lib/esm/src/mplAssetAPI.js +0 -125
- package/lib/esm/src/mplAssetAPI.js.map +0 -1
- package/lib/esm/src/proofArgsAndAccounts.js +0 -37
- package/lib/esm/src/proofArgsAndAccounts.js.map +0 -1
- package/lib/esm/src/token.js +0 -208
- package/lib/esm/src/token.js.map +0 -1
- package/lib/esm/src/transaction.js +0 -415
- package/lib/esm/src/transaction.js.map +0 -1
- package/lib/esm/src/utils.js +0 -73
- package/lib/esm/src/utils.js.map +0 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +0 -1
- package/lib/types/src/anchorError.d.ts +0 -9
- package/lib/types/src/anchorError.d.ts.map +0 -1
- package/lib/types/src/constants.d.ts +0 -7
- package/lib/types/src/constants.d.ts.map +0 -1
- package/lib/types/src/executeRemoteTxn.d.ts +0 -23
- package/lib/types/src/executeRemoteTxn.d.ts.map +0 -1
- package/lib/types/src/extendBorsh.d.ts +0 -3
- package/lib/types/src/extendBorsh.d.ts.map +0 -1
- package/lib/types/src/index.d.ts +0 -12
- package/lib/types/src/index.d.ts.map +0 -1
- package/lib/types/src/mplAssetAPI.d.ts +0 -69
- package/lib/types/src/mplAssetAPI.d.ts.map +0 -1
- package/lib/types/src/proofArgsAndAccounts.d.ts +0 -21
- package/lib/types/src/proofArgsAndAccounts.d.ts.map +0 -1
- package/lib/types/src/token.d.ts +0 -21
- package/lib/types/src/token.d.ts.map +0 -1
- package/lib/types/src/transaction.d.ts +0 -37
- package/lib/types/src/transaction.d.ts.map +0 -1
- package/lib/types/src/utils.d.ts +0 -19
- package/lib/types/src/utils.d.ts.map +0 -1
package/lib/cjs/transaction.js
DELETED
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.bulkSendRawTransactions = exports.bulkSendTransactions = exports.bufferToTransaction = exports.stringToTransaction = exports.sendAndConfirmWithRetry = exports.awaitTransactionSignatureConfirmation = exports.executeBig = exports.execute = exports.sendMultipleInstructions = exports.sendInstructions = exports.chunks = void 0;
|
|
27
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
28
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
29
|
-
const anchorError_1 = require("./anchorError");
|
|
30
|
-
const chunks = (array, size) => Array.apply(0, new Array(Math.ceil(array.length / size))).map((_, index) => array.slice(index * size, (index + 1) * size));
|
|
31
|
-
exports.chunks = chunks;
|
|
32
|
-
function sleep(ms) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function promiseAllInOrder(it) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
let ret = [];
|
|
40
|
-
for (const i of it) {
|
|
41
|
-
ret.push(yield i());
|
|
42
|
-
}
|
|
43
|
-
return ret;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function sendInstructions(provider, instructions, signers = [], payer = provider.wallet.publicKey, commitment = "confirmed", idlErrors = new Map()) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
if (instructions.length == 0) {
|
|
49
|
-
return "";
|
|
50
|
-
}
|
|
51
|
-
let tx = new web3_js_1.Transaction();
|
|
52
|
-
tx.recentBlockhash = (yield provider.connection.getLatestBlockhash()).blockhash;
|
|
53
|
-
tx.feePayer = payer || provider.wallet.publicKey;
|
|
54
|
-
tx.add(...instructions);
|
|
55
|
-
if (signers.length > 0) {
|
|
56
|
-
tx.partialSign(...signers);
|
|
57
|
-
}
|
|
58
|
-
if (tx.feePayer.equals(provider.wallet.publicKey) ||
|
|
59
|
-
tx.instructions.some((ix) => ix.keys.some((key) => key.isSigner && key.pubkey.equals(provider.wallet.publicKey)))) {
|
|
60
|
-
tx = yield provider.wallet.signTransaction(tx);
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
const { txid } = yield sendAndConfirmWithRetry(provider.connection, tx.serialize(), {
|
|
64
|
-
skipPreflight: true,
|
|
65
|
-
}, commitment);
|
|
66
|
-
return txid;
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
console.error(e);
|
|
70
|
-
const wrappedE = anchorError_1.ProgramError.parse(e, idlErrors);
|
|
71
|
-
throw wrappedE == null ? e : wrappedE;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
exports.sendInstructions = sendInstructions;
|
|
76
|
-
function truthy(value) {
|
|
77
|
-
return !!value;
|
|
78
|
-
}
|
|
79
|
-
function sendMultipleInstructions(provider, instructionGroups, signerGroups, payer, finality = "confirmed", idlErrors = new Map()) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const recentBlockhash = (yield provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
82
|
-
const ixAndSigners = instructionGroups
|
|
83
|
-
.map((instructions, i) => {
|
|
84
|
-
const signers = signerGroups[i];
|
|
85
|
-
return {
|
|
86
|
-
instructions,
|
|
87
|
-
signers,
|
|
88
|
-
};
|
|
89
|
-
})
|
|
90
|
-
.filter(({ instructions }) => instructions.length > 0);
|
|
91
|
-
const txns = ixAndSigners.map(({ instructions }) => {
|
|
92
|
-
const tx = new web3_js_1.Transaction({
|
|
93
|
-
feePayer: payer || provider.wallet.publicKey,
|
|
94
|
-
recentBlockhash,
|
|
95
|
-
});
|
|
96
|
-
tx.add(...instructions);
|
|
97
|
-
return tx;
|
|
98
|
-
});
|
|
99
|
-
const txnsSignedByWallet = yield provider.wallet.signAllTransactions(txns);
|
|
100
|
-
const txnsSigned = txnsSignedByWallet
|
|
101
|
-
.map((tx, index) => {
|
|
102
|
-
const signers = ixAndSigners[index].signers;
|
|
103
|
-
if (signers.length > 0) {
|
|
104
|
-
tx.partialSign(...signers);
|
|
105
|
-
}
|
|
106
|
-
return tx;
|
|
107
|
-
})
|
|
108
|
-
.map((tx) => tx.serialize());
|
|
109
|
-
console.log("Sending multiple transactions...");
|
|
110
|
-
try {
|
|
111
|
-
return yield promiseAllInOrder(txnsSigned.map((txn) => () => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const { txid } = yield sendAndConfirmWithRetry(provider.connection, txn, {
|
|
113
|
-
skipPreflight: true,
|
|
114
|
-
}, finality);
|
|
115
|
-
return txid;
|
|
116
|
-
})));
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
console.error(e);
|
|
120
|
-
const wrappedE = anchorError_1.ProgramError.parse(e, idlErrors);
|
|
121
|
-
throw wrappedE == null ? e : wrappedE;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
exports.sendMultipleInstructions = sendMultipleInstructions;
|
|
126
|
-
function execute(program, provider, command, payer = provider.wallet.publicKey, commitment) {
|
|
127
|
-
var _a;
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
const { instructions, signers, output } = command;
|
|
130
|
-
const errors = (_a = program.idl.errors) === null || _a === void 0 ? void 0 : _a.reduce((acc, err) => {
|
|
131
|
-
acc.set(err.code, `${err.name}: ${err.msg}`);
|
|
132
|
-
return acc;
|
|
133
|
-
}, new Map());
|
|
134
|
-
if (instructions.length > 0) {
|
|
135
|
-
const txid = yield sendInstructions(provider, instructions, signers, payer, commitment, errors);
|
|
136
|
-
return Object.assign({ txid }, output);
|
|
137
|
-
}
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
return output;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
exports.execute = execute;
|
|
143
|
-
function executeBig(program, provider, command, payer = provider.wallet.publicKey, finality) {
|
|
144
|
-
var _a;
|
|
145
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
const { instructions, signers, output } = command;
|
|
147
|
-
const errors = (_a = program.idl.errors) === null || _a === void 0 ? void 0 : _a.reduce((acc, err) => {
|
|
148
|
-
acc.set(err.code, `${err.name}: ${err.msg}`);
|
|
149
|
-
return acc;
|
|
150
|
-
}, new Map());
|
|
151
|
-
if (instructions.length > 0) {
|
|
152
|
-
const txids = yield sendMultipleInstructions(provider, instructions, signers, payer || provider.wallet.publicKey, finality, errors);
|
|
153
|
-
return Object.assign(Object.assign({}, output), { txids: Array.from(txids) });
|
|
154
|
-
}
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
return output;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
exports.executeBig = executeBig;
|
|
160
|
-
function getUnixTime() {
|
|
161
|
-
return new Date().valueOf() / 1000;
|
|
162
|
-
}
|
|
163
|
-
const SEND_TRANSACTION_INTERVAL = 10;
|
|
164
|
-
const awaitTransactionSignatureConfirmation = (txid, timeout, connection, commitment = "recent", queryStatus = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
-
let done = false;
|
|
166
|
-
let status = {
|
|
167
|
-
slot: 0,
|
|
168
|
-
confirmations: 0,
|
|
169
|
-
err: null,
|
|
170
|
-
};
|
|
171
|
-
let subId = 0;
|
|
172
|
-
status = yield new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
-
const t = setTimeout(() => {
|
|
174
|
-
if (done) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
done = true;
|
|
178
|
-
console.log("Rejecting for timeout...");
|
|
179
|
-
reject({ timeout: true });
|
|
180
|
-
}, timeout);
|
|
181
|
-
try {
|
|
182
|
-
subId = connection.onSignature(txid, (result, context) => {
|
|
183
|
-
status = {
|
|
184
|
-
err: result.err,
|
|
185
|
-
slot: context.slot,
|
|
186
|
-
confirmations: 0,
|
|
187
|
-
};
|
|
188
|
-
done = true;
|
|
189
|
-
if (result.err) {
|
|
190
|
-
console.log("Rejected via websocket", result.err);
|
|
191
|
-
reject(status);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
resolve(status);
|
|
195
|
-
}
|
|
196
|
-
}, commitment);
|
|
197
|
-
}
|
|
198
|
-
catch (e) {
|
|
199
|
-
console.error("WS error in setup", txid, e);
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
done = true;
|
|
203
|
-
clearTimeout(t);
|
|
204
|
-
}
|
|
205
|
-
while (!done && queryStatus) {
|
|
206
|
-
// eslint-disable-next-line no-loop-func
|
|
207
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
-
try {
|
|
209
|
-
const signatureStatuses = yield connection.getSignatureStatuses([
|
|
210
|
-
txid,
|
|
211
|
-
]);
|
|
212
|
-
status = signatureStatuses && signatureStatuses.value[0];
|
|
213
|
-
if (!done) {
|
|
214
|
-
if (!status) {
|
|
215
|
-
}
|
|
216
|
-
else if (status.err) {
|
|
217
|
-
console.log("REST error for", txid, status);
|
|
218
|
-
done = true;
|
|
219
|
-
reject(status.err);
|
|
220
|
-
}
|
|
221
|
-
else if (!status.confirmations && !status.confirmationStatus) {
|
|
222
|
-
console.log("REST no confirmations for", txid, status);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
console.log("REST confirmation for", txid, status);
|
|
226
|
-
if (!status.confirmationStatus ||
|
|
227
|
-
status.confirmationStatus == commitment) {
|
|
228
|
-
done = true;
|
|
229
|
-
resolve(status);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
catch (e) {
|
|
235
|
-
if (!done) {
|
|
236
|
-
console.log("REST connection error: txid", txid, e);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}))();
|
|
240
|
-
yield sleep(2000);
|
|
241
|
-
}
|
|
242
|
-
}));
|
|
243
|
-
if (
|
|
244
|
-
//@ts-ignore
|
|
245
|
-
connection._signatureSubscriptions &&
|
|
246
|
-
//@ts-ignore
|
|
247
|
-
connection._signatureSubscriptions[subId]) {
|
|
248
|
-
connection.removeSignatureListener(subId);
|
|
249
|
-
}
|
|
250
|
-
done = true;
|
|
251
|
-
return status;
|
|
252
|
-
});
|
|
253
|
-
exports.awaitTransactionSignatureConfirmation = awaitTransactionSignatureConfirmation;
|
|
254
|
-
function simulateTransaction(connection, transaction, commitment) {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
transaction.recentBlockhash = yield connection._recentBlockhash(
|
|
258
|
-
// @ts-ignore
|
|
259
|
-
connection._disableBlockhashCaching);
|
|
260
|
-
const signData = transaction.serializeMessage();
|
|
261
|
-
// @ts-ignore
|
|
262
|
-
const wireTransaction = transaction._serialize(signData);
|
|
263
|
-
const encodedTransaction = wireTransaction.toString("base64");
|
|
264
|
-
const config = { encoding: "base64", commitment };
|
|
265
|
-
const args = [encodedTransaction, config];
|
|
266
|
-
// @ts-ignore
|
|
267
|
-
const res = yield connection._rpcRequest("simulateTransaction", args);
|
|
268
|
-
if (res.error) {
|
|
269
|
-
throw new Error("failed to simulate transaction: " + res.error.message);
|
|
270
|
-
}
|
|
271
|
-
return res.result;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
const DEFAULT_TIMEOUT = 3 * 60 * 1000; // 3 minutes
|
|
275
|
-
/*
|
|
276
|
-
A validator has up to 120s to accept the transaction and send it into a block.
|
|
277
|
-
If it doesn’t happen within that timeframe, your transaction is dropped and you’ll need
|
|
278
|
-
to send the transaction again. You can get the transaction signature and periodically
|
|
279
|
-
Ping the network for that transaction signature. If you never get anything back,
|
|
280
|
-
that means it’s definitely been dropped. If you do get a response back, you can keep pinging
|
|
281
|
-
that means it’s definitely been dropped. If you do get a response back, you can keep pinging
|
|
282
|
-
until it’s gone to a confirmed status to move on.
|
|
283
|
-
*/
|
|
284
|
-
function sendAndConfirmWithRetry(connection, txn, sendOptions, commitment, timeout = DEFAULT_TIMEOUT) {
|
|
285
|
-
var _a, _b;
|
|
286
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
let done = false;
|
|
288
|
-
let slot = 0;
|
|
289
|
-
const txid = yield connection.sendRawTransaction(txn, sendOptions);
|
|
290
|
-
console.log("txid", txid);
|
|
291
|
-
const startTime = getUnixTime();
|
|
292
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
while (!done && getUnixTime() - startTime < timeout) {
|
|
294
|
-
yield connection.sendRawTransaction(txn, sendOptions);
|
|
295
|
-
yield sleep(500);
|
|
296
|
-
}
|
|
297
|
-
}))();
|
|
298
|
-
try {
|
|
299
|
-
const confirmation = yield (0, exports.awaitTransactionSignatureConfirmation)(txid, timeout, connection, commitment, true);
|
|
300
|
-
if (!confirmation)
|
|
301
|
-
throw new Error("Timed out awaiting confirmation on transaction");
|
|
302
|
-
if (confirmation.err) {
|
|
303
|
-
const tx = yield connection.getTransaction(txid, {
|
|
304
|
-
commitment: "confirmed",
|
|
305
|
-
});
|
|
306
|
-
console.error((_b = (_a = tx === null || tx === void 0 ? void 0 : tx.meta) === null || _a === void 0 ? void 0 : _a.logMessages) === null || _b === void 0 ? void 0 : _b.join("\n"));
|
|
307
|
-
console.error(confirmation.err);
|
|
308
|
-
throw new Error("Transaction failed: Custom instruction error");
|
|
309
|
-
}
|
|
310
|
-
slot = (confirmation === null || confirmation === void 0 ? void 0 : confirmation.slot) || 0;
|
|
311
|
-
}
|
|
312
|
-
catch (err) {
|
|
313
|
-
console.error("Error caught", err);
|
|
314
|
-
if (err.timeout) {
|
|
315
|
-
throw new Error("Timed out awaiting confirmation on transaction");
|
|
316
|
-
}
|
|
317
|
-
const tx = yield connection.getTransaction(txid, {
|
|
318
|
-
commitment: "confirmed",
|
|
319
|
-
});
|
|
320
|
-
if (tx && tx.meta && tx.meta.logMessages) {
|
|
321
|
-
console.error(tx.meta.logMessages.join("\n"));
|
|
322
|
-
}
|
|
323
|
-
if (err.err) {
|
|
324
|
-
throw err.err;
|
|
325
|
-
}
|
|
326
|
-
throw err;
|
|
327
|
-
}
|
|
328
|
-
finally {
|
|
329
|
-
done = true;
|
|
330
|
-
}
|
|
331
|
-
console.log("Latency", txid, getUnixTime() - startTime);
|
|
332
|
-
return { txid };
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
exports.sendAndConfirmWithRetry = sendAndConfirmWithRetry;
|
|
336
|
-
function stringToTransaction(solanaTransaction) {
|
|
337
|
-
return web3_js_1.Transaction.from(Buffer.from(solanaTransaction));
|
|
338
|
-
}
|
|
339
|
-
exports.stringToTransaction = stringToTransaction;
|
|
340
|
-
function bufferToTransaction(solanaTransaction) {
|
|
341
|
-
return web3_js_1.Transaction.from(solanaTransaction);
|
|
342
|
-
}
|
|
343
|
-
exports.bufferToTransaction = bufferToTransaction;
|
|
344
|
-
function withRetries(tries, input) {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
for (let i = 0; i < tries; i++) {
|
|
347
|
-
try {
|
|
348
|
-
return yield input();
|
|
349
|
-
}
|
|
350
|
-
catch (e) {
|
|
351
|
-
console.log(`Retrying ${i}...`, e);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
throw new Error("Failed after retries");
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
const TX_BATCH_SIZE = 200;
|
|
358
|
-
function bulkSendTransactions(provider, txs, onProgress, triesRemaining = 10 // Number of blockhashes to try resending txs with before giving up
|
|
359
|
-
) {
|
|
360
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
-
let ret = [];
|
|
362
|
-
// attempt to chunk by blockhash bounds (so signing doesn't take too long)
|
|
363
|
-
for (let chunk of (0, exports.chunks)(txs, TX_BATCH_SIZE)) {
|
|
364
|
-
const thisRet = [];
|
|
365
|
-
// Continually send in bulk while resetting blockhash until we send them all
|
|
366
|
-
while (true) {
|
|
367
|
-
const recentBlockhash = yield withRetries(5, () => provider.connection.getLatestBlockhash("confirmed"));
|
|
368
|
-
const blockhashedTxs = yield Promise.all(chunk.map((tx) => __awaiter(this, void 0, void 0, function* () {
|
|
369
|
-
tx.recentBlockhash = recentBlockhash.blockhash;
|
|
370
|
-
return tx;
|
|
371
|
-
})));
|
|
372
|
-
const signedTxs = yield provider.wallet.signAllTransactions(blockhashedTxs);
|
|
373
|
-
const txsWithSigs = signedTxs.map((tx, index) => {
|
|
374
|
-
return {
|
|
375
|
-
transaction: chunk[index],
|
|
376
|
-
sig: bs58_1.default.encode(tx.signatures[0].signature),
|
|
377
|
-
};
|
|
378
|
-
});
|
|
379
|
-
const confirmedTxs = yield bulkSendRawTransactions(provider.connection, signedTxs.map((s) => s.serialize()), (_a) => {
|
|
380
|
-
var { totalProgress } = _a, rest = __rest(_a, ["totalProgress"]);
|
|
381
|
-
return onProgress &&
|
|
382
|
-
onProgress(Object.assign(Object.assign({}, rest), { totalProgress: totalProgress + ret.length + thisRet.length }));
|
|
383
|
-
}, recentBlockhash.lastValidBlockHeight,
|
|
384
|
-
// Hail mary, try with preflight enabled. Sometimes this causes
|
|
385
|
-
// errors that wouldn't otherwise happen
|
|
386
|
-
triesRemaining != 1);
|
|
387
|
-
thisRet.push(...confirmedTxs);
|
|
388
|
-
if (confirmedTxs.length == signedTxs.length) {
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
const retSet = new Set(thisRet);
|
|
392
|
-
chunk = txsWithSigs
|
|
393
|
-
.filter(({ sig }) => !retSet.has(sig))
|
|
394
|
-
.map(({ transaction }) => transaction);
|
|
395
|
-
triesRemaining--;
|
|
396
|
-
if (triesRemaining <= 0) {
|
|
397
|
-
throw new Error(`Failed to submit all txs after blockhashes expired, ${signedTxs.length - confirmedTxs.length} remain`);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
ret.push(...thisRet);
|
|
401
|
-
}
|
|
402
|
-
return ret;
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
exports.bulkSendTransactions = bulkSendTransactions;
|
|
406
|
-
// Returns the list of succesfully sent txns
|
|
407
|
-
// NOTE: The return signatures are ordered by confirmation, not by order they are passed
|
|
408
|
-
// This list should be in order. Seom txns may fail
|
|
409
|
-
// due to blockhash exp
|
|
410
|
-
function bulkSendRawTransactions(connection, txs, onProgress, lastValidBlockHeight, skipPreflight = true) {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
const txBatchSize = TX_BATCH_SIZE;
|
|
413
|
-
let totalProgress = 0;
|
|
414
|
-
const ret = [];
|
|
415
|
-
if (!lastValidBlockHeight) {
|
|
416
|
-
const blockhash = yield withRetries(5, () => connection.getLatestBlockhash("confirmed"));
|
|
417
|
-
lastValidBlockHeight = blockhash.lastValidBlockHeight;
|
|
418
|
-
}
|
|
419
|
-
for (let chunk of (0, exports.chunks)(txs, txBatchSize)) {
|
|
420
|
-
let currentBatchProgress = 0;
|
|
421
|
-
let pendingCount = chunk.length;
|
|
422
|
-
let txids = [];
|
|
423
|
-
let lastRetry = 0;
|
|
424
|
-
while (pendingCount > 0) {
|
|
425
|
-
if ((yield withRetries(5, () => connection.getBlockHeight())) >
|
|
426
|
-
lastValidBlockHeight) {
|
|
427
|
-
return ret;
|
|
428
|
-
}
|
|
429
|
-
// only resend txs every 4s
|
|
430
|
-
if (lastRetry < new Date().valueOf() - 4 * 1000) {
|
|
431
|
-
lastRetry = new Date().valueOf();
|
|
432
|
-
txids = [];
|
|
433
|
-
for (const tx of chunk) {
|
|
434
|
-
const txid = yield connection.sendRawTransaction(tx, {
|
|
435
|
-
skipPreflight,
|
|
436
|
-
});
|
|
437
|
-
txids.push(txid);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
const statuses = yield getAllTxns(connection, txids);
|
|
441
|
-
const completed = statuses.filter((status) => status !== null);
|
|
442
|
-
totalProgress += completed.length;
|
|
443
|
-
currentBatchProgress += completed.length;
|
|
444
|
-
onProgress &&
|
|
445
|
-
onProgress({
|
|
446
|
-
totalProgress: totalProgress,
|
|
447
|
-
currentBatchProgress: currentBatchProgress,
|
|
448
|
-
currentBatchSize: txBatchSize,
|
|
449
|
-
});
|
|
450
|
-
const failures = completed
|
|
451
|
-
.map((status) => { var _a; return status !== null && ((_a = status.meta) === null || _a === void 0 ? void 0 : _a.err); })
|
|
452
|
-
.filter(truthy);
|
|
453
|
-
if (failures.length > 0) {
|
|
454
|
-
console.error(failures);
|
|
455
|
-
throw new Error("Failed to run txs");
|
|
456
|
-
}
|
|
457
|
-
ret.push(...txids
|
|
458
|
-
.map((txid, idx) => statuses[idx] == null ? null : txid)
|
|
459
|
-
.filter(truthy));
|
|
460
|
-
chunk = chunk.filter((_, index) => statuses[index] === null);
|
|
461
|
-
txids = txids.filter((_, index) => statuses[index] === null);
|
|
462
|
-
pendingCount -= completed.length;
|
|
463
|
-
yield sleep(1000); // Wait one seconds before querying again
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
return ret;
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
exports.bulkSendRawTransactions = bulkSendRawTransactions;
|
|
470
|
-
const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS = 200;
|
|
471
|
-
function getAllTxns(connection, txids) {
|
|
472
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
473
|
-
return (yield Promise.all((0, exports.chunks)(txids, MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS).map((txids) => connection.getTransactions(txids, {
|
|
474
|
-
maxSupportedTransactionVersion: 0,
|
|
475
|
-
commitment: "confirmed",
|
|
476
|
-
})))).flat();
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
//# sourceMappingURL=transaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAeyB;AACzB,gDAAwB;AACxB,+CAA6C;AAEtC,MAAM,MAAM,GAAG,CAAI,KAAU,EAAE,IAAY,EAAS,EAAE,CAC3D,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CACzE,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAC9C,CAAC;AAHS,QAAA,MAAM,UAGf;AAEJ,SAAe,KAAK,CAAC,EAAU;;QAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CAAA;AAED,SAAe,iBAAiB,CAC9B,EAAwB;;QAExB,IAAI,GAAG,GAAQ,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE;YAClB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CAAA;AAcD,SA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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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.heliumAddressFromSolAddress = exports.heliumAddressFromSolKey = exports.heliumAddressToSolAddress = exports.heliumAddressToSolPublicKey = exports.getSolanaKeypair = exports.humanReadable = exports.humanReadableBigint = exports.roundToDecimals = exports.numberWithCommas = exports.supplyAsNum = exports.toBN = exports.amountAsNum = exports.toNumber = exports.truthy = void 0;
|
|
30
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
31
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
32
|
-
const address_1 = __importStar(require("@helium/address"));
|
|
33
|
-
const truthy = (value) => !!value;
|
|
34
|
-
exports.truthy = truthy;
|
|
35
|
-
function toNumber(numberOrBn, mintOrDecimals) {
|
|
36
|
-
if (bn_js_1.default.isBN(numberOrBn) || typeof numberOrBn == "bigint") {
|
|
37
|
-
return amountAsNum(numberOrBn, mintOrDecimals);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return numberOrBn;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.toNumber = toNumber;
|
|
44
|
-
function amountAsNum(amount, mintOrDecimals) {
|
|
45
|
-
const decimals = typeof mintOrDecimals === "number"
|
|
46
|
-
? mintOrDecimals
|
|
47
|
-
: mintOrDecimals.decimals;
|
|
48
|
-
const factor = new bn_js_1.default(Math.pow(10, decimals).toString());
|
|
49
|
-
const decimal = new bn_js_1.default(amount.toString()).mod(factor).toNumber() / factor.toNumber();
|
|
50
|
-
return new bn_js_1.default(amount.toString()).div(factor).toNumber() + decimal;
|
|
51
|
-
}
|
|
52
|
-
exports.amountAsNum = amountAsNum;
|
|
53
|
-
function toBN(numberOrBn, mintOrDecimals) {
|
|
54
|
-
const decimals = typeof mintOrDecimals === "number"
|
|
55
|
-
? mintOrDecimals
|
|
56
|
-
: mintOrDecimals.decimals;
|
|
57
|
-
if (bn_js_1.default.isBN(numberOrBn)) {
|
|
58
|
-
return numberOrBn;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return new bn_js_1.default(Number(Math.floor(Number(numberOrBn))))
|
|
62
|
-
.mul(new bn_js_1.default(Math.pow(10, decimals)))
|
|
63
|
-
.add(new bn_js_1.default(Math.round((Number(numberOrBn) % 1) * Math.pow(10, decimals))));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.toBN = toBN;
|
|
67
|
-
function supplyAsNum(mint) {
|
|
68
|
-
return amountAsNum(new bn_js_1.default(mint.supply.toString()), mint);
|
|
69
|
-
}
|
|
70
|
-
exports.supplyAsNum = supplyAsNum;
|
|
71
|
-
function numberWithCommas(x, decimals = 4) {
|
|
72
|
-
return roundToDecimals(x, decimals).toLocaleString("en-US", {
|
|
73
|
-
maximumFractionDigits: decimals,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
exports.numberWithCommas = numberWithCommas;
|
|
77
|
-
function roundToDecimals(num, decimals) {
|
|
78
|
-
return Math.trunc(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
79
|
-
}
|
|
80
|
-
exports.roundToDecimals = roundToDecimals;
|
|
81
|
-
function humanReadableBigint(bigint, decimals, round = decimals) {
|
|
82
|
-
return numberWithCommas(roundToDecimals(toNumber(bigint, decimals), round));
|
|
83
|
-
}
|
|
84
|
-
exports.humanReadableBigint = humanReadableBigint;
|
|
85
|
-
function humanReadable(bn, decimalsOrMint) {
|
|
86
|
-
return numberWithCommas(roundToDecimals(toNumber(bn, decimalsOrMint), typeof decimalsOrMint == "number"
|
|
87
|
-
? decimalsOrMint
|
|
88
|
-
: decimalsOrMint.decimals));
|
|
89
|
-
}
|
|
90
|
-
exports.humanReadable = humanReadable;
|
|
91
|
-
const getSolanaKeypair = (secretKey) => web3_js_1.Keypair.fromSecretKey(Buffer.from(secretKey, "base64"));
|
|
92
|
-
exports.getSolanaKeypair = getSolanaKeypair;
|
|
93
|
-
const heliumAddressToSolPublicKey = (heliumAddress) => {
|
|
94
|
-
const heliumPK = address_1.default.fromB58(heliumAddress).publicKey;
|
|
95
|
-
return new web3_js_1.PublicKey(heliumPK);
|
|
96
|
-
};
|
|
97
|
-
exports.heliumAddressToSolPublicKey = heliumAddressToSolPublicKey;
|
|
98
|
-
const heliumAddressToSolAddress = (heliumAddress) => {
|
|
99
|
-
return (0, exports.heliumAddressToSolPublicKey)(heliumAddress).toBase58();
|
|
100
|
-
};
|
|
101
|
-
exports.heliumAddressToSolAddress = heliumAddressToSolAddress;
|
|
102
|
-
const heliumAddressFromSolKey = (pubKey) => {
|
|
103
|
-
return new address_1.default(0, address_1.NetTypes.MAINNET, address_1.KeyTypes.ED25519_KEY_TYPE, pubKey.toBuffer()).b58;
|
|
104
|
-
};
|
|
105
|
-
exports.heliumAddressFromSolKey = heliumAddressFromSolKey;
|
|
106
|
-
const heliumAddressFromSolAddress = (solAddress) => {
|
|
107
|
-
try {
|
|
108
|
-
const pubKey = new web3_js_1.PublicKey(solAddress);
|
|
109
|
-
return (0, exports.heliumAddressFromSolKey)(pubKey);
|
|
110
|
-
}
|
|
111
|
-
catch (_a) {
|
|
112
|
-
return "";
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
exports.heliumAddressFromSolAddress = heliumAddressFromSolAddress;
|
|
116
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/cjs/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAuB;AAEvB,6CAAqD;AACrD,2DAA8D;AAIvD,MAAM,MAAM,GAAG,CAAI,KAAQ,EAAsB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAAtD,QAAA,MAAM,UAAgD;AAEnE,SAAgB,QAAQ,CACtB,UAAgC,EAChC,cAA6B;IAE7B,IAAI,eAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,OAAO,UAAU,IAAI,QAAQ,EAAE;QACxD,OAAO,WAAW,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;KAChD;SAAM;QACL,OAAO,UAAU,CAAC;KACnB;AACH,CAAC;AATD,4BASC;AAED,SAAgB,WAAW,CACzB,MAAmB,EACnB,cAA6B;IAE7B,MAAM,QAAQ,GACZ,OAAO,cAAc,KAAK,QAAQ;QAChC,CAAC,CAAC,cAAc;QAChB,CAAC,CAAE,cAAuB,CAAC,QAAQ,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,eAAE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