@streamflow/common 6.0.3 → 6.1.0
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 +8 -1
- package/dist/solana/types.js +24 -0
- package/dist/solana/utils.d.ts +31 -16
- package/dist/solana/utils.js +164 -108
- package/package.json +2 -2
package/dist/solana/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AccountInfo, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { AccountInfo, BlockhashWithExpiryBlockHeight, Commitment, Context, PublicKey } from "@solana/web3.js";
|
|
3
3
|
export interface ITransactionSolanaExt {
|
|
4
4
|
computePrice?: number;
|
|
5
5
|
computeLimit?: number;
|
|
@@ -20,3 +20,10 @@ export interface AtaParams {
|
|
|
20
20
|
owner: PublicKey;
|
|
21
21
|
programId?: PublicKey;
|
|
22
22
|
}
|
|
23
|
+
export interface ConfirmationParams {
|
|
24
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
25
|
+
context: Context;
|
|
26
|
+
commitment?: Commitment;
|
|
27
|
+
}
|
|
28
|
+
export declare class TransactionFailedError extends Error {
|
|
29
|
+
}
|
package/dist/solana/types.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TransactionFailedError = void 0;
|
|
19
|
+
var TransactionFailedError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(TransactionFailedError, _super);
|
|
21
|
+
function TransactionFailedError() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return TransactionFailedError;
|
|
25
|
+
}(Error));
|
|
26
|
+
exports.TransactionFailedError = TransactionFailedError;
|
package/dist/solana/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Mint } from "@solana/spl-token";
|
|
2
2
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
3
|
-
import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, SignatureStatus } from "@solana/web3.js";
|
|
4
|
-
import { Account, AtaParams, ITransactionSolanaExt } from "./types";
|
|
3
|
+
import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, SignatureStatus, VersionedTransaction, Context } from "@solana/web3.js";
|
|
4
|
+
import { Account, AtaParams, ConfirmationParams, ITransactionSolanaExt } from "./types";
|
|
5
5
|
/**
|
|
6
6
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
7
7
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -23,6 +23,12 @@ export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAd
|
|
|
23
23
|
* @returns {boolean} - Returns true if parameter is a Keypair.
|
|
24
24
|
*/
|
|
25
25
|
export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
|
|
26
|
+
/**
|
|
27
|
+
* Utility function to check whether given transaction is Versioned
|
|
28
|
+
* @param tx {Transaction | VersionedTransaction} - Transaction to check
|
|
29
|
+
* @returns {boolean} - Returns true if transaction is Versioned.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTransactionVersioned(tx: Transaction | VersionedTransaction): tx is VersionedTransaction;
|
|
26
32
|
/**
|
|
27
33
|
* Creates a Transaction with given instructions and optionally signs it.
|
|
28
34
|
* @param connection - Solana client connection
|
|
@@ -33,39 +39,45 @@ export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletA
|
|
|
33
39
|
* @returns Transaction and Blockhash
|
|
34
40
|
*/
|
|
35
41
|
export declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
|
|
36
|
-
tx:
|
|
42
|
+
tx: VersionedTransaction;
|
|
37
43
|
hash: BlockhashWithExpiryBlockHeight;
|
|
44
|
+
context: Context;
|
|
38
45
|
}>;
|
|
39
|
-
export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx:
|
|
46
|
+
export declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
|
|
40
47
|
/**
|
|
41
48
|
* Signs, sends and confirms Transaction
|
|
42
49
|
* @param connection - Solana client connection
|
|
43
50
|
* @param invoker - Keypair used as signer
|
|
44
51
|
* @param tx - Transaction instance
|
|
45
|
-
* @param
|
|
52
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
46
53
|
* @returns Transaction signature
|
|
47
54
|
*/
|
|
48
|
-
export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction,
|
|
55
|
+
export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams): Promise<string>;
|
|
49
56
|
/**
|
|
50
57
|
* Sends and confirms Transaction
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* -
|
|
55
|
-
* -
|
|
58
|
+
* Uses custom confirmation logic that:
|
|
59
|
+
* - simulates tx before sending separately
|
|
60
|
+
* - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
|
|
61
|
+
* - rebroadcasts a tx every 500 ms
|
|
62
|
+
* - after broadcasting check whether tx has executed once
|
|
63
|
+
* - catch errors for every actionable item, throw only the ones that signal that tx has failed
|
|
64
|
+
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
56
65
|
* @param connection - Solana client connection
|
|
57
66
|
* @param tx - Transaction instance
|
|
58
67
|
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
68
|
+
* @param context - context at which blockhash has been retrieve
|
|
69
|
+
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
59
70
|
* @returns Transaction signature
|
|
60
71
|
*/
|
|
61
|
-
export declare function executeTransaction(connection: Connection, tx: Transaction, hash:
|
|
72
|
+
export declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams): Promise<string>;
|
|
62
73
|
/**
|
|
63
74
|
* Confirms and validates transaction success once
|
|
64
75
|
* @param connection - Solana client connection
|
|
65
76
|
* @param signature - Transaction signature
|
|
77
|
+
* @param passError - return status even if tx failed
|
|
66
78
|
* @returns Transaction Status
|
|
67
79
|
*/
|
|
68
|
-
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string): Promise<SignatureStatus | null>;
|
|
80
|
+
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string, passError?: boolean): Promise<SignatureStatus | null>;
|
|
69
81
|
/**
|
|
70
82
|
* Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
|
|
71
83
|
* @param {PublicKey} mint - SPL token Mint address.
|
|
@@ -87,20 +99,23 @@ export declare function enrichAtaParams(connection: Connection, paramsBatch: Ata
|
|
|
87
99
|
* @param connection - Solana client connection
|
|
88
100
|
* @param payer - Transaction invoker, should be a signer
|
|
89
101
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
102
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
90
103
|
* @returns Unsigned Transaction with create ATA instructions
|
|
91
104
|
*/
|
|
92
|
-
export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[]): Promise<{
|
|
93
|
-
tx:
|
|
105
|
+
export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
|
|
106
|
+
tx: VersionedTransaction;
|
|
94
107
|
hash: BlockhashWithExpiryBlockHeight;
|
|
108
|
+
context: Context;
|
|
95
109
|
}>;
|
|
96
110
|
/**
|
|
97
111
|
* Creates ATA for an array of owners
|
|
98
112
|
* @param connection - Solana client connection
|
|
99
113
|
* @param invoker - Transaction invoker and payer
|
|
100
114
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
115
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
101
116
|
* @returns Transaction signature
|
|
102
117
|
*/
|
|
103
|
-
export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[]): Promise<string>;
|
|
118
|
+
export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment): Promise<string>;
|
|
104
119
|
/**
|
|
105
120
|
* Utility function that checks whether associated token accounts exist and return instructions to populate them if not
|
|
106
121
|
* @param connection - Solana client connection
|
package/dist/solana/utils.js
CHANGED
|
@@ -35,31 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
38
|
var __values = (this && this.__values) || function(o) {
|
|
64
39
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
65
40
|
if (m) return m.call(o);
|
|
@@ -75,10 +50,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
75
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
51
|
};
|
|
77
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
-
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.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.executeTransaction = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isTransactionVersioned = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
|
|
79
54
|
var spl_token_1 = require("@solana/spl-token");
|
|
80
55
|
var web3_js_1 = require("@solana/web3.js");
|
|
81
56
|
var bs58_1 = __importDefault(require("bs58"));
|
|
57
|
+
var types_1 = require("./types");
|
|
82
58
|
var utils_1 = require("../utils");
|
|
83
59
|
/**
|
|
84
60
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
@@ -125,6 +101,15 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
125
101
|
walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
|
|
126
102
|
}
|
|
127
103
|
exports.isSignerKeypair = isSignerKeypair;
|
|
104
|
+
/**
|
|
105
|
+
* Utility function to check whether given transaction is Versioned
|
|
106
|
+
* @param tx {Transaction | VersionedTransaction} - Transaction to check
|
|
107
|
+
* @returns {boolean} - Returns true if transaction is Versioned.
|
|
108
|
+
*/
|
|
109
|
+
function isTransactionVersioned(tx) {
|
|
110
|
+
return "message" in tx;
|
|
111
|
+
}
|
|
112
|
+
exports.isTransactionVersioned = isTransactionVersioned;
|
|
128
113
|
/**
|
|
129
114
|
* Creates a Transaction with given instructions and optionally signs it.
|
|
130
115
|
* @param connection - Solana client connection
|
|
@@ -140,34 +125,21 @@ function prepareTransaction(connection, ixs, payer, commitment) {
|
|
|
140
125
|
partialSigners[_i - 4] = arguments[_i];
|
|
141
126
|
}
|
|
142
127
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var hash,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
case 0: return [4 /*yield*/, connection.getLatestBlockhash(commitment)];
|
|
128
|
+
var _a, hash, context, messageV0, tx, signers;
|
|
129
|
+
return __generator(this, function (_b) {
|
|
130
|
+
switch (_b.label) {
|
|
131
|
+
case 0: return [4 /*yield*/, connection.getLatestBlockhashAndContext(commitment)];
|
|
148
132
|
case 1:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
tx.partialSign(signer);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
164
|
-
finally {
|
|
165
|
-
try {
|
|
166
|
-
if (partialSigners_1_1 && !partialSigners_1_1.done && (_b = partialSigners_1.return)) _b.call(partialSigners_1);
|
|
167
|
-
}
|
|
168
|
-
finally { if (e_1) throw e_1.error; }
|
|
169
|
-
}
|
|
170
|
-
return [2 /*return*/, { tx: tx, hash: hash }];
|
|
133
|
+
_a = _b.sent(), hash = _a.value, context = _a.context;
|
|
134
|
+
messageV0 = new web3_js_1.TransactionMessage({
|
|
135
|
+
payerKey: payer,
|
|
136
|
+
recentBlockhash: hash.blockhash,
|
|
137
|
+
instructions: ixs,
|
|
138
|
+
}).compileToV0Message();
|
|
139
|
+
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
140
|
+
signers = partialSigners.filter(function (item) { return !!item; });
|
|
141
|
+
tx.sign(signers);
|
|
142
|
+
return [2 /*return*/, { tx: tx, context: context, hash: hash }];
|
|
171
143
|
}
|
|
172
144
|
});
|
|
173
145
|
});
|
|
@@ -185,7 +157,12 @@ function signTransaction(invoker, tx) {
|
|
|
185
157
|
signedTx = _a.sent();
|
|
186
158
|
return [3 /*break*/, 3];
|
|
187
159
|
case 2:
|
|
188
|
-
tx
|
|
160
|
+
if (isTransactionVersioned(tx)) {
|
|
161
|
+
tx.sign([invoker]);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
tx.partialSign(invoker);
|
|
165
|
+
}
|
|
189
166
|
signedTx = tx;
|
|
190
167
|
_a.label = 3;
|
|
191
168
|
case 3: return [2 /*return*/, signedTx];
|
|
@@ -199,10 +176,10 @@ exports.signTransaction = signTransaction;
|
|
|
199
176
|
* @param connection - Solana client connection
|
|
200
177
|
* @param invoker - Keypair used as signer
|
|
201
178
|
* @param tx - Transaction instance
|
|
202
|
-
* @param
|
|
179
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
203
180
|
* @returns Transaction signature
|
|
204
181
|
*/
|
|
205
|
-
function signAndExecuteTransaction(connection, invoker, tx,
|
|
182
|
+
function signAndExecuteTransaction(connection, invoker, tx, confirmationParams) {
|
|
206
183
|
return __awaiter(this, void 0, void 0, function () {
|
|
207
184
|
var signedTx;
|
|
208
185
|
return __generator(this, function (_a) {
|
|
@@ -210,7 +187,7 @@ function signAndExecuteTransaction(connection, invoker, tx, hash) {
|
|
|
210
187
|
case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
|
|
211
188
|
case 1:
|
|
212
189
|
signedTx = _a.sent();
|
|
213
|
-
return [2 /*return*/, executeTransaction(connection, signedTx,
|
|
190
|
+
return [2 /*return*/, executeTransaction(connection, signedTx, confirmationParams)];
|
|
214
191
|
}
|
|
215
192
|
});
|
|
216
193
|
});
|
|
@@ -218,51 +195,127 @@ function signAndExecuteTransaction(connection, invoker, tx, hash) {
|
|
|
218
195
|
exports.signAndExecuteTransaction = signAndExecuteTransaction;
|
|
219
196
|
/**
|
|
220
197
|
* Sends and confirms Transaction
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* -
|
|
225
|
-
* -
|
|
198
|
+
* Uses custom confirmation logic that:
|
|
199
|
+
* - simulates tx before sending separately
|
|
200
|
+
* - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
|
|
201
|
+
* - rebroadcasts a tx every 500 ms
|
|
202
|
+
* - after broadcasting check whether tx has executed once
|
|
203
|
+
* - catch errors for every actionable item, throw only the ones that signal that tx has failed
|
|
204
|
+
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
226
205
|
* @param connection - Solana client connection
|
|
227
206
|
* @param tx - Transaction instance
|
|
228
207
|
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
208
|
+
* @param context - context at which blockhash has been retrieve
|
|
209
|
+
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
229
210
|
* @returns Transaction signature
|
|
230
211
|
*/
|
|
231
|
-
function executeTransaction(connection, tx,
|
|
212
|
+
function executeTransaction(connection, tx, _a) {
|
|
213
|
+
var hash = _a.hash, context = _a.context, commitment = _a.commitment;
|
|
232
214
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
var
|
|
234
|
-
return __generator(this, function (
|
|
235
|
-
switch (
|
|
215
|
+
var i, res, errMessage, isVersioned, signature, blockheight, transactionSent, rawTransaction, e_1, value, e_2, _e_1;
|
|
216
|
+
return __generator(this, function (_b) {
|
|
217
|
+
switch (_b.label) {
|
|
236
218
|
case 0:
|
|
237
|
-
|
|
238
|
-
if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
|
|
219
|
+
if (!hash.lastValidBlockHeight || tx.signatures.length === 0 || !hash.blockhash) {
|
|
239
220
|
throw Error("Error with transaction parameters.");
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
signature: signature,
|
|
244
|
-
blockhash: hash.blockhash,
|
|
245
|
-
};
|
|
246
|
-
_a.label = 1;
|
|
221
|
+
}
|
|
222
|
+
i = 0;
|
|
223
|
+
_b.label = 1;
|
|
247
224
|
case 1:
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return [
|
|
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)];
|
|
255
233
|
case 4:
|
|
256
|
-
|
|
257
|
-
|
|
234
|
+
res = _b.sent();
|
|
235
|
+
_b.label = 5;
|
|
258
236
|
case 5:
|
|
259
|
-
|
|
260
|
-
|
|
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
|
+
isVersioned = isTransactionVersioned(tx);
|
|
249
|
+
if (isVersioned) {
|
|
250
|
+
signature = bs58_1.default.encode(tx.signatures[0]);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
signature = bs58_1.default.encode(tx.signature);
|
|
254
|
+
}
|
|
255
|
+
return [4 /*yield*/, connection.getBlockHeight(commitment)];
|
|
256
|
+
case 8:
|
|
257
|
+
blockheight = _b.sent();
|
|
258
|
+
transactionSent = false;
|
|
259
|
+
rawTransaction = tx.serialize();
|
|
260
|
+
_b.label = 9;
|
|
261
|
+
case 9:
|
|
262
|
+
if (!(blockheight < hash.lastValidBlockHeight)) return [3 /*break*/, 24];
|
|
263
|
+
_b.label = 10;
|
|
264
|
+
case 10:
|
|
265
|
+
_b.trys.push([10, 12, , 13]);
|
|
266
|
+
return [4 /*yield*/, connection.sendRawTransaction(rawTransaction, {
|
|
267
|
+
maxRetries: 0,
|
|
268
|
+
minContextSlot: context.slot,
|
|
269
|
+
preflightCommitment: commitment,
|
|
270
|
+
skipPreflight: true,
|
|
271
|
+
})];
|
|
272
|
+
case 11:
|
|
273
|
+
_b.sent();
|
|
274
|
+
transactionSent = true;
|
|
275
|
+
return [3 /*break*/, 13];
|
|
276
|
+
case 12:
|
|
277
|
+
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
|
+
return [3 /*break*/, 9];
|
|
281
|
+
}
|
|
282
|
+
throw e_1;
|
|
283
|
+
case 13: return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
284
|
+
case 14:
|
|
285
|
+
_b.sent();
|
|
286
|
+
_b.label = 15;
|
|
287
|
+
case 15:
|
|
288
|
+
_b.trys.push([15, 17, , 19]);
|
|
289
|
+
return [4 /*yield*/, confirmAndEnsureTransaction(connection, signature)];
|
|
290
|
+
case 16:
|
|
291
|
+
value = _b.sent();
|
|
292
|
+
if (value) {
|
|
293
|
+
return [2 /*return*/, signature];
|
|
294
|
+
}
|
|
295
|
+
return [3 /*break*/, 19];
|
|
296
|
+
case 17:
|
|
297
|
+
e_2 = _b.sent();
|
|
298
|
+
if (e_2 instanceof types_1.TransactionFailedError) {
|
|
261
299
|
throw e_2;
|
|
262
300
|
}
|
|
263
|
-
return [
|
|
264
|
-
case
|
|
265
|
-
|
|
301
|
+
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
302
|
+
case 18:
|
|
303
|
+
_b.sent();
|
|
304
|
+
return [3 /*break*/, 19];
|
|
305
|
+
case 19:
|
|
306
|
+
_b.trys.push([19, 21, , 23]);
|
|
307
|
+
return [4 /*yield*/, connection.getBlockHeight(commitment)];
|
|
308
|
+
case 20:
|
|
309
|
+
blockheight = _b.sent();
|
|
310
|
+
return [3 /*break*/, 23];
|
|
311
|
+
case 21:
|
|
312
|
+
_e_1 = _b.sent();
|
|
313
|
+
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
314
|
+
case 22:
|
|
315
|
+
_b.sent();
|
|
316
|
+
return [3 /*break*/, 23];
|
|
317
|
+
case 23: return [3 /*break*/, 9];
|
|
318
|
+
case 24: throw new Error("Transaction ".concat(signature, " expired."));
|
|
266
319
|
}
|
|
267
320
|
});
|
|
268
321
|
});
|
|
@@ -272,9 +325,10 @@ exports.executeTransaction = executeTransaction;
|
|
|
272
325
|
* Confirms and validates transaction success once
|
|
273
326
|
* @param connection - Solana client connection
|
|
274
327
|
* @param signature - Transaction signature
|
|
328
|
+
* @param passError - return status even if tx failed
|
|
275
329
|
* @returns Transaction Status
|
|
276
330
|
*/
|
|
277
|
-
function confirmAndEnsureTransaction(connection, signature) {
|
|
331
|
+
function confirmAndEnsureTransaction(connection, signature, passError) {
|
|
278
332
|
return __awaiter(this, void 0, void 0, function () {
|
|
279
333
|
var response, value;
|
|
280
334
|
return __generator(this, function (_a) {
|
|
@@ -289,9 +343,9 @@ function confirmAndEnsureTransaction(connection, signature) {
|
|
|
289
343
|
if (!value) {
|
|
290
344
|
return [2 /*return*/, null];
|
|
291
345
|
}
|
|
292
|
-
if (value.err) {
|
|
346
|
+
if (!passError && value.err) {
|
|
293
347
|
// That's how solana-web3js does it, `err` here is an object that won't really be handled
|
|
294
|
-
throw new
|
|
348
|
+
throw new types_1.TransactionFailedError("Raw transaction ".concat(signature, " failed (").concat(JSON.stringify({ err: value.err }), ")"));
|
|
295
349
|
}
|
|
296
350
|
switch (connection.commitment) {
|
|
297
351
|
case "confirmed":
|
|
@@ -398,12 +452,12 @@ exports.enrichAtaParams = enrichAtaParams;
|
|
|
398
452
|
* @param connection - Solana client connection
|
|
399
453
|
* @param payer - Transaction invoker, should be a signer
|
|
400
454
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
455
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
401
456
|
* @returns Unsigned Transaction with create ATA instructions
|
|
402
457
|
*/
|
|
403
|
-
function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
|
|
458
|
+
function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitment) {
|
|
404
459
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
|
-
var ixs, hash, tx;
|
|
406
|
-
var _a;
|
|
460
|
+
var ixs, _a, hash, context, messageV0, tx;
|
|
407
461
|
var _this = this;
|
|
408
462
|
return __generator(this, function (_b) {
|
|
409
463
|
switch (_b.label) {
|
|
@@ -427,15 +481,16 @@ function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
|
|
|
427
481
|
}))];
|
|
428
482
|
case 2:
|
|
429
483
|
ixs = _b.sent();
|
|
430
|
-
return [4 /*yield*/, connection.
|
|
484
|
+
return [4 /*yield*/, connection.getLatestBlockhashAndContext({ commitment: commitment })];
|
|
431
485
|
case 3:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
})
|
|
438
|
-
|
|
486
|
+
_a = _b.sent(), hash = _a.value, context = _a.context;
|
|
487
|
+
messageV0 = new web3_js_1.TransactionMessage({
|
|
488
|
+
payerKey: payer,
|
|
489
|
+
recentBlockhash: hash.blockhash,
|
|
490
|
+
instructions: ixs,
|
|
491
|
+
}).compileToV0Message();
|
|
492
|
+
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
493
|
+
return [2 /*return*/, { tx: tx, hash: hash, context: context }];
|
|
439
494
|
}
|
|
440
495
|
});
|
|
441
496
|
});
|
|
@@ -446,11 +501,12 @@ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|
|
|
446
501
|
* @param connection - Solana client connection
|
|
447
502
|
* @param invoker - Transaction invoker and payer
|
|
448
503
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
504
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
449
505
|
* @returns Transaction signature
|
|
450
506
|
*/
|
|
451
|
-
function createAtaBatch(connection, invoker, paramsBatch) {
|
|
507
|
+
function createAtaBatch(connection, invoker, paramsBatch, commitment) {
|
|
452
508
|
return __awaiter(this, void 0, void 0, function () {
|
|
453
|
-
var _a, tx, hash, _b, _c;
|
|
509
|
+
var _a, tx, hash, context, _b, _c;
|
|
454
510
|
return __generator(this, function (_d) {
|
|
455
511
|
switch (_d.label) {
|
|
456
512
|
case 0:
|
|
@@ -458,10 +514,10 @@ function createAtaBatch(connection, invoker, paramsBatch) {
|
|
|
458
514
|
_c = [connection,
|
|
459
515
|
invoker.publicKey];
|
|
460
516
|
return [4 /*yield*/, enrichAtaParams(connection, paramsBatch)];
|
|
461
|
-
case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([_d.sent()]))];
|
|
517
|
+
case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([_d.sent(), commitment]))];
|
|
462
518
|
case 2:
|
|
463
|
-
_a = _d.sent(), tx = _a.tx, hash = _a.hash;
|
|
464
|
-
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
|
|
519
|
+
_a = _d.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
|
|
520
|
+
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, { hash: hash, context: context, commitment: commitment })];
|
|
465
521
|
}
|
|
466
522
|
});
|
|
467
523
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
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": "170947ffbd1de885ac95c4b809b0e889d938eaaf",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@streamflow/eslint-config": "6.0.0",
|
|
29
29
|
"@types/bn.js": "5.1.1",
|