@streamflow/common 6.0.3 → 6.1.1
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 +41 -17
- package/dist/solana/utils.js +203 -106
- 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,54 @@ 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
|
-
* @param
|
|
67
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
59
68
|
* @returns Transaction signature
|
|
60
69
|
*/
|
|
61
|
-
export declare function executeTransaction(connection: Connection, tx: Transaction,
|
|
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
|
|
76
|
+
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
77
|
+
* @param context - context at which blockhash has been retrieve
|
|
78
|
+
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
79
|
+
*/
|
|
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>;
|
|
62
82
|
/**
|
|
63
83
|
* Confirms and validates transaction success once
|
|
64
84
|
* @param connection - Solana client connection
|
|
65
85
|
* @param signature - Transaction signature
|
|
86
|
+
* @param ignoreError - return status even if tx failed
|
|
66
87
|
* @returns Transaction Status
|
|
67
88
|
*/
|
|
68
|
-
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string): Promise<SignatureStatus | null>;
|
|
89
|
+
export declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
|
|
69
90
|
/**
|
|
70
91
|
* Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
|
|
71
92
|
* @param {PublicKey} mint - SPL token Mint address.
|
|
@@ -87,20 +108,23 @@ export declare function enrichAtaParams(connection: Connection, paramsBatch: Ata
|
|
|
87
108
|
* @param connection - Solana client connection
|
|
88
109
|
* @param payer - Transaction invoker, should be a signer
|
|
89
110
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
111
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
90
112
|
* @returns Unsigned Transaction with create ATA instructions
|
|
91
113
|
*/
|
|
92
|
-
export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[]): Promise<{
|
|
93
|
-
tx:
|
|
114
|
+
export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
|
|
115
|
+
tx: VersionedTransaction;
|
|
94
116
|
hash: BlockhashWithExpiryBlockHeight;
|
|
117
|
+
context: Context;
|
|
95
118
|
}>;
|
|
96
119
|
/**
|
|
97
120
|
* Creates ATA for an array of owners
|
|
98
121
|
* @param connection - Solana client connection
|
|
99
122
|
* @param invoker - Transaction invoker and payer
|
|
100
123
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
124
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
101
125
|
* @returns Transaction signature
|
|
102
126
|
*/
|
|
103
|
-
export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[]): Promise<string>;
|
|
127
|
+
export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment): Promise<string>;
|
|
104
128
|
/**
|
|
105
129
|
* Utility function that checks whether associated token accounts exist and return instructions to populate them if not
|
|
106
130
|
* @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,11 +50,13 @@ 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.simulateTransaction = exports.sendAndConfirmTransaction = 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");
|
|
59
|
+
var SIMULATE_TRIES = 3;
|
|
83
60
|
/**
|
|
84
61
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
85
62
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -125,6 +102,15 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
125
102
|
walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
|
|
126
103
|
}
|
|
127
104
|
exports.isSignerKeypair = isSignerKeypair;
|
|
105
|
+
/**
|
|
106
|
+
* Utility function to check whether given transaction is Versioned
|
|
107
|
+
* @param tx {Transaction | VersionedTransaction} - Transaction to check
|
|
108
|
+
* @returns {boolean} - Returns true if transaction is Versioned.
|
|
109
|
+
*/
|
|
110
|
+
function isTransactionVersioned(tx) {
|
|
111
|
+
return "message" in tx;
|
|
112
|
+
}
|
|
113
|
+
exports.isTransactionVersioned = isTransactionVersioned;
|
|
128
114
|
/**
|
|
129
115
|
* Creates a Transaction with given instructions and optionally signs it.
|
|
130
116
|
* @param connection - Solana client connection
|
|
@@ -140,34 +126,25 @@ function prepareTransaction(connection, ixs, payer, commitment) {
|
|
|
140
126
|
partialSigners[_i - 4] = arguments[_i];
|
|
141
127
|
}
|
|
142
128
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var hash,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
hash = _c.sent();
|
|
150
|
-
tx = (_a = new web3_js_1.Transaction({
|
|
151
|
-
feePayer: payer,
|
|
152
|
-
blockhash: hash.blockhash,
|
|
153
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
154
|
-
})).add.apply(_a, __spreadArray([], __read(ixs), false));
|
|
155
|
-
try {
|
|
156
|
-
for (partialSigners_1 = __values(partialSigners), partialSigners_1_1 = partialSigners_1.next(); !partialSigners_1_1.done; partialSigners_1_1 = partialSigners_1.next()) {
|
|
157
|
-
signer = partialSigners_1_1.value;
|
|
158
|
-
if (signer) {
|
|
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; }
|
|
129
|
+
var _a, hash, context, messageV0, tx, signers;
|
|
130
|
+
return __generator(this, function (_b) {
|
|
131
|
+
switch (_b.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
if (!payer) {
|
|
134
|
+
throw new Error("Payer public key is not provided!");
|
|
169
135
|
}
|
|
170
|
-
return [
|
|
136
|
+
return [4 /*yield*/, connection.getLatestBlockhashAndContext(commitment)];
|
|
137
|
+
case 1:
|
|
138
|
+
_a = _b.sent(), hash = _a.value, context = _a.context;
|
|
139
|
+
messageV0 = new web3_js_1.TransactionMessage({
|
|
140
|
+
payerKey: payer,
|
|
141
|
+
recentBlockhash: hash.blockhash,
|
|
142
|
+
instructions: ixs,
|
|
143
|
+
}).compileToV0Message();
|
|
144
|
+
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
145
|
+
signers = partialSigners.filter(function (item) { return !!item; });
|
|
146
|
+
tx.sign(signers);
|
|
147
|
+
return [2 /*return*/, { tx: tx, context: context, hash: hash }];
|
|
171
148
|
}
|
|
172
149
|
});
|
|
173
150
|
});
|
|
@@ -185,7 +162,12 @@ function signTransaction(invoker, tx) {
|
|
|
185
162
|
signedTx = _a.sent();
|
|
186
163
|
return [3 /*break*/, 3];
|
|
187
164
|
case 2:
|
|
188
|
-
tx
|
|
165
|
+
if (isTransactionVersioned(tx)) {
|
|
166
|
+
tx.sign([invoker]);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
tx.partialSign(invoker);
|
|
170
|
+
}
|
|
189
171
|
signedTx = tx;
|
|
190
172
|
_a.label = 3;
|
|
191
173
|
case 3: return [2 /*return*/, signedTx];
|
|
@@ -199,10 +181,10 @@ exports.signTransaction = signTransaction;
|
|
|
199
181
|
* @param connection - Solana client connection
|
|
200
182
|
* @param invoker - Keypair used as signer
|
|
201
183
|
* @param tx - Transaction instance
|
|
202
|
-
* @param
|
|
184
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
203
185
|
* @returns Transaction signature
|
|
204
186
|
*/
|
|
205
|
-
function signAndExecuteTransaction(connection, invoker, tx,
|
|
187
|
+
function signAndExecuteTransaction(connection, invoker, tx, confirmationParams) {
|
|
206
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
207
189
|
var signedTx;
|
|
208
190
|
return __generator(this, function (_a) {
|
|
@@ -210,7 +192,7 @@ function signAndExecuteTransaction(connection, invoker, tx, hash) {
|
|
|
210
192
|
case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
|
|
211
193
|
case 1:
|
|
212
194
|
signedTx = _a.sent();
|
|
213
|
-
return [2 /*return*/, executeTransaction(connection, signedTx,
|
|
195
|
+
return [2 /*return*/, executeTransaction(connection, signedTx, confirmationParams)];
|
|
214
196
|
}
|
|
215
197
|
});
|
|
216
198
|
});
|
|
@@ -218,63 +200,176 @@ function signAndExecuteTransaction(connection, invoker, tx, hash) {
|
|
|
218
200
|
exports.signAndExecuteTransaction = signAndExecuteTransaction;
|
|
219
201
|
/**
|
|
220
202
|
* Sends and confirms Transaction
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* -
|
|
225
|
-
* -
|
|
203
|
+
* Uses custom confirmation logic that:
|
|
204
|
+
* - simulates tx before sending separately
|
|
205
|
+
* - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
|
|
206
|
+
* - rebroadcasts a tx every 500 ms
|
|
207
|
+
* - after broadcasting check whether tx has executed once
|
|
208
|
+
* - catch errors for every actionable item, throw only the ones that signal that tx has failed
|
|
209
|
+
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
226
210
|
* @param connection - Solana client connection
|
|
227
211
|
* @param tx - Transaction instance
|
|
228
|
-
* @param
|
|
212
|
+
* @param {ConfirmationParams} confirmationParams - Confirmation Params that will be used for execution
|
|
229
213
|
* @returns Transaction signature
|
|
230
214
|
*/
|
|
231
|
-
function executeTransaction(connection, tx,
|
|
215
|
+
function executeTransaction(connection, tx, confirmationParams) {
|
|
232
216
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
var rawTx, signature, confirmationStrategy, e_2, value;
|
|
234
217
|
return __generator(this, function (_a) {
|
|
235
218
|
switch (_a.label) {
|
|
236
219
|
case 0:
|
|
237
|
-
|
|
238
|
-
if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
|
|
220
|
+
if (tx.signatures.length === 0) {
|
|
239
221
|
throw Error("Error with transaction parameters.");
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
lastValidBlockHeight: hash.lastValidBlockHeight + 50,
|
|
243
|
-
signature: signature,
|
|
244
|
-
blockhash: hash.blockhash,
|
|
245
|
-
};
|
|
246
|
-
_a.label = 1;
|
|
222
|
+
}
|
|
223
|
+
return [4 /*yield*/, simulateTransaction(connection, tx)];
|
|
247
224
|
case 1:
|
|
248
|
-
_a.
|
|
249
|
-
return [
|
|
250
|
-
|
|
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
|
|
237
|
+
* @param hash - blockhash information, the same hash should be used in the Transaction
|
|
238
|
+
* @param context - context at which blockhash has been retrieve
|
|
239
|
+
* @param commitment - optional commitment that will be used for simulation and confirmation
|
|
240
|
+
*/
|
|
241
|
+
function sendAndConfirmTransaction(connection, tx, _a) {
|
|
242
|
+
var hash = _a.hash, context = _a.context, commitment = _a.commitment;
|
|
243
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
+
var isVersioned, signature, blockheight, transactionSent, rawTransaction, e_1, value, e_2, _e_1;
|
|
245
|
+
return __generator(this, function (_b) {
|
|
246
|
+
switch (_b.label) {
|
|
247
|
+
case 0:
|
|
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 1:
|
|
257
|
+
blockheight = _b.sent();
|
|
258
|
+
transactionSent = false;
|
|
259
|
+
rawTransaction = tx.serialize();
|
|
260
|
+
_b.label = 2;
|
|
261
|
+
case 2:
|
|
262
|
+
if (!(blockheight < hash.lastValidBlockHeight + 15)) return [3 /*break*/, 20];
|
|
263
|
+
_b.label = 3;
|
|
251
264
|
case 3:
|
|
252
|
-
|
|
253
|
-
if (!(
|
|
254
|
-
return [4 /*yield*/, (
|
|
265
|
+
_b.trys.push([3, 6, , 9]);
|
|
266
|
+
if (!(blockheight < hash.lastValidBlockHeight || !transactionSent)) return [3 /*break*/, 5];
|
|
267
|
+
return [4 /*yield*/, connection.sendRawTransaction(rawTransaction, {
|
|
268
|
+
maxRetries: 0,
|
|
269
|
+
minContextSlot: context.slot,
|
|
270
|
+
preflightCommitment: commitment,
|
|
271
|
+
skipPreflight: true,
|
|
272
|
+
})];
|
|
255
273
|
case 4:
|
|
256
|
-
|
|
274
|
+
_b.sent();
|
|
275
|
+
transactionSent = true;
|
|
276
|
+
_b.label = 5;
|
|
277
|
+
case 5: return [3 /*break*/, 9];
|
|
278
|
+
case 6:
|
|
279
|
+
e_1 = _b.sent();
|
|
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:
|
|
284
|
+
_b.sent();
|
|
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]);
|
|
257
293
|
return [4 /*yield*/, confirmAndEnsureTransaction(connection, signature)];
|
|
258
|
-
case
|
|
259
|
-
value =
|
|
260
|
-
if (
|
|
294
|
+
case 12:
|
|
295
|
+
value = _b.sent();
|
|
296
|
+
if (value) {
|
|
297
|
+
return [2 /*return*/, signature];
|
|
298
|
+
}
|
|
299
|
+
return [3 /*break*/, 15];
|
|
300
|
+
case 13:
|
|
301
|
+
e_2 = _b.sent();
|
|
302
|
+
if (e_2 instanceof types_1.TransactionFailedError) {
|
|
261
303
|
throw e_2;
|
|
262
304
|
}
|
|
263
|
-
return [
|
|
264
|
-
case
|
|
305
|
+
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
306
|
+
case 14:
|
|
307
|
+
_b.sent();
|
|
308
|
+
return [3 /*break*/, 15];
|
|
309
|
+
case 15:
|
|
310
|
+
_b.trys.push([15, 17, , 19]);
|
|
311
|
+
return [4 /*yield*/, connection.getBlockHeight(commitment)];
|
|
312
|
+
case 16:
|
|
313
|
+
blockheight = _b.sent();
|
|
314
|
+
return [3 /*break*/, 19];
|
|
315
|
+
case 17:
|
|
316
|
+
_e_1 = _b.sent();
|
|
317
|
+
return [4 /*yield*/, (0, utils_1.sleep)(500)];
|
|
318
|
+
case 18:
|
|
319
|
+
_b.sent();
|
|
320
|
+
return [3 /*break*/, 19];
|
|
321
|
+
case 19: return [3 /*break*/, 2];
|
|
322
|
+
case 20: throw new Error("Transaction ".concat(signature, " expired."));
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
}
|
|
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];
|
|
265
359
|
case 7: return [2 /*return*/];
|
|
266
360
|
}
|
|
267
361
|
});
|
|
268
362
|
});
|
|
269
363
|
}
|
|
270
|
-
exports.
|
|
364
|
+
exports.simulateTransaction = simulateTransaction;
|
|
271
365
|
/**
|
|
272
366
|
* Confirms and validates transaction success once
|
|
273
367
|
* @param connection - Solana client connection
|
|
274
368
|
* @param signature - Transaction signature
|
|
369
|
+
* @param ignoreError - return status even if tx failed
|
|
275
370
|
* @returns Transaction Status
|
|
276
371
|
*/
|
|
277
|
-
function confirmAndEnsureTransaction(connection, signature) {
|
|
372
|
+
function confirmAndEnsureTransaction(connection, signature, ignoreError) {
|
|
278
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
279
374
|
var response, value;
|
|
280
375
|
return __generator(this, function (_a) {
|
|
@@ -289,9 +384,9 @@ function confirmAndEnsureTransaction(connection, signature) {
|
|
|
289
384
|
if (!value) {
|
|
290
385
|
return [2 /*return*/, null];
|
|
291
386
|
}
|
|
292
|
-
if (value.err) {
|
|
387
|
+
if (!ignoreError && value.err) {
|
|
293
388
|
// That's how solana-web3js does it, `err` here is an object that won't really be handled
|
|
294
|
-
throw new
|
|
389
|
+
throw new types_1.TransactionFailedError("Raw transaction ".concat(signature, " failed (").concat(JSON.stringify({ err: value.err }), ")"));
|
|
295
390
|
}
|
|
296
391
|
switch (connection.commitment) {
|
|
297
392
|
case "confirmed":
|
|
@@ -398,12 +493,12 @@ exports.enrichAtaParams = enrichAtaParams;
|
|
|
398
493
|
* @param connection - Solana client connection
|
|
399
494
|
* @param payer - Transaction invoker, should be a signer
|
|
400
495
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
496
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
401
497
|
* @returns Unsigned Transaction with create ATA instructions
|
|
402
498
|
*/
|
|
403
|
-
function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
|
|
499
|
+
function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitment) {
|
|
404
500
|
return __awaiter(this, void 0, void 0, function () {
|
|
405
|
-
var ixs, hash, tx;
|
|
406
|
-
var _a;
|
|
501
|
+
var ixs, _a, hash, context, messageV0, tx;
|
|
407
502
|
var _this = this;
|
|
408
503
|
return __generator(this, function (_b) {
|
|
409
504
|
switch (_b.label) {
|
|
@@ -427,15 +522,16 @@ function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
|
|
|
427
522
|
}))];
|
|
428
523
|
case 2:
|
|
429
524
|
ixs = _b.sent();
|
|
430
|
-
return [4 /*yield*/, connection.
|
|
525
|
+
return [4 /*yield*/, connection.getLatestBlockhashAndContext({ commitment: commitment })];
|
|
431
526
|
case 3:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
})
|
|
438
|
-
|
|
527
|
+
_a = _b.sent(), hash = _a.value, context = _a.context;
|
|
528
|
+
messageV0 = new web3_js_1.TransactionMessage({
|
|
529
|
+
payerKey: payer,
|
|
530
|
+
recentBlockhash: hash.blockhash,
|
|
531
|
+
instructions: ixs,
|
|
532
|
+
}).compileToV0Message();
|
|
533
|
+
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
534
|
+
return [2 /*return*/, { tx: tx, hash: hash, context: context }];
|
|
439
535
|
}
|
|
440
536
|
});
|
|
441
537
|
});
|
|
@@ -446,11 +542,12 @@ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|
|
|
446
542
|
* @param connection - Solana client connection
|
|
447
543
|
* @param invoker - Transaction invoker and payer
|
|
448
544
|
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
545
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
449
546
|
* @returns Transaction signature
|
|
450
547
|
*/
|
|
451
|
-
function createAtaBatch(connection, invoker, paramsBatch) {
|
|
548
|
+
function createAtaBatch(connection, invoker, paramsBatch, commitment) {
|
|
452
549
|
return __awaiter(this, void 0, void 0, function () {
|
|
453
|
-
var _a, tx, hash, _b, _c;
|
|
550
|
+
var _a, tx, hash, context, _b, _c;
|
|
454
551
|
return __generator(this, function (_d) {
|
|
455
552
|
switch (_d.label) {
|
|
456
553
|
case 0:
|
|
@@ -458,10 +555,10 @@ function createAtaBatch(connection, invoker, paramsBatch) {
|
|
|
458
555
|
_c = [connection,
|
|
459
556
|
invoker.publicKey];
|
|
460
557
|
return [4 /*yield*/, enrichAtaParams(connection, paramsBatch)];
|
|
461
|
-
case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([_d.sent()]))];
|
|
558
|
+
case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([_d.sent(), commitment]))];
|
|
462
559
|
case 2:
|
|
463
|
-
_a = _d.sent(), tx = _a.tx, hash = _a.hash;
|
|
464
|
-
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
|
|
560
|
+
_a = _d.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
|
|
561
|
+
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, { hash: hash, context: context, commitment: commitment })];
|
|
465
562
|
}
|
|
466
563
|
});
|
|
467
564
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
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": "a05d8010b3000b00038ca16a4d5b915436319bdc",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@streamflow/eslint-config": "6.0.0",
|
|
29
29
|
"@types/bn.js": "5.1.1",
|