@streamflow/common 6.0.0-alpha.1 → 6.0.0-alpha.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 +5 -13
- package/dist/solana/types.js +0 -3
- package/dist/solana/utils.d.ts +21 -2
- package/dist/solana/utils.js +73 -11
- 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,19 @@ 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
|
+
* @param connection - Solana client connection
|
|
28
|
+
* @param ixs - Instructions to add to the Transaction
|
|
29
|
+
* @param payer - PublicKey of payer
|
|
30
|
+
* @param commitment - optional Commitment that will be used to fetch latest blockhash
|
|
31
|
+
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
32
|
+
* @returns Transaction and Blockhash
|
|
33
|
+
*/
|
|
34
|
+
export declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
|
|
35
|
+
tx: Transaction;
|
|
36
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
37
|
+
}>;
|
|
25
38
|
export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
|
|
26
39
|
/**
|
|
27
40
|
* Signs, sends and confirms Transaction
|
|
@@ -74,3 +87,9 @@ export declare function createAtaBatch(connection: Connection, invoker: Keypair
|
|
|
74
87
|
* @returns Array of Transaction Instructions that should be added to a transaction
|
|
75
88
|
*/
|
|
76
89
|
export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair): Promise<TransactionInstruction[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Create Base instructions for Solana
|
|
92
|
+
* - sets compute price if `computePrice` is provided
|
|
93
|
+
* - sets compute limit if `computeLimit` is provided
|
|
94
|
+
*/
|
|
95
|
+
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,54 @@ 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
|
+
* @param connection - Solana client connection
|
|
130
|
+
* @param ixs - Instructions to add to the Transaction
|
|
131
|
+
* @param payer - PublicKey of payer
|
|
132
|
+
* @param commitment - optional Commitment that will be used to fetch latest blockhash
|
|
133
|
+
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
134
|
+
* @returns Transaction and Blockhash
|
|
135
|
+
*/
|
|
136
|
+
function prepareTransaction(connection, ixs, payer, commitment) {
|
|
137
|
+
var partialSigners = [];
|
|
138
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
139
|
+
partialSigners[_i - 4] = arguments[_i];
|
|
140
|
+
}
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
var hash, tx, partialSigners_1, partialSigners_1_1, signer;
|
|
143
|
+
var _a, e_1, _b;
|
|
144
|
+
return __generator(this, function (_c) {
|
|
145
|
+
switch (_c.label) {
|
|
146
|
+
case 0: return [4 /*yield*/, connection.getLatestBlockhash(commitment)];
|
|
147
|
+
case 1:
|
|
148
|
+
hash = _c.sent();
|
|
149
|
+
tx = (_a = new web3_js_1.Transaction({
|
|
150
|
+
feePayer: payer,
|
|
151
|
+
blockhash: hash.blockhash,
|
|
152
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
153
|
+
})).add.apply(_a, __spreadArray([], __read(ixs), false));
|
|
154
|
+
try {
|
|
155
|
+
for (partialSigners_1 = __values(partialSigners), partialSigners_1_1 = partialSigners_1.next(); !partialSigners_1_1.done; partialSigners_1_1 = partialSigners_1.next()) {
|
|
156
|
+
signer = partialSigners_1_1.value;
|
|
157
|
+
if (signer) {
|
|
158
|
+
tx.partialSign(signer);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
163
|
+
finally {
|
|
164
|
+
try {
|
|
165
|
+
if (partialSigners_1_1 && !partialSigners_1_1.done && (_b = partialSigners_1.return)) _b.call(partialSigners_1);
|
|
166
|
+
}
|
|
167
|
+
finally { if (e_1) throw e_1.error; }
|
|
168
|
+
}
|
|
169
|
+
return [2 /*return*/, { tx: tx, hash: hash }];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
exports.prepareTransaction = prepareTransaction;
|
|
127
175
|
function signTransaction(invoker, tx) {
|
|
128
176
|
return __awaiter(this, void 0, void 0, function () {
|
|
129
177
|
var signedTx;
|
|
@@ -279,16 +327,13 @@ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
|
|
|
279
327
|
*/
|
|
280
328
|
function createAtaBatch(connection, invoker, paramsBatch) {
|
|
281
329
|
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
var _a, tx, hash
|
|
330
|
+
var _a, tx, hash;
|
|
283
331
|
return __generator(this, function (_b) {
|
|
284
332
|
switch (_b.label) {
|
|
285
333
|
case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
|
|
286
334
|
case 1:
|
|
287
335
|
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
288
|
-
return [
|
|
289
|
-
case 2:
|
|
290
|
-
signature = _b.sent();
|
|
291
|
-
return [2 /*return*/, signature];
|
|
336
|
+
return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
|
|
292
337
|
}
|
|
293
338
|
});
|
|
294
339
|
});
|
|
@@ -304,8 +349,8 @@ exports.createAtaBatch = createAtaBatch;
|
|
|
304
349
|
*/
|
|
305
350
|
function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
306
351
|
return __awaiter(this, void 0, void 0, function () {
|
|
307
|
-
var ixs, atas, owners_1, owners_1_1, owner, _a, _b,
|
|
308
|
-
var
|
|
352
|
+
var ixs, atas, owners_1, owners_1_1, owner, _a, _b, e_2_1, response, i;
|
|
353
|
+
var e_2, _c;
|
|
309
354
|
return __generator(this, function (_d) {
|
|
310
355
|
switch (_d.label) {
|
|
311
356
|
case 0:
|
|
@@ -329,14 +374,14 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
|
329
374
|
return [3 /*break*/, 2];
|
|
330
375
|
case 5: return [3 /*break*/, 8];
|
|
331
376
|
case 6:
|
|
332
|
-
|
|
333
|
-
|
|
377
|
+
e_2_1 = _d.sent();
|
|
378
|
+
e_2 = { error: e_2_1 };
|
|
334
379
|
return [3 /*break*/, 8];
|
|
335
380
|
case 7:
|
|
336
381
|
try {
|
|
337
382
|
if (owners_1_1 && !owners_1_1.done && (_c = owners_1.return)) _c.call(owners_1);
|
|
338
383
|
}
|
|
339
|
-
finally { if (
|
|
384
|
+
finally { if (e_2) throw e_2.error; }
|
|
340
385
|
return [7 /*endfinally*/];
|
|
341
386
|
case 8: return [4 /*yield*/, connection.getMultipleAccountsInfo(atas)];
|
|
342
387
|
case 9:
|
|
@@ -352,3 +397,20 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
|
|
|
352
397
|
});
|
|
353
398
|
}
|
|
354
399
|
exports.checkOrCreateAtaBatch = checkOrCreateAtaBatch;
|
|
400
|
+
/**
|
|
401
|
+
* Create Base instructions for Solana
|
|
402
|
+
* - sets compute price if `computePrice` is provided
|
|
403
|
+
* - sets compute limit if `computeLimit` is provided
|
|
404
|
+
*/
|
|
405
|
+
function prepareBaseInstructions(connection, _a) {
|
|
406
|
+
var computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
407
|
+
var ixs = [];
|
|
408
|
+
if (computePrice) {
|
|
409
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
|
|
410
|
+
}
|
|
411
|
+
if (computeLimit) {
|
|
412
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
|
|
413
|
+
}
|
|
414
|
+
return ixs;
|
|
415
|
+
}
|
|
416
|
+
exports.prepareBaseInstructions = prepareBaseInstructions;
|
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.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,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": "0d8959b0eb4183e745173f69490f3567ee5ff880",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@streamflow/eslint-config": "6.0.0-alpha.
|
|
28
|
+
"@streamflow/eslint-config": "6.0.0-alpha.2",
|
|
29
29
|
"@types/bn.js": "5.1.1",
|
|
30
30
|
"@types/jest": "29.2.4",
|
|
31
31
|
"date-fns": "2.28.0",
|