@streamflow/common 6.0.0-alpha.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/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,3 @@
1
+ export * from "./instructions";
2
+ export * from "./types";
3
+ export * from "./utils";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./instructions"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,3 @@
1
+ import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
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
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ exports.prepareWrappedAccount = void 0;
65
+ var spl_token_1 = require("@solana/spl-token");
66
+ var web3_js_1 = require("@solana/web3.js");
67
+ var prepareWrappedAccount = function (connection, senderAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
68
+ var tokenAccount, accInfo, instructions;
69
+ var _a, _b;
70
+ return __generator(this, function (_c) {
71
+ switch (_c.label) {
72
+ case 0: return [4 /*yield*/, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, senderAddress, true)];
73
+ case 1:
74
+ tokenAccount = _c.sent();
75
+ return [4 /*yield*/, connection.getParsedAccountInfo(tokenAccount)];
76
+ case 2:
77
+ accInfo = _c.sent();
78
+ instructions = ((_b = (_a = accInfo.value) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0
79
+ ? []
80
+ : [(0, spl_token_1.createAssociatedTokenAccountInstruction)(senderAddress, tokenAccount, senderAddress, spl_token_1.NATIVE_MINT)];
81
+ return [2 /*return*/, __spreadArray(__spreadArray([], __read(instructions), false), [
82
+ web3_js_1.SystemProgram.transfer({
83
+ fromPubkey: senderAddress,
84
+ toPubkey: tokenAccount,
85
+ lamports: amount.toNumber(),
86
+ }),
87
+ (0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
88
+ ], false)];
89
+ }
90
+ });
91
+ }); };
92
+ exports.prepareWrappedAccount = prepareWrappedAccount;
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
+ import { AccountInfo, Keypair, PublicKey, TransactionInstruction, TransactionSignature } from "@solana/web3.js";
4
+ export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";
5
+ export interface Account {
6
+ pubkey: PublicKey;
7
+ account: AccountInfo<Buffer>;
8
+ }
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
+ export interface CheckAssociatedTokenAccountsData {
20
+ sender: PublicKey;
21
+ recipient: PublicKey;
22
+ partner: PublicKey;
23
+ streamflowTreasury: PublicKey;
24
+ mint: PublicKey;
25
+ }
26
+ export interface AtaParams {
27
+ mint: PublicKey;
28
+ owner: PublicKey;
29
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
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; } });
@@ -0,0 +1,76 @@
1
+ import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
2
+ import { Connection, Keypair, PublicKey, TransactionInstruction, Transaction, BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
3
+ import { AtaParams, Account } from "./types";
4
+ /**
5
+ * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
6
+ * @param {Connection} connection - Solana web3 connection object.
7
+ * @param {PublicKey} wallet - PublicKey to compare against.
8
+ * @param {number} offset - Offset of bits of the PublicKey in the account binary.
9
+ * @param {PublicKey} programId - Solana program ID.
10
+ * @return {Promise<Account[]>} - Array of resulting accounts.
11
+ */
12
+ export declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
13
+ /**
14
+ * Utility function to check if the transaction initiator is a Wallet object
15
+ * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
16
+ * @return {boolean} - Returns true if parameter is a Wallet.
17
+ */
18
+ export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
19
+ /**
20
+ * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
21
+ * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
22
+ * @returns {boolean} - Returns true if parameter is a Keypair.
23
+ */
24
+ export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
25
+ export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
26
+ /**
27
+ * Signs, sends and confirms Transaction
28
+ * @param connection - Solana client connection
29
+ * @param invoker - Keypair used as signer
30
+ * @param tx - Transaction instance
31
+ * @param hash - blockhash information, the same hash should be used in the Transaction
32
+ * @returns Transaction signature
33
+ */
34
+ export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
35
+ /**
36
+ * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
37
+ * @param {PublicKey} mint - SPL token Mint address.
38
+ * @param {PublicKey} owner - Owner of the Associated Token Address
39
+ * @return {Promise<PublicKey>} - Associated Token Address
40
+ */
41
+ export declare function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
42
+ /**
43
+ * Function that checks whether ATA exists for each provided owner
44
+ * @param connection - Solana client connection
45
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
46
+ * @returns Array of boolean where each members corresponds to owners member
47
+ */
48
+ export declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
49
+ /**
50
+ * Generates a Transaction to create ATA for an array of owners
51
+ * @param connection - Solana client connection
52
+ * @param payer - Transaction invoker, should be a signer
53
+ * @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
54
+ * @returns Unsigned Transaction with create ATA instructions
55
+ */
56
+ export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[]): Promise<{
57
+ tx: Transaction;
58
+ hash: BlockhashWithExpiryBlockHeight;
59
+ }>;
60
+ /**
61
+ * Creates ATA for an array of owners
62
+ * @param connection - Solana client connection
63
+ * @param invoker - Transaction invoker and payer
64
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
65
+ * @returns Transaction signature
66
+ */
67
+ export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[]): Promise<string>;
68
+ /**
69
+ * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
70
+ * @param connection - Solana client connection
71
+ * @param owners - Array of ATA owners
72
+ * @param mint - Mint for which ATA will be checked
73
+ * @param invoker - Transaction invoker and payer
74
+ * @returns Array of Transaction Instructions that should be added to a transaction
75
+ */
76
+ export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair): Promise<TransactionInstruction[]>;
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
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
+ var __values = (this && this.__values) || function(o) {
64
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
65
+ if (m) return m.call(o);
66
+ if (o && typeof o.length === "number") return {
67
+ next: function () {
68
+ if (o && i >= o.length) o = void 0;
69
+ return { value: o && o[i++], done: !o };
70
+ }
71
+ };
72
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
73
+ };
74
+ var __importDefault = (this && this.__importDefault) || function (mod) {
75
+ return (mod && mod.__esModule) ? mod : { "default": mod };
76
+ };
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;
79
+ var spl_token_1 = require("@solana/spl-token");
80
+ var web3_js_1 = require("@solana/web3.js");
81
+ var bs58_1 = __importDefault(require("bs58"));
82
+ /**
83
+ * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
84
+ * @param {Connection} connection - Solana web3 connection object.
85
+ * @param {PublicKey} wallet - PublicKey to compare against.
86
+ * @param {number} offset - Offset of bits of the PublicKey in the account binary.
87
+ * @param {PublicKey} programId - Solana program ID.
88
+ * @return {Promise<Account[]>} - Array of resulting accounts.
89
+ */
90
+ function getProgramAccounts(connection, wallet, offset, programId) {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ return __generator(this, function (_a) {
93
+ return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
94
+ filters: [
95
+ {
96
+ memcmp: {
97
+ offset: offset,
98
+ bytes: wallet.toBase58(),
99
+ },
100
+ },
101
+ ],
102
+ })];
103
+ });
104
+ });
105
+ }
106
+ exports.getProgramAccounts = getProgramAccounts;
107
+ /**
108
+ * Utility function to check if the transaction initiator is a Wallet object
109
+ * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
110
+ * @return {boolean} - Returns true if parameter is a Wallet.
111
+ */
112
+ function isSignerWallet(walletOrKeypair) {
113
+ return walletOrKeypair.signTransaction !== undefined;
114
+ }
115
+ exports.isSignerWallet = isSignerWallet;
116
+ /**
117
+ * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
118
+ * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
119
+ * @returns {boolean} - Returns true if parameter is a Keypair.
120
+ */
121
+ function isSignerKeypair(walletOrKeypair) {
122
+ return (walletOrKeypair instanceof web3_js_1.Keypair ||
123
+ walletOrKeypair.constructor === web3_js_1.Keypair ||
124
+ walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
125
+ }
126
+ exports.isSignerKeypair = isSignerKeypair;
127
+ function signTransaction(invoker, tx) {
128
+ return __awaiter(this, void 0, void 0, function () {
129
+ var signedTx;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ if (!isSignerWallet(invoker)) return [3 /*break*/, 2];
134
+ return [4 /*yield*/, invoker.signTransaction(tx)];
135
+ case 1:
136
+ signedTx = _a.sent();
137
+ return [3 /*break*/, 3];
138
+ case 2:
139
+ tx.partialSign(invoker);
140
+ signedTx = tx;
141
+ _a.label = 3;
142
+ case 3: return [2 /*return*/, signedTx];
143
+ }
144
+ });
145
+ });
146
+ }
147
+ exports.signTransaction = signTransaction;
148
+ /**
149
+ * Signs, sends and confirms Transaction
150
+ * @param connection - Solana client connection
151
+ * @param invoker - Keypair used as signer
152
+ * @param tx - Transaction instance
153
+ * @param hash - blockhash information, the same hash should be used in the Transaction
154
+ * @returns Transaction signature
155
+ */
156
+ function signAndExecuteTransaction(connection, invoker, tx, hash) {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var signedTx, rawTx, confirmationStrategy, signature;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
162
+ case 1:
163
+ signedTx = _a.sent();
164
+ rawTx = signedTx.serialize();
165
+ if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
166
+ throw Error("Error with transaction parameters.");
167
+ confirmationStrategy = {
168
+ lastValidBlockHeight: hash.lastValidBlockHeight,
169
+ signature: bs58_1.default.encode(signedTx.signature),
170
+ blockhash: hash.blockhash,
171
+ };
172
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
173
+ case 2:
174
+ signature = _a.sent();
175
+ return [2 /*return*/, signature];
176
+ }
177
+ });
178
+ });
179
+ }
180
+ exports.signAndExecuteTransaction = signAndExecuteTransaction;
181
+ /**
182
+ * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
183
+ * @param {PublicKey} mint - SPL token Mint address.
184
+ * @param {PublicKey} owner - Owner of the Associated Token Address
185
+ * @return {Promise<PublicKey>} - Associated Token Address
186
+ */
187
+ function ata(mint, owner) {
188
+ return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
189
+ }
190
+ exports.ata = ata;
191
+ /**
192
+ * Function that checks whether ATA exists for each provided owner
193
+ * @param connection - Solana client connection
194
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
195
+ * @returns Array of boolean where each members corresponds to owners member
196
+ */
197
+ function ataBatchExist(connection, paramsBatch) {
198
+ return __awaiter(this, void 0, void 0, function () {
199
+ var tokenAccounts, response;
200
+ var _this = this;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
204
+ var mint = _a.mint, owner = _a.owner;
205
+ return __awaiter(_this, void 0, void 0, function () {
206
+ var pubkey;
207
+ return __generator(this, function (_b) {
208
+ switch (_b.label) {
209
+ case 0: return [4 /*yield*/, ata(mint, owner)];
210
+ case 1:
211
+ pubkey = _b.sent();
212
+ return [2 /*return*/, pubkey];
213
+ }
214
+ });
215
+ });
216
+ }))];
217
+ case 1:
218
+ tokenAccounts = _a.sent();
219
+ return [4 /*yield*/, connection.getMultipleAccountsInfo(tokenAccounts)];
220
+ case 2:
221
+ response = _a.sent();
222
+ return [2 /*return*/, response.map(function (accInfo) { return !!accInfo; })];
223
+ }
224
+ });
225
+ });
226
+ }
227
+ exports.ataBatchExist = ataBatchExist;
228
+ /**
229
+ * Generates a Transaction to create ATA for an array of owners
230
+ * @param connection - Solana client connection
231
+ * @param payer - Transaction invoker, should be a signer
232
+ * @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
233
+ * @returns Unsigned Transaction with create ATA instructions
234
+ */
235
+ function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var ixs, hash, tx;
238
+ var _a;
239
+ var _this = this;
240
+ return __generator(this, function (_b) {
241
+ switch (_b.label) {
242
+ case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
243
+ var mint = _a.mint, owner = _a.owner;
244
+ return __awaiter(_this, void 0, void 0, function () {
245
+ var _b, _c;
246
+ return __generator(this, function (_d) {
247
+ switch (_d.label) {
248
+ case 0:
249
+ _b = spl_token_1.createAssociatedTokenAccountInstruction;
250
+ _c = [payer];
251
+ return [4 /*yield*/, ata(mint, owner)];
252
+ case 1: return [2 /*return*/, _b.apply(void 0, _c.concat([_d.sent(), owner, mint]))];
253
+ }
254
+ });
255
+ });
256
+ }))];
257
+ case 1:
258
+ ixs = _b.sent();
259
+ return [4 /*yield*/, connection.getLatestBlockhash()];
260
+ case 2:
261
+ hash = _b.sent();
262
+ tx = (_a = new web3_js_1.Transaction({
263
+ feePayer: payer,
264
+ blockhash: hash.blockhash,
265
+ lastValidBlockHeight: hash.lastValidBlockHeight,
266
+ })).add.apply(_a, __spreadArray([], __read(ixs), false));
267
+ return [2 /*return*/, { tx: tx, hash: hash }];
268
+ }
269
+ });
270
+ });
271
+ }
272
+ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
273
+ /**
274
+ * Creates ATA for an array of owners
275
+ * @param connection - Solana client connection
276
+ * @param invoker - Transaction invoker and payer
277
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
278
+ * @returns Transaction signature
279
+ */
280
+ function createAtaBatch(connection, invoker, paramsBatch) {
281
+ return __awaiter(this, void 0, void 0, function () {
282
+ var _a, tx, hash, signature;
283
+ return __generator(this, function (_b) {
284
+ switch (_b.label) {
285
+ case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
286
+ case 1:
287
+ _a = _b.sent(), tx = _a.tx, hash = _a.hash;
288
+ return [4 /*yield*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
289
+ case 2:
290
+ signature = _b.sent();
291
+ return [2 /*return*/, signature];
292
+ }
293
+ });
294
+ });
295
+ }
296
+ exports.createAtaBatch = createAtaBatch;
297
+ /**
298
+ * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
299
+ * @param connection - Solana client connection
300
+ * @param owners - Array of ATA owners
301
+ * @param mint - Mint for which ATA will be checked
302
+ * @param invoker - Transaction invoker and payer
303
+ * @returns Array of Transaction Instructions that should be added to a transaction
304
+ */
305
+ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
306
+ return __awaiter(this, void 0, void 0, function () {
307
+ var ixs, atas, owners_1, owners_1_1, owner, _a, _b, e_1_1, response, i;
308
+ var e_1, _c;
309
+ return __generator(this, function (_d) {
310
+ switch (_d.label) {
311
+ case 0:
312
+ ixs = [];
313
+ atas = [];
314
+ _d.label = 1;
315
+ case 1:
316
+ _d.trys.push([1, 6, 7, 8]);
317
+ owners_1 = __values(owners), owners_1_1 = owners_1.next();
318
+ _d.label = 2;
319
+ case 2:
320
+ if (!!owners_1_1.done) return [3 /*break*/, 5];
321
+ owner = owners_1_1.value;
322
+ _b = (_a = atas).push;
323
+ return [4 /*yield*/, ata(mint, owner)];
324
+ case 3:
325
+ _b.apply(_a, [_d.sent()]);
326
+ _d.label = 4;
327
+ case 4:
328
+ owners_1_1 = owners_1.next();
329
+ return [3 /*break*/, 2];
330
+ case 5: return [3 /*break*/, 8];
331
+ case 6:
332
+ e_1_1 = _d.sent();
333
+ e_1 = { error: e_1_1 };
334
+ return [3 /*break*/, 8];
335
+ case 7:
336
+ try {
337
+ if (owners_1_1 && !owners_1_1.done && (_c = owners_1.return)) _c.call(owners_1);
338
+ }
339
+ finally { if (e_1) throw e_1.error; }
340
+ return [7 /*endfinally*/];
341
+ case 8: return [4 /*yield*/, connection.getMultipleAccountsInfo(atas)];
342
+ case 9:
343
+ response = _d.sent();
344
+ for (i = 0; i < response.length; i++) {
345
+ if (!response[i]) {
346
+ ixs.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(invoker.publicKey, atas[i], owners[i], mint));
347
+ }
348
+ }
349
+ return [2 /*return*/, ixs];
350
+ }
351
+ });
352
+ });
353
+ }
354
+ exports.checkOrCreateAtaBatch = checkOrCreateAtaBatch;
@@ -0,0 +1,32 @@
1
+ import { TransactionInstruction } from "@solana/web3.js";
2
+ import { Types } from "aptos";
3
+ export interface ITransactionResult {
4
+ ixs: (TransactionInstruction | Types.TransactionPayload)[];
5
+ txId: string;
6
+ }
7
+ export declare enum ICluster {
8
+ Mainnet = "mainnet",
9
+ Devnet = "devnet",
10
+ Testnet = "testnet",
11
+ Local = "local"
12
+ }
13
+ export declare enum IChain {
14
+ Solana = "Solana",
15
+ Aptos = "Aptos",
16
+ Ethereum = "Ethereum",
17
+ BNB = "BNB",
18
+ Polygon = "Polygon",
19
+ Sui = "Sui"
20
+ }
21
+ /**
22
+ * Error wrapper for calls made to the contract on chain
23
+ */
24
+ export declare class ContractError extends Error {
25
+ contractErrorCode: string | null;
26
+ /**
27
+ * Constructs the Error Wrapper
28
+ * @param error Original error raised probably by the chain SDK
29
+ * @param code extracted code from the error if managed to parse it
30
+ */
31
+ constructor(error: Error, code?: string | null);
32
+ }