@streamflow/common 6.0.0-alpha.1 → 6.0.0-alpha.10
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 +5 -13
- package/dist/solana/types.js +0 -3
- package/dist/solana/utils.d.ts +27 -2
- package/dist/solana/utils.js +79 -11
- package/dist/types.d.ts +2 -1
- package/dist/types.js +2 -1
- package/package.json +3 -3
package/dist/solana/types.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { AccountInfo, PublicKey } from "@solana/web3.js";
|
|
3
|
+
export interface ITransactionSolanaExt {
|
|
4
|
+
computePrice?: number;
|
|
5
|
+
computeLimit?: number;
|
|
6
|
+
}
|
|
5
7
|
export interface Account {
|
|
6
8
|
pubkey: PublicKey;
|
|
7
9
|
account: AccountInfo<Buffer>;
|
|
8
10
|
}
|
|
9
|
-
export interface IInteractStreamSolanaExt {
|
|
10
|
-
invoker: SignerWalletAdapter | Keypair;
|
|
11
|
-
}
|
|
12
|
-
export interface TransactionResponse {
|
|
13
|
-
tx: TransactionSignature;
|
|
14
|
-
}
|
|
15
|
-
export interface TxResponse {
|
|
16
|
-
ixs: TransactionInstruction[];
|
|
17
|
-
tx: TransactionSignature;
|
|
18
|
-
}
|
|
19
11
|
export interface CheckAssociatedTokenAccountsData {
|
|
20
12
|
sender: PublicKey;
|
|
21
13
|
recipient: PublicKey;
|
package/dist/solana/types.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Cluster = void 0;
|
|
4
|
-
var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
|
|
5
|
-
Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
|
package/dist/solana/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
|
|
2
|
-
import { Connection, Keypair, PublicKey,
|
|
3
|
-
import { AtaParams,
|
|
2
|
+
import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { Account, AtaParams, ITransactionSolanaExt } from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
6
6
|
* @param {Connection} connection - Solana web3 connection object.
|
|
@@ -22,6 +22,25 @@ export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAd
|
|
|
22
22
|
* @returns {boolean} - Returns true if parameter is a Keypair.
|
|
23
23
|
*/
|
|
24
24
|
export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a Transaction with given instructions and optionally signs it.
|
|
27
|
+
* Be careful when passing `commitment` as for `confirmed` blockhash it always returns blockheight + 300 in `lastValidBlockHeight`
|
|
28
|
+
* And if you use this blockheight to confirm the transaction it could happen so that transaction is successfully executed
|
|
29
|
+
* But because `confirmTransaction` waits for only a minute it considers tx as expired as it could be that 300 blocks won't pass in a minute
|
|
30
|
+
* https://solana.stackexchange.com/questions/6238/why-is-lastvalidblockheight-300-blocks-ahead-than-current-blockheight-if-hashes
|
|
31
|
+
* https://solana.com/docs/core/transactions/retry
|
|
32
|
+
* It might be better to rely on `commitment` level that you pass to `Connection` instance of Solana client as it will be used when fetching blockheight on transaction confirmation
|
|
33
|
+
* @param connection - Solana client connection
|
|
34
|
+
* @param ixs - Instructions to add to the Transaction
|
|
35
|
+
* @param payer - PublicKey of payer
|
|
36
|
+
* @param commitment - optional Commitment that will be used to fetch latest blockhash
|
|
37
|
+
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
38
|
+
* @returns Transaction and Blockhash
|
|
39
|
+
*/
|
|
40
|
+
export declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
|
|
41
|
+
tx: Transaction;
|
|
42
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
43
|
+
}>;
|
|
25
44
|
export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
|
|
26
45
|
/**
|
|
27
46
|
* Signs, sends and confirms Transaction
|
|
@@ -74,3 +93,9 @@ export declare function createAtaBatch(connection: Connection, invoker: Keypair
|
|
|
74
93
|
* @returns Array of Transaction Instructions that should be added to a transaction
|
|
75
94
|
*/
|
|
76
95
|
export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair): Promise<TransactionInstruction[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Create Base instructions for Solana
|
|
98
|
+
* - sets compute price if `computePrice` is provided
|
|
99
|
+
* - sets compute limit if `computeLimit` is provided
|
|
100
|
+
*/
|
|
101
|
+
export declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
|
package/dist/solana/utils.js
CHANGED
|
@@ -75,7 +75,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
75
75
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
76
|
};
|
|
77
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
-
exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.signAndExecuteTransaction = exports.signTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
|
|
78
|
+
exports.prepareBaseInstructions = exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
|
|
79
79
|
var spl_token_1 = require("@solana/spl-token");
|
|
80
80
|
var web3_js_1 = require("@solana/web3.js");
|
|
81
81
|
var bs58_1 = __importDefault(require("bs58"));
|
|
@@ -124,6 +124,60 @@ function isSignerKeypair(walletOrKeypair) {
|
|
|
124
124
|
walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
|
|
125
125
|
}
|
|
126
126
|
exports.isSignerKeypair = isSignerKeypair;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a Transaction with given instructions and optionally signs it.
|
|
129
|
+
* Be careful when passing `commitment` as for `confirmed` blockhash it always returns blockheight + 300 in `lastValidBlockHeight`
|
|
130
|
+
* And if you use this blockheight to confirm the transaction it could happen so that transaction is successfully executed
|
|
131
|
+
* But because `confirmTransaction` waits for only a minute it considers tx as expired as it could be that 300 blocks won't pass in a minute
|
|
132
|
+
* https://solana.stackexchange.com/questions/6238/why-is-lastvalidblockheight-300-blocks-ahead-than-current-blockheight-if-hashes
|
|
133
|
+
* https://solana.com/docs/core/transactions/retry
|
|
134
|
+
* It might be better to rely on `commitment` level that you pass to `Connection` instance of Solana client as it will be used when fetching blockheight on transaction confirmation
|
|
135
|
+
* @param connection - Solana client connection
|
|
136
|
+
* @param ixs - Instructions to add to the Transaction
|
|
137
|
+
* @param payer - PublicKey of payer
|
|
138
|
+
* @param commitment - optional Commitment that will be used to fetch latest blockhash
|
|
139
|
+
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
140
|
+
* @returns Transaction and Blockhash
|
|
141
|
+
*/
|
|
142
|
+
function prepareTransaction(connection, ixs, payer, commitment) {
|
|
143
|
+
var partialSigners = [];
|
|
144
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
145
|
+
partialSigners[_i - 4] = arguments[_i];
|
|
146
|
+
}
|
|
147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var hash, tx, partialSigners_1, partialSigners_1_1, signer;
|
|
149
|
+
var _a, e_1, _b;
|
|
150
|
+
return __generator(this, function (_c) {
|
|
151
|
+
switch (_c.label) {
|
|
152
|
+
case 0: return [4 /*yield*/, connection.getLatestBlockhash(commitment)];
|
|
153
|
+
case 1:
|
|
154
|
+
hash = _c.sent();
|
|
155
|
+
tx = (_a = new web3_js_1.Transaction({
|
|
156
|
+
feePayer: payer,
|
|
157
|
+
blockhash: hash.blockhash,
|
|
158
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
159
|
+
})).add.apply(_a, __spreadArray([], __read(ixs), false));
|
|
160
|
+
try {
|
|
161
|
+
for (partialSigners_1 = __values(partialSigners), partialSigners_1_1 = partialSigners_1.next(); !partialSigners_1_1.done; partialSigners_1_1 = partialSigners_1.next()) {
|
|
162
|
+
signer = partialSigners_1_1.value;
|
|
163
|
+
if (signer) {
|
|
164
|
+
tx.partialSign(signer);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
169
|
+
finally {
|
|
170
|
+
try {
|
|
171
|
+
if (partialSigners_1_1 && !partialSigners_1_1.done && (_b = partialSigners_1.return)) _b.call(partialSigners_1);
|
|
172
|
+
}
|
|
173
|
+
finally { if (e_1) throw e_1.error; }
|
|
174
|
+
}
|
|
175
|
+
return [2 /*return*/, { tx: tx, hash: hash }];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
exports.prepareTransaction = prepareTransaction;
|
|
127
181
|
function signTransaction(invoker, tx) {
|
|
128
182
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
183
|
var signedTx;
|
|
@@ -279,16 +333,13 @@ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|
|
|
279
333
|
*/
|
|
280
334
|
function createAtaBatch(connection, invoker, paramsBatch) {
|
|
281
335
|
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
var _a, tx, hash
|
|
336
|
+
var _a, tx, hash;
|
|
283
337
|
return __generator(this, function (_b) {
|
|
284
338
|
switch (_b.label) {
|
|
285
339
|
case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
|
|
286
340
|
case 1:
|
|
287
341
|
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
288
|
-
return [
|
|
289
|
-
case 2:
|
|
290
|
-
signature = _b.sent();
|
|
291
|
-
return [2 /*return*/, signature];
|
|
342
|
+
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
|
|
292
343
|
}
|
|
293
344
|
});
|
|
294
345
|
});
|
|
@@ -304,8 +355,8 @@ exports.createAtaBatch = createAtaBatch;
|
|
|
304
355
|
*/
|
|
305
356
|
function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
306
357
|
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
-
var ixs, atas, owners_1, owners_1_1, owner, _a, _b,
|
|
308
|
-
var
|
|
358
|
+
var ixs, atas, owners_1, owners_1_1, owner, _a, _b, e_2_1, response, i;
|
|
359
|
+
var e_2, _c;
|
|
309
360
|
return __generator(this, function (_d) {
|
|
310
361
|
switch (_d.label) {
|
|
311
362
|
case 0:
|
|
@@ -329,14 +380,14 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
|
329
380
|
return [3 /*break*/, 2];
|
|
330
381
|
case 5: return [3 /*break*/, 8];
|
|
331
382
|
case 6:
|
|
332
|
-
|
|
333
|
-
|
|
383
|
+
e_2_1 = _d.sent();
|
|
384
|
+
e_2 = { error: e_2_1 };
|
|
334
385
|
return [3 /*break*/, 8];
|
|
335
386
|
case 7:
|
|
336
387
|
try {
|
|
337
388
|
if (owners_1_1 && !owners_1_1.done && (_c = owners_1.return)) _c.call(owners_1);
|
|
338
389
|
}
|
|
339
|
-
finally { if (
|
|
390
|
+
finally { if (e_2) throw e_2.error; }
|
|
340
391
|
return [7 /*endfinally*/];
|
|
341
392
|
case 8: return [4 /*yield*/, connection.getMultipleAccountsInfo(atas)];
|
|
342
393
|
case 9:
|
|
@@ -352,3 +403,20 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
|
352
403
|
});
|
|
353
404
|
}
|
|
354
405
|
exports.checkOrCreateAtaBatch = checkOrCreateAtaBatch;
|
|
406
|
+
/**
|
|
407
|
+
* Create Base instructions for Solana
|
|
408
|
+
* - sets compute price if `computePrice` is provided
|
|
409
|
+
* - sets compute limit if `computeLimit` is provided
|
|
410
|
+
*/
|
|
411
|
+
function prepareBaseInstructions(connection, _a) {
|
|
412
|
+
var computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
413
|
+
var ixs = [];
|
|
414
|
+
if (computePrice) {
|
|
415
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
|
|
416
|
+
}
|
|
417
|
+
if (computeLimit) {
|
|
418
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
|
|
419
|
+
}
|
|
420
|
+
return ixs;
|
|
421
|
+
}
|
|
422
|
+
exports.prepareBaseInstructions = prepareBaseInstructions;
|
package/dist/types.d.ts
CHANGED
|
@@ -23,10 +23,11 @@ export declare enum IChain {
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class ContractError extends Error {
|
|
25
25
|
contractErrorCode: string | null;
|
|
26
|
+
description: string | null;
|
|
26
27
|
/**
|
|
27
28
|
* Constructs the Error Wrapper
|
|
28
29
|
* @param error Original error raised probably by the chain SDK
|
|
29
30
|
* @param code extracted code from the error if managed to parse it
|
|
30
31
|
*/
|
|
31
|
-
constructor(error: Error, code?: string | null);
|
|
32
|
+
constructor(error: Error, code?: string | null, description?: string | null);
|
|
32
33
|
}
|
package/dist/types.js
CHANGED
|
@@ -43,9 +43,10 @@ var ContractError = /** @class */ (function (_super) {
|
|
|
43
43
|
* @param error Original error raised probably by the chain SDK
|
|
44
44
|
* @param code extracted code from the error if managed to parse it
|
|
45
45
|
*/
|
|
46
|
-
function ContractError(error, code) {
|
|
46
|
+
function ContractError(error, code, description) {
|
|
47
47
|
var _this = _super.call(this, error.message) || this;
|
|
48
48
|
_this.contractErrorCode = code !== null && code !== void 0 ? code : null;
|
|
49
|
+
_this.description = description !== null && description !== void 0 ? description : null;
|
|
49
50
|
// Copy properties from the original error
|
|
50
51
|
Object.setPrototypeOf(_this, ContractError.prototype);
|
|
51
52
|
_this.name = "ContractError"; // Set the name property
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/common",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.10",
|
|
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,9 +23,9 @@
|
|
|
23
23
|
"lint-config": "eslint --print-config",
|
|
24
24
|
"prepublishOnly": "npm run lint && npm run build"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "ba69862bbf25947672eb767e5852c9763a4a1165",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@streamflow/eslint-config": "6.0.0-alpha.
|
|
28
|
+
"@streamflow/eslint-config": "6.0.0-alpha.10",
|
|
29
29
|
"@types/bn.js": "5.1.1",
|
|
30
30
|
"@types/jest": "29.2.4",
|
|
31
31
|
"date-fns": "2.28.0",
|