@streamflow/common 6.1.0 → 6.1.2
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/solana/types.d.ts +1 -0
- package/dist/solana/types.js +5 -2
- package/dist/solana/utils.d.ts +13 -4
- package/dist/solana/utils.js +113 -72
- package/package.json +2 -2
package/dist/solana/types.d.ts
CHANGED
package/dist/solana/types.js
CHANGED
|
@@ -18,8 +18,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.TransactionFailedError = void 0;
|
|
19
19
|
var TransactionFailedError = /** @class */ (function (_super) {
|
|
20
20
|
__extends(TransactionFailedError, _super);
|
|
21
|
-
function TransactionFailedError() {
|
|
22
|
-
|
|
21
|
+
function TransactionFailedError(m) {
|
|
22
|
+
var _this = _super.call(this, m) || this;
|
|
23
|
+
Object.setPrototypeOf(_this, TransactionFailedError.prototype);
|
|
24
|
+
_this.name = "TransactionFailedError";
|
|
25
|
+
return _this;
|
|
23
26
|
}
|
|
24
27
|
return TransactionFailedError;
|
|
25
28
|
}(Error));
|
package/dist/solana/utils.d.ts
CHANGED
|
@@ -64,20 +64,29 @@ export declare function signAndExecuteTransaction(connection: Connection, invoke
|
|
|
64
64
|
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
65
65
|
* @param connection - Solana client connection
|
|
66
66
|
* @param tx - Transaction instance
|
|
67
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
68
|
+
* @returns Transaction signature
|
|
69
|
+
*/
|
|
70
|
+
export declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
|
|
73
|
+
* - we add additional 30 bocks to account for validators in an PRC pool divergence
|
|
74
|
+
* @param connection - Solana client connection
|
|
75
|
+
* @param tx - Transaction instance
|
|
67
76
|
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
68
77
|
* @param context - context at which blockhash has been retrieve
|
|
69
78
|
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
70
|
-
* @returns Transaction signature
|
|
71
79
|
*/
|
|
72
|
-
export declare function
|
|
80
|
+
export declare function sendAndConfirmTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams): Promise<string>;
|
|
81
|
+
export declare function simulateTransaction(connection: Connection, tx: Transaction | VersionedTransaction): Promise<void>;
|
|
73
82
|
/**
|
|
74
83
|
* Confirms and validates transaction success once
|
|
75
84
|
* @param connection - Solana client connection
|
|
76
85
|
* @param signature - Transaction signature
|
|
77
|
-
* @param
|
|
86
|
+
* @param ignoreError - return status even if tx failed
|
|
78
87
|
* @returns Transaction Status
|
|
79
88
|
*/
|
|
80
|
-
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string,
|
|
89
|
+
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
|
|
81
90
|
/**
|
|
82
91
|
* Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
|
|
83
92
|
* @param {PublicKey} mint - SPL token Mint address.
|
package/dist/solana/utils.js
CHANGED
|
@@ -50,12 +50,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.getMintAndProgram = exports.prepareBaseInstructions = exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.enrichAtaParams = exports.ataBatchExist = exports.ata = exports.confirmAndEnsureTransaction = exports.executeTransaction = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isTransactionVersioned = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
|
|
53
|
+
exports.getMintAndProgram = exports.prepareBaseInstructions = exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.enrichAtaParams = exports.ataBatchExist = exports.ata = exports.confirmAndEnsureTransaction = exports.simulateTransaction = exports.sendAndConfirmTransaction = exports.executeTransaction = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isTransactionVersioned = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
|
|
54
54
|
var spl_token_1 = require("@solana/spl-token");
|
|
55
55
|
var web3_js_1 = require("@solana/web3.js");
|
|
56
56
|
var bs58_1 = __importDefault(require("bs58"));
|
|
57
57
|
var types_1 = require("./types");
|
|
58
58
|
var utils_1 = require("../utils");
|
|
59
|
+
var SIMULATE_TRIES = 3;
|
|
59
60
|
/**
|
|
60
61
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
61
62
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -128,7 +129,11 @@ function prepareTransaction(connection, ixs, payer, commitment) {
|
|
|
128
129
|
var _a, hash, context, messageV0, tx, signers;
|
|
129
130
|
return __generator(this, function (_b) {
|
|
130
131
|
switch (_b.label) {
|
|
131
|
-
case 0:
|
|
132
|
+
case 0:
|
|
133
|
+
if (!payer) {
|
|
134
|
+
throw new Error("Payer public key is not provided!");
|
|
135
|
+
}
|
|
136
|
+
return [4 /*yield*/, connection.getLatestBlockhashAndContext(commitment)];
|
|
132
137
|
case 1:
|
|
133
138
|
_a = _b.sent(), hash = _a.value, context = _a.context;
|
|
134
139
|
messageV0 = new web3_js_1.TransactionMessage({
|
|
@@ -204,47 +209,42 @@ exports.signAndExecuteTransaction = signAndExecuteTransaction;
|
|
|
204
209
|
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
205
210
|
* @param connection - Solana client connection
|
|
206
211
|
* @param tx - Transaction instance
|
|
212
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
213
|
+
* @returns Transaction signature
|
|
214
|
+
*/
|
|
215
|
+
function executeTransaction(connection, tx, confirmationParams) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
return __generator(this, function (_a) {
|
|
218
|
+
switch (_a.label) {
|
|
219
|
+
case 0:
|
|
220
|
+
if (tx.signatures.length === 0) {
|
|
221
|
+
throw Error("Error with transaction parameters.");
|
|
222
|
+
}
|
|
223
|
+
return [4 /*yield*/, simulateTransaction(connection, tx)];
|
|
224
|
+
case 1:
|
|
225
|
+
_a.sent();
|
|
226
|
+
return [2 /*return*/, sendAndConfirmTransaction(connection, tx, confirmationParams)];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
exports.executeTransaction = executeTransaction;
|
|
232
|
+
/**
|
|
233
|
+
* Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
|
|
234
|
+
* - we add additional 30 bocks to account for validators in an PRC pool divergence
|
|
235
|
+
* @param connection - Solana client connection
|
|
236
|
+
* @param tx - Transaction instance
|
|
207
237
|
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
208
238
|
* @param context - context at which blockhash has been retrieve
|
|
209
239
|
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
210
|
-
* @returns Transaction signature
|
|
211
240
|
*/
|
|
212
|
-
function
|
|
241
|
+
function sendAndConfirmTransaction(connection, tx, _a) {
|
|
213
242
|
var hash = _a.hash, context = _a.context, commitment = _a.commitment;
|
|
214
243
|
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
-
var
|
|
244
|
+
var isVersioned, signature, blockheight, transactionSent, rawTransaction, e_1, value, e_2, _e_1;
|
|
216
245
|
return __generator(this, function (_b) {
|
|
217
246
|
switch (_b.label) {
|
|
218
247
|
case 0:
|
|
219
|
-
if (!hash.lastValidBlockHeight || tx.signatures.length === 0 || !hash.blockhash) {
|
|
220
|
-
throw Error("Error with transaction parameters.");
|
|
221
|
-
}
|
|
222
|
-
i = 0;
|
|
223
|
-
_b.label = 1;
|
|
224
|
-
case 1:
|
|
225
|
-
if (!(i < 3)) return [3 /*break*/, 7];
|
|
226
|
-
res = void 0;
|
|
227
|
-
if (!isTransactionVersioned(tx)) return [3 /*break*/, 3];
|
|
228
|
-
return [4 /*yield*/, connection.simulateTransaction(tx)];
|
|
229
|
-
case 2:
|
|
230
|
-
res = _b.sent();
|
|
231
|
-
return [3 /*break*/, 5];
|
|
232
|
-
case 3: return [4 /*yield*/, connection.simulateTransaction(tx)];
|
|
233
|
-
case 4:
|
|
234
|
-
res = _b.sent();
|
|
235
|
-
_b.label = 5;
|
|
236
|
-
case 5:
|
|
237
|
-
if (res.value.err) {
|
|
238
|
-
errMessage = JSON.stringify(res.value.err);
|
|
239
|
-
if (!errMessage.includes("BlockhashNotFound") || i === 2) {
|
|
240
|
-
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + errMessage, res.value.logs || undefined);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return [3 /*break*/, 7];
|
|
244
|
-
case 6:
|
|
245
|
-
i++;
|
|
246
|
-
return [3 /*break*/, 1];
|
|
247
|
-
case 7:
|
|
248
248
|
isVersioned = isTransactionVersioned(tx);
|
|
249
249
|
if (isVersioned) {
|
|
250
250
|
signature = bs58_1.default.encode(tx.signatures[0]);
|
|
@@ -253,82 +253,123 @@ function executeTransaction(connection, tx, _a) {
|
|
|
253
253
|
signature = bs58_1.default.encode(tx.signature);
|
|
254
254
|
}
|
|
255
255
|
return [4 /*yield*/, connection.getBlockHeight(commitment)];
|
|
256
|
-
case
|
|
256
|
+
case 1:
|
|
257
257
|
blockheight = _b.sent();
|
|
258
258
|
transactionSent = false;
|
|
259
259
|
rawTransaction = tx.serialize();
|
|
260
|
-
_b.label =
|
|
261
|
-
case
|
|
262
|
-
if (!(blockheight < hash.lastValidBlockHeight)) return [3 /*break*/,
|
|
263
|
-
_b.label =
|
|
264
|
-
case
|
|
265
|
-
_b.trys.push([
|
|
260
|
+
_b.label = 2;
|
|
261
|
+
case 2:
|
|
262
|
+
if (!(blockheight < hash.lastValidBlockHeight + 15)) return [3 /*break*/, 20];
|
|
263
|
+
_b.label = 3;
|
|
264
|
+
case 3:
|
|
265
|
+
_b.trys.push([3, 6, , 9]);
|
|
266
|
+
if (!(blockheight < hash.lastValidBlockHeight || !transactionSent)) return [3 /*break*/, 5];
|
|
266
267
|
return [4 /*yield*/, connection.sendRawTransaction(rawTransaction, {
|
|
267
268
|
maxRetries: 0,
|
|
268
269
|
minContextSlot: context.slot,
|
|
269
270
|
preflightCommitment: commitment,
|
|
270
271
|
skipPreflight: true,
|
|
271
272
|
})];
|
|
272
|
-
case
|
|
273
|
+
case 4:
|
|
273
274
|
_b.sent();
|
|
274
275
|
transactionSent = true;
|
|
275
|
-
|
|
276
|
-
case
|
|
276
|
+
_b.label = 5;
|
|
277
|
+
case 5: return [3 /*break*/, 9];
|
|
278
|
+
case 6:
|
|
277
279
|
e_1 = _b.sent();
|
|
278
|
-
if (transactionSent ||
|
|
279
|
-
(e_1 instanceof web3_js_1.SendTransactionError && e_1.message.includes("Minimum context slot has not been reached")))
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
throw e_1;
|
|
283
|
-
case 13: return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
284
|
-
case 14:
|
|
280
|
+
if (!(transactionSent ||
|
|
281
|
+
(e_1 instanceof web3_js_1.SendTransactionError && e_1.message.includes("Minimum context slot has not been reached")))) return [3 /*break*/, 8];
|
|
282
|
+
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
283
|
+
case 7:
|
|
285
284
|
_b.sent();
|
|
286
|
-
|
|
287
|
-
case
|
|
288
|
-
|
|
285
|
+
return [3 /*break*/, 2];
|
|
286
|
+
case 8: throw e_1;
|
|
287
|
+
case 9: return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
288
|
+
case 10:
|
|
289
|
+
_b.sent();
|
|
290
|
+
_b.label = 11;
|
|
291
|
+
case 11:
|
|
292
|
+
_b.trys.push([11, 13, , 15]);
|
|
289
293
|
return [4 /*yield*/, confirmAndEnsureTransaction(connection, signature)];
|
|
290
|
-
case
|
|
294
|
+
case 12:
|
|
291
295
|
value = _b.sent();
|
|
292
296
|
if (value) {
|
|
293
297
|
return [2 /*return*/, signature];
|
|
294
298
|
}
|
|
295
|
-
return [3 /*break*/,
|
|
296
|
-
case
|
|
299
|
+
return [3 /*break*/, 15];
|
|
300
|
+
case 13:
|
|
297
301
|
e_2 = _b.sent();
|
|
298
302
|
if (e_2 instanceof types_1.TransactionFailedError) {
|
|
299
303
|
throw e_2;
|
|
300
304
|
}
|
|
301
305
|
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
302
|
-
case
|
|
306
|
+
case 14:
|
|
303
307
|
_b.sent();
|
|
304
|
-
return [3 /*break*/,
|
|
305
|
-
case
|
|
306
|
-
_b.trys.push([
|
|
308
|
+
return [3 /*break*/, 15];
|
|
309
|
+
case 15:
|
|
310
|
+
_b.trys.push([15, 17, , 19]);
|
|
307
311
|
return [4 /*yield*/, connection.getBlockHeight(commitment)];
|
|
308
|
-
case
|
|
312
|
+
case 16:
|
|
309
313
|
blockheight = _b.sent();
|
|
310
|
-
return [3 /*break*/,
|
|
311
|
-
case
|
|
314
|
+
return [3 /*break*/, 19];
|
|
315
|
+
case 17:
|
|
312
316
|
_e_1 = _b.sent();
|
|
313
317
|
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
314
|
-
case
|
|
318
|
+
case 18:
|
|
315
319
|
_b.sent();
|
|
316
|
-
return [3 /*break*/,
|
|
317
|
-
case
|
|
318
|
-
case
|
|
320
|
+
return [3 /*break*/, 19];
|
|
321
|
+
case 19: return [3 /*break*/, 2];
|
|
322
|
+
case 20: throw new Error("Transaction ".concat(signature, " expired."));
|
|
319
323
|
}
|
|
320
324
|
});
|
|
321
325
|
});
|
|
322
326
|
}
|
|
323
|
-
exports.
|
|
327
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
328
|
+
function simulateTransaction(connection, tx) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
330
|
+
var i, res, errMessage;
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
i = 0;
|
|
335
|
+
_a.label = 1;
|
|
336
|
+
case 1:
|
|
337
|
+
if (!(i < SIMULATE_TRIES)) return [3 /*break*/, 7];
|
|
338
|
+
res = void 0;
|
|
339
|
+
if (!isTransactionVersioned(tx)) return [3 /*break*/, 3];
|
|
340
|
+
return [4 /*yield*/, connection.simulateTransaction(tx)];
|
|
341
|
+
case 2:
|
|
342
|
+
res = _a.sent();
|
|
343
|
+
return [3 /*break*/, 5];
|
|
344
|
+
case 3: return [4 /*yield*/, connection.simulateTransaction(tx)];
|
|
345
|
+
case 4:
|
|
346
|
+
res = _a.sent();
|
|
347
|
+
_a.label = 5;
|
|
348
|
+
case 5:
|
|
349
|
+
if (res.value.err) {
|
|
350
|
+
errMessage = JSON.stringify(res.value.err);
|
|
351
|
+
if (!errMessage.includes("BlockhashNotFound") || i === SIMULATE_TRIES - 1) {
|
|
352
|
+
throw new web3_js_1.SendTransactionError("failed to simulate transaction: " + errMessage, res.value.logs || undefined);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return [3 /*break*/, 7];
|
|
356
|
+
case 6:
|
|
357
|
+
i++;
|
|
358
|
+
return [3 /*break*/, 1];
|
|
359
|
+
case 7: return [2 /*return*/];
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
exports.simulateTransaction = simulateTransaction;
|
|
324
365
|
/**
|
|
325
366
|
* Confirms and validates transaction success once
|
|
326
367
|
* @param connection - Solana client connection
|
|
327
368
|
* @param signature - Transaction signature
|
|
328
|
-
* @param
|
|
369
|
+
* @param ignoreError - return status even if tx failed
|
|
329
370
|
* @returns Transaction Status
|
|
330
371
|
*/
|
|
331
|
-
function confirmAndEnsureTransaction(connection, signature,
|
|
372
|
+
function confirmAndEnsureTransaction(connection, signature, ignoreError) {
|
|
332
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
333
374
|
var response, value;
|
|
334
375
|
return __generator(this, function (_a) {
|
|
@@ -343,7 +384,7 @@ function confirmAndEnsureTransaction(connection, signature, passError) {
|
|
|
343
384
|
if (!value) {
|
|
344
385
|
return [2 /*return*/, null];
|
|
345
386
|
}
|
|
346
|
-
if (!
|
|
387
|
+
if (!ignoreError && value.err) {
|
|
347
388
|
// That's how solana-web3js does it, `err` here is an object that won't really be handled
|
|
348
389
|
throw new types_1.TransactionFailedError("Raw transaction ".concat(signature, " failed (").concat(JSON.stringify({ err: value.err }), ")"));
|
|
349
390
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2",
|
|
4
4
|
"description": "Common utilities and types used by streamflow packages.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"lint-config": "eslint --print-config",
|
|
24
24
|
"prepublishOnly": "npm run lint && npm run build"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "1104b998070b9c5c70142025ba8aa22895990b10",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@streamflow/eslint-config": "6.0.0",
|
|
29
29
|
"@types/bn.js": "5.1.1",
|