@streamflow/stream 3.0.1 → 3.0.3

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.
@@ -0,0 +1,248 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __read = (this && this.__read) || function (o, n) {
62
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
63
+ if (!m) return o;
64
+ var i = m.call(o), r, ar = [], e;
65
+ try {
66
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
67
+ }
68
+ catch (error) { e = { error: error }; }
69
+ finally {
70
+ try {
71
+ if (r && !r.done && (m = i["return"])) m.call(i);
72
+ }
73
+ finally { if (e) throw e.error; }
74
+ }
75
+ return ar;
76
+ };
77
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
78
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
79
+ if (ar || !(i in from)) {
80
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
81
+ ar[i] = from[i];
82
+ }
83
+ }
84
+ return to.concat(ar || Array.prototype.slice.call(from));
85
+ };
86
+ var __importDefault = (this && this.__importDefault) || function (mod) {
87
+ return (mod && mod.__esModule) ? mod : { "default": mod };
88
+ };
89
+ var _a;
90
+ Object.defineProperty(exports, "__esModule", { value: true });
91
+ exports.timePeriodOptions = exports.PERIOD = exports.TIME_FORMAT = exports.DATE_FORMAT = void 0;
92
+ var StreamClient_1 = __importDefault(require("../StreamClient"));
93
+ var types_1 = require("../types");
94
+ var web3 = __importStar(require("@solana/web3.js"));
95
+ var utils_1 = require("../utils");
96
+ var airdrop_request_1 = require("./test_dependencies/airdrop/airdrop-request");
97
+ var anchor_1 = require("@project-serum/anchor");
98
+ var constants_1 = require("../constants");
99
+ var bn_js_1 = require("bn.js");
100
+ var streamInstance = null;
101
+ var sender;
102
+ var recipient;
103
+ var recipients = [];
104
+ var connection = null;
105
+ var date_fns_1 = require("date-fns");
106
+ var CLUSTER_LOCAL = "local";
107
+ var clusterUrls = (_a = {},
108
+ _a[CLUSTER_LOCAL] = function () { return "http://localhost:8899"; },
109
+ _a[types_1.Cluster.Devnet] = function () { return "https://api.devnet.solana.com"; },
110
+ _a[types_1.Cluster.Mainnet] = function () { return "https://api.mainnet-beta.solana.com"; },
111
+ _a);
112
+ beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
113
+ return __generator(this, function (_a) {
114
+ switch (_a.label) {
115
+ case 0:
116
+ streamInstance = new StreamClient_1.default(clusterUrls[types_1.Cluster.Devnet](), types_1.Cluster.Devnet, {
117
+ commitment: "confirmed",
118
+ disableRetryOnRateLimit: true,
119
+ });
120
+ connection = new web3.Connection(web3.clusterApiUrl(), "confirmed");
121
+ sender = new anchor_1.Wallet(web3.Keypair.generate());
122
+ recipient = new anchor_1.Wallet(web3.Keypair.generate());
123
+ recipients = __spreadArray([], __read(new Array(30)), false).map(function () { return new anchor_1.Wallet(web3.Keypair.generate()); });
124
+ return [4 /*yield*/, (0, airdrop_request_1.requestAirdrop)(sender, connection)];
125
+ case 1:
126
+ _a.sent();
127
+ return [2 /*return*/];
128
+ }
129
+ });
130
+ }); }, 100000);
131
+ test("Sender wallet airdropped funds", function () { return __awaiter(void 0, void 0, void 0, function () {
132
+ var _a;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ _a = expect;
137
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getBalance(sender.publicKey))];
138
+ case 1:
139
+ _a.apply(void 0, [_b.sent()]).toBeGreaterThan(0);
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ }); }, 100000);
144
+ test("Stream client connects to cluster", function () { return __awaiter(void 0, void 0, void 0, function () {
145
+ var streamInstanceConnection;
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ expect(streamInstance).toBeTruthy();
150
+ return [4 /*yield*/, (streamInstance === null || streamInstance === void 0 ? void 0 : streamInstance.getConnection())];
151
+ case 1:
152
+ streamInstanceConnection = _a.sent();
153
+ expect(streamInstanceConnection).toBeTruthy();
154
+ return [2 /*return*/];
155
+ }
156
+ });
157
+ }); });
158
+ var newCreateMultipleStreamsPayload = function (values, sender) {
159
+ var recipients = values.recipients, releaseAmount = values.releaseAmount, startDate = values.startDate, startTime = values.startTime, releaseFrequencyCounter = values.releaseFrequencyCounter, releaseFrequencyPeriod = values.releaseFrequencyPeriod, whoCanTransfer = values.whoCanTransfer, whoCanCancel = values.whoCanCancel, referral = values.referral;
160
+ var start = (0, date_fns_1.getUnixTime)(new Date(startDate + "T" + startTime));
161
+ var recipientsFormatted = recipients.map(function (_a) {
162
+ var depositedAmount = _a.depositedAmount, recipient = _a.recipient, name = _a.name;
163
+ return ({
164
+ recipient: recipient,
165
+ name: name,
166
+ depositedAmount: (0, utils_1.getBN)(depositedAmount, 9),
167
+ amountPerPeriod: (0, utils_1.getBN)(releaseAmount, 9),
168
+ cliffAmount: new bn_js_1.BN(0),
169
+ });
170
+ });
171
+ var data = {
172
+ sender: sender,
173
+ recipientsData: recipientsFormatted,
174
+ mint: constants_1.AIRDROP_TEST_TOKEN,
175
+ start: start,
176
+ period: releaseFrequencyCounter * releaseFrequencyPeriod,
177
+ cliff: start,
178
+ cancelableBySender: whoCanCancel === types_1.TransferCancelOptions.Sender ||
179
+ whoCanCancel === types_1.TransferCancelOptions.Both,
180
+ cancelableByRecipient: whoCanCancel === types_1.TransferCancelOptions.Recipient ||
181
+ whoCanCancel === types_1.TransferCancelOptions.Both,
182
+ transferableBySender: whoCanTransfer === types_1.TransferCancelOptions.Sender ||
183
+ whoCanTransfer === types_1.TransferCancelOptions.Both,
184
+ transferableByRecipient: whoCanTransfer === types_1.TransferCancelOptions.Recipient ||
185
+ whoCanTransfer === types_1.TransferCancelOptions.Both,
186
+ automaticWithdrawal: false,
187
+ withdrawalFrequency: 0,
188
+ canTopup: true,
189
+ partner: referral,
190
+ };
191
+ return data;
192
+ };
193
+ exports.DATE_FORMAT = "yyyy-MM-dd";
194
+ exports.TIME_FORMAT = "HH:mm";
195
+ exports.PERIOD = {
196
+ SECOND: 1,
197
+ MINUTE: 60,
198
+ HOUR: 3600,
199
+ DAY: 24 * 3600,
200
+ WEEK: 7 * 24 * 3600,
201
+ MONTH: Math.floor(30.4167 * 24 * 3600),
202
+ YEAR: 365 * 24 * 3600, // 365 days
203
+ };
204
+ exports.timePeriodOptions = [
205
+ { value: exports.PERIOD.SECOND, label: "second" },
206
+ { value: exports.PERIOD.MINUTE, label: "minute" },
207
+ { value: exports.PERIOD.HOUR, label: "hour" },
208
+ { value: exports.PERIOD.DAY, label: "day" },
209
+ { value: exports.PERIOD.WEEK, label: "week" },
210
+ { value: exports.PERIOD.MONTH, label: "month" },
211
+ { value: exports.PERIOD.YEAR, label: "year" },
212
+ ];
213
+ test("Can create multiple stremas", function () { return __awaiter(void 0, void 0, void 0, function () {
214
+ var now, recipientsPayload, values, data, response;
215
+ return __generator(this, function (_a) {
216
+ switch (_a.label) {
217
+ case 0:
218
+ now = new Date();
219
+ recipientsPayload = recipients.map(function (recipient, i) { return ({
220
+ recipient: recipient.publicKey.toBase58(),
221
+ recipientEmail: "",
222
+ name: "Recipient " + i,
223
+ depositedAmount: 0.0001,
224
+ }); });
225
+ values = {
226
+ releaseAmount: 0.00001,
227
+ tokenSymbol: "",
228
+ startDate: (0, date_fns_1.format)(now, exports.DATE_FORMAT),
229
+ startTime: (0, date_fns_1.format)((0, date_fns_1.add)(now, { minutes: 5 }), exports.TIME_FORMAT),
230
+ releaseFrequencyCounter: 1,
231
+ releaseFrequencyPeriod: exports.timePeriodOptions[0].value,
232
+ whoCanTransfer: types_1.TransferCancelOptions.Recipient,
233
+ whoCanCancel: types_1.TransferCancelOptions.Sender,
234
+ automaticWithdrawal: false,
235
+ withdrawalFrequencyCounter: 1,
236
+ withdrawalFrequencyPeriod: exports.timePeriodOptions[1].value,
237
+ referral: "",
238
+ email: "",
239
+ recipients: recipientsPayload,
240
+ };
241
+ data = newCreateMultipleStreamsPayload(values, sender);
242
+ return [4 /*yield*/, (streamInstance === null || streamInstance === void 0 ? void 0 : streamInstance.createMultiple(data))];
243
+ case 1:
244
+ response = _a.sent();
245
+ return [2 /*return*/, response];
246
+ }
247
+ });
248
+ }); }, 600000);
@@ -0,0 +1,3 @@
1
+ import { Wallet } from "@project-serum/anchor";
2
+ import { Connection } from "@solana/web3.js";
3
+ export declare const requestAirdrop: (wallet: Wallet, connection: Connection) => Promise<[import("@solana/web3.js").RpcResponseAndContext<import("@solana/web3.js").SignatureResult>] | undefined>;
@@ -0,0 +1,67 @@
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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.requestAirdrop = void 0;
40
+ var web3_js_1 = require("@solana/web3.js");
41
+ var airdrop_1 = require("./airdrop");
42
+ var constants_1 = require("../constants");
43
+ var constants_2 = require("../constants");
44
+ var requestAirdrop = function (wallet, connection) { return __awaiter(void 0, void 0, void 0, function () {
45
+ var txSolAirdrop, txTestTokenAirdrop;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ if (!(wallet === null || wallet === void 0 ? void 0 : wallet.publicKey) || !connection) {
50
+ return [2 /*return*/];
51
+ }
52
+ return [4 /*yield*/, connection.requestAirdrop(wallet.publicKey, constants_1.AIRDROP_AMOUNT * web3_js_1.LAMPORTS_PER_SOL)];
53
+ case 1:
54
+ txSolAirdrop = _a.sent();
55
+ return [4 /*yield*/, connection.confirmTransaction(txSolAirdrop, constants_2.TX_FINALITY_CONFIRMED)];
56
+ case 2:
57
+ _a.sent();
58
+ return [4 /*yield*/, (0, airdrop_1.getTestTokenAirdrop)(connection, wallet)];
59
+ case 3:
60
+ txTestTokenAirdrop = _a.sent();
61
+ return [2 /*return*/, Promise.all([
62
+ connection.confirmTransaction(txTestTokenAirdrop, constants_2.TX_FINALITY_CONFIRMED),
63
+ ])];
64
+ }
65
+ });
66
+ }); };
67
+ exports.requestAirdrop = requestAirdrop;
@@ -0,0 +1,6 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ import type { TransactionSignature } from "@solana/web3.js";
3
+ import { Wallet } from "@project-serum/anchor";
4
+ export declare function initialize(connection: Connection, wallet: Wallet): Promise<boolean>;
5
+ export declare function getTestTokenAirdrop(connection: Connection, wallet: Wallet): Promise<TransactionSignature>;
6
+ export declare function cancel(connection: Connection, wallet: Wallet): Promise<boolean>;
@@ -0,0 +1,215 @@
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 (_) 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 __importDefault = (this && this.__importDefault) || function (mod) {
55
+ return (mod && mod.__esModule) ? mod : { "default": mod };
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.cancel = exports.getTestTokenAirdrop = exports.initialize = void 0;
59
+ var anchor_1 = require("@project-serum/anchor");
60
+ var web3_js_1 = require("@solana/web3.js");
61
+ var spl_token_1 = require("@solana/spl-token");
62
+ var airdrop_1 = __importDefault(require("../idl/airdrop"));
63
+ var constants_1 = require("../constants");
64
+ var PROGRAM_ID = "Ek6Jpdv5iEEDLXTVQ8UFcntms3DT2ewHtzzwH2R5MpvN";
65
+ function initProgram(connection, wallet) {
66
+ var provider = new anchor_1.Provider(connection, wallet, {});
67
+ return new anchor_1.Program(airdrop_1.default, PROGRAM_ID, provider);
68
+ }
69
+ function initialize(connection, wallet) {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var program, mint, airdropAccount, assTokenAccount, assAirdropTokAcc, instr, err_1;
72
+ return __generator(this, function (_a) {
73
+ switch (_a.label) {
74
+ case 0:
75
+ program = initProgram(connection, wallet);
76
+ mint = new web3_js_1.PublicKey(constants_1.AIRDROP_TEST_TOKEN);
77
+ airdropAccount = new web3_js_1.Keypair();
78
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getTokenAccountsByOwner(wallet === null || wallet === void 0 ? void 0 : wallet.publicKey, {
79
+ mint: mint,
80
+ }))];
81
+ case 1:
82
+ assTokenAccount = (_a.sent()).value[0].pubkey;
83
+ return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, airdropAccount.publicKey)];
84
+ case 2:
85
+ assAirdropTokAcc = _a.sent();
86
+ instr = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, assAirdropTokAcc, airdropAccount.publicKey, wallet.publicKey);
87
+ _a.label = 3;
88
+ case 3:
89
+ _a.trys.push([3, 5, , 6]);
90
+ return [4 /*yield*/, program.rpc.initializeAirdrop(new anchor_1.BN(1000000 * Math.pow(10, 9)), new anchor_1.BN(100 * Math.pow(10, 9)), {
91
+ accounts: {
92
+ initializer: wallet === null || wallet === void 0 ? void 0 : wallet.publicKey,
93
+ initializerDepositTokenAccount: assTokenAccount,
94
+ airdropAccount: airdropAccount.publicKey,
95
+ airdropTokenAccount: assAirdropTokAcc,
96
+ systemProgram: web3_js_1.SystemProgram.programId,
97
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
98
+ },
99
+ signers: [airdropAccount],
100
+ instructions: [instr],
101
+ })];
102
+ case 4:
103
+ _a.sent();
104
+ return [2 /*return*/, true];
105
+ case 5:
106
+ err_1 = _a.sent();
107
+ return [2 /*return*/, false];
108
+ case 6: return [2 /*return*/];
109
+ }
110
+ });
111
+ });
112
+ }
113
+ exports.initialize = initialize;
114
+ function getTestTokenAirdrop(connection, wallet) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var program, mint, airdropAccount, assTokenAcc, pda, _a, _pda, assAirdropTokAcc, tx, err_2;
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ program = initProgram(connection, wallet);
121
+ mint = new web3_js_1.PublicKey(constants_1.AIRDROP_TEST_TOKEN);
122
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(new web3_js_1.PublicKey(PROGRAM_ID)))];
123
+ case 1:
124
+ airdropAccount = (_b.sent())[0];
125
+ return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, wallet.publicKey)];
126
+ case 2:
127
+ assTokenAcc = _b.sent();
128
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(program.programId))];
129
+ case 3:
130
+ pda = (_b.sent())[0]
131
+ .pubkey;
132
+ return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([Buffer.from("streamflow-airdrop", "utf-8")], program.programId)];
133
+ case 4:
134
+ _a = __read.apply(void 0, [_b.sent(), 1]), _pda = _a[0];
135
+ return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, pda)];
136
+ case 5:
137
+ assAirdropTokAcc = _b.sent();
138
+ _b.label = 6;
139
+ case 6:
140
+ _b.trys.push([6, 8, , 9]);
141
+ return [4 /*yield*/, program.rpc.getAirdrop({
142
+ accounts: {
143
+ taker: wallet === null || wallet === void 0 ? void 0 : wallet.publicKey,
144
+ takerReceiveTokenAccount: assTokenAcc,
145
+ airdropAccount: airdropAccount.pubkey,
146
+ airdropTokenAccount: assAirdropTokAcc,
147
+ mint: mint,
148
+ pdaAccount: _pda,
149
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
150
+ associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
151
+ systemProgram: web3_js_1.SystemProgram.programId,
152
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
153
+ },
154
+ })];
155
+ case 7:
156
+ tx = _b.sent();
157
+ return [2 /*return*/, tx];
158
+ case 8:
159
+ err_2 = _b.sent();
160
+ throw new Error(err_2);
161
+ case 9: return [2 /*return*/];
162
+ }
163
+ });
164
+ });
165
+ }
166
+ exports.getTestTokenAirdrop = getTestTokenAirdrop;
167
+ function cancel(connection, wallet) {
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ var program, mint, airdropAccount, assTokenAcc, pda, _a, _pda, assAirdropTokAcc, err_3;
170
+ return __generator(this, function (_b) {
171
+ switch (_b.label) {
172
+ case 0:
173
+ program = initProgram(connection, wallet);
174
+ mint = new web3_js_1.PublicKey(constants_1.AIRDROP_TEST_TOKEN);
175
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(new web3_js_1.PublicKey(PROGRAM_ID)))];
176
+ case 1:
177
+ airdropAccount = (_b.sent())[0];
178
+ return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, wallet.publicKey)];
179
+ case 2:
180
+ assTokenAcc = _b.sent();
181
+ return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(program.programId))];
182
+ case 3:
183
+ pda = (_b.sent())[0]
184
+ .pubkey;
185
+ return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([Buffer.from("streamflow-airdrop", "utf-8")], program.programId)];
186
+ case 4:
187
+ _a = __read.apply(void 0, [_b.sent(), 1]), _pda = _a[0];
188
+ return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, pda)];
189
+ case 5:
190
+ assAirdropTokAcc = _b.sent();
191
+ _b.label = 6;
192
+ case 6:
193
+ _b.trys.push([6, 8, , 9]);
194
+ return [4 /*yield*/, program.rpc.cancelAirdrop({
195
+ accounts: {
196
+ initializer: wallet === null || wallet === void 0 ? void 0 : wallet.publicKey,
197
+ initializerDepositTokenAccount: assTokenAcc,
198
+ pdaAccount: _pda,
199
+ airdropAccount: airdropAccount.pubkey,
200
+ airdropTokenAccount: assAirdropTokAcc,
201
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
202
+ },
203
+ })];
204
+ case 7:
205
+ _b.sent();
206
+ return [2 /*return*/, true];
207
+ case 8:
208
+ err_3 = _b.sent();
209
+ return [2 /*return*/, false];
210
+ case 9: return [2 /*return*/];
211
+ }
212
+ });
213
+ });
214
+ }
215
+ exports.cancel = cancel;
@@ -0,0 +1,122 @@
1
+ export declare const AIRDROP_AMOUNT = 1;
2
+ export declare const AIRDROP_PDA = "DRCLpDJUNiMeKuRP9dcnGuibjTMjDGFwbZEXsq1RRgiR";
3
+ export declare const AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
4
+ export declare const AIRDROP_WHITELIST: string[];
5
+ export declare const ALLOWED_PDA_PROGRAMS: string[];
6
+ export declare const TX_FINALITY_CONFIRMED = "confirmed";
7
+ export declare const TX_FINALITY_FINALIZED = "finalized";
8
+ export declare const INSTRUCTION_CREATE_STREAM = 0;
9
+ export declare const INSTRUCTION_WITHDRAW_STREAM = 1;
10
+ export declare const INSTRUCTION_CANCEL_STREAM = 2;
11
+ export declare const INSTRUCTION_TRANSFER_RECIPIENT = 3;
12
+ export declare enum ProgramInstruction {
13
+ Create = 0,
14
+ Withdraw = 1,
15
+ Topup = 2,
16
+ Cancel = 3,
17
+ TransferRecipient = 4
18
+ }
19
+ export declare const EXPLORER_TYPE_TX = "tx";
20
+ export declare const EXPLORER_TYPE_ADDR = "address";
21
+ export declare const DATE_FORMAT = "yyyy-MM-dd";
22
+ export declare const TIME_FORMAT = "HH:mm";
23
+ export declare const START = "start";
24
+ export declare const END = "end";
25
+ export declare const ERR_NO_STREAM = "Specified stream doesn't exist. Please double check with the sender.";
26
+ export declare const ERR_NOT_CONNECTED = "There was an issue with the connection - please try to refresh the page.";
27
+ export declare const ERR_NO_TOKEN_SELECTED = "Please select the token";
28
+ export declare const ERR_NO_PRIOR_CREDIT = "You don't have enough SOL in your wallet to pay for transaction fees.";
29
+ export declare const PRODUCT_VESTING = "vesting";
30
+ export declare const PRODUCT_STREAMS = "streams";
31
+ export declare const PRODUCT_MULTIPAY = "multipay";
32
+ export declare const PRODUCT_MULTISIG = "multisig";
33
+ export declare const products: string[];
34
+ export declare const DEFAULT_DECIMAL_PLACES = 2;
35
+ export declare const ERRORS: {
36
+ amount_required: string;
37
+ amount_greater_than: string;
38
+ token_required: string;
39
+ recipient_required: string;
40
+ not_valid_email: string;
41
+ subject_required: string;
42
+ start_date_required: string;
43
+ start_date_is_in_the_past: string;
44
+ start_time_required: string;
45
+ start_time_is_in_the_past: string;
46
+ end_date_required: string;
47
+ end_time_required: string;
48
+ deposited_amount_required: string;
49
+ amount_too_high: string;
50
+ invalid_address: string;
51
+ address_is_a_program: string;
52
+ release_amount_greater_than_deposited: string;
53
+ end_should_be_after_start: string;
54
+ cliff_should_be_after_start: string;
55
+ cliff_should_be_before_end: string;
56
+ required: string;
57
+ release_frequency_is_too_slow: string;
58
+ should_be_greater_than_0: string;
59
+ max_year: string;
60
+ subject_too_long: string;
61
+ withdrawal_frequency_too_high: string;
62
+ };
63
+ export declare const PERIOD: {
64
+ SECOND: number;
65
+ MINUTE: number;
66
+ HOUR: number;
67
+ DAY: number;
68
+ WEEK: number;
69
+ MONTH: number;
70
+ YEAR: number;
71
+ };
72
+ export declare const timePeriodOptions: {
73
+ value: number;
74
+ label: string;
75
+ }[];
76
+ export declare const EVENT_CATEGORY: {
77
+ WALLET: string;
78
+ STREAM: string;
79
+ VESTING: string;
80
+ };
81
+ export declare const EVENT_ACTION: {
82
+ TRANSFER: string;
83
+ CANCEL: string;
84
+ TOP_UP: string;
85
+ WITHDRAW: string;
86
+ CONNECT: string;
87
+ DISCONNECT: string;
88
+ };
89
+ export declare const EVENT_LABEL: {
90
+ NONE: string;
91
+ };
92
+ export declare const EVENT_TYPE: {
93
+ EVENT: string;
94
+ PAGEVIEW: string;
95
+ PURCHASE: string;
96
+ };
97
+ export declare const TRANSACTION_VARIANT: {
98
+ CREATE_VESTING: string;
99
+ CREATE_STREAM: string;
100
+ TOP_UP_STREAM: string;
101
+ };
102
+ export declare const AFFILIATION: {
103
+ FREE: string;
104
+ APP: string;
105
+ };
106
+ export declare const DEFAULT_GA_PURCHASE_CURRENCY = "USD";
107
+ export declare const USD_PEGGED_COINS: string[];
108
+ export declare const DATA_LAYER_VARIABLE: {
109
+ WALLET_TYPE: string;
110
+ TOKEN_FEE: string;
111
+ TOKEN_SYMBOL: string;
112
+ STREAM_ADDRESS: string;
113
+ TOKEN_WITHDRAW_USD: string;
114
+ STREAMFLOW_FEE_USD: string;
115
+ STREAMFLOW_FEE_TOKEN: string;
116
+ TOTAL_AMOUNT_TOKEN: string;
117
+ TOTAL_AMOUNT_USD: string;
118
+ };
119
+ export declare const transferCancelOptions: {
120
+ value: string;
121
+ label: string;
122
+ }[];